Пример #1
0
        /// <summary>
        /// Gets specified service session logs.
        /// </summary>
        /// <param name="service">Service name. SMTP,POP3,IMAP,RELAY,FETCH.</param>
        /// <param name="limit">Specifies maximum number of log entries to return.</param>
        /// <param name="date">Date what logs to get.</param>
        /// <param name="startTime">Start time filter.</param>
        /// <param name="endTime">End time filter.</param>
        /// <param name="containsText">Log record text filter. Pass null or "" if no text filter.</param>
        /// <returns></returns>
        private LogSession[] GetLogSessions(string service, int limit, DateTime date, DateTime startTime, DateTime endTime, string containsText)
        {
            /* GetLogSessions <virtualServerID> <service> <limit> "<startTime>" "<endTime>" "containsText"
             *    Responses:
             +OK <sizeOfData>
             *      <data>
             *
             *      -ERR <errorText>
             */

            lock (m_pVirtualServer.Server.LockSynchronizer){
                // Call TCP GetLogSessions
                m_pVirtualServer.Server.TcpClient.TcpStream.WriteLine("GetLogSessions " +
                                                                      m_pVirtualServer.VirtualServerID + " " +
                                                                      service + " " +
                                                                      limit.ToString() + " " +
                                                                      TextUtils.QuoteString(startTime.ToUniversalTime().ToString("u")) + " " +
                                                                      TextUtils.QuoteString(endTime.ToUniversalTime().ToString("u")) + " " +
                                                                      TextUtils.QuoteString(containsText)
                                                                      );

                string response = m_pVirtualServer.Server.ReadLine();
                if (!response.ToUpper().StartsWith("+OK"))
                {
                    throw new Exception(response);
                }

                int          sizeOfData = Convert.ToInt32(response.Split(new char[] { ' ' }, 2)[1]);
                MemoryStream ms         = new MemoryStream();
                m_pVirtualServer.Server.TcpClient.TcpStream.ReadFixedCount(ms, sizeOfData);

                // Decompress dataset
                DataSet ds = Utils.DecompressDataSet(ms);

                List <LogSession> retVal = new List <LogSession>();
                if (ds.Tables.Contains("LogSessions"))
                {
                    foreach (DataRow dr in ds.Tables["LogSessions"].Rows)
                    {
                        retVal.Add(new LogSession(
                                       m_pVirtualServer,
                                       service,
                                       dr["SessionID"].ToString(),
                                       Convert.ToDateTime(dr["StartTime"]),
                                       ConvertEx.ToIPEndPoint(dr["RemoteEndPoint"].ToString(), new IPEndPoint(IPAddress.None, 0)),
                                       dr["UserName"].ToString()
                                       ));
                    }
                }

                return(retVal.ToArray());
            }
        }
Пример #2
0
        /// <summary>
        /// Gets server virtual servers and binds them to this, if not binded already.
        /// </summary>
        private void Bind()
        {
            /* GetVirtualServers Responses:
             +OK <sizeOfData>
             *      <data>
             *
             + ERR <errorText>
             */

            lock (m_pParent){
                // Call TCP GetVirtualServers
                m_pParent.TcpClient.TcpStream.WriteLine("GetVirtualServers");

                string response = m_pParent.ReadLine();
                if (!response.ToUpper().StartsWith("+OK"))
                {
                    throw new Exception(response);
                }

                int          sizeOfData = Convert.ToInt32(response.Split(new char[] { ' ' }, 2)[1]);
                MemoryStream ms         = new MemoryStream();
                m_pParent.TcpClient.TcpStream.ReadFixedCount(ms, sizeOfData);

                // Decompress dataset
                DataSet ds = Utils.DecompressDataSet(ms);

                if (ds.Tables.Contains("Servers"))
                {
                    foreach (DataRow dr in ds.Tables["Servers"].Rows)
                    {
                        m_pVirtualServers.Add(new VirtualServer(
                                                  m_pParent,
                                                  this,
                                                  dr["ID"].ToString(),
                                                  ConvertEx.ToBoolean(dr["Enabled"], true),
                                                  dr["Name"].ToString(),
                                                  dr["API_assembly"].ToString(),
                                                  dr["API_class"].ToString(),
                                                  dr["API_initstring"].ToString()
                                                  ));
                    }
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Converts specified value to IP end point. Returns default value specified if parsing fails.
 /// </summary>
 /// <param name="value">Value to convert.</param>
 /// <param name="defultValue">Default value if parsing fails.</param>
 public static IPEndPoint ToIPEndPoint(string value, IPEndPoint defultValue)
 {
     if (value == null)
     {
         return(defultValue);
     }
     else
     {
         try{
             // Port is missing, add 0.
             if (value.IndexOf(':') == -1)
             {
                 value += ":";
             }
             return(new IPEndPoint(IPAddress.Parse(value.Split(':')[0]), ConvertEx.ToInt32(value.Split(':')[1])));
         }
         catch {
             return(defultValue);
         }
     }
 }
        /// <summary>
        /// Gets server users default folders and binds them to this, if not binded already.
        /// </summary>
        private void Bind()
        {
            /* GetUsersDefaultFolders <virtualServerID>
             *    Responses:
             +OK <sizeOfData>
             *      <data>
             *
             + ERR <errorText>
             */

            lock (m_pVirtualServer.Server.LockSynchronizer){
                // Call TCP GetUsersDefaultFolders
                m_pVirtualServer.Server.TcpClient.TcpStream.WriteLine("GetUsersDefaultFolders " + m_pVirtualServer.VirtualServerID);

                string response = m_pVirtualServer.Server.ReadLine();
                if (!response.ToUpper().StartsWith("+OK"))
                {
                    throw new Exception(response);
                }

                int          sizeOfData = Convert.ToInt32(response.Split(new char[] { ' ' }, 2)[1]);
                MemoryStream ms         = new MemoryStream();
                m_pVirtualServer.Server.TcpClient.TcpStream.ReadFixedCount(ms, sizeOfData);

                // Decompress dataset
                DataSet ds = Utils.DecompressDataSet(ms);

                if (ds.Tables.Contains("UsersDefaultFolders"))
                {
                    foreach (DataRow dr in ds.Tables["UsersDefaultFolders"].Rows)
                    {
                        m_pFolders.Add(new UsersDefaultFolder(
                                           this,
                                           dr["FolderName"].ToString(),
                                           ConvertEx.ToBoolean(dr["Permanent"])
                                           ));
                    }
                }
            }
        }