/// <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); } }
public IPBanWindowsEventViewer(IIPBanService service) { this.service = service; service.AddUpdater(this); Update(); }