
    =*f@w                        S r SrSrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKJr   SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJrJrJrJrJrJrJ r   \" \!5      r"\	RF                  " 5       r$\RJ                  r&\RN                  " S5      r(Sr)\RN                  " S5      r*S S S.r+SSS.r,\,R[                  \+5         " S S\\.5      r/ " S S\.\S9r0SSS.r1 " S S \05      r2g! \ a	    SSKJr   Nf = f)!z'Cyril Jaquier and Fail2Ban Contributorsz>Copyright (c) 2004 Cyril Jaquier, 2011-2012 Yaroslav HalchenkoGPL    N)ABCMeta)MutableMapping   )
mapTag2Opt)DNSUtils)MyTime)Utils   )	getLogger_merge_copy_dicts
splitwordssubstituteRecursiveTags
uni_stringTAG_CREMAX_TAG_REPLACE_COUNTz<F-([A-Z0-9_\-]+)>)inet4inet6z^(\w+)\?(family)=(.*)$c                  <    [        [        R                  " SS95      $ )NTfqdnstrr   getHostname     8/usr/lib/python3/dist-packages/fail2ban/server/action.py<lambda>r   ?   s    H00d;<r   c                  <    [        [        R                  " SS95      $ )NFr   r   r   r   r   r   r   @   s    H00e<=r   )zfq-hostnamezsh-hostname
 )brspc                   x    \ rS rSrSrSrSrS rSS jrSS jr	\	r
SS	 jrS
 rS rS rS rS rS rS rS rSrg)
CallingMapJ   a  A Mapping type which returns the result of callable values.

`CallingMap` behaves similar to a standard python dictionary,
with the exception that any values which are callable, are called
and the result is returned as the value.
No error handling is in place, such that any errors raised in the
callable will raised as usual.
Actual dictionary is stored in property `data`, and can be accessed
to obtain original callable values.

Attributes
----------
data : dict
        The dictionary data which can be accessed to obtain items uncalled
r   )datastorage	immutable
__org_datac                 P    [        5       U l        SU l        [        U0 UD6U l        g )NT)dictr(   r)   r'   )selfargskwargss      r   __init__CallingMap.__init___   s#    $,$.D#F#$)r   c                 r    [        5       U l         U R                  U l        Xl        g ! [         a     Nf = fN)r,   r(   _CallingMap__org_datar'   AttributeErrorr)   )r-   r)   s     r   resetCallingMap.resetd   s6    $,49 . 
 s   ) 
66c                 f    U R                   R                  < SU R                  U[        5      < S3$ )N())	__class____name___asdictr   )r-   
calculateds     r   _asreprCallingMap._asreprl   s"    ^^,,dll:s.K	LLr   Nc                 ^  ^  [        T R                  40 T R                  D6nU(       d#  [        U 4S jUR                  5        5       5      $ [	        UR                  5       5       H<  u  pE[        U5      (       d  M   T R                  U5      nU(       a  U" U5        XSU'   M>     U$ !    MG  = f)Nc              3   r   >#    U  H,  u  p[        U5      (       a  UTR                  ;   d  M'  X4v   M.     g 7fr3   )callableCM_REPR_ITEMS).0nvr-   s      r   	<genexpr>%CallingMap._asdict.<locals>.<genexpr>u   s2      3	A;;!t111 u	s   &7
7)r,   r'   r(   itemslistrC   __getitem__)r-   r>   checkerdrF   rG   s   `     r   r=   CallingMap._asdictr   s    
499%%!	
 3	 3 3 3!'')_caqkk
			!	QqT  
(
	s   =$B''B,c                 f     U R                   U   nU$ ! [         a    U R                  U   n U$ f = fr3   )r(   KeyErrorr'   r-   keyvalues      r   
getRawItemCallingMap.getRawItem   s?    <<5 
, 
 99S>5	,s    00c                     U R                   U   n[        U5      (       aI  [	        US5      (       a#  UR
                  R                  (       a  U" U 5      OU" 5       nX R                   U'   U$ ! [         a    U R                  U   n Nvf = f)N__code__)r(   rQ   r'   rC   hasattrrX   co_argcountrR   s      r   rL   CallingMap.__getitem__   sv    <<5 e__!%449S9S5;Y^Y`5<<	, 
 99S>5s   A, ,BBc                     U R                   (       aV  U R                  R                  5       U l        U R                  U l        U R                  R                  5       U l        SU l         X R                  U'   g NF)r)   r(   copyr'   r4   rR   s      r   __setitem__CallingMap.__setitem__   sM    	^^,,##%4<YY4?yy~~494>,,sr   c                     [        SU-  5      e)NzKey %r was deleted)rQ   r-   rS   s     r   __unavailableCallingMap.__unavailable   s    %+,,r   c                 (   U R                   (       aV  U R                  R                  5       U l        U R                  U l        U R                  R                  5       U l        SU l          U R                  U	 U R                  U	 g ! [
         a     Nf = fr]   )r)   r(   r^   r'   r4   rQ   rb   s     r   __delitem__CallingMap.__delitem__   ss    	^^,,##%4<YY4?yy~~494>||C iin 
 s   )B 
BBc                 ,    [        U R                  5      $ r3   )iterr'   r-   s    r   __iter__CallingMap.__iter__   s    	diir   c                 ,    [        U R                  5      $ r3   )lenr'   rj   s    r   __len__CallingMap.__len__   s    	TYYr   c                 `    U R                  [        U R                  U R                  5      5      $ r3   )r;   r   r'   r(   rj   s    r   r^   CallingMap.copy   s!    	)$))T\\B	CCr   )r*   r'   r)   r(   )T)F)FN)r<   
__module____qualname____firstlineno____doc__rD   	__slots__r0   r6   r?   __repr__r=   rU   rL   r_   _CallingMap__unavailablerf   rk   ro   r^   __static_attributes__r   r   r   r%   r%   J   sZ       <$
M $	-Dr   r%   c                   \    \ rS rSrSr\S 5       rS rS rS r	S r
S r\S	 5       rS
 rSrg)
ActionBase   a  An abstract base class for actions in Fail2Ban.

Action Base is a base definition of what methods need to be in
place to create a Python based action for Fail2Ban. This class can
be inherited from to ease implementation.
Required methods:

- __init__(jail, name)
- start()
- stop()
- ban(aInfo)
- unban(aInfo)

Called when action is created, but before the jail/actions is
started. This should carry out necessary methods to initialise
the action but not "start" the action.

Parameters
----------
jail : Jail
        The jail in which the action belongs to.
name : str
        Name assigned to the action.

Notes
-----
Any additional arguments specified in `jail.conf` or passed
via `fail2ban-client` will be passed as keyword arguments.
c                 R    SnU H  n[        [        XS 5      5      (       a  M    g   g)N)startstopbanrebanunbanFT)rC   getattr)clsCrequiredmethods       r   __subclasshook__ActionBase.__subclasshook__   s/    ( f
71d+
,
,  
r   c                 j    Xl         X l        [        SU R                  R                  -  5      U l        g )Nzfail2ban.%s)_jail_namer   r;   r<   _logSys)r-   jailnames      r   r0   ActionBase.__init__   s'    **=4>>+B+BBC$,r   c                     g)z:Executed when the jail/action is started.
                Nr   rj   s    r   r   ActionBase.start        r   c                     g)z:Executed when the jail/action is stopped.
                Nr   rj   s    r   r   ActionBase.stop   r   r   c                     g)Executed when a ban occurs.

Parameters
----------
aInfo : dict
        Dictionary which includes information in relation to
        the ban.
Nr   r-   aInfos     r   r   ActionBase.ban        r   c                 $    U R                  U5      $ )r   )r   r   s     r   r   ActionBase.reban   s     
%r   c                     gr]   r   rj   s    r   _prolongableActionBase._prolongable  s    	r   c                     g)zExecuted when a ban expires.

Parameters
----------
aInfo : dict
        Dictionary which includes information in relation to
        the ban.
Nr   r   s     r   r   ActionBase.unban  r   r   )r   r   r   N)r<   rs   rt   ru   rv   classmethodr   r0   r   r   r   r   propertyr   r   rz   r   r   r   r|   r|      sN    <  D


		  	r   r|   )	metaclassstr2secondsignore)timeoutbantimec                     ^  \ rS rSrSr\" S5      rS rU 4S jr\	S 5       r
S r\rS r\S	 5       r\S
 5       rS rS r/ S4S jr\S 5       r\S 5       r\S 5       rS rS*S jrS+S jr\S 5       rS rS rS rS rS rS,S jr S r!S,S jr"\#RH                  " S5      r%\	S 5       r&\	S-S  j5       r'\#RH                  " S!5      r%\#RH                  " S"5      r(\	S,S# j5       r)\S$ 5       r*S% r+S.S& jr,S,S' jr-\.S/S( j5       r/S)r0U =r1$ )0CommandActioni   a  A action which executes OS shell commands.

This is the default type of action which Fail2Ban uses.

Default sets all commands for actions as empty string, such
no command is executed.

Parameters
----------
jail : Jail
        The jail in which the action belongs to.
name : str
        Name assigned to the action.

Attributes
----------
actionban
actioncheck
actionreban
actionreload
actionrepair
actionstart
actionstop
actionunban
timeout
)matches	ipmatchesipjailmatchesc                     SU l          SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l	        SU l
        SU l         g! SU l         f = f)zEClear all lists/dicts parameters (used by reloading)
                r   <    r   N)_CommandAction__initr   actionstart	actionbanactionrebanactionunbanactioncheckactionrepairactionflush
actionstopactionreloadrj   s    r   clearAllParamsCommandAction.clearAllParams>  sl     $+4<44>444444?44;4;s   AA 	A c                    > [         [        U ]  X5        SU l        S U l        0 U l        0 U l        U R                  5         U R                  R                  SU R                  -  5        g )Nr   z
Created %s)superr   r0   r   _CommandAction__properties_CommandAction__started_CommandAction__substCacher   r   debugr;   )r-   r   r   r;   s      r   r0   CommandAction.__init__X  sW    t%d1$+$$.$,,\DNN23r   c                     [         $ r3   )NotImplemented)r   r   s     r   r   CommandAction.__subclasshook__a  s    	r   c                 x   UR                  S5      (       d  U R                  (       d  [        U5      (       du  [        R	                  U5      nUS:X  a  g US:X  a  [
        R                  " U5      nS U l        U R                  R                  5         U R                  R                  SX5        X R                  U'   g )N_r   r   z  Set %s = %r)
startswithr   rC   WRAP_CMD_PARAMSgetr	   r   r   r   clearr   r   __dict__)r-   r   rT   wrps       r   __setattr__CommandAction.__setattr__e  s    			dkk(5//			T	"3	Xo
}u%E4<<ot3--r   c                     UR                  S5      (       d=  S U l        U R                  R                  5         U R                  R                  SU5        U R                  U	 g )Nr   z
  Unset %s)r   r   r   r   r   r   r   )r-   r   s     r   __delattr__CommandAction.__delattr__w  sK    			4<<lD)
mmDr   c                    ^  T R                   b  T R                   $ [        U 4S j[        T 5       5       5      T l         T R                   $ )z\A dictionary of the actions properties.

This is used to substitute "tags" in the commands.
c              3      >#    U  HG  nUR                  S 5      (       a  M  [        [        TU5      5      (       a  M7  U[        TU5      4v   MI     g7f)r   N)r   rC   r   )rE   rS   r-   s     r   rH   ,CommandAction._properties.<locals>.<genexpr>  sF      s
..
 &.wtS/A&B Cs	s   AAA)r   r,   dirrj   s   `r   _propertiesCommandAction._properties  sI     
"


 $i $
 
		r   c                     U R                   $ r3   )r   rj   s    r   _substCacheCommandAction._substCache  s    			r   c                     U R                  XR                  U(       a  SU-   OSU R                  S9nU(       a  SU;  a  U$ U R                  USU05      nU$ )Nfamily=r   conditionalcache<family)
replaceTagr   r   replaceDynamicTags)r-   tagr   cmds       r   _getOperationCommandAction._getOperation  s_     	--$*	& 			 	 	# 
3c>#:hv%67#	*r   c                    SU4n[        U5      (       d  [        U5      (       d+  U R                  R                  U0 5      R                  U5      $ U R                  R                  U0 5      R	                  5        VVs/ s H  u  pVU" U5      (       d  M  UPM     snn$ US   nU(       a   U R                  U   nXxU'   g U R                  U   nUR                  U5      n[        UR	                  5       5       H  u  p&Xg:X  d  M  X	 M     gs  snnf ! [
         a    0 =oR                  U'    Ntf = f! [
         a     gf = f)zLGet, set or delete command of operation considering family.
                __eOpCmdr   N)rn   rC   r   r   rJ   rQ   poprK   )	r-   r   r   r.   rS   frG   r   famds	            r   _operationExecuted CommandAction._operationExecuted  s,    
C#	T
6

  b)--f55**..sB7==?
M?6!91?
MMQ#'S!D <	S!D
((6
C$**,'		
, ( N
  '$&&DS!'  		s7   =DD+D  AD2 D2 D/.D/2
D?>D?Nc           
        ^ SnSnU(       d7  U R                   R                  5        VVs/ s H  u  pxU(       d  M  UPM     nnnU GH3  m U R                  UT5      n	Sn
U	(       a  XR                  UU4S j5      ;  a  U	nU R                  (       a  [        U R                  R                  SS5      nU(       dF  U R                  R                  R                  S5      n[        U R                  R                  SU5        [        R                  " 5       US'   TUS'   U R                  X5      nU R                  XR                  5      n
XZ-  nU(       a	  U" TU
5        U R                  UTU
(       a  U	OS5        GM6     U(       d/  [        S	U< S
U R                  < SU R                   < SU< 35      eU$ s  snnf ! [         a  nSnUn SnAGM  SnAff = f)zExecutes the operation commands (like "actionstart", "actionstop", etc).

Replace the tags in the action command with actions properties
and executes the resulting command.
TzScript errorc                    > U T:g  $ r3   r   )r   famopers    r   r   1CommandAction._executeOperation.<locals>.<lambda>  s	    gr   
actionInfoNtimer   FzError z action /z: )r   rJ   r   r   r   r   actions_getActionInfosetattrr	   r   r   
executeCmdr   
ValueErrorRuntimeErrorr   )r-   r   	operationr   	afterExecreserrr   rG   r   retrealCmdr   es          `      r   _executeOperationCommandAction._executeOperation  sx    	##	(,(<(<(>D(>'!W(>6Dg


S'
*C
C
s11#7MNNW

djj((,=ezz!!006utzz!!<7kkmeFmeHo''3g??7LL1SZS)GS)C#$?) 0 
	Y

DJJX[\	]]	*7 E,  
C
Cs#   F6F6D.F<<
GGGc                     U R                   R                  S5      nUb  U$ SnU R                    H!  n[        R                  U5      (       d  M  Sn  O   XR                   S'   U$ )N__hasCondSectionFT)r   r   CONDITIONAL_FAM_REmatch)r-   rG   rF   s      r   _hasCondSectionCommandAction._hasCondSection  sg    
-.!]
8!aq!!A	  *+%&	
(r   c                 R   U R                   R                  S5      nU(       a  U$ U R                   R                  S5      nU(       a'  [        U[        [        45      (       d  [        U5      nO+U R                  (       a  [        5       (       a  SS/OS/nOS/nXR                   S'   U$ )N
__familiesfamiliesr   r   r   )r   r   
isinstancerK   setr   r  allowed_ipv6r-   rG   s     r   	_familiesCommandAction._families  s    
<(!q
:&!z!d3Z((!}1)^^'1
t1#$< 	
(r   c                 z    U R                   R                  S5      nUb  U$ U R                  nXR                   S'   U$ )z1Checks the action depends on family (conditional)actionstart_on_demand)r   r   r  r  s     r   _startOnDemandCommandAction._startOnDemand  sD     23!]
8
!./*+	
(r   c                 "    U R                  5       $ )Executes the "actionstart" command.

Replace the tags in the action command with actions properties
and executes the resulting command.
)_startrj   s    r   r   CommandAction.start	  s     
r   c                    ^  T R                   (       a	  U(       d  gO(U(       d!  T R                  R                  U5      (       a  gUb  U/OT R                  nU 4S jnT R	                  SSXS9nU$ )r  Tc                 Z   > U(       a#  TR                  SU S 5        STR                  U '   g g )N<actionstop>r   )r   r   r   r  r-   s     r   _started&CommandAction._start.<locals>._started  s+    	NFD9DNN6 
r   <actionstart>startingr   r  )r  r   r   r  r  )r-   r   
forceStartr$  r  s   `    r   r  CommandAction._start  sh     

 $..,,V44
)F8t~~& 	
6^#	*r   c                 J   UR                  SS5      nU R                  (       a0  U R                  R                  U5      (       d  U R                  USS9  U R	                  X!5      (       d  [        SU-  5      eU R                  R                  US5      S-  U R                  U'   g)	a'  Executes the given command ("actionban" or "actionreban").

Replaces the tags in the action command with actions properties
and ban information, and executes the resulting command.

Parameters
----------
aInfo : dict
        Dictionary which includes information in relation to
        the ban.
r   r   Tr)  zError banning %(ip)sr      N)r   r  r   r  _processCmdr   )r-   r   r   r   s       r   r   CommandAction.ban%  s     99Xr"&	
..

V
$
$KK4K(			#	%	%	,u4	55>>--fa81<$..r   c                     [        U S5      =(       a;    U R                  =(       a(    [        U R                  5      R                  5       (       + $ )Nactionprolong)rY   r1  r   isspacerj   s    r   r   CommandAction._prolongable;  s=    
$
( -T-?-? -t!!"**,,.r   c                 N    U R                  SU5      (       d  [        SU-  5      eg)a  Executes the "actionprolong" command.

Replaces the tags in the action command with actions properties
and ban information, and executes the resulting command.

Parameters
----------
aInfo : dict
        Dictionary which includes information in relation to
        the ban.
z<actionprolong>zError prolonging %(ip)sN)r.  r   r   s     r   prolongCommandAction.prolong@  s.     
		+U	3	3	/%7	88 
4r   c                     UR                  SS5      nU R                  R                  US5      S-  (       a&  U R                  SU5      (       d  [        SU-  5      egg)a  Executes the "actionunban" command.

Replaces the tags in the action command with actions properties
and ban information, and executes the resulting command.

Parameters
----------
aInfo : dict
        Dictionary which includes information in relation to
        the ban.
r   r   r   r   <actionunban>zError unbanning %(ip)sN)r   r   r.  r   )r-   r   r   s      r   r   CommandAction.unbanO  s[     99Xr"&	^^"Q&


?E
2
2
/%7
88 3 'r   c                 R    U R                  XR                  (       a  S5      $ S5      $ )aB  Executes the "actionreban" command if available, otherwise simply repeat "actionban".

Replaces the tags in the action command with actions properties
and ban information, and executes the resulting command.

Parameters
----------
aInfo : dict
        Dictionary which includes information in relation to
        the ban.
z<actionreban><actionban>)r   r   r   s     r   r   CommandAction.reban`  s#     
%,<,<	PP-	PPr   c                    ^  T R                   R                  5        VVs/ s H  u  pUS-  S:X  d  M  UPM     nnnU(       d  gU 4S jnT R                  SSX4S9$ s  snnf )a  Executes the "actionflush" command.

Command executed in order to flush all bans at once (e. g. by stop/shutdown 
the system), instead of unbanning of each single ticket.

Replaces the tags in the action command with actions properties
and executes the resulting command.
r-  Tc                    > U(       a9  TR                   R                  U 5      (       a  TR                   U ==   S-  ss'   g g g )N)r   r   r#  s     r   _afterFlush(CommandAction.flush.<locals>._afterFlush}  s5    	dnn  ((NN6b  )cr   z<actionflush>flushingr(  )r   rJ   r  )r-   r   rG   r   r@  s   `    r   flushCommandAction.flusho  s^      >>//1@1%1QUaZA1&@	" 
		F		bb As
   AAc                 "    U R                  5       $ )Executes the "actionstop" command.

Replaces the tags in the action command with actions properties
and executes the resulting command.
)_stoprj   s    r   r   CommandAction.stop  s     
r   c                 (  ^  UcG  T R                   R                  5        VVs/ s H  u  p#U(       d  M  UPM     nnnU(       d  g0 T l         O T R                   U==   S-  ss'   U/nU 4S jnT R                  SSXS9$ s  snnf ! [         a     gf = f)rF  Tr   c                 <   > U(       a  TR                  SU S 5        g g )Nr&  )r   r#  s     r   _stopped%CommandAction._stop.<locals>._stopped  s    	OVT: 
r   r"  stoppingr(  )r   rJ   rQ   r  )r-   r   r   rG   rK  s   `    r   rG  CommandAction._stop  s     ^ NN002825AaQ268
4>NN6aXF; 
		
6		^^ 9  s   A>A>B 
BBc                 &    U R                  SS5      $ )zExecutes the "actionreload" command.

Parameters
----------
kwargs : dict
  Currently unused, because CommandAction do not support initOpts

Replaces the tags in the action command with actions properties
and executes the resulting command.
z<actionreload>	reloading)r  )r-   r/   s     r   reloadCommandAction.reload  s     
		 0+	>>r   c                    SnU R                   (       at  [        U R                  R                  5       5       HM  u  p4U(       d  M  U R	                  X15      (       a  M&  SU R                  U'   U R                  SUS5        US-  nMO     U$ )zTExecutes the invariant check with repair if expected (conditional).
                Tr   r&  NF)r   rK   r   rJ   _invariantCheckr   )r-   beforeRepairr  r   starteds        r   consistencyCheckCommandAction.consistencyCheck  sv     	#	 !5!5!78wt++FAAT^^F	_fd;E\S 9 
*r   z[\\#&;`|*?~<>^()\[\]{}$'"\n\r]c                 T   ^ SSS.mU4S jnU R                   R                  X!5      nU$ )a   Escape characters which may be used for command injection.

                Parameters
                ----------
                value : str
                        A string of which characters will be escaped.

                Returns
                -------
                str
                        `value` with certain characters escaped.

                Notes
                -----
                The following characters are escaped::

                        \#&;`|*?~<>^()[]{}$'"


                rF   r)r    c                 L   > U R                  5       nSTR                  X5      -   $ )N\)groupr   )mc_map2cs     r   	substChar*CommandAction.escapeTag.<locals>.substChar  s"    wwy1
A!
!!r   )
ESCAPE_CREsub)r   rT   rb  ra  s      @r   	escapeTagCommandAction.escapeTag  s/    * S!&" ..

Y
.%	,r   c                   ^ ^^^ SU;  a  U$ Ub	  UT4n XV   $ [        U[        5      nUmU(       d:  S=mnUb  S[        U5      T4n XX   mTc  [	        UTT R
                  US9mUb  TXX'   [        [        5      mUU UU4S jn	[        S-   n
 [        R                  " X5      nU(       a  O*X:X  d  SU;  a  OUnU
S-  n
U
S::  a  [        SU< 35      eMH  Ub  XW'   U$ ! [          a     Nf = f! [          a     Nf = f)	zReplaces tags in `query` with property values.

Parameters
----------
query : str
        String with tags.
aInfo : dict
        Tags(keys) and associated values for substitution in query.

Returns
-------
str
        `query` string with tags replaced.
r   Nz
subst-tags)r   addreplc                 .  > U R                  S5      nS nT(       a  TR                  US-   T-   5      nUc3  TR                  U5      nUc  TR                  XR                  5       5      $ [        U5      nUTR                  ;   a  TR	                  U5      nU$ )Nr   ?)r^  r   r   _escapedTagsrf  )r_  r   rT   ADD_REPL_TAGS_CMr   r   subInfos      r   substVal*CommandAction.replaceTag.<locals>.substVal  s    	
35KKc	K/0EmKKE}  ggi00e5	S MM% E
<r   r   r   z_unexpected too long replacement interpolation, possible self referencing definitions in query: )rQ   r  r%   idr   rl  ADD_REPL_TAGSr   r   re  r   )r   queryr   r   ri  r   ckey	noRecReplcsubkeyro  countrT   rm  rn  s   `  `        @@r   r   CommandAction.replaceTag  sX     	e| +
4	; 
+)'	 7WRY4G
~W o%e[AQAQG EN  . &  !
#%;;x'5n5(%5A:5qj
=BEF F 	 ;	,C  		  
	
s#   C C/ 
C,+C,/
C<;C<z![\\#&;`|*?~<>\^\(\)\[\]{}$'"\n\r]z\Wc                 P  ^ ^^^^^ [        5       mT(       d  U U4S jm[        [        5      mUUU4S jn[        R                  " XA5      nSU;   a6  TR                  S5      mT(       d  0 mUU4S jn[        R	                  XQ5      nT(       a  [        R                  " UT5      nU$ )a  Replaces dynamical tags in `query` with property values.

**Important**
-------------
Because this tags are dynamic resp. foreign (user) input:
  - values should be escaped (using "escape" as shell variable)
  - no recursive substitution (no interpolation for <a<b>>)
  - don't use cache

Parameters
----------
query : str
        String with tags.
aInfo : dict
        Tags(keys) and associated values for substitution in query.

Returns
-------
str
        shell script as string or array with tags replaced (direct or as variables).
c                    > TR                   R                  U5      (       a)  STR                  R                  SU 5      -  n UTU '   SU -   nU$ )Nzf2bV_%sr   $)rd  searchESCAPE_VN_CREre  )r   rT   r   varsDicts     r   	escapeVal3CommandAction.replaceDynamicTags.<locals>.escapeValS  sN    
~~U## s((,,S#66SXc]WULr   c                    > U R                  S5      n TU   n[        U5      nT" X5      $ ! [         a"    TR                  XR                  5       5      s $ f = f)Nr   )r^  rQ   r   r   )r_  r   rT   rm  r   r  s      r   ro  2CommandAction.replaceDynamicTags.<locals>.substVala  s]    	
30#JE e5
C
  0WWY//0s   , )AAr   zF-*c                    > [        U R                  S5      5      n [        TU   5      nT" SU-   U5      $ ! [         a     gf = f)Nr   r   F_)r   r^  r   rQ   )r_  r   rT   r  tickDatas      r   substTag2CommandAction.replaceDynamicTags.<locals>.substTags  sO    
QWWQZ
 C&U T#Xu%%  s   7 
AA)	r,   r%   rr  r   re  r   FCUSTAG_CREr
   buildShellCmd)	r   r  r   r  ro  r  rm  r  r~  s	   ` ``  @@@r   r    CommandAction.replaceDynamicTags8  s    0 V(		  .	  KK*' 	G^ii8
rH& __X/7   (37	.r   c                     [        U SS5      $ )N	_banEpochr   )r   rj   s    r   banEpochCommandAction.banEpoch  s    	{A	&&r   c                     U R                   bD  U R                   R                  R                  S-   =U l        U R                   R                  l        gU R                  S-   U l        g)zIncrements ban epoch of jail and this action, so already banned tickets would cause
a re-ban for all tickets with previous epoch.Nr   )r   r   r  r  rj   s    r   invalidateBanEpoch CommandAction.invalidateBanEpoch  sM     
ZZ26**2D2D2M2MPQ2QQ4>DJJ&&/MMA%4>r   c                 \   U(       d  Ub  XR                   ;  a  gU R                  SU5      nU(       a   U R                  X@R                  5      (       a  gU(       a  U" 5       (       d  gU R                  R                  S5        U R                  5         U R                  SU5      nU(       a[  U R                  XPR                  5      (       d+  SU R                   U'   U R                  R                  S5        gSU R                   U'   O9 U R                  U5        U R                  X=(       d    U R                  (       + S9  U R                   R                  U5      (       a<  U R                  X@R                  5      (       d  U R                  R                  S5        gg! [         a     Nf = f)	z>Executes a substituted `actioncheck` command.
                r   z<actioncheck>z<Invariant check failed. Trying to restore a sane environmentz<actionrepair>r   zUnable to restore environmentr,  )r   r   r   r   r   errorr  criticalrG  r   r  r  r   )r-   r   rU  r)  checkCmd	repairCmds         r   rT  CommandAction._invariantCheck  sP    
*v^^/K
8(	T__X||<<
,..
,,AC   !16:)
//)\\
2
2DNN6LL9:4>>&	JJv ;;v"GD4G4G0G;H	^^,,(O(O<<89
	
  		s   	F 
F+*F+c                   ^ ^ TS:X  a  T R                   R                  S5        g US   nSn U(       a2  T R                  (       a!  UU 4S jnT R                  X5TS:g  S9nUS	:w  a  g
T R                  TT R                  U(       a  SU-   OST R                  S9nUb  T R                  Xr5      nOTnT R                  UT R                  5      nUS	-  nU(       d  US	:  a  U$ M  ! [        [        4 a    Sn Nf = f)a  Executes a command with preliminary checks and substitutions.

Before executing any commands, executes the "check" command first
in order to check if pre-requirements are met. If this check fails,
it tries to restore a sane environment before executing the real
command.

Parameters
----------
cmd : str
        The command to execute.
aInfo : dictionary
        Dynamic properties.

Returns
-------
bool
        True if the command succeeded.
r   Nothing to doTr   r   c                     > T S:X  a<  TR                   R                  S5      (       d  TR                  R                  S5        gg)Nr8  actionrepair_on_unbanz,Invariant check failed. Unban is impossible.FT)r   r   r   r  )r   r-   s   r   _beforeRepair0CommandAction._processCmd.<locals>._beforeRepair  s;    t'7'7';';<S'T'T
llGHr   r8  r,  r   Fr   r   )r   r   rQ   	TypeErrorr   rT  r   r   r   r   r   r   )r-   r   r   r   repcntr  r  r  s   ``      r   r.  CommandAction._processCmd  s   ( 	BY<<o&
(O6 & !! 

v#BX

ZC
ax __S$"2"2%+6!D<M<M  O7 %%g5GG 
$,,	/3	Q;6	VaZJ= 		 I	 6s   C" "C76C7c                 *   [         R                  5       [        R                  :  a  [         R	                  SU 5        U (       d  [         R                  S5        g[           [        R                  " X4SSS.UD6sSSS5        $ ! , (       d  f       g= f)aJ  Executes a command.

Parameters
----------
realCmd : str
        The command to execute.
timeout : int
        The time out in seconds for the command.

Returns
-------
bool
        True if the command succeeded.

Raises
------
OSError
        If command fails to be executed.
RuntimeError
        If command execution times out.
	   r  TF)shelloutputN)	logSysgetEffectiveLevelloggingDEBUGlogr   	_cmd_lockr
   r   )r  r   r/   s      r   r   CommandAction.executeCmd  s`    . '--/	::a		<< 



7
P4
P
P yys    B
B)__init__properties	__started__substCacher  r   r   r   r   r   r   r   r   r   r   r]   )r;  r3   )r   NN)NNT)r   )2r<   rs   rt   ru   rv   r  rl  r   r0   r   r   r   r_   r   r   r   r   r   r   r  r  r  r  r   r  r   r   r5  r   r   rC  r   rG  rQ  rW  recompilerd  rf  r   r}  r   r  r  rT  r.  staticmethodr   rz   __classcell__)r;   s   @r   r   r      s   6 =>44         		4 57$ %N 
 
    (>, . .99"Qc&_.? jj>? 8 W Wr jjABE"G GR ' '&&P=~ Q Qr   r   )3
__author____copyright____license__r  osr  signal
subprocesstempfile	threadingr   abcr   collections.abcr   ImportErrorcollections	failregexr   ipdnsr   mytimer	   utilsr
   helpersr   r   r   r   r   r   r   r<   r  Lockr  IPv6IsAllowedr  r  r  COND_FAMILIESr  DYN_REPL_TAGSrr  updateobjectr%   r|   r   r   r   r   r   <module>r     s,  ( 7
P  	 	      (+ "   Q Q Q 
8	 NN	 %% jj./"ZZ 9: 
 == 	   ] #lD lD^_7 _F 
rQJ rQ{  ('(s   C- -C<;C<