HEX
Server: LiteSpeed
System: Linux osault1.hostarmada.net 4.18.0-553.123.2.lve.el8.x86_64 #1 SMP Thu May 7 23:17:13 UTC 2026 x86_64
User: tucom (1048)
PHP: 8.4.24
Disabled: NONE
Upload Files
File: //opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/__pycache__/wp_utils.cpython-311.pyc
�

�wljwI��t�ddlmZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZmZddl
mZddlmZddlmZddlmZmZdd	lmZmZmZdd
lmZddlmZmZm Z ddl!m"Z"dd
l#m$Z$ddl%m&Z&ddl'm(Z(m)Z)ddl*m+Z+m,Z,m-Z-ddl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7ee8��Z9eGd�d����Z:de;de"fd�Z<de;de;de=fd�Z>ed���de;de"fd���Z?de;de
e"fd�Z@dd�de;de;d e;dee;e:ffd!�ZAd"ejBd#e;fd$�ZCde;de=fd%�ZDd:d'e;d(e;de
e;fd)�ZEd*e;d+e;fd,�ZFd-�ZGGd.�d/e��ZHe$d;de;deeHfd0���ZId;de;deeHfd1�ZJd;de;fd2�ZKdeeHfd3�ZLd;de;d4e;de=fd5�ZMd;de;d4e;de=fd6�ZNd;de;d7e;de
e:fd8�ZOd;de;de
e:fd9�ZPdS)<�)�absolute_importN)�	dataclass)�Optional�Union�List)�	lru_cache)�	TypedDict)�gettext)�	WposError�WpCliCommandError)�RedisRequiredConstants�WP_CLI�WP_CLI_SKIP_PLUGINS_ENV)�php_info)�
setup_logging�ADMIN_LOGFILE_PATH�USER_LOGFILE_PATH)�PHP)�cached_in_scope)�wp_config_cache)�RollbackException�WebsiteCheckError)�WebsiteCheckBadHttpCode�CDNActivationFailed�JSCssCheckBadHttpCode)	�WposUser�is_run_under_user�wp_cli_compatibility_check�run_in_cagefs_if_needed�redact_command_secrets�	user_name�litespeed_is_running�nginx_is_running�apache2nginx_is_runningc�>�eZdZUeed<eed<dZeeed<dS)�WordpressError�message�contextN�code)	�__name__�
__module__�__qualname__�str�__annotations__�dictr)r�int���F/opt/cloudlinux/venv/lib64/python3.11/site-packages/clwpos/wp_utils.pyr&r&-s8�������
�L�L�L�
�M�M�M��D�(�3�-�����r2r&�abs_wp_path�returnc��ttj�d����}|rt	|��pt|��}nt|��}|S)z�
    Return php_version that will be used for calling wp-cli commands.
    If 'CLWPOS_USE_SAVED_PHP_VERSION' envar is defined,
    try to get this version from a previously saved file.
    �CLWPOS_USE_SAVED_PHP_VERSION)�bool�os�environ�get�_get_saved_php_version�_get_php_version)r4�use_saved_php_version�php_versions   r3�get_php_versionr@4sY��!�����0N�!O�!O�P�P���4�,�[�9�9�Z�=M�k�=Z�=Z���&�{�3�3���r2�documentrootc���tj�|��}tj�|��}	tj�||g��|kS#t$rYdSwxYw)a

    Return True if abs_wp_path is the documentroot or a path contained within it,
    using canonical containment rather than a raw string prefix so that a path
    containing ``..`` cannot escape the documentroot while still textually
    matching its prefix.
    F)r9�path�realpath�
commonpath�
ValueError)r4rA�resolved_docroot�resolved_wp_paths    r3�_path_within_docrootrIBs|���w�'�'��5�5���w�'�'��4�4����w�!�!�#3�5E�"F�G�G�K[�[�[�������u�u����s�$A%�%
A3�2A3�)�maxsizec���t��}g}|D];}t||d��r#|�|d|df���<|�d���|ddS)zReturn PHP version.rA�versionT)�reverser�)rrI�append�sort)r4�result�items�items    r3r=r=Ws~���Z�Z�F��E��B�B����T�.�-A�B�B�	B��L�L�$�~�.��Y��@�A�A�A��	�J�J�t�J������8�A�;�r2c	��t��std���tj�d��}tt
����j�|���}tj	�
|��sdS	t|��5}tj
|��}ddd��n#1swxYwYnD#ttjjf$r&}t"�d|��Yd}~dSd}~wwxYwg}|D];}t'||d��r#|�|d|df���<|sdSt+d
it-|d�d	�
��dd��S)z@
    Get domain's php version from a previously saved file.
    z*Internal Error. Contact CloudLinux support�CLWPOS_PHP_FILE_ID)�file_idNz,Error during reading of ".php_info" file: %srArMc��|ddS)NrO�
identifierr1)rTs r3�<lambda>z(_get_saved_php_version.<locals>.<lambda>}s��t�A�w�|�7L�r2T)�keyrNrrOr1)rrr9r:r;rr!r�formatrC�exists�open�json�load�OSError�decoder�JSONDecodeError�_logger�	exceptionrIrPr�sorted)r4�php_file_id�
php_info_file�f�	_php_info�e�php_versions�
vhost_infos        r3r<r<ds������F��D�E�E�E��*�.�.�!5�6�6�K��Y�[�[�)�)�2�9�9�+�9�N�N�M�
�7�>�>�-�(�(���t��
�-�
 �
 �	%�A��	�!���I�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%����	%�	%�	%�	%����T�\�1�2�������J�A�N�N�N��t�t�t�t�t����������L��U�U�
���Z��-G�H�H�	U�����N�!;�Z�	�=R� S�T�T�T�����t��b�b���*L�*L�VZ�[�[�[�\]�^�_`�a�b�b�bs<�C�"C�7C�C�C�
C�C�D�*D�D��envrC�command�
subcommandc�$�t|��}t|j��}tj�|��s<t�d||��ttd��d|i���St|��||g|�}t||g|�}|pi}	t�dd�
t|������	t|d|	���}
�nI#t j$�r6}d	|jv}t|j��|_d�
t|����}t|��}t|��}d}
t�d
||j|j|j��tj��st0n<t3jt7jtj����j���}|rt=||��ntd��}|||jd
�}t|||j���cYd}~Sd}~wwxYwt�dd�
t|����t|
j����|
jS)a[
    Helper to execute wp commands, for example
        wp --path=<path> plugin install redis-cache
        wp --path=<path> plugin activate redis-cache
        wp --path=<path> redis enable
        wp --path=<path> plugin deactivate redis-cache
        wp --path=<path> plugin uninstall redis-cache
    @return: stderr if error was happened.
    zLError during wp-cli command execution "%s": invalid path to binary file "%s"zQError during resolving path to php binary file:
got non-existent path "%(path)s".rC�r'r(zExecuting command=%s� T)�checkrozPost-check failedzEError during command execution: 
%s
returncode=%s
stdout=%s
stderr=%s)�homedirz�Unexpected error happened during command execution: '%(command)s'.
Event is logged to file: '%(logger_path)s' with stdout and stderr recorded.�rp�logger_path�
error_desc)r'r(r)NzCommand=%s returned output=%s)r@r-�binr9rCr]rdrer&�_rr�info�joinr r�
subprocess�CalledProcessError�stderr�cmd�error�
returncode�stdout�getuidrrr\�pwd�getpwuid�pw_dir�_process_post_check)rCrprqro�argsr?�php_bin_path�command_part�full_command�environment�outputr��post_check_flag�__traceback_hide__rxr'r(s                 r3�	wordpressr��s���"�$�'�'�K��{��'�'�L�
�7�>�>�,�'�'�
����^�`g�iu�	
�	
�	
���l�m�m��\�*�
�
�
�	
�
�{�+�+�+��Z�/�$�/�L��L�$�>��>�L��)��K��L�L�'����2H��2V�2V�)W�)W�X�X�X�*W�(��T�{�S�S�S�����(�(W�(W�(W�-���=��+�5�9�5�5��	��(�(�1�,�?�?�@�@��.�l�;�;��-�l�;�;��!���
�
�W�����L��L�	
�	
�	
��9�;�;�
T���"�)�#�,�r�y�{�{�2K�2K�2R�S�S�S�	�
�	c���{�3�3�3�3��^���G�#*�+�UZ�Ua�b�b�G��g�w�U�EU�V�V�V�V�V�V�V�V�V�����Q(W����R�L�L�0�#�(�(�;Q�R^�;_�;_�2`�2`�be�fl�fs�bt�bt�u�u�u��=�s� C4�4H:�D+H5�/H:�5H:rR�log_pathc��d}||jvrtt|�����d}d}||jvrr||jvri|j�|��\}}|���d}|�d��}tt||�����d}	|	|jvrQ|j�d��d}|�d��}tt
|�����td��}
|j||j	|jzd	�}ttd
|
|d������)
zx
    In some rare cases plugin installation (CDN) may return
    post-check errors which we should handle properly.
    zCDN url not found on pagezURL z#returned unexpected response statusrOu( )’'z+CDN url returned unexpected response status�(z�WordPress plugin failed to activate correctly. Changes were reverted and caching module is now disabled.
Error reported from plugin: 
%(error_desc)s.

Event is logged to file: '%(logger_path)s' with stdout and stderr recorded.rwzPost check failed�)�header�descriptionr(�fix_tip)r�rr�split�striprrr{r�r�r)rRr��cnd_not_active_msg�	url_match�unexpected_error_match�url_part�	code_part�urlr)�unexpected_error_static_contentr'r(s            r3r�r��sk��5���V�]�*�*�� 3�H� =� =�>�>�>��I�B���F�M�!�!�&<��
�&M�&M�$�m�1�1�2H�I�I���)��n�n���q�!�����y�)�)��� 7��T� B� B�C�C�C�'T�#�&�&�-�7�7��M�'�'��,�,�Q�/�	����y�)�)��� 5�d� ;� ;�<�<�<��	V���G�!�*�X�V�]�]c�]j�Mj�k�k�G�
��&����		
�	
�	
���r2c�H�d}d|z}td|���5}|jr||jvcddd��St|d|tdi���}t	|t
��rt
|j|j����||_||vcddd��S#1swxYwYdS)	N�cl_multisite_detectedzCif ( is_multisite() ) { echo "%s"; } else { echo "not_multisite"; }�is_multisite�rC�eval�1rnrs)	r�datar�r�
isinstancer&rr'r()rC�markerrp�recordrRs     r3r�r��s��
$�F�S�V\�\�G�	��d�	3�	3�	3� �v��;�	)��V�[�(� � � � � � � � ��4���7N�PS�6T�U�U�U���f�n�-�-�	L��F�N�F�N�K�K�K�K������� � � � � � � � � � � � ���� � � � � � s�B�AB�B�BF�wp_path�constantc��dd|iz}td|z|���5}|jr|jcddd��St|d|tdi���}t	|t
��rF|rt
|j|j�	���t�
d
|��	ddd��dS||_|cddd��S#1swxYwYdS)zt
    Get:
    - defined constant value
    - None in case of error
    - empty string if no such constant found
    z-if (defined('%(const)s')) { echo %(const)s; }�constzconst.r�Nr�r�rnrsz Error during get WP constant: %s)rr�r�rr�r&rr'r(rdr�)r�r��raise_exceptionrpr�rRs      r3�wp_get_constantr�s`��>��(�@S�S�G�	��H�,�7�	;�	;�	;��v��;�	��;����������7�F�G�:Q�SV�9W�X�X�X���f�n�-�-�	��
X�'�����W�W�W�W��M�M�<�f�E�E�E����������������������������������s�C�A(C�,C�C�C�docroot�wordpress_pathc�"�ttj�||��tjjd���}|s8|tjjkr#tdtjj|d�����ttj�||��tj	jd���}|s"tddtj	ji����tj�
|��stdd	|i����d
S)zE
    Check required constants for redis connection establishment
    T)r�zVWordPress constant "%(constant)s" is not defined or defined with wrong value %(value)s)r��value)r(z0WordPress constant "%(constant)s" is not definedr�z4Redis socket %(socket)s does not exist in the system�socketN)r�r9rCr}r
�WP_REDIS_SCHEME�name�valr�
WP_REDIS_PATHr])r�r��redis_schemar�s    r3�#diagnose_redis_connection_constantsr�%s&��#�
����W�n�-�-�/E�/U�/Z�lp����L��
�L�,B�,R�,V�V�V��d�!7�!G�!L�Wc�d�d�
�
�
�	
��
����W�n�-�-�/E�/S�/X�jn����F��
��>��!7�!E�!J�K�
�
�
�	
��7�>�>�&�!�!�l��N�Ya�ci�Xj�k�k�k�k�l�lr2c�v�d}d}t��rd}nt��rd}t��rd}||d�S)z*
    Returns needed envars for wp-cli
    �Apacher��	LiteSpeed�nginxzCloudLinux MAx Webserver)�SERVER_SOFTWARE�SERVER_SOFTWARE_EXTRA)r"r#r$)�server_software�server_software_extras  r3�obtain_wp_cli_envr�=sb���O������"�%���	�	�	�"�!��� � �;� :��+�!6���r2c�8�eZdZUeed<eed<eed<eed<dS)�
PluginInfor��status�updaterMN)r*r+r,r-r.r1r2r3r�r�Ss:�������

�I�I�I�
�K�K�K�
�K�K�K��L�L�L�L�Lr2r�c��|r,t|��}|�tdi��n	tdi}t|ddd|���}t	|t
��rgSd�}	t
j|��}ng#tttj
f$rH}||��}|�|}n.ttd��d|it|���	���Yd}~nd}~wwxYwt	|t��s ttd
��d|i����|D]7}t	|t��s ttd��d|i�����8|S)
Nr��plugin�listz--jsonrnc��d}d}tj||��}|r;	|�d��}tj|��}n#t
$rYnwxYw|S)Nz(\[{.*?}\])rO)�re�search�groupr_�loads�	Exception)r��_result�pattern�matches�json_strings     r3�_maybe_jsonz(_cached_plugin_list.<locals>._maybe_jsonqss���� ���)�G�V�,�,���	�
�%�m�m�A�.�.���*�[�1�1�����
�
�
���
�����s�)A�
A�AzQMalformed plugins information received from wp-cli. Raw response is %(response)s.�response)r'r(�detailszIMalformed plugin list received from wp-cli. Raw response is %(response)s.rszPMalformed plugin information received from wp-cli. Raw response is %(response)s.)r/r�rr�r�r&r_r�rF�	TypeErrorrcrr{r-r�)r4�
wp_cli_envrRr��plugin_list_rawrk�maybe_json_result�plugin_infos        r3�_cached_plugin_listr�as����4��*�%�%�
����2�C�8�9�9�9�9�-�s�3�
�
�{�H�f�h�J�
O�
O�
O�F��&�.�)�)���	������*�V�,�,�����	�4�#7�8�	�	�	�'�K��/�/���(�/�O�O���m�n�n�#�V�,��A������
�
�O�O�O�O�����	�����o�t�,�,�
���a�b�b���(�
�
�
�	
�
'�����+�t�,�,�	���l�m�m�#�V�,����
�	�
�s�'A<�<C �>C�C c��ttj�|��|r!t	|�����nd��S�N)r�r9rC�normpath�tuplerS�r4r�s  r3�plugin_listr��sB���r�w�/�/��<�<�[e�>o�e�J�DT�DT�DV�DV�>W�>W�>W�ko�p�p�pr2c�6�d�t||��D��S)Nc�*�g|]}|ddk�|��S)r��activer1)�.0rTs  r3�
<listcomp>z'list_active_plugins.<locals>.<listcomp>�s'��`�`�`�T�T�(�^�W_�E_�E_�D�E_�E_�E_r2)r�r�s  r3�list_active_pluginsr��s ��`�`�[��j�A�A�`�`�`�`r2c���t|���}t|t��rt|j|j�����fd�|D��S)N)r4rsc�,��g|]}|d�k�|��S)r�r1�r�rT�plugin_names  �r3r�z#get_plugin_data.<locals>.<listcomp>�s'���I�I�I�T�T�&�\�[�-H�-H�D�-H�-H�-Hr2)r�r�r&rr'r()�wordpress_abs_pathr��plugins_datas ` r3�get_plugin_datar��sZ����+=�>�>�>�L��,��/�/�T��� 4�l�>R�S�S�S�S�I�I�I�I�\�I�I�I�Ir2r�c�V��t�fd�t||��D����S)Nc3�H�K�|]}|d�ko|ddkV��dS)r�r�r�Nr1r�s  �r3�	<genexpr>z&is_plugin_activated.<locals>.<genexpr>�sK�������GK��V���#�B��X��(�(B������r2��anyr��r4r�r�s ` r3�is_plugin_activatedr��sG��������OZ�[f�hr�Os�Os������r2c�V��t�fd�t||��D����S)Nc3�0�K�|]}|d�kV��dS)r�Nr1r�s  �r3r�z&is_plugin_installed.<locals>.<genexpr>�s,�����\�\�t�t�F�|�{�*�\�\�\�\�\�\r2r�r�s ` r3�is_plugin_installedr��s1����\�\�\�\�{�;�PZ�7[�7[�\�\�\�\�\�\r2�
constant_namec�X�|�Rt|dd|dtdi���}t|t��rd}nst|dd|ddtdi���}nUt|dd||d	dd
ddtdi���}t|t��rt|dd||d	ddtdi��	�	}|S)N�config�hasz--type=constantr�rn�deletez--quiet�setz--rawz/--anchor=// End of CloudLinux generated sectionz--placement=before)r�rr�r&)r4r��constant_valuerRs    r3�update_constantr�s�������5�-�9J�Qh�jm�Pn�
�
�
���f�n�-�-�	��F�F������!��,�c�2����F�F���������=� ��(�#�.�
�
�
���f�n�-�-�	��������!��,�c�2�
�
�
�F��Mr2c�B�t|tjj|��Sr�)rr
�WP_REDIS_DISABLE_BANNERSr�)r4rs  r3�%update_redis_disable_banners_constantr�s���;�(>�(W�(\�^l�m�m�mr2)Fr�)Q�
__future__rr_r9r�r�r~�dataclassesr�typingrrr�	functoolsr�typing_extensionsr	�clwposr
r{�clwpos.cl_wpos_exceptionsrr�clwpos.constantsr
rr�clwpos.data_collector_utilsr�clwpos.logsetuprrr�clwpos.php.baser�clwpos.scoped_cacher�clwpos.user.cacher�clwpos.user.website_checkrr� clwpos.user.website_check.errorsrrr�clwpos.utilsrrrrr r!r"r#r$r*rdr&r-r@r8rIr=r<r�rr�r�r�r�r�r�r�r�r�r�r�r�rrr1r2r3�<module>rs���'�&�&�&�&�&�����	�	�	�	�
�
�
�
�	�	�	�	�����!�!�!�!�!�!�(�(�(�(�(�(�(�(�(�(�������'�'�'�'�'�'�������B�B�B�B�B�B�B�B�T�T�T�T�T�T�T�T�T�T�0�0�0�0�0�0�P�P�P�P�P�P�P�P�P�P�������/�/�/�/�/�/�-�-�-�-�-�-�J�J�J�J�J�J�J�J�p�p�p�p�p�p�p�p�p�p�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
��-��
!�
!����������������������c���������*��3����	�#�	�#�	�	�	���	�c��c���
�c�c�c�c�8DH�F�F�F�C�F�#�F�3�F�E�RU�We�Re�Lf�F�F�F�F�R3�
� =�3��3�3�3�3�l �s� �t� � � � ���S��C��8�TW�=�����.l��l�c�l�l�l�l�0���,����������6�6�S�6�d�:�>N�6�6�6���6�rq�q�S�q�d�:�6F�q�q�q�q�a�a�S�a�a�a�a�J��Z�8H�J�J�J�J���S��s��PT�����]�]�S�]�s�]�PT�]�]�]�]�0�0��0�S�0�RZ�[i�Rj�0�0�0�0�fn�n�s�n�T\�]k�Tl�n�n�n�n�n�nr2