Mjo d Z ddlZddlZddlZddlZddlZddlmZ ddlm Z ddl
mZ ddlm
Z
mZ ddlmZmZ dd lmZ dd
lmZ ddlmZ ddlmZ dd
lmZ ddlmZmZmZ ddl m!Z!m"Z"m#Z$ G d d Z%ddZ&dS )zA
This module contains classes implementing SSA Manager behaviour
N)contextmanager)iglob)
disable_quota)OptionalTuple )load_validated_parserload_configuration) flag_file)SSAManagerError)ssa_version)
AutoTracer)
DecisionMaker)
INI_FILE_NAMEINI_USER_LOCATIONS_BASEis_excluded_path)$copy_inis_to_website_isolation_paths(remove_inis_from_website_isolation_pathsregenerate_inis_for_userc J e Zd ZdZd Zd Zedefd Ze de
fd Ze defd Z
e defd Zd edefd
Zd0dedej fd
Zdededeej fdZdedefdZdefdZdefdZdefdZdefdZdefdZdede
fdZdededefdZdedefdZde e e!e!f ef fdZ"e#d Z$d e!d!e!dedd"fd#Z%d1d$Z&de e e!e!f ef fd%Z'd1d&Z(d1d'Z)d1d(Z*defd)Z+d1d*Z,d1d+Z-defd,Z.d1d-Z/d.edd"fd/Z0d"S )2Managerz
SSA Manager class.
c t j d | _ t | _ ddg| _ ddg| _ d| _ d| _ t | _
t t t j f| _ d S )Nmanagerz!usr/lib64/php/modules/clos_ssa.soz0usr/lib/x86_64-linux-gnu/php/modules/clos_ssa.sozlib64/php/modules/clos_ssa.soz,lib/x86_64-linux-gnu/php/modules/clos_ssa.soz lib/php/extensions/*/clos_ssa.so)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.d)logging getLoggerloggerr
ini_file_namemodule_patterns_with_usrmodule_patterns_no_usrmodule_glob_pattern_directadminwildcard_ini_locationsr wildcard_ini_user_locationsOSError
ValueError
subprocessSubprocessErrorsubprocess_errorsselfs B/opt/cloudlinux/venv/lib64/python3.11/site-packages/ssa/manager.py__init__zManager.__init__. sx ' 22*
0>)
%
,:'
# 0R,'
# ,C("):z7Q!R c J t j } t j | j }n# t
$ r d}Y nw xY wd d | D }| j d||||| d S # t
$ r Y d S w xY w)Nz c 3 * K | ]\ }}|d |V dS )=N .0kvs r* z!Manager._audit..O s1 #Q#QAqqq!!$4#Q#Q#Q#Q#Q#Qr, z0[audit] operation=%s status=%s uid=%d user=%s %s)
osgetuidpwdgetpwuidpw_name Exceptionjoinitemsr info)r) operationstatusdetailsuidusernamedetail_partss r* _auditzManager._auditH s )++C
'<,,4
'
'
'&
'88#Q#Q#Q#Q#QQQLKBIvWZ\dfr
DD s- B 0 B ?B ?AB
B"!B"returnc ddi}| d | D t j | S )z@
Form a success json response with given kwargs
resultsuccessc i | ]\ }}|| S r1 r1 r2 s r*
z$Manager.response..\ s ===daQ===r, )updater> jsondumps)argskwargsraw_responses r* responsezManager.responseV sI
!),==fllnn===>>>z,'''r, c J t j t S )z
Is SSA enabled
)r7 pathisfiler r( s r* _enabledzManager._enabled_ s
w~~i(((r, c
ddhS )zK
Configuration settings required Request Processor restart
requests_durationignore_listr1 r( s r* _restart_required_settingsz"Manager._restart_required_settingsf s
$]33r, c
h dS )N> timecorrelationdomains_numberrequest_numbercorrelation_coefficientr1 r( s r* solo_filtered_settingszManager.solo_filtered_settingsm s eeeer, settingsc 6 | j | S )z
SSA Agent requires restart in case of changing these configuration:
- requests_duration
- ignore_list
)r[ intersection)r) rc s r* _restart_requiredzManager._restart_requiredq s .;;HEEEr, Fcommandc t j dd|gdd| }| j d| d n# t j $ r}| j dt
|j t
|j t
|j |j |j |j |j
d t d
|j d|j d|j p|j
d
}~w| j $ rS}| j dt
| dt
| i t d| d| d
}~ww xY w|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-agentTcapture_outputtextcheckz
ssa-agent z
succeededz$SSA Agent %s failed with code %s: %s)cmdretcodestdoutstderrextraz
SSA Agent z failed with code z: Nz&Failed to run %s command for SSA AgenterrzFailed to run z for SSA Agent: )
r% runr r? CalledProcessErrorerrorstrrm
returncodero rp r r' )r) rg
check_retcoderI es r* run_service_utilityzManager.run_service_utilityy s Q^ +w7SW_l F
K='===>>>>, p p pK6AE
AL!!AH
e\]\dee
""nqu"n"n"n"nXYX`Xldedl"n"nooo% Q Q QKFG]bdghidjdj\klll!"O7"O"OA"O"OPPP Q
s# 9= EBC((
E5AEEunitc t j d||gddd }| j d|||j |S # | j $ r5}| j d||t | Y d}~dS d}~ww xY w)u
Run systemctl on a specific unit. Failures are logged but never raised
— the socket unit may be absent on legacy / non-systemd installs, and
a best-effort attempt is enough for shutdown paths.
:return: the CompletedProcess on success (any return code, since
``check=False``), or ``None`` if systemctl could not be spawned at
all (e.g. missing binary). Callers must guard ``.returncode``
access against ``None``.
z/bin/systemctlTFri zsystemctl %s %s rc=%dz!Failed to run systemctl %s %s: %sN)r% rt r r? rx r' warningrw )r) rg r| rI rz s r*
run_systemctlzManager.run_systemctl s ^%5w$EVZaemrsssFK4gtVEVWWWM% K CWdTWXYTZTZ[[[44444 s >A
B *A;;B rP c
t }fdt | D }| | nv# t
$ ri}| j ddt | i | dd|t | t d| d }~ww xY w| dd
| | r| dd
|
S )z
Change SSA config and restart it.
:args: dict to override current option values
:return: JSON encoded result of the action
c $ i | ]\ }}|v ||
S r1 r1 )r3 r4 r5 rP s r* rL z&Manager.set_config..