%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/opt/alt/python37/lib/python3.7/site-packages/__pycache__/
Upload File :
Create Path :
Current File : //proc/self/root/opt/alt/python37/lib/python3.7/site-packages/__pycache__/cpanel.cpython-37.pyc

B

�4Lbkh�
@sxddlmZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddl
mZmZmZmZmZddlmZddlmZdd	lmZmZdd
lmZddlmZddlmZm Z m!Z!m"Z"m#Z#dd
l$m%Z%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z-ddl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;e*e<�Z=dZ>e?e?d�dd�Z@eAd�dd�ZBeAeAd�dd�ZCe?e?eAd�dd�ZDeAeAd�dd �ZEe?ed!�d"d#�ZFd$d%�ZGd&d'�ZHd(d)�ZIe?e?d*�d+d,�ZJd-d.�ZKd/d0�ZLd1d2�ZMe
�e6eAd3�d4d5��ZNeAeAd�d6d7�ZOeAeAd�d8d9�ZPeAd�d:d;�ZQe?e6d<�d=d>�ZRe6e6d3�d?d@�ZSee6ee6dA�dBdC�ZTe
ddD�ee6d�dEdF��ZUe
ddD�eVd�dGdH��ZWe
ddD�eVd�dIdJ��ZXd�e?eee?e?fdK�dLdM�ZYe?eZdN�dOdP�Z[e?e?ee?dQ�dRdS�Z\e?e?dT�dUdV�Z]e?ee6d<�dWdX�Z^e?e6d<�dYdZ�Z_eGd[d\�d\��Z`e?e?e?ee?e`fd]�d^d_�ZaGd`da�dae?�ZbGdbdc�dce?�Zceebecfe?e?ee`dd�dedf�Zdeebecfe?e?eeZee?ee?eAfffdd�dgdh�Zed�efdi�djdk�Zge?e?dl�dmdn�Zhe?do�dpdq�Zie?do�drds�Zje?e?dl�dtdu�Zke?do�dvdw�Zle?do�dxdy�Zme?e?ee`dz�d{d|�Zne?ee`d<�d}d~�Zoe?ee`d<�dd��ZpdS)��)�absolute_importN)�	dataclass)�	lru_cache)�Path)�Optional�Dict�Tuple�Union�List)�
parse_version)�userdomains)�
find_wp_paths�get_wp_cache_plugin)�is_cl_solo_edition)�write_file_via_tempfile)�WP_CLI_EXTENSIONS�RedisRequiredConstants�
EA_PHP_PREFIX�	CAGEFSCTL�CLSOP_ZIP_PATH)�	WposError�PhpBrokenException)�
WposDaemon)�
setup_logging)�gettext)
�WposUser�is_run_under_user�check_domain�home_dir�clear_redis_cache_config�create_redis_cache_config�daemon_communicate�PHP�wp_cli_compatibility_check�run_in_cagefs_if_needed�create_pid_file�	user_name�user_uidz/opt/cpanel)�vhost�returncCstdd|d��}|dS)NZphp_get_domain_handlerr()�typer(Zphp_handler)�uapi)r(�result�r-�7/opt/alt/python37/lib/python3.7/site-packages/cpanel.py�_get_php_handler7sr/)r)cCs@t�t���j}i}x&t|�D]\}}|�|g��|�qW|S)N)�pwd�getpwuid�os�geteuidZpw_namer�
setdefault�append)�userr,Zdomain�doc_rootr-r-r.�_get_doc_roots_info<s
r8)�	user_infor)cCsDi}x:|��D].\}}t|�}|tt||d��d�}|||<qW|S)N)�excludes)�domains�wp_paths)�items�listr
)r9r<r7r;r:�itemr-r-r.�_add_wp_path_infoEsr@)r7�wp_pathr)cCsJt||�}t|�d��d}tjddd|gdd�}|j����}||d�S)	z0Convert WP path to {"path": str, "version": str}zwp-includes/version.phprz	/bin/grepz-Poz(?<=wp_version = ')[^']+T)�capture_output)�path�version)rr>�glob�
subprocess�run�stdout�strip�decode)r7rAZabsolute_wp_pathZversion_filer,Z
wp_versionr-r-r.�_wp_infoRs
rKcs:x4|��D](\�}|�d�}�fdd�|D�|d<q
W|S)Nr<csg|]}t�|��qSr-)rK)�.0rA)r7r-r.�
<listcomp>asz _add_wp_info.<locals>.<listcomp>�wps)r=�pop)r9�
doc_root_infor<r-)r7r.�_add_wp_info^s
rQ)�	attributer)c
Cs�ddlm}|t��}tj�|d�}y"t|��}t�|�|SQRXWn6t	t
tjfk
r|}zt�
d|�gSd}~XYnXdS)z7
    Return attribute's value from info.json file.
    r)�get_admin_config_directoryz	info.jsonNz,Error during reading of "info.json" file: %s)�clwpos.optimization_modulesrSr'r2rC�join�open�json�load�OSError�KeyError�JSONDecodeError�_logger�	exception)rRrSZadmin_config_dirZ	info_json�f�er-r-r.�_get_data_from_info_jsones

r`cCs0ytdtji�dStk
r*td�SXdS)a�
    @return: [
        {
            "account": "rm3",
            "account_owner": "root",
            "documentroot": "/home/example/public_html",
            "homedir": "/home/rm3",
            "is_suspended": 0,
            "main_domain": 1,
            "php_fpm": 1,
            "php_fpm_pool_parms": {
                "pm_max_children": 5,
                "pm_max_requests": 20,
                "pm_process_idle_timeout": 10
            },
            "phpversion_source": [
                {
                    "domain": "example.com",
                    "system_default": 1
                }
            ],
            "version": "ea-php72",
            "vhost": "otherchars.rm3.tld"
        }
    ]
    �command�dataZvhost_versionsN)r!rZ%DAEMON_PHP_GET_VHOST_VERSIONS_COMMANDrr`r-r-r-r.�_php_get_vhost_versionsvsrccCs0ytdtji�dStk
r*td�SXdS)z-
    @return: [
        "ea-php74"
    ]
    rarbZinstalled_versionsN)r!rZ)DAEMON_PHP_GET_INSTALLED_VERSIONS_COMMANDrr`r-r-r-r.�_php_get_installed_versions�srdcCs,t�}x |D]}tt|d��|d<qW|S)a
    Returns php info, example:
    [{'vhost': 'sub.wposuser.com', 'account': 'stackoverflow',
    'phpversion_source': {'domain': 'sub.wposuser.com'},
    'version': 'ea-php80', 'account_owner': 'root', 'php_fpm': 1,
    'php_fpm_pool_parms': {'pm_process_idle_timeout': 10,
    'pm_max_requests': 20, 'pm_max_children': 5},
    'main_domain': 0, 'documentroot': '/home/stackoverflow/public_html',
    'homedir': '/home/stackoverflow'},
    ...................................................................]
    rD)rc�_normalized_php_versionr")r,�elemr-r-r.�php_info�s
rg)�ini_name�php_versioncCstt|�����d|���S)z,
    Builds path to <ini_name>.ini file
    zroot/etc/php.d/)rr"�dir�joinpath)rhrir-r-r.�ea_php_ini_file_path�srlcCsLtt�}td�}g}x2t�|�D]$}|�d�r t|�|kr |�|�q W|S)z;
    Looks through /opt/cpanel and gets installed phps
    zea-php74zea-php)r�BASE_CPANEL_EA_PHP_DIRrr2�listdir�
startswithr5)Zbase_dirZminimal_supportedZ	supportedr?r-r-r.�get_supported_ea_php�srpc	Csd}ttj�d��}dd�t�D�}dd�|��D�}|s>dStt���x�|D]�}|�|�}|�d�s�|�d	�}tj	d
dd|gd
d
d�}|j
dkr�d|jkr�t�
d||j�d|j���qNt|�d
}qN|�d�sNt|�d
}qNW|�r|�rtj	tddgtjtjd�WdQRXdS)zX
    Sets up redis if needed:
     - installing package
     - enables in .ini file
    FZCL_WPOS_WAIT_CHILD_PROCESScSsi|]}tt|��|�qSr-)�_redis_extension_infor")rL�phpr-r-r.�
<dictcomp>�sz4configure_redis_extension_for_ea.<locals>.<dictcomp>cSs(g|] \}}|�d�r |�d�s|�qS)�
is_present�	is_loaded)�get)rLrr�
redis_datar-r-r.rM�sz4configure_redis_extension_for_ea.<locals>.<listcomp>Nrtz
-php-redisZyumz-y�installT)rB�textrz
Nothing to doz/Failed to install package %s, due to reason: %s�
ruz--wait-lockz--force-update)rH�stderr)�boolr2�environrvrpr=r%rrFrG�
returncoderHr\�errorr{�enable_redis_extension_for_earZDEVNULL)Zneed_cagefs_updateZcl_jenkins_testsZphp_versions_redis_dataZphp_versions_to_enable_redisrrrwZ
redis_packager,r-r-r.� configure_redis_extension_for_ea�s8






r�c	Cs�td|�}d}tj�|�s6t�dt|�|�d��dSt|��}|��}WdQRXt	�
d|���}t	�
d|���}d|�d	�}d
}g}	xB|D]:}
|�|
�r�dS|s�|�|
�r�|	�|�d}q�|	�|
�q�W|s�|	�|�t
d�|	�|d
�dS)z<
    Enables (if needed) redis extension in .ini config
    z50-redis.inizredis.sozWRedis extension config: %s is not found, ensure corresponding rpm package installed: %sz
-php-redisNz^\s*extension\s*=\s*z^\s*;\s*extension\s*=\s*zextension = rzFT�i�)rlr2rC�existsr\r�strrV�	readlines�re�compile�matchr5rrU)rirC�keywordr^Zextension_dataZuncommented_patternZcommented_patternZenabled_lineZwas_enabled�lines�liner-r-r.r��s.





r�)rDr)cCsdtt|���d���}|��}t��dkr2tj}nt	}|rV||�d�ddid�j
dknd}||d�S)	Nz**/redis.sorz -m | /bin/grep redisTz	/bin/bash)�shell�
executable�envF)rtru)r|r>rjrE�binr2r3rFrGr$r~)rDrt�php_bin_path�	exec_funcrur-r-r.rqs$rqcCsDt�}x8|D]0}|dt|d�t|d�d�||dd<qW|S)z.
    Updates user_info dict with php data
    rDZphp_fpmr()rDZfpmZhandler�documentrootrr)rgr|r/)r9r,r?r-r-r.�_add_php&s

 r�cCsLxF|��D]:\}}x0|dD]$}tt|��|d�d�}||d<qWq
W|S)z�
    Search for 'object-cache.php' files in 'wp-content/plugins' directory
    in order to find what plugin is being used for object caching.
    rNrCzobject-cacheZobject_cache)r=rrrk)r9r7rPZwp�pluginr-r-r.�_add_object_cache_info5s
r�cCs&t�}xtttfD]}||�}qW|S)a
    Collect info about user.
    @return {
        '/home/user/public_html': {
            'domains': ['domain.com'],
            'wps': [
                {
                    'path': 'wp_path_1',
                    'version': '5.7.2',
                    'object_cache': 'redis-cache'
                }
            ],
            'php': {
                'version': 'ea-php74',
                'handler': 'cgi',
                'redis_extension': False,
                'fpm': True
            }
        }
    }
    )r8r@rQr�)r9�funcr-r-r.�
get_user_infoBsr�)�abs_wp_pathr)cCsTt�}g}x0|D](}|�|d�r|�|d|df�qW|jdd�|ddS)zReturn PHP version.r�rDT)�reverser�)rgror5�sort)r�r,r=r?r-r-r.�_get_php_version`s
r�cCshtdd�sd|���d�}t|ddid�}|jrH|jsHtt|���|j��t|j���d��	dd��S|S)z^
    PHP selector can replace path with symlink. It's a reason why we need normalization.
    T)Zskip_jwt_checkzR -i  | /bin/grep 'Loaded Configuration File' | /bin/grep -oE "(alt|ea).*php[^/]*/"z	/bin/bash)r�r�r��/�-)
rr�r$r{rHrr�r"rI�replace)rDrar,r-r-r.rels
re)�php_versionsr)cCs8g}x.|D]&}t|�}|ds
|dr
|�|�q
W|S)zr
    Filter list of given php versions to find out
    for which redis extension is presented but not loaded.
    rurt)rqr5)r�Z"php_versions_with_not_loaded_redisrDZphp_redis_infor-r-r.�)filter_php_versions_with_not_loaded_redis~s
r�)�maxsizecCst�}dd�|D�S)zY
    List all installed php version on the system
    :return: installed php version
    cSsg|]}t|��qSr-)r")rLrDr-r-r.rM�sz5get_cached_php_installed_versions.<locals>.<listcomp>)rd)r,r-r-r.�!get_cached_php_installed_versions�sr�cCst�}dd�|D�S)z�
    List all installed php version on the system which has redis-extension enabled
    :return: installed php versions which has redis-extension
    cSsh|]}t|�dr|�qS)ru)rq)rLrDr-r-r.�	<setcomp>�sz<get_cached_php_versions_with_redis_loaded.<locals>.<setcomp>)r�)�versionsr-r-r.�)get_cached_php_versions_with_redis_loaded�sr�cCst�}dd�|D�S)z�
    List all installed php version on the system which has redis-extension installed
    :return: installed php versions which has redis-extension installed
    cSsh|]}t|�dr|�qS)rt)rq)rLrDr-r-r.r��sz=get_cached_php_versions_with_redis_present.<locals>.<setcomp>)r�)r�r-r-r.�*get_cached_php_versions_with_redis_present�sr�)�function�input_parameterscCsF|rdd�|��D�ng}tddd|f|�id�}t�|j�ddS)	NcSsg|]\}}|�d|���qS)�=r-)rL�key�valuer-r-r.rM�szuapi.<locals>.<listcomp>z
/usr/bin/uapiz
--output=jsonZLangPHP)r�r,rb)r=r$rW�loadsrH)r�r�Zinput_parameters_as_listr,r-r-r.r+�sr+)rCr)cCs:d}d|}t|d|�}t|t�r2t|j|jd��||kS)NZcl_multisite_detectedz$if ( is_multisite() ) { echo "%s"; }�eval)�message�context)�	wordpress�
isinstance�WordpressErrorrr�r�)rCZmarkerrar,r-r-r.�is_multisite�s
r�)rA�constantr)cCs6dd|i}t|d|�}t|t�r2t�d|�dS|S)zS
    Get defined constant value or None in case of error or undefined constant
    z-if (defined('%(const)s')) { echo %(const)s; }�constr�z Error during get WP constant: %sN)r�r�r�r\r)rAr�rar,r-r-r.�wp_get_constant�s
r�)�docroot�wordpress_pathcCs�ttj�||�tjj�}|s>|tjjkr>tdtjj|d�d��ttj�||�tj	j�}|sntddtj	jid��tj�
|�s�tdd|id��dS)	zE
    Check required constants for redis connection establishment
    zVWordPress constant "%(constant)s" is not defined or defined with wrong value %(value)s)r�r�)r�z0WordPress constant "%(constant)s" is not definedr�z4Redis socket %(socket)s does not exist in the system�socketN)r�r2rCrUrZWP_REDIS_SCHEME�namer�rZ
WP_REDIS_PATHr�)r�r�Zredis_schemar�r-r-r.�#diagnose_redis_connection_constants�sr�c
Cs�t�std��tj�d�}tt��jj|d�}tj	�
|�s>dSy"t|��}t�
|�}WdQRXWn6ttjjfk
r�}zt�d|�dSd}~XYnXg}x0|D](}|�|d�r�|�|d|df�q�W|s�dStt|dd	�d
d�S)z@
    Get domain's php version from a previously saved file.
    z*Internal Error. Contact CloudLinux supportZCLWPOS_PHP_FILE_ID)Zfile_idNz,Error during reading of ".php_info" file: %sr�rDT)r�rr�)rrr2r}rvrr&rg�formatrCr�rVrWrXrY�decoderr[r\r]ror5r"�sorted)r�Zphp_file_idZ
php_info_filer^Z	_php_infor_r�Z
vhost_infor-r-r.�_get_saved_php_version�s&

r�cCs2ttj�d��}|r&t|�p"t|�}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.
    ZCLWPOS_USE_SAVED_PHP_VERSION)r|r2r}rvr�r�)r�Zuse_saved_php_versionrir-r-r.�get_php_version�s
r�c@seZdZUeed<eed<dS)r�r�r�N)�__name__�
__module__�__qualname__r��__annotations__�dictr-r-r-r.r�s
r�)rCra�
subcommandr)c

Gs�t|�}t|���}tj�|�sBt�d||�tt	d�d|id�St
|�d�|�||f|�}|ftd|�}yt
|did�}Wn\tjk
r�}	z<d	�d
d�|D��}t�d||	j|	j�tt	d
�d|id�Sd}	~	XYnX|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".rC)r�r�z	--path={}�/opt/clwpos/wp-cliT)Zcheckr�� cSsg|]}d|�qS)z"%s"r-)rL�tokenr-r-r.rM$szwordpress.<locals>.<listcomp>z7Error during command execution: 
%s
stdout=%s
stderr=%sz{Unexpected error happened during command execution: '%(command)s'.
Event is logged to file with stdout and stderr recorded.raN)r�)r�r�r�r2rCr�r\r]r��_r#r�rr$rFZCalledProcessErrorrUrHr{)
rCrar��argsrir�Zcommand_partZfull_command�outputrr-r-r.r�s*
r�c@seZdZdZdS)�DocRootPathz&This class represent path to doc_root.N)r�r�r��__doc__r-r-r-r.r�4sr�c@seZdZdZdS)�
DomainNamez!This class represent domain name.N)r�r�r�r�r-r-r-r.r�9sr�)�argrA�moduler)cCslt|t�rt|�d}n t|t�r0tt�|�}ntd��tt|��|��	��}d}t
||�}|rh|d}|S)a
    Deactivate and delete specified wordpress module.
    :param arg: user's docroot or domain
    :param wp_path: path to user's wordpress directory
    :param module: module on which to perform disable operations
    :return: error if error was happened else None
    ���zInvalid argument formatN)r�r�rr�rr�
ValueErrorr�rk�absolute�disable_module)r�rAr�r7r�Z
last_error�errorsr-r-r.� disable_without_config_affecting>s



r�c
Cs�t|t�rt|�\}}n t|t�r0tt�|�}ntd��|�d�}tt|��	|��
��}yt||�Wn8tk
r�}zdt
td�|j|jd�fSd}~XYnXyt||�WnBtk
r�}z$t||�dt
td�|j|jd�fSd}~XYnXdifS)	a
    Install and activate specified wordpress module.
    :param arg: user's docroot or domain
    :param wp_path: path to user's wordpress directory
    :param module: module on which to perform enable operations
    :return: tuple that consists of enabling status and details
    zInvalid argument formatr�FzhWordPress plugin installation failed. Try again and contact your system administrator if issue persists.)r�Zdetailsr�Nz�WordPress plugin activation failed. Changes were reverted and caching module is now disabled. Try again and contact your system administrator if issue persists.T)r�r�rr�rrr��lstripr�rkr��install_modulerr�r�r�r��
enable_moduler�)r�rAr��__r7r�r_r-r-r.�enable_without_config_affectingYs.




r�)�uidcCs ddi}|r||d<t|�dS)zQ
    Make redis reload via CLWPOS daemon
    :param uid: User uid (optional)
    ra�reloadr�N)r!)r�Zcmd_dictr-r-r.�reload_redis�sr�)r�r�cCs,ddlm}m}|t|ti}|||�dS)z2
    Enable specified WP optimization module.
    r)�OBJECT_CACHE_MODULE�SITE_OPTIMIZATION_MODULEN)rTr�r��enable_redis_object_cache�enable_site_optimization_plugin)r�r�r�r��module_func_mapr-r-r.r��sr�)r�cCsZt|ddd�}t|t�r(t|j|jd��t|dd�}t|t�rNt|j|jd��t|�dS)zk
    Enable redis-cache plugin for user.
    :param abs_wp_path: absolute path to wp site
    :return:
    r��activatezredis-cache)r�r�ZredisZenableN)r�r�r�rr�r�r )r��resr-r-r.r��s

r�cCs,t|ddd�}t|t�r(t|j|jd��dS)z|
    Enable cloudlinux-site-optimization plugin for user.
    :param abs_wp_path: absolute path to wp site
    :return:
    r�r��clsop)r�r�N)r�r�r�rr�r�)r�r�r-r-r.r��s
r�cCs,ddlm}m}|t|ti}|||�dS)z3
    Install specified WP optimization module.
    r)r�r�N)rTr�r��install_redis_cache� install_site_optimization_plugin)r�r�r�r�r�r-r-r.r��sr�cCs,t|ddd�}t|t�r(t|j|jd��dS)zl
    Install redis-cache plugin for user.
    :param abs_wp_path: absolute path to wp site
    :return:
    r�rxzredis-cache)r�r�N)r�r�r�rr�r�)r�r�r-r-r.r��s
r�cCs,t|ddt�}t|t�r(t|j|jd��dS)z}
    Install cloudlinux-site-optimization plugin for user.
    :param abs_wp_path: absolute path to wp site
    :return:
    r�rx)r�r�N)r�rr�r�rr�r�)r�r�r-r-r.r��s
r�)r�r�r)cCs(ddlm}m}|t|ti}|||�S)zA
    Deactivate and delete specified WP optimization module.
    r)r�r�)rTr�r��disable_object_cache� disable_site_optimization_plugin)r�r�r�r�r�r-r-r.r��sr�c
Cs�g}yt|�Wn�tk
rP}z"t�|�|�t|j|j��Wdd}~XYnLtk
r�}z.t�|�|�tt	d�t
t|�d�d��Wdd}~XYnXt|ddd�}t
|t�r�|�|�t|ddd�}t
|t�r�|�|�|S)	z�
    Delete cloudlinux info from wp-config.php,
    deactivate and delete redis-cache plugin for user.
    :param abs_wp_path: absolute path to wp site
    :return: list of errors that occured during command execution
    Nz9Unexpected error happened while clearing cache: %(error)s)r)r�r�r��
deactivatezredis-cache�delete)rrr\r]r5r�r�r��	Exceptionr�r�r�r�r�)r�r��errr_r�r-r-r.r��s&
$
&



r�cCsLg}t|ddd�}t|t�r&|�|�t|ddd�}t|t�rH|�|�|S)z�
    Deactivate and delete cloudlinux-site-optimization plugin for user.
    :param abs_wp_path: absolute path to wp site
    :return: list of errors that occured during command execution
    r�r�r�Z	uninstall)r�r�r�r5)r�r�r�r-r-r.r�s



r�)N)N)qZ
__future__rrWr2r0r�rFZdataclassesr�	functoolsrZpathlibr�typingrrrr	r
Z
pkg_resourcesrZclcommon.cpapirZclcommon.clwpos_libr
rZclcommon.lib.cleditionrZsecureiorZclwpos.constantsrrrrrZclwpos.cl_wpos_exceptionsrrZ
clwpos.daemonrZclwpos.logsetuprZclwposrr�Zclwpos.utilsrrrrrr r!r"r#r$r%r&r'r�r\rmr�r/r�r8r@rKrQr`rcrdrgrlrpr�r�rqr�r�r�r�rer�r��setr�r�r+r|r�r�r�r�r�r�r�r�r�r�r��intr�r�r�r�r�r�r�r�r�r�r-r-r-r.�<module>s�<	
!
* 

					,&,




Zerion Mini Shell 1.0