https://t.me/AnonymousX5
Server : Apache
System : Linux cvar2.toservers.com 3.10.0-962.3.2.lve1.5.73.el7.x86_64 #1 SMP Wed Aug 24 21:31:23 UTC 2022 x86_64
User : njnconst ( 1116)
PHP Version : 8.4.18
Disable Function : NONE
Directory :  /opt/alt/python37/lib/python3.7/site-packages/clwpos/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

A�c2��@sjddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlmZddlmZddlmZmZmZddlmZmZmZmZmZddlZddlmZdd	l m!Z!dd
l"m#Z#ddl$m%Z%m&Z&m'Z'ddl(m)Z)dd
l*m+Z+m,Z,m-Z-ddl.m/Z/m0Z0m1Z1ddl2m3Z3m4Z4ddl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;ddl<m=Z=ddl>m?Z?m@Z@ddlAmBZBddl*mCZCddlDmEZEddlFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQddlRmSZSmTZTddlUmVZVdaWdd�ZXd�eYeYd�dd�ZZd�eYe[e\d �d!d"�Z]d�eYe[d$�d%d&�Z^eYd'�d(d)�Z_eYd*�d+d,�Z`d�eYd'�d-d.�Zad/d0�Zbd1d2�Zcd�ededd3�d4d5�Zeedd'�d6d7�Zfdd8�ede\d3�d9d:�Zgdd8�edd8�d;d<�ZhGd=d>�d>�Zie[ee[d?�d@dA�Zjeedd'�dBdC�ZkedddD�dEdF�ZledddG�dHdI�ZmedddG�dJdK�ZndLdM�ZoedeededfdN�dOdP�Zpedee\dQ�dRdS�ZqGdTdU�dUer�Zsed�edee\dW�dXdY��ZtdZd[�ZuGd\d]�d]ed�ZvGd^d_�d_ev�ZwGd`da�daev�Zxevdb�dcdd�Zyedde�dfdg�Zzeedd'�dhdi�Z{eYee\edfdj�dkdl�Z|eedeYfd'�dmdn�Z}dodp�Z~dqdr�Zdsdt�Z�eevd'�dudv�Z�Gdwdx�dx�Z�d�dydz�Z�Gd{d|�d|�Z�eedd}�d~d��Z�edeYd��d�d��Z�eYd'�d�d��Z�eYd'�d�d��Z�eYd'�d�d��Z�eieidd��d�d��Z�edeieidd��d�d��Z�e\d'�d�d��Z�eYd'�d�d��Z�ee\ededfd'�d�d��Z�eYedeYee\ededfd��d�d��Z�eYee\ededfd��d�d��Z�d�d��Z�eYd'�d�d��Z�eYd'�d�d��Z�dS)��)�absolute_importN)�contextmanager)�wraps)�Path)�socket�AF_UNIX�SOCK_STREAM)�Dict�List�Tuple�Optional�Set)�write_file_via_tempfile)�NoDomain)�ClPwd)�is_cl_solo_edition�is_cl_shared_pro_edition�CLEditionDetectionError)�
check_license)�docroot�	getCPName�CPANEL_NAME)�exec_utility�run_command�demote)�gettext�	wp_config)�	WposError�WPOSLicenseMissing�WpCliUnsupportedException�WpNotExists�WpConfigWriteFailed�PhpBrokenException)�UIConfig)�	in_cagefs�_is_cagefs_enabled)�Feature)�is_panel_feature_supported�)�
setup_logging)�
USER_WPOS_DIR�WPOS_DAEMON_SOCKET_FILE�CLCONFIG_UTILITY�RedisRequiredConstants�CAGEFS_ENTER_USER_BIN�CAGEFS_ENTER_UTIL�CLWPOS_OPT_DIR�ALT_PHP_PREFIX�
EA_PHP_PREFIX�USER_CLWPOS_CONFIG�PUBLIC_OPTIONS)�pack_data_for_socket�'read_unpack_response_from_socket_client)�RollbackExceptioncs�fdd�}|S)z'
    Decorator for catching errors
    c
stdkrtt�ay�|f|�|�Stk
r\}zt|j|j|j|jd��Wdd}~XYn�t	k
r�}zRt
|t�r�t�|�n
t�
|�|j|j|jd�}|jr�|j|d<t|j|�Wdd}~XYnDtk
�r}z$t�
|�t|jit|�d��Wdd}~XYnXdS)N)�context�resultZissues)r8r9�warning�details)r8r9)�loggerr)�__name__r7�error_and_exitZ_is_jsonr8�message�errorsr�
isinstancerr:Z	exceptionr;�	Exception�str)�self�args�kwargs�eZresponse)�func��=/opt/alt/python37/lib/python3.7/site-packages/clwpos/utils.py�func_wrapperTs(



z!catch_error.<locals>.func_wrapperrI)rHrKrI)rHrJ�catch_errorOsrLF)�is_json�	is_prettycCs>|r2|rttj|ddd��q:ttj|dd��nt|�dS)z�
    Print specified dictionary
    :param data_dict: data dictionary to print
    :param is_json: True - print in JSON, False - in text
    :param is_pretty: True - pretty json print, False - none (default)
    :return: None
    �T)�indent�	sort_keys)rQN)�print�json�dumps)Z	data_dictrMrNrIrIrJ�_print_dictionaryps
rU)rMr?�
error_codec
Cs�d|��kr |�d�s |�d�|rF|�dt��i�t||dd�nXy tt|d�|�di��Wn6tk
r�}ztdt|�|f�Wdd}~XYnXt	�
|�dS)	z�
    Print error and exit
    :param is_json:
    :param message: Dictionary with keys "result" as string and optional "context" as dict
    :param error_code: Utility return code on error
    r:�	timestampT)rNr9r8zError: %s [%s]N)�keys�get�pop�update�timerUrRrC�KeyError�sys�exit)rMr?rVrGrIrIrJr>�s
 &r>�success)rM�datacCs0t|t�r|�|t��d��t||dd�dS)zo
    Output data wrapper
    :param is_json:
    :param data: data for output to stdout
    :param result:
    )r9rWT)rNN)rA�dictr[r\rU)rMrar9rIrIrJ�
print_data�s
rc)�returncCst��dkS)zQ
    Detects is we running under root
    :return: True - user, False - root
    r)�os�geteuidrIrIrIrJ�is_run_under_user�srg)�safelycCs*yt�Stk
r$|rdS�YnXdS)z�
    Detecting of shared_pro edition depends on jwt token
    There are some cases when we do not fail if there are
    cases with decoding (e.g summary collection)
    FN)rr)rhrIrIrJ�is_shared_pro_safely�sricCs t�tk}tdd�st|�o|S)u�
    Сheck if system environment is supported by WPOS
    :return:
        True - CPanel on Solo/ CL Shared Pro
        False - else
    T)�skip_jwt_check)rrrri)rhZ	is_cpanelrIrIrJ�is_wpos_supported�s
rkcCs0tj�t|�t�}tj�|�s,tj|dd�dS)z@
    Creates {homedir}/.clwpos directory if it's not exists
    i�)�modeN)re�path�join�home_dirr*�isdir�mkdir)�usernameZ
clwpos_dirrIrIrJ�create_clwpos_dir_if_not_exists�srscCsFt|�d}|�|�s0td|�d|�d|����|t|�d��d�S)Nrzdocroot z for domain z should start with �/)r�
startswithr�len�lstrip)�domain�homedirZdrrIrIrJ�get_relative_docroot�s
rz)rrrdcCst|d�}|jS)N)rr)�get_pw�pw_dir)rrZpwrIrIrJro�s
rocCst�jS)N)r{Zpw_namerIrIrIrJ�	user_name�sr})rrcCst|d�jS)N)rr)r{Zpw_uid)rrrIrIrJ�user_uid�sr~cCs |rt�|�St�t���SdS)N)�pwd�getpwnam�getpwuidrerf)rrrIrIrJr{�s
r{c@s4eZdZdZd
eedd�dd�Zdd�Zdd	�ZdS)�WposUserzQ
    Helper class to construct paths to user's WPOS dir and files inside it.
    N)rrryrdcCsz||_|dkrt|�n||_tj�|jt�|_tj�|jt�|_tj�|jd�|_	tj�|jd�|_
tj�|jd�|_dS)Nz
redis.confz
redis.sockz.php_info-{file_id})�namerorermrnr*�wpos_dirr3Zwpos_config�
redis_conf�redis_socketZphp_info)rDrrryrIrIrJ�__init__�szWposUser.__init__cCs|j|jkS)N)r�)rD�otherrIrIrJ�__eq__�szWposUser.__eq__cCs
t|j�S)N)�hashr�)rDrIrIrJ�__hash__�szWposUser.__hash__)N)r=�
__module__�__qualname__�__doc__rCr�r�r�rIrIrIrJr��s	r�)�cmd_dictrdcCs�t|�}ttt���}yp|�t�|�|�t|�}|dksDt|t	�sZt
td�t|�id��|ddkr�t
td�|d|�
d�d��|Stk
r�t
td�d	ti��YnDtttttjtfk
r�}zt
td
�t|�d��Wdd}~XYnXWdQRXdS)z�
    Send command to CLWPOS daemon via socket
    :param cmd_dict: Command dictionary
    :return: Daemon response as dictionary, None - daemon data/socket error
    NzPUnexpected response from daemon. Report this issue to your system administrator.)r?r;r8r9r`z3Daemon was unable to execute the requested command.r8zbCloudLinux AccelerateWP daemon socket (%(filename)s) not found. Contact your system administrator.�filenamez&Unexpected daemon communication error.)r;)r5rrrZconnectr+Zsendallr6rArbrrrCrY�FileNotFoundError�ConnectionError�OSError�IOError�AttributeError�struct�errorr])r�Z
bytes_to_send�sZ
response_dictrGrIrIrJ�daemon_communicate�s*

r�c
Cs�tj�t�td�}t��}tj}tj	}tj
}tj}dd|j�d|j
�d�dtjj�d|�d�d|j�d|j
�d�d|j�d|j
�|�d�d|j�d|j
�d�dgS)	ak
    Construct list of lines (configuration settings)
    that should be in Wordpress config file to enable redis.
    Please note that deleting of the plugin would flush all keys related to the plugin (site) from redis.
    REDIS_PREFIX and SELECTIVE_FLUSH in wp-config.php would guarantee that plugin will not flush keys unrelated
    to this plugin (site)
    z
redis.sockz)// Start of CloudLinux generated section
zdefine('z', 'z');
z', z);
z'// End of CloudLinux generated section
)rermrnror*�uuidZuuid4r-�WP_REDIS_PREFIXZWP_REDIS_SCHEMEZWP_REDIS_CLIENTZWP_REDIS_SELECTIVE_FLUSHr��valueZ
WP_REDIS_PATH)Zsocket_pathZprefix_uuidZredis_prefixZredis_schemaZredis_clientZredis_flushrIrIrJ�redis_cache_config_sectionsr�)�wp_config_pathrdcCsDtj�|�}tj�|�s t|��tj�|�s@ttd�d|id��dS)z�
    Check that wp-config.php exists inside Wordpress directory.
    :param wp_config_path: absolute path to Wordpress config file
    :raises: WposError
    z)Wordpress config file %(file)s is missing�file)r?r8N)rerm�dirname�existsr �isfilerr)r�Zwp_pathrIrIrJ�check_wp_config_existance5sr�)�abs_wp_pathrdc
s�tt�|��}t|�t��ttd��fdd�}y.t�|�}tt||��}t	d�
|�|d�Wn0ttfk
r�}zt
||��Wdd}~XYnXdS)z�
    Clear cloudlinux section with redis object cache config from docroot's wp-config.php
    :param abs_wp_path: Absolute path to WordPress
    :raises: WposError
    )�linerdcs|�kod|kS)zn
        Filter function that should delete CL config options from the `redis_cache_config_section()`
        r�rI)r�)�lines_to_filterrIrJ�__config_filterNsz1clear_redis_cache_config.<locals>.__config_filter�i�N)rCrrmr�r��bool�read�list�filterrrnr�r�r!)r�r�r��wp_config_linesZcleared_wp_configrGrI)r�rJ�clear_redis_cache_configDs
r�c
stt�|��}t|�y�|�d�}tj�|�s:t�||�dd�tD�}t�	|�}g}xJ|D]B��fdd�|�
�D�}|s~dSt�fdd�tD��s\|���q\W|dft
�|d	d��}td
�|�|d�Wn2ttfk
�r}zt||��Wdd}~XYnXdS)a
    Create config for redis-cache.
    We use manual copy cause we want to preserve file metadata
    and permissions and also we could add some custom config editing in the future.
    :param abs_wp_path: absolute path to WordPress
    :raises: WposError
    z.backupcSsi|]}|j|j�qSrI)r�r�)�.0ZconstantrIrIrJ�
<dictcomp>lsz-create_redis_cache_config.<locals>.<dictcomp>cs&i|]\}}d|�d��kr||�qS)zdefine('�'rI)r��k�v)r�rIrJr�qsNc3s |]}d|j�d��kVqdS)zdefine('r�N)r�)r�Zredis_constant)r�rIrJ�	<genexpr>wsz,create_redis_cache_config.<locals>.<genexpr>rr(r�i�)rCrrmr�rer��shutil�copyr-r��items�any�appendr�rrnr�r�r!)r�r�Zbackup_wp_configZabsent_constantsr�Z
cleaned_linesZupdated_configrGrI)r�rJ�create_redis_cache_config\s*


r�cst���fdd��}|S)z,Decorator to check for license validity
    cst�st���||�S)zLicense check wrapper)rr)rErF)rHrIrJ�wrapper�sz(check_license_decorator.<locals>.wrapper)r)rHr�rI)rHrJ�check_license_decorator�sr�)rxrdcCsByt|�\}}||fStk
r<ttd�d|id��YnXdS)z�
    Validates domain, determines it's owner and docroot or exit with error
    :param domain: Domain name to check
    :return: Tuple (username, docroot)
    zNo such domain: %(domain)s.rx)r?r8N)rrrr)rxZ
document_root�ownerrIrIrJ�check_domain�s
r�)rm�attemptsc	Cs�tj}|dk	r|tjO}yft|d�}xVt|p.d�D]:}yt�|��|�PWq2tk
rjt�	d�Yq2Xq2Wt
td���Wn tk
r�t
td���YnX|S)zE
    Try to take lock on file with specified number of attempts.
    Nza+r(g333333�?zwAnother utility instance is already running. Try again later or contact system administrator in case if issue persists.z%IO error happened while getting lock.)
�fcntlZLOCK_EXZLOCK_NB�open�range�flock�filenor�r\Zsleep�LockFailedExceptionrr�)rmr�Z	lock_type�lock_fd�_rIrIrJ�	lock_file�s

r�c@seZdZdZdS)r�z,
    Exception when failed to take lock
    N)r=r�r�r�rIrIrIrJr��sr��
)�
resource_pathr�ccs t|d|�}dVt|�dS)z�
    Lock a file, than do something.
    Make specified number of attempts to acquire the lock,
    if attempts is None, wait until the lock is released.
    Usage:
    with acquire_lock(path, attempts=1):
       ... do something with files ...
    z.lockN)r��release_lock)r�r�r�rIrIrJ�acquire_lock�s
r�cCs8yt�|��tj�Wntk
r*YnX|��dS)z
    Releases lock file
    N)r�r�r�ZLOCK_UNr��close)Z
descriptorrIrIrJr��s
r�c@s�eZdZdZdd�Zeed�dd��Zed�dd�Ze	d�d	d
�Z
ed�dd�Ze	d�d
d�Zed�dd�Z
e	d�dd�Zedd��ZdS)�PHPzDClass helper which hides differences of PHP behind abstract methods.cGsZ|tkrtj|f|��Sx*ttfD]}|d�|���r"||�Sq"Wtd|d����dS)Nrz
Unknown PHP: )r�rC�__new__�_AltPHP�_EaPHPru�prefixrB)�clsrE�tprIrIrJr��szPHP.__new__)rdcCst�dS)zReturn prefix of PHP.N)�NotImplementedErrorrIrIrIrJr��sz
PHP.prefixcCst�dS)z#Return relative path to dir of PHP.N)r�)rDrIrIrJ�_dir_relative_path�szPHP._dir_relative_pathcCstd|�����S)zReturn path to dir of PHP.z/opt/)rr�)rDrIrIrJ�dir�szPHP.dircCst�dS)z#Return relative path to bin of PHP.N)r�)rDrIrIrJ�_bin_relative_path�szPHP._bin_relative_pathcCs|���|���S)zReturn path to bin of PHP.)r��joinpathr�)rDrIrIrJ�bin�szPHP.bincCst�dS)z#Return relative path to ini of PHP.N)r�)rDrIrIrJ�_ini_relative_path�szPHP._ini_relative_pathcCs|���|���S)zReturn path to ini of PHP.)r�r�r�)rDrIrIrJ�iniszPHP.inicCs |�|��d��dd�}t|�S)Nr�Zphp)�replacer��int)rD�versionrIrIrJ�digitssz
PHP.digitsN)r=r�r�r�r��staticmethodrCr�r�rr�r�r�r�r��propertyr�rIrIrIrJr��s
r�c@s4eZdZdZedd��Zdd�Zdd�Zdd	�Zd
S)r�zImplementation for alt-phpcCsdS)Nzalt-rIrIrIrIrJr�sz_AltPHP.prefixcCsd|t|���d���S)Nzalt/)rvr�)rDrIrIrJr�sz_AltPHP._dir_relative_pathcCsdS)Nzusr/bin/phprI)rDrIrIrJr�sz_AltPHP._bin_relative_pathcCsdS)Nzlink/conf/default.inirI)rDrIrIrJr�sz_AltPHP._ini_relative_pathN)	r=r�r�r�r�r�r�r�r�rIrIrIrJr�
s
r�c@s4eZdZdZedd��Zdd�Zdd�Zdd	�Zd
S)r�zImplementation for ea-phpcCsdS)Nzea-rIrIrIrIrJr�!sz
_EaPHP.prefixcCs
d|��S)Nzcpanel/rI)rDrIrIrJr�%sz_EaPHP._dir_relative_pathcCsdS)Nzroot/usr/bin/phprI)rDrIrIrJr�(sz_EaPHP._bin_relative_pathcCsdS)Nzroot/etc/php.inirI)rDrIrIrJr�+sz_EaPHP._ini_relative_pathN)	r=r�r�r�r�r�r�r�r�rIrIrIrJr�s
r�)�php_versioncCsPt|���}t|dgid�}|jr4|js4t||j��|j}||�d�krLdSdS)z!
    Checks <module> enabled
    z-m)�env�
TF)rCr��run_in_cagefs_if_needed�stderr�stdoutr"�split)r��modulermr9�outrIrIrJ�is_conflict_modules_installed/sr�)�php_pathcCs2d}d|kr.ttd�|�r.ttd�d|id��dS)zX
    Ensures wp-cli is compatible, e.g some
    php modules may prevent stable work
    Z
snuffleupaguszea-php74z�Seems like ea-php74 %(module)s module is enabled. It may cause instabilities while managing object_cache. Disable it and try againr�)r?r8N)r�r�rr)r�Zdangerous_modulerIrIrJ�wp_cli_compatibility_check?sr�cCsdg}tdd�s|�d�|S)z@
    Return list of supported handlers according to edition
    zphp-fpmT)rjZlsapi)rr�)Z	supportedrIrIrJ�supported_php_handlersLs

r�)�hiderdcCs4ddt�ddd|iii�dg}tt|�\}}||fS)zf
    Call cloudlinux-config utility
    to hide/show WPOS icon in user's control panel interface.
    �setz--dataZoptions�
uiSettings�hideWPOSAppz--json)rSrTrr,)r�Zparams�
returncoder�rIrIrJ�set_wpos_icon_visibilityVsr�cCs i}t��dd�}||d<|S)zC
    Return default content of /opt/clwpos/public_config.json.
    r�r�Z	show_icon)r#Z	get_param)Zconfig_dictZis_icon_hiddenrIrIrJ�get_default_public_optionses
r�c
CsNtj�t�st�Stt��*ttd��}|��}t�	|�SQRXWdQRXdS)zS
    Gets admin options by reading UI config
    or wpos PUBLIC_OPTIONS config
    �rN)
rermr�r4r�r�r�r�rS�loads)�fZcontentrIrIrJ�get_admin_optionsos
r�cKs�t�sttj�s8tj|fddtt��t�	��d�|��St��dkrZt
td|�d��d��t|t
�rrtd|}n
tg|}tj|ftt��t�	��ddd�|��Sd	S)
z�
    Wrapper for subprocess to enter cagefs
    do not enter cagefs if:
     - CloudLinux Solo
     - if process already started as user in cagefs
    T)�text�capture_output�
preexec_fnrzInternal error: command zf must not be run as root. Please contact support if you have questions: https://cloudlinux.zendesk.com)r?� )r�r�r�N)r$r'r&�CAGEFS�
subprocess�runrrerf�getegidrrrArCr/)�commandrFZwith_cagefs_enterrIrIrJr�}s 

r�cCs(yt��|�Stjk
r"dSXdS)z
    Returns uid for user
    N)rZget_uidZNoSuchUserException)r�rIrIrJ�uid_by_name�srcs*d}t�d���fdd�t�|�D�}|S)z1
    Get list of installed alt-php versions.
    z/opt/altz
^php\d{2}$cs$g|]}��|�rtd|����qS)zalt-)�matchr�)r�r�)�patternrIrJ�
<listcomp>�sz(get_alt_php_versions.<locals>.<listcomp>)�re�compilere�listdir)Zalt_dirZalt_php_versionsrI)rrJ�get_alt_php_versions�s
rc@s�eZdZdZed�dd�Zeeed�dd�Zee	ee
d�d	d
�Zee	ee
d�dd�Zeeeed
�dd�Z
eeeed�dd�ZdS)�PhpIniConfigz>
    Helper class to update extensions in php .ini files.
    )r�cCs"||_t�d�|_t�d�|_dS)Nz-^;\s*extension\s*=\s*(?P<module_name>\w+)\.soz,^\s*extension\s*=\s*(?P<module_name>\w+)\.so)r�rr	�disabled_pattern�enabled_pattern)rDr�rIrIrJr��szPhpIniConfig.__init__)rmrdc	s(t|d��}�fdd�|D�SQRXdS)zU
        Return enabled modules.
        :param path: full path to .ini file
        r�cs.h|]&}�j�|�dk	r�j�|��d��qS)N�module_name)rr�group)r�r�)rDrIrJ�	<setcomp>�sz0PhpIniConfig._enabled_modules.<locals>.<setcomp>N)r�)rDrmr�rI)rDrJ�_enabled_modules�szPhpIniConfig._enabled_modules)rm�modulesrdc	s�tj��j��|�}tj�|�s$dSt|���|���r�t|��@}��fdd�|�	�D�}x t
��D]}|�d�|��qfWWdQRXt
d�|�|d�dS)	z�
        Enable specified modules in .ini php file.
        :param path: path to .ini file related to php directory
        :param modules: list of modules that should be enabled
        Fcsg|]}��|���qSrI)�_enable_module)r�r�)�modules_to_enablerDrIrJr�sz/PhpIniConfig.enable_modules.<locals>.<listcomp>zextension={}.so
Nr�i�T)rermrnr�r�r�r�rr��	readlines�sortedr��formatr)rDrmr�	full_pathr��
new_ini_linesr�rI)rrDrJ�enable_modules�s
zPhpIniConfig.enable_modulesc	s|tj��j��|�}tj�|�s$dSt|���|�@��rxt|��}��fdd�|�	�D�}WdQRXt
d�|�|d�dS)z�
        Disable specified modules in .ini php file.
        :param path: path to .ini file related to php directory
        :param modules: list of modules that should be disabled
        Fcsg|]}��|���qSrI)�_disable_module)r�r�)�modules_to_disablerDrIrJr�sz0PhpIniConfig.disable_modules.<locals>.<listcomp>Nr�i�T)rermrnr�r�r�r�rr�rr)rDrmrrr�rrI)rrDrJ�disable_modules�s
zPhpIniConfig.disable_modules)r�rrdcCsB|j�|�}|dk	r>|�d�}||kr>|�|�|�d���S|S)zV
        Search for disabled module in line, uncomment line to enable module.
        Nr�;)r
rr�removerw)rDr�rrrrIrIrJr�s

zPhpIniConfig._enable_module)r�rrdcCs4|j�|�}|dk	r0|�d�}||kr0d|��S|S)zT
        Search for enabled module in line, comment line to disable module.
        Nrr)rrr)rDr�rrrrIrIrJr�s

zPhpIniConfig._disable_moduleN)r=r�r�r�r�r�rCr
rr
r�rrrrrIrIrIrJr�s	rcCs�ttj�sdSt�sP|dkr*ttd�d��t|gtjdd�tjdd�}n$t	�spt
t�d�rptgtj}ndSt
j|tjtjid�}|��t�|j�dS)a%
    All user-related actions must run inside of cagefs for security reasons.
    If solo just return because cagefs is only for shared and shared pro
    If root executed, we enter into user cagefs if user is pointed
    If not in cagefs and cagefs is enabeled for user enter into cagefs
    Nz�Internal Error: root enters into CageFS without specifying usernamePlease contact support if you have questions: https://cloudlinux.zendesk.com)r?r(�)�user)r��stdinr�)r'r&r�rgrrr.r^�argvr$r%r}r/r�Popenr�r#Zcommunicater_r�)r"�cmd�prIrIrJ�_run_clwpos_as_user_in_cagefss

&r(c@s\eZdZdZedd�dd�Zdd�dd�Zdd�d	d
�Zed�dd�Z	e
ed�d
d��ZdS)�RedisConfigurePidFilezm
    Helper class that provides methods to work with
    pid files of php redis configuration processes.
    N)�
php_prefixrdcCs|�d�|_tt|j�|_dS)Nz-cloudlinux.pid)Z_pid_file_namerr0rm)rDr*rIrIrJr�&szRedisConfigurePidFile.__init__)rdc	Cs.|j�d��}|�tt����WdQRXdS)N�w)rmr��writerCre�getpid)rDr�rIrIrJ�create*szRedisConfigurePidFile.createcCs|j��r|j��dS)N)rm�is_file�unlink)rDrIrIrJr .s
zRedisConfigurePidFile.removecCs
|j��S)N)rmr/)rDrIrIrJr�2szRedisConfigurePidFile.existsc	CsL|��sdS|j���,}yt|�����Stk
r<YnXWdQRXdS)N���)r�rmr�r�r��strip�
ValueError)rDr�rIrIrJ�pid5szRedisConfigurePidFile.pid)
r=r�r�r�rCr�r.r r�r�r�r�r4rIrIrIrJr) sr))r*ccs*t|�}z|��dVWd|��XdS)za
    Context manager for creating pid file of current process.
    Removes pid file on exit.
    N)r)r.r )r*�pid_filerIrIrJ�create_pid_fileAs

r6)r*rdc	CsTt|�}t��dkr|��Syt�|j�}d|��kSttj	fk
rNdSXdS)z�
    Find out if PHP redis configuration process is running.
    Based on looking for presence of pid files.
    For root also checks process existence.
    rZenable_redisFN)
r)rerfr��psutil�Processr4r�r3Z
NoSuchProcess)r*r5ZprocessrIrIrJ�"is_php_redis_configuration_runningOsr9cCstt�S)zE
    Find out if alt-PHP redis configuration process is running.
    )r9r1rIrIrIrJ�&is_alt_php_redis_configuration_running_sr:cCstt�S)zD
    Find out if ea-PHP redis configuration process is running.
    )r9r2rIrIrIrJ�%is_ea_php_redis_configuration_runningfsr;cCst�p
t�S)za
    Find out if redis configuration process
    is running for any PHP (ea-php or alt-php).
    )r:r;rIrIrIrJ�is_redis_configuration_runningmsr<)�new_user�old_userrdc	sJt�j��}|��}WdQRX��fdd�|D�}td�|��jd�dS)z;
    Replace user's wpos directory path in redis.conf.
    Ncsg|]}|��j�j��qSrI)r�r�)r�r�)r=r>rIrJr~sz%update_redis_conf.<locals>.<listcomp>r�i�)r�r�rrrn)r=r>r�Zredis_conf_lines�
updated_linesrI)r=r>rJ�update_redis_confvsr@)r�r=r>rdc
s|yt�|�}Wn<tk
rJ}ztd|�d|��tjd�dSd}~XYnX��fdd�|D�}td�|�t�|�d�dS)	z<
    Replace user's redis socket path in wp-config.php.
    z=Error occurred during opening wp-config.php located in path "z": )r�Ncs*g|]"}�j|kr"|��j�j�n|�qSrI)r�r�)r�r�)r=r>rIrJr�sz$update_wp_config.<locals>.<listcomp>r�i�)	rr�r�rRr^r�rrnrm)r�r=r>r�rGr?rI)r=r>rJ�update_wp_config�s
rAcCst�t���}|��S)z!
    Get parent process PID.
    )r7r8rer-Zppid)�procrIrIrJ�get_parent_pid�srCcCs(tdddgdd�\}}}|dkr$dSdS)z`
    Detect CL WPOS daemon presence in system
    :return: True - daemon works / False - No
    z
/sbin/service�clwpos_monitoring�statusT)�return_full_outputrF)r)r�r�rIrIrJ�_is_monitoring_daemon_exists�srGcCsHt�d|�tdddgdd�\}}}|s>tddgdd�\}}}|||fS)z5
    Update systemd unit file and reload systemd
    z//usr/share/cloudlinux/clwpos_monitoring.servicez/usr/bin/systemctlZenablezclwpos_monitoring.serviceT)rFz
daemon-reload)r�r�r)�systemd_unit_file�retcoder�r�rIrIrJ�$_update_clwpos_daemon_config_systemd�s
rJ)�is_solorH�is_module_allowed_on_serverrdcCsld\}}}dt��kr0tdddgdd�\}}}n|sF|rFt|�\}}}|sbtddd	gdd�\}}}|||fS)
z4
    Install WPOS daemon to system and start it
    )rNNZel6z/sbin/chkconfigz--addrDT)rFz
/sbin/service�start)�platform�releaserrJ)rKrHrLrIr�r�rIrIrJ�_install_daemon_internal�s


rP)rLrdcCs8d}t�}|stj�|�r"t|�t�r,dSt|||�S)a�
    Install WPOS daemon to server if need:
        - if daemon already present - do nothing;
        - on CL Solo install daemon always;
        - on CL Shared Pro install daemon if module allowed
    On solo and if /etc/systemd/system/clwpos_monitoring.service present it will be updated always
    We do not need restart installed daemon here, it's done in rpm_posttrans.sh
    :param is_module_allowed_on_server: True/False
    z-/etc/systemd/system/clwpos_monitoring.service)rr�r�)rrermr�rJrGrP)rLrHrKrIrIrJ�install_monitoring_daemon�s
rQcCs<dd|�d�i}yt|�}Wntk
r0dSX|�d�S)Nrzget-z-statusFrE)r�rrY)ZserviceZcommand_get_service_status_dictZ
daemon_resultrIrIrJ�get_status_from_daemon�srRcCstd�S)NZredis)rRrIrIrIrJ�redis_is_running�srScCstd�S)NZ	litespeed)rRrIrIrIrJ�litespeed_is_running�srT)FF)r()r`)F)N)r�)N)�Z
__future__rrerr�r�r^r\rSrr�r�rr7�
contextlibr�	functoolsrZpathlibrrrr�typingr	r
rrr
rNZsecureiorZclcommon.cpapi.cpapiexceptionsrZclcommon.clpwdrZclcommon.lib.cleditionrrrZcllicenselibrZclcommon.cpapirrrZclcommon.utilsrrrZclwposrrZclwpos.cl_wpos_exceptionsrrrr r!r"Zclcommon.ui_configr#Zclcommon.clcagefsr$r%Zclcommon.constr&r'Zlogsetupr)Zclwpos.constantsr*r+r,r-r.r/r0r1r2r3r4Zsocket_utilsr5r6Zuser.website_check.errorsr7r<rLr�rUrbr�r>rcrgrirkrsrzrCror}r~r{r�r�r�r�r�r�r�r�r�rBr�r�r�r�r�r�r�r�r�r�r�r�r�rrrr(r)r6r9r:r;r<r@rArCrGrJrPrQrRrSrTrIrIrIrJ�<module>
s� 4!	)
0




Q
!
	
	

https://t.me/AnonymousX5 - 2025