ok

Mini Shell

Direktori : /opt/cloudlinux/venv/lib64/python3.11/site-packages/clwpos/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/clwpos/__pycache__/utils.cpython-311.pyc

�

�2�fv��	���ddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlmZmZmZddlmZddlmZddlmZddlmZmZmZm Z ddl!m"Z"ddl#Z#dd	lm$Z$dd
l%m&Z&m'Z'ddl(m)Z)ddl*m*Z*m+Z+m,Z,dd
lm-Z-m.Z.m/Z/m0Z0m1Z1ddl2Z2ddl3m4Z4m5Z5ddl6m7Z7ddl8m9Z9m:Z:ddl;m<Z<ddl=m>Z>m?Z?ddl@mAZAmBZBddlCmDZDmEZEddlFmGZGmHZHddlImJZJddlKmLZLmMZMmNZNmOZOddlPmQZQmRZRmSZSddlTmZmUZUddlVmWZWmXZXmYZYmZZZm[Z[m\Z\ddl]m^Z^ddl_m`Z`maZaddlbmcZcddlKmdZddd lemfZfdd!lgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvdd"lwmxZxmyZydd#lzm{Z{dd$l|m}Z}ej~rdd%lm�Z�da�d&�Z�Gd'�d(e
j���Z�d�d*e�d+e�fd,�Z�d�d*e�d-e�d.e�fd/�Z�d�d*e�d1e�fd2�Z�d3e�fd4�Z�d5e�fd6�Z�d3e�fd7�Z�d8ej�fd9�Z�d:�Z�d�d;e�d3e�fd<�Z�d3e�fd=�Z�dd>�d;e�d3e�fd?�Z�dd>�d;e�fd@�Z�GdA�dB��Z�dCe�d3e/e�fdD�Z�d3e-e�fdE�Z�dFe�d3dfdG�Z�dHe�d3dfdI�Z�dHe�d3dfdJ�Z�dK�Z�dLe�d3e.e�e�ffdM�Z�dNe�dOe/e�fdP�Z�GdQ�dRe���Z�e$d�dTe�dOe/e�fdU���Z�dV�Z�e}d�dY���Z�dZe�d3e.e�e�ffd[�Z�d�d3e�fd]�Z�d^�Z�d_�Z�eGd`�da����Z�eGdb�dc����Z�dd�Z�de�Z�d3e�fdf�Z�dg�Z�dh�Z�di�Z�d3e�fdj�Z�d3e�fdk�Z�e$d3e1e�fdl���Z�dm�Z�dn�Z�Gdo�dp��Z�d�dq�Z�Gdr�ds��Z�e$dte�fdu���Z�dte�d3e�fdv�Z�d3e�fdw�Z�d3e�fdx�Z�d3e�fdy�Z�d3e�fdz�Z�d{e�d|e�d3dfd}�Z�dHe�d{e�d|e�d3dfd~�Z�d3e�fd�Z�d3e�fd��Z�d3e.e�e�e�ffd��Z�d�e�d�e�d3e.e�e�e�ffd��Z�d�e�d3e.e�e�e�ffd��Z�d��Z�e}d3e�fd����Z�e}d3e�fd����Z�d�e�d3e-fd��Z�d��Z�d�e�d�e�d�e�fd��Z�d��Z�d��Z�d��Z�dS)��)�absolute_importN)�	dataclass�asdict�field)�iglob)�Enum)�gettext)�	urlencode�urlparse�	parse_qsl�
urlunparse)�Version)�contextmanager)�wraps�	lru_cache)�Path)�socket�AF_UNIX�SOCK_STREAM)�List�Tuple�Optional�Set�ContextManager)�write_file_via_tempfile�
disable_quota)�NoDomain)�ClPwd�drop_privileges)�mkdir��is_cl_shared_pro_edition�CLEditionDetectionError)�read_jwt�
decode_jwt)�CLN_JWT_TOKEN_PATH�DEFAULT_JWT_ES_TOKEN_PATH)�
PyJWTError�
exceptions)�
check_license)�docroot�get_domain_login�
get_server_ip�cpusers)�exec_utility�run_command�demote)r	�	wp_config)�	WposError�WPOSLicenseMissing�WpCliUnsupportedException�WpNotExists�WpConfigWriteFailed�PhpBrokenException)�UIConfig)�	in_cagefs�_is_cagefs_enabled)�Feature)�is_panel_feature_supported�)�
setup_logging)�
USER_WPOS_DIR�WPOS_DAEMON_SOCKET_FILE�CLCONFIG_UTILITY�RedisRequiredConstants�CAGEFS_ENTER_USER_BIN�CAGEFS_ENTER_UTIL�CLWPOS_OPT_DIR�ALT_PHP_PREFIX�
EA_PHP_PREFIX�PLESK_PHP_PREFIX�USER_CLWPOS_CONFIG�PUBLIC_OPTIONS�SUITES_MARKERS�XRAY_MANAGER_UTILITY�XRAY_USER_SOCKET)�pack_data_for_socket�'read_unpack_response_from_socket_client)�RollbackException)�cached_in_scope)�PHPc����fd�}|S)z'
    Decorator for catching errors
    c���t�tt��a	�|g|�Ri|��S#t$r3}t	|j|j|j|jd���Yd}~dSd}~wt$r�}t|t��rt�|��nt�
|��|j|j|jd�}|jr
|j|d<t	|j|��Yd}~dSd}~wt$rJ}t�
|��t	|jit!|��d���Yd}~dSd}~wwxYw)N)�context�result�issues)rVrW�warning�details)rVrW)�loggerr?�__name__rQ�error_and_exit�_is_jsonrV�message�errorsr3�
isinstancer4rY�	exceptionrZ�	Exception�str)�self�args�kwargs�e�response�funcs     ��C/opt/cloudlinux/venv/lib64/python3.11/site-packages/clwpos/utils.py�func_wrapperz!catch_error.<locals>.func_wrapperrs�����>�"�8�,�,�F�	M��4��.�t�.�.�.�v�.�.�.�� �	�	�	��4�=��9��)��(�+�+�
�
�
�
�
�
�
�
�
�����
�	4�	4�	4��!�/�0�0�
$����q�!�!�!�!�� � ��#�#�#�#$�9��	�a�i�X�X�H��y�
0�&'�i���#��4�=�(�3�3�3�3�3�3�3�3�3������	M�	M�	M����Q�����4�=�b�C��F�F�*K�*K�L�L�L�L�L�L�L�L�L�����	M���s-�*�
E�(A"�"
E�/BC:�:
E�?E�E�)rjrls` rk�catch_errorrnms)���
M�M�M�M�M�2��c�(��eZdZdZ�fd�Zd�Z�xZS)�ExtendedJSONEncoderzz
    Makes it easier to use ENUMs and DATACLASSes in program,
    automatically converting them when json is printed.
    c�D��d|d<t��jdi|��dS)NF�ensure_asciirm)�super�__init__)rerg�	__class__s  �rkruzExtendedJSONEncoder.__init__�s0���!&��~�������"�"�6�"�"�"�"�"roc��t|t��r|jSt|tjtjf��r|���St|t��rt|��Stj	|��rtj
|��Stj�
||��S�N)rar�value�datetime�date�	isoformatrrd�dataclasses�is_dataclassr�json�JSONEncoder�default)re�objs  rkr�zExtendedJSONEncoder.default�s����c�4� � �	+��9��
��h�m�X�->�?�
@�
@�	+��=�=�?�?�"�
��W�
%�
%�	+��s�8�8�O�
�
%�c�
*�
*�	+��%�c�*�*�*���'�'��c�2�2�2ro)r\�
__module__�__qualname__�__doc__rur��
__classcell__)rvs@rkrqrq�sQ���������#�#�#�#�#�	3�	3�	3�	3�	3�	3�	3rorqF�is_json�	is_prettyc���|rY|r,ttj|ddt�����dSttj|dt�����dSt|��dS)z�
    Print specified dictionary
    :param data_dict: data dictionary to print
    :param is_json: True - print in JSON, False - in text
    :param is_pretty: True - pretty json print, False - none (default)
    :return: None
    �T)�indent�	sort_keys�cls)r�r�N)�printr�dumpsrq)�	data_dictr�r�s   rk�_print_dictionaryr��sy�����	R��$�*�Y�q�D�FY�Z�Z�Z�[�[�[�[�[��$�*�Y�$�<O�P�P�P�Q�Q�Q�Q�Q�	�i�����ror_�
error_codec��d|���vr*|�d��s|�d��|r;|�dt	j��i��t||d���nu	t
t|d��|�di��z��n:#t$r-}t
dt|���d|�d	���Yd
}~nd
}~wwxYwtj
|��d
S)z�
    Print error and exit
    :param is_json:
    :param message: Dictionary with keys "result" as string and optional "context" as dict
    :param error_code: Utility return code on error
    rY�	timestampT�r�rWrVzError: z [�]N)�keys�get�pop�update�timer�r�rd�KeyError�sys�exit)r�r_r�rhs    rkr]r]�s���G�L�L�N�N�"�"�7�;�;�y�+A�+A�"����I�����8�����T�Y�[�[�1�2�2�2��'�7�d�;�;�;�;�;�	8��#�g�h�'�(�(�7�;�;�y�"�+E�+E�E�F�F�F�F���	8�	8�	8��E�c�!�f�f�f�f�g�g�g�6�7�7�7�7�7�7�7�7�����	8�����H�Z�����s�?9B9�9
C0�#C+�+C0�success�datac��t|t��r)|�|tj��d���t	||d���dS)zo
    Output data wrapper
    :param is_json:
    :param data: data for output to stdout
    :param result:
    )rWr�Tr�N)ra�dictr�r�r�)r�r�rWs   rk�
print_datar��sR���$����B����v�D�I�K�K�@�@�A�A�A��d�G�t�4�4�4�4�4�4ro�returnc�0�tj��dkS)zQ
    Detects is we running under root
    :return: True - user, False - root
    r)�os�geteuidrmrork�is_run_under_userr��s��
�:�<�<�1��ro�safelyc�H�	t��S#t$r|rYdS�wxYw)z�
    Detecting of shared_pro edition depends on jwt token
    There are some cases when we do not fail if there are
    cases with decoding (e.g summary collection)
    Fr!�r�s rk�is_shared_pro_safelyr��s@���'�)�)�)��"�����	��5�5��	���s�
�!�!c�4�ttj��S)u�
    Сheck if system environment is supported by WPOS
    :return:
        True - CPanel/Plesk on Solo/ CL Shared Pro/ CL Admin
        False - else
    )r=r<�WPOSrmrork�is_wpos_supportedr��s��&�g�l�3�3�3ro�user_pwc��tj�|jt��}tj�|��st
|d���dSdS)z@
    Creates {homedir}/.clwpos directory if it's not exists
    i�)�modeN)r��path�join�pw_dirr@�isdirr )r��
clwpos_dirs  rk�create_clwpos_dir_if_not_existsr��sT������g�n�m�<�<�J�
�7�=�=��$�$�&�
�j�u�%�%�%�%�%�%�&�&roc���t|��d}|�|��std|�d|�d|�����|t|��d��d��S)Nrzdocroot z for domain z should start with �/)r+�
startswithr3�len�lstrip)�domain�homedir�drs   rk�get_relative_docrootr�sq��	�����	�B�
�=�=��!�!�Y��W�2�W�W�6�W�W�g�W�W�X�X�X�
�c�'�l�l�m�m��#�#�C�(�(�(ro�usernamec�0�t|���}|jS�N�r�)�get_pwr�)r��pws  rk�home_dirr�	s��	��	"�	"�	"�B�
�9�roc�(�t��jSrx)r��pw_namermrork�	user_namer�s���8�8��ror�c�,�t|���jSr�)r��pw_uidr�s rk�user_uidr�s���8�$�$�$�+�+roc�x�|rtj|��Stjtj����Srx)�pwd�getpwnam�getpwuidr�r�r�s rkr�r�s0���*��|�H�%�%�%��|�B�J�L�L�)�)�)roc�4�eZdZdZd	dededdfd�Zd�Zd�ZdS)
�WposUserzQ
    Helper class to construct paths to user's WPOS dir and files inside it.
    Nr�r�r�c��||_|�t|��n||_tj�|jt
��|_tj�|jt��|_tj�|jd��|_	tj�|jd��|_
tj�|jd��|_dS)Nz
redis.conf�
redis.sockz.php_info-{file_id})�namer�r�r�r�r@�wpos_dirrJ�wpos_config�
redis_conf�redis_socket�php_info)rer�r�s   rkruzWposUser.__init__"s�����	�.5�o���*�*�*�7��
�����T�]�M�B�B��
��7�<�<��
�7I�J�J����'�,�,�t�}�l�C�C����G�L�L����E�E�������T�]�4I�J�J��
�
�
roc�"�|j|jkSrx�r�)re�others  rk�__eq__zWposUser.__eq__+s���y�E�J�&�&roc�*�t|j��Srx)�hashr��res rk�__hash__zWposUser.__hash__.s���D�I���rorx)r\r�r�r�rdrur�r�rmrorkr�r�sr��������K�K��K�s�K�d�K�K�K�K�'�'�'�����ror��cmd_dictc	�^�t|��}ttt��5}	|�t
��|�|��|�d��t|��}|�t|t��s,ttd��t|��i����|ddkr8ttd��|d|�d������|cddd��S#t$r%ttd	��d
t
i���t t"t$t&t(jt,f$r0}ttd��t|������d}~wwxYw#1swxYwYdS)
z�
    Send command to CLWPOS daemon via socket
    :param cmd_dict: Command dictionary
    :return: Daemon response as dictionary, None - daemon data/socket error
    �xNzPUnexpected response from daemon. Report this issue to your system administrator.�r_rZrVrWr�z3Daemon was unable to execute the requested command.rVzbCloudLinux AccelerateWP daemon socket (%(filename)s) not found. Contact your system administrator.�filenamez&Unexpected daemon communication error.)rZ)rOrrr�connectrA�sendall�
settimeoutrPrar�r3r	rdr��FileNotFoundError�ConnectionError�OSError�IOError�AttributeError�struct�errorr�)r��
bytes_to_send�s�
response_dictrhs     rk�daemon_communicater�2s(��)��2�2�M�	���	%�	%�_��	_�
�I�I�-�.�.�.�
�I�I�m�$�$�$�
�L�L�����C�A�F�F�M��$�J�}�d�,K�,K�$��#�%V�W�W��
�.�.��	 � � � �
�X�&�)�3�3���0e�(f�(f�(5�h�(?�(5�(9�(9�)�(D�(D�F�F�F�F�!�#_�_�_�_�_�_�_�_��$!�	C�	C�	C��G�%I�J�J�'�)@�A�C�C�
C� ��'�>�6�<�QY�Z�	_�	_�	_��G�$L�M�M�WZ�[\�W]�W]�^�^�^�^�����	_����-_�_�_�_����_�_�_�_�_�_s0�F"�CD�AF�/+F�F�F"�"F&�)F&c�R�d}t��jrd}tj�t��td��}tj��}tj
}tj}tj}tj
}tj}tj}dd|j�d|j�d�dtjj�d|�d�d|j�d|j�d�d|j�d|j�d�d|j�d|j�|�d�d|j�d|j�d	�d|j�d|�d	�d
g	S)ak
    Construct list of lines (configuration settings)
    that should be in Wordpress config file to enable redis.
    Please note that deleting of the plugin would flush all keys related to the plugin (site) from redis.
    REDIS_PREFIX and SELECTIVE_FLUSH in wp-config.php would guarantee that plugin will not flush keys unrelated
    to this plugin (site)
    �false�truer�z)// Start of CloudLinux generated section
�define('z', 'z');
z', z);
z'// End of CloudLinux generated section
)�get_server_wide_options�disable_object_cache_bannersr�r�r�r�r@�uuid�uuid4rC�WP_REDIS_PREFIX�WP_REDIS_SCHEME�WP_REDIS_CLIENT�WP_REDIS_SELECTIVE_FLUSH�WP_REDIS_GRACEFUL�WP_REDIS_DISABLE_BANNERSr��val�
WP_REDIS_PATH)	�disable_banners_value�socket_path�prefix_uuid�redis_prefix�redis_schema�redis_client�redis_flush�redis_graceful�disable_bannerss	         rk�redis_cache_config_sectionrSsN��$��� � �=�'� &���'�,�,�x�z�z�=�,�G�G�K��*�,�,�K�)�9�L�)�9�L�)�9�L�(�A�K�+�=�N�,�E�O�8�E�|�(�E�E�l�.>�E�E�E�X�-�;�@�X�X�k�X�X�X�E�|�(�E�E�l�.>�E�E�E�I�~�*�I�I��0B�I�I�I�R�|�(�R�R�l�.>�R��R�R�R�A�{�'�A�A�K�O�A�A�A�K��+�K�K�0E�K�K�K�6�8�8ro�wp_config_pathc��tj�|��}tj�|��st	|���tj�|��s t
td��d|i����dS)z�
    Check that wp-config.php exists inside Wordpress directory.
    :param wp_config_path: absolute path to Wordpress config file
    :raises: WposError
    z)Wordpress config file %(file)s is missing�file�r_rVN)r�r��dirname�existsr6�isfiler3r	)r�wp_paths  rk�check_wp_config_existancerss����g�o�o�n�-�-�G�
�7�>�>�'�"�"�#��'�"�"�"�
�7�>�>�.�)�)�:���(S� T� T�!'�� 8�:�:�:�	:�:�:ro�abs_wp_pathc���ttj|����}t|��t	���dtdt
f�fd�}	tj|��}tt||����}td�
|��|d��dS#ttf$r}t||���d}~wwxYw)z�
    Clear cloudlinux section with redis object cach config from docroot's wp-config.php
    :param abs_wp_path: Absolute path to WordPress
    :raises: WposError
    �liner�c���|�vod|vS)zn
        Filter function that should delete CL config options from the `redis_cache_config_section()`
        rrm)r�lines_to_filters �rk�__config_filterz1clear_redis_cache_config.<locals>.__config_filter�s����?�*�L�/@��/L�Lro��N)rdr2r�rr�bool�read�list�filterrr�r�r�r7)rrr �wp_config_lines�cleared_wp_configrhrs      @rk�clear_redis_cache_configr)�s��������4�4�5�5�N��n�-�-�-�0�2�2�O�M�c�M�d�M�M�M�M�M�M�5�#�.��5�5�� ����!I�!I�J�J������(9� :� :�N�E�R�R�R�R�R���W��5�5�5�!�.�!�4�4�4�����5���s�AB,�,C�=C
�
Cc����ttj|����}t|��	|�d�}tj�|��st
j||��d�tD��}tj	|��}g}|D]\��fd�|�
��D��}|sdSt�fd�tD����s|�����]|dgt���|dd��}td�|��|d	��dS#t t"f$r}t%||���d}~wwxYw)
a
    Create config for redis-cache.
    We use manual copy cause we want to preserve file metadata
    and permissions and also we could add some custom config editing in the future.
    :param abs_wp_path: absolute path to WordPress
    :raises: WposError
    z.backupc�(�i|]}|j|j��Srm)r�r)�.0�constants  rk�
<dictcomp>z-create_redis_cache_config.<locals>.<dictcomp>�s��_�_�_�H�H�M�8�<�_�_�_roc�,��i|]\}}d|�d��v�
||��S)r��'rm)r,�k�vrs   �rkr.z-create_redis_cache_config.<locals>.<dictcomp>�s3���i�i�i���A�_�XY�_�_�_�dh�Mh�Mh��1�Mh�Mh�MhroNc3�2�K�|]}d|j�d��vV��dS)r�r0Nr�)r,�redis_constantrs  �rk�	<genexpr>z,create_redis_cache_config.<locals>.<genexpr>�s7�����n�n�^�8�.�"5�8�8�8�D�@�n�n�n�n�n�nrorr>r!r")rdr2r�rr�r�shutil�copyrCr$�items�any�appendrrr�r�r�r7)	rr�backup_wp_config�absent_constantsr'�
cleaned_lines�updated_configrhrs	        @rk�create_redis_cache_configr?�s��������4�4�5�5�N��n�-�-�-�5�,�5�5�5���w�~�~�.�/�/�	:��K��(8�9�9�9�_�_�H^�_�_�_��#�.��5�5���
�#�	+�	+�D�i�i�i�i�1A�1G�1G�1I�1I�i�i�i��#�
�����n�n�n�n�Wm�n�n�n�n�n�
+��$�$�T�*�*�*��
�!��
�
'�
)�
)�
��1�2�2�
�
��
	 ����� 7� 7���O�O�O�O�O���W��5�5�5�!�.�!�4�4�4�����5���s�BD9�<A;D9�9E�
E�Ec�<��t����fd���}|S)z,Decorator to check for license validity
    c�L��t��st����|i|��S)zLicense check wrapper)r*r4)rfrgrjs  �rk�wrapperz(check_license_decorator.<locals>.wrapper�s2������	'�$�&�&�&��t�T�$�V�$�$�$ro)r)rjrBs` rk�check_license_decoratorrC�s5����4�[�[�%�%�%�%��[�%��Nror�c��	t|��\}}||fS#t$r!ttd��d|i����wxYw)z�
    Validates domain, determines it's owner and docroot or exit with error
    :param domain: Domain name to check
    :return: Tuple (username, docroot)
    zNo such domain: %(domain)s.r�r)r+rr3r	)r��
document_root�owners   rk�check_domainrG�se��d�&�v����
�u��m�#�#���d�d�d���(E� F� F�QY�[a�Pb�c�c�c�c�d���s	��+Ar��attemptsc��tj}|�|tjz}	t|d��}t	|pd��D]O}	tj|���|��n@#t$rtj	d��Y�LwxYwttd�����n*#t$rttd�����wxYw|S)zE
    Try to take lock on file with specified number of attempts.
    Nza+r>g333333�?zwAnother utility instance is already running. Try again later or contact system administrator in case if issue persists.z%IO error happened while getting lock.)
�fcntl�LOCK_EX�LOCK_NB�open�range�flock�filenor�r��sleep�LockFailedExceptionr	r�)r�rH�	lock_type�lock_fd�_s     rk�	lock_filerV�s���
�I����U�]�"�	�
T��t�T�"�"���x�}�1�%�%�		M�		M�A�
 ���G�N�N�,�,�i�8�8�8�����
 �
 �
 ��
�3������
 ����&�g�/K�'L�'L�M�M�
M�	���T�T�T�!�'�*Q�"R�"R�S�S�S�T�����Ns/�#B-�'A,�*B-�,B
�
B-�B
�
B-�-'Cc��eZdZdZdS)rRz,
    Exception when failed to take lock
    N)r\r�r�r�rmrorkrRrR�s��������	�DrorR�
�
resource_pathc#�VK�t|dz|��}dV�t|��dS)z�
    Lock a file, than do something.
    Make specified number of attempts to acquire the lock,
    if attempts is None, wait until the lock is released.
    Usage:
    with acquire_lock(path, attempts=1):
       ... do something with files ...
    z.lockN)rV�release_lock)rYrHrTs   rk�acquire_lockr\�s9�����
��/��:�:�G�	�E�E�E�������roc��	tj|���tj��n#t$rYnwxYw|���dS)z
    Releases lock file
    N)rJrOrP�LOCK_UNr��close)�
descriptors rkr[r[sd��
�
��J�%�%�'�'���7�7�7�7���
�
�
���
�����������s�14�
A�A�php_versionrSc��d}d|jkr5|�|��r"ttd��d|i����dSdS)zX
    Ensures wp-cli is compatible, e.g some
    php modules may prevent stable work
    �
snuffleupaguszea-php74z�Seems like ea-php74 %(module)s module is enabled. It may cause instabilities while managing Object Caching. Disable it and try again�modulerN)�
identifier�is_extension_loadedr5r	)ra�dangerous_modules  rk�wp_cli_compatibility_checkrhsw��'���[�+�+�+��/�/�0@�A�A�,�'��9c�1d�1d�2:�;K�0L�N�N�N�	N�,�+�+�+ro�hidec�v�ddtjddd|iii��dg}tt|��\}}||fS)zf
    Call cloudlinux-config utility
    to hide/show WPOS icon in user's control panel interface.
    �setz--data�options�
uiSettings�hideAccelerateWPAppz--json)rr�r/rB)ri�params�
returncode�stdouts    rk�set_wpos_icon_visibilityrr*sS��	���
�I��/D�d�.K�L�M�N�N��	�F�&�&6��?�?��J���v��rornc�F�t���|d��S)zP
    Check the current state of WPOS icon in user's control panel interface
    rm)r9�	get_param��	icon_names rk�is_ui_icon_hiddenrw8s���:�:���	�<�8�8�8roc�h�ttj�t��|g��S)z[
    1. xray utility exists = alt-php-xray package installed
    2. feature is visible
    )�allr�r�rrM)�feature_visibles rk�should_xray_user_agent_enabledr{>s/��
�����3�4�4��!�"�"�"roc���ttj�t��tj�t
��t
d���g��S)z�
    1. xray utility exists = alt-php-xray installed
    2. xray socket exists
    3. end-user plugin was not enabled by admin = hidden in UI
    �hideXrayAppru)ryr�r�rrMrNrwrmrork�should_xray_user_agent_disabledr~FsP�������3�4�4��G�N�N�#3�4�4�%�
�>�>�>�@�A�A�Aroc�l�eZdZUee���Zeeed<ee���Z	eeed<dS)�WHMCSServerWideOptions��default_factory�allowed_suites�visible_suitesN)
r\r�r�rr%r�rr�__annotations__r�rmrorkr�r�PsT�������%*�U�4�%@�%@�%@�N�H�T�N�@�@�@�%*�U�4�%@�%@�%@�N�H�T�N�@�@�@�@�@ror�c�n�eZdZUdZeed<eed<eed<eed<eed<eed<ee���Z	eed	<d
Z
eeed<d
Zeeed<d
Z
eeed
<d
Zeeed<d
Zeeed<d
Zeeed<dd�Zed���Zed���Zed���Zed���Zd
S)�ServerWideOptionsz�
    Options holder representing server-wide option
    available for reading for any user on server.

    Only can be changed by root.
    �	show_iconr�r��supported_suites�supported_features�hidden_featuresr��
whmcs_optionsNr��"disable_smart_advice_notifications�%disable_smart_advice_wordpress_plugin�disable_smart_advice_reminders�upgrade_url�upgrade_url_cdn�object_cachec	���	�ddlm�	m�i�	fd��	jD����fd��jD���}||vrdSd}|�	jvr|j�dS|j}|�jvr|j�dS|j}|�dSt
t|����}tt|d����}|�
t||��|t��dd||d	���t|��|d<t|��S)
z�
        Append some needed arguments to upgrade url to make it specific for user.
        Please pay attention that we add *customer_name* instead of system user,
        that may be different on plesk.
        r)�PremiumSuite�CDNSuiteProc� ��i|]
}|�j��Srmr�)r,�featurer�s  �rkr.z>ServerWideOptions.get_upgrade_url_for_user.<locals>.<dictcomp>zs���W�W�W�g�w��)�W�W�Wroc� ��i|]
}|�j��Srmr�)r,r�r�s  �rkr.z>ServerWideOptions.get_upgrade_url_for_user.<locals>.<dictcomp>{s���U�U�U�W�w��(�U�U�UroNr��cloudlinux_advantage�provisioning)r�r��	server_ip�m�action�suite)�clwpos.feature_suitesr�r��primary_featuresr�r�r%rr�rr�r,r-r
r
)
rer�r�r��feature_to_suite�
target_url�	url_parts�queryr�r�s
        @@rk�get_upgrade_url_for_userz*ServerWideOptions.get_upgrade_url_for_usernsd����	D�C�C�C�C�C�C�C�

�W�W�W�W��9V�W�W�W�
�U�U�U�U��8T�U�U�U�
��
�*�*�*��4��
��l�3�3�3���'��t��)�J��k�2�2�2��#�+��t��-�J����4���*�-�-�.�.�	��Y�y��|�,�,�-�-��
���(��6�:�:��&���'�$�%�g�.�

�
�	�	�	�!��'�'�	�!���)�$�$�$roc��ttt|j��t|jj��z����Srx)r%rkr�r�r�s rk�allowed_suites_listz%ServerWideOptions.allowed_suites_list��6���C��T�0�1�1�D��9K�9Z�4[�4[�[�\�\�]�]�]roc��ttt|j��t|jj��z����Srx)r%rkr�r�r�s rk�visible_suites_listz%ServerWideOptions.visible_suites_list�r�roc���ddlm}t��}�jD].}|��fd�||jD�����/|S)Nr>��
ALL_SUITESc�&��h|]
}|�jv�|��Srm�r��r,r�res  �rk�	<setcomp>z5ServerWideOptions.allowed_features.<locals>.<setcomp>��3���&M�&M�&M�'�)0�D�4K�)K�)K�'.�)K�)K�)Kro)�feature_suitesr�rkr�r��feature_set)rer��_allowed_featuresr�s`   rk�allowed_featuresz"ServerWideOptions.allowed_features�s����	/�.�.�.�.�.��E�E���-�	N�	N�E��$�$�&M�&M�&M�&M�Z��=N�=Z�&M�&M�&M�
N�
N�
N�
N� � roc���ddlm}t��}�jD].}|��fd�||jD�����/|S)Nr>r�c�&��h|]
}|�jv�|��Srmr�r�s  �rkr�z5ServerWideOptions.visible_features.<locals>.<setcomp>�r�ro)r�r�rkr�r�r�)rer��_visible_featuresr�s`   rk�visible_featuresz"ServerWideOptions.visible_features�s����.�.�.�.�.�.��E�E���-�	N�	N�E��$�$�&M�&M�&M�&M�Z��=N�=Z�&M�&M�&M�
N�
N�
N�
N� � ro)r�)r\r�r�r�r#r�rrr�r�r�rr�r�r�r�rdr�r��propertyr�r�r�r�rmrorkr�r�Vs�����������O�O�O���������������������,1�E�BX�,Y�,Y�,Y�M�)�Y�Y�Y�37� �(�4�.�7�7�7�9=�&����=�=�=�<@�)�8�D�>�@�@�@�59�"�H�T�N�9�9�9�!%�K��#��%�%�%�%)�O�X�c�]�)�)�)�.%�.%�.%�.%�`�^�^��X�^��^�^��X�^��!�!��X�!��!�!��X�!�!�!ror�c�<�ddlm}m}m}t	j��st
��\}}nCddlm}	td|j
i��}|d|d}}n#t$rd\}}YnwxYw|j||j||j|i�
|d��S)	Nr)r�r��CDNSuite��
WposDaemon�command�accelerate_wp_premium�accelerate_wp_cdn�FFT)r�r�r�r�r�r��get_suites_status_from_license�
clwpos.daemonr�r��&DAEMON_GET_SUPPORTED_SUITES_BY_LICENSEr3r�r�)r�r�r�r��awp_premium_status�awp_cdn_statusr��suites_statuses_by_licenses        rk�is_feature_supported_by_licenser��s���I�I�I�I�I�I�I�I�I�I�
�:�<�<�>�-K�-M�-M�*��N�N�	-�,�,�,�,�,�		>�);��z�P��*�*�&�
3M�Md�2e�2L�M`�2a�!/�����	>�	>�	>�1=�.�����	>����	��-��
�~���.��
�c�%����	s�&A�A0�/A0c���ddlm}t��}|���D]:\}}|jD]-}|jrt
|��r|�|���.�;|S)Nr>r�)r�r�rkr8�features�IS_BILLABLEr��add)r�r��
suite_name�
suite_item�
suite_features     rk�get_supported_featuresr��s���*�*�*�*�*�*�����",�"2�"2�"4�"4�6�6��
�J�'�0�	6�	6�M� �,�
6�0O�PZ�0[�0[�
6�"�&�&�}�5�5�5��	6��roc
���ddlm}m}m}m}m}t
���dd��}g}g}|j|j|j|jfD]W}tj
�t|��s�-|�
|��|�
|���Xt|||t|��tt!����g���S)zw
    Return default content of /opt/clwpos/public_config.json.
    This file is accessible by all users on server.
    r>)�AWPSuiter�r�r��SUPPORTED_SUITESrnrm)r�r�r�r�r�r�)r�r�r�r�r�r�r9rtr�r�r�rrLr:r�r%r�)	r�r�r�r�r��is_icon_hiddenr�r�r�s	         rk�get_default_server_wide_optionsr��s��`�_�_�_�_�_�_�_�_�_�_�_�_�_��Z�Z�)�)�*?��N�N�N��N��N�
�#�X�]�H�M�;�CS�T�%�%���w�~�~�n�U�3�4�4�	�����e�$�$�$����e�$�$�$�$��$�$�%�%��.�/�/�� 6� 8� 8�9�9��
���roc��ddlm}m}m}m}t��\}}t
j||||gdd||g��}d�|D��S)zY
    Get list of supported suites taking
    into account license and status on CLN.
    r>)r�r�r�r�Tc��g|]	}|j��
Srmr�)r,r�s  rk�
<listcomp>z(get_supported_suites.<locals>.<listcomp>
s��+�+�+�5�E�J�+�+�+ro)r�r�r�r�r�r��	itertools�compress)r�r�r�r��is_awp_premium_allowed�is_awp_cdn_allowed�suitess       rk�get_supported_suitesr��s���
������������2P�1Q�1Q�.��.�
�
�	�<��;�7�	
�t�'�);�<���F�
,�+�F�+�+�+�+roc���td���x}}tj�t��r:t��}|�d|��}|�d|��}||fS)NTr�r�r�)r�r�r�rr&�_get_jwt_payloadr�)r�r��jwts   rkr�r�st��2F�d�2S�2S�2S�S��/�	�w�~�~�(�)�)�O�� � ��!$���)A�CY�!Z�!Z�� �W�W�%9�;M�N�N��!�#5�5�5roc��tt��}	t|d���}n,#t$r}t	dt�d|�����d}~wwxYw|S)z1
    Read jwt, verify it and return payload.
    F)�
verify_expz)Unable to detect edition from jwt token: z-. Please, make sure it is not broken, error: N)r$r&r%r(r#)�tokenr�rhs   rkr�r�s���
�'�(�(�E�Y���5�1�1�1�����Y�Y�Y�%�'X�Rd�'X�'X�TU�'X�'X�Y�Y�	Y�����Y�����Js�(�
A�A�Ac�f�t|jt��r|jStdi|j��S)Nrm)rar�r�)�server_wide_optionss rk�get_whcms_server_wide_optionsr�"s:���%�3�5K�L�L�1�"�0�0�!�F�F�$7�$E�F�F�Froc�b��ddlm}t��}tj�t��s|Sdh�ttd��5}|���}	tj
|��}dD]�}||vr�|�|��}t||��}ttt|tt|���t|������z������}t#|||����|j��fd�|���D����t+|��|_	t/��}	|jdd�D] }
|
|	vr|j�|
���!n#t4$r
d|_YnwxYw|cddd��S#tjj$r8}t;t=d��t?|��d	ti�
���d}~wwxYw#1swxYwYdS)zL
    Gets server wide options which apply
    as defaults for all users
    r>r�r��r)r�r�r�c�$��i|]\}}|�v�	||��
Srmrm)r,r1r2�non_overridable_fieldss   �rkr.z+get_server_wide_options.<locals>.<dictcomp>Gs7���-Q�-Q�-Q�d�a��01�9O�0O�0O�./��0O�0O�0OroNzZFile is corrupted: Please, delete file %(config_file)s or fix the line provided in details�config_filer�) r�r�r�r�r�rrKrMr$r�loadsr��getattrr%�sortedrk�intersection�setattr�__dict__r�r8r�r�r�r��remove�PermissionError�decoder�JSONDecodeErrorr3rUrd)
r��default_options�f�content�
configuration�option_to_merge�suites_from_config�suites_from_defaults�
merged_values�server_suites_allowedr��errr�s
            @rkr�r�'s����
+�*�*�*�*�*�5�7�7�O�
�7�>�>�.�)�)����2�3��	
�n�c�	"�	"�*9�a��&�&�(�(��'	9�"&�*�W�"5�"5�M�$\�	
I�	
I��"�-�7�7��%2�%6�%6��%G�%G�"�'.���'P�'P�$�!%�V�C�0D�t�C�&�M(�M(�(4��S��_�_�(E�(E�HG�HG�1G�-H�-H�&I�&I�!J�!J�
����-�H�H�H�H�
�$�+�+�-Q�-Q�-Q�-Q�m�>Q�>Q�>S�>S�-Q�-Q�-Q�
R�
R�
R�,I�/�,Z�,Z�O�)�	
G�(<�(>�(>�%�-�=�a�a�a�@�G�G�E��$9�9�9�'�8�?�?��F�F�F��G��#�
8�
8�
8�48��0�0�0�
8����#�I*9�*9�*9�*9�*9�*9�*9�*9��J�|�+�	9�	9�	9���A�B�B��C���&��7�	9�9�9�
9�����	9����K*9�*9�*9�*9����*9�*9�*9�*9�*9�*9sU�H$�*DG�1F0�?1G�0G�G�G�G�H!�)3H�H!�!H$�$H(�+H(c#�K�tj�t��st	dt�d����t��}|V�t
t��5ttd��5}tj
t|��|��ddd��n#1swxYwYddd��dS#1swxYwYdS)z1Set icon visibility in clwpos public options filez6Can't write public options as configuration directory z does not exist�wN)r�r�rrFr�r�r\rKrMr�dumpr)�public_config_datar�s  rk�write_public_optionsr`sH�����7�>�>�.�)�)�
��d�^�d�d�d�
�
�	
�1�2�2��
����	�n�	%�	%�1�1����%�%�1�)*��	�&�+�,�,�a�0�0�0�1�1�1�1�1�1�1�1�1�1�1����1�1�1�1�1�1�1�1�1�1�1�1�1�1�1�1����1�1�1�1�1�1s6�%C�;#B*�C�*B.	�.C�1B.	�2C�C�	Cc
��t��}d|vr
|r||dd<tjdt|��t|�d������t��st
tj��sFtj
|fddttj
��tj����d�|��Stj
��dkr tt!d��|z����t#|t��rt$d	z|z}nt$d
g|z}tj
|fttj
��tj����ddd�|��S)z�
    Wrapper for subprocess to enter cagefs
    do not enter cagefs if:
     - CloudLinux Solo
     - if process already started as user in cagefs
    �env�LANG�*Executing command: %s with environment: %sT)�text�capture_output�
preexec_fnrz�Internal error: command %s must not be run as root. Please contact support if you have questions: https://cloudlinux.zendesk.com�r_z --no-io-and-memory-limit �--no-io-and-memory-limit)rrr
)�get_locale_from_envars�logging�infordr�r:r=r<�CAGEFS�
subprocess�runr1r�r��getegidr3r	rarE)r�rg�locale�with_cagefs_enters    rk�run_in_cagefs_if_neededrrs���$�
%�
%�F�����6�� &��u�
�f���L�=��W����V�Z�Z��&�&�'�'�)�)�)��{�{�(�4�W�^�D�D�(��~�g�(�#'�-1�)/��
���b�j�l�l�)K�)K�(�(�!'�	(�(�	(��:�<�<�1����G�-M�%N�%N�PW�%X�Y�Y�Y�
Y��g�s�#�#�	Z� 1�4P� P�SZ� Z���!2�4N� O�RY� Y���~�/�(�)/��
���b�j�l�l�)K�)K�#'�-1�(�(�!'�	(�(�	(roc�r�	t���|��S#tj$rYdSwxYw)z
    Returns uid for user
    N)r�get_uid�NoSuchUserExceptionr�s rk�uid_by_namer�sB����w�w���t�$�$�$���$�����t�t����s� #�6�6c� �eZdZdZdd�Zd�Zd�Zdedeefd�Z	dd	�Z
dd�Zdd�Zded
e
efd�Zd�Zdedeed
efd�Zed���Zdd�Zd�Zdedeed
efd�Zdede
ed
efd�Zdede
ed
efd�ZdS)�PhpIniConfigz>
    Helper class to update extensions in php .ini files.
    Nc�4�||_tjd��|_tjd��|_tjd��|_|pt
jt��|_	td|jj��d����f|_dS)Nz-^;\s*extension\s*=\s*(?P<module_name>\w+)\.soz,^\s*extension\s*=\s*(?P<module_name>\w+)\.soz1^\s*;?\s*extension\s*=\s*(?P<module_name>\w+)\.soz/var/cagefs/*/*/etc/cl.php.d/c�8�|�d��dS)Nr�r�)�split)r�s rk�<lambda>z'PhpIniConfig.__init__.<locals>.<lambda>�s��4�:�:�c�?�?�1�#5�ro)r��user)
ra�re�compile�disabled_pattern�enabled_pattern�	extensionr�	getLoggerr\r[r�re�wildcard_ini_user_locations)rera�
custom_loggers   rkruzPhpIniConfig.__init__�s���&��� "�
�+[� \� \���!�z�*Y�Z�Z�����$X�Y�Y���#�B�w�'8��'B�'B���
�S�d�6F�6Q�S�S�5�5�
7�
7�
7�,
��(�(�(roc���	|�d��d�d��dS#t$r4}|j�d|t	|����Yd}~dSd}~wwxYw)z-
        Parse .so extensions safely
        �=r>z.sorz4Cannot parse extension name from line: %s, error: %sN)r#rcr[rYrd)rerrhs   rk�_parse_extension_namez"PhpIniConfig._parse_extension_name�s���	��:�:�c�?�?�1�%�+�+�E�2�2�1�5�5���	�	�	��K��� V� $� #�A���
(�
(�
(��4�4�4�4�4�����		���s�36�
A4�)A/�/A4c�z�tj�|jj|��}tj�|��sgSt
|��5}|���}ddd��n#1swxYwYg}|D]/}|�|��}|s�|�	|���0|Srx)
r�r�r�ra�dirrrM�	readlinesr0r:)re�ini_path�	full_pathr��ini_content�modules�ext�raw_module_names        rk�get_ini_contentzPhpIniConfig.get_ini_content�s����G�L�L��!1�!5�x�@�@�	��w�~�~�i�(�(�	��I�
�)�_�_�	(���+�+�-�-�K�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(����	(�	(�	(�	(����	,�	,�C�"�8�8��=�=�O�"�
���N�N�?�+�+�+�+��s�A<�<B�Br�r7c��tj�|jj|��}tj�|��s|�||d���dS|�||��dS)NF�r)r�r�r�rar2r�_write_modules�enable_modules)rer�r7r5s    rk�create_custom_inizPhpIniConfig.create_custom_ini�st���G�L�L��!1�!5�t�<�<�	��w�~�~�i�(�(�	/����	�7�5��A�A�A�A�A�
����g�.�.�.�.�.roc�.�|rztj�|jj|��}tj�|��r1|j�d|����tj|��|�	dgd���dS)NzCustom ini to be removed: zacceleratewp.iniT)r�)
r�r�r�rar2rr[�debug�unlink�update_user_ini)rer��all_inir5s    rk�remove_custom_inizPhpIniConfig.remove_custom_ini�s����	%�����T�%5�%9�4�@�@�I��w�~�~�i�(�(�
%���!�!�"J�y�"J�"J�K�K�K��	�)�$�$�$����/��D��A�A�A�A�AroFc	���|jD]`}t|d��}|D]F}	|�|||||���#t$r|j�d��Y�CwxYw�adS)Nr�z&Error updating single acceleratewp.ini)r,r�_update_single_inircr[rb)re�ini_filenamer7r��location�cagefs_paths�dir_paths       rkrCzPhpIniConfig.update_user_ini�s����8�	�	�H� ��&�!1�2�2�L�(�
�
����+�+�H�h���W]�^�^�^�^�� �����K�)�)�*R�S�S�S��H�����
�	�	s�>�$A%�$A%c	��|d|��}tj�||��}t|��5t	��5|rOtj�|��r/|j�d|��tj|��n5|�	||tj�|�����ddd��n#1swxYwYddd��dS#1swxYwYdS)Nr%z#Custom user ini: %s will be removedr<)
r�r�r�rrrr[rArBr=)rerIrKr7rHr�r�r�s        rkrGzPhpIniConfig._update_single_ini�s���#�8�F�#�H�-�-���w�|�|�H�l�3�3��
�X�
&�
&�	P�	P����	P�	P��
P��7�>�>�$�'�'�$��K�%�%�&K�T�R�R�R��I�d�O�O�O���#�#�D�'�"�'�.�.��:N�:N�#�O�O�O�	P�	P�	P�	P�	P�	P�	P�	P�	P�	P�	P����	P�	P�	P�	P�	P�	P�	P�	P�	P�	P�	P�	P�	P�	P�	P�	P����	P�	P�	P�	P�	P�	Ps7�C;�BC#�C;�#C'	�'C;�*C'	�+C;�;C?�C?r�c�t��t|d��5}�fd�|D��cddd��S#1swxYwYdS)zU
        Return enabled modules.
        :param path: full path to .ini file
        r�c���h|]I}�j�|����j�|���d����JS�N�module_name�r)�match�group�r,rres  �rkr�z0PhpIniConfig._enabled_modules.<locals>.<setcomp>s[���E�E�E�d��+�1�1�$�7�7�C��(�.�.�t�4�4�:�:�=�I�I�C�C�CroN�rM�rer�r�s`  rk�_enabled_moduleszPhpIniConfig._enabled_modules�s����
�$��_�_�	E��E�E�E�E�VW�E�E�E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E����	E�	E�	E�	E�	E�	E��-�1�1c�t��t|d��5}�fd�|D��cddd��S#1swxYwYdS)Nr�c���h|]I}�j�|����j�|���d����JSrO)r*rRrSrTs  �rkr�z0PhpIniConfig._extensions_list.<locals>.<setcomp>sV���?�?�?���~�+�+�D�1�1�=��N�(�(��.�.�4�4�]�C�C�=�=�=rorUrVs`  rk�_extensions_listzPhpIniConfig._extensions_lists����
�$��_�_�	?��?�?�?�?�PQ�?�?�?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?����	?�	?�	?�	?�	?�	?rXc�$�tj�|jj|��}tj�|��sdS|j�d|����t|��}|r|�	||��dS)z�
        Enable specified modules in .ini php file.
        :param path: path to .ini file related to php directory
        :param modules: list of modules that should be enabled
        FzEnable such extensions: T)
r�r�r�rar2rr[rArkr=)rer�r7r5�modules_to_enables     rkr>zPhpIniConfig.enable_moduless����G�L�L��!1�!5�t�<�<�	��w�~�~�i�(�(�	��5�����>�W�>�>�?�?�?���L�L���	>����	�+<�=�=�=��troc��d|�d�S)z-
        redis -> extension=redis.so
        z
extension=z.so
rm)rds rk�_format_as_ini_extzPhpIniConfig._format_as_ini_exts��
*�F�)�)�)�)roTc	���	�g}�j�d|����|r�t|��}t|��5}|���D]U�	t�	�fd�|D����r"�j�d�	�d|�d����@|��	���V	ddd��n#1swxYwYt|��}d|vr|�d����|D]I}��	|��}�j�d	|����|�|���J|rC�j�d
|����td�|��|d��dSdS)
Nz,Such extensions are required to be enabled: c3�F�K�|]}��|���vV��dSrx)r_)r,r8rres  ��rkr5z.PhpIniConfig._write_modules.<locals>.<genexpr>&s6�����]�]�C�4�2�2�3�7�7�4�?�]�]�]�]�]�]rozSkip z, z will be added further�redisc�,�|�d��S�Nrb)�endswith)�xs rkr$z-PhpIniConfig._write_modules.<locals>.<lambda>/s��a�j�j��.A�.A�ro)�keyzAppending lines to be written: zPath to write: r!�)r[rArkrMr3r9r:r��sortr_rr�)
rer5r]r�
new_ini_linesr��sorted_modulesrd�extension_liners
`        @rkr=zPhpIniConfig._write_moduless�����
�����\�IZ�\�\�]�]�]��	/� #�$5� 6� 6���i���
/�A��K�K�M�M�/�/�D��]�]�]�]�]�K\�]�]�]�]�]�!���)�)�*c�$�*c�*c�:K�*c�*c�*c�d�d�d� �!�(�(��.�.�.�.�	/�
/�
/�
/�
/�
/�
/�
/�
/�
/�
/�
/����
/�
/�
/�
/� � 1�2�2���n�$�$����$A�$A��B�B�B�$�	1�	1�F�!�4�4�V�<�<�N��K���P��P�P�Q�Q�Q�� � ��0�0�0�0��	N��K���;�	�;�;�<�<�<�#�B�G�G�M�$:�$:�I�u�M�M�M�M�M�	N�	Ns�A+B:�:B>�B>c� �tj�|jj|��}tj�|��sgSt
|�|����}|j�	d|�d|����|S)zH
        Reads <ext>.ini file and loads all required extensions
        zRequired extensions for z are: )
r�r�r�rar2rr%r[r[rA)rer�r5�required_moduless    rk�get_required_modulesz!PhpIniConfig.get_required_modules:s����G�L�L��!1�!5�t�<�<�	��w�~�~�i�(�(�	��I��� 5� 5�i� @� @�A�A������S�T�S�S�AQ�S�S�T�T�T��roc�����tj��jj|��}tj�|��sdSt
|����|��z��rlt|��5}��fd�|�	��D��}ddd��n#1swxYwYtd�|��|d��dS)z�
        Disable specified modules in .ini php file.
        :param path: path to .ini file related to php directory
        :param modules: list of modules that should be disabled
        Fc�<��g|]}��|�����Srm)�_disable_module)r,r�modules_to_disableres  ��rkr�z0PhpIniConfig.disable_modules.<locals>.<listcomp>Qs:���!<�!<�!<�%)�"&�!5�!5�d�<N�!O�!O�!<�!<�!<roNr!rhT)r�r�r�rar2rrkrWrMr3r)rer�r7r5r�rjrss`     @rk�disable_moduleszPhpIniConfig.disable_modulesEs�����G�L�L��!1�!5�t�<�<�	��w�~�~�i�(�(�	��5� ��\�\�D�,A�,A�)�,L�,L�L���	N��i���
<�A�!<�!<�!<�!<�!<�-.�[�[�]�]�!<�!<�!<�
�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<����
<�
<�
<�
<�
$�B�G�G�M�$:�$:�I�u�M�M�M��ts�"B2�2B6�9B6rr]c���|j�|��}|�U|�d��}||vr<|�|��|�d�����S|S)zV
        Search for disabled module in line, uncomment line to enable module.
        NrP�;)r(rRrSr�r�)rerr]rRrPs     rk�_enable_modulezPhpIniConfig._enable_moduleVst���%�+�+�D�1�1�����+�+�m�4�4�K��/�/�/�!�(�(��5�5�5��{�{�3�'�'�.�.�0�0�0��rorsc�z�|j�|��}|�|�d��}||vrd|��S|S)zT
        Search for enabled module in line, comment line to disable module.
        NrPrvrQ)rerrsrRrPs     rkrrzPhpIniConfig._disable_modulebsN���$�*�*�4�0�0�����+�+�m�4�4�K��0�0�0�!�4�z�z�!��rorx)F)T)r\r�r�r�rur0r:rdrr?rErCrGrrWr[r#r>�staticmethodr_r=rortrwrrrmrorkr r �s���������
�
�
�
�
�
�
����$/�c�/�D��I�/�/�/�/�B�B�B�B�����P�P�P�P�E�S�E�S��X�E�E�E�E�?�?�?�

�3�
��c��
�t�
�
�
�
��*�*��\�*�N�N�N�N�8	 �	 �	 ��C��$�s�)�������"
�3�
�3�s�8�
��
�
�
�
�	�C�	�S��X�	�#�	�	�	�	�	�	ror c��ttj��sdSt��sT|�t	td������td|gtjdd�ztjdd�z}nCt��s3tt�����rtdgtjz}ndSdt��i}tjd	t!|��t!|����t#j|tjtj|�
��}|���tj|j��dS)a%
    All user-related actions must run inside of cagefs for security reasons.
    If solo just return because cagefs is only for shared and shared pro
    If root executed, we enter into user cagefs if user is pointed
    If not in cagefs and cagefs is enabeled for user enter into cagefs
    Nz�Internal Error: root enters into CageFS without specifying usernamePlease contact support if you have questions: https://cloudlinux.zendesk.comrrr>�)r%r
r)rq�stdinr	)r=r<rr�r3r	rDr��argvr:r;r�rErrrrdr�Popenrqr|�communicater�rp)r%�cmdr	�ps    rk�_run_clwpos_as_user_in_cagefsr�nsI��&�g�n�5�5���������<��G�1�%�%����
�%�)����x����|�$�&)�h�q�r�r�l�3����[�[��/�Y�[�[�A�A�A�� �"<�=���H���	���)�+�+�
,�C��L�=�s�3�x�x��S���R�R�R����S�Z�s�y� �	"�	"�	"�A��M�M�O�O�O��H�Q�\�����roc�Z�eZdZdZdeddfd�Zd
d�Zd
d�Zdefd�Z	e
defd	���ZdS)�RedisConfigurePidFilezm
    Helper class that provides methods to work with
    pid files of php redis configuration processes.
    �
php_prefixr�Nc�X�|�d�|_tt|j��|_dS)Nz-cloudlinux.pid)�_pid_file_namerrFr�)rer�s  rkruzRedisConfigurePidFile.__init__�s+��!+�<�<�<������)<�=�=��	�	�	roc���|j�d��5}|�tt	j������ddd��dS#1swxYwYdS)Nr)r�rM�writerdr��getpid�rer�s  rk�createzRedisConfigurePidFile.create�s���
�Y�^�^�C�
 �
 �	&�A�
�G�G�C��	���$�$�%�%�%�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&����	&�	&�	&�	&�	&�	&s�4A�A �#A c�n�|j���r|j���dSdSrx)r��is_filerBr�s rkr�zRedisConfigurePidFile.remove�s<���9�����	��I��������	�	roc�4�|j���Srx)r�r�r�s rkrzRedisConfigurePidFile.exists�s���y� � �"�"�"roc�6�|���sdS|j���5}	t|��������cddd��S#t$rYnwxYw	ddd��n#1swxYwYdS)N���)rr�rM�intr$�strip�
ValueErrorr�s  rk�pidzRedisConfigurePidFile.pid�s����{�{�}�}�	��2�
�Y�^�^�
�
�	��
��1�6�6�8�8�>�>�+�+�,�,�	�	�	�	�	�	�	�	���
�
�
���
�����		�	�	�	�	�	�	�	�	�	�	����	�	�	�	�
�rs.�B�2A1�1
A>�;B�=A>�>B�B�B)r�N)
r\r�r�r�rdrur�r�r#rr�r�r�rmrorkr�r��s���������
>�3�>�4�>�>�>�>�&�&�&�&�����#��#�#�#�#���S�����X���ror�r�c#�K�t|��}	|���dV�|���dS#|���wxYw)za
    Context manager for creating pid file of current process.
    Removes pid file on exit.
    N)r�r�r�)r��pid_files  rk�create_pid_filer��s_����%�Z�0�0�H��������
����������������������s�A�Ac��t|��}tj��dkr|���S	t	j|j��}d|���vS#ttj	f$rYdSwxYw)z�
    Find out if PHP redis configuration process is running.
    Based on looking for presence of pid files.
    For root also checks process existence.
    r�enable_redisF)
r�r�r�r�psutil�Processr�r�r��
NoSuchProcess)r�r��processs   rk�"is_php_redis_configuration_runningr��s���%�Z�0�0�H�	�z�|�|�q������ � � ���.���.�.��������/�/����,�-�����u�u����s�.A+�+B�Bc�*�tt��S)zE
    Find out if alt-PHP redis configuration process is running.
    )r�rGrmrork�&is_alt_php_redis_configuration_runningr��s��.�n�=�=�=roc�*�tt��S�zD
    Find out if ea-PHP redis configuration process is running.
    )r�rHrmrork�%is_ea_php_redis_configuration_runningr��s��.�m�<�<�<roc�*�tt��Sr�)r�rIrmrork�(is_plesk_php_redis_configuration_runningr��s��.�.>�?�?�?roc�V�t��pt��p
t��S)za
    Find out if redis configuration process
    is running for any PHP (ea-php or alt-php).
    )r�r�r�rmrork�is_redis_configuration_runningr��s.��
2�3�3�6�0�2�2�6�3�5�5�6ro�new_user�old_userc����t�j��5}|���}ddd��n#1swxYwY��fd�|D��}td�|���jd��dS)z;
    Replace user's wpos directory path in redis.conf.
    Nc�P��g|]"}|��j�j����#Srm)�replacer��r,rr�r�s  ��rkr�z%update_redis_conf.<locals>.<listcomp>�s:������?C����X�&��(9�:�:���ror!r")rMr�r3rr�)r�r�r��redis_conf_lines�
updated_liness``   rk�update_redis_confr��s�����
�h�!�	"�	"�)�a��;�;�=�=��)�)�)�)�)�)�)�)�)�)�)����)�)�)�)������GW����M��B�G�G�M�2�2�H�4G��O�O�O�O�Os�8�<�<c�2���	tj|��}n9#t$r,}td|�d|��tj���Yd}~dSd}~wwxYw��fd�|D��}t
d�|��tj|��d��dS)z<
    Replace user's redis socket path in wp-config.php.
    z=Error occurred during opening wp-config.php located in path "z": )rNc�f��g|]-}�j|vr |��j�j��n|��.Srm)r�r�r�s  ��rkr�z$update_wp_config.<locals>.<listcomp>sU������
�� �D�(�(�	
���X�*�H�,A�B�B�B�.2���ror!r")	r2r$r�r�r��stderrrr�r�)rr�r�r'rhr�s ``   rk�update_wp_configr��s������#�.��5�5��������
�6�"-�6�6�23�6�6�<?�J�	H�	H�	H�	H���������������
�����$����M�
�B�G�G�M�2�2�I�N�;�4O�4O�QV�W�W�W�W�Ws��
A�!A
�
Ac�t�tjtj����}|���S)z!
    Get parent process PID.
    )r�r�r�r��ppid)�procs rk�get_parent_pidr�s'���>�"�)�+�+�&�&�D��9�9�;�;�roc�D�tgd�d���\}}}|dkrdSdS)z`
    Detect CL WPOS daemon presence in system
    :return: True - daemon works / False - No
    )�
/sbin/service�clwpos_monitoring�statusT��return_full_outputrF)r0)rprUs  rk�_is_monitoring_daemon_existsr�s8��#�#S�#S�#S�hl�m�m�m��J��1��Q����u��4roc��tjd|��tgd�d���\}}}|stddgd���\}}}|||fS)z5
    Update systemd unit file and reload systemd
    z//usr/share/cloudlinux/clwpos_monitoring.service)�/usr/bin/systemctl�enablezclwpos_monitoring.serviceTr�r�z
daemon-reload)r6r7r0)�systemd_unit_file�retcoderqr�s    rk�$_update_clwpos_daemon_config_systemdr�$sx���K�A�CT�U�U�U�)�*g�*g�*g�=A�C�C�C��G�V�V��p�"-�/C�_�.U�jn�"o�"o�"o������F�F�"�"ror��is_module_allowed_on_serverc���d\}}}dtj��vrtgd�d���\}}}n|rt|��\}}}|stgd�d���\}}}|||fS)z4
    Install WPOS daemon to system and start it
    )rNN�el6)z/sbin/chkconfigz--addr�Tr�)r�r��start)�platform�releaser0r�)r�r�r�rqr�s     rk�_install_daemon_internalr�0s���,��G�V�V��� �"�"�"�"�"-�._�._�._�AE�#G�#G�#G������'�	^�'K�K\�&]�&]�#�G�V�V��G�"-�.]�.]�.]�AE�#G�#G�#G������F�F�"�"roc��d}tj�|��rt|��t	��rdSt||��S)a�
    Install WPOS daemon to server if need:
        - if daemon already present - do nothing;
        - on CL Shared Pro install daemon if module allowed
    On solo and if /etc/systemd/system/clwpos_monitoring.service present it will be updated always
    We do not need restart installed daemon here, it's done in rpm_posttrans.sh
    :param is_module_allowed_on_server: True/False
    z-/etc/systemd/system/clwpos_monitoring.service)rr!r!)r�r�rr�r�r�)r�r�s  rk�install_monitoring_daemonr�CsW��H��	�w�~�~�'�(�(�@�,�->�?�?�?�#�%�%���y�#�$5�7R�S�S�Sroc��dd|�d�i}	t|��}n#t$rYdSwxYw|�d��S)Nr�zget-z-statusFr�)r�r3r�)�service�command_get_service_status_dict�
daemon_results   rk�get_status_from_daemonr�Vsd��'0�2I��2I�2I�2I�&J�#��*�+J�K�K�
�
�������u�u��������X�&�&�&s��
(�(c� �td��Srd�r�rmrork�redis_is_runningr�_s��!�'�*�*�*roc� �td��S)N�	litespeedr�rmrork�litespeed_is_runningr�ds��!�+�.�.�.ro�	attributec���ddlm}|t����}tj�|d��}	t
|��5}tj|��|cddd��S#1swxYwYdS#ttj
f$r6}tjd|��ttd�����d}~wt$rttd�����wxYw)z7
    Return attribute's value from info.json file.
    r)�get_admin_config_directoryz	info.jsonNz,Error during reading of "info.json" file: %sz�Failed to retrieve data about php version which is currently used. Daemon is not available and cache data is malformed, please try again and contact your administrator if the issue persists.z�Failed to retrieve data about php version which is currently used. Daemon is not available and cache data is not available. Contact your administrator if the issue persists.)r�r�r�r�r�r�rMr�loadr�r�rrbr3rUr�)r�r��admin_config_dir�	info_jsonr�rhs      rk�_get_data_from_info_jsonr�ism��A�@�@�@�@�@�1�1�(�*�*�=�=������-�{�;�;�I�P�
�)�_�_�	+���9�Q�<�<�	�*�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+����	+�	+�	+�	+�	+�	+���d�*�+�Q�Q�Q���J�A�N�N�N���O�P�P�Q�Q�	Q������P�P�P���N�O�O�P�P�	P�P���s;�B�A5�(B�5A9�9B�<A9�=B�C3�1C	�	*C3c�d�t}tj��rtj}||��Srx)rr�r��
contextlib�nullcontext)r�rVs  rk�drop_permissions_if_neededr��s/���G�	�z�|�|�)��(���7�8���ror�r�r�c��ddlm}||�|��vrdnd}	t|j|d���d}n#t
$rd}YnwxYw|rd}|S)Nrr��active�no)r�r��pendingF)r�r�r�r��!DAEMON_GET_UPGRADE_ATTEMPT_STATUSr3)r�r�r�r��subscription_status�
is_pendings      rk�get_subscription_statusr��s���(�(�(�(�(�(�&-�1A�1E�1E�e�1L�1L�&L�&L�(�(�RV���'�!�C��)
�)
�����
�
�������
�
�
������(�'���s�A�A�Ac�\�d\}}}	tt��}n4#ttf$r dd�t��dfcYSwxYw	t|��nG#tj$r	d\}}}Yn0tj$r	d\}}}Yntj	$r	d\}}}YnwxYw|||fS)z�
    JWT token check. Mostly copied from cllib, but with some accelerate-wp tunes, including:
    - clsolo, cladmin tokens are now valid
    - no need to check for shared, because our tools just don't work on shared
    )T�OKNFzJWT file {} read errorN)FzJWT token issuer is invalidN)FzJWT token expiredN)FzJWT token format errorN)
r$r'r�r��formatr%r)�InvalidIssuerError�ExpiredSignatureErrorr()�success_flag�
error_message�token_strings   rk�jwt_token_checkr��s��1A�-�L�-��W�� 9�:�:�����W��W�W�W��.�5�5�6O�P�P�RV�V�V�V�V�W����Z��<� � � � ���(�_�_�_�4^�1��m�\�\�\��+�U�U�U�4T�1��m�\�\�\�� �Z�Z�Z�4Y�1��m�\�\�\�Z�������4�4s-��.A�
A�A"�"B&�9B&�B&�%B&c��tj�d��p^tj�d��p?tj�d��p tj�d��pdS)z�
    Locale could be set via those envvars, let`s get them in same priority gettext does
    for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_MESSAGES = "UTF-8",
    LANG = "uk_UA.UTF-8"
    �LANGUAGE�LC_ALL�LC_MESSAGESr
�en_US)r��environr�rmrorkrr�sh��
�J�N�N�:�&�&�
��z�~�~�h�'�'�
��z�~�~�m�,�,�
��z�~�~�f�%�%�
��	roc���d}tj�|��sdSt|��5}|������cddd��S#1swxYwYdS)Nz+/usr/share/cloudlinux/accelerate-wp.version)r�r�rrMr$r�)�version_filer�s  rk�get_accelerate_wp_versionr��s���@�L�
�7�>�>�,�'�'���t�	
�l�	�	� �q��v�v�x�x�~�~��� � � � � � � � � � � � ���� � � � � � s�&A&�&A*�-A*r�)r>)r�rx)rX)rarS)rn)��
__future__rr�r}rzr�rr�r&r6r�r�r�rr��typingrJr�rrrr�globr�enumrr	rU�urllib.parser
rrr
�packaging.versionrr�r�	functoolsrr�pathlibrrrrrrrrrr��secureiorr�clcommon.cpapi.cpapiexceptionsr�clcommon.clpwdrr�clcommon.clcaptainr �clcommon.lib.cleditionr"r#�clcommon.lib.jwt_tokenr$r%�clcommon.lib.constsr&r'r�r(r)�cllicenselibr*�clcommon.cpapir+r,r-r.�clcommon.utilsr/r0r1�clwposr2�clwpos.cl_wpos_exceptionsr3r4r5r6r7r8�clcommon.ui_configr9�clcommon.clcagefsr:r;�clcommon.constr<r=�logsetupr?�clwpos.constantsr@rArBrCrDrErFrGrHrIrJrKrLrMrN�socket_utilsrOrP�user.website_check.errorsrQ�clwpos.scoped_cacherR�
TYPE_CHECKING�clwpos.php.baserSr[rnr�rqr#r�r�r�r]r�r�r�r��
struct_passwdr�r�rdr�r�r�r�r�r�rrr)r?rCrGrVrcrRr\r[rhrrrwr{r~r�r�r�r�r�r�r�r�r�r�rrrr r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�rmrork�<module>rs�
��'�&�&�&�&�&���������������������	�	�	�	�	�	�	�	�
�
�
�
�
�
�
�
�
�
�
�
���������
�
�
�
�
�
�
�
�������������0�0�0�0�0�0�0�0�0�0������������� � � � � � �������������&�%�%�%�%�%�
�
�
�
�%�%�%�%�%�%�&�&�&�&�&�&�&�&�������/�/�/�/�/�/�/�/�/�/�=�=�=�=�=�=�=�=�=�=�=�=�=�=�����;�;�;�;�;�;�;�;�3�3�3�3�3�3�1�1�1�1�1�1�1�1�$�$�$�$�$�$���������8�7�7�7�7�7�7�7�M�M�M�M�M�M�M�M�&�&�&�&�&�&�&�&�&�&�&�&�&�&�L�L�L�L�L�L�L�L�L�L�L�L�<�<�<�<�<�<�<�<�<�<�%�%�%�%�%�%�%�%�����������������(�'�'�'�'�'�;�;�;�;�;�;�;�;�"�"�"�"�"�"�5�5�5�5�5�5�#�#�#�#�#�#�����������������������������������$X�W�W�W�W�W�W�W�8�8�8�8�8�8�/�/�/�/�/�/�	��$�#�#�#�#�#�#�	
�����B3�3�3�3�3�$�*�3�3�3�*��$��4�����&��D��4��S�����*	5�	5��	5�D�	5�	5�	5�	5��4�����������4�4�4�4�4�4�&�S�->�&�&�&�&�)�)�)���s��c�����
�3�����!%�,�,�,�#�,��,�,�,�,�#�*�*�*��*�*�*�*���������*_��_�(�4�.�_�_�_�_�B8�D��I�8�8�8�8�@:�c�:�d�:�:�:�:�5�#�5�$�5�5�5�5�0&5�3�&5�4�&5�&5�&5�&5�R���d��d��s�C�x��d�d�d�d��C��8�C�=�����2	�	�	�	�	�)�	�	�	������x��}�������
�
�
��N�N�N���N��4��E�#�s�(�O�����9�9�$�9�9�9�9�"�"�"�A�A�A��A�A�A�A�A�A�A���A�
�`!�`!�`!�`!�`!�`!�`!���`!�D���.����):�����>,�,�,�(6�6�6�
�
�
�G�:P�G�G�G�G�
69�!2�69�69�69�69�r�1�n�->�?�1�1�1���1�""(�"(�"(�J���K�K�K�K�K�K�K�K�\����D��������B�
��
�
�
���
�
�3�
�4�
�
�
�
� >��>�>�>�>�=�t�=�=�=�=�@�$�@�@�@�@�6��6�6�6�6�
P��
P�H�
P��
P�
P�
P�
P�X�#�X��X�X�X�RV�X�X�X�X�&�������d�����	#�u�S�#�s�]�?S�	#�	#�	#�	#�#��#�RV�#�[`�ad�fi�kn�an�[o�#�#�#�#�&T�4�T�E�#�s�TW�-�DX�T�T�T�T�&'�'�'��+�$�+�+�+���+��/�d�/�/�/���/�P��P��P�P�P�P�.����d��3�������,5�5�5�,
�
�
� � � � � ro

Zerion Mini Shell 1.0