コード例 #1
0
 /// <summary>
 /// Create a log file scanner
 /// </summary>
 /// <param name="failedLogin">Interface for handling failed logins</param>
 /// <param name="dns">Interface for dns lookup</param>
 /// <param name="source">The source, i.e. SSH or SMTP, etc.</param>
 /// <param name="pathAndMask">File path and mask (i.e. /var/log/auth*.log)</param>
 /// <param name="recursive">Whether to parse all sub directories of path and mask recursively</param>
 /// <param name="regex">Regex to parse file lines to pull out ipaddress and username</param>
 /// <param name="maxFileSizeBytes">Max size of file (in bytes) before it is deleted or 0 for unlimited</param>
 /// <param name="pingIntervalMilliseconds">Ping interval in milliseconds, less than 1 for manual ping required</param>
 public IPBanIPAddressLogFileScanner
 (
     IFailedLogin failedLogin,
     IDnsLookup dns,
     string source,
     string pathAndMask,
     bool recursive,
     string regex,
     long maxFileSizeBytes        = 0,
     int pingIntervalMilliseconds = 0
 ) : base(pathAndMask, recursive, maxFileSizeBytes, pingIntervalMilliseconds)
 {
     failedLogin.ThrowIfNull(nameof(failedLogin));
     dns.ThrowIfNull(nameof(dns));
     Source           = source;
     this.failedLogin = failedLogin;
     this.dns         = dns;
     this.regex       = IPBanConfig.ParseRegex(regex);
 }
コード例 #2
0
        /// <summary>
        /// Create a log file scanner
        /// </summary>
        /// <param name="service">IPBan service</param>
        /// <param name="source">The source, i.e. SSH or SMTP, etc.</param>
        /// <param name="pathAndMask">File path and mask (i.e. /var/log/auth*.log)</param>
        /// <param name="regex">Regex to parse file lines to pull out ipaddress and username</param>
        /// <param name="maxFileSize">Max size of file before it is deleted or 0 for unlimited</param>
        /// <param name="pingIntervalMilliseconds"></param>
        public IPBanLogFileScanner(IIPBanService service, string source, string pathAndMask, string regex, long maxFileSize = 0, int pingIntervalMilliseconds = 10000)
        {
            Source           = source;
            this.service     = service;
            this.maxFileSize = maxFileSize;
            service.AddUpdater(this);
            PathAndMask        = pathAndMask;
            Regex              = IPBanConfig.ParseRegex(regex);
            directoryToWatch   = Path.GetDirectoryName(pathAndMask);
            fileMask           = Path.GetFileName(pathAndMask);
            pingTimer          = new System.Timers.Timer(pingIntervalMilliseconds);
            pingTimer.Elapsed += PingTimerElapsed;
            pingTimer.Start();

            // add initial files
            foreach (string existingFileName in Directory.GetFiles(Path.GetDirectoryName(pathAndMask), Path.GetFileName(pathAndMask), SearchOption.TopDirectoryOnly))
            {
                // start at end of existing files
                AddPingFile(existingFileName, new FileInfo(existingFileName).Length);
            }
        }
コード例 #3
0
        internal void ReadAppSettings()
        {
            try
            {
                string   path         = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
                DateTime lastDateTime = File.GetLastWriteTimeUtc(path);
                if (lastDateTime > lastConfigFileDateTime)
                {
                    lastConfigFileDateTime = lastDateTime;
                    IPBanConfig newConfig = new IPBanConfig();
                    config = newConfig;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogLevel.Error, ex.ToString());

                if (config == null)
                {
                    throw new ApplicationException("Configuration failed to load, make sure to unblock all the files. Right click each file, select properties and then unblock.", ex);
                }
            }
        }
コード例 #4
0
        private void ReadAppSettings()
        {
            try
            {
                string path = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
                DateTime lastDateTime = File.GetLastWriteTimeUtc(path);
                if (lastDateTime > lastConfigFileDateTime)
                {
                    lastConfigFileDateTime = lastDateTime;
                    IPBanConfig newConfig = new IPBanConfig();
                    config = newConfig;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogLevel.Error, ex.ToString());

                if (config == null)
                {
                    throw new ApplicationException("Configuration failed to load, make sure to unblock all the files. Right click each file, select properties and then unblock.", ex);
                }
            }
        }
コード例 #5
0
 private void ReadAppSettings()
 {
     try
     {
         config = new IPBanConfig();
     }
     catch (Exception ex)
     {
         Log.Write(LogLevel.Error, ex.ToString());
     }
 }
コード例 #6
0
        private void ReadAppSettings()
        {
            try
            {
                config = new IPBanConfig();
            }
            catch (Exception ex)
            {
                Log.Write(LogLevel.Error, ex.ToString());

                if (config == null)
                {
                    throw new ApplicationException("Configuration failed to load, make sure to unblock all the files. Right click each file, select properties and then unblock.", ex);
                }
            }
        }
コード例 #7
0
 private void ReadAppSettings()
 {
     config = new IPBanConfig();
 }