Beispiel #1
0
        public void UpdateLog(object obj)
        {
            FtpLogEntry entry = obj as FtpLogEntry;

            if (entry == null)
            {
                return;
            }
            _entryBuilder.Append(entry.Date.ToLongTimeString()).Append("\t")
            .Append(entry.CIP ?? "-").Append("\t")
            .Append(entry.CSUsername ?? "-").Append("\t")
            .Append(entry.CSMethod ?? "-").Append(" ")
            .Append(entry.CSArgs ?? "-").Append("\t")
            .Append(entry.CSBytes ?? "-").Append("\t")
            .Append(entry.SCStatus ?? "-").Append("\t")
            .Append(entry.SCBytes ?? "-").Append("\t")
            .Append(entry.Info ?? "");
            if (Active)
            {
                Core.LogTextBox.Invoke(new MethodInvoker(() =>
                {
                    Core.LogTextBox.AppendText(_entryBuilder.ToString());
                    Core.LogTextBox.AppendText(Environment.NewLine);
                }));
            }
            else
            {
                LogBuilder.Append(_entryBuilder.ToString()).AppendLine();
            }
            _entryBuilder.Clear();
        }
Beispiel #2
0
    // Implement custom actions by using the Log() method.
    void IFtpLogProvider.Log(FtpLogEntry loggingParameters)
    {
        // Test if the control channel was opened or the USER command was sent.
        if ((String.Compare(loggingParameters.Command,
                            "ControlChannelOpened", true) == 0) ||
            (String.Compare(loggingParameters.Command,
                            "USER", true) == 0))
        {
            // Check if the IP address is banned.
            if (IsAddressBanned(loggingParameters.RemoteIPAddress) == true)
            {
                // If the IP is banned, flag the session.
                FlagSession(loggingParameters.SessionId);
                return;
            }
        }
        // Test if the PASS command was sent.
        if (String.Compare(loggingParameters.Command,
                           "PASS", true) == 0)
        {
            // Check for password failures (230 is a success).
            if (loggingParameters.FtpStatus != 230)
            {
                // Periodic garbage collection - remove authentication
                // failures that are older than the flood timeout.
                GarbageCollection(false);

                // Test if the existing number of failures exceeds the maximum logon attempts.
                if (GetRecordCountByCriteria("[Failures]",
                                             "[IPAddress]='" + loggingParameters.RemoteIPAddress +
                                             "'") < _logonAttempts)
                {
                    // Add the failure to the list of failures.
                    InsertDataIntoTable("[Failures]",
                                        "[IPAddress],[FailureDateTime]",
                                        "'" + loggingParameters.RemoteIPAddress +
                                        "','" + DateTime.Now.ToString() + "'");
                }
                else
                {
                    // Ban the IP address if authentication has failed
                    // from that IP more than the defined number of failures.
                    BanAddress(loggingParameters.RemoteIPAddress);
                    FlagSession(loggingParameters.SessionId);
                }
                return;
            }
        }
        // Test if the control channel was closed.
        if (String.Compare(loggingParameters.Command,
                           "ControlChannelClosed", true) == 0)
        {
            // Session-based garbage collection - remove the
            // current session from the list of flagged sessions.
            _flaggedSessions.Remove(loggingParameters.SessionId);
            return;
        }
    }
Beispiel #3
0
 // Implement the logging method.
 void IFtpLogProvider.Log(FtpLogEntry loggingParameters)
 {
     // Test for a file upload operation.
     if (loggingParameters.Command == "STOR")
     {
         // Create an SMTP message.
         SmtpClient smtpClient =
             new SmtpClient(smtpServerName, smtpServerPort);
         MailAddress mailFromAddress =
             new MailAddress(smtpFromAddress);
         MailAddress mailToAddress = new
                                     MailAddress(smtpToAddress);
         using (MailMessage mailMessage =
                    new MailMessage(mailFromAddress, mailToAddress))
         {
             // Format the SMTP message as UTF8.
             mailMessage.BodyEncoding = Encoding.UTF8;
             // Test for a successful operation.
             if (loggingParameters.FtpStatus == 226)
             {
                 // Create a customized message for a successful operation.
                 mailMessage.Subject = "File Uploaded Successfully";
                 mailMessage.Body    = loggingParameters.UserName +
                                       " successfully uploaded a file to " +
                                       loggingParameters.FullPath;
             }
             else
             {
                 // Create a customized message for a failed operation.
                 mailMessage.Subject = "File Operation Status";
                 mailMessage.Body    =
                     "The FTP service returned a status of " +
                     loggingParameters.FtpStatus + "." +
                     loggingParameters.FtpSubStatus +
                     " when " + loggingParameters.UserName +
                     " attempted to upload a file to " +
                     loggingParameters.FullPath;
             }
             try
             {
                 // Send the email message.
                 smtpClient.Send(mailMessage);
             }
             catch (SmtpException ex)
             {
                 // Send an exception message to the debug
                 // channel if the email fails to send.
                 Debug.WriteLine(ex.Message.ToString());
             }
         }
     }
 }
Beispiel #4
0
 public void Log(FtpLogEntry logEntry)
 {
     // Test if the control channel was opened.
     if (logEntry.Command.Equals(
             "ControlChannelOpened",
             StringComparison.InvariantCultureIgnoreCase))
     {
         // Add the current session to the dictionary.
         _sessionList.Add(logEntry.SessionId, 0);
     }
     // Test if the control channel was closed.
     if (logEntry.Command.Equals(
             "ControlChannelClosed",
             StringComparison.InvariantCultureIgnoreCase))
     {
         // Remove the current session from the dictionary.
         _sessionList.Remove(logEntry.SessionId);
     }
 }
Beispiel #5
0
 void IFtpLogProvider.Log(FtpLogEntry loggingParameters)
 {
     // Note: You would add your own custom logic here.
     // Open the log file for output.
     using (StreamWriter sw =
                new StreamWriter(@"C:\logfiles\myftpsite\myftplog.log", true))
     {
         // Retrieve the current date and time for the log entry.
         DateTime dt = DateTime.Now;
         // Retrieve the user name.
         string un = loggingParameters.UserName;
         // Write the log entry to the log file.
         sw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}",
                      dt.ToShortDateString(),
                      dt.ToLongTimeString(),
                      loggingParameters.RemoteIPAddress,
                      (un.Length == 0) ? "-" : un,
                      loggingParameters.Command,
                      loggingParameters.SessionId);
     }
 }
 public SqlFtpLogEntry(FtpLogEntry logEntry)
 {
     Date                = DateTime.UtcNow;
     Time                = DateTime.UtcNow.TimeOfDay;
     ServerName          = Environment.MachineName;
     SessionID           = logEntry.SessionId.ParseToGuid();
     UserName            = logEntry.UserName.NullIfEmpty();
     RemoteIPAddress     = logEntry.RemoteIPAddress ?? string.Empty;
     RemoteIPPort        = logEntry.RemoteIPPort;
     LocalIPAddress      = logEntry.LocalIPAddress ?? string.Empty;
     LocalIPPort         = logEntry.LocalIPPort;
     Information         = logEntry.Information.NullIfEmpty();
     HRStatus            = logEntry.HRStatus;
     SiteName            = logEntry.SiteName ?? string.Empty;
     HostName            = logEntry.HostName.NullIfEmpty();
     FtpStatus           = logEntry.FtpStatus;
     FtpSubStatus        = logEntry.FtpSubStatus;
     Command             = logEntry.Command ?? string.Empty;
     CommandParameters   = logEntry.CommandParameters.NullIfEmpty();
     ElapsedMilliseconds = logEntry.ElapsedMilliseconds;
     BytesSent           = logEntry.BytesSent;
     BytesReceived       = logEntry.BytesReceived;
     FullPath            = logEntry.FullPath.NullIfEmpty();
 }
Beispiel #7
0
 public void Log(FtpLogEntry logEntry)
 {
     _bulkPushService.Add(new SqlFtpLogEntry(logEntry));
 }
Beispiel #8
0
 void IFtpLogProvider.Log(FtpLogEntry loggingParameters)
 {