CasperSecurity

Current Path : /lib/python3/dist-packages/fail2ban/server/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/fail2ban/server/__pycache__/utils.cpython-310.pyc

o

;s*b�0�@s�dZdZdZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlZddlm
Z
mZmZzddlmZWneyEeZYnwejd	krPddlZnddlZe
e�Zd
diZedd
�ej��D��ZGdd�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.ccs&�|]\}}|�d�r||fVqdS)�SIGN)�
startswith)�.0�name�num�r�7/usr/lib/python3/dist-packages/fail2ban/server/utils.py�	<genexpr>;s��rc@s�eZdZdZdZdZdZedZGdd�de�Z	e
dd	��Ze
d
d��Ze
	
	ddd��Z
e
ddd��Zejdkr@e
dd��Zne
dd��Ze
dd��ZdS)�UtilszPUtilities provide diverse static methods like executes OS shell commands, etc.
	rg�������?g����MbP?�dc@sLeZdZdZdd�Zddd�Zdd	�Zddd�Zd
d�Zdd�Z	dd�Z
d
S)zUtils.Cachez.A simple cache with a TTL and limit on size
		cOs$|j|i|��t�|_t�|_dS�N)�
setOptionsr�_cacher�_Cache__lock)�self�args�kwargsrrr�__init__LszUtils.Cache.__init__���<cCs||_||_dSr)�maxCount�maxTime)rr r!rrrrQs
zUtils.Cache.setOptionscCs
t|j�Sr)�lenr�rrrr�__len__Us
zUtils.Cache.__len__NcCs6|j�|�}|r|dt��kr|dS|�|�|S)N�r)r�get�time�unset)r�k�defv�vrrrr&Xs
zUtils.Cache.getcCst��}|j}|j�pt|�|jkrittur1|r0|jdd�\}}|d|kr.t|�|jkr.n|sn8g}|��D]\}}|d|krF|�	|�q7|D]	}|j�
|d�qI|rit|�|jkri|��|rit|�|jks\|||jf||<Wd�dS1s}wYdS)NF)�lastr%)r'rrr"r r�dict�popitem�items�append�popr!)rr)r+�t�cache�ck�cv�remlstrrr�set`s.��
��"�zUtils.Cache.setcCs:|j�|j�|d�Wd�dS1swYdSr)rrr1)rr)rrrr(|s"�zUtils.Cache.unsetcCs6|j�|j��Wd�dS1swYdSr)rr�clearr#rrrr8�s"�zUtils.Cache.clear)rrr)�__name__�
__module__�__qualname__�__doc__rrr$r&r7r(r8rrrr�CacheHs

r=cCs>t�|tj�}|s|tjO}n|tjM}t�|tj|�|Sr)�fcntl�F_GETFL�os�
O_NONBLOCK�F_SETFL)�fhandle�value�flagsrrr�
setFBlockMode�szUtils.setFBlockModecCsld}t|t�s
|g}t|�d}|��D]\}}|d||f7}|�|�|d7}q|d|d|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%s=$%s �
r)�
isinstance�listr"r/r0)�realCmd�varsDict�varsStat�ir)r+rrr�
buildShellCmd�s


zUtils.buildShellCmdrTF�rNc
s�d}}d}	d�}
|r|rt��|��nttj|�}
t�����fdd�}z�tj�tjtj||
tj	d����
�}	|	durQ�fdd�}t�||tj�}	|	rQ|	d}	|	dur�|r^|t
j�d}t�d�|f�t��j�}
t�|
tj�t�tj���
�}	|	dus�|r�t�|
tj�t�tj�|	dur���
�}	|	dur�t�|
�s�tj}	Wn8ty�}z,|r�|t
j�d}d	�|f}t�|��s�|s�d
nd
|||	fWYd}~SWYd}~nd}~ww|	|vr�t
jnt
j}|t��k�r|�r||t
jkr�|dnt
j�d}|�s
|t��k�r��j�rfz|	du�s|	dk�r#t��jd
��j� �}Wnt!�yB}zt�d|�WYd}~nd}~ww|du�rf|d
k�rf|t��k�rf|�"�D]
}t�#|d�t$|���qX�j%�r�z|	du�su|	dk�r|t��j%d
��j%� �}Wnt!�y�}zt�d|�WYd}~nd}~ww|du�r�|d
k�r�|t��k�r�|�"�D]
}t�#|d�t$|���q��j�rȈj�&��j%�rшj%�&�d
}|	|v�r�t�'d�|	�d}nM|	du�r�t�d��j�n?|	dk�s�|	dk�r|	dk�r|	n|	d}t�d�t(�)|d|�|	�nt*�)|	d�}t�d�|	�|�r/t�+d|	|t,��|�r8||||	fSt-|�dk�rA|S||	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.
		Ncst�|d���S)Nz%x -- exec: %s)�logSys�log)�level)rK�	realCmdIdrr�<lambda>�sz"Utils.executeCmd.<locals>.<lambda>)�stdout�stderr�shell�env�
preexec_fncs���}|durd|fSdS)NT)�poll)�retcode)�popenrr�_popen_wait_end�sz)Utils.executeCmd.<locals>._popen_wait_endr%z!%x -- timed out after %s seconds.z%s -- failed with %sFrz  ... -- failed to read stdout %srGz%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).rrOrr@�environ�id�
subprocess�Popen�PIPE�setsidr[�wait_for�DEFAULT_SHORTEST_INTERVAL�logging�ERRORrQ�error�getpgid�pid�killpg�signal�SIGTERMr'�sleep�DEFAULT_SLEEP_INTERVAL�SIGKILL�
pid_exists�OSError�DEBUG�getEffectiveLevelrVrF�read�IOError�
splitlinesrRrrW�close�debug�signamer&�_RETCODE_HINTS�info�localsr")rK�timeoutrX�output�tout_kill_tree�
success_codesrLrVrWr\rY�logCmdr^�pgid�e�	std_level�l�success�sigcode�msgr)r]rKrTr�
executeCmd�s� ���
 ���&��"��"

�zUtils.executeCmdcsxd}	|�}|r
|S|r(d}}t|�s!t��|��fdd�}n|}|s(tj}|�r.	|St||tj�}t�|�q)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%Trcst���kSr)r'r��time0rrrULsz Utils.wait_for.<locals>.<lambda>)�callabler'rrq�min�DEFAULT_SLEEP_TIMErp)�condr��interval�ini�ret�stm�timeout_exprrr�rrf-s&�
�zUtils.wait_for�posixc
CsXddl}|dkr
dSz	t�|d�WdSty+}z|j|jkWYd}~Sd}~ww)z6Check whether pid exists in the current process table.rNFT)�errnor@�killrt�EPERM)rlr�r�rrrrsZs���zUtils.pid_existscCs<ddl}|jj}d}|�|d|�}|dkr|�|�dSdS)NriTF)�ctypes�windll�kernel32�OpenProcess�CloseHandle)rlr�r��SYNCHRONIZE�processrrrrsgs
cCsHtj�tj�|��d}tjdkrtj�||��	�}|St
�||�}|S)Nrr	)r@�path�splitext�basename�sys�version_info�	importlib�	machinery�SourceFileLoader�load_module�imp�load_source)�pythonModule�pythonModuleName�modrrr�load_python_modulets 
��
����zUtils.load_python_module)rTFTrPNr)r9r:r;r<r�rq�DEFAULT_SHORT_INTERVALrg�objectr=�staticmethodrFrOr�rfr@rrsr�rrrrr>s2=
	
�
+
r)�
__author__�
__copyright__�__license__r>rhr@rnrbr��	threadingrr'�helpersrrr�collectionsr�ImportErrorr-r��importlib.machineryr�r�r9rQr}�__dict__r/r|rrrrr�<module>s6�

��
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY