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/cloudlinux/venv/lib/python3.11/site-packages/clwpos/__pycache__/wp_utils.cpython-311.pyc
�

�4j�D��p�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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6ee7��Z8eGd�d����Z9de:de"fd�Z;de:de:de<fd�Z=ed���de:de"fd���Z>de:de
e"fd�Z?dd�de:de:de:dee:e9ffd �Z@d!ejAd"e:fd#�ZBde:de<fd$�ZCd9d&e:d'e:de
e:fd(�ZDd)e:d*e:fd+�ZEd,�ZFGd-�d.e��ZGe$d:de:deeGfd/���ZHd:de:deeGfd0�ZId:de:fd1�ZJdeeGfd2�ZKd:de:d3e:de<fd4�ZLd:de:d3e:de<fd5�ZMd:de:d6e:de
e9fd7�ZNd:de:de
e9fd8�ZOdS);�)�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_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%4s8�������
�L�L�L�
�M�M�M��D�(�3�-�����r1r%�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)r3�use_saved_php_version�php_versions   r2�get_php_versionr?;sY��!�����0N�!O�!O�P�P���4�,�[�9�9�Z�=M�k�=Z�=Z���&�{�3�3���r1�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)r8�path�realpath�
commonpath�
ValueError)r3r@�resolved_docroot�resolved_wp_paths    r2�_path_within_docrootrHIs|���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.r@�versionT)�reverser�)rrH�append�sort)r3�result�items�items    r2r<r<\s~���Z�Z�F��E��B�B����T�.�-A�B�B�	B��L�L�$�~�.��Y��@�A�A�A��	�J�J�t�J������8�A�;�r1c	��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: %sr@rKc��|ddS)NrM�
identifierr0)rRs r2�<lambda>z(_get_saved_php_version.<locals>.<lambda>�s���a���.�r1T)�keyrLrrMr0)rrr8r9r:rr r�formatrB�exists�open�json�load�OSError�decoder�JSONDecodeError�_logger�	exceptionrHrNr�sorted)r3�php_file_id�
php_info_file�f�	_php_info�e�php_versions�
vhost_infos        r2r;r;is������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��
�
���.�.������		�
�	�
�
�
s<�C�"C�7C�C�C�
C�C�D�*D�D��envrB�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".rB�r&r'zExecuting command=%s� T)�checkrmzPost-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.�rn�logger_path�
error_desc)r&r'r(NzCommand=%s returned output=%s)r?r,�binr8rBr[rbrcr%�_rr�info�joinr�
subprocess�CalledProcessError�stderr�stdout�getuidrrrZ�pwd�getpwuid�pw_dir�_process_post_check�
returncode)rBrnrorm�argsr>�php_bin_path�command_part�full_command�environment�output�error�post_check_flagrvr&r's                r2�	wordpressr��sz��"�$�'�'�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�GrP�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 statusrMu( )’'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.ruzPost check failed�)�header�descriptionr'�fix_tip)r~rr�split�striprrry�cmdrr)rPr��cnd_not_active_msg�	url_match�unexpected_error_match�url_part�	code_part�urlr(�unexpected_error_static_contentr&r's            r2r�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��-�"����	�����r1c�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�rB�eval�1rlrq)	r�datar�r�
isinstancer%rr&r')rB�markerrn�recordrPs     r2r�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�rlrqz Error during get WP constant: %s)rr�r�rr�r%rr&r'rbr�)r�r��raise_exceptionrnr�rPs      r2�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�r8rBr{r
�WP_REDIS_SCHEME�name�valr�
WP_REDIS_PATHr[)r�r��redis_schemar�s    r2�#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�4r1c�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  r2�obtain_wp_cli_envr�<sb���O������"�%���	�	�	�"�!��� � �;� :��+�!6���r1c�8�eZdZUeed<eed<eed<eed<dS)�
PluginInfor��status�updaterKN)r)r*r+r,r-r0r1r2r�r�Rs:�������

�I�I�I�
�K�K�K�
�K�K�K��L�L�L�L�Lr1r�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--jsonrlc��d}d}tj||��}|r;	|�d��}tj|��}n#t
$rYnwxYw|S)Nz(\[{.*?}\])rM)�re�search�groupr]�loads�	Exception)r��_result�pattern�matches�json_strings     r2�_maybe_jsonz(_cached_plugin_list.<locals>._maybe_jsonpss���� ���)�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.rqzPMalformed plugin information received from wp-cli. Raw response is %(response)s.)r.r�rr�r�r%r]r�rE�	TypeErrorrarryr,r�)r3�
wp_cli_envrPr��plugin_list_rawri�maybe_json_result�plugin_infos        r2�_cached_plugin_listr�`s����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�r8rB�normpath�tuplerQ�r3r�s  r2�plugin_listr��sK���
�����%�%��( �u�Z�-=�-=�-?�-?�'@�'@�'@����r1c�6�d�t||��D��S)Nc�*�g|]}|ddk�|��S)r��activer0)�.0rRs  r2�
<listcomp>z'list_active_plugins.<locals>.<listcomp>�s1��������>�X�%�%�	
�%�%�%r1)r�r�s  r2�list_active_pluginsr��s-����$�[�*�=�=����r1c���t|���}t|t��rt|j|j�����fd�|D��S)N)r3rqc�,��g|]}|d�k�|��S)r�r0�r�rR�plugin_names  �r2r�z#get_plugin_data.<locals>.<listcomp>�s'���I�I�I�T�T�&�\�[�-H�-H�D�-H�-H�-Hr1)r�r�r%rr&r')�wordpress_abs_pathr��plugins_datas ` r2�get_plugin_datar��sb����+=�>�>�>�L��,��/�/�6��� 4� ,� 4�6�6�6�	6�I�I�I�I�\�I�I�I�Ir1r�c�V��t�fd�t||��D����S)Nc3�H�K�|]}|d�ko|ddkV��dS)r�r�r�Nr0r�s  �r2�	<genexpr>z&is_plugin_activated.<locals>.<genexpr>�sV�����A�A���F�|�{�*�I�t�H�~��/I�A�A�A�A�A�Ar1��anyr��r3r�r�s ` r2�is_plugin_activatedr��sO����A�A�A�A�&�{�J�?�?�A�A�A�A�A�Ar1c�V��t�fd�t||��D����S)Nc3�0�K�|]}|d�kV��dS)r�Nr0r�s  �r2r�z&is_plugin_installed.<locals>.<genexpr>�s,�����\�\�t�t�F�|�{�*�\�\�\�\�\�\r1r�r�s ` r2�is_plugin_installedr��s1����\�\�\�\�{�;�PZ�7[�7[�\�\�\�\�\�\r1�
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�rl�deletez--quiet�setz--rawz/--anchor=// End of CloudLinux generated sectionz--placement=before)r�rr�r%)r3r��constant_valuerPs    r2�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��Mr1c�B�t|tjj|��Sr�)rr
�WP_REDIS_DISABLE_BANNERSr�)r3rs  r2�%update_redis_disable_banners_constantr�s���;�(>�(W�(\�^l�m�m�mr1)Fr�)P�
__future__rr]r8r�r�r|�dataclassesr�typingrrr�	functoolsr�typing_extensionsr	�clwposr
ry�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)rbr%r,r?r7rHr<r;r�r}r�r�r�r�r�r�r�r�r�r�r�r�rrr0r1r2�<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�����������
	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	��-��
!�
!����������������������c���������&��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�nr1