private static string CreateEntry(SocketLogger logger, string text, string prefix) { string retVal = ""; if (text.EndsWith("\r\n")) { text = text.Substring(0, text.Length - 2); } string remIP = "xxx.xxx.xxx.xxx"; try { if (logger.RemoteEndPoint != null) { remIP = ((IPEndPoint)logger.RemoteEndPoint).Address.ToString(); } } catch { } string[] lines = text.Replace("\r\n", "\n").Split('\n'); foreach (string line in lines) { retVal += "SessionID: " + logger.SessionID + " RemIP: " + remIP + " " + prefix + " '" + line + "'\r\n"; } return(retVal); }
private string m_UserName = ""; // Holds loggedIn UserName. #endregion Fields #region Constructors /// <summary> /// Default constructor. /// </summary> /// <param name="clientSocket">Referance to socket.</param> /// <param name="server">Referance to FTP server.</param> /// <param name="sessionID">Session ID which is assigned to this session.</param> /// <param name="logWriter">Log writer.</param> public FTP_Session(Socket clientSocket,FTP_Server server,string sessionID,SocketLogger logWriter) { m_pSocket = new BufferedSocket(clientSocket); m_pServer = server; m_SessionID = sessionID; // m_pLogWriter = logWriter; m_SessionStartTime = DateTime.Now; m_LastDataTime = DateTime.Now; m_pSocket.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.NoDelay,1); m_pSocket.Activity += new EventHandler(OnSocketActivity); // Start session proccessing StartSession(); }
private string m_UserName = ""; // Holds loggedIn UserName. #endregion Fields #region Constructors /// <summary> /// Default constructor. /// </summary> /// <param name="clientSocket">Referance to socket.</param> /// <param name="server">Referance to IMAP server.</param> /// <param name="logWriter">Log writer.</param> internal IMAP_Session(Socket clientSocket,IMAP_Server server,SocketLogger logWriter) { m_pSocket = new BufferedSocket(clientSocket); m_pServer = server; m_SessionID = Guid.NewGuid().ToString(); m_SessionStartTime = DateTime.Now; m_LastDataTime = DateTime.Now; if(m_pServer.LogCommands){ m_pSocket.Logger = logWriter; m_pSocket.Logger.SessionID = m_SessionID; } m_pSocket.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.NoDelay,1); m_pSocket.Activity += new EventHandler(OnSocketActivity); // Start session proccessing StartSession(); }
/// <summary> /// Writes socket log to the specified log file. /// </summary> /// <param name="file">Log file.</param> /// <param name="logger">Socket logger.</param> public static void WriteLog(string file,SocketLogger logger) { try{ using(TextDb db = new TextDb('\t')){ db.OpenOrCreate(file); db.AppendComment("Fields: SessionID SessionStartTime RemoteEndPoint AuthenticatedUser LogType LogText"); foreach(SocketLogEntry logEntry in logger.LogEntries){ string logText = logEntry.Text.Replace("\r",""); if(logText.EndsWith("\n")){ logText = logText.Substring(0,logText.Length - 1); } string logType = ""; if(logEntry.Type == SocketLogEntryType.FreeText){ logType = "xxx"; } else if(logEntry.Type == SocketLogEntryType.ReadFromRemoteEP){ logType = "<<<"; } else if(logEntry.Type == SocketLogEntryType.SendToRemoteEP){ logType = ">>>"; } foreach(string logLine in logText.Split('\n')){ db.Append(new string[]{ logger.SessionID, DateTime.Now.ToString(), ConvertEx.ToString(logger.RemoteEndPoint), logger.UserName, logType, logLine }); } } } } catch(Exception x){ Error.DumpError(x,new System.Diagnostics.StackTrace()); } }
/// <summary> /// Converts log entries to string. /// </summary> /// <param name="logger">Socket logger.</param> /// <param name="firstLogPart">Specifies if first log part of multipart log.</param> /// <param name="lastLogPart">Specifies if last log part (logging ended).</param> /// <returns></returns> public static string LogEntriesToString(SocketLogger logger, bool firstLogPart, bool lastLogPart) { string logText = "//----- Sys: 'Session:'" + logger.SessionID + " added " + DateTime.Now + "\r\n"; if (!firstLogPart) { logText = "//----- Sys: 'Session:'" + logger.SessionID + " partial log continues " + DateTime.Now + "\r\n"; } foreach (SocketLogEntry entry in logger.LogEntries) { if (entry.Type == SocketLogEntryType.ReadFromRemoteEP) { logText += CreateEntry(logger, entry.Text, ">>>"); } else if (entry.Type == SocketLogEntryType.SendToRemoteEP) { logText += CreateEntry(logger, entry.Text, "<<<"); } else { logText += CreateEntry(logger, entry.Text, "---"); } } if (lastLogPart) { logText += "//----- Sys: 'Session:'" + logger.SessionID + " removed " + DateTime.Now + "\r\n"; } else { logText += "//----- Sys: 'Session:'" + logger.SessionID + " partial log " + DateTime.Now + "\r\n"; } return(logText); }
private string m_UserName = ""; // Holds loggedIn UserName. #endregion Fields #region Constructors /// <summary> /// Default constructor. /// </summary> /// <param name="clientSocket">Referance to socket.</param> /// <param name="server">Referance to SMTP server.</param> /// <param name="logWriter">Log writer.</param> internal SMTP_Session(Socket clientSocket,SMTP_Server server,SocketLogger logWriter) { m_pSocket = new BufferedSocket(clientSocket); m_pServer = server; m_pMsgStream = new MemoryStream(); m_SessionID = Guid.NewGuid().ToString(); m_BodyType = BodyType.x7_bit; m_Forward_path = new Hashtable(); m_CmdValidator = new SMTP_Cmd_Validator(); m_SessionStart = DateTime.Now; m_LastDataTime = DateTime.Now; if(m_pServer.LogCommands){ m_pSocket.Logger = logWriter; m_pSocket.Logger.SessionID = m_SessionID; } m_pSocket.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.NoDelay,1); m_pSocket.Activity += new EventHandler(OnSocketActivity); // Start session proccessing StartSession(); }
private static string CreateEntry(SocketLogger logger,string text,string prefix) { string retVal = ""; if(text.EndsWith("\r\n")){ text = text.Substring(0,text.Length - 2); } string remIP = "xxx.xxx.xxx.xxx"; try{ if(logger.RemoteEndPoint != null){ remIP = ((IPEndPoint)logger.RemoteEndPoint).Address.ToString(); } } catch{ } string[] lines = text.Replace("\r\n","\n").Split('\n'); foreach(string line in lines){ retVal += "SessionID: " + logger.SessionID + " RemIP: " + remIP + " " + prefix + " '" + line + "'\r\n"; } return retVal; }
/// <summary> /// Converts log entries to string. /// </summary> /// <param name="logger">Socket logger.</param> /// <param name="firstLogPart">Specifies if first log part of multipart log.</param> /// <param name="lastLogPart">Specifies if last log part (logging ended).</param> /// <returns></returns> public static string LogEntriesToString(SocketLogger logger,bool firstLogPart,bool lastLogPart) { string logText = "//----- Sys: 'Session:'" + logger.SessionID + " added " + DateTime.Now + "\r\n"; if(!firstLogPart){ logText = "//----- Sys: 'Session:'" + logger.SessionID + " partial log continues " + DateTime.Now + "\r\n"; } foreach(SocketLogEntry entry in logger.LogEntries){ if(entry.Type == SocketLogEntryType.ReadFromRemoteEP){ logText += CreateEntry(logger,entry.Text,">>>"); } else if(entry.Type == SocketLogEntryType.SendToRemoteEP){ logText += CreateEntry(logger,entry.Text,"<<<"); } else{ logText += CreateEntry(logger,entry.Text,"---"); } } if(lastLogPart){ logText += "//----- Sys: 'Session:'" + logger.SessionID + " removed " + DateTime.Now + "\r\n"; } else{ logText += "//----- Sys: 'Session:'" + logger.SessionID + " partial log " + DateTime.Now + "\r\n"; } return logText; }
/// <summary> /// Default constructor. /// </summary> /// <param name="logger">Socket logger.</param> /// <param name="firstLogPart">Specifies if first log part of multipart log.</param> /// <param name="lastLogPart">Specifies if last log part (logging ended).</param> public Log_EventArgs(SocketLogger logger,bool firstLogPart,bool lastLogPart) { m_pLoggger = logger; m_FirstLogPart = firstLogPart; m_LastLogPart = lastLogPart; }
/// <summary> /// Default constructor. /// </summary> /// <param name="logText"></param> /// <param name="logger"></param> public Log_EventArgs(string logText,SocketLogger logger) { m_LogText = logText; m_pLoggger = logger; }
/// <summary> /// Default constructor. /// </summary> /// <param name="logger">Socket logger.</param> /// <param name="firstLogPart">Specifies if first log part of multipart log.</param> /// <param name="lastLogPart">Specifies if last log part (logging ended).</param> public Log_EventArgs(SocketLogger logger, bool firstLogPart, bool lastLogPart) { m_pLoggger = logger; m_FirstLogPart = firstLogPart; m_LastLogPart = lastLogPart; }