HEX
Server: LiteSpeed
System: Linux baran.dnsprotection.me 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64
User: ddir12 (3618)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/imunify360/venv/lib/python3.11/site-packages/im360/utils/__pycache__/__init__.cpython-311.pyc
�

q�Lj� ����ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZm
Z
ddlmZddlZddlmZeje��ZdZehd���Ze	d��ZGd	�d
e��ZGd�de��Zd
e
ededefd�ZGd�de��Zdej ej!ej"ej#ffd�Z$d�Z%dd�d�Z&de'fd�Z(de'fd�Z)de*de'fd�Z+de'fd�Z,de'fd�Z-dS)�N)�Path)�Any�Callable�Type)�
is_enabled)�LazyLocki�>;�www-data�systemd-network�systemd-resolve�systemd-timesync�lp�adm�bin�ftp�man�ntp�sys�www�bind�dbus�halt�mail�news�nscd�root�sshd�sync�uucp�cpses�games�httpd�mysql�named�nginx�plesk�redis�squid�apache�chrony�clamav�cpanel�daemon�docker�nobody�psaadm�psaftp�vsftpd�dnsmasq�dovecot�haproxy�mailman�polkitd�postfix�proftpd�varnish�_imunify�clamscan�diradmin�operator�postgres�shutdown�	memcached�
clamupdate�
containerd�cpaneleximfilterz2/etc/sysconfig/imunify360/imunify360-merged.configc��eZdZdS)�	RulesLockN��__name__�
__module__�__qualname__���I/opt/imunify360/venv/lib/python3.11/site-packages/im360/utils/__init__.pyrErE]��������DrKrEc��eZdZdS)�
ModSecLockNrFrJrKrLrOrOarMrKrO�error�value�returnc������fd�}|S)a.
    Decorator that causes coroutine to return *value* if it raises *error*.

    For example:

       return await return_value_on_error(FileNotFoundError, X)(coro)(*args)

    is equivalent to:

       try:
           return await coro(*args)
       except FileNotFoundError:
           return X
    c�L���tj������fd���}|S)Nc���K�	�|i|���d{V��S#�$r)}t�d|�����cYd}~Sd}~wwxYw)NzReplacing %s from %s with %s)�logger�info)�args�kwargs�e�cororPrQs   ���rL�wrapperz9return_value_on_error.<locals>.decorator.<locals>.wrappervsz�����
�!�T�4�2�6�2�2�2�2�2�2�2�2�2���
�
�
����:�A�t�U�K�K�K������������
���s�
�A�<�A�A)�	functools�wraps)r[r\rPrQs` ��rL�	decoratorz(return_value_on_error.<locals>.decoratorusC����	���	�	�	�	�	�	�	�	�
�	�	��rKrJ)rPrQr_s`` rL�return_value_on_errorr`es*���� 	�	�	�	�	�	��rKc���eZdZ�fd�Z�xZS)�PasswordChangeErrorc�V��t���d|�d|����dS)Nz)Password change process exited with code z: )�super�__init__)�self�stderr�
returncode�	__class__s   �rLrezPasswordChangeError.__init__�s<���
�����N�
�N�N�f�N�N�	
�	
�	
�	
�	
rK)rGrHrIre�
__classcell__)ris@rLrbrb�s8�������
�
�
�
�
�
�
�
�
rKrb�c����|t|��kr"td|�dt|�������ttt|����s
Jd���d�|���	d��fd�t|��D�����t�fd�|D����r�S�L)z�
    Return password with *length* char.
    It is guaranteed that password have at least one character from
    each given *required_char_groups*
    z
Given length=zR is too short. Can't get chars from all required groups len(required_char_groups)=zgot empty char group�Tc�8��g|]}tj�����SrJ)�secrets�choice)�.0�_�alphabets  �rL�
<listcomp>z,generate_strong_password.<locals>.<listcomp>�s#���L�L�L��G�N�8�4�4�L�L�LrKc3�P��K�|]�t�fd��D����V�� dS)c3� �K�|]}|�vV��	dS)NrJ)rq�c�groups  �rL�	<genexpr>z5generate_strong_password.<locals>.<genexpr>.<genexpr>�s'�����-�-�q��U�
�-�-�-�-�-�-rKN)�any)rqrx�passwords @�rLryz+generate_strong_password.<locals>.<genexpr>�sR������
�
�27�C�-�-�-�-�H�-�-�-�-�-�
�
�
�
�
�
rK)�len�
ValueError�all�map�join�range)�length�required_char_groupsrsr{s  @@rL�generate_strong_passwordr��s������(�)�)�)�)��
,�V�
,�
,��'�(�(�
,�
,�
�
�	
�
��� �	
�	
�����
�����w�w�+�,�,�H�	��7�7�L�L�L�L�e�F�m�m�L�L�L�M�M���
�
�
�
�;O�
�
�
�
�
�	��O�	rKc�v�ddlm}|r|���tvr)t�d|��|d|�����	t
j|��j}n#t$rYdSwxYw|tkr5t�d||��|d|�dt�d|�����dS)	Nr)�ValidationErrorz0Rejected password change for reserved account %rz9Refusing to change password for reserved system account: z;Rejected password change for non-tenant account %r (uid %d)z8Refusing to change password for non-tenant account (uid z < z): )�defence360agent.rpc_toolsr��lower�SYSTEM_USERNAMESrV�warning�pwd�getpwnam�pw_uid�KeyError�MIN_TENANT_UID)�usernamer��uids   rL�_assert_non_system_userr��s#��9�9�9�9�9�9��
�x�~�~�'�'�+;�;�;����>��	
�	
�	
��o�
%� �
%�
%�
�
�	
���l�8�$�$�+���������������
�^������I���	
�	
�	
�
�o�
<��
<�
<�*�
<�
<�/7�
<�
<�
�
�	
�
�s�A(�(
A6�5A6)�
passwd_cmdc��t|��|�!tjdtj���g}t|t��sJ�	tjg|�|�d�	|�
��gdz��dd���dS#tj$r}t|j
|j���d}~wwxYw)N�passwd)�path�
�T)�input�capture_output�check)r��shutil�which�os�defpath�
isinstance�list�
subprocess�runr��encode�CalledProcessErrorrbrgrh)r��new_passwordr�rZs    rL�change_system_passwordr��s����H�%�%�%����l�8�"�*�=�=�=�>�
��j�$�'�'�'�'�'�:���#�j�#�(�#��*�*�l�1�1�3�3�4�q�8�9�9���		
�	
�	
�	
�	
�	
���(�:�:�:�!�!�(�A�L�9�9�9�����:���s�AB�C�!B;�;Cc��td��}|���rW	|������}|dkS#t$rt
�d��YnwxYwdS)zHCheck if apache2nginx is enabled by reading /var/lib/apache2nginx/state.z/var/lib/apache2nginx/state�onz&Failed to read apache2nginx state fileF)r�is_file�	read_text�strip�OSErrorrV�	exception)�
state_file�contents  rL�is_apache2nginx_enabledr��s����3�4�4�J������G�	G� �*�*�,�,�2�2�4�4�G��d�?�"���	G�	G�	G����E�F�F�F�F�F�	G�����5s�+A�$A8�7A8c��	t���5}tj|��pi}ddd��n#1swxYwYnQ#t$rYdSt
tjf$r,}t�dt|��Yd}~dSd}~wwxYw|�	di���	dd��S)NTz6Failed to read %s: %s; assuming use_feature_flags=True�	WEBSHIELD�use_feature_flags)
�_MERGED_CONFIG_PATH�open�yaml�	safe_load�FileNotFoundErrorr��	YAMLErrorrVr��get)�fp�mergedrPs   rL�_use_feature_flags_from_yamlr��s��>�
 �
%�
%�
'�
'�	.�2��^�B�'�'�-�2�F�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.��������t�t��T�^�$�������D���	
�	
�	
�
�t�t�t�t�t�����
�����:�:�k�2�&�&�*�*�+>��E�E�Es=�A
�>�A
�A�A
�A�A
�

B�B�,!B�B�	flag_namec�D�t��sdSt|d���S)NF)�default)r��
is_ff_enabled)r�s rL�_feature_flag_enabledr�s(��'�)�)���u���E�2�2�2�2rKc� �td��S)N�coraza_for_cpanel_apache�r�rJrKrL�use_coraza4cpanelr�s�� �!;�<�<�<rKc� �td��S)N�coraza_for_cloudways_hybridr�rJrKrL� coraza_for_cloudways_hybrid_flagr�!s�� �!>�?�?�?rK).r]�loggingr�r�ror��stringr��pathlibr�typingrrr�'defence360agent.internals.feature_flagsrr�r��defence360agent.utilsr�	getLoggerrGrVr��	frozensetr�r�rErO�	Exceptionr`rb�ascii_lowercase�ascii_uppercase�digits�punctuationr�r�r��boolr�r��strr�r�r�rJrKrL�<module>r�s�����������	�	�	�	�
�
�
�
�����
�
�
�
�
�
�
�
�����������&�&�&�&�&�&�&�&�&�&�O�O�O�O�O�O�����*�*�*�*�*�*�	��	�8�	$�	$�����9�<�<�<�>�>��@�d�8����
	�	�	�	�	��	�	�	�	�	�	�	�	��	�	�	���i����������<
�
�
�
�
�)�
�
�
�������
���	�%�%�%�%�P
�
�
�6BF�
:�
:�
:�
:�
:� 	��	�	�	�	�+F�d�+F�+F�+F�+F�\3�S�3�T�3�3�3�3�=�4�=�=�=�=�@�$�@�@�@�@�@�@rK