HEX
Server: LiteSpeed
System: Linux cluster02.load-balancer.x2.network 4.18.0-553.51.1.lve.1.el8.x86_64 #1 SMP Wed May 14 14:34:57 UTC 2025 x86_64
User: kbdhpghp (1098)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/__pycache__/wp_utils.cpython-311.pyc
�

׊�hRA��`�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<ed���de;de"fd���Z=de;de
e"fd�Z>dd�de;de;de;dee;e:ffd�Z?dej@d e;fd!�ZAde;deBfd"�ZCd7d$e;d%e;de
e;fd&�ZDd'e;d(e;fd)�ZEd*�ZFGd+�d,e��ZGe$d8de;deeGfd-���ZHd8de;deeGfd.�ZId8de;fd/�ZJdeeGfd0�ZKd8de;d1e;deBfd2�ZLd8de;d1e;deBfd3�ZMd8de;d4e;de
e:fd5�ZNd8de;de
e:fd6�ZOdS)9�)�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�	user_name�litespeed_is_running�nginx_is_running�apache2nginx_is_running�is_wp2_environment_safec�>�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&5s8�������
�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@<sY��!�����0N�!O�!O�P�P���4�,�[�9�9�Z�=M�k�=Z�=Z���&�{�3�3���r2)�maxsizec�*�t��}g}|D]]}|�tj�|d����r#|�|d|df���^|�d���|ddS)zReturn PHP version.�documentroot�versionT)�reverser�)r�
startswithr9�path�normpath�append�sort)r4�result�items�items    r3r=r=Js����Z�Z�F��E��B�B���!�!�"�'�"2�"2�4��3G�"H�"H�I�I�	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]@}|�|d��r#|�|d|df���A|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: %srCrDc��|ddS)NrF�
identifierr1)rNs r3�<lambda>z(_get_saved_php_version.<locals>.<lambda>rs���a���.�r2T)�keyrErrFr1)rrr9r:r;rr r�formatrH�exists�open�json�load�OSError�decoder�JSONDecodeError�_logger�	exceptionrGrJr�sorted)r4�php_file_id�
php_info_file�f�	_php_info�e�php_versions�
vhost_infos        r3r<r<Ws������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�
��!�!�*�^�"<�=�=�	U�����N�!;�Z�	�=R� S�T�T�T�����t��
�
���.�.������		�
�	�
�
�
s<�C�"C�7C�C�C�
C�C�D�*D�D��envrH�command�
subcommandc�T�t|��}t|j��}tj�|��s<t�d||��ttd��d|i���St|��||g|�}t||g|�}|pi}	t�dd�
|����	t|d|	���}
n�#tj$r�}d	|jv}d�
|��}t�d
||j|j��tj��st(n<t+jt/jtj����j���}
|rt5||
��ntd��}||
|jd
�}t|||j���cYd}~Sd}~wwxYwt�dd�
|��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".rH�r'r(zExecuting command=%s� T)�checkrizPost-check failedz7Error during command execution: 
%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.�rj�logger_path�
error_desc)r'r(r)NzCommand=%s returned output=%s)r@r-�binr9rHrWr^r_r&�_rr�info�joinr�
subprocess�CalledProcessError�stderr�stdout�getuidrrrV�pwd�getpwuid�pw_dir�_process_post_check�
returncode)rHrjrkri�argsr?�php_bin_path�command_part�full_command�environment�output�error�post_check_flagrrr'r(s                r3�	wordpressr�wsz��"�$�'�'�K��{��'�'�L�
�7�>�>�,�'�'�
����?�!�<�	1�	1�	1���<�=�=��\�*�
�
�
�	
��{�+�+�+��Z�/�$�/�L�����
�	�L��)��K��L�L�'����,�)?�)?�@�@�@�
�(��T�{�S�S�S�����(�
�
�
�-���=���(�(�<�(�(�����&�"�5�<���	?�	?�	?�13�	���6�(�(�AR�AY��L�����-�-�4�B6�B6�B6���		���{�3�3�3�3��f�g�g�G�#�*�#�l���G�
����!�
�
�
�	
�	
�	
�	
�	
�	
�����'
����0�L�L�0�#�(�(�<�2H�2H�#�f�m�J\�J\�]�]�]��=�s�C&�&G�5CG�G�GrL�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 statusrFu( )’'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.rqzPost check failed�)�header�descriptionr(�fix_tip)rzrr�split�striprrru�cmdr{r)rLr��cnd_not_active_msg�	url_match�unexpected_error_match�url_part�	code_part�urlr)�unexpected_error_static_contentr'r(s            r3r�r��s��5���V�]�*�*�� 3�H� =� =�>�>�>��I�B���F�M�!�!�&<��
�&M�&M�$�m�1�1�2H�I�I���)��n�n���q�!�����y�)�)���#�C��.�.�
�
�	
�'T�#�&�&�-�7�7��M�'�'��,�,�Q�/�	����y�)�)���!�$�'�'�
�
�	
�
�^�_�_�G��:���m�f�m�3���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�rH�eval�1rhrm)	r�datar�r�
isinstancer&rr'r()rH�markerrj�recordrLs     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�rhrmz Error during get WP constant: %s)rr�r�rr�r&rr'r(r^r�)r�r��raise_exceptionrjr�rLs      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�r9rHrwr
�WP_REDIS_SCHEME�name�valr�
WP_REDIS_PATHrW)r�r��redis_schemar�s    r3�#diagnose_redis_connection_constantsr�s*��#�2�7�<�<���#H�#H�J`�Jp�Ju�37�9�9�9�L��r�L�,B�,R�,V�V�V��p�-C�-S�-X�co� p� p�r�r�r�	r�
�R�W�\�\�'�>�B�B�DZ�Dh�Dm�-1�3�3�3�F��Y��J�!+�-C�-Q�-V� W�Y�Y�Y�	Y�
�7�>�>�&�!�!�4��N�!)�6� 2�4�4�4�	4�4�4r2c�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�updaterDN)r*r+r,r-r.r1r2r3r�r�@s:�������

�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--jsonrhc��d}d}tj||��}|r;	|�d��}tj|��}n#t
$rYnwxYw|S)Nz(\[{.*?}\])rF)�re�search�grouprY�loads�	Exception)r��_result�pattern�matches�json_strings     r3�_maybe_jsonz(_cached_plugin_list.<locals>._maybe_json^ss���� ���)�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.rmzPMalformed plugin information received from wp-cli. Raw response is %(response)s.)r/r�rr�r�r&rYr��
ValueError�	TypeErrorr]rrur-r�)r4�
wp_cli_envrLr��plugin_list_rawre�maybe_json_result�plugin_infos        r3�_cached_plugin_listr�Ns����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���4�5�5�$�V�,��A������
�
�O�O�O�O����������o�t�,�,�
���0�1�1� ��(�	
�
�
�	
�'�����+�t�,�,�	���4�5�5�$�V�,�	���
�	��s�'A<�<C �>C�C c��ttj�|��|r!t	|�����nd��S�N)r�r9rHrI�tuplerM�r4r�s  r3�plugin_listr��sK���
�����%�%��( �u�Z�-=�-=�-?�-?�'@�'@�'@����r2c�6�d�t||��D��S)Nc�*�g|]}|ddk�|��S)r��activer1)�.0rNs  r3�
<listcomp>z'list_active_plugins.<locals>.<listcomp>�s1��������>�X�%�%�	
�%�%�%r2)r�r�s  r3�list_active_pluginsr��s-����$�[�*�=�=����r2c���t|���}t|t��rt|j|j�����fd�|D��S)N)r4rmc�,��g|]}|d�k�|��S)r�r1�r�rN�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��sb����+=�>�>�>�L��,��/�/�6��� 4� ,� 4�6�6�6�	6�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>�sV�����A�A���F�|�{�*�I�t�H�~��/I�A�A�A�A�A�Ar2��anyr��r4r�r�s ` r3�is_plugin_activatedr��sO����A�A�A�A�&�{�J�?�?�A�A�A�A�A�Ar2c�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�rh�deletez--quiet�setz--rawz/--anchor=// End of CloudLinux generated sectionz--placement=before)r�rr�r&)r4r��constant_valuerLs    r3�update_constantr��s�����;��%��HY� 7��=�?�?�?���f�n�-�-�	C��F�F��{�H�h�
�O`�bk�$;�S�#A�C�C�C�F�F�
�;��%���X_�,�._�/��AX�Z]�@^�`�`�`���f�n�-�-�	a��{�H�e�]�N�\c�0�)�BY�[^�A_�a�a�a�F��Mr2c�B�t|tjj|��Sr�)r�r
�WP_REDIS_DISABLE_BANNERSr�)r4r�s  r3�%update_redis_disable_banners_constantr�s���;�(>�(W�(\�^l�m�m�mr2)Fr�)P�
__future__rrYr9r}r�rx�dataclassesr�typingrrr�	functoolsr�typing_extensionsr	�clwposr
ru�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*r^r&r-r@r=r<r�ryr�r8r�r�r�r�r�r�r�r�r�r�r�r�rr1r2r3�<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�����������
 ������/�/�/�/�/�/�-�-�-�-�-�-�J�J�J�J�J�J�J�J�����������

�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
��-��
!�
!�����������������������4����	�#�	�#�	�	�	���	�
��
���
�
�
�
�
�@DH�;�;�;�C�;�#�;�3�;�E�RU�We�Re�Lf�;�;�;�;�|9��-�9��9�9�9�9�x �s� �t� � � � ���S��C��8�TW�=�����.4��4�c�4�4�4�4�&���,����������=�=�S�=�d�:�>N�=�=�=���=�@��S��d�:�6F�������S�����J��Z�8H�J�J�J�J�A�A�S�A�s�A�PT�A�A�A�A�
]�]�S�]�s�]�PT�]�]�]�]�����S��RZ�[i�Rj�����0n�n�s�n�T\�]k�Tl�n�n�n�n�n�nr2