HEX
Server: LiteSpeed
System: Linux catuipe.dhs10.info 4.18.0-553.111.1.lve.el8.x86_64 #1 SMP Fri Mar 13 13:42:17 UTC 2026 x86_64
User: paradatacom (1125)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //usr/share/cagefs/__pycache__/cagefsreconfigure.cpython-311.pyc
�

��ljt����ddlTddlZddlZddlZddlZddlZddlZddlZddl	m
cmZddl
Z
ddlmZddlZddlmZddlmZddlZddlZddlZddlZddlmZmZddlmZmZddlm Z m!Z!m"Z"d	a#d
Z$dZ%dZ&d
Z'dZ(dZ)dZ*dZ+dZ,d�Z-dZ.d�Z/d�Z0d�Z1d�Z2d3d�Z3d�Z4d�Z5d�Z6d�Z7d4d�Z8d �Z9d!�Z:d"�Z;e$fd#�Z<d$�Z=d%�Z>d&�Z?d'�Z@d(�ZAd)�ZBd*�ZCd+�ZDd4d,�ZEd4d-�ZFd.�ZGd/�ZHd0�ZId1�ZJd2�ZKdS)5�)�*N)�parse)�touch)�write_file_content)�is_ea4_enabled�read_cpanel_ea4_php_conf)�PROXY_COMMANDS�check_cagefs_skeleton)�mod_makedirs�get_file_lines�delete_line_from_file�z/usr/local/bin/lsphpz/var/run/postgresz/etc/sysconfig/postgresz/var/run/postgresqlz
hdir:/.cagefsz!/etc/cagefs/cagefs.base.home.dirsz/var/lib/php/sessionz/usr/local/directadmin/sharedz"/usr/local/directadmin/directadminc��tj��sdStj�t
��r.t
jd�t
����dSd�tj
��}	tj�t
��r[tt
d��5}|�
��}||vr|�|��ddd��n#1swxYwYnWtt
d��5}|�d��|�|��ddd��n#1swxYwYtjt
d��dS#t t"f$r3}t
jdt
t%|����Yd}~dSd}~wwxYw)Nz!Error: "{}" shouldn't be a folderz
^{}/[^/]+
zr+�wzmount_basedir=1
�zFailed to write )�detect�is_plesk�os�path�isdir�PLESK_BASE_HOME_DIRS_FILE�secureio�print_error�format�	cagefslib�PLESK_VHOSTS_D�exists�open�	readlines�write�chmod�OSError�IOError�str)�current_vhosts_d_regexp�f�content�es    �e/builddir/build/BUILDROOT/cagefs-7.6.44-1.el8.cloudlinux.x86_64/usr/share/cagefs/cagefsreconfigure.py�create_plesk_base_home_dirsr*7s���?������	�w�}�}�.�/�/����0�7�7�8Q�R�R�	
�	
�	
�	��+�2�2�9�3K�L�L��T�
�7�>�>�3�4�4�	1��/��6�6�
5�!��+�+�-�-��*�'�9�9��G�G�3�4�4�4�
5�
5�
5�
5�
5�
5�
5�
5�
5�
5�
5����
5�
5�
5�
5��
�/��5�5�
1�����+�,�,�,����/�0�0�0�
1�
1�
1�
1�
1�
1�
1�
1�
1�
1�
1����
1�
1�
1�
1�	��*�E�2�2�2�2�2���W��T�T�T���/�1J�C�PQ�F�F�S�S�S�S�S�S�S�S�S�����T���s`�9E:�.C;�/E:�;C?�?E:�C?�E:�+E�E:�E�E:�E�E:�:F>�(F9�9F>z//usr/local/cpanel/sys_cpanel/boxtrapper-messagec�2�ttd���dS)NT��	read_only)�add_mount_to_cagefs_mp�BOX_TRAPPER_DIR��r)�add_boxtrapper_dir_cpanelr2Ss���?�d�;�;�;�;�;�;r1c�4�ttdd���dS)NT�700��personal�perm)r.�PLESK_PHP_SESSION_DIRr0r1r)�add_php_session_dir_pleskr9Ws���0�4�e�L�L�L�L�L�Lr1c�6�d}|D]}t|d����dS)z;
    Add mounts related to ClamAV into cagefs.mp file.
    )z/usr/local/share/clamavz/var/lib/clamavTr,N�r.)�clamav_database_dirs�	directorys  r)�add_mounts_for_clamavr>[s:��J��)�:�:�	��y�D�9�9�9�9�9�:�:r1c�6�d}|D]}t|d����dS)zF
    Add mounts related to Phusion Passenger into cagefs.mp file.
    )z/var/run/ea-passenger-runtimez/usr/share/passengerz/usr/libexec/passengerFr,Nr;)�passenger_dirsr=s  r)�add_mounts_for_passengerrAds:���N�
$�;�;�	��y�E�:�:�:�:�:�;�;r1Fc��|r|rtd���ddl}|s tj�|���rtj�d��r�|���|�|jdd���}|dz|j	vr�|tj|j|j
|j|j��vr~|rd|z}|r|dz|z}n|rd	|z}t!dd
��}|�|���dz��|���t)d��dSdSdSdSdS)Nz5read_only and personal can`t be true in the same timerz/etc/cagefs/cagefs.mpT)r�skip_errors�skip_cpanel_check�
�@�,�!�atz/usr/share/cagefs/need.remount)�
ValueError�	cagefsctlrrr�isfile�
check_mp_file�MountpointConfig�
ETC_MPFILE�
common_mounts�	itertools�chain�read_only_mounts�personal_mounts�splitted_by_username_mounts�splitted_by_uid_mountsrr �strip�closer)�liner-r6r7rK�	mp_configr&s       r)r.r.qs����R�X�R��P�Q�Q�Q������4�B�G�M�M�$�'�'�4�R�W�^�^�<S�-T�-T�4����!�!�!��.�.��%��"�/�
�
�	�
�$�;�i�5�5�5�$�i�o��&��%��1��,�	G
�G
�;
�;
��
"��T�z���-��#�:��,�D���
"��T�z���,�d�3�3�A�
�G�G�D�J�J�L�L�4�'�(�(�(�
�G�G�I�I�I��2�3�3�3�3�3�-4�4�4�4�6�5�;
�;
r1c���tj�|��}d�|�d��D��}tjdtjtjztjz��}|g}	|}|D�]}	tj||d���}	n<#t$r/Y|D]'}
	tj
|
���#t$rY�$wxYwdSwxYwtj|	j
��rtd���tj|	j
��std���tj|tjtjztjztjz|���}
|�|
��|
}��	tj|||��|D]'}
	tj
|
���#t$rY�$wxYwdS#|D]'}
	tj
|
���#t$rY�$wxYwwxYw)aChown ``path`` after opening it via an O_NOFOLLOW component-by-
    component walk anchored at ``/``.

    F-06 (CLOS-5944) DiD, follow-up to the AI-scanner HIGH: opening only
    the final component with O_NOFOLLOW still lets a writable ancestor
    (e.g. an attacker-controllable segment above the configured
    SOCK_DIR) redirect the resulting fd via an ancestor-symlink swap
    between path resolution and open. Walking every component with
    lstat + O_NOFOLLOW + O_DIRECTORY closes that window: a symlink at
    any depth causes the walk to raise before the fchown runs.

    Silently returns when the path does not yet exist (there is nothing
    to chown; the caller mod_makedirs above creates it first).
    Raises OSError on a non-directory or symlinked component.
    c��g|]}|�|��Sr0r0)�.0�cs  r)�
<listcomp>z-_chown_via_component_walk.<locals>.<listcomp>�s��6�6�6��A�6�!�6�6�6r1�/F)�dir_fd�follow_symlinksNzOperation not permitted.)ra)rr�abspath�splitr�O_RDONLY�O_DIRECTORY�	O_CLOEXEC�stat�FileNotFoundErrorrXr"�S_ISLNK�st_mode�PermissionError�S_ISDIR�
O_NOFOLLOW�append�fchown)r�uid�gid�abs_path�
components�base_fd�opened�
current_fd�comp�st�fds           r)�_chown_via_component_walkr{�sO�� �w���t�$�$�H�6�6�X�^�^�C�0�0�6�6�6�J��g��R�[�2�>�
)�B�L�
8���G��Y�F���
��	�	�D�
��W�T�*�e�L�L�L����$�
�
�
����	�	�B�
����������
�
�
���
����	�	�
�����|�B�J�'�'�
B�%�&@�A�A�A��<��
�+�+�
B�%�&@�A�A�A������b�m�+�b�n�<�r�|�K�!����B�

�M�M�"�����J�J�
�	�*�c�3�'�'�'��	�	�B�
����������
�
�
���
����	�	��&�	�	�B�
����������
�
�
���
����	���sy�<G�B�G�
C�&G�-C�
C�C�C�C
G�$F9�9
G�G�G7�G&�%G7�&
G3	�0G7�2G3	�3G7c�&�tj���r�tj�t
��st
t��dStjt
dd��}|dkrt}nh|tkr]	tj
|t��nA#tf$r3}tj
dtt|����Yd}~dSd}~wwxYw	tjd��}n;#t"f$r-}tj
dt|����Yd}~dSd}~wwxYw|j}|j}tj�|��sN	t+|d	��n<#tf$r.}tj
d
|t|����Yd}~dSd}~wwxYw	t-|||��n<#tf$r.}tj
d|t|����Yd}~dSd}~wwxYwt
t��dSdS)NT�SOCK_DIR�=rzfailed to create symlinkF�postgreszfailed to find 'postgres' user���failed to createzfailed to change owner of)r�detect_postgresqlrrrL�
POSTGRES_CONFr.�POSTGRES_CL7_FOLDER�get_param_from_file�DEFAULT_POSTGRES_FOLDER�symlinkr"rrr$�pwd�getpwnam�KeyError�pw_uid�pw_gid�lexistsrr{)�postgres_folderr(�pg_user�postgres_uid�postgres_gids     r)�postgresql_configurer��sK��
��!�!�4��w�~�~�m�,�,�	�"�#6�7�7�7��4� �4�]�J�PS�T�T���b� � �5�O�O�
� 7�
7�
7�
��
�?�,C�D�D�D�D���:�
�
�
��$�.�0G��Q�������u�u�u�u�u�����	
����	��l�:�.�.�G�G���{�	�	�	�� �!A�3�q�6�6�J�J�J��5�5�5�5�5�����	�����~���~���w����/�/�	�
��_�e�4�4�4�4���:�
�
�
��$�%7��#�a�&�&�Q�Q�Q��u�u�u�u�u�����
����	�%�o�|�\�R�R�R�R���z�	�	�	�� �+�_�c�!�f�f�
�
�
��5�5�5�5�5�����		����	�6�7�7�7��t��5s`�B�C�*(C�C�!C6�6D.�"D)�)D.�E0�0F)�;#F$�$F)�-F?�?G8�
#G3�3G8c�@�tdkr�	tjtj��adS#ddl}t
|���tj	���tjdtjzdz��tjd��YdSxYwdS)Nrr��file�bad � file�)
�
LITESPEED_XML�xmlrr�LITESPEED_CONFIG_FILE�	traceback�print�
format_exc�sys�stderrrr�exit)r�s r)�litespeed_config_readr�s�������	��I�f�&B�C�C�M�M�M��	������)�&�&�(�(�s�z�:�:�:�:�� ��&�*F�!F��!P�Q�Q�Q��H�Q�K�K�K�K�K�K�����s
�-�A+Bc�D�tj��r�tjtjtjdz��ttjd��}|�t�ddd�����|�	��dSdS)Nz.cagefs�wbrzUTF-8)�indent�newl�encoding)
r�detect_enterprise_litespeed�shutil�copyfiler�rr r��toprettyxmlrX)r&s r)�litespeed_config_writer�s���
�)�+�+�����(�&�*F��*R�	
�	
�	
�
��-�t�4�4��	���
�)�)��"�w�)�O�O�P�P�P�	���	�	�	�	�	�
�r1c���tj���r`t��|�d}n|}	t�d��d�d��djj}|}|�t|��dkrRt|��t�d��d�d��dj_|}n�#t$r�t�
d��}t�t|����}|�|��t�d��d�|��|}YnwxYw|SdS)N��httpServerConfigr�	enableLVE�
rr�r�r��getElementsByTagName�
firstChild�	nodeValue�intr$�
IndexError�
createElement�createTextNode�appendChild)�force_value�	new_value�enableLVE_value�resultr�s     r)�litespeed_enableLVE_configurer�s���
�)�+�+���������I�I�#�I�	��2�2�3E�F�F�q�I�%�%�k�2�2�1�6��I�
�
%�F��&�#�o�*>�*>��*B�*B�OR��O�O��2�2�3E�F�F���&�&�{�3�3�A�7�7A�)�#�����	�	�	�%�3�3�K�@�@�I�+�:�:�3�y�>�>�J�J�O��!�!�/�2�2�2��.�.�/A�B�B�1�E�Q�Q��
�
�
��F�F�F�	�����
�9�s�B,C�BE0�/E0c���tj���rSt��	t�d��d�d��djj}t|��dkrRtd��t�d��d�d��dj_dSdS#t$r�t�
d��}t�td����}|�|��t�d��d�|��YdSwxYwdS)Nr�r�	phpSuExecr�r�)�phpSuExec_valuer�s  r)�litespeed_phpSuExec_configurer�@sd��
�)�+�+������	��2�2�3E�F�F�q�I�%�%�k�2�2�1�6��I�
�
�?�#�#�q�(�(�OR�RS�f�f��2�2�3E�F�F���&�&�{�3�3�A�7�7A�)�)�)�)�(���	�	�	�%�3�3�K�@�@�I�+�:�:�3�q�6�6�B�B�O��!�!�/�2�2�2��.�.�/A�B�B�1�E�Q�Q��
�
�
�
�
�
�		�����s�B&C�BE%�$E%c�8�tj��}t�d��d�d��}|sQt	|��t	d��kr1tdtjzdzdzdztj�	��|S)
z�
    CAG-914
    Check if there is extProcessorList section
    If not, print doc link to configure LiteSpeed
    Starting from LSWS v5.3 external apps and script handlers are no longer required.
    r�r�extProcessorListz5.3z%No extProcessorList section in file:
z'
Please configure LiteSpeed Web Server z+using Web Admin Console as discribed here:
z;https://docs.cloudlinux.com/php_selector/#litespeed-supportr�)	r�get_litespeed_versionr�r��
parse_versionr�r�r�r�)�litespeed_version�checks  r)�check_extProcessorListr�Vs����4�6�6���.�.�/A�B�B�	�
���-�.�.�
��
�]�#4�5�5�
�e�8L�8L�L�L�
�4��*�
+�8�
9�=�
=�L�	
L�
��
	
�	
�	
�	
��Lr1c�.�tj���rt��	t��}|sdS|d�d��}|D�]D}t|�d��djj��dk�r
	|�d��djdkrht|�d��djj��}|dvr2td��|�d��dj_��#t$rot�
d��}t�td����}|�|��|�|��Y��@wxYw��FdS#t$rmddl
}t|���t j���t%jd	tjzd
z��t!jd��YdSwxYwdS)NTr�extProcessor�name�lsphp5�runOnStartUp)�1�0r�r�r�r�)rr�r�r�r�r$r�r�r�r�r�r�r�r�r�r�r�r�rrr�r�)�check_nodelist�nodelist�node�runOnStartUp_valuer�r�s      r)� litespeed_runOnStartUp_configurer�os3��
�)�+�+�$�����"	�3�5�5�N�!�
��t�%�a�(�=�=�n�M�M�H� �
7�
7����1�1�&�9�9�!�<�G�Q�R�R�� � �7� �5�5�n�E�E�a�H�S�#�$�$�25� $� 9� 9�.� I� I�$%�!"�",�Y�2�2�.�
 2��C�C�:=�Q���!%� 9� 9�.� I� I�$%�!"�",�Y���%�7�7�7�'4�'B�'B�>�'R�'R��-:�-I�-I�#�a�&�&�-Q�-Q�*�$�0�0�1C�D�D�D��(�(��6�6�6�6�6�	7����# �
7�
7��0�	�	�	������)�&�&�(�(�s�z�:�:�:�:�� ��&�*F�!F��!P�Q�Q�Q��H�Q�K�K�K�K�K�K�	����?$�$s>�F�AF�BD�F�A5F�F�F�F�A3H�Hc�x�tj���r%t��	t��}|sdS|d�d��}|D]j}t|�d��djj��dkr2t|��|�d��dj_�kny#t$rlddl	}t|���tj
���tjd	tjzd
z��tjd��YnwxYwdSdS)
z:
    LiteSpeed extProcessorList->path change for php5
    Trr�r�r�rNr�r�r�r�F)rr�r�r�r�r$r�r�r�r�r�r�r�r�rrr�r�)�lsphp5_pathr�r�r�r�s     r)�litespeed_lsphp5_path_changer��sR���)�+�+������	�3�5�5�N�!�
��t�%�a�(�=�=�n�M�M�H� �
�
����1�1�&�9�9�!�<�G�Q�R�R�� � �QT�#�Q�Q�D�-�-�f�5�5�a�8�C�M��
���	�	�	������)�&�&�(�(�s�z�:�:�:�:�� ��&�*F�!F��!P�Q�Q�Q��H�Q�K�K�K�K�K�	�����t��us�B?�BB?�?A3D5�4D5c�h�	tjddd|gd���dS#tj$rYdSwxYw)zO
    Perform '/usr/local/directadmin/custombuild/build set cagefs' command
    �(/usr/local/directadmin/custombuild/build�set�cagefsT�r�N��
subprocess�run�CalledProcessError)�options r)�custombuild_set_cagefsr��s`�����
7���&�Q��	
�	
�	
�	
�	
�	
���(����������s��1�1c�d�	tjddgd���dS#tj$rYdSwxYw)zR
    Perform '/usr/local/directadmin/custombuild/build rewrite_confs' command
    r��
rewrite_confsTr�Nr�r0r1r)�custombuild_rewrite_confsr��s\�����
7��I��	
�	
�	
�	
�	
�	
���(����������s��/�/c��	t��td��t��t��t	��dS#YdSxYw�Nr�TF)r�r�r�r�r�r0r1r)�litespeed_configure_selectorr��sZ���$�&�&�&�%�a�(�(�(�%�'�'�'�(�*�*�*�� � � ��t����u�u���s�AA�Ac��tj��r2tj��rtd��t	��dSdS)z;
    OpenLitespeed configure for CageFS on DirectAdmin
    �yesTF)r�detect_open_litespeed�is_dar�r�r0r1r)�configure_open_litespeedr��sF���#�%�%��&�,�.�.���u�%�%�%�!�#�#�#��t��5r1c��	tt����dkrt��t��dS#YdSxYwr�)r�r�r�r�r0r1r)�litespeed_configurer��sN����,�.�.�/�/�1�4�4�)�+�+�+�� � � ��t����u�u���s	�;?�Ac
���d}tj��rtj�|��sdS	tj|dd��}|�d��}t|��dkr|d}|dkrdStj	d|gd	td
��tjtjddd�
��}|j
���}tdd��}|�|dz��|���tjdd��dS#t$t&f$r-}t)jdt-|����Yd}~dSd}~wwxYw)Nz/usr/local/assp/assp.cfg�sendAllSpamz:=rFr�r�rz/scripts/whoownsFz	/dev/nullTz	/scripts/)�shell�stdin�stdoutr��	close_fds�cwd�textz/etc/cagefs/exclude/assp-deluxerrErz*Failed to disable CageFS for ASSP Deluxe: )r�	is_cpanelrrrLr�rd�lenr��Popenr�PIPE�STDOUTr��readr rXr!r"r#rrr$)�config_file�
adm_domain�parts�p�	user_namer&r(s       r)�disable_cagefs_for_assp_deluxer�s���,�K������R�W�^�^�K�%@�%@����S��/��]�D�Q�Q�
�� � ��%�%���u�:�:��?�?��q��J������F�
��
��,���{�#�#��?��$����	
�	
�	
���H�M�M�O�O�	�
�2�C�8�8��	���	�D� �!�!�!�	���	�	�	�
��2�E�:�:�:�:�:���W��S�S�S���I�3�q�6�6�R�R�R�R�R�R�R�R�R�����S���s�AD1�B)D1�1E/�"E*�*E/c��tj��tjd}t��rwtj�|��sXt��}|rH	|d}n#t$rgcYSwxYw|�	d��sgSd�
|��}tj�|��r|tj||d��fgStjdt|����gS)z�
    Return parameter and its value from native php.ini
    :param param_name: name of parameter in php.ini
    :type param_name: string
    zphp.ini�defaultzea-phpz/opt/cpanel/{}/root/etc/php.inir~�failed to open file)r�read_native_conf�
orig_binariesrrrrLrr��
startswithrrr�rrr$)�
param_name�ini_file�conf�default_phps    r)�get_native_settingsrs���� � � ��&�y�1�H����M�����x� 8� 8�M�'�)�)���		M�
�"�9�o�����
�
�
��	�	�	�
�����)�)�(�3�3�
��	�8�?�?��L�L�H�	�w�~�~�h���U��V�7��*�c�R�R�S�T�T���.��H�
�
�>�>�>�
�Is�$A-�-A<�;A<c��d}g}tj�|��r�t|��}t	jdd���}	|�|��n#tj$rgcYSwxYw|���D]*}|�	|�
|�����+|���|S)z-
    Return settings from global_php.ini
    z/etc/cl.selector/global_php.iniNF)�
interpolation�strict)rrrLr�configparser�ConfigParser�readfp�Error�sections�extend�itemsrX)�
GLOBAL_INI�settingsr&�cfg�sects     r)�get_global_php_settingsr6s���3�J��H�	�w�~�~�j�!�!�	�������'�d�5�I�I�I��	��J�J�q�M�M�M�M���!�	�	�	��I�I�I�	�����L�L�N�N�	-�	-�D��O�O�C�I�I�d�O�O�,�,�,�,�	���	�	�	��Os�
A � A4�3A4c	��|sdS|gkrddg}n|�g}tj��D�]}tj�d|d��}tj�|���r�t
|d��}|���}|D�];}d}tj	d|d	zd
z��}ttt|������D]�}	|�
||	��}
|
r�|r$||	d	dkrd||	zdz||	<�E||	�d
d��\}}|���dvs*|���r|���|vr|d	dz|dzdz||	<d}��|s*|�|d	dz|dzdz����=|���t
|d��}|�|��|������t'jdt+|������dS)av
    Replace or add settings in php.ini for all alt-php versions
    :param settings: list of tuples like [('date.timezone', 'Europe/Moscow'), ('error_log', 'error_log')]
    :param overwrite_list: list of options to overwrite; empty list [] == overwrite all the two options ('error_log', 'date.timezone')
                           None == do not overwrite the options
    N�	error_log�
date.timezonez	/opt/alt/zetc/php.ini�rFz;*\s*rz\s*=.*�;rEr~r�)r r!z = Trr)r�get_alt_dirsrr�joinrLrr�re�compile�reversed�ranger��matchrdrWrorX�
writelinesrrr$)
r�overwrite_list�alt_dirrr&r��setting�changed�prog�ir��param�values
             r)�reconfigure_alt_settingsr4IsL����������%��7���	�	����)�+�+�C�C���w�|�|�K��-�@�@��
�7�>�>�$���	C��T�3���A��;�;�=�=�D�#�
H�
H�����z�'�G�A�J�"6��"A�B�B��!�%��D�	�	�"2�"2�3�3�+�+�A�!�Z�Z��Q��0�0�F��+�"�+�#�A�w�q�z�S�0�0�*-��Q��-�$�*>��Q���+/��7�=�=��a�+@�+@�L�E�5� %���
�
�5S� S� S�',�{�{�}�}�!T�#(�;�;�=�=�N�#B�#B�*1�!�*�u�*<�w�q�z�*I�D�*P��Q��&*�G���H��K�K���
�U� 2�W�Q�Z� ?�$� F�G�G�G��
�G�G�I�I�I��T�3���A�
�L�L�����
�G�G�I�I�I�I�� �!6��D�	�	�B�B�B�B�=C�Cr1c�v�d}|��g}|r�|D]�}t|�d����}|�ddg��sAtd��td��td��t	jd��|�|����t��}td	�|D����d
kr"|�td����td�|D����d
kr"|�td����t||��dS)a&
    Replace or add settings in php.ini for all alt-php versions
    :param options: list of options to overwrite; empty list [] == overwrite all the two options ('error_log', 'date.timezone')
                                    None == do not overwrite the options
    :type options: list
    NrGr r!z<Error: incorrect parameter of --apply-global-php-ini option:zGPlease use 0, 1 or 2 parameters from the list: error_log, date.timezonezausing --apply-global-php-ini without arguments applies all global php options including two abover�c�*�g|]}|ddk�|��S)rr r0�r]�xs  r)r_z(replace_alt_settings.<locals>.<listcomp>�s&��7�7�7�!�1�Q�4�;�#6�#6�A�#6�#6�#6r1rc�*�g|]}|ddk�|��S)rr!r0r7s  r)r_z(replace_alt_settings.<locals>.<listcomp>�s&��;�;�;�!�1�Q�4�?�#:�#:�A�#:�#:�#:r1)r�rd�issubsetr�r�r�rrr�rr4)�optionsr,�arg�srs     r)�replace_alt_settingsr>ws_���N������	)��

)�

)����	�	�#���'�'���z�z�;��"@�A�A�
 ��V�����a�����{�����H�Q�K�K�K��%�%�a�(�(�(�(�&�(�(�H�
�7�7�x�7�7�7�8�8�A�=�=����+�K�8�8�9�9�9�
�;�;�x�;�;�;�<�<��A�A����+�O�<�<�=�=�=��X�~�6�6�6�6�6r1c�&�tj��sdS	tj�d��r�tdd��}|���}|���d}|D]$}|�t��dkrd}n�%|s0|�
dtzdz��td|��n-tdtdz��tjdd��tj�d��r�tdd��}|���}|���d}|D]-}|�
���d	��rd}n�.|s'|�
d
��td|��dSdStdd��tjdd��dS#tt f$r-}t#jdt'|����Yd}~dSd}~wwxYw)
Nz/etc/cxs/cxs.ignorer"F���TrEi�z/etc/cxs/cxs.defaultzignore=/etc/cxs/cxs.ignorez
ignore=/etc/cxs/cxs.ignore
zignore=/etc/cxs/cxs.ignore
z/Failed to change CXS configuration for CageFS: )r�	CXS_checkrrrLrrrX�find�CXS_IGNORE_COMMANDrorr!rWr
r"r#rrr$)r&r'�CXS_HOOK_INSTALLEDrY�IGNORE_HOOK_INSTALLEDr(s      r)�
configure_cxsrF�sM���������%X�
�7�>�>�/�0�0�	3��*�C�0�0�A��k�k�m�m�G�
�G�G�I�I�I�!&���
�
���9�9�/�0�0�B�6�6�)-�&��E�7�&�
C����t�&8�8�4�?�@�@�@�"�#8�'�B�B�B���4�6H�4�6O�P�P�P��H�*�E�2�2�2��7�>�>�0�1�1�	4��+�S�1�1�A��k�k�m�m�G�
�G�G�I�I�I�$)�!��
�
���:�:�<�<�*�*�+G�H�H��,0�)��E��)�
D����I�J�J�J�"�#9�7�C�C�C�C�C�
D�
D�
�5�7U�V�V�V��H�+�U�3�3�3�3�3���W��X�X�X���N�PS�TU�PV�PV�W�W�W�W�W�W�W�W�W�����X���s�FG�+%G�H�#"H�Hc�N�tj�t��rt	t��dS	ttd��t	t��dS#t$r3}tjdtt|����Yd}~dSd}~wwxYw)a�
    Create '/usr/local/directadmin/shared' directory if it doesn't already exist
    and add a corresponding line into the '/etc/cagefs/cagefs.mp' file.

    This directory is intended for storing files available to all users.
    Recent versions of DA panel will create this directory themselves,
    creation of the directory in our code is made for backwards compatibility
    with older DA panels.
    r�r�N)
rrr�
DA_SHARED_DIRr.rr"rrr$)r(s r)�_add_da_shared_dir_to_cagefs_mprI�s���
�w�~�~�m�$�$�2��}�-�-�-�-�-�	2����.�.�.�
#�=�1�1�1�1�1���	L�	L�	L�� �!3�]�C��F�F�K�K�K�K�K�K�K�K�K�����	L���s�A'�'
B$�1(B�B$c
�H�dt��}tj��ttj��td��kr�	tt��}|d�|D��vrj|r |d���dz|d<|�|dz��tj
d�|��td��d
Sd
S#t$r5}tj
d|d	tt|����Yd
}~d
Sd
}~wwxYw	tt|��nA#t$r4}tj
d|dtt|����Yd
}~nd
}~wwxYwt!��r#t#jgd
�t�d�d���d
Sd
S)a�
    Add a line containing the path to DA binary into the 'proxy.commands' file
    if DA panel version < 1.62.8. If DA panel version >= 1.62.8 remove this line.

    Starting '1.62.8' version DA no longer supports having suid bit set on DA binary,
    version < 1.62.8 means DA binary have suid bit, it should be executed via proxyexec,
    hence, we should add a line that contains path to DA binary
    into the 'proxy.commands' file if it is not already there.
    zDIRECTADMIN=z1.62.8c3�>K�|]}|���V��dS�N)rW)r]rYs  r)�	<genexpr>z8_configure_proxy_commands_file_for_da.<locals>.<genexpr>�s*����%S�%S�t�d�j�j�l�l�%S�%S�%S�%S�%S�%Sr1r@rErrz
failed to add�intoNzfailed to remove�from)z/usr/sbin/cagefsctlz--wait-lockz
--update-listT)�inputr�)�DA_BINr�getCPr��
CP_VERSIONrr	rWror�write_file_via_tempfiler%r"rr$r
r
r�r�)�da_binary_line�proxy_command_linesr(s   r)�%_configure_proxy_commands_file_for_darW�s��-�F�,�,�N�
�L�N�N�N��V�&�'�'�-��*A�*A�A�A�	�"0��"@�"@���%S�%S�?R�%S�%S�%S�S�S�&�U�.A�"�.E�.K�.K�.M�.M�PT�.T�'��+�#�*�*�>�D�+@�A�A�A��0��G�G�/�0�0�.�%������	T�S���	�	�	�� ������Q���
�
�
�
�
�
�
�
�
�����	����
	�!�.�.�A�A�A�A���	�	�	�� �"�N�F�N�C�PQ�F�F�
�
�
�
�
�
�
�
�����	����!�"�"�	��N�G�G�G��m�m�m��
�
�
�
�
�
�	�	s1�	B
C�
D�!*D�D�D0�0
E.�:*E)�)E.c�h�tj��sdSt��t��dS)z1
    Configure CageFs for Directadmin panel.
    N)rr�rIrWr0r1r)�directadmin_configurerYs5���<�>�>����#�%�%�%�)�+�+�+�+�+r1c��ddl}t��rtj��t	��t��t
j��t��|�	��tj��r"|���t��tj��rt��tj��rt#��|���|���t)tjdd���t-��t/��dS)NrTr4r5)rKr�r�detect_postgresr*r�
cagefs_da_lib�"configure_selector_for_directadminrF�
check_excluderr��add_spamassassin_dirs_cpanelr2rr9r�rY�add_mount_for_php_apm�add_mounts_for_ea_php_sessionsr.�VAR_RUN_CAGEFSr>rA)rKs r)�reconfigure_cagefsrcs,���������$��!�#�#�#��!�!�!�"�$�$�$��4�6�6�6��O�O�O�
������
����$��.�.�0�0�0�!�#�#�#�
����$�!�#�#�#�
�|�~�~� �����
�#�#�%�%�%�
�,�,�.�.�.��9�3�d��O�O�O�O����������r1)FFrrL)L�builtinsrQ�cldetectlibrrr�r�rhr��xml.dom.minidom�dom�minidomr�r��packaging.versionrr�rr�cagefshooksrrr&rr\�clcagefslib.selector.configurerrrKr	r
�clcommon.utilsrrr
r��LSPHP5_PATHr�r�r�rCrr8rHrQr*r/r2r9r>rAr.r{r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr4r>rFrIrWrYrcr0r1r)�<module>rns���������������	�	�	�	�
�
�
�
�
�
�
�
�����
�
�
�
��������������4�4�4�4�4�4�����������*�*�*�*�*�*�����	�	�	�	���������S�S�S�S�S�S�S�S�;�;�;�;�;�;�;�;�N�N�N�N�N�N�N�N�N�N��
�$��-����,��$��?��.��/�
�	-��T�T�T�2D��<�<�<�M�M�M�:�:�:�
;�
;�
;�4�4�4�4�<5�5�5�r7�7�7�|
�
�
��������B���,���2%�%�%�R.9�����<
�
�
�
�
�
�	�	�	�������#S�#S�#S�L���4���&+C�+C�+C�+C�\7�7�7�7�D)X�)X�)X�X2�2�2�*)�)�)�X,�,�,�����r1