HEX
Server: Apache
System: Linux insrv.serversdaddy.com 5.14.0-362.24.2.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Mar 30 14:11:54 EDT 2024 x86_64
User: jsaha (1066)
PHP: 8.3.6
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/clcommon/__pycache__/clwpos_lib.cpython-37.opt-1.pyc
B

!��¨��@s�ddlmZddlmZddlmZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
mZmZmZddlmZddlmZdd	lmZGd
d�de�ZGdd
�d
e�Zeeeeefd�dd�Zeed�dd�Zeee
fed�dd�Zeed�dd�Zeee
fed�dd�Zeee
fed�dd�Z d@eeeee
ed�dd �Z!d!d"�Z"e
d#�d$d%�Z#d&d'�Z$d(d)�Z%e
ed*�d+d,�Z&e
e
eed-�d.d/�Z'e
eed0�d1d2�Z(dAd4d5�Z)d6d7�Z*d8d9�Z+d:d;�Z,d<d=�Z-d>d?�Z.dS)B�)�print_function)�absolute_import)�divisionN)�Path)�Union�Iterable�Optional�Tuple�List)�Enum)�ClPwd)�get_rhn_systemid_valuec@seZdZdZdZdZdS)�
PluginTypez2
    Plugin types that are currently detected
    zobject-cachezadvanced-cacheN)�__name__�
__module__�__qualname__�__doc__ZOBJECT_CACHE�ADVANCED_CACHE�rr��/builddir/build/BUILDROOT/alt-python27-cllib-3.4.1-1.el9.cloudlinux.x86_64/opt/alt/python37/lib/python3.7/site-packages/clcommon/clwpos_lib.pyrsrc@seZdZdZdZdZdZdS)�	WpPluginszj
    Static WP plugin names, that are not detected
    dynamically from drop-in files, dir names, etc
    ZUnknownz	WP RocketZAccelerateWPN)rrrr�UNKNOWN�	WP_ROCKET�
ACCELERATE_WPrrrrr sr)�line�is_multiline_comment�returncCs�|rVd|krdS|�d�}t|d|�d�\}}t||dd�d�\}}|||fSd|krx|�d�}|d|�dfSd|kr�|�d�}|d|�dfSd	|kr�|�d	�}t|d|�d�\}}t||dd�d�\}}|||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)rr�posZpart1�_Zpart2rrrr!*s&



r!)�filercCstj�|�}tj�|�S)N)�os�path�realpath�isfile)r$Z
realpath_filerrr�
_is_real_fileJsr))�abs_pathrcCs�y*tj�|d�}tj�|�r(t|�r(dSWntk
r>YnXtj�|tj�}tj�|d�}tj�|d�}tj�|�o~t|�}tj�|�o�|o�t|�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.
    z
wp-config.phpTzwp-settings.php)r%r&�join�existsr)�OSError�pardir)r*Z
wp_config_phpZabs_path_level_upZwp_config_php_level_upZwp_settings_phpZwp_settings_php_existsrrr�_check_wp_config_phpOs	r/)�dirrcCstj�|�}tj�|�S)N)r%r&r'�isdir)r0Zrealpath_dirrrr�_is_real_dirisr2cCs$tj�|d�}dt�|�ko"t|�S)z.
    Check wp-includes exists and is dir.
    zwp-includes)r%r&r+�listdirr2)r*Zwp_includesrrr�_check_wp_includesnsr4cCsTytj�|�sdSWntk
r(dSXyt|�o:t|�Stk
rNYnXdS)z�
    Checks whether passed directory is a wordpress directory
    by checking presence of wp-includes folder and wp-config.php file.
    F)r%r&r,r-r/r4)r*rrr�
is_wp_pathvsr5)�doc_root�excludesrccsdtj�|�sdSt|�rdVx@t|���D]0}|��s:q,|rLt|�|krLq,t|�r,|jVq,WdS)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)	r%r&r,r5r�iterdir�is_dir�str�name)r6r7r&rrr�
find_wp_paths�s
r<c	Csht�d|�d|�d��}t|dd��:}d}x.|��}|s:Pt||�\}}|�|�r,dSq,WWdQRXdS)	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)�varr&�r�frrZcleaned_linerrr�_is_php_define_var_found�s
rG)�wordpress_pathcCs$|�d�}tj�|�sdStd|�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/
    z
wp-config.phpFZWP_CACHE)�joinpathr%r&r,rG)rHZ	wp_configrrr�is_advanced_cache_enabled�s
rJcCs"t|�dkrtd|�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
    NZWP_ROCKET_ADVANCED_CACHE)�accelerate_wp_pluginrGrr�value)�drop_in_pathrrr�wp_rocket_plugin�s
rNc	Cs0t|dd��}d|��kr"tjjSWdQRXdS)zB
    Checking if the plugin folder name exists in the drop-in
    r=)r>z/clsopN)rA�readrrrL)rMrFrrrrK�srK)rH�plugin_typecCsz|�d�}|�|�d��}tj�|�s*dS|tjjkrBt|�sBdS|�d�}t||�ptt	|�ptt
|�ptt|�pttj
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.phpNZplugins)rIr%r&r,rrrLrJ�$get_wp_cache_plugin_by_scanning_dirs�get_wp_cache_plugin_by_headerrKrNrr)rHrPZwp_content_dirZactivated_cache�plugins_dir�plugin_namerrr�get_wp_cache_plugin�s


rU)�activated_pluginrSrcCs^tj�|�sdSxH|��D]<}t|�d|j����}|r|d}|��|��kr|jSqWdS)zT
    Scanning plugins/* dir and looking for similar <object/advanced_cache>.php
    Nz**/r)r%r&r,r8�listZglobr;Z
read_bytes)rVrS�pluginZplugin_object_cacherrrrQ�s
rQ)rVrc	Csttj�|�sdSd}t�dtj�}t|dd��<}x4t|�D](}|��}|�	|�}|dk	r:|�
d�Sq:WWdQRXdS)zS
    Looking for Plugin name: <Some name> in <object/advanced.php>
    headers
    N�z-^.*plugin name:\s*(?P<plugin_name>[\w ]+)\s*$r=)r>rT)r%r&r,r?r@�
IGNORECASErA�rangerB�search�group)rVZmax_top_lines_countrErFr#rrCrrrrRs
rR�object_cachec	Cs�g}yt��|�}Wntjk
r*gSXtj�|dd�}tj�|�sLgSy.t|dd��}|��}WdQRXt	�
|�}Wntk
r�gSX|�di��di�}	x*|D]"}
|
|	kr�||	|
kr�|�
|
�q�W|S)z?
    Filter user`s wp paths with paths with enabled module
    z.clwposzclwpos_config.jsonr=)r>NZdocrootsZpublic_html)rZget_homedirZNoSuchUserExceptionr%r&r+r,rArO�json�loads�	Exception�get�append)�userZ
user_wp_pathsrXZpaths_with_enabled_module�homeZconfigrFZconf�dataZmodules_dataZwp_pathrrr� get_wp_paths_with_enabled_modules&
rgcCsg}tj�d�s|�d�tj�d�s0|�d�tj�d�sF|�d�|rzddd	g|}tj|d
d
d�}t�d|j|j	�tj�d
�s�tjddgd
d
d�}t�d|j|j	�tjdddgd
d
d�}t�d|j|j	�t
d�}|�rtjddd|�dd�gd
d
d�}t�d|j|j	�dS)Nz/usr/bin/cloudlinux-awp-adminz
accelerate-wpz /usr/sbin/cloudlinux-ssa-managerzalt-php-ssaz/usr/sbin/cloudlinux-xray-agentzalt-php-xrayZyumZinstallz-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: %sz /usr/sbin/cloudlinux-autotracingZenablez--allz0Activation autotracing captured out: %s, err: %s�	system_idz!/usr/sbin/cloudlinux-xray-managerzenable-user-agentz--system_idzID-rz1Activation xray manager captured out: %s, err: %s)r%r&r,rc�
subprocess�run�logging�debug�stdout�stderrr
�replace)ZpackagesZinstall_command�procrjrrr�install_accelerate_wp0s0





rscCsHt�tj�d�rdStjdddddgdddd	�}t�d
|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.flagNz/usr/bin/cloudlinux-awp-adminz	set-suitez--allowed-for-allz--suitesZ
accelerate_wpT)�checkrhriz6Activation AccelerateWP Free captured out: %s, err: %s)
rsr%r&r,rkrlrmrnrorp)rrrrr�configure_accelerate_wpNsrucCsHt�tj�d�rdStjdddddgdddd�}t�d	|j|j	�dS)
Nz3/var/clwpos/admin/allowed_for_all_object_cache.flagz/usr/bin/cloudlinux-awp-adminz	set-suitez--visible-for-allz--suites�accelerate_wp_premiumT)rtrhriz9Activation AccelerateWP Premium captured out: %s, err: %s)
rsr%r&r,rkrlrmrnrorp)rrrrr�configure_accelerate_wp_premiumcsrwcCsvt�tj�d�rdStjdddddgdddd�}t�d	|j|j	�tjddd
ddgdddd�}t�d|j|j	�dS)
Nz*/var/clwpos/admin/allowed_for_all_cdn.flagz/usr/bin/cloudlinux-awp-adminz	set-suitez--allowed-for-allz--suitesZaccelerate_wp_cdnT)rtrhriz5Activation AccelerateWP CDN captured out: %s, err: %sz--visible-for-allZaccelerate_wp_cdn_proz9Activation AccelerateWP CDN PRO captured out: %s, err: %s)
rsr%r&r,rkrlrmrnrorp)rrrrr�configure_accelerate_wp_cdnqsrxcCsp|sdStjddgdddd�j}t�|�}||�d�kr<dStjddd|dd	gdddd�}t�d
|j|j�dS)Nz/usr/bin/cloudlinux-awp-adminzget-optionsT)rtrhri�upgrade_urlzset-optionsz
--upgrade-urlz--suitervzBSetting AccelerateWP Premium upgrade url captured out: %s, err: %s)	rkrlror_r`rbrmrnrp)ryZoptions_jsonZoptionsrrrrr�configure_upgrade_url�s(


rz)N)r^)/Z
__future__rrrr_r?r%rkrmZpathlibr�typingrrrr	r
�enumrZclcommon.clpwdrZclcommon.utilsr
rrr:�boolr!r)r/r2r4r5r<rGrJrNrKrUrQrRrgrsrurwrxrzrrrr�<module>sD