HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /proc/1991111/cwd/usr/lib/python3/dist-packages/fail2ban/server/__pycache__/
Upload File :
Current File : //proc/1991111/cwd/usr/lib/python3/dist-packages/fail2ban/server/__pycache__/action.cpython-311.pyc
�

�Bd@w���dZdZdZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZ	ddl
mZn#e$r	ddlmZYnwxYwddlmZdd	lmZdd
lmZddlmZdd
lmZmZmZmZmZmZm Z ee!��Z"e	j#��Z$ej%Z&ej'd��Z(dZ)ej'd��Z*d�d�d�Z+ddd�Z,e,�-e+��Gd�dee.��Z/Gd�de.e���Z0ddd�Z1Gd�d e0��Z2dS)!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�F�ttjd�����S)NT��fqdn��strr�getHostname���8/usr/lib/python3/dist-packages/fail2ban/server/action.py�<lambda>r?s���H�0�d�;�;�;�<�<�rc�F�ttjd�����S)NFrrrrrrr@s���H�0�e�<�<�<�=�=�r)zfq-hostnamezsh-hostname�
� )�br�spc�l�eZdZdZdZdZd�Zdd�Zdd�ZeZ	dd
�Z
d�Zd�Zd
�Z
d�Zd�Zd�Zd�Zd�Zd	S)�
CallingMapa"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�\�t��|_d|_t|i|��|_dS)NT)�dictr'r(r&)�self�args�kwargss   r�__init__zCallingMap.__init___s,�����$�,��$�.��D�#�F�#�#�$�)�)�)rTc�v�t��|_	|j|_n#t$rYnwxYw||_dS�N)r+r'�_CallingMap__org_datar&�AttributeErrorr()r,r(s  r�resetzCallingMap.resetdsH�����$�,����4�9�9��	�����4������$�.�.�.s�"�
/�/Fc�X�|jj�d|�|t���d�S)N�(�))�	__class__�__name__�_asdictr)r,�
calculateds  r�_asreprzCallingMap._asreprls,���^�,�,�,�d�l�l�:�s�.K�.K�.K�.K�	L�LrNc�`��t�jfi�j��}|s-t�fd�|���D����St	|�����D]D\}}t|��r0	��|��}|r||��|||<�=#Y�AxYw�E|S)Nc3�V�K�|]#\}}t|��r	|�jv�||fV��$dSr1)�callable�
CM_REPR_ITEMS)�.0�n�vr,s   �r�	<genexpr>z%CallingMap._asdict.<locals>.<genexpr>usR�����3�3���1��A�;�;�3��t�1�1�1��!�u�1�1�1�1�3�3r)r+r&r'�items�listr?�__getitem__)r,r;�checker�drBrCs`     rr:zCallingMap._asdictrs����
�4�9�%�%���%�%�!�	�3�
�3�3�3�3����	�	�3�3�3�3�3�3�
�!�'�'�)�)�_�_�

�

�c�a���q�k�k�	
�
�	
�	�	�!�	�	�Q���������
�Q�q�T�T��
�	�T����	
�
�(s�>'B&�&B*c�^�	|j|}n#t$r|j|}YnwxYw|Sr1)r'�KeyErrorr&�r,�key�values   r�
getRawItemzCallingMap.getRawItem�sD����<���5�5��	�����9�S�>�5�5�5�����	�,��
�*�*c���	|j|}n#t$r|j|}YnwxYwt|��r;t	|d��r|jjr||��n	|��}||j|<|S)N�__code__)r'rKr&r?�hasattrrR�co_argcountrLs   rrGzCallingMap.__getitem__�s�����<���5�5��	�����9�S�>�5�5�5�����
�e�_�_��!�%��4�4�`���9S�`�5�5��;�;�;�Y^�Y^�Y`�Y`�5��4�<���	�,rPc���|jrO|j���|_|j|_|j���|_d|_||j|<dS�NF)r(r'�copyr&r2rLs   r�__setitem__zCallingMap.__setitem__�sV��	�^���,�#�#�%�%�4�<��Y�4�?��y�~�~���4�9��4�>��$�,�s���rc�&�td|z���)NzKey %r was deleted)rK�r,rMs  r�
__unavailablezCallingMap.__unavailable�s���%��+�,�,�,rc��|jrO|j���|_|j|_|j���|_d|_	|j|=n#t
$rYnwxYw|j|=dSrV)r(r'rWr&r2rKrZs  r�__delitem__zCallingMap.__delitem__�s���	�^���,�#�#�%�%�4�<��Y�4�?��y�~�~���4�9��4�>���|�C����	�����4�����
�i��n�n�ns�A!�!
A.�-A.c�*�t|j��Sr1)�iterr&�r,s r�__iter__zCallingMap.__iter__�s��	
�d�i���rc�*�t|j��Sr1)�lenr&r`s r�__len__zCallingMap.__len__�s��	�T�Y���rc�\�|�t|j|j����Sr1)r8r
r&r'r`s rrWzCallingMap.copy�s#��	
���)�$�)�T�\�B�B�	C�	C�Cr)T)F)FN)r9�
__module__�__qualname__�__doc__r@�	__slots__r/r4r<�__repr__r:rOrGrX�_CallingMap__unavailabler]rardrWrrrr%r%Js��������� ��<��$�$�$�
����M�M�M�M�
������$���	�	�	����-�-�-����������D�D�D�D�Drr%c�b�eZdZdZed���Zd�Zd�Zd�Zd�Z	d�Z
ed���Zd	�Z
d
S)�
ActionBasea�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�V�d}|D]#}tt||d����sdS�$dS)N)�start�stop�ban�reban�unbanFT)r?�getattr)�cls�C�required�methods    r�__subclasshook__zActionBase.__subclasshook__�sG���(����f�
�7�1�f�d�+�+�
,�
,���5�5��	
�rc�d�||_||_td|jjz��|_dS)Nzfail2ban.%s)�_jail�_namerr8r9�_logSys)r,�jail�names   rr/zActionBase.__init__�s-���$�*��$�*��=�4�>�+B�B�C�C�$�,�,�,rc��dS)z,Executed when the jail/action is started.
		Nrr`s rrozActionBase.start��	���$rc��dS)z,Executed when the jail/action is stopped.
		Nrr`s rrpzActionBase.stop�r�rc��dS)��Executed when a ban occurs.

		Parameters
		----------
		aInfo : dict
			Dictionary which includes information in relation to
			the ban.
		Nr�r,�aInfos  rrqzActionBase.ban��	���$rc�,�|�|��S)r�)rqr�s  rrrzActionBase.rebans��
���%���rc��dSrVrr`s r�_prolongablezActionBase._prolongables��	�rc��dS)z�Executed when a ban expires.

		Parameters
		----------
		aInfo : dict
			Dictionary which includes information in relation to
			the ban.
		Nrr�s  rrszActionBase.unbanr�rN)r9rfrgrh�classmethodryr/rorprqrr�propertyr�rsrrrrmrm�s���������<����+��D�D�D�
���
���
	�	�	�	�	�	�����(��	�	�	�	�	rrm)�	metaclass�str2seconds�ignore)�timeout�bantimec�4��eZdZdZed��Zd�Z�fd�Zed���Z	d�Z
e
Zd�Ze
d���Ze
d	���Zd
�Zd�Zgdfd
�Ze
d���Ze
d���Ze
d���Zd�Zd-d�Zd.d�Ze
d���Zd�Zd�Zd�Zd�Zd�Zd/d�Zd�Z d/d�Z!e"j#d��Z$ed ���Z%ed0d"���Z&e"j#d#��Z$e"j#d$��Z'ed/d%���Z(e
d&���Z)d'�Z*d1d)�Z+d/d*�Z,e-d2d,���Z.�xZ/S)3�
CommandActiona�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���d|_	d|_d|_d|_d|_d|_d|_d|_d|_d|_	d|_
d|_dS#d|_wxYw)z8 Clear all lists/dicts parameters (used by reloading)
		r�<�rN)�_CommandAction__initr��actionstart�	actionban�actionreban�actionunban�actioncheck�actionrepair�actionflush�
actionstop�actionreloadr`s r�clearAllParamszCommandAction.clearAllParams>sw���$�+���4�<��4���4�>��4���4���4���4���4���4�?��4���4�;�;�;���4�;�?�?�?�?s�AA�	A!c���tt|���||��d|_d|_i|_i|_|���|j�	d|j
z��dS)Nrz
Created %s)�superr�r/r��_CommandAction__properties�_CommandAction__started�_CommandAction__substCacher�r}�debugr8)r,r~rr8s   �rr/zCommandAction.__init__Xsv����
�t���%�%�d�D�1�1�1��$�+��$���$�.��$���������,���\�D�N�2�3�3�3�3�3rc��tSr1)�NotImplemented)rurvs  rryzCommandAction.__subclasshook__as��	�rc�`�|�d��s�|js�t|��sxt�|��}|dkrdS|dkrtj|��}d|_|j�	��|j
�d||��||j|<dS)N�_r�r�z
  Set %s = %r)
�
startswithr�r?�WRAP_CMD_PARAMS�getr	r�r�r��clearr}r��__dict__)r,rrN�wrps    r�__setattr__zCommandAction.__setattr__es���	
����	�	�4�d�k�4�(�5�/�/�4�	�	�	�T�	"�	"�3�	�X�o�o�
�F��}�����u�%�%�E��4����������<���o�t�U�3�3�3��$�-����rc��|�d��s;d|_|j���|j�d|��|j|=dS)Nr�z
  Unset %s)r�r�r�r�r}r�r�)r,rs  r�__delattr__zCommandAction.__delattr__ws[��	
����	�	�*��4����������<���l�D�)�)�)�
�m�D���rc����j��jSt�fd�t���D�����_�jS)z`A dictionary of the actions properties.

		This is used to substitute "tags" in the commands.
		Nc3��K�|]H}|�d���tt�|�����4|t�|��fV��IdS)r�N)r�r?rt)rArMr,s  �rrDz,CommandAction._properties.<locals>.<genexpr>�st�������
�

�.�.��
�
��'/�w�t�S�/A�/A�&B�&B�����s�	�	�������r)r�r+�dirr`s`r�_propertieszCommandAction._properties�s`���
��"�
�
��������$�i�i������$��

�	�rc��|jSr1)r�r`s r�_substCachezCommandAction._substCache�s��	
�	�rc��|�||j|rd|znd|j���}|rd|vr|S|�|d|i��}|S)N�family=r���conditional�cache�<�family)�
replaceTagr�r��replaceDynamicTags)r,�tagr��cmds    r�
_getOperationzCommandAction._getOperation�sn��	
����T�-�$*�2�	�&� � ��	
�	�	�	�	�#�
�-�3�c�>�>�#�:�����h�v�%6�7�7�#�	�*rc�Z��d|f}t|��svt���s.|j�|i������S�fd�|j�|i�����D��S|d}|r2	|j|}n#t
$rix}|j|<YnwxYw||�<dS	|j|}|����}t|�����D]\�}||kr|�=�dS#t
$rYdSwxYw)z? Get, set or delete command of operation considering family.
		�__eOpCmdc�0��g|]\}}�|���|��Srr)rA�frCr�s   �r�
<listcomp>z4CommandAction._operationExecuted.<locals>.<listcomp>�s*���
M�
M�
M���A�6�6�!�9�9�
M�1�
M�
M�
MrrN)rcr?r�r�rErK�poprF)r,r�r�r-rMr��famdrCs  `     r�_operationExecutedz CommandAction._operationExecuted�sx���
�C��#�	�T���N�
�6�
�
�6��� � ��b�)�)�-�-�f�5�5�5�
M�
M�
M�
M��*�.�.�s�B�7�7�=�=�?�?�
M�
M�
M�M��Q��#��	�'���S�!�D�D��
�'�'�'�$&�&�D�4��S�!�!�!�'�����4��<�<�<�	���S�!�D�
�(�(�6�
�
�C��$�*�*�,�,�'�'���	���	�S���
�v�,������	�	�	��D�D�	���s%�
B$�$B=�<B=�AD�
D*�)D*Nc
���d}d}|s#d�|j���D��}|D�]/�	|�|���}d}|r�||�|�fd���vr�|}	|jr�t|jjdd��}
|
s:|jj�d��}
t|jjd|
��tj
��|
d<�|
d<|�||
��}	|�|	|j
��}||z}|r|�|��|�|�|r|nd����#t$r}d	}|}Yd}~��)d}~wwxYw|s%td
|�d|j�d|j�d
|�����|S)z�Executes 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��g|]	\}}|�|��
Srr)rA�famoperrCs   rr�z3CommandAction._executeOperation.<locals>.<listcomp>�s!��D�D�D��'�!�!�D�W�D�D�Drc���|�kSr1r)r�r�s �rrz1CommandAction._executeOperation.<locals>.<lambda>�s����g��r�
actionInfoN�timer�FzError z action �/z: )r�rEr�r�r{rt�actions�_getActionInfo�setattrr	r�r��
executeCmdr��
ValueError�RuntimeErrorr|)
r,r��	operationr��	afterExec�res�errr��ret�realCmdr��er�s
            @r�_executeOperationzCommandAction._executeOperation�s����	
�#��#�	�E�D�D���(<�(<�(>�(>�D�D�D�6����g��
�
�
�S�'�
*�
*�C�
�C�
�
�s�$�1�1�#�7M�7M�7M�7M�N�N�N�N��W��
�	4��d�j�(�,��=�=�e�
�8��z�!�0�0��6�6�u��t�z�!�<��7�7�7��k�m�m�e�F�m��e�H�o��'�'��U�3�3�g��?�?�7�D�L�1�1�S��C�Z�S��)�)�)�G�S�)�)�)����C���*>�#�#�$�?�?�?�?��
����
�C�
�C�C�C�C�C�C���������

�^�	��Y�Y�Y��
�
�
�D�J�J�J�X[�X[�\�	]�	]�]�	�*s�DE�
E�E�Ec��|j�d��}|�|Sd}|jD] }t�|��rd}n�!||jd<|S)N�__hasCondSectionFT)r�r��CONDITIONAL_FAM_RE�match)r,rCrBs   r�_hasCondSectionzCommandAction._hasCondSection�st��
����-�.�.�!��]�
�8��!���
�
�a����q�!�!�
��A�	�E�
�*+�$��%�&�	
�(rc�&�|j�d��}|r|S|j�d��}|r,t|ttf��st|��}n |jrt��rddgndg}ndg}||jd<|S)N�
__families�familiesrrr�)r�r��
isinstancerF�setrr��allowed_ipv6�r,rCs  r�	_familieszCommandAction._families�s���
����<�(�(�!��.�q��
����:�&�&�!���z�!�d�3�Z�(�(���!�}�}�1�1����)�^�^�:�����'��1�1�
�t�1�#$�$��<� �	
�(rc�d�|j�d��}|�|S|j}||jd<|S)z1Checks the action depends on family (conditional)�actionstart_on_demand)r�r�r�r�s  r�_startOnDemandzCommandAction._startOnDemand�s@������2�3�3�!��]�
�8�
��!�./�$��*�+�	
�(rc�*�|���S)��Executes the "actionstart" command.

		Replace the tags in the action command with actions properties
		and executes the resulting command.
		)�_startr`s rrozCommandAction.start	s��
�����rFc����jr|sdSn|s�j�|��rdS|�|gn�j}�fd�}��dd||���}|S)r�TNc�R��|r#��d|d��d�j|<dSdS)N�<actionstop>r)r�r��r�r�r,s  �r�_startedz&CommandAction._start.<locals>._starteds?���	�����N�F�D�9�9�9��D�N�6�����r�
<actionstart>�starting�r�r�)r�r�r�r�r�)r,r��
forceStartr�r�s`    rr�zCommandAction._starts����
���
���4����$�.�,�,�V�4�4��
�$��)�F�8�8�t�~�&������	
����
�6�U]��^�^�#�	�*r�<actionban>c�>�|�dd��}|jr1|j�|��s|�|d���|�||��std|z���|j�|d��dz|j|<dS)	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�rzError banning %(ip)sr�N)r�r�r�r��_processCmdr�)r,r�r�r�s    rrqzCommandAction.ban%s����9�9�X�r�"�"�&�	��)�
�.�
�
�V�
$�
$�)��K�K��4�K�(�(�(�	
�	�	�#�u�	%�	%�6�	�,�u�4�	5�	5�5��>�-�-�f�a�8�8�1�<�$�.����rc�~�t|d��o-|jo&t|j�����S)N�
actionprolong)rSr
r�isspacer`s rr�zCommandAction._prolongable;s@��
�$��
(�
(�-�T�-?�-��t�!�"�"�*�*�,�,�,�.rc�V�|�d|��std|z���dS)aExecutes 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>zError prolonging %(ip)sN)rr�r�s  r�prolongzCommandAction.prolong@s;��
�	�	�+�U�	3�	3�9�	�/�%�7�	8�	8�8�9�9rc���|�dd��}|j�|d��dzr(|�d|��std|z���dSdS)aExecutes 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�rr�
<actionunban>zError unbanning %(ip)sN)r�r�rr�)r,r�r�s   rrszCommandAction.unbanOsv���9�9�X�r�"�"�&�	�^�����"�"�Q�&�9�
�
�
�?�E�
2�
2�9�
�/�%�7�
8�
8�8�9�9�9�9rc�@�|�||jrdnd��S)aDExecutes 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>r)rqr�r�s  rrrzCommandAction.reban`s$��
���%�D�,<�O���-�	P�	P�Prc���d��j���D��}|sdS�fd�}��dd||���S)aExecutes 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.
		c�*�g|]\}}|dzdk�|��S)rr�rAr�rCs   rr�z'CommandAction.flush.<locals>.<listcomp>ys%��@�@�@�%�1�Q�Q��U�a�Z�Z�A�Z�Z�ZrTc�r��|r1�j�|��r�j|xxdzcc<dSdSdS)N���)r�r�r�s  �r�_afterFlushz(CommandAction.flush.<locals>._afterFlush}sZ���	�"�d�n� � ��(�(�"��N�6����b� ������"�"�"�"rz
<actionflush>�flushingr)r�rEr�)r,r�rs`  r�flushzCommandAction.flushosj���A�@�4�>�/�/�1�1�@�@�@�&�	����"�"�"�"�"�
�	�	���F�Va�	�	b�	b�brc�*�|���S)��Executes the "actionstop" command.

		Replaces the tags in the action command with actions properties
		and executes the resulting command.
		)�_stopr`s rrpzCommandAction.stop�s��
�����rc���|�/d��j���D��}|sdSi�_n+	�j|xxdzcc<|g}n#t$rYdSwxYw�fd�}��dd||���S)	rNc��g|]	\}}|�|��
Srrrs   rr�z'CommandAction._stop.<locals>.<listcomp>�s!��8�8�8�5�A�a�a�8�Q�8�8�8rTrc�>��|r��d|d��dSdS)Nr)r�r�s  �r�_stoppedz%CommandAction._stop.<locals>._stopped�s3���	�;����O�V�T�:�:�:�:�:�;�;rr��stoppingr)r�rErKr�)r,r�rs`  rrzCommandAction._stop�s�����^�8�8�D�N�0�0�2�2�8�8�8�6�
�����4�>�>���N�6����a������X�F�F��
�����4�4�����;�;�;�;�;�
�	�	��
�6�U]�	�	^�	^�^s�A
�
A�Ac�.�|�dd��S)z�Executes 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�reloadzCommandAction.reload�s��
�	�	� 0�+�	>�	>�>rc���d}|jrjt|j�����D]C\}}|r<|�||��s&d|j|<|�d|d��|dz}�D|S)zFExecutes the invariant check with repair if expected (conditional).
		TrrNF)r�rFr�rE�_invariantCheckr�)r,�beforeRepairr�r��starteds     r�consistencyCheckzCommandAction.consistencyCheck�s���	
�#�	��� ���!5�!5�!7�!7�8�8��������t�+�+�F�L�A�A���T�^�F��	���_�f�d�;�;�;��E�\�S��	�*rz[\\#&;`|*?~<>^()\[\]{}$'"\n\r]c�R��ddd���fd�}|j�||��}|S)a5Escape 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::

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


		rB�r)r �
c�^��|���}d��||��zS)N�\)�groupr�)�m�c�_map2cs  �r�	substCharz*CommandAction.escapeTag.<locals>.substChar�s)����w�w�y�y�1�
����A�q�!�!�
!�!r)�
ESCAPE_CRE�sub)rurNr2r1s   @r�	escapeTagzCommandAction.escapeTag�sI���*�S�!�!�&�"�"�"�"�"��.�
�
�Y��
.�
.�%�	�,rr�c�����
�d|vr|S|�|�f}	||S#t$rYnwxYwt|t��}|�
|sSdx�
}|�,dt|���f}	||�
n#t$rYnwxYw�
�t	|��j|����
|��
||<tt�������
fd�}	tdz}
	tj	|	|��}|rn+||ksd|vrn |}|
dz}
|
dkrtd	|������C|�|||<|S)
z�Replaces 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�L��|�d��}d}�r��|dz�z��}|�?��|��}|�(��||�����St|��}|�jvr��|��}|S)Nr�?)r.r�r�_escapedTagsr5)r/r�rN�ADD_REPL_TAGS_CMrur��subInfos   ����r�substValz*CommandAction.replaceTag.<locals>.substVals����	
������3��5��1��K�K��c�	�K�/�0�0�E��m��K�K����E��}�� � ��a�g�g�i�i�0�0�0��e���5�	�S�
���
�M�M�%� � �E�
�<rrTrz_unexpected too long replacement interpolation, possible self referencing definitions in query: )rKr�r%�idrr:�
ADD_REPL_TAGSrrr4r�)ru�queryr�r�r7r��ckey�	noRecRepl�csubkeyr=�countrNr;r<s`  `        @@rr�zCommandAction.replaceTag�s������� 	����e�|����+�
�4�	���;���
�	�	�	��D�	����
��
�+�+�)��'�	����7�W����R��Y�Y��4�G�
��W�~�W�W���
�
�
�	�T�
�����o�%�e�[��AQ�
����G����E�'�N� �
�.�.����������& �!�
#�%�F��;�x��'�'�5�����u�n�n��5�(�(�%��5��A�:�5��q�j�j�
�*�=B�U�E�F�F�F�F����5��;�	�,s��
'�'�A%�%
A2�1A2z![\\#&;`|*?~<>\^\(\)\[\]{}$'"\n\r]z\Wc�H�������t����s��fd��tt������fd�}tj||��}d|vr:��d����si���fd�}t�||��}�rtj|���}|S)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����j�|��r(d�j�d|��z}|�|<d|z}|S)Nzf2bV_%sr��$)r3�search�
ESCAPE_VN_CREr4)r�rNru�varsDicts  ��r�	escapeValz3CommandAction.replaceDynamicTags.<locals>.escapeValSsQ���
�~���U�#�#���s�(�,�,�S�#�6�6�6�S��X�c�]�
��W�U��Lrc����|�d��}	�|}n8#t$r+��||�����cYSwxYwt|��}�||��S)Nr)r.rKr�r)r/r�rNr;r�rKs   ���rr=z2CommandAction.replaceDynamicTags.<locals>.substValas����	
������3�0��#�J�E�E��
�0�0�0�����Q�W�W�Y�Y�/�/�/�/�/�0�����e���5�
�)�C��
�
�s�!�2A�Ar�zF-*c���t|�d����}	t�|��}n#t$rYdSwxYw�d|z|��S)Nrr��F_)rr.rrK)r/r�rNrK�tickDatas   ��r�substTagz2CommandAction.replaceDynamicTags.<locals>.substTagssj���
�Q�W�W�Q�Z�Z�
 �
 �C��
���
�
&�
&�U�U�������B�B������9�T�#�X�u�%�%�%s�;�
A	�A	)	r+r%r?rr4r��FCUSTAG_CREr
�
buildShellCmd)	rur�r�rKr=rPr;rOrJs	` ``  @@@rr�z CommandAction.replaceDynamicTags8s���������0�V�V�(�	�
�	�	�	�	�	�	� �
�.�.��	 �	 �	 �	 �	 �	 �	 �
�K��'�*�*�'�	�G�^�^��i�i����8�
�!�r�H�&�&�&�&�&�&��_�_�X�w�
/�
/�7��4�
�
 ��(�
3�
3�7�	�.rc�$�t|dd��S)N�	_banEpochr)rtr`s r�banEpochzCommandAction.banEpoch�s��	��{�A�	&�	&�&rc��|j�,|jjjdzx|_|jj_dS|jdz|_dS)z�Increments 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�rUrTr`s r�invalidateBanEpochz CommandAction.invalidateBanEpoch�sF��
�Z��26�*�2D�2M�PQ�2Q�Q�4�>�D�J�&�/�/�/��M�A�%�4�>�>�>rTc��|s
|�||jvrdS|�d|��}|r|�||j��rdS|r|��sdS|j�d��|���|�d|��}|rL|�||j��s&d|j|<|j�d��dSd|j|<nF	|�|��n#t$rYnwxYw|�
||p|j�	��|j�|��r7|�||j��s|j�d��dSdS)
z0Executes a substituted `actioncheck` command.
		Nrz
<actioncheck>���z<Invariant check failed. Trying to restore a sane environmentz<actionrepair>rzUnable to restore environmentr)
r�r�r�r�r}�errorrW�criticalrr�r�r�r�)r,r�r&r�checkCmd�	repairCmds      rr%zCommandAction._invariantCheck�s���
���*�v�T�^�/K�/K�
�!�
�
�
���
8�
8�(�	��T�_�_�X�t�|�<�<��
�!��
�,�,�.�.�
�
�"��,���A�C�C�C�������� � �!1�6�:�:�)��I�
�/�/�)�T�\�
2�
2�
��D�N�6���L���9�:�:�:��1��4�>�&���	��J�J�v������
�	�	�	��D�	�����;�;�v�*�"G�D�4G�0G�;�H�H�H�	�^�����������$�,�(O�(O���<���8�9�9�9�
�!�	
�s�&C<�<
D	�D	c������dkr�j�d��dS	|d}n#ttf$rd}YnwxYwd}	|r1�jr*��fd�}��||�dk���}|d	krd
S����j|rd|znd�j���}|���	||��}n�}��
|�j��}|d	z
}|s|d	kr|S��)
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�rc����dkr6�j�d��s�j�d��dSdS)Nr�actionrepair_on_unbanz,Invariant check failed. Unban is impossible.FT)r�r�r}rZ)r�r,s��r�
_beforeRepairz0CommandAction._processCmd.<locals>._beforeRepair�sF�������t�'7�';�';�<S�'T�'T��
�l���G�H�H�H�
�U��DrrrrFr�r�)r}r�rK�	TypeErrorr�r%r�r�r�r�r�r�)r,r�r�r��repcntrbr�r�s``      rrzCommandAction._processCmd�sh����(	�B�Y�Y��<���o�&�&�&�
�$���(�O�6�6��
�I�	�����6�6�6�����
�&��
���!���������
�
�v�}�#��BX�
�
Z�
Z�C�
�a�x�x��E��_�_�S�$�"2�%+�3��6�!�!��D�<M��O�O�7����%�%�g�u�5�5�G�G��G�
����$�,�	/�	/�3�	�Q�;�6�	��V�a�Z�Z��J�=s�/�A�Ar�c�0�t���tjkrt�d|��|st�d��dSt5tj||fddd�|��cddd��S#1swxYwYdS)aIExecutes 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   rr�zCommandAction.executeCmd�s���.�����'�-�/�/�	�:�:�a�����	��	�<�<�� � � �
�$��Q�Q�
�
�7�G�
P�4��
P�
P��
P�
P�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q����Q�Q�Q�Q�Q�Qs�(B�B�BrV)rr1)r�NN)NNT)r�)0r9rfrgrhr�r:r�r/r�ryr�rXr�r�r�r�r�r�r�r�r�r�ror�rqr�r
rsrrrrprr#r(�re�compiler3r5r�rIr�rUrWr%r�staticmethodr��
__classcell__)r8s@rr�r� sX���������6��=�>�>�����44�4�4�4�4�����+����� ���������(�� ����(��	
�	
�	
�	�	�	�457�$�%
�%
�%
�%
�N�
�
��(�
�����(������(�����
�
�
�
�(>�>�>�>�,�.�.��(�.�
9�
9�
9�9�9�9�"
Q�
Q�
Q�c�c�c�&���_�_�_�_�.?�?�?�
�
�
�
��b�j�>�?�?��
����+��8�W�W�W��+�W�r�b�j�A�B�B�����E�"�"��
�G�G�G��+�G�R�'�'��(�'�&�&�&�&�&�&�&�P=�=�=�=�~�Q�Q�Q��,�Q�Q�Q�Q�Qrr�)3�
__author__�
__copyright__�__license__rk�osro�signal�
subprocess�tempfile�	threadingr��abcr�collections.abcr�ImportError�collections�	failregexr�ipdnsr�mytimer	�utilsr
�helpersrr
rrrrrr9ri�Lockrn�
IPv6IsAllowedr�rprQ�
COND_FAMILIESr��
DYN_REPL_TAGSr?�update�objectr%rmr�r�rrr�<module>r�s���(7�
�P�
�������	�	�	�	�	�	�	�	�
�
�
�
�����������������������(�+�+�+�+�+�+�+���(�(�(�'�'�'�'�'�'�'�'�(����"�!�!�!�!�!�������������������Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�
��8�	�	��
�I�N���	��%���b�j�.�/�/��"�
��R�Z� 9�:�:��
=�<�=�=���
�	
����
����]�#�#�#�lD�lD�lD�lD�lD���lD�lD�lD�^_�_�_�_�_��7�_�_�_�_�F
�����
rQ�rQ�rQ�rQ�rQ�J�rQ�rQ�rQ�rQ�rQs�5�A�A