⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inetserverdlg.cpp

📁 一个SMTP邮件发送的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
								
								sprintf(fwdstr,"");
								
								fgets(fwdstr,255,fwdfp);
								
								
								if (strlen(fwdstr) > 3)
								{
									
									if (fwdstr[strlen(fwdstr)-2] == '\n') fwdstr[strlen(fwdstr)-2] = '\0';
									if (fwdstr[strlen(fwdstr)-2] == '\r') fwdstr[strlen(fwdstr)-2] = '\0';
									
									sscanf(fwdstr,"%s %s",fwdsrc,fwddest);

									sprintf(sendstrh,"\r\n%-20s %-20s",fwdsrc,fwddest);
									pSocket->Send (sendstrh,strlen(sendstrh),0);
				
								}
							}
							fclose(fwdfp);
						}
				
				
				
				sprintf(sendstrh,"\r\n> ");
				pSocket->Send (sendstrh,strlen(sendstrh),0);
				
				return;
						
						
			}
			else
			{
					sprintf(sendstr,"\r\nAccess denied\r\n> ");
					pSocket->Send (sendstr,strlen(sendstr),0);
					return;
					
			}
			
				
		}				
		
		
	

		if (strcmpi(tempstr2,"logger") == 0)
		{
			if (MatchFlag (SocketList[i].Username,'O'))
			{
				sprintf(sendstrh,"\r\nLogging to your screen - Press enter to abort\r\n----------------------------------------------------\r\n");
				pSocket->Send (sendstrh,strlen(sendstrh),0);
				SocketList[i].status = 4;
				SocketList[i].showlog = TRUE;
				return;
			}
			else
			{
				sprintf(sendstr,"\r\nAccess denied\r\n> ");
				pSocket->Send (sendstr,strlen(sendstr),0);
				return;
			}
			
			
		}
		
		
		
		
		
		if ((strcmpi(tempstr2,"clear") == 0) || (strcmpi(tempstr2,"cls") == 0))
		{
			//beta (works only with ANSI terminals)!
			
			
			
			sprintf(sendstrh,"\x01b[0;37;40m\x01b[2J");
			pSocket->Send (sendstrh,strlen(sendstrh),0);
			sprintf(sendstrh,"\r\n> ");
			pSocket->Send (sendstrh,strlen(sendstrh),0);
			
			return;
		}
		
		
		
		if (strcmpi(tempstr2,"useradd") == 0)  
		{
			if (MatchFlag (SocketList[i].Username,'O'))
			{
				sprintf(sendstr,"\r\nCreating a new user\r\nPOP3 login name:");
				pSocket->Send (sendstr,strlen(sendstr),0);
				SocketList[i].status2 = 1;
				SocketList[i].status = 3;
				return;
			}
			else
			{
				sprintf(sendstr,"\r\nAccess denied\r\n> ");
				pSocket->Send (sendstr,strlen(sendstr),0);
				return;
			}
		}
		
		
		if (strcmpi(tempstr2,"userdel") == 0)  
		{
			if (MatchFlag (SocketList[i].Username,'O'))
			{
				sprintf(sendstr,"\r\nDeleting a user\r\nUsername to delete:");
				pSocket->Send (sendstr,strlen(sendstr),0);
				SocketList[i].status2 = 1;
				SocketList[i].status = 5;
				return;
			}
			else
			{
				sprintf(sendstr,"\r\nAccess denied\r\n> ");
				pSocket->Send (sendstr,strlen(sendstr),0);
				return;
			}
		}
		
		if (strcmpi(tempstr2,"motd") == 0)  
		{
			
			
			FILE *fpmotd;
			
			fpmotd = fopen("telnet\\motd.txt","rt");
			sprintf(sendstr,"\r\n");
			pSocket->Send (sendstr,strlen(sendstr),0);
			if (fpmotd == NULL)
			{
				AddLog("Couldn't read telnet motd from telnet\\motd.txt");
				
				
			}
			else
			{
				while (fgets(sendstr,255,fpmotd))
				{
					pSocket->Send (sendstr,strlen(sendstr),0);
					pSocket->Send ("\r",1,0);
				}
				
				fclose(fpmotd);
				
			}
			
			sprintf(sendstr,"\r\n> ");
			pSocket->Send (sendstr,strlen(sendstr),0);
			return;
		}
		
		sprintf(sendstr,"\r\nUnknown command, try \"help\"\r\n> ");
		pSocket->Send (sendstr,strlen(sendstr),0);
		return;
	}
	
	
	if 	(SocketList[i].status == 3)  
	{
		if (MatchFlag (SocketList[i].Username,'O'))
		{
			char tempstr2[255];
			sprintf(tempstr2,"%s",tempstr);
			SocketList[i].Temp = "";
			
			DeleteCRLF(tempstr2);
			
			if (SocketList[i].status2 == 1)
			{
				SocketList[i].info1 = tempstr2;
				sprintf(sendstr,"\r\nPassword:");
				pSocket->Send (sendstr,strlen(sendstr),0);
				SocketList[i].status2 = 2;
				SocketList[i].dontwrite = TRUE;
				return;
			}
			
			if (SocketList[i].status2 == 2)
			{
				SocketList[i].info2 = tempstr2;
				sprintf(sendstr,"\r\nConfirm password:");
				pSocket->Send (sendstr,strlen(sendstr),0);
				SocketList[i].dontwrite = TRUE;
				SocketList[i].status2 = 3;
				return;
			}
			if (SocketList[i].status2 == 3)
			{
				SocketList[i].dontwrite = FALSE;
				SocketList[i].info3 = tempstr2;
				if (strcmp(SocketList[i].info2,SocketList[i].info3) != 0)
				{
					sprintf(sendstr,"\r\nThe entered passwords are not the same.\r\nAborted.\r\n> ");
					
					pSocket->Send (sendstr,strlen(sendstr),0);
					SocketList[i].status2 = 0;
					SocketList[i].status = 2;
					return;
				}
				else
				{
					sprintf(sendstr,"\r\nFlags:");
					pSocket->Send (sendstr,strlen(sendstr),0);
					SocketList[i].status2 = 4;
					return;
				}
				return;
				
			}
			if (SocketList[i].status2 == 4)
			{
				SocketList[i].info4 = tempstr2;
				sprintf(sendstr,"\r\nType \"add\" to accept the user, or press enter to abort\r\n");
				pSocket->Send (sendstr,strlen(sendstr),0);
				SocketList[i].status2 = 5;
				return;
			}
			if (SocketList[i].status2 == 5) 
			{
				if (strcmp(tempstr2,"add") == 0)
				{
					sprintf(sendstr,"\r\nUser added");
					
					
					MailUserInfo MyUserInfo;
					MyUserInfo.Username= SocketList[i].info1;
					char temps[255];
					sprintf(temps,"%s",SocketList[i].info2);
					MyUserInfo.Password= CreatePassword(temps);
					MyUserInfo.Flags= SocketList[i].info4;
					MailUserList.Add(MyUserInfo);
					SavePOP3Users();
					
					
					
					pSocket->Send (sendstr,strlen(sendstr),0);
				}
				else
				{
					sprintf(sendstr,"\r\nAdding of user aborted");
					pSocket->Send (sendstr,strlen(sendstr),0);
				}
				
				SocketList[i].status2 = 0;
				SocketList[i].status = 2;
				sprintf(sendstr,"\r\n> ");
				pSocket->Send (sendstr,strlen(sendstr),0);
				
				return;
			}
		}
		else
		{
			sprintf(sendstr,"\r\nAccess denied\r\n> ");
			pSocket->Send (sendstr,strlen(sendstr),0);
			return;
		}
		
		
	}
	
	
	if 	(SocketList[i].status == 4)
	{
		
		SocketList[i].status = 2;
		SocketList[i].showlog = FALSE;
		sprintf(sendstr,"\r\nLogging output stopped\r\n> ");
		SocketList[i].Temp = "";
		
		pSocket->Send (sendstr,strlen(sendstr),0);
		return;
	}
	
	if 	(SocketList[i].status == 5)
	{
		
		char tempstr2[255];
		sprintf(tempstr2,"%s",tempstr);
		SocketList[i].Temp = "";
		DeleteCRLF(tempstr2);
		
		if (MatchFlag (SocketList[i].Username,'O'))
		{
			if (stricmp(SocketList[i].Username,tempstr2) == 0)
			{
				sprintf(sendstr,"\r\nYou can't delete youself\r\n> ",tempstr2);
				pSocket->Send (sendstr,strlen(sendstr),0);
				SocketList[i].status2 = 0;
				SocketList[i].status = 2;
				return;
			}
			
			sprintf(sendstr,"\r\nDeleting user %s...\r\n> ",tempstr2);
			pSocket->Send (sendstr,strlen(sendstr),0);
			SocketList[i].status2 = 0;
			SocketList[i].status = 2;
			
			
			for (int x= 0;x<=MailUserList.GetSize()-1;x++)
			{
				if (stricmp(MailUserList[x].Username,tempstr2) == 0)
				{
					MailUserList.RemoveAt(x);
					break;
					
				}
				
				
			}
			
			
			SavePOP3Users();
			
			
			
			
			return;
		}
		else
		{
			sprintf(sendstr,"\r\nAccess denied\r\n> ");
			pSocket->Send (sendstr,strlen(sendstr),0);
			return;
		}
		
		
	}

	if 	(SocketList[i].status == 6)
	{
		char tempstr2[255];
		sprintf(tempstr2,"%s",tempstr);
		
		SocketList[i].Temp = "";
		DeleteCRLF(tempstr2);
		SocketList[i].status = 2;

		char tempstr3[255];
		sprintf(tempstr3,"%s",GetReg("Software\\InetServ",tempstr2));
		sprintf(sendstr,"\r\nCurrent value:%s\r\n> ",tempstr3);
		pSocket->Send (sendstr,strlen(sendstr),0);
		return;

	}

	if 	(SocketList[i].status == 7)
	{
		char tempstr2[255];
		char tempstr3[255];
		sprintf(tempstr2,"%s",tempstr);
		
		SocketList[i].Temp = "";
		DeleteCRLF(tempstr2);
		SocketList[i].status = 8;
		SocketList[i].info1 = tempstr2;

		sprintf(tempstr3,"%s",GetReg("Software\\InetServ",tempstr2));
		sprintf(sendstr,"\r\nCurrent value:%s\r\nNew Value: ",tempstr3);
		pSocket->Send (sendstr,strlen(sendstr),0);

		return;

	}

	if 	(SocketList[i].status == 8)
	{
		char tempstr2[255];
		char tempstr3[255];
		sprintf(tempstr2,"%s",tempstr);
		
		SocketList[i].Temp = "";
		DeleteCRLF(tempstr2);
		SocketList[i].status = 2;
		sprintf(tempstr3,"%s",SocketList[i].info1);

		SetReg("Software\\InetServ",tempstr3,tempstr2);
		sprintf(sendstr,"\r\nNew value set\r\n> ");
		pSocket->Send (sendstr,strlen(sendstr),0);


		return;

	}
	
}


void CInetServerDlg::ReadPop3(CClientSocket* pSocket,int i)
{
	char buf[1024];
	CString tempstr = "";
	int nix = pSocket->Receive(&buf, 1024,0);
	buf[nix] = '\0';
	CString tempcstr;
	tempstr = buf;
	
	
	
	
	char sendstr[255];
	
	tempcstr = tempstr;
	SocketList[i].Temp = SocketList[i].Temp + tempstr;
	if (SocketList[i].Temp.GetLength()>240) { SocketList[i].Temp = "";return;}; //buffer to large problem	
	
	
	tempstr =  SocketList[i].Temp;
	if (tempstr.GetAt(tempstr.GetLength()-1) != '\n') return;
	
	
	
	char atstr[255];
	sprintf(atstr,"%i",i);
	AddToLogAll("Received [" + (CString) atstr + "]" + (CString) tempstr);
	
	char tempstrU[255];
	
	sprintf(tempstrU,"%s",tempstr);
	strupr(tempstrU);
	
	if ((tempstrU[0] == 'A') && (tempstrU[1] == 'U') 
		&& (tempstrU[2] == 'T') && (tempstrU[3] == 'H') 
		&& (tempstrU[4] == ' ') )
	{
		sprintf(sendstr,"-ERR %s\r\n",pop3_msg02);
		pSocket->Send (sendstr,strlen(sendstr),0);
		SocketList[i].Temp = "";
		return;
	}
	
	
	if ((tempstrU[0] == 'U') && (tempstrU[1] == 'S') 
		&& (tempstrU[2] == 'E') && (tempstrU[3] == 'R') 
		&& (tempstrU[4] == ' ') )
	{
		
		
		sprintf(sendstr,"+OK %s\r\n",pop3_msg03);
		pSocket->Send (sendstr,strlen(sendstr),0);
		char tempstr2[255];
		
		sprintf(tempstr2,"%s",tempstrU);
		
		for (UINT z = 5; z<= strlen(tempstr2);z++)
		{
			tempstr2[z-5] = tempstr2[z];
		}
		tempstr2[z-5] = '\0';
		
		CString tempcstr;
		if (tempstr2[strlen(tempstr2)-2] == '\n') tempstr2[strlen(tempstr2)-2] = '\0';
		if (tempstr2[strlen(tempstr2)-2] == '\r') tempstr2[strlen(tempstr2)-2] = '\0';
		tempcstr = tempstr2;
		
		SocketList[i].Username= tempcstr;
		SocketList[i].status = 1; 
		SocketList[i].Temp = "";
		return;
	}
	
	
	if ((tempstrU[0] == 'X') && (tempstrU[1] == 'S') 
		&& (tempstrU[2] == 'E') && (tempstrU[3] == 'N') 
		&& (tempstrU[4] == 'D') && (tempstrU[5] == 'E')
		&& (tempstrU[6] == 'R') && (tempstrU[7] == ' '))
	{
		pSocket->Send ("+OK\r\n",5,0);
		SocketList[i].Temp = "";
		return;
	}
	
	
	
	
	
	if (((tempstrU[0] == 'P') && (tempstrU[1] == 'A') 
		&& (tempstrU[2] == 'S') && (tempstrU[3] == 'S') 
		&& (tempstrU[4] == ' ') ) && (SocketList[i].status == 1))
	{
		
		int itsok = -1;
		for (int zz = 0;zz<=MailUserList.GetSize()-1;zz++)
		{
			if (MailUserList[zz].Username == SocketList[i].Username) itsok = zz;
		}
		
		if (itsok == -1)
		{
			char logstr[255];
			sprintf(logstr,"POP3 Login incorrect: User:%s Password:%s from %s",SocketList[i].Username,tempcstr,SocketList[i].ip);
			AddLog(logstr);
			
			sprintf(sendstr,"-ERR %s\r\n",pop3_msg04);
			pSocket->Send (sendstr,strlen(sendstr),0);
			SocketList[i].status = 0;
			return;
		}
		
		char logstr[255];
		char tempstr2[255];
		sprintf(tempstr2,"%s",tempstr);
		
		for (UINT z = 5; z<= strlen(tempstr2);z++)
		{
			tempstr2[z-5] = tempstr2[z];
		}
		tempstr2[z-5] = '\0';
		
		
		CString tempcstr;
		if (tempstr2[strlen(tempstr2)-2] == '\n') tempstr2[strlen(tempstr2)-2] = '\0';
		if (tempstr2[strlen(tempstr2)-2] == '\r') tempstr2[strlen(tempstr2)-2] = '\0';
		
		
		
		tempcstr = CreatePassword(tempstr2);
		
		if (MailUserList[itsok].Password == tempcstr)
		{
			
			sprintf(sendstr,"+OK %s\r\n",pop3_msg05);
			pSocket->Send (sendstr,strlen(sendstr),0);
			SocketList[i].Temp = "";
			SocketList[i].status = 2; 
			sprintf(logstr,"User login: %s from %s",SocketList[i].Username,SocketList[i].ip);
			AddLog(logstr);
		}
		else
		{
			sprintf(sendstr,"-ERR %s\r\n",pop3_msg06);
			pSocket->Send (sendstr,strlen(sendstr),0);
			SocketList[i].Temp = "

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -