????

Your IP : 3.14.141.163


Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/__pycache__/clwpos_lib.cpython-311.pyc

�

�j�e�8��D�ddlmZddlmZddlmZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
mZmZmZddlmZddlmZdd	lmZGd
�de��ZGd�d
e��Zdededeeeffd�Zdedefd�Zdeee
fdefd�Zdedefd�Zdeee
fdefd�Zdeee
fdefd�Z d/dedeeede
efd�Z!d�Z"de
fd�Z#d �Z$d!�Z%de
d"efd#�Z&d$e
d%e
deefd&�Z'd$e
deefd'�Z(d0d)�Z)d*�Z*d+�Z+d,�Z,d-�Z-d.�Z.dS)1�)�print_function)�absolute_import)�divisionN)�Path)�Union�Iterable�Optional�Tuple�List)�Enum)�ClPwd)�get_rhn_systemid_valuec��eZdZdZdZdZdS)�
PluginTypez2
    Plugin types that are currently detected
    zobject-cachezadvanced-cacheN)�__name__�
__module__�__qualname__�__doc__�OBJECT_CACHE�ADVANCED_CACHE����/builddir/build/BUILDROOT/alt-python27-cllib-3.3.15-1.el8.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/clwpos_lib.pyrrs$��������"�L�%�N�N�Nrrc��eZdZdZdZdZdZdS)�	WpPluginszj
    Static WP plugin names, that are not detected
    dynamically from drop-in files, dir names, etc
    �Unknownz	WP Rocket�AccelerateWPN)rrrr�UNKNOWN�	WP_ROCKET�
ACCELERATE_WPrrrrr s)���������G��I�"�M�M�Mrr�line�is_multiline_comment�returnc�
�|r[d|vrdS|�d��}t|d|�d��\}}t||dzd�d��\}}||z|fSd|vr!|�d��}|d|�dfSd|vr!|�d��}|d|�dfSd	|vrU|�d	��}t|d|�d��\}}t||dzd�d��\}}||z|fS|dfS)
z�
    Yep, this bicycle is needed to handle different comment types in .php file
    https://www.php.net/manual/en/language.basic-syntax.comments.php
    and ensure that needed line is not under comment
    z*/)�TNT�Fz//�#z/*)�find�
clean_comment)r!r"�pos�part1�_�part2s      rr)r)*s;���7��t����8��)�)�D�/�/�C�$�T�$�3�$�Z��6�6�H�E�1�*7��S�1�W�X�X���*N�*N�'�E�'��5�=�"6�6�6��t�|�|��i�i��o�o���D�S�D�z�5� � �
�d�{�{��i�i��n�n���D�S�D�z�5� � ��t�|�|��i�i��o�o�� ��d�s�d��U�3�3���q�&3�D��q����N�D�&I�&I�#��#��u�}�2�2�2���;�r�filec�~�tj�|��}tj�|��S�N)�os�path�realpath�isfile)r.�
realpath_files  r�
_is_real_filer6Js+���G�$�$�T�*�*�M�
�7�>�>�-�(�(�(r�abs_pathc�X�	tj�|d��}tj�|��rt	|��rdSn#t
$rYnwxYwtj�|tj��}tj�|d��}tj�|d��}tj�|��ot	|��}tj�|��o|ot	|��S)a&
    WordPress looks for wp-config.php file in the
    (1) WordPress root and (2) one directory above the root.

    Check that there is no wp-settings.php file in the second case.
    This check helps when there is a nested installation, e.g
    / is WordPress and /wp_path/ is WordPress.
    �
wp-config.phpTzwp-settings.php)r1r2�join�existsr6�OSError�pardir)r7�
wp_config_php�abs_path_level_up�wp_config_php_level_up�wp_settings_php�wp_settings_php_existss      r�_check_wp_config_phprCOs��
�����X��?�?�
�
�7�>�>�-�(�(�	�]�=�-I�-I�	��4����
�
�
���
��������X�r�y�9�9���W�\�\�*;�_�M�M���g�l�l�#4�6G�H�H�O��W�^�^�O�<�<�_���A_�A_��
�7�>�>�0�1�1�1�%�%�1��/�0�0�1s�AA�
A �A �dirc�~�tj�|��}tj�|��Sr0)r1r2r3�isdir)rD�realpath_dirs  r�_is_real_dirrHis+���7�#�#�C�(�(�L�
�7�=�=��&�&�&rc��tj�|d��}dtj|��vot	|��S)z.
    Check wp-includes exists and is dir.
    zwp-includes)r1r2r:�listdirrH)r7�wp_includess  r�_check_wp_includesrLns;���'�,�,�x��7�7�K��B�J�x�0�0�0�N�\�+�5N�5N�Nrc���	tj�|��sdSn#t$rYdSwxYw	t	|��ot|��S#t$rYnwxYwdS)z�
    Checks whether passed directory is a wordpress directory
    by checking presence of wp-includes folder and wp-config.php file.
    F)r1r2r;r<rCrL)r7s r�
is_wp_pathrNvs���
��w�~�~�h�'�'�	��5�	�������u�u�����
�#�H�-�-�N�2D�X�2N�2N�N���
�
�
���
�����5s�$�
2�2�A�
A!� A!�doc_root�excludesc#�<K�tj�|��sdSt|��rdV�t	|�����D]C}|���s�|rt|��|vr�+t|��r	|jV��DdS)z�
    Returns folder with wordpress
    Empty string is wp is in docroot dir

    :param doc_root:
        root path to start search from
    :param excludes:
        list of paths that must be excluded from search, e.g. subdomains
    Nr%)	r1r2r;rNr�iterdir�is_dir�str�name)rOrPr2s   r�
find_wp_pathsrV�s������7�>�>�(�#�#�����(���������X���&�&�(�(�����{�{�}�}�	���	��D�	�	�X�-�-���d���	��)�O�O�O���rc�2�tjd|�d|�d���}t|d���5}d}	|���}|sn7t	||��\}}|�|��r	ddd��dS�N	ddd��n#1swxYwYdS)	z8
    Looks for defined php variable with true value
    z^\s*define\s*\(\s*((\'z\')|(\"z\"))\s*,\s*true\s*\)\s*;�ignore��errorsFTN)�re�compile�open�readliner)�match)�varr2�r�fr"r!�cleaned_lines       r�_is_php_define_var_foundrd�s��	�
�V�S�V�V��V�V�V�W�W�A�	
�d�8�	$�	$�	$���$��	��:�:�<�<�D��
��1>�t�EY�1Z�1Z�.�L�.��w�w�|�$�$�
����������	���������������������5s�AB�>B�B�B�wordpress_pathc��|�d��}tj�|��sdSt	d|��S)z�
    Detects whether plugin is really enabled,
    cause not all plugins are enabled 'on load'
    # https://kevdees.com/what-are-wordpress-drop-in-plugins/
    r9F�WP_CACHE)�joinpathr1r2r;rd)re�	wp_configs  r�is_advanced_cache_enabledrj�sB���'�'��8�8�I�
�7�>�>�)�$�$���u�#�J�	�:�:�:rc�f�t|���!td|��rtjjSdS)z�
    They are advising to check whether WP_ROCKET_ADVANCED_CACHE is defined
    to ensure plugin is working
    https://docs.wp-rocket.me/article/134-advanced-cache-error-message
    N�WP_ROCKET_ADVANCED_CACHE)�accelerate_wp_pluginrdrr�value)�drop_in_paths r�wp_rocket_pluginrp�s6���L�)�)�1�$�%?��N�N�2��"�(�(��4rc��t|d���5}d|���vrtjjcddd��S	ddd��n#1swxYwYdS)zB
    Checking if the plugin folder name exists in the drop-in
    rXrYz/clsopN)r]�readrr rn)rorbs  rrmrm�s���
�l�8�	,�	,�	,�1���q�v�v�x�x����*�0�1�1�1�1�1�1�1�1��1�1�1�1�1�1�1�1�1�1�1����1�1�1�1��4s�'A�A�A�plugin_typec��|�d��}|�|�d���}tj�|��sdS|tjjkrt|��sdS|�d��}t||��p=t|��p.t|��pt|��ptj
j}|S)a
    Looking for object-cache.php or advanced-cache.php in wordpress folder
    If found - tries to find 'plugin-owner' of <-cache>.php by
    content comparison
    If cannot be found -> tries to read <-cache>.php headers looking for Plugin name: <Plugin>
    z
wp-contentz.phpN�plugins)rhr1r2r;rrrnrj�$get_wp_cache_plugin_by_scanning_dirs�get_wp_cache_plugin_by_headerrmrprr)rers�wp_content_dir�activated_cache�plugins_dir�plugin_names      r�get_wp_cache_pluginr|�s���$�,�,�\�:�:�N�$�-�-��.B�.B�.B�C�C�O�
�7�>�>�/�*�*���t��j�/�5�5�5�>W�Xf�>g�>g�5��t� �)�)�)�4�4�K�6���T�T�-�2�?�C�C�-�)�/�:�:�-�&�o�6�6�-��&�,�	��r�activated_pluginrzc�D�tj�|��sdS|���D]i}t	|�d|j������}|r;|d}|���|���kr	|jcS�jdS)zT
    Scanning plugins/* dir and looking for similar <object/advanced_cache>.php
    Nz**/r)r1r2r;rR�list�globrU�
read_bytes)r}rz�plugin�plugin_object_caches    rrvrv�s����7�>�>�+�&�&���t��%�%�'�'�#�#��"�6�;�;�/L�5E�5J�/L�/L�#M�#M�N�N���	#�"5�a�"8��"�-�-�/�/�3C�3N�3N�3P�3P�P�P��{�"�"�"���4rc��tj�|��sdSd}tjdtj��}t
|d���5}t|��D]P}|���}|�	|��}|�#|�
d��ccddd��S�Q	ddd��n#1swxYwYdS)zS
    Looking for Plugin name: <Some name> in <object/advanced.php>
    headers
    N�z-^.*plugin name:\s*(?P<plugin_name>[\w ]+)\s*$rXrYr{)r1r2r;r[r\�
IGNORECASEr]�ranger^�search�group)r}�max_top_lines_countrarbr,r!r_s       rrwrws*��
�7�>�>�*�+�+���t���
�
�C�R�]�S�S�A�	
��x�	0�	0�	0�2�A��*�+�+�	2�	2�A��:�:�<�<�D��H�H�T�N�N�E�� ��{�{�=�1�1�1�1�2�2�2�2�2�2�2�2�!�	2�2�2�2�2�2�2�2�2�2�2�2����2�2�2�2��4s�AC�4C�C�	C�object_cachec�p�g}	t���|��}n#tj$rgcYSwxYwtj�|dd��}tj�|��sgS	t|d���5}|���}ddd��n#1swxYwYtj
|��}n#t$rgcYSwxYw|�di���di��}	|D]%}
|
|	vr||	|
vr|�
|
���&|S)z?
    Filter user`s wp paths with paths with enabled module
    z.clwposzclwpos_config.jsonrXrYN�docroots�public_html)r
�get_homedir�NoSuchUserExceptionr1r2r:r;r]rr�json�loads�	Exception�get�append)�user�
user_wp_pathsr��paths_with_enabled_module�home�configrb�conf�data�modules_data�wp_paths           r� get_wp_paths_with_enabled_moduler�s���!#����w�w�"�"�4�(�(�����$�����	�	�	������W�\�\�$�	�+?�
@�
@�F�
�7�>�>�&�!�!���	��
�&��
*�
*�
*�	�a��6�6�8�8�D�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��z�$�����������	�	�	������8�8�J��+�+�/�/�
�r�B�B�L� �6�6���l�"�"�v��g�1F�'F�'F�%�,�,�W�5�5�5��$�$sB�!&�:�:�C�B2�&C�2B6�6C�9B6�:C�C!� C!c	��g}tj�d��s|�d��tj�d��s|�d��tj�d��s|�d��|r>gd�|z}t	j|dd�	��}t
jd
|j|j	��tj�d��s9t	jddgdd�	��}t
jd
|j|j	��t	jgd�dd�	��}t
jd|j|j	��td��}|rQt	jddd|�dd��gdd�	��}t
jd|j|j	��dSdS)N�/usr/bin/cloudlinux-awp-adminz
accelerate-wpz /usr/sbin/cloudlinux-ssa-managerzalt-php-ssaz/usr/sbin/cloudlinux-xray-agentzalt-php-xray)�yum�installz-yT)�capture_output�textz:Installing AccelerateWP packages captured out: %s, err: %sz/usr/share/clos_ssa/ssa_enabledz
enable-ssaz(Activation SSA captured out: %s, err: %s)z /usr/sbin/cloudlinux-autotracing�enablez--allz0Activation autotracing captured out: %s, err: %s�	system_idz!/usr/sbin/cloudlinux-xray-managerzenable-user-agentz--system_idzID-r%z1Activation xray manager captured out: %s, err: %s)r1r2r;r��
subprocess�run�logging�debug�stdout�stderrr�replace)�packages�install_command�procr�s    r�install_accelerate_wpr�0s����H�
�7�>�>�9�:�:�)�����(�(�(�
�7�>�>�<�=�=�'����
�&�&�&�
�7�>�>�;�<�<�(�����'�'�'��n�2�2�2�X�=���~�o�d��N�N�N���
�R�TX�T_�ae�al�m�m�m�
�7�>�>�;�<�<�\��~�A�<�P�-1��>�>�>���
�@�$�+�t�{�[�[�[��>�Q�Q�Q�bf�mq�r�r�r�D��M�D�d�k�SW�S^�_�_�_�&�{�3�3�I��e��~�B�DW�Yf�(�0�0���;�;�=�-1�#'�)�)�)��	�
�I�4�;�X\�Xc�d�d�d�d�d�e�erc���t��tj�d��rdSt	jgd�ddd���}t
jd|j|j	��dS)zh
    1. Installs needed packages
    2. Allows AccelerateWP Free for all
    3. Enables autotracing
    z8/var/clwpos/admin/allowed_for_all_site_optimization.flagN)r��	set-suite�--allowed-for-all�--suites�
accelerate_wpT��checkr�r�z6Activation AccelerateWP Free captured out: %s, err: %s�
r�r1r2r;r�r�r�r�r�r��r�s r�configure_accelerate_wpr�Ns������	�w�~�~�P�Q�Q�����>�%�%�%�
!%�)-�#�%�%�%�D��M�J�D�K�Y]�Yd�e�e�e�e�erc���t��tj�d��rdSt	jgd�ddd���}t
jd|j|j	��dS)Nz3/var/clwpos/admin/allowed_for_all_object_cache.flag)r�r��--visible-for-allr��accelerate_wp_premiumTr�z9Activation AccelerateWP Premium captured out: %s, err: %sr�r�s r�configure_accelerate_wp_premiumr�cs�������	�w�~�~�K�L�L�����>�-�-�-�59��TX�	Z�Z�Z�D�
�M�M�t�{�\`�\g�h�h�h�h�hrc�L�t��tj�d��rdSt	jgd�ddd���}t
jd|j|j	��t	jgd�ddd���}t
jd|j|j	��dS)Nz*/var/clwpos/admin/allowed_for_all_cdn.flag)r�r�r�r��accelerate_wp_cdnTr�z5Activation AccelerateWP CDN captured out: %s, err: %s)r�r�r�r��accelerate_wp_cdn_proz9Activation AccelerateWP CDN PRO captured out: %s, err: %sr�r�s r�configure_accelerate_wp_cdnr�qs�������	�w�~�~�B�C�C�����>�0�0�0�8<�D�W[�	]�]�]�D�
�M�I�4�;�X\�Xc�d�d�d��>�4�4�4�<@�PT�[_�	a�a�a�D�
�M�M�t�{�\`�\g�h�h�h�h�hrc�&�|sdStjddgddd���j}tj|��}||�d��krdStjddd|dd	gddd���}t
jd
|j|j��dS)Nr�zget-optionsTr��upgrade_urlzset-optionsz
--upgrade-urlz--suiter�zBSetting AccelerateWP Premium upgrade url captured out: %s, err: %s)	r�r�r�r�r�r�r�r�r�)r��options_json�optionsr�s    r�configure_upgrade_urlr��s��������>�#B�M�"R�#'�,0�"&�(�(�(�)/���j��&�&�G��g�k�k�-�0�0�0�0����>�:�(�*�&�$�2�4�!%�)-�#�%�%�%�D��M�V��+�t�{�,�,�,�,�,rr0)r�)/�
__future__rrrr�r[r1r�r��pathlibr�typingrrr	r
r�enumr�clcommon.clpwdr
�clcommon.utilsrrrrT�boolr)r6rCrHrLrNrVrdrjrprmr|rvrwr�r�r�r�r�r�rrr�<module>r�s���&�%�%�%�%�%�&�&�&�&�&�&�����������	�	�	�	�	�	�	�	���������������9�9�9�9�9�9�9�9�9�9�9�9�9�9������� � � � � � �1�1�1�1�1�1�&�&�&�&�&��&�&�&�#�#�#�#�#��#�#�#����4��E�#�t�)�<L�����@)��)��)�)�)�)�
1�5��d��#3�1��1�1�1�1�4'�c�'�d�'�'�'�'�
O��s�D�y�!1�O�d�O�O�O�O���s�D�y�)��d�����(��C��8�D��I�+>��(�SV�-�����6���$;�d�;�;�;�;�	�	�	�������3�����.�4��d��W_�`c�Wd������D��X�c�]�����(%�%�%�%�8e�e�e�<f�f�f�*i�i�i�i�i�i�,,�,�,�,�,r