403Webshell
Server IP : 192.158.238.246  /  Your IP : 18.116.15.98
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /proc/7779/root/opt/alt/python37/lib/python3.7/site-packages/ssa/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/7779/root/opt/alt/python37/lib/python3.7/site-packages/ssa/__pycache__/manager.cpython-37.pyc
B

V�d�7�@s�dZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddl
mZddlmZdd	lmZmZdd
lmZddlmZddlmZdd
lmZddlmZGdd�d�Zdd�dd�ZdS)zA
This module contains classes implementing SSA Manager behaviour
�N)�contextmanager)�iglob)�is_cl_solo_edition)�
disable_quota)�Tuple�)�load_validated_parser�load_configuration)�	flag_file)�SSAManagerError)�ssa_version)�
AutoTracer)�
DecisionMakerc@s�eZdZdZdd�Zedd�dd��Zeed�dd	��Z	ee
d�d
d��Zee
d�dd
��Ze
e
d�dd�ZdAeejd�dd�Ze
dd�dd�Zdd�dd�Zdd�dd�Zdd�dd�Zdd�dd�Zdd�d d!�Zeed"�d#d$�Zeeeefefd�d%d&�Zed'd(��Zeeed)d*�d+d,�Z d)d�d-d.�Z!eeeefefd�d/d0�Z"d)d�d1d2�Z#d)d�d3d4�Z$d)d�d5d6�Z%ed�d7d8�Z&d)d�d9d:�Z'd)d�d;d<�Z(dd�d=d>�Z)d)d�d?d@�Z*d)S)B�Managerz
    SSA Manager class.
    cCsDt�d�|_d|_d|_d|_tddd�d�f|_tt	t
jf|_dS)	N�managerzclos_ssa.ini)Zphp44Zphp51Zphp52Zphp53zphp\d+-imunifyzphp-internal)z /opt/alt/php[0-9][0-9]/link/confz+/opt/cpanel/ea-php[0-9][0-9]/root/etc/php.dz$/opt/plesk/php/[0-9].[0-9]/etc/php.dz'/usr/local/php[0-9][0-9]/lib/php.conf.dzM/usr/share/cagefs/.cpanel.multiphp/opt/cpanel/ea-php[0-9][0-9]/root/etc/php.dzA/usr/share/cagefs-skeleton/usr/local/php[0-9][0-9]/lib/php.conf.dz./var/cagefs/*/*/etc/cl.php.d/alt-php[0-9][0-9]cSst�|�d�d�S)N�/�)�pwd�getpwnam�split)�path�r�</opt/alt/python37/lib/python3.7/site-packages/ssa/manager.py�<lambda>6�z"Manager.__init__.<locals>.<lambda>)r�user)
�logging�	getLogger�logger�
ini_file_name�substrings_to_exclude_dir_paths�wildcard_ini_locations�dict�wildcard_ini_user_locations�OSError�
ValueError�
subprocess�SubprocessError�subprocess_errors)�selfrrr�__init__%s	zManager.__init__zjson str)�returncOs*ddi}|�dd�|��D��t�|�S)z@
        Form a success json response with given kwargs
        �result�successcSsi|]\}}||�qSrr)�.0�k�vrrr�
<dictcomp>Bsz$Manager.response.<locals>.<dictcomp>)�update�items�json�dumps)�args�kwargsZraw_responserrr�response<szManager.responsecCstj�t�S)z 
        Is SSA enabled
        )�osr�isfiler
)r)rrr�_enabledEszManager._enabledcCsddhS)zK
        Configuration settings required Request Processor restart
        �requests_duration�ignore_listr)r)rrr�_restart_required_settingsLsz"Manager._restart_required_settingscCsdddddhS)N�correlation�correlation_coefficient�request_number�time�domains_numberr)r)rrr�solo_filtered_settingsSszManager.solo_filtered_settings)�settingsr+cCs|j�|�S)z�
        SSA Agent requires restart in case of changing these configuration:
            - requests_duration
            - ignore_list
        )r>�intersection)r)rErrr�_restart_requiredXszManager._restart_requiredF)�commandr+c
Csy0tjdd|gdd|d�}|j�d|�d��Wn�tjk
r�}zd|jjdt|j�t|j�t|j	�|j|j|j	|j
d�d	�td
|j�d|j�d|j	p�|j
����Wd
d
}~XYnX|jk
�r
}z6|jjdt|�dt|�id	�td|�d|����Wd
d
}~XYnX|S)z�
        Run /sbin/service utility to make given operation with SSA Agent service
        :command: command to invoke
        :check_retcode: whether to run with check or not
        :return: subprocess info about completed process
        z
/sbin/servicez	ssa-agentT)�capture_output�text�checkz
ssa-agent z
 succeededz$SSA Agent %s failed with code %s: %s)�cmd�retcode�stdout�stderr)�extraz
SSA Agent z failed with code z: Nz&Failed to run %s command for SSA Agent�errzFailed to run z for SSA Agent: )
r&�runr�info�CalledProcessError�error�strrL�
returncoderNrOrr()r)rH�
check_retcoder,�errr�run_service_utility`s.4$zManager.run_service_utility)r6r+c
Cs�t�}|�|�y|��WnHtk
rd}z*|jjddt|�id�td|����Wdd}~XYnX|�|�r~|j	ddd�|�
�S)	z�
        Change SSA config and restart it.
        :args: dict to override current option values
        :return: JSON encoded result of the action
        z Failed to update SSA config filerQ)rPz"Failed to update SSA config file: N�restartT)rX)r�overrideZwrite_ssa_confr$rrUrVrrGrZr8)r)r6�configrYrrr�
set_config�s
 
zManager.set_configcs>t�}tdd�r2�fdd�|��D�}�j|d�S�j|d�S)zV
        Get current SSA config.
        :return: JSON encoded current config
        T)�skip_jwt_checkcs i|]\}}|�jkr||�qSr)rD)r.�key�value)r)rrr1�sz&Manager.get_config.<locals>.<dictcomp>)r])r	rr3r8)r)Zfull_configZfiltered_configr)r)r�
get_config�s

zManager.get_configcCs|jr
dnd}|j|d�S)zY
        Get current status of SSA.
        :return: JSON encoded current status
        �enabled�disabled)Z
ssa_status)r;r8)r)�statusrrr�get_ssa_status�szManager.get_ssa_statuscCs2|jrtddd��|��|��|��|��S)a�
        Enable SSA:
            - add clos_ssa extension for each PHP version on server
            - add clos_ssa extension into cagefs for each user and each ver
            - start SSA Agent (if it is not already started)
            - restart Apache (etc.) and FPM, reset CRIU images
            - create flag_file indicating that SSA is enabled successfully
        :return: JSON encoded current status
        zSSA is already enabled�warning)�flag)r;r�
generate_inis�start_ssa_agent�create_flagr8)r)rrr�
enable_ssa�s
zManager.enable_ssacCs2|jstddd��|��|��|��|��S)a{
        Disable SSA:
            - remove clos_ssa extension for each PHP version on server
            - remove clos_ssa extension from cagefs for each user and each ver
            - stop SSA Agent
            - restart Apache (etc.) and FPM, reset CRIU images
            - remove flag_file indicating that SSA is enabled
        :return: JSON encoded current status
        zSSA is already disabledrg)rh)r;r�remove_clos_inis�stop_ssa_agent�remove_flagr8)r)rrr�disable_ssa�s
zManager.disable_ssacCs>dd�t���D�}|j|t�|jr(dnd|��t���d�S)z�
        Get SSA statistics.
        Includes:
        - config values
        - version
        - SSA status (enabled|disabled)
        - SSA Agent status (active|inactive)
        :return: JSON encoded current statistics
        cSsi|]\}}t|���|�qSr)rV�lower)r.r`rarrrr1�sz%Manager.get_stats.<locals>.<dictcomp>rcrd)r]�versionre�agent_statusZautotracing)r	r3r8rr;�status_ssa_agentr
�	get_stats)r)Z_configrrrru�s
zManager.get_stats)�dir_pathr+cs�fdd�|jD�}|S)z6
        Checking for substrings in a string.
        csg|]}t�|��r|�qSr)�re�search)r.Z	substring)rvrr�
<listcomp>�sz+Manager.unused_dir_path.<locals>.<listcomp>)r )r)rv�resr)rvr�unused_dir_path�szManager.unused_dir_pathc	cs�x6|jD],}x&t|�D]}|�|�r&qd|fVqWqWxp|jD]f}x`t|d�D]P}|�|�rbqRy|d|�}Wn|j�d|�wRYqRX|j|jf|fVqRWq@WdS)z�
        Generator of existing paths (matching known wildcard locations)
        for additional ini files
        Returns tuple of (uid, gid) and path.
        )rrrrzhUnable to get information about user owning %s directory (maybe he`s already terminated?), skip updatingN)r!rr{r#rrS�pw_uid�pw_gid)r)�locationrvZ	pw_recordrrr�existing_paths�s 

zManager.existing_pathsc	cs:zt�|�t�|�dVWdt�d�t�d�XdS)z�
        Dive into user context by dropping permissions
        to avoid most of the security issues.

        Does not cover cagefs case because it also requires nsenter,
        which is only available with execve() call in our system
        Nr)r9�setegid�seteuid)r)�uid�gidrrr�
_user_contexts	



zManager._user_contextN)r�r��ini_pathr+cCsltj�||j�}|�||��Ft��4t|d��}|j�d|�|�	d�WdQRXWdQRXWdQRXdS)zB
        Enable SSA extension for single ini_path (given)
        �wzGenerating %s file...zextension=clos_ssa.soN)
r9r�joinrr�r�openrrS�write)r)r�r�r�rZinirrr�generate_single_iniszManager.generate_single_inicCs�|j�d�x�|��D]z\\}}}y|�|||�Wqtk
rX|j�d|�wYqtk
r�}z|j�d|t|��wWdd}~XYqXqW|j�d�dS)zj
        Place clos_ssa.ini into each existing Additional ini path,
        including cagefs ones
        z Generating clos_ssa.ini files...z>Unable to update file %s, possible permission misconfigurationz7Exception on generating clos_ssa.ini: "%s", error: "%s"Nz	Finished!)rrSrr��PermissionError�	ExceptionrUrV)r)r�r�r�rYrrrriszManager.generate_inisccsVxP|��D]D\\}}}x6t�|�D](}|j|kr2q"||ftj�||�fVq"Wq
WdS)z�
        Generator function searching for clos_ssa.ini files
        in all existing Additional ini paths
        Returns tuple of (uid, gid) and path.
        N)rr9�listdirrrr�)r)r�r�r��namerrr�find_clos_inis/s

zManager.find_clos_iniscCs�|j�d�xx|��D]l\\}}}y&|�||��t�|�WdQRXWqtk
r�}z|j�d|t|��wWdd}~XYqXqW|j�d�dS)z8
        Remove all gathered clos_ssa.ini files
        zRemoving clos_ssa.ini files...Nz5Exception on removing clos_ssa.ini: "%s", error: "%s"z	Finished!)	rrSr�r�r9�unlinkr��	exceptionrV)r)r�r�Zclos_inirYrrrrm;szManager.remove_clos_iniscCs2|�d�}|jr |jddd�n|jddd�dS)ze
        Start SSA Agent service
        or restart it if it is accidentally already running
        re�startT)rXr[N)rZrW)r)rsrrrrjKs
zManager.start_ssa_agentcCs"|�d�}|js|jddd�dS)z`
        Stop SSA Agent service
        or do nothing if it is accidentally not running
        re�stopT)rXN)rZrW)r)rsrrrrnVs
zManager.stop_ssa_agentcCs,y|jddd�Wntk
r&dSXdS)z:
        Get SSA Agent status: active or inactive
        reT)rX�inactive�active)rZr)r)rrrrt_s
zManager.status_ssa_agentc	Cs.ttd��WdQRX|j�dt�d��dS)zE
        Create a flag file indicating successful enablement
        r�Nz
Flag file z created)r�r
rrS)r)rrrrkis
zManager.create_flagc
Csfy"t�t�|j�dt�d��Wn>tk
r`}z |j�dt�dt|����Wdd}~XYnXdS)z:
        Remove a flag file indicating enablement
        z
Flag file z removedz removal failed: N)r9r�r
rrSr$rgrV)r)rYrrrroqs
zManager.remove_flagcCst���}|jf|�S)zG
        Get last report.
        :return: JSON encoded report
        )rZget_json_reportr8)r)Zreportrrr�
get_report|s
zManager.get_reportcCs|jr|��dS)z@
        Regenerates clos_ssa inis while SSA is enabled
        N)r;ri)r)rrr�regenerate_inis�szManager.regenerate_inis)F)+�__name__�
__module__�__qualname__�__doc__r*�staticmethodr8�property�boolr;�setr>rDr"rGrVr&�CompletedProcessrZr^rbrfrlrpru�listr{r�intrrr�r�rir�rmrjrnrtrkror�r�rrrrr s@		
rzManager instance)r+cCst�S)zk
    Factory function for appropriate manager initialization
    :return: appropriate manager instance
    )rrrrr�initialize_manager�sr�) r�r4rr9rrwr&�
contextlibr�globr�clcommon.lib.cleditionr�secureior�typingrZ
configurationrr	�internal.constantsr
�internal.exceptionsr�internal.utilsrZmodules.autotracerr
Zmodules.decision_makerrrr�rrrr�<module>
s*n

Youez - 2016 - github.com/yon3zu
LinuXploit