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

📄 inetserverdlg.cpp

📁 一个SMTP邮件发送的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:

void CInetServerDlg::ReadTelnet(CClientSocket* pSocket,int i)
{
	
	char buf[1024];
	char buf2[1024];
	CString tempstr = "";
	int nix = pSocket->Receive(&buf, 1024,0);
	if (buf[0] == -1) return;
	if (buf[0] == 0) return;
	if ((buf[0] == 8) && (nix == 1))
	{
		
		if (SocketList[i].Temp.GetLength()>=1)
		{
			sprintf(buf,"%c %c",8,8);
			pSocket->Send (buf,strlen(buf),0);
			SocketList[i].Temp.GetBufferSetLength(SocketList[i].Temp.GetLength()-1);
		}
		
		return;
	}
	
	
	
	buf[nix] = '\0';
	
		
	//ok, generally we send everything back to to client (w/o lf)
	if (SocketList[i].dontwrite == FALSE)
	{
				sprintf(buf2,"%s",buf);
				DeleteCRLF(buf2);
				pSocket->Send (buf2,strlen(buf2),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;
	
	BOOL flf = FALSE;
	
	if (tempstr.GetAt(tempstr.GetLength()-1) == '\r') flf = TRUE;
	if (tempstr.GetAt(tempstr.GetLength()-2) == '\r') flf = TRUE;
	
	if (flf == FALSE) return;
	
	
	
	if (SocketList[i].status == 0) //user name check
	{
		
		
		SocketList[i].Temp = "";
		char tempstr2[255];
		sprintf(tempstr2,"%s",tempstr);
		DeleteCRLF (tempstr2);
		
		SocketList[i].Username = strupr(tempstr2);
		
		sprintf(sendstr,"\r\npassword:");
		pSocket->Send(sendstr,strlen(sendstr),0);
		SocketList[i].dontwrite = TRUE;
		SocketList[i].status = 1;
		
		
		return;
	}
	
	if (SocketList[i].status == 1) //password
	{
		SocketList[i].dontwrite = FALSE;
		int itsok = -1;
		for (int zz = 0;zz<=MailUserList.GetSize()-1;zz++)
		{
			
			if (MailUserList[zz].Username== SocketList[i].Username) itsok = zz;
		}
		
		
		if (!MatchFlag (SocketList[i].Username,'T'))
		{
			itsok = -1;		
		}
		
		
		if (itsok == -1)
		{
			char logstr[255];
			sprintf(logstr,"Telnet login incorrect: User:%s from %s",SocketList[i].Username,SocketList[i].ip);
			AddLog(logstr);
			
			sprintf(sendstr,"\r\nI dont know you. Bye bye.");
			pSocket->Send (sendstr,strlen(sendstr),0);
			SocketList[i].pSock->ShutDown();
			SocketList[i].pSock->Close();
			
			sprintf(logstr,"Connection closed for %s",SocketList[i].ip);
			AddLog(logstr);
			SocketList.RemoveAt(i);
			mc_list1.DeleteString(i);
			ChngList();
			
			return;
		}
		
		char logstr[255];
		char tempstr2[255];
		sprintf(tempstr2,"%s",tempstr);
		
		
		
		CString tempcstr;
		DeleteCRLF (tempstr2);
		
		
		tempcstr = CreatePassword(tempstr2);
		
		
		if (MailUserList[itsok].Password == tempcstr)
		{
			
			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);
			
			SocketList[i].Temp = "";
			SocketList[i].status = 2; //on it
			sprintf(logstr,"Telnet login: %s from %s",SocketList[i].Username,SocketList[i].ip);
			AddLog(logstr);
		}
		else
		{
			sprintf(sendstr,"\r\nWrong password.\r\nTry again");
			pSocket->Send (sendstr,strlen(sendstr),0);
			SocketList[i].pSock->ShutDown();
			SocketList[i].pSock->Close();
			char logstr[255];
			sprintf(logstr,"Telnet login incorrect (wrong password): %s from %s",SocketList[i].Username,SocketList[i].ip);
			AddLog(logstr);
			sprintf(logstr,"Connection closed for %s",SocketList[i].ip);
			AddLog(logstr);
			SocketList.RemoveAt(i);
			mc_list1.DeleteString(i);
			ChngList();
			
		}
		
		
		return;
		
	}
	
	
	if 	(SocketList[i].status == 2) 
	{
		
		char tempstr2[255];
		sprintf(tempstr2,"%s",tempstr);
		char sendstrh[1024];
		SocketList[i].Temp = "";
		DeleteCRLF(tempstr2);
		if (strcmpi(tempstr2,"userlist") == 0) 
		{
			if (MatchFlag (SocketList[i].Username,'O'))
			{
				
				
				sprintf(sendstrh,"\r\nUsername             Flags          Comment\r\n-----------------------------------------");
				pSocket->Send (sendstrh,strlen(sendstrh),0);
				
				for (int zz = 0;zz<=MailUserList.GetSize()-1;zz++)
				{
					sprintf(sendstrh,"\r\n%-20s %-14s %s",MailUserList[zz].Username,MailUserList[zz].Flags,MailUserList[zz].Comment);
					pSocket->Send (sendstrh,strlen(sendstrh),0);
					
					
				}
				
				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,"version") == 0) 
		{
			sprintf(sendstr,"\r\nInetserv version: %s\r\n",CURVER);
			pSocket->Send (sendstr,strlen(sendstr),0);
			
			sprintf(sendstr,"\r\n> ");
			pSocket->Send (sendstr,strlen(sendstr),0);
			
			return;
		}
		
		if (strcmpi(tempstr2,"help") == 0) 
		{
			FILE *fphelp;
			
			fphelp = fopen("telnet\\help.txt","rt");
			sprintf(sendstr,"\r\n");
			pSocket->Send (sendstr,strlen(sendstr),0);
			if (fphelp == NULL)
			{
				AddLog("Couldn't read telnet help file");
				sprintf(sendstr,"Couldn't read telnet help file\r\n");
				pSocket->Send (sendstr,strlen(sendstr),0);
				
				
				
			}
			else
			{
				while (fgets(sendstr,255,fphelp))
				{
					pSocket->Send (sendstr,strlen(sendstr),0);
					pSocket->Send ("\r",1,0);
				}
				
				fclose(fphelp);
				
			}
			
			sprintf(sendstr,"\r\n> ");
			pSocket->Send (sendstr,strlen(sendstr),0);
			
			return;
		}
		
		
		
		if (strcmpi(tempstr2,"exit") == 0) 
		{
			
			sprintf(sendstrh,"\r\nBye bye!\r\n");
			pSocket->Send (sendstrh,strlen(sendstrh),0);
			SocketList[i].pSock->ShutDown();
			SocketList[i].pSock->Close();
			
			sprintf(sendstr,"Connection closed for %s",SocketList[i].ip);
			AddLog(sendstr);
			SocketList.RemoveAt(i);
			mc_list1.DeleteString(i);
			ChngList();
			return;
		}
		
		if (strcmpi(tempstr2,"listmail") == 0) 
		{
			
			sprintf(sendstrh,"\r\nCurrent mails for user %s\r\n",SocketList[i].Username);
			pSocket->Send (sendstrh,strlen(sendstrh),0);

			char fstr[255];
			sprintf(fstr,"mail\\%s\\*.in",SocketList[i].Username); 
			
			HANDLE hFind;
			char fname[255];
			WIN32_FIND_DATA findData = {0};
			
			hFind = FindFirstFile (fstr, &findData);
			
			if (hFind == INVALID_HANDLE_VALUE)
			{
				sprintf(sendstr,"no mail\r\n> ",pop3_msg10);
				pSocket->Send (sendstr,strlen(sendstr),0);
			}
			else
			{
				int c = 0;
				int length = 0;
				
				int status1 = 0;
				do
				{
					
					if (findData.cFileName[0] != '.')
					{	
						
						c++;
						length = (findData.nFileSizeHigh * MAXDWORD) + findData.nFileSizeLow;
							
							
							char sendstr[255];
							char templine[255];
							char lastsubject[255];
							char lastfrom[255];
							
								
							sprintf(fname,"mail\\%s\\%s",SocketList[i].Username, findData.cFileName);
							
							FILE *fp = fopen(fname,"rt");
							if (fp != NULL)
							{
								while (!feof(fp))
								{
									fgets(templine,255,fp);
									DeleteCRLF(templine);
									if ((templine[0] == 'S') && (templine[1] == 'u') && (templine[2] == 'b')
										&& (templine[3] == 'j') && (templine[4] == 'e') && (templine[5] == 'c')
										&& (templine[6] == 't') && (templine[7] == ':'))
									{
										sprintf(lastsubject,"%s",templine);
									}

									if ((templine[0] == 'F') && (templine[1] == 'r') && (templine[2] == 'o')
										&& (templine[3] == 'm') && (templine[4] == ':'))
									{
										sprintf(lastfrom,"%s",templine);
										
									}
									if (stricmp(templine,"\r\n") == 0) break;
									
								}
								fclose(fp);
									
								sprintf(sendstr,"----------------------------------------\r\nSize: %i\r\n%s\r\n%s\r\n",length,lastsubject,lastfrom);
								pSocket->Send (sendstr,strlen(sendstr),0); 

								
							}
							
						
					}
				}
				while (FindNextFile(hFind, &findData));
				
				
				FindClose (hFind);
				
			}
				sprintf(sendstr,"\r\n> ");
				pSocket->Send (sendstr,strlen(sendstr),0); 
			
			return;
		}
		
		if (strcmpi(tempstr2,"status") == 0) 
		{
			if (MatchFlag (SocketList[i].Username,'O'))
			{
				
				
				sprintf(sendstrh,"\r\n#   Type    Username             IP");
				pSocket->Send (sendstrh,strlen(sendstrh),0);
				sprintf(sendstrh,"\r\n----------------------------------------------------");
				pSocket->Send (sendstrh,strlen(sendstrh),0);
				
				
				for (int x= 0;x<=SocketList.GetSize()-1;x++)
				{
					
					if (SocketList[x].typ == 1) //POP3
					{
						sprintf(sendstrh,"\r\n%-3i POP3    %-20s %s",x,SocketList[x].Username,SocketList[x].ip);
						pSocket->Send (sendstrh,strlen(sendstrh),0);
						
						
						
					}
					
					if (SocketList[x].typ == 2) //SMTP
					{
						sprintf(sendstrh,"\r\n%-3i SMTP    %-20s %s",x,SocketList[x].Username,SocketList[x].ip);
						pSocket->Send (sendstrh,strlen(sendstrh),0);
						
					}
					
					if (SocketList[x].typ == 3) //telnet
					{
						sprintf(sendstrh,"\r\n%-3i Telnet  %-20s %s",x,SocketList[x].Username,SocketList[x].ip);
						pSocket->Send (sendstrh,strlen(sendstrh),0);
						
					}

					if (SocketList[x].typ == 4) //webmail
					{
						sprintf(sendstrh,"\r\n%-3i WebMail  %-20s %s",x,SocketList[x].Username,SocketList[x].ip);
						pSocket->Send (sendstrh,strlen(sendstrh),0);
						
					}

				}
				
				
				
				
				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,"restart") == 0) 
		{
			if (MatchFlag (SocketList[i].Username,'O'))
			{
				sprintf(sendstrh,"\r\nLets hope we run as service!\r\n");
				pSocket->Send (sendstrh,strlen(sendstrh),0);
				PostQuitMessage(0); 
				return;
				
			}
			else
			{
				sprintf(sendstr,"\r\nAccess denied\r\n> ");
				pSocket->Send (sendstr,strlen(sendstr),0);
				return;
				
			}
				

		}
		
		if (strcmpi(tempstr2,"getreg") == 0) 
		{
			if (MatchFlag (SocketList[i].Username,'O'))
			{
				sprintf(sendstrh,"\r\nKeyname:");
				pSocket->Send (sendstrh,strlen(sendstrh),0);
				SocketList[i].status = 6;
				return;
				
			}
			else
			{
				sprintf(sendstr,"\r\nAccess denied\r\n> ");
				pSocket->Send (sendstr,strlen(sendstr),0);
				return;
				
			}
				

		}
		
		if (strcmpi(tempstr2,"setreg") == 0) 
		{
			if (MatchFlag (SocketList[i].Username,'O'))
			{
				sprintf(sendstrh,"\r\nKeyname:");
				pSocket->Send (sendstrh,strlen(sendstrh),0);
				SocketList[i].status = 7;
				return;
				
			}
			else
			{
				sprintf(sendstr,"\r\nAccess denied\r\n> ");
				pSocket->Send (sendstr,strlen(sendstr),0);
				return;
				
			}
				

		}
		
		if (strcmpi(tempstr2,"fwdlist") == 0) 
		{
			if (MatchFlag (SocketList[i].Username,'O'))
			{
				
				
				sprintf(sendstrh,"\r\nFrom                 To");
				pSocket->Send (sendstrh,strlen(sendstrh),0);
				sprintf(sendstrh,"\r\n----------------------------------------------------");
				pSocket->Send (sendstrh,strlen(sendstrh),0);
				
				
				
						BOOL fwd =FALSE;
						FILE *fwdfp;
						
						fwdfp = fopen ("forward.ctl","rt");
						
						if (fwdfp != NULL)
						{
							char fwdstr[255];
							char fwdsrc[255];
							char fwddest[255];
							
							sprintf(fwdstr,"");
							while (!feof(fwdfp))
							{
								

⌨️ 快捷键说明

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