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/lib/python3/dist-packages/fail2ban/server/__pycache__/
Upload File :
Current File : //proc/1991111/cwd/lib/python3/dist-packages/fail2ban/server/__pycache__/utils.cpython-311.pyc
�

�Bd�.��.�dZdZdZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlZddlm
Z
mZmZddlmZejd	krddlZnddlZe
e��Zd
diZed�ej���D����ZGd
�d��ZdS)z2Serg G. Brester (sebres) and Fail2Ban ContributorszYCopyright (c) 2004 Cyril Jaquier, 2011-2012 Yaroslav Halchenko, 2012-2015 Serg G. Brester�GPL�N)�Lock�)�	getLogger�_merge_dicts�
uni_decode)�OrderedDict��r�am"Command not found".  Make sure that all commands in %(realCmd)r are in the PATH of fail2ban-server process (grep -a PATH= /proc/`pidof -x fail2ban-server`/environ). You may want to start "fail2ban-server -f" separately, initiate it with "fail2ban-client reload" in another shell session and observe if additional informative error messages appear in the terminals.c#�NK�|] \}}|�d���||fV��!dS)�SIGN)�
startswith)�.0�name�nums   �7/usr/lib/python3/dist-packages/fail2ban/server/utils.py�	<genexpr>r7sW����E�E��T�3�T�_�_�U�-C�-C�E��T�{�E�E�E�E�E�E�c��eZdZdZdZdZdZedzZGd�de��Z	e
d���Ze
d	���Ze
		dd���Z
e
dd���Zejdkre
d���Zne
d���Ze
d���ZdS)�UtilszPUtilities provide diverse static methods like executes OS shell commands, etc.
	rg�������?g����MbP?�dc�@�eZdZdZd�Zdd�Zd�Zd
d�Zd	�Zd
�Z	d�Z
dS)�Utils.Cachez.A simple cache with a TTL and limit on size
		c�l�|j|i|��t��|_t��|_dS�N)�
setOptionsr	�_cacher�_Cache__lock)�self�args�kwargss   r�__init__zUtils.Cache.__init__Hs3���4�?�D�#�F�#�#�#����4�;����4�;�;�;r���<c�"�||_||_dSr)�maxCount�maxTime)r r'r(s   rrzUtils.Cache.setOptionsMs���4�=��4�<�<�<rc�*�t|j��Sr)�lenr�r s r�__len__zUtils.Cache.__len__Qs��

�d�k�
�
�rNc��|j�|��}|r:|dtj��kr|dS|�|��|S)N�r)r�get�time�unset)r �k�defv�vs    rr/zUtils.Cache.getTsO���{���q���1�����t�d�i�k�k���
�a�D�[��J�J�q�M�M�M�
�;rc�L�tj��}|j}|j5t|��|jkrB|r@|�d���\}}|d|krt|��|jkrn|�@|||jzf||<ddd��dS#1swxYwYdS)NF)�lastr.)r0rrr*r'�popitemr()r r2r4�t�cache�ck�cvs       r�setzUtils.Cache.set\s����y�{�{�1��;�5���
%�
%�
�5�z�z�T�]�"�"��
����E��*�*�h�r�2�	�A�����s�5�z�z�D�M�1�1��	�
��1�t�|�#�$�E�!�H�
%�
%�
%�
%�
%�
%�
%�
%�
%�
%�
%�
%����
%�
%�
%�
%�
%�
%s�A*B�B� Bc�|�|j5|j�|d��ddd��dS#1swxYwYdSr)rr�pop)r r2s  rr1zUtils.Cache.unsetls��������K�O�O�A�t������������������������s�1�5�5c�x�|j5|j���ddd��dS#1swxYwYdSr)rr�clearr+s rr@zUtils.Cache.clearps��������K��������������������������s�/�3�3)r$r%r)�__name__�
__module__�__qualname__�__doc__r#rr,r/r<r1r@�rr�CacherDs������������
�����������%�%�%� �������rrFc���tj|tj��}|s|tjz}n|tjz}tj|tj|��|Sr)�fcntl�F_GETFL�os�
O_NONBLOCK�F_SETFL)�fhandle�value�flagss   r�
setFBlockModezUtils.setFBlockModeusT��
�+�g�u�}�
-�
-�%�	���B�M��5�5��R�]�N��5��+�g�u�}�e�,�,�,�	�,rc��d}t|t��s|g}t|��dz
}|���D]*\}}||�d|�d�z
}|�|��|dz
}�+|dz|dz|d<|S)a�Generates new shell command as array, contains map as variables to
		arguments statement (varsStat), the command (realCmd) used this variables and
		the list of the arguments, mapped from varsDict

		Example:
			buildShellCmd('echo "V2: $v2, V1: $v1"', {"v1": "val 1", "v2": "val 2", "vUnused": "unused var"})
		returns:
			['v1=$0 v2=$1 vUnused=$2 
echo "V2: $v2, V1: $v1"', 'val 1', 'val 2', 'unused var']
		�r.z=$� �
r)�
isinstance�listr*�items�append)�realCmd�varsDict�varsStat�ir2r4s      r�
buildShellCmdzUtils.buildShellCmds����(�	�G�T�	"�	"���Y�7�	�'�l�l�1�n�!��n�n���
�
�d�a���A�A�A�q�q�q�!�!�8�
�>�>�!������6�1�1��$�����+�'�!�*�	�.rr%TF�rNc	�*����dx}}d}	dx�}
|r8|rt��|���nttj|��}
t������fd�}	t
j�tjtj||
tj	������
��}	|	�5�fd�}t�||tj��}	|	r|	d}	|	��!|r|tj��d}t�d�|fz��tj�j��}
tj|
t(j��t-jtj����
��}	|	�|rStj|
t(j��t-jtj��|	���
��}	|	�&t�|
��st(j}	nb#t6$rU}|r|tj��d}��d|��}t�|���s|sdnd|||	fcYd}~SYd}~nd}~wwxYw|	|vrtjntj}|t���kr.|r,||tjkr|dz
ntj��d}|s|t���k�rĉjr�	|	�|	d	kr t��jd���j� ��}n2#tB$r%}t�d
|��Yd}~nd}~wwxYw|�d|dkr^|t���krA|�"��D],}t�#|d�tI|�����-�j%r�	|	�|	d	kr t��j%d���j%� ��}n2#tB$r%}t�d
|��Yd}~nd}~wwxYw|�d|dkr^|t���krA|�"��D],}t�#|d�tI|�����-�jr�j�&���j%r�j%�&��d}|	|vrt�'d�|	��d}n�|	�"t�d��j��n�|	d	ks|	dkrH|	d	kr|	n|	dz
}t�d�tP�)|d|z��|	��ndtT�)|	d��}t�d�|	��|r+t�+d|	|tY��z��|r||||	fSt[|��dkr|n||	fS)aExecutes a command.

		Parameters
		----------
		realCmd : str
			The command to execute.
		timeout : int
			The time out in seconds for the command.
		shell : bool
			If shell is True (default), the specified command (may be a string) will be 
			executed through the shell.
		output : bool
			If output is True, the function returns tuple (success, stdoutdata, stderrdata, returncode).
			If False, just indication of success is returned
		varsDict: dict
			variables supplied to the command (or to the shell script)

		Returns
		-------
		bool or (bool, str, str, int)
			True if the command succeeded and with stdout, stderr, returncode if output was set to True

		Raises
		------
		OSError
			If command fails to be executed.
		RuntimeError
			If command execution times out.
		Nc�>��t�|d����S)Nz%x -- exec: %s)�logSys�log)�levelrY�	realCmdIds ��r�<lambda>z"Utils.executeCmd.<locals>.<lambda>�s������E�+;�Y��P�P�r)�stdout�stderr�shell�env�
preexec_fnc�<������}|�d|fndS)NT)�poll)�retcode�popens �r�_popen_wait_endz)Utils.executeCmd.<locals>._popen_wait_end�s#����z�z�|�|�W�&�2�T�7�O�O��<rr.z!%x -- timed out after %s seconds.z -- failed with Frz  ... -- failed to read stdout %srRz%x -- stdout: %rz  ... -- failed to read stderr %sz%x -- stderr: %rz%x -- returned successfully %iTz%x -- unable to kill PID %i�z&%x -- killed with %s (return code: %s)z	signal %iz%x -- returned %izHINT on %i: %s).rr]rrJ�environ�id�
subprocess�Popen�PIPE�setsidrl�wait_for�DEFAULT_SHORTEST_INTERVAL�logging�ERRORra�error�getpgid�pid�killpg�signal�SIGTERMr0�sleep�DEFAULT_SLEEP_INTERVAL�SIGKILL�
pid_exists�OSError�DEBUG�getEffectiveLevelrfrP�read�IOError�
splitlinesrbrrg�close�debug�signamer/�_RETCODE_HINTS�info�localsr*)rY�timeoutrh�output�tout_kill_tree�
success_codesrZrfrgrmri�logCmdro�pgid�e�	std_level�l�success�sigcode�msgrnrds`                   @@r�
executeCmdzUtils.executeCmd�sp�����@��&�6��'���%�#�
�-��-��!�!�'�8�4�4�G�G�
�r�z�8�
,�
,�C���k�k�)�P�P�P�P�P�&�'E����J�O�J�O�5�c��y����5�
�Z�Z�\�\�7�
�o�=�=�=�=�=��n�n�_�g�u�7V�W�W�G����q�z�W�
�o�
�3�v�v�g�m�$�$�$�t�f�
�L�L�4��������
�:�e�i� � �D��I�d�F�N�#�#�#��J�u�+�,�,�,��j�j�l�l�G���.���Y�t�V�^�$�$�$�	�Z��,�-�-�-����
�
���g���u�/�/��5�5���~�W���	�E�E�E��2�f�f�W�]�#�#�#�d�V�&-�g�g�q�q�1�6�	�<�<�����
�E��D�5�5�U�F�F�G�$D�D�D�D�D�D�D�E�E�E�E�E�����	E���� '�-�7�7�g�m�m�W�]�)��&�*�*�,�,�,�,��a�f�f�I���$>�$>�Y�q�[�[�G�M�R�R�R�]a�TZ��J�y�F�4�4�6�6�6�6��l�	J�9���7�Q�;�;����%�,��.�.�.��l���!�!�V�V���9�9�9��\�\�4�a�8�8�8�8�8�8�8�8�����9����
��f��l�l�y�F�<T�<T�<V�<V�/V�/V����!�!�J�J���j�j��.�	�:�a�=�=�I�I�I�I��l�	J�9���7�Q�;�;����%�,��.�.�.��l���!�!�V�V���9�9�9��\�\�4�a�8�8�8�8�8�8�8�8�����9����
��f��l�l�y�F�<T�<T�<V�<V�/V�/V����!�!�J�J���j�j��.�	�:�a�=�=�I�I�I�I�
�\�'�5�<�%�%�'�'�'�
�\�'�5�<�%�%�'�'�'��'��
���	�<�<�0�)�W�E�E�E�
�7�7���	�<�<�-�y�%�)�D�D�D�D���{�{�g��m�m� �1���g�X�X�'�C�-�7�	�<�<�8�
�w�{�{�7�K�'�$9�:�:�G�E�E�E�E�
�	�	�G�T�	*�	*�3�	�<�<�#�Y��8�8�8�	�;�
�K�K� �'�3����>�:�:�:��+�
�6�6�7�
*�*��
�&�&�!�+�+���'�7�1C�CsR�F'H�
I%�AI �I%� I%�7AL9�9
M(�M#�#M(�AP�
Q
�%Q�Q
c�"��d}	|��}|r|S|r1dx}}t|��stj��|z��fd�}n|}|��rn>t||ptjztj��}tj|����|S)a5Wait until condition expression `cond` is True, up to `timeout` sec

		Parameters
		----------
		cond : callable
			The expression to check condition 
			(should return equivalent to bool True if wait successful).
		timeout : float or callable
			The time out for end of wait
			(in seconds or callable that returns True if timeout occurred).
		interval : float (optional)
			Polling start interval for wait cycle in seconds.

		Returns
		-------
		variable
			The return value of the last call of `cond`, 
			logical False (or None, 0, etc) if timeout occurred.
		r.Trc�2��tj���kSr)r0)�time0s�rrez Utils.wait_for.<locals>.<lambda><s���D�I�K�K�%�/�r)�callabler0�minrr��DEFAULT_SLEEP_TIMEr�)�condr��interval�ini�ret�stm�timeout_exprr�s       @rrwzUtils.wait_fors����,	
�#��	
����3�	���J�	���M�C�#��G����
�Y�[�[�7�
"�U�/�/�/�/�\�\��\��l�n�n�
�	�	�S�H�<�� <�
=�u�?W�	X�	X�3��:�c�?�?�?��

�*r�posixc��ddl}|dkrdS	tj|d��dS#t$r}|j|jkcYd}~Sd}~wwxYw)z6Check whether pid exists in the current process table.rNFT)�errnorJ�killr��EPERM)r}r�r�s   rr�zUtils.pid_existsHsu���<�<�<�	�A�g�g��5���G�C��O�O�O��4���"�"�"��7�e�k�!�!�!�!�!�!�!�����"���s�%�
A	�A�A	�A	c��ddl}|jj}d}|�|d|��}|dkr|�|��dSdS)NriTF)�ctypes�windll�kernel32�OpenProcess�CloseHandle)r}r�r��SYNCHRONIZE�processs     rr�zUtils.pid_existsUsX���=�=�=��m�$�8��;�
�
!�
!�+�q�#�
6�
6�7�
��l�l�����!�!�!��4��5rc�:�tj�tj�|����d}tjdkr3tj�||���	��}ntj||��}|S)Nrr
)rJ�path�splitext�basename�sys�version_info�	importlib�	machinery�SourceFileLoader�load_module�imp�load_source)�pythonModule�pythonModuleName�mods   r�load_python_modulezUtils.load_python_modulebs����W�%�%��7���L�!�!�#�#�#$�&�������	�	�	-�	-��l�
$�
$�$/�K�M�M��3�

���l�
$�
$�3�	�*r)r%TFTr^Nr)rArBrCrDr�r��DEFAULT_SHORT_INTERVALrx�objectrF�staticmethodrPr]r�rwrJrr�r�rErrrr:sQ��������������3�c�9��.�.�.�.�.�V�.�.�.�b����,������,��,�NR�#�DD�DD�DD��,�DD�L�%
�%
�%
��,�%
�R�G�w����
�
��<�
�
��
�
��<�
��	
�	
��,�	
�	
�	
rr)�
__author__�
__copyright__�__license__rHryrJrrsr��	threadingrr0�helpersrrr�collectionsr	r��importlib.machineryr�r�rArar��dict�__dict__rWr�rrErr�<module>r�sd��(B�
�k�
�����������	�	�	�	�
�
�
�
�����
�
�
�
�����������9�9�9�9�9�9�9�9�9�9�#�#�#�#�#�#���v������������
��8�	�	���D����$�E�E��/�'�'�)�)�E�E�E�E�E��r
�r
�r
�r
�r
�r
�r
�r
�r
�r
r