Commit graph

57 commits

Author SHA1 Message Date
sebres
8cb4ae0242 Code review and small optimizations, prepared to provide offset-based time zones for date-detectors (parsing of input-string) 2017-06-09 13:55:30 +02:00
Georges Racinet
e8f2173904 New logtimezone jail option
This new option allows to force the time zone on log lines
that don't bear a time zone indication (GitHub issue #1773), so it behaves
actually with respect to log line contents as a default time zone.

For the time being, only fixed offset timezones (UTC or UTC[+-]hhmm) are
supported, but the implementation is designed to later on treat the case
of logical timezones with DST, e.g., Europe/Paris etc.

In particular, the timezone name gets passed all the way to the strptime
module, and the resulting offset is computed for the given log line, even
though for now, it doesn't actually depend on it.

Also, the DateTemplate subclass gets to choose whether to use it or not.
For instance, it doesn't make sense to apply a time zone offset to
Unix timestamps.

The drawback is to introduce an API change for DateTemplate. I hope it's
internal enough for that not being a problem.
2017-05-23 17:39:37 +02:00
sebres
cf53a834f7 python-3.6 compatibility:
- dynamical string replacement within call of regexp.sub fixed with lambda-replacement (otherwise "sre_constants.error: bad escape \s at position");
- optional arguments (3.6 has more agrs by calling of SMTPServer.process_message);
- implicit convert byte to string, because python3.6 fails on binary data (test_smtp).
2017-02-15 19:05:45 +01:00
sebres
8018796b45 wrong indentation (important code-piece in if log-level only) 2016-11-28 17:17:48 +01:00
sebres
39c343bd06 better reorder templates handling, code coverage increase (a small part of _reorderTemplate was not covered at all) 2016-11-28 15:18:31 +01:00
sebres
a2cf34a64e code review: added endpos to found tuple, just to be safe by unpack 2016-11-17 21:12:23 +01:00
sebres
faee5f1fdc better caching (thereby better performance), better recognition of similar regex 2016-10-17 11:20:30 +02:00
sebres
ae7297e16b more precise date template handling (WARNING: this commit creates possible incompatibilities):
- datedetector rewritten more strict as earlier;
  - default templates can be specified exacter using prefix/suffix syntax (via `datepattern`);
  - more as one date pattern can be specified using option `datepattern` now (new-line separated);
  - some default options like `datepattern` can be specified directly in section `[Definition]`, that avoids contrary usage of unnecessarily `[Init]` section, because of performance (each extra section costs time);
  - option `datepattern` can be specified in jail also (jails without filters);
  - if first group specified, only this will be cut out from search log-line (e. g.: `^date:[({DATE})]` will cut out only datetime match pattern, and leaves `date:[] failure ip...` for searching in filter);
  - faster match and fewer searching of appropriate templates (DateDetector.matchTime calls rarer DateTemplate.matchDate now);
  - standard filters extended with exact prefixed or anchored date templates;

template cache introduced (in opposition to default template cache, holds custom templates cached by pattern for possible common usage of same template/regex);
2016-10-17 11:20:27 +02:00
sebres
bd1eb70c52 speedup template first time selection through pre-sorted template list by template hits 2016-10-17 11:18:35 +02:00
sebres
e735f8f568 default non-unicode and case-sensitive matching (by pattern templates automatically add (?iu) for "ignore case" and "unicode" if expected) 2016-10-17 11:18:32 +02:00
sebres
ab0ac2111c added possibility to specify more precise default date pattern:
- `datepattern = {^LN-BEG}` - only line-begin anchored default patterns
     (matches date only at begin of line, or with max distance up to 2 non-alphanumeric characters from line-begin);
  - `datepattern = {*WD-BEG}` - only word-begin anchored default patterns;
  - `datepattern = ^prefix{DATE}suffix` - exact specified default patterns (using prefix and suffix);
common filter configs gets a more precise, line-begin anchored (datepattern = {^LN-BEG}) resp. custom anchoring default date-patterns;
2016-10-17 11:18:30 +02:00
sebres
f56ff5f48b optimized to better usage of the last time template (parse part of line at the same place as last time, if enclosed in the same boundaries)
thereby follow rule "shortest distance to datetime should win", so possible collision causes search though all templates;
speedup it a little bit (not possible collision if distance <= 1 or if line-begin anchoring, so break search if such template found)
2016-10-17 11:18:27 +02:00
sebres
b9033d004e amend distance collision check - always find template with shortest distance, also first time (test-case extended);
datedetector property template without lock, initially placed start-anchored templates at begin of template list, small optimization of strptime
2016-10-17 11:18:26 +02:00
sebres
75a5440acf extends date detector template with distance (position of match in log-line), to prevent grave collision using (re)ordered template list (e.g. find-spot of wrong date-match inside foreign input, misleading date patterns by ambiguous formats, etc.);
By change of the distance (e.g. another format found), the pattern with smallest distance will be always preferred now.
To speedup (template lookup) resp. minimize of list reorder counts, the distance will be used as divider factor of the template weight by the templates comparison.
2016-10-17 11:18:24 +02:00
sebres
84fe55b99b [temp commit] 2nd try to optimize datedetector/datetemplate functionality (almost ready, needs fine tuning) 2016-10-17 11:18:19 +02:00
sebres
a7d9de8c52 [temp commit] 1st try to optimize datedetector/datetemplate functionality (fix ambiguous resp. misleading date detection if several formats used in log resp. by format switch after restart of some services):
* Misleading date patterns defined more precisely (using extended syntax %E[mdHMS]
  for exact two-digit match)
* `filter.d/freeswitch.conf`
    - Optional prefixes (server, daemon, dual time) if systemd daemon logs used (gh-1548)
    - User part rewritten to accept IPv6 resp. domain after "@" (gh-1548)
2016-10-17 11:16:20 +02:00
sebres
90f9009959 fixes wrong date (invalid format or value) recognition if template available (+ test cases extended) 2016-09-05 16:11:45 +02:00
sebres
dca3db941e merge getTime2 functionality to getTime 2016-03-07 17:28:37 +01:00
sebres
da51fbf9c6 code review and performance optimization:
- default date templates cache + regexp compiling on the fly (if required);
- better usage of shared config over all test cases;
- obsolete test cases removed (simple test of memleak/gc);
- skip some slow test cases in fast mode (setup test, etc.);
2015-12-29 12:49:53 +01:00
sebres
3f2b58e973 datedetector: matchTime, template list etc. rewritten because of performance degradation (without sorting templates now) - in-place reordering using hits and last used time;
todo: rewrite "reGroupDictStrptime" because may be too slow;
2015-12-29 12:49:51 +01:00
sebres
db5ee0842a increase code coverage 2015-12-29 12:49:13 +01:00
sebres
410f9d7c10 filter, datedetector, datetemplate: performance optimizing of combination datedetector.matchTime/getTime2, because early getTime search a template and call template.matchTime again (so the date parsing was really executed twice, now just once);
debug logging optimized;
added info line log "Start Fail2ban ..." after changed logging target;
2015-12-29 12:49:06 +01:00
Yaroslav Halchenko
db1a3f17e1 ENH: new date pattern with year after day (not after entire entry) 2015-09-16 08:56:46 -04:00
Lee Clemens
fdc3172aec Fix PEP8 E302 expected 2 blank lines, found X 2015-07-04 13:47:40 -04:00
Steven Hiscocks
4fc7f1a831 ENH: Tweak naming of getF2BLogger, and ensure consistent use 2014-06-10 20:36:19 +01:00
Steven Hiscocks
e8131475cd ENH: Realign and harmonise log messages with getF2BLogger helper 2014-06-09 22:17:00 +01:00
Steven Hiscocks
41cbbbc248 BF: Remove unused imports and variables.
All highlighted by using pyflakes.
2014-03-16 14:31:34 +00:00
Steven Hiscocks
689ed9d511 DOC: Fix up doc strings styling to comply with numpy doc style 2014-02-27 20:46:48 +00:00
Daniel Black
a7456377b5 ENH: more datetemplate compression 2014-01-28 08:15:48 +11:00
Daniel Black
8b51d0c394 ENH: compress DateDetector templates more 2014-01-27 10:10:06 +11:00
Steven Hiscocks
f2ddb3e3d0 RF: Refactor date detector and date template elements
Changes include to use Python class properties, merge some date
patterns, and change ISO8601 date template to DatePatternRegex class.
2014-01-26 22:03:55 +00:00
Steven Hiscocks
5c16ac3a89 ENH: Full regex for datepattern, utilising modified Python _strptime 2014-01-12 18:59:31 +00:00
Steven Hiscocks
a070284a18 ENH: Change all imports to "." style relative imports 2014-01-04 13:19:09 +00:00
Steven Hiscocks
6f104638cf BF: Ensure all imports for fail2ban modules are not relative 2013-12-30 22:31:06 +00:00
Daniel Black
ea2a13946e TST: more test of filters 2013-12-29 05:29:59 +00:00
Daniel Black
7c0efc8ec8 MRG: merge so far - flushLogs not working yet 2013-12-16 15:08:34 +00:00
Daniel Black
98eacdf333 MRG/BF: merge from master. Fix bugs in iso8601 2013-11-24 16:36:06 +11:00
Daniel Black
47d35c9d80 MRG: 0.8.11 to 0.9
Epnoc of selinux is now true UTC

Merge multiline support and date detection in filter
2013-11-02 15:59:05 +11:00
Daniel Black
a0676cdd1e ENH: add date format 2005-01-23 21:59:59 (%Y-%m-%d %H:%M:%S) so ISO8601 doesnt handle it 2013-09-21 11:44:50 +10:00
Daniel Black
855d802ba8 ENH: more detail in debug messages in date/time detection 2013-09-21 10:31:26 +10:00
Daniel Black
0035c99d07 BF: remove unused function DateDetector.getUnixTime 2013-09-21 10:22:15 +10:00
Daniel Black
33aee14fcc DOC: comment examples of date formats 2013-09-21 09:16:31 +10:00
Daniel Black
d9f0438a8d MRG: remerge in %z and %f datetime format 2013-09-20 21:18:44 +10:00
Steven Hiscocks
72430e805d Merge branch 'datepatterns' into datepatterns-dateregex
Conflicts:
	bin/fail2ban-regex
	fail2ban/client/beautifier.py
	fail2ban/server/datedetector.py
2013-07-17 21:07:09 +01:00
Steven Hiscocks
05fac65a50 BF: fail2ban-regex multiline regex matches no longer in missed lines
Closes #263
Closes #282
2013-07-17 00:08:43 +01:00
Steven Hiscocks
1eea0dcec8 Merge branch 'master' into 0.9
Conflicts:
	ChangeLog
	bin/fail2ban-regex
	bin/fail2ban-testcases
	config/jail.conf
	fail2ban/server/failregex.py
	fail2ban/server/filter.py
	fail2ban/tests/files/logs/lighttpd
	fail2ban/tests/files/logs/mysqld.log
	fail2ban/tests/files/logs/wu-ftpd
	fail2ban/tests/filtertestcase.py
	fail2ban/tests/utils.py
	testcases/files/logs/lighttpd
	testcases/files/logs/lighttpd-auth
	testcases/files/logs/mysqld-auth
	testcases/files/logs/mysqld.log
	testcases/files/logs/wu-ftpd
	testcases/files/logs/wuftpd
2013-07-16 23:16:22 +01:00
Steven Hiscocks
9b8eaa90ef ENH: Reorder date regex and remove duplicate ISO8601 format 2013-06-18 22:19:53 +01:00
Yaroslav Halchenko
f1b6806eb4 Merge branch 'master' into 0.9
* master: (51 commits)
  ENH: Use real (resolving) example.com instead of test.example.com
  DOC: Slight tune ups to ChangeLog -- we must release!
  Changelog entries for the latest merges
  BF: add bash-completion to MANIFEST
  DOC: ChangeLog for default action type change
  ENH: consolidate where blocktype is defined for iptables rules
  BF: default type to unreachable
  ENH: separate out regex and escape a .
  ENH: logs/sshd -- have ":" after [daemon] (other uses are uncommon)
  ENH: logs/sshd -- use example.com as the resolved hostname in sample log lines
  ENH: filter.d/sshd.conf -- allow for trailing "via IP" in logs
  DOC: Drop sudo from bash-completion
  DOC: Added bash-completion script
  ENH: add blocktype to all relevant actions. Also default the rejection to a ICMP reject rather than a drop
  ENH: Removed unused log line
  ENH: logrotate file
  BF: missed MANIFEST include
  BF: missed MANIFEST include
  BF: missed MANIFEST include
  ENH: some form of logrotate based on what distros are doing
  ...

Conflicts:
	ChangeLog
	MANIFEST
	client/actionreader.py
	config/jail.conf
	fail2ban/server/datedetector.py
	fail2ban/tests/datedetectortestcase.py
2013-05-08 13:53:38 -04:00
Steven Hiscocks
20049dd3a0 NF: Generate datetemplates from strptime format strings
Can also set custom time format from fail2ban-client, replacing the
default detectors
2013-05-04 16:59:01 +01:00
Yaroslav Halchenko
b65205d4ad Merge branch 'master' into 0.9
* master:
  ENH: "is None" instead of "== None" + tune ups in headers
  BF: log error only if there were missed config files that couldn't be read
  DOC: missing cinfo tags are ok. Log error for self referencing definitions
  DOC: s/defination/definition/g learn to spell
  Changelog entry for the previous commit and some untabify
  BF: pyinotify backend should also handle IN_MOVED_TO events
  ENH: remove stats of config files and use results of SafeConfigParserWithIncludes.read to facilitate meaningful error messages
  DOC: credits for gh-70 fix
  BF: ensure dates in email are in the C locale. Thanks iGeorgeX
  DOC: ChangeLog for recursive tag substition
  ENH: allow recursive tag substitution in action files.
  DOC: document <br> tag
  DOC: ChangeLog for named-refused entry
  ENH: Account for views in named filter. By Romain Riviere in gentoo bug #259458
  DOC: release documentation and distributor contacts
  DOC: changelog entry for enhanced ssh filter
  BF: Rename mentioning of README to README.md (Fixes #187)
  updated README.md to hyperlink, add travis and coversall
  Moving README into a markup README.md for github's goodnesses

Conflicts:
	DEVELOP
	README.md
	fail2ban/client/configreader.py
	fail2ban/server/datedetector.py
2013-05-02 23:55:26 -04:00