HEX
Server: LiteSpeed
System: Linux 112.webhostingindonesia.co.id 5.14.0-570.62.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 10:10:59 EST 2025 x86_64
User: iyfwylsv (10313)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/fail2ban/client/__pycache__/fail2banregex.cpython-39.opt-2.pyc
a

E���V�ʎ�@s�dZdZdZdZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddl
ZddlZddlmZmZddlmZmZmZzdd	lmZWney�dZYn0dd
lmZmZddlmZmZmZdd
lm Z m!Z!m"Z"ddl#m$Z$m%Z%ddl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,e*d�Z-d0dd�Z.dd�Z/d1dd�Z0d2dd�Z1dd�Z2dd�Z3d d!�Z4Gd"d#�d#e�Z5d$d%�Z6Gd&d'�d'e7�Z8Gd(d)�d)e7�Z9Gd*d+�d+e7�Z:d,d-�Z;d.d/�Z<dS)3z�
Fail2Ban  reads log file that contains password failure report
and bans the corresponding IP addresses using firewall rules.

This tools can test regular expressions for "fail2ban".
zFail2Ban DevelopersaICopyright (c) 2004-2008 Cyril Jaquier, 2008- Fail2Ban Contributors
Copyright of modifications held by their respective authors.
Licensed under the GNU General Public License v2 (GPL).

Written by Cyril Jaquier <cyril.jaquier@fail2ban.org>.
Many contributions by Yaroslav O. Halchenko, Steven Hiscocks, Sergey G. Brester (sebres).ZGPL�N)�OptionParser�Option)�
NoOptionError�NoSectionError�MissingSectionHeaderError�)�
FilterSystemd)�version�normVersion�)�FilterReader�
JailReader�NoJailError)�Filter�
FileContainer�MyTime)�Regex�RegexException)�str2LogLevel�getVerbosityFormat�FormatterWithTraceBack�	getLogger�extractOptions�
PREFER_ENCZfail2banF�yescCs2tj||d�|dd�}|r"d|d<dtj�|�S)N)�useDnsZpython)�re�strZflavor�m�flagszhttps://www.debuggex.com/?)rZ_resolveHostTag�urllib�parseZ	urlencode)Zsample�regex�	multiliner�args�r%�A/usr/lib/python3.9/site-packages/fail2ban/client/fail2banregex.py�debuggexURL?s�r'cCst|�dS�N)�print�r$r%r%r&�outputHsr+�5cCs$t|�|kr |d|d�dS|S)zReturn shortened string
	N��...)�len)�s�lr%r%r&�shortstrKsr2cCs<t|�sdS|rd|}nd}t|dd�|�d�dS)Nz|- %s
�z|  z
|  z
`-)r/r+�join)r1�headerr0r%r%r&�pprint_listRs
r6ccs<z|��}Wnty"YqYn0|s*q8|�|�VqdSr()Zget_next�OSErrorZformatJournalEntry)�flt�	myjournal�entryr%r%r&�journal_lines_gen[s
r;cGstt��t�d�dS�Nr)r+r
�sys�exitr*r%r%r&�dumpNormVersiones
r?cCsdtjdS)Nz(%s [OPTIONS] <LOG> <REGEX> [IGNOREREGEX]r)r=�argvr%r%r%r&�<lambda>i�rAc@seZdZdd�ZdS)�
_f2bOptParsercOs@d|_dt�dtdtj|g|�Ri|��dtdS)z, Overwritten format helper with full ussage.r3zUsage: �
a�
LOG:
  string                a string representing a log line
  filename              path to a log file (/var/log/auth.log)
  systemd-journal       search systemd journal (systemd-python required),
                        optionally with backend parameters, see `man jail.conf`
                        for usage and examples (systemd-journal[journalflags=1]).

REGEX:
  string                a string representing a 'failregex'
  filter                name of filter, optionally with options (sshd[mode=aggressive])
  filename              path to a filter file (filter.d/sshd.conf)

IGNOREREGEX:
  string                a string representing an 'ignoreregex'
  filename              path to a filter file (filter.d/sshd.conf)

z>

Report bugs to https://github.com/fail2ban/fail2ban/issues

)�usage�__doc__r�format_help�
__copyright__)�selfr$�kwargsr%r%r&rGls����z_f2bOptParser.format_helpN)�__name__�
__module__�__qualname__rGr%r%r%r&rCksrCcCsftt�dtd�}|�tddddd�tdd	d
d�tdd
dddd�tddtdd�tdddddd�tddddd�tddtddd�td d!d"d�td#d$d%d&d'd(�td)d*td+d,�td-d.d/d0dd1d2�td3dd0td4d5�td6d7dd8d9�td:d;dd<d9�td=d>d?d@dAd2�tdBdCddDddEd2�tdFddGd9�tdHddId9�tdJddKd9�tdLddMd9�tdNddOd9�tdPdQddRd9�tdSddTd9�g�|S)UNz%prog )rEr	z-cz--configz
/etc/fail2banzset alternate config directory)�default�helpz-dz
--datepatternz+set custom pattern used to match date/times)rOz
--timezonez--TZZstorez)set time-zone used by convert time format)�actionrNrOz-ez
--encodingz%File encoding. Default: system localez-rz--raw�
store_trueFzRaw hosts, don't resolve dnsz--usednszpDNS specified replacement of tags <HOST> in regexp ('yes' - matches all form of hosts, 'no' - IP addresses only)z-Lz
--maxlinesrzmaxlines for multi-line regex.)�typerNrOz-mz--journalmatchzGjournalctl style matches overriding filter file. "systemd-journal" onlyz-lz--log-level�	log_level�criticalz(Log level for the Fail2Ban logger to use)�destrNrOz-V�callbackz,get version in machine-readable short format)rPrVrOz-vz	--verbose�count�verbosezIncrease verbosity)rPrUrNrOz--verbosityz'Set numerical level of verbosity (0..4))rPrUrRrOz--verbose-datez--VDz%Verbose date patterns/regex in output)rPrOz-Dz
--debuggexz-Produce debuggex.com urls for debugging therez--no-check-allZstore_false�
checkAllRegexTzDisable check for all regex'sz-oz--out�outzaSet token to print failure information only (row, id, ip, msg, host, ip4, ip6, dns, matches, ...)z--print-no-missedzDo not print any missed linesz--print-no-ignoredzDo not print any ignored linesz--print-all-matchedzPrint all matched linesz--print-all-missedz*Print all missed lines, no matter how manyz--print-all-ignoredz+Print all ignored lines, no matter how manyz-tz--log-tracebackz.Enrich log-messages with compressed tracebacksz--full-tracebackzBEither to make the tracebacks full, not compressed (as by default))rCrEr	Zadd_optionsrr�intr?)�pr%r%r&�get_opt_parser�s����
��
��
����
�
���
����������6r]c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�	RegexStatcCsd|_||_t�|_dSr<)�_stats�
_failregex�list�_ipList)rI�	failregexr%r%r&�__init__�szRegexStat.__init__cCsd|j|j|j|jfS)Nz%s(%r) %d failed: %s)�	__class__r`r_rb�rIr%r%r&�__str__�s�zRegexStat.__str__cCs|jd7_dS�Nr�r_rfr%r%r&�inc�sz
RegexStat.inccCs|jSr(rirfr%r%r&�getStats�szRegexStat.getStatscCs|jSr()r`rfr%r%r&�getFailRegex�szRegexStat.getFailRegexcCs|j�|�dSr()rb�append)rI�valuer%r%r&�appendIP�szRegexStat.appendIPcCs|jSr()rbrfr%r%r&�	getIPList�szRegexStat.getIPListN)
rKrLrMrdrgrjrkrlrorpr%r%r%r&r^�sr^c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�	LineStatsz(Just a convenience container for stats
	cCsFd|_|_g|_d|_g|_d|_g|_|jrBg|_g|_	g|_
dSr<)�tested�matched�
matched_lines�missed�missed_lines�ignored�
ignored_linesZdebuggex�matched_lines_timeextracted�missed_lines_timeextracted�ignored_lines_timeextracted)rI�optsr%r%r&rd�szLineStats.__init__cCsd|S)NzM%(tested)d lines, %(ignored)d ignored, %(matched)d matched, %(missed)d missedr%rfr%r%r&rg�szLineStats.__str__cCst||�rt||�SdS)Nr3)�hasattr�getattr)rI�keyr%r%r&�__getitem__�szLineStats.__getitem__N)rKrLrMrFrdrgr�r%r%r%r&rq�srqc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zd dd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)!�
Fail2banRegexcCsN|j�tdd�|j��D���||_d|_d|_d|_t�|_t	d�|_
d|_t�|_
t�|_t�|_d|_t|�|_|jr�|�|j�nd|_|jdur�|�t�|j��|jr�|j
�|j�d|j
_t�d�ddlm }|�|j!r�|�"|j!�|j#�r|j
�$|j#�|j%|j
_&|j'�o&|j(|j
_'t)|j(�|j
_*|j+|j
_,d|_-dS)	Ncss|]\}}d||fVqdS)�_Nr%)�.0�o�vr%r%r&�	<genexpr>�rBz)Fail2banRegex.__init__.<locals>.<genexpr>Fr�r)�
_updateTimeRE�auto).�__dict__�update�dict�items�_opts�
_maxlines_set�_datepattern_set�
_journalmatch�share_configr�_filter�_prefREMatchedra�
_prefREGroups�_ignoreregexr`�
_time_elapsedrq�_line_stats�maxlines�setMaxLines�	_maxlines�journalmatch�setJournalMatch�shlex�split�timezoneZsetLogTimeZoneZ
checkFindTimerZsetAlternateNowZserver.strptimer��datepattern�setDatePattern�usednsZ	setUseDns�rawZ
returnRawHostrYrZ�boolZ
ignorePending�_onIgnoreRegexZ
onIgnoreRegex�_backend)rIr|r�r%r%r&rd�sB 





zFail2banRegex.__init__cCs|jjst|�dSr()r�rZr+�rI�liner%r%r&r+!szFail2banRegex.outputcCs|�|jd�S)N�ignore)�encode�	_encodingr�r%r%r&�encode_line$szFail2banRegex.encode_linecCs@|js<|j�|�d|_|dur<|�d||j��df�dS)NTzUse      datepattern : %s : %sr)r�r�r�r+ZgetDatePattern)rI�patternr%r%r&r�'s�zFail2banRegex.setDatePatterncCs4|js0|j�t|��d|_|�d|j���dS)NTzUse         maxlines : %d)r�r�r�r[r+�getMaxLines�rIr�r%r%r&r�/szFail2banRegex.setMaxLinescCs
||_dSr()r�r�r%r%r&r�5szFail2banRegex.setJournalMatchc	s�i}���}t�t�r$�fdd�}n�jr8�fdd�}ndd�}ddgt|���D]8}z ||vrj||n||�||<WqTty�YqT0qT|�d|�dS)Ncs��d|�S�NZ
Definition)�get��k��readerr%r&rA<rBz0Fail2banRegex._dumpRealOptions.<locals>.<lambda>cs�j�d|�Sr�)�filterr�r�r�r%r&rA>rBcSsdSr(r%r�r%r%r&rA@rBZlogtyper�zReal  filter options : %r)ZgetCombined�
isinstancerr�ra�keysrr+)rIr��fltOptZrealoptsZcomboptsZ_get_optr�r%r�r&�_dumpRealOptions8s
 zFail2banRegex._dumpRealOptionscCs>|dvsJ�|d}|jj}|}d}i}d}|dk�r�t�d|��r��zt|�\}}t�d|�s�zt|d|j|d�}|��Wnty�d}Yn0d|d	d�vr�|f}	n||d
|df}	|	D]�}t	j
�|�dkr�t	j
�||�}nJd
|v�r&t	j
�
|�dk�rt	j
�||�}nt	j
�|d|�}nt	j
�|�}t	j
�|��rF�qLd}q�WnTt�y�}
z:tdt|
�f�td|f�|j�r�|
�WYd}
~
dSd}
~
00d}|�rD|�dd|f�|�r�|�d|�|�s�i}|j|d<|j|d�}|�std|f�dS|jdk�s(t��tjk�r4|�||�|jdd�}�n�|du�r�||jjk�s�t	j
�
|�dk�s�d|d	d�v�r�d
|v�r�t	j
�
|�dk�r�t	j
�|�}t	j
�t	j
�
|��d}|�dd||f�n0|�dd|f�d}t	j
�|��st	j
�|�}|�r|�d|�t|d||j|d�}
d}z*|du�rH|
��}n|
�d�|
� �}WnDt�y�}
z*td t|
�f�|j�r�|
�WYd}
~
n
d}
~
00|�s�td!|�dS|
�!|j�|
�d�|jdk�s�t��tjk�r�|�|
|�|
��}|�r�i}|D�]�}|dd"k�r*|d#}n |dd$k�r|d#d�}n�q�z,|d%d&k�rt|D]}||j"_#�q`�n|d%d'k�r�|�$d�}|�s�t%�}|d<|D]}|�&t'|���q�n�|d%d(k�r|�$d)�}|�s�t%�}|d)<|D]}|�&t'|���q�nr|d%d*k�r*|D]}|�(|��qnL|d%d+k�rP|D]}|�)|��q<n&|d%d,k�rv|jj*du�rv|�+|�WnBt,�y�}
z(td-|d%|||
f�WYd}
~
dSd}
~
00�qn$|�d.|t-|�f�|t'|�gi}|�.�D]J\}}|d}t/|d/||�|D]"}t0|j"d0|�1��|�2���q�q�dS)1N)�failr�r"r�z"(?ms)^/{0,3}[\w/_\-.]+(?:\[.*\])?$z(?ms)(?:/|\.(?:conf|local)$)T)Zforce_enabler��basedir�.i����z.confz.localzfilter.d�/z'ERROR: Wrong filter name or options: %sz       while parsing: %sFzUse %11s jail : %sr3zUse jail/flt options : %r�backend)ZaddOptsz ERROR: Failed to get jail for %rr)Zallow_no_filesrzUse %11s file : %s, basedir: %sr�zUse %11s file : %szUse   filter options : %rzfail2ban-regex-jail)r�r�zWrong config file: %szERROR: failed to load filter %sz	multi-setr-�setrZ	prefregexZaddfailregexZaddignoreregexr�r�r�Zaddjournalmatchz1ERROR: Invalid value for %s (%r) read from %s: %szUse %11s line : %sr�z
add%sRegex)3r�Zconfigr�searchrr
r��readr�os�path�dirnamer4�basename�isfile�	Exceptionr+r�_verboser�Z
getOptions�logSys�getEffectiveLevel�logging�DEBUGr��convert�splitext�isabs�abspathrZ
setBaseDirZreadexplicitZapplyAutoOptionsr��	prefRegexr�rarmr^r�r�r�r��
ValueErrorr2r��setattrr~�titlerl)rIrnZ	regextyper"r�ZfltNameZfltFiler�ZjailZtryNames�eZreadercommands�retr�Zregex_values�optZoptvalZstorr%r%r&�	readRegexKs
�





����


"




� 
��zFail2banRegex.readRegexcCsd|_|j|��dS)NT)�_lineIgnoredr�rj)rI�idxZignoreRegexr%r%r&r��szFail2banRegex._onIgnoreRegexNcCs�|jj}|j��dkr"|dd�}t|�|j��k}d}|_�z|j�||�}g}g}|D]\}	|jjs�|	�t|�dk�|j	|	d}
|
�
�|
�|	�|	d�d�s�|�|	�q\d}q\|jjr�d|dfWS|jj
�rB|jj
}|���rB|jd7_|j�rBt|j�|jk�r$|j�|���nt|j�|jk�rB|j�d�Wn4t�yx}ztd|�WYd}~d	Sd}~00|j��dk�rt|t|�d�D]�}
|
|jjv�r�zR|jj�|jj�d
�|
���|j�r�|jj�|jj�d
�|
ddd����Wnt�yYn0|j�rP|j�s:|jj �d
�|
��n|�|
d|
d�|jj!d7_!|jj"d8_"�q�|�r�|�|j�#��d�|�}|||�p�|jfS)
NrFrr-ZnofailTr.�	ERROR: %s)NrNr3rrD)$r�Z_Filter__lineBufferr�r/r�ZprocessLiner�rZrmr`rjror�r�Z
hasMatchedr�r�r�r�Z	getGroupsrr+r[r�rv�pop�indexr4�	_debuggexrzr��_print_all_matchedrtrsruZ
processedLine)rIr��dateZ
orgLineBufferZ
fullBuffer�
is_ignored�found�linesr��matchr"�prer�ZbufLiner%r%r&�	testRegex�sr



���
zFail2banRegex.testRegexcs�|jj��dvrdd�}n|�dkr,dd�}nj�dkr>dd�}nX�dkrPd	d�}nFd
�vrf�fdd�}n0dd
lm�m�m�dd�������fdd�}|S)zOPrepares output- and fetch-function corresponding given '--out' option (format))�idZfidcSs|D]}t|d�qdSrh)r+�r��rr%r%r&�_out/sz+Fail2banRegex._prepaireOutput.<locals>._out�ipcSs&|D]}t|d�d|d��qdS)Nr-r�r�r+r�r�r%r%r&r�3s�msgcSsH|D]>}|d�d�D]*}t|t�s8d�dd�|D��}t|�qqdS)Nr-�matchesr3css|]
}|VqdSr(r%�r�r�r%r%r&r�;rB�>Fail2banRegex._prepaireOutput.<locals>._out.<locals>.<genexpr>)r�r�rr4r+r�r%r%r&r�7s

�rowc	Ss>|D]4}td|d|dtdd�|d��D��f�qdS)Nz
[%r,	%r,	%r],rrcss"|]\}}|dkr||fVqdS)r�Nr%)r�r�r�r%r%r&r�@rBr�r-)r+r�r�r�r%r%r&r�>s�<cs |D]}t|d����qdS)Nr-r�r�)�ofmtr%r&r�Bsr)�Actions�
CommandAction�	BanTicketcSs|dvr|�dd�S|S)N)r��z\x00)�replace)�tr�r%r%r&�_escOutGsz.Fail2banRegex._prepaireOutput.<locals>._escOutcs�g}ddi�|D]n���d�d�dd�}��|�}��fdd�}||d	<�j�|�d
�}�drv|��|f�qt|�q|D]N\�}�d�d�D]6�t�t�s�d�d
d��D���|�d���t��q�q�dS)N�NLrrrr-)�time�datacs8�ds(t�d�dg��dkr(|dSd�d<dSdS)Nr�r-r�r�msg)r/r�rf�r�Zwrapr%r&�_get_msgSs z=Fail2banRegex._prepaireOutput.<locals>._out.<locals>._get_msgr�)Z	escapeValr�r3css|]
}|VqdSr(r%r�r%r%r&r�drBr�r)	Z
ActionInfoZreplaceDynamicTagsrmr+r�r�rr4r�)r�ZrowsZticketZaInforr��r�r�r�r�r�rr&r�Ls$


)r�rZZserver.actionsr�r�r�)rIr�r%rr&�_prepaireOutput+s



zFail2banRegex._prepaireOutputcCs�t��}|jjr|��}|D�]�}t|t�rV|�|d|d�\}}}d�|d�}n*|�d�}|�	d�s|spq|�|�\}}}|jjr�t
|�dkr|s||�q|r�|jjd7_|j
s�|js�|jj|jdkr�|jj�|�|jr�|jj�|�n�t
|�dk�rD|jjd7_|j�r�|jj�|�|j�r�|jj�|�nX|jjd7_|j�s�|j�sx|jj|jdk�r�|jj�|�|j�r�|jj�|�|jjd7_qt��||_dS)Nrrr3z
�#)r�r�rZrr��tupler�r4�rstrip�
startswithr/r�rw�_print_no_ignoredZ_print_all_ignoredr�rxrmr�r{rsr�rtryru�_print_no_missedZ_print_all_missedrvrzrrr�)rI�
test_linesZt0rZr�Zline_datetimestrippedr�r�r%r%r&�processjsB


$zFail2banRegex.processc	sN�j}|j|j|j|jks"J�||}||d}�j��dk�|�rJd|��f}�j�r|dksp|dkrx�j	}n�j
}||d}|�jks�t�d|�r�gg}||fD]��fdd	�|D�}q���fd
d	�|D�}t
dd	�|D�|�ntd|||f�nD|�jk�s"t�d|��r8t
d
d	�|D�|�ntd|||f�dS)NZ_linesrz%s line(s):rursZ_lines_timeextractedZ_print_all_cs g|]}�D]}||g�qqSr%r%)r��x�y)�argr%r&�
<listcomp>�rBz,Fail2banRegex.printLines.<locals>.<listcomp>csLg|]D}|dd|d��dt��|d�|d����jj��qS)rz | rz |  )rlr'r�r�r�)r��a)r#rIr%r&r�s���cSsg|]}|���qSr%�r�r�r
r%r%r&r�rBz?%s too many to print.  Use --print-all-%s to print all %d linescSsg|]}|���qSr%rrr%r%r&r�rB)r�rurrrsrwr�r��
capitalizer�r`r�r�r~r6r+)	rIZltypeZlstatsr�r1r5Z	regexlistZans�br%)rr#rIr&�
printLines�s8���zFail2banRegex.printLinesc
s��jjrdStd�td�td��fdd�}�jjr��jj}|��g}�jrl�jD]}|�d|f�qVtdd	�j	f�t
|�|d
�j�}|d�j�}�jj
du�r4td�g}�jj
jD]f}�js�|jr�|�d
|j|jf��jr�|�d|j|jjt|dd�f�|�dt|dd�f�q�t
|d�td�j��jdu�r\td�j�td��j�rv��d��j�s���d��j�s���d�dS)NTr3ZResultsz=======c
	s�dg}}t|�D]�\}}|��}||7}|s4�jrP|�d|d||��f��jrt|���r|��D]B}t�|d�}t�	d|�}	|�d|d|	|dr�dp�d	f�qjqt
d
||f�t|d�|S)Nrz%2d) [%d] %srrz%a %b %d %H:%M:%S %Yz    %s  %s%s���z (multiple regex matched)r3�
%s: %d totalz" #) [# of hits] regular expression)�	enumeraterkr�rmrlr/rpr��	localtime�strftimer+r6)
r�Zfailregexes�totalrZZcntrcr�r�Z	timeTupleZ
timeStringrfr%r&�print_failregexes�s(

��
z3Fail2banRegex.printStats.<locals>.print_failregexesz    %srZ	PrefregexZ	FailregexZIgnoreregexz
Date template hits:z[%d] %sz&    # weight: %.3f (%.3f), pattern: %sr�z    # regex:   %sr"z[# of hits] date formatz

Lines: %sz[processed in %.2f sec]rsrwru)r�rZr+r�r�ZgetRegexr�r�rmr�r6r`r�ZdateDetectorZ	templates�hits�nameZ
_verbose_dateZweight�templater~r�r�r�rr	r
)rIrr�rZ�grprr�r r%rfr&�
printStats�sN



�



zFail2banRegex.printStatsc

Csx|dd�\}}|�d�r d|_z8|�|d�s4WdSt|�dkrV|�|dd�sVWdSWn2ty�}ztd|�WYd}~dSd}~00tj�|��rz2t	||j
d	d
�}|�d|�|�d|j
�Wn0t�y�}zt|�WYd}~dSd}~00�nP|�d��r�t�s td
�dS|�d�|�d|j
�t
|�\}}tdi|��}|�|j
�|��}	|j}
|�d�|
�r�|�|
�|�dd�|
��t||	�}n�|j��dk�r�d|v�r�|�dt|�dd���|g}nn|�d�}|�dt|��t|�D]>\}}|dk�r*|�d��qH|�d|dt|�f��q|�d�|�d�|�|�|���stdSd	S)Nrzsystemd-journalZsystemdr�Fr-r�r�T)ZdoOpenzUse         log file : %szUse         encoding : %sz,Error: systemd library not found. Exiting...zUse         systemd journalzUse    journal match : %s� rrDzUse      single line : %sz\nz Use      multi line : %s line(s)�z| ...z| %2.2s: %sz`-r3)N)rr�r�r/rr+r�r�r�rr��IOErrorrrZsetLogEncodingZgetJournalReaderr�r�ZaddJournalMatchr4r;r�r�r2r�r�rrr")
rIr$Zcmd_logZ	cmd_regexr�rr�ZbeArgsr8r9r��ir1r%r%r&�start�sd










zFail2banRegex.start)N)rKrLrMrdr+r�r�r�r�r�r�r�r�rrrr"r'r%r%r%r&r��s *
@?)Hr�cCs6|tkr|tks|jdkr(t�|||�St�d�dS)N� r)�BrokenPipeErrorr%�errnor=�__excepthook__r>)�exctypern�	tracebackr%r%r&�_loc_except_hook;sr.c	
Gs�tt_dt_t�}|j|�\}}g}|jr:|jr:|�	d�|j
rP|jrP|�	d�t|�dvrf|�	d�|r�|�
�tj�dd�|�d�t�d�|js�td�td	�td
�td�t|j�|_t�|j�t�tj�}|jdkr�dnd
}|j�rt}|j�rd�pd|}ntj}|�|t |j|���t�!|�zt"|�}Wndt#�y�}zJ|j�srt�$�tj%k�r�tj&|dd�ntd|�t�d�WYd}~n
d}~00|�'|��s�t�d�dS)NTzGERROR: --print-no-missed and --print-all-missed are mutually exclusive.zIERROR: --print-no-ignored and --print-all-ignored are mutually exclusive.)rr-z&ERROR: provide both <LOG> and <REGEX>.rD�r3z
Running testsz
=============rz%(levelname)-1.1s: %(message)sz %(message)sz %(tb)sz %(tbc)s)�exc_infor�)(r.r=�
excepthookr�Z
exitOnIOErrorr]�
parse_argsZprint_no_missedZprint_all_missedrmZprint_no_ignoredZprint_all_ignoredr/Z
print_help�stderr�writer4r>rZr+rrSr�ZsetLevelZ
StreamHandler�stdoutrXZ
log_tracebackrZfull_traceback�	FormatterZsetFormatterrZ
addHandlerr�r�r�r�rTr')	r$�parserr|�errorsr5Zfmtr6Z
fail2banRegexr�r%r%r&�exec_command_lineAsN




 r9)Fr)r,)N)=rF�
__author__rHZ__license__Zgetoptr�rr�r�r=r�Zurllib.requestr Zurllib.parseZurllib.errorZoptparserrZconfigparserrrrZserver.filtersystemdr�ImportErrorr	r
Z
jailreaderrr
rZ
server.filterrrrZserver.failregexrrZhelpersrrrrrrr�r'r+r2r6r;r?rErCr]�objectr^rqr�r.r9r%r%r%r&�<module>sR
 
	

	
?J