œ_#ÁÕ§TE NAŒ“KeÉ:”(åŽÖJÞùY’‚ñùž7; «]Û ý`8g“¯B© jd ÖÖ¸ðzœ¸¦4Ç3Kó^(ÍÖ¼ Õ€pvìwšõB4d f$Èü^0˜…åÌC$#2FŽÑ§±¦ÛZ/÷š&m£ñzÒÖ ’.Î]!Î;ƒ(Õ–¢d/—#Kª+tZyuÏB>NÛÖ†(¸ŒSà'³„Y˜´-_•¦¼´˜OlNK§¶ÒàŠˆTHµƒeTPå·fïM’…þuÏÍüp6دªE£åü‡ZØ'CKF#â«;‹eyO Qp„†l"ö1èíÙP ÏŒúl! BÝ2ñª•_VÁÉ÷3eu`–F¸ìI--ö<¿žë¯4õ캿¢)34Å{wMÉ2ÆÖFŸ¥` e9Ú¶¸P‡.”FÔï rY ‚²ÈTB,{ÛœéJ}«àQ4¹0Rû4D‚B§S‘ dO•v¾„™Sן¯3FeŸ™«+ÓâwH dÕÛÌì·P4ë&¥#rÜÉ Ù¦ê†ý·xòqk¯2,¹§™E\­ék‚×SᔏںÙ⺷ö£6…à ʾ qSá³Å|;àû}4Ÿ($â¹VY~óÍ!èÜÒŒËX½Ù1j‚VíÍŸš³+œ]«½g{_{/vµ½\¢¶vÉWKÿ:ñám½ ¥ S²x‘t ŽšÝÙÿÀÇ^ný PK   IW™k‚½÷ á  _rels/.relsUT dìd dìd dìd­’ÏNÃ0 ‡ï{ŠÈ÷ÕÝ@¡¥» ¤Ý*`%îÑ&QâÁöö‚J£ì°cœŸ¿|¶²ÙÆA½rL½wVE Šñ¶w­†çúay * 9Kƒw¬áÈ ¶ÕbóÄIîI]’Ê—4t"á1™ŽGJ…ìòMããH’±Å@æ…ZÆuYÞ`üÍ€jÂT;«!îì T} |Û7MoøÞ›ýÈNN<|v–í2ÄÜ¥ÏèšbË¢Ázó˜Ë )„"£O­Ï7ú{ZYÈ’yÞç#1'tuÉM?6o>Z´_å9›ëKÚ˜}?þ³žÏÌ·N>fµx PK    IWª½e  ¢ U  € word/document.xmlUT dìdPK    IWþË3” z  €J¢ word/settings.xmlUT dìdPK    IWC‡{š' ƒ  €¤ docProps/custom.xmlUT dìdPK    IW츱=Œ   €‡¥ [Content_Types].xmlUT dìdPK    IWV%ë±"   €U§ docProps/app.xmlUT dìdPK    IW€RŒ 3  €¶¨ docProps/core.xmlUT dìdPK    IWkòDn ô  €ª word/_rels/document.xml.relsUT dìdPK    IW ;$î   €Î« word/fontTable.xmlUT dìdPK    IW+åäz] ÷.  €ý¬ word/numbering.xmlUT dìdPK    IW¤2×r- ¿  €›° word/styles.xmlUT dìdPK    IWMFÒ ø  €´ word/header1.xmlUT dìdPK    IWF— T e  €· word/media/image1.jpegUT dìdPK    IW!Yéáå   €°Ë word/media/image2.pngUT dìdPK    IW°Àºë ú  €ÙÌ word/media/image3.pngUT dìdPK    IW$“†ª L  €Î word/footer1.xmlUT dìdPK    IWzaGôM   €ñÑ word/footer2.xmlUT dìdPK    IW–µ­âº P  €}Õ word/theme/theme1.xmlUT dìdPK    IW™k‚½÷ á €{Û _rels/.relsUT PK   ! bîh^   [Content_Types].xml ¢(   ¬”ËNÃ0E÷HüCä-Jܲ@5í‚Ç*Q>Àēƪc[žiiÿž‰ûB¡j7±ÏÜ{2ñÍh²nm¶‚ˆÆ»R ‹ÈÀU^7/ÅÇì%¿’rZYï @1__f› ˜q·ÃR4DáAJ¬h>€ãÚÇV߯¹ ªZ¨9ÈÛÁàNVÞ8Ê©ÓãÑÔji){^óã-I‹"{Üv^¥P!XS)bR¹rú—K¾s(¸3Õ`cÞ0†½ÝÎß»¾7M4²©ŠôªZƐk+¿|\|z¿(Ž‹ôPúº6h_-[ž@!‚ÒØ Pk‹´­2nÏ}Ä?£LËð Ýû%áÄßdºždN"m,à¥ÇžDO97*‚~§Èɸ8ÀOíc|n¦Ñ äEøÿöéºóÀBÉÀ!$}‡íàÈé;{ìÐå[ƒîñ–é2þ ÿÿ PK   ! µU0#ô L _rels/.rels ¢(   ¬’MOÃ0 †ïHü‡È÷ÕݐBKwAH»!T~€Iܵ£$Ý¿'TƒG½~üÊÛÝ<êÈ!öâ4¬‹;#¶w­†—úqu *&r–Fq¬áÄvÕõÕö™GJy(v½*«¸¨¡KÉß#FÓñD±Ï.W ¥†=™ZÆMYÞbø®ÕBSí­†°·7 ê“Ï›×–¦é ?ˆ9LìÒ™ÈsbgÙ®|Èl!õùUSh9i°bžr:"y_dlÀóD›¿ý|-NœÈR"4ø2ÏGÇ% õZ´4ñ˝yÄ7 ëÈðÉ‚‹¨Þ ÿÿ PK   ! Q48wÛ —  xl/workbook.xml¤UÙnâ0}iþ!cñ‡ *–¢AšVU×$dC¬&vÆv UÕŸë@XÊK§/¹p|Žï¹N÷b“¥Ö •Š ÞC¸î"‹òHÄŒ¯zèá~b·‘¥4á1I§=ôJºèÿüÑ] ù¼âÙ ®z(Ñ:GE ͈ª‹œrˆ,…̈†©\9*—”Ä*¡Tg©ã¹nàd„q´Eåg0ÄrÉ":Q‘Q®· ’¦D}•°\UhYô¸ŒÈç"·#‘å ±`)Ó¯%(²²(œ®¸d‘‚ì nZ w v¡ñª• t¶TÆ")”Xê:@;[Ògú±ë`|²›ó=ø’ïHúÂL÷¬dðEVÁ+8€a÷Ûh¬Uz%„Íû"ZsÏÍCýî’¥ôqk]‹äù5ÉL¦Rd¥Dé˘i÷P ¦bM/|dÉ",…¨çãFNoçiûéë>aêiçsó#ðÄ ÕTr¢éHp ÜIú®ÝJìQ"ÀÜÖ-ý[0I¡¦ÀZ Z…d¡nˆN¬B¦=4 g %PDF-1.4 %âãÏÓ 3 0 obj << /Linearized 1 /L 422775 ÿØÿà JFIF    ÿÛ C      ÿÛ C   ÿÀ  X" ÿÄ    ÿÄ H   !1A"Qaq2‘¡#±ÁBRÑ3Cbrá$S‚¢²ð4ñ%6DTc’ÂsÿÄ   ÿÄ =  !1AQ"aq‘Á2R¡±BÑð#3br’²4á$‚¢ÂñÿÚ   ? áHBßÝ`„! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! ! stream

___________________________ < root@rinduuu:~# /home/rinduuuuuuu?! > ___________________________

Command :

ikan Uploader :
Directory :  /opt/alt/python37/lib/python3.7/site-packages/__pycache__/
Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 
Current File : //opt/alt/python37/lib/python3.7/site-packages/__pycache__/cpanel.cpython-37.pyc
B

�tbc�s�
@s�ddlmZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddl
mZmZmZmZmZddlmZddlmZdd	lmZmZdd
lmZddlmZddlmZm Z m!Z!m"Z"m#Z#m$Z$dd
l%m&Z&m'Z'm(Z(ddl)m*Z*ddl+m,Z,m-Z-m.Z.ddl/m0Z1ddl2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@e,eA�ZBdZCeDeDd�dd�ZEeFd�dd�ZGeFeFd�dd�ZHeDeDeFd�dd�ZIeFeFd�dd �ZJeDed!�d"d#�ZKd$d%�ZLd&d'�ZMd(d)�ZNeDeDd*�d+d,�ZOd-d.�ZPd/d0�ZQd1d2�ZRe
�e:eFd3�d4d5��ZSeFeFd�d6d7�ZTeFeFd�d8d9�ZUeFd�d:d;�ZVeDe:d<�d=d>�ZWe:e:d3�d?d@�ZXee:ee:dA�dBdC�ZYe
ddD�ee:d�dEdF��ZZe
ddD�e[d�dGdH��Z\e
ddD�e[d�dIdJ��Z]d�eDeeeDeDfdK�dLdM�Z^eDe_dN�dOdP�Z`d�eDeDeeDdR�dSdT�ZaeDeDdU�dVdW�ZbeDee:d<�dXdY�ZceDe:d<�dZd[�ZdeGd\d]�d]��Zedd^�eDeDeDeeDeefd_�d`da�ZfGdbdc�dceD�ZgGddde�deeD�ZheegehfeDeDeeedf�dgdh�ZieegehfeDeDee_eeDeeDeFfffdf�didj�Zjd�ekdk�dldm�ZleDeDdn�dodp�ZmeDdq�drds�ZneDdq�dtdu�ZoeDdq�dvdw�ZpeDeDdn�dxdy�ZqeDdq�dzd{�ZreDdq�d|d}�ZseDeDeeed~�dd��ZteDeeed<�d�d��Zud�eDeDe_d��d�d��Zvd�eDeDe_d��d�d��ZweDeeed<�d�d��ZxdS)��)�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�WP_CLI_ENABLE_ALL_FUNCTIONS�RedisRequiredConstants�
EA_PHP_PREFIX�	CAGEFSCTL�CLSOP_ZIP_PATH)�	WposError�PhpBrokenException�WpCliCommandError)�
WposDaemon)�
setup_logging�ADMIN_LOGFILE_PATH�USER_LOGFILE_PATH)�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_uid�litespeed_is_runningz/opt/cpanel)�vhost�returncCstdd|d��}|dS)NZphp_get_domain_handlerr-)�typer-�php_handler)�uapi)r-�result�r3�7/opt/alt/python37/lib/python3.7/site-packages/cpanel.py�_get_php_handler>sr5)r.cCs@t�t���j}i}x&t|�D]\}}|�|g��|�qW|S)N)�pwd�getpwuid�os�geteuid�pw_namer�
setdefault�append)�userr2�domain�doc_rootr3r3r4�_get_doc_roots_infoCs
r@)�	user_infor.cCsDi}x:|��D].\}}t|�}|tt||d��d�}|||<qW|S)N)�excludes)�domains�wp_paths)�items�listr
)rArDr?rCrB�itemr3r3r4�_add_wp_path_infoLsrH)r?�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)rrF�glob�
subprocess�run�stdout�strip�decode)r?rIZabsolute_wp_pathZversion_filer2Z
wp_versionr3r3r4�_wp_infoYs
rScs:x4|��D](\�}|�d�}�fdd�|D�|d<q
W|S)NrDcsg|]}t�|��qSr3)rS)�.0rI)r?r3r4�
<listcomp>hsz _add_wp_info.<locals>.<listcomp>�wps)rE�pop)rA�
doc_root_inforDr3)r?r4�_add_wp_infoes
rY)�	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.feature_suitesr[r+r8rK�join�open�json�load�OSError�KeyError�JSONDecodeError�_logger�	exception)rZr[Zadmin_config_dirZ	info_json�f�er3r3r4�_get_data_from_info_jsonls

rhcCs0ytdtji�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_COMMANDrrhr3r3r3r4�_php_get_vhost_versions}srkcCs0ytdtji�dStk
r*td�SXdS)z-
    @return: [
        "ea-php74"
    ]
    rirjZinstalled_versionsN)r%rZ)DAEMON_PHP_GET_INSTALLED_VERSIONS_COMMANDrrhr3r3r3r4�_php_get_installed_versions�srlcCs,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'},
    ...................................................................]
    rL)rk�_normalized_php_versionr&)r2�elemr3r3r4�php_info�s
ro)�ini_name�php_versioncCstt|�����d|���S)z,
    Builds path to <ini_name>.ini file
    zroot/etc/php.d/)rr&�dir�joinpath)rprqr3r3r4�ea_php_ini_file_path�srtcCsLtt�}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_DIRrr8�listdir�
startswithr<)Zbase_dirZminimal_supportedZ	supportedrGr3r3r4�get_supported_ea_php�srxc	Cshd}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���qPt|�d
}qP|�d�sPt|�d
}qPW|�rZ|�rZtj�t��rZytj	tdgtjtjd
d�Wn"tjk
�r>t�d�YnXtj	tddgtjtjd�WdQRXdS)zX
    Sets up redis if needed:
     - installing package
     - enables in .ini file
    FZCL_WPOS_WAIT_CHILD_PROCESScSsi|]}tt|��|�qSr3)�_redis_extension_infor&)rT�phpr3r3r4�
<dictcomp>�sz4configure_redis_extension_for_ea.<locals>.<dictcomp>cSs(g|] \}}|�d�r |�d�s|�qS)�
is_present�	is_loaded)�get)rTrz�
redis_datar3r3r4rU�sz4configure_redis_extension_for_ea.<locals>.<listcomp>Nr|z
-php-redisZyumz-y�installT)rJ�textrz
Nothing to doz/Failed to install package %s, due to reason: %s�
r}z--check-cagefs-initialized)rP�stderr�checkz-CageFS in unintialized, skipping force-updatez--wait-lockz--force-update)rPr�)�boolr8�environr~rxrEr)rrNrO�
returncoderPrd�errorr��enable_redis_extension_for_earK�isfilerZDEVNULL�CalledProcessError�info)Zneed_cagefs_updateZwait_child_processZphp_versions_redis_dataZphp_versions_to_enable_redisrzrZ
redis_packager2r3r3r4� configure_redis_extension_for_ea�sF






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 = r�FT�i�)rtr8rK�existsrdr��strr^�	readlines�re�compile�matchr<rr])rqrK�keywordrfZextension_dataZuncommented_patternZcommented_patternZenabled_lineZwas_enabled�lines�liner3r3r4r�s.





r�)rLr.cCsdtt|���d���}|��}t��dkr2tj}nt	}|rV||�d�ddid�j
dknd}||d�S)	Nz**/redis.sorz -m | /bin/grep redisTz	/bin/bash)�shell�
executable�envF)r|r})r�rFrrrM�binr8r9rNrOr(r�)rLr|�php_bin_path�	exec_funcr}r3r3r4ry"s$rycCsDt�}x8|D]0}|dt|d�t|d�d�||dd<qW|S)z.
    Updates user_info dict with php data
    rLZphp_fpmr-)rLZfpm�handler�documentrootrz)ror�r5)rAr2rGr3r3r4�_add_php5s

 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.
    rVrKzobject-cache�object_cache)rErrrs)rAr?rXZwp�pluginr3r3r4�_add_object_cache_infoDs
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
            }
        }
    }
    )r@rHrYr�)rA�funcr3r3r4�
get_user_infoQsr�)�abs_wp_pathr.cCsTt�}g}x0|D](}|�|d�r|�|d|df�qW|jdd�|ddS)zReturn PHP version.r�rLT)�reverser�)rorwr<�sort)r�r2rErGr3r3r4�_get_php_versionos
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�rPrr�r&rQ�replace)rLrir2r3r3r4rm{s
rm)�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.
    r}r|)ryr<)r�Z"php_versions_with_not_loaded_redisrLZphp_redis_infor3r3r4�)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|��qSr3)r&)rTrLr3r3r4rU�sz5get_cached_php_installed_versions.<locals>.<listcomp>)rl)r2r3r3r4�!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)r})ry)rTrLr3r3r4�	<setcomp>�sz<get_cached_php_versions_with_redis_loaded.<locals>.<setcomp>)r�)�versionsr3r3r4�)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)r|)ry)rTrLr3r3r4r��sz=get_cached_php_versions_with_redis_present.<locals>.<setcomp>)r�)r�r3r3r4�*get_cached_php_versions_with_redis_present�sr�)�function�input_parameterscCsF|rdd�|��D�ng}tddd|f|�id�}t�|j�ddS)	NcSsg|]\}}|�d|���qS)�=r3)rT�key�valuer3r3r4rU�szuapi.<locals>.<listcomp>z
/usr/bin/uapiz
--output=jsonZLangPHP)r�r2rj)rEr(r_�loadsrP)r�r�Zinput_parameters_as_listr2r3r3r4r1�sr1)rKr.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�)rKZmarkerrir2r3r3r4�is_multisite�s
r�F)rI�constantr.cCsJdd|i}t|d|�}t|t�rF|r6t|j|jd��t�d|�dS|S)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; }�constr�)r�r�z Error during get WP constant: %sN)r�r�r�rr�r�rdr�)rIr��raise_exceptionrir2r3r3r4�wp_get_constant�s
r�)�docroot�wordpress_pathcCs�ttj�||�tjjdd�}|sB|tjjkrBtdtjj|d�d��ttj�||�tj	jdd�}|svtddtj	jid��tj�
|�s�tdd	|id��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�r�)r�z0WordPress constant "%(constant)s" is not definedr�z4Redis socket %(socket)s does not exist in the system�socketN)r�r8rKr]rZWP_REDIS_SCHEME�namer�rZ
WP_REDIS_PATHr�)r�r�Zredis_schemar�r3r3r4�#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�rLT)r�rr�)r rr8r�r~rr*ro�formatrKr�r^r_r`ra�decoderrcrdrerwr<r&�sorted)r�Zphp_file_idZ
php_info_filerfZ	_php_inforgr�Z
vhost_infor3r3r4�_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�r8r�r~r�r�)r�Zuse_saved_php_versionrqr3r3r4�get_php_version
s
r�c@seZdZUeed<eed<dS)r�r�r�N)�__name__�
__module__�__qualname__r��__annotations__�dictr3r3r3r4r�s
r�)r�)rKri�
subcommandr.c

Gs�t|�}t|���}tj�|�sBt�d||�tt	d�d|id�St
|�d�|�||f|�}|ftt
df|�}|pvi}	yt|d|	d�}
Wnltjk
r�}zLd	�|�}t�d
||j|j�t��s�tn
tjdd�}tt	d
�||d�d�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".rK)r�r�z	--path={}z/opt/clwpos/wp-cliT)r�r�� z7Error during command execution: 
%s
stdout=%s
stderr=%s�HOME)�homedirz�Unexpected error happened during command execution: '%(command)s'.
Event is logged to file: '%(logger_path)s' with stdout and stderr recorded.)ri�logger_pathN)r�r�r�r8rKr�rdrer��_r'r�rrr(rNr�r]rPr��getuidrr)
rKrir�r��argsrqr�Zcommand_partZfull_commandZenvironment�outputr�r�r3r3r4r�s8

r�c@seZdZdZdS)�DocRootPathz&This class represent path to doc_root.N)r�r�r��__doc__r3r3r3r4r�Wsr�c@seZdZdZdS)�
DomainNamez!This class represent domain name.N)r�r�r�r�r3r3r3r4r�\sr�)�argrI�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�r!r�rr"�
ValueErrorr�rs�absolute�disable_module)r�rIr�r?r�Z
last_error�errorsr3r3r4� disable_without_config_affectingas



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��detailsr�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�r!r�rr"r��lstripr�rsr��install_modulerr�r�r�r��
enable_moduler�)r�rIr��__r?r�rgr3r3r4�enable_without_config_affecting|s.




r�)�uidcCs ddi}|r||d<t|�dS)zQ
    Make redis reload via CLWPOS daemon
    :param uid: User uid (optional)
    riZreloadr�N)r%)r�Zcmd_dictr3r3r4�reload_redis�sr�)r�r�cCs,ddlm}m}|t|ti}|||�dS)z3
    Enable specified WP optimization feature.
    r)�OBJECT_CACHE_FEATURE�SITE_OPTIMIZATION_FEATUREN)�clwpos.optimization_featuresr�r��enable_redis_object_cache�enable_site_optimization_plugin)r�r�r�r��module_func_mapr3r3r4r��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��resr3r3r4r��s

r�cCs4d}tj�tj�|d��r0t�r$dnd}d|i}|S)z*
    Returns needed envars for wp-cli
    Nz	.htaccessZ	LiteSpeedZApacheZSERVER_SOFTWARE)r8rKr�r]r,)r�r�Zserver_softwarer3r3r4�obtain_wp_cli_env�s
r�cCs8t|�}t|ddd|d�}t|t�r4t|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�r�N)r�r�r�r�rr�r�)r�r�r�r3r3r4r��s
r�cCs,ddlm}m}|t|ti}|||�dS)z4
    Install specified WP optimization feature.
    r)r�r�N)r�r�r��install_redis_cache� install_site_optimization_plugin)r�r�r�r�r�r3r3r4r��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�r�zredis-cache)r�r�N)r�r�r�rr�r�)r�r�r3r3r4r��s
r�cCs8t|�}t|ddt|d�}t|t�r4t|j|jd��dS)z}
    Install cloudlinux-site-optimization plugin for user.
    :param abs_wp_path: absolute path to wp site
    :return:
    r�r�)r�)r�r�N)r�r�rr�r�rr�r�)r�r�r�r3r3r4r�s
r�)r�r�r.cCs(ddlm}m}|t|ti}|||�S)zB
    Deactivate and delete specified WP optimization feature.
    r)r�r�)r�r�r��disable_object_cache� disable_site_optimization_plugin)r�r�r�r�r�r3r3r4r�
sr�c
Csg}t|d�r0t|ddd�}t|t�r0|�|�|s`t|d�r`t|ddd�}t|t�r`|�|�|s�yt|�Wn�tk
r�}z"t�	|�|�t|j
|j��Wdd}~XYnLtk
r�}z.t�	|�|�tt
d�tt|�d�d��Wdd}~XYnX|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 occurred during command execution
    zredis-cacher��
deactivate�deleteNz9Unexpected error happened while clearing cache: %(error)s)r�)r�r�)�is_plugin_activatedr�r�r�r<�is_plugin_installedr#rrdrer�r��	Exceptionr�r�r�)r�r�r��errrgr3r3r4r�s,





$
&r�)r��plugin_namer.cCst|dd||d�}t|t�S)Nr�z	is-active)r�)r�r�r�)r�r�
wp_cli_envr2r3r3r4r@srcCst|dd||d�}t|t�S)Nr�zis-installed)r�)r�r�r�)r�rrr2r3r3r4rEsrcCsxg}t|�}t|d|�r>t|ddd|d�}t|t�r>|�|�|stt|d|�rtt|ddd|d�}t|t�rt|�|�|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 occurred during command execution
    r�r�r)r�Z	uninstall)r�rr�r�r�r<r)r�r�r�r�r3r3r4r�Js



r�)N)F)N)N)N)yZ
__future__rr_r8r6r�rN�dataclassesr�	functoolsr�pathlibr�typingrrrr	r
Z
pkg_resourcesrZclcommon.cpapir�clcommon.clwpos_libr
rZclcommon.lib.cleditionrZsecureior�clwpos.constantsrrrrrr�clwpos.cl_wpos_exceptionsrrrZ
clwpos.daemonrZclwpos.logsetuprrr�clwposrr��clwpos.utilsrr r!r"r#r$r%r&r'r(r)r*r+r,r�rdrur�r5r�r@rHrSrYrhrkrlrortrxr�r�ryr�r�r�r�rmr�r��setr�r�r1r�r�r�r�r�r�r�r�r�r�r�r��intr�r�r�r�r�r�r�r�r�r�rrr�r3r3r3r4�<module>s� @	
!
2 

					"9&,


&

........