HEX
Server: Apache
System: Linux cpanelx.inxs.ro 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: crowdandsafety (1041)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/__pycache__/wp_utils.cpython-311.pyc
�

�]�f�=��Z�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/m0Z0m1Z1m2Z2m3Z3m4Z4ee5��Z6eGd�d����Z7de8de"fd�Z9ed���de8de"fd���Z:de8de
e"fd�Z;dd�de8de8de8dee8e7ffd�Z<dej=d e8fd!�Z>de8de?fd"�Z@d7d$e8d%e8de
e8fd&�ZAd'e8d(e8fd)�ZBde8fd*�ZCGd+�d,e��ZDe$d8de8deeDfd-���ZEd8de8deeDfd.�ZFd8de8fd/�ZGdeeDfd0�ZHd8de8d1e8de?fd2�ZId8de8d1e8de?fd3�ZJd8de8d4e8de
e7fd5�ZKd8de8de
e7fd6�ZLdS)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_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#2s8�������
�L�L�L�
�M�M�M��D�(�3�-�����r/r#�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)r1�use_saved_php_version�php_versions   r0�get_php_versionr=9sY��!�����0N�!O�!O�P�P���4�,�[�9�9�Z�=M�k�=Z�=Z���&�{�3�3���r/)�maxsizec���t��}g}|D]@}|�|d��r#|�|d|df���A|�d���|ddS)zReturn PHP version.�documentroot�versionT)�reverser�)r�
startswith�append�sort)r1�result�items�items    r0r:r:Gs����Z�Z�F��E��B�B���!�!�$�~�"6�7�7�	B��L�L�$�~�.��Y��@�A�A�A��	�J�J�t�J������8�A�;�r/c	�
�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: %sr@rAc��|ddS)NrC�
identifierr.)rIs r0�<lambda>z(_get_saved_php_version.<locals>.<lambda>os���a���.�r/T)�keyrBrrCr.)rrr6r7r8rr r�format�path�exists�open�json�load�OSError�decoder�JSONDecodeError�_logger�	exceptionrDrEr�sorted)r1�php_file_id�
php_info_file�f�	_php_info�e�php_versions�
vhost_infos        r0r9r9Ts������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��envrR�command�
subcommandc�v�t|��}t|j��}tj�|��s<t�d||��ttd��d|i���St|��||g|�}t||g|�}|pi}		t|d|	���}
n�#tj$r�}d|jv}d�|��}t�d	||j|j��tj��st&n<t)jt-jtj����j�
��}
|rt3||
��ntd��}||
|jd�}t|||j�
��cYd}~Sd}~wwxYw|
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".rR�r$r%T)�checkrezPost-check failed� z7Error 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.�rf�logger_path�
error_desc)r$r%r&N)r=r*�binr6rRrSrZr[r#�_rrr�
subprocess�CalledProcessError�stderr�join�stdout�getuidrrrQ�pwd�getpwuid�pw_dir�_process_post_check�
returncode)rRrfrgre�argsr<�php_bin_path�command_part�full_command�environment�output�error�post_check_flagrnr$r%s                r0�	wordpressr�ts,��"�$�'�'�K��{��'�'�L�
�7�>�>�,�'�'�
����?�!�<�	1�	1�	1���<�=�=��\�*�
�
�
�	
��{�+�+�+��Z�/�$�/�L�����
�	�L��)��K�
�(��T�{�S�S�S�����(�
�
�
�-���=���(�(�<�(�(�����&�"�5�<���	?�	?�	?�13�	���6�(�(�AR�AY��L�����-�-�4�B6�B6�B6���		���{�3�3�3�3��f�g�g�G�#�*�#�l���G�
����!�
�
�
�	
�	
�	
�	
�	
�	
�����'
����2�=�s�%B8�8F1�CF,�&F1�,F1rG�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 statusrCu( )’'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.rmzPost check failed�)�header�descriptionr%�fix_tip)rtrr�split�striprrrq�cmdrvr)rGr��cnd_not_active_msg�	url_match�unexpected_error_match�url_part�	code_part�urlr&�unexpected_error_static_contentr$r%s            r0r{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��-�"����	�����r/c�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�rR�eval�1rdri)	r�datar�r�
isinstancer#rr$r%)rR�markerrf�recordrGs     r0r�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�rdriz Error during get WP constant: %s)rr�r�rr�r#rr$r%rZr�)r�r��raise_exceptionrfr�rGs      r0�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�r6rRrur
�WP_REDIS_SCHEME�name�valr�
WP_REDIS_PATHrS)r�r��redis_schemar�s    r0�#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�4r/c��d}tj�tj�|d����rt	��rdnd}d|i}|S)z*
    Returns needed envars for wp-cli
    Nz	.htaccess�	LiteSpeed�Apache�SERVER_SOFTWARE)r6rRrSrur!)r1re�server_softwares   r0�obtain_wp_cli_envr�&sR���C�	�w�~�~�b�g�l�l�;��<�<�=�=�3�)=�)?�)?�M�+�+�X�� �/�2���Jr/c�8�eZdZUeed<eed<eed<eed<dS)�
PluginInfor��status�updaterAN)r'r(r)r*r+r.r/r0r�r�1s:�������

�I�I�I�
�K�K�K�
�K�K�K��L�L�L�L�Lr/r�c���|r,t|��}|�tdi��n	tdi}t|ddd|���}t	|t
��rgSd�}	t
j|��}ny#tttj
f$rZ}||��}|�t
j|��}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--jsonrdc��d}d}tj||��}|r;	|�d��}tj|��}n#t
$rYnwxYw|S)Nz(\[{.*?}\])rC)�re�search�grouprU�loads�	Exception)r��_result�pattern�matches�json_strings     r0�_maybe_jsonz(_cached_plugin_list.<locals>._maybe_jsonOss���� ���)�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.rizPMalformed plugin information received from wp-cli. Raw response is %(response)s.)r,r�rr�r�r#rUr��
ValueError�	TypeErrorrYrrqr*r�)r1�
wp_cli_envrGr��plugin_list_rawra�maybe_json_result�plugin_infos        r0�_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��/�/���(�"�j��0�0�O�O���4�5�5�$�V�,��A������
�
�O�O�O�O����������o�t�,�,�
���0�1�1� ��(�	
�
�
�	
�'�����+�t�,�,�	���4�5�5�$�V�,�	���
�	��s�'A<�<C2�AC-�-C2c��ttj�|��|r!t	|�����nd��S�N)r�r6rR�normpath�tuplerH�r1r�s  r0�plugin_listr��sK���
�����%�%��( �u�Z�-=�-=�-?�-?�'@�'@�'@����r/c�6�d�t||��D��S)Nc�*�g|]}|ddk�|��S)r��activer.)�.0rIs  r0�
<listcomp>z'list_active_plugins.<locals>.<listcomp>�s1��������>�X�%�%�	
�%�%�%r/)r�r�s  r0�list_active_pluginsr��s-����$�[�*�=�=����r/c���t|���}t|t��rt|j|j�����fd�|D��S)N)r1ric�,��g|]}|d�k�|��S)r�r.�r�rI�plugin_names  �r0r�z#get_plugin_data.<locals>.<listcomp>�s'���I�I�I�T�T�&�\�[�-H�-H�D�-H�-H�-Hr/)r�r�r#rr$r%)�wordpress_abs_pathr��plugins_datas ` r0�get_plugin_datar��sb����+=�>�>�>�L��,��/�/�6��� 4� ,� 4�6�6�6�	6�I�I�I�I�\�I�I�I�Ir/r�c�V��t�fd�t||��D����S)Nc3�H�K�|]}|d�ko|ddkV��dS)r�r�r�Nr.r�s  �r0�	<genexpr>z&is_plugin_activated.<locals>.<genexpr>�sV�����A�A���F�|�{�*�I�t�H�~��/I�A�A�A�A�A�Ar/��anyr��r1r�r�s ` r0�is_plugin_activatedr��sO����A�A�A�A�&�{�J�?�?�A�A�A�A�A�Ar/c�V��t�fd�t||��D����S)Nc3�0�K�|]}|d�kV��dS)r�Nr.r�s  �r0r�z&is_plugin_installed.<locals>.<genexpr>�s,�����\�\�t�t�F�|�{�*�\�\�\�\�\�\r/r�r�s ` r0�is_plugin_installedr��s1����\�\�\�\�{�;�PZ�7[�7[�\�\�\�\�\�\r/�
constant_namec���|�Rt|dd|dtdi���}t|t��rd}n?t|dd|ddtdi���}n!t|dd||d	dd
ddtdi���}|S)N�config�hasz--type=constantr�rd�deletez--quiet�setz--rawz/--anchor=// End of CloudLinux generated sectionz--placement=before)r�rr�r#)r1r��constant_valuerGs    r0�update_constantr��s������;��%��HY� 7��=�?�?�?���f�n�-�-�	C��F�F��{�H�h�
�O`�bk�$;�S�#A�C�C�C�F�F��;��%���X_�ar�L�Nb�dm� 7��=�?�?�?���Mr/c�B�t|tjj|��Sr�)r�r
�WP_REDIS_DISABLE_BANNERSr�)r1r�s  r0�%update_redis_disable_banners_constantr��s���;�(>�(W�(\�^l�m�m�mr/)Fr�)M�
__future__rrUr6rxr�rr�dataclassesr�typingrrr�	functoolsr�typing_extensionsr	�clwposr
rq�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'rZr#r*r=r:r9r�rsr{r5r�r�r�r�r�r�r�r�r�r�r�r�r�r.r/r0�<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�:�:�:�:�z9��-�9��9�9�9�9�x �s� �t� � � � ���S��C��8�TW�=�����.4��4�c�4�4�4�4�&�3���������������=�=�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�����&n�n�s�n�T\�]k�Tl�n�n�n�n�n�nr/