Viewing File: /opt/imunify360/venv/lib/python3.11/site-packages/clcommon/__pycache__/utils.cpython-311.pyc



]jf
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZmZddl
mZddlmZmZmZmZmZmZddlZddlZddlmcmZddlmZmZmZmZdZ dZ!dZ"d	Z#d
Z$dZ%dQdZ&d
Z'dZ(dZ)dZ*					dRdZ+dZ,dee-fdZ.dZ/de0fdZ1de-dzfdZ2de-dzfdZ3edee-fdZ4de5fdZ6de-de0fdZ7de0fd Z8de0fd!Z9de0fd"Z:d#Z;d$e-de0fd%Z<d&Z=d'Z>d(Z?d)Z@d*ZAd+e-de0fd,ZBd-e5de0fd.ZCd/edee0fd0ZDde5fd1ZEd2e-dee0e0ffd3ZFd2e-dee0e0ffd4ZGd2e-dee0e0ffd5ZHd6e-d7e0de0fd8ZId9eejejJfde-fd:ZK	dQd;e-d<e-d=e-d>e5dee5e-ff
d?ZLde-fd@ZMde0fdAZNdBe-dee5fdCZOdBe-fdDZPdBe-fdEZQdFZRdGe-de-fdHZSde0fdIZTdJe-de-fdKZUdeVe-dze-dzffdLZWde0fdMZXde0fdNZYdOZZdPZ[dS)SN)ConfigParserError)cache)AnyAnyStrDictOptionalTupleUnion)ExternalProgramFailed
check_commandexec_utilityrun_commandz/etc/sysconfig/rhn/systemid)MonTueWedThuFriSatSunz /opt/cloudlinux/litespeed_statusz/opt/cloudlinux/nginx_statusz/opt/apache2nginx/statecd}tj|r&	tj|}n#t$rYnwxYw||kr=	tj|n#t$rYnwxYwtj||dSdS)a
    Create symlink link_path -> link_value if it does not exist or
    points to different location
    :param link_value: path that symlink should point to (symlink value)
    :type link_value: str
    :param link_path: path where to create symlink
    :type link_path: str
    N)ospathislinkreadlinkOSErrorunlinksymlink)
link_value	link_pathlink_tos   n/builddir/build/BUILD/imunify360-venv-2.6.3/opt/imunify360/venv/lib/python3.11/site-packages/clcommon/utils.pycreate_symlinkr#1sG	w~~i  	k),,GG			D	W	Ii    			D	

:y)))))s!8
AAA$$
A10A1cg}tj|r>t|d|5}|}dddn#1swxYwY|S)a
    Read file and return file's lines
    errors param may be passed to define how handle
    unicode errors, errors=None is default value of open()
    :param path: path to file
    :param unicode_errors_handle: how to handle unicode errors
    :return: list of file's lines
    utf-8)encodingerrorsN)rrisfileopen	readlines)runicode_errors_handlecontentfs    r"get_file_linesr.HsG	w~~d$
$1F
G
G
G	$1kkmmG	$	$	$	$	$	$	$	$	$	$	$	$	$	$	$NsAAAct||d5}||ddddS#1swxYwYdS)z
    Write lines to file
    :param content: list of lines for writing to file
    :param path: path to file
    :param mode: open mode
    :return: None
    r%r&N)r)
writelines)rr,moder-s    r"write_file_linesr3Xs
dD7	+	+	+q	Ws6::ct|}fd|D}t|t|k}t||d|S)a
    Delete line from file.
    Return True when line(s) have been deleted, False otherwise (specified line is not found)

    :param path: path to file
    :type path: string
    :param line: line to delete without EOL ('\n')
    :type line: string
    :rtype bool
    cFg|]}|dk|S)
)rstrip).0itemlines  r"
<listcomp>z)delete_line_from_file.<locals>.<listcomp>ps/OOOtTT[[=N=N5N5Nd5N5N5Nw+)r.lenr3)rr:
file_linesout_file_linesfounds `   r"delete_line_from_filerBdsZ %%JOOOOzOOON
OOs>222ET>4000Lr<cLtj}|dkr	tjdj}|tjvstj|krdSn#t$rYnwxYwtdtj
tjddSdS)zH
    Check whether current user is effectively root and exit if not
    r
clsupergidNz'Error: root privileges required. Abort.)file)rgeteuidgrpgetgrnamgr_gid	getgroupsgetegidKeyErrorprintsysstderrexit)euidrJs  r"is_root_or_exitrSws:<<Dqyy	\,//6F''2:<<6+A+A,B			D	
7cjIIIIysAA##
A0/A0c@tjdS)z^
    Detect whether EA4 is installed.
    :return: True - EA4 present; False - EA4 absent
    z/etc/cpanel/ea4/is_ea4)rrr(r<r"is_ea4rVs
7>>2333r<FTc#jK|t|}d}|s1|ds|sd|}tj|}nd}|D]]}|r3|r||dks||r|}n||r|}|r||Vn|nd}^||VdSdS)a
    Grep pattern in file
    :param multiple_search: if True - search all match,
                            False - search first match
    :param pattern: pattern for search
    :param path: path to file
    :param data_from_file: read data from file for parsing
    :param fixed_string: if True - search only fixed string,
           False - search by regexp
    :param match_any_position: if True - search any match position,
           False - search only from string begin
    :return: Generator with matched strings
    N^rF)r.
startswithrecompilefindsearch)	patternrfixed_stringmatch_any_positionmultiple_searchdata_from_fileresultpattern_compr:s	         r"grepres*'--
F!!#&&	$/A	$#'mmGz'**

	"
tyy'9'9R'?'?DOOT[D\D\'?

 
 
&
&	F	v1LLLL

E
r<c4tjtS)z-
    :rtype: lxml.etree._ElementTree obj
    )etreeparseRHN_SYSTEMID_FILErUr<r"_parse_systemid_filerjs;()))r<returnc(	t}|dD]B}|dj|kr"|ddjcSCn)#tt
ttjf$rYdSwxYwdS)z`
    find a member in xml by name and return value
    :type name: str
    :rtype: str|None
    membernamevaluerN)	rjiterr\textr
IndexErrorrMrg
ParseError)rnrhn_systemid_xmlrms   r"get_rhn_systemid_valuerus/11&++H55	4	4F{{6""'4//{{7++A.33330	4
Z5+;<tt4sA$A)'A))"BBc&dd|dd}tj|s|S	tjd|gdd}|dd}tjd	gdd}d
}d|d}|D]
}||vr|}n|rd|d
<||d<nd|d|d|d<n/#tjtf$r}d|d|d|d<Yd}~nd}~wwxYw|S)aG
    Detect the file system on which a given file is stored.

    E.g., the file can be stored in NFS and this can affect the normal operation of the file.
    We want to receive information about FS in emergency situations during reading or writing
    :param file_path: path to file, for which we want to detect file system
    :return: dict, which contains two keys:
            key 'success' can be equals to False if we got error or True if we got normal result
            key 'details' can contais error string if key 'success' is False or result if key 'success' is True
    FzFile "z" isn't exists)successdetailsdfT)shellrqrFmountz on z type rwrxz#We can't get file system for file "z". Mount point "z" not found in mount output.z". Exception ""N)
rrexists
subprocesscheck_outputstrip
splitlinessplitCalledProcessErrorr)		file_pathrc	df_outputmount_pointmount_outputdataneedler:errs	         r"*get_file_system_in_which_file_is_stored_onrs6I666F7>>)$$
c+
9


	
 oo''2244R8>>@@D!.
I



++++ ++--		D~~	 $F9 $F9JyJJ +JJJ
9
)73cccb9bb\_bbbycMsB5C""D8D		Dctdd}	|d|dd}n#t$rd}YnwxYw|S)z
    Check if testing is enabled in /etc/yum.repos.d/cloudlinux.repo config
    :return: bool value if testing enabled or not
    NF)
interpolationstrictz /etc/yum.repos.d/cloudlinux.repozcloudlinux-updates-testingenabled)rread
getbooleanr)parserress  r"is_testing_enabled_reporso
U
;
;
;F6777 <iHHJs+?A
Acddd}td}|r||vr||Std}|r |dd}d|Sd	S)
ax
    Return the CloudLinux OS version.

    Ubuntu + CL Extension is a separate case from normal CL variants.
    The string returned is based on /etc/os-release and contains the major version of the Ubuntu system.

    Previously Ubuntu 20.04 identified itself as "cl8" in this scenario.

    :return: Appropriate version string or None if the version is not recognized.
    ubuntu22ubuntu20)jammyfocal
os_release.rubuntuN)ruget_os_versionr)
ubuntu_maprelease
version_ids   r"get_cl_version_ubuntursJ%\22G#7j(('"" !!!$J%%%c**1-
$
$$$4r<c@trtSdddddddd}tj}|D]\}}|r||vr|cStd	}|d
St
dd}|D]}t||vrd
|cSd
S)ab
    Return the CloudLinux OS version taking into account the release version
    from `platform.release()` or the RHN systemid file.

    E.g: release =
        2.6.32-896.16.1.lve1.4.54.el6.x86_64
        5.14.0-162.6.1.el9_1.x86_64

    The release string is converted to return the appropriate version string:
        el6 = cl6
        el8 = cl8
    cl6cl6hcl7cl7hcl8cl9cl10)zel6.zel6h.zel7.zel7h.zel8.z.el9z.el10rNcl)	is_ubunturplatformritemsrurangestr)check_vals_decoderr	check_val
cl_versionaccepted_cl_versionsvers      r"get_cl_versionr<s{{'$&&&  G!3!9!9!;!;	:	yG++$\22Gt F++#s88w::4r<c	tdg}n#tjtf$rYdSwxYw|dkr|dddSdS)	a
    Return virtualization type on current system.

    It is reachable via virt-what utility.
    E.g.: 'kvm', 'bhyve', 'openvz', 'qemu'
    All acceptable outputs are listed here:
    https://people.redhat.com/~rjones/virt-what/virt-what.txt

    Output will be returned with at least two rows
    Sample:
        > kvm
        >
    Furthermore, there is a possibility for multiple text rows
    Sample:
        > xen
        > xen-domU
    That's why, the result will be taken from a first row.
    If the output is empty, and there were no errors, the machine
    is either non-virtual, or virt-what tool isn't familiar with it's
    hypervisor. But the list of supported hypervisors and containers
    covers all popular VMs types.

    :return: virt_type - Optional[AnyStr]
        - appropriate virtualization type string,
        - 'physical' if there is no virtualization,
        - None if there was an error
    z/usr/sbin/virt-whatNr|r6r)maxsplitrphysical)rrrrFileNotFoundErrorr)virt_what_outputs r"
get_virt_typerhs:&(='>??EEGG)+<=tt2%%dQ%77:::s"%??pidcT	tj|ddS#t$rYdSwxYw)z
    Check for a process existence by os.kill command
    If os.kill will be used as os.kill(pid, 0), it will
    just check for a presence of such PID

    And if such pid can't be reached with kill method,
    there will be raised OSError
    rTF)rkillr)rs r"	check_pidrsA
Qtuus
''
pid_file_pathc	tj|tjtjz}n#t$rYdSwxYw	tj|}t
j|js1	|dkr(	tj	|dS#t$rYdSwxYwdStj
|d5}d}tt|
cddd|dkr&	tj	|S#t$rYSwxYwS#1swxYwYnF#ttf$r2Y|dkr(	tj	|dS#t$rYdSwxYwdSwxYw	|dkr(	tj	|dS#t$rYdSwxYwdS#|dkr&	tj	|w#t$rYwwxYwwxYw)z
    Check if process running using pid file
    Arguments:
        pid_file_path: path to the pid file of service

    Returns:
        bool: True or False

    Frr%r0rFN)rr)O_RDONLY
O_NOFOLLOWrfstatstatS_ISREGst_modeclosefdopenrintrr
ValueError)rfdstr-s    r"is_process_runningrs
W]BK"-$?
@
@uu
Xb\\|BJ''	77




7
YrG
,
,
,	4BS!1!12233	4	4	4	4	4	4	477





	4	4	4	4	4	4	4	4	4
 
77




7	477




7277




s,/
==-D<6B
BBD<5AD07D<
D
D,+D,0D44D<7D48D<;F3<E?
F3E++
E98E9>E??F3
F  
F.-F.3G!;GG!
GG!GG!cttjdkr"d}d}t|pt|Stjt
sdSt
t
d5}|}dddn#1swxYwY|dkS)	a
    Detect that server works under Litespeed.

    Note: be careful when modifying this method.
    It is used in X-Ray, ask @dkavchuk or someone else from C-Projects team
    for details.
    return: True - LS working; False - LS not running (stopped or absent)
    rz/tmp/lshttpd/lshttpd.pidz/var/run/openlitespeed.pidFr%r0N0)	rrGrrr~LITESPEED_STATUS_FOR_USERSr)rr)litespeed_pid_pathopenlitespeed_pid_pathr-statuss    r"is_litespeed_runningrs
z||q7!=!"455c9KLb9c9cc
7>>455u	
(7	;	;	;"q!!"""""""""""""""S=s6'B))B-0B-cRtjdkrd}t|Stjt
sdSt
t
d5}|}dddn#1swxYwY|dkS)a

    Detect that server works under nginx.
    Note: be careful when modifying this method.
    It is used in X-Ray, ask @dkavchuk or someone else from C-Projects team
    for details.
    return: True - nginx working; False - nginx not running (stopped or absent)
    rz/run/nginx.pidFr%r0Nr)	rrGrrr~NGINX_STATUS_FOR_USERSr)rr)rr-rs   r"is_nginx_runningrs
z||q(
!-000
7>>011u	
$w	7	7	7"1!!"""""""""""""""S=s%'BBBctjtsdSt	td5}|}dddn#1swxYwY|dkS)a"
    Detect that server works under apache2nginx.
    Note: be careful when modifying this method.
    It is used in X-Ray, ask @dkavchuk or someone else from C-Projects team
    for details.
    return: True - apache2nginx working; False - apache2nginx not running (stopped or absent)
    Fr%r0Non)rrr~APACHE2NGINX_STATEr)rr)r-rs  r"is_apache2nginx_runningrs7>>,--u	
 7	3	3	3"q!!"""""""""""""""T>s'A00A47A4c&trdSdS)zU
    Return proper passenger package according to apache version
    :rtype: str
    zapache24-passengerzalt-mod-passenger)rVrUr<r"get_passenger_package_namers
xx$$#r<package_namec	trtddd|g}d|vrdSntdd|gn#t$rYdSwxYwdS)	z
    Check that the given package is installed on the server.

    :param package_name: Package name to check.
    :return: True if package is installed, False otherwise.
    z
dpkg-queryz-Wz-f='${Status}
'zinstall ok installedFrpmz-qT)rrr)r
pkg_statuss  r"is_package_installedrs
;;
	5%lD:Ll%[\\J&Z77u8
l3444 uu4s%==
A
AcVtrtStS)z
    Pick the package manager to check depending on the OS.
    If we're not on Ubuntu, assume a CL variant with RPM.

    :return: Error string, if any, None otherwise.
    )rget_apt_db_errorsget_rpm_db_errorsrUr<r"get_package_db_errorsrs({{# """r<cT	tjddgdtjtjd5}|\}}|jdkrd|d|d	cd
d
d
S	d
d
d
n#1swxYwYn&#t
$r}t
|cYd
}~Sd
}~wwxYwd
S)z
    Check the dpkg DB as described in https://man7.org/linux/man-pages/man1/dpkg.1.html
    See `--audit`.

    :return: Error string, if any, None otherwise.
    dpkgz--auditFT)rzstdoutrPrqrzdpkg audit error: r6rNrPopenPIPEcommunicate
returncoderr)procstd_outstd_errrs    r"rr'sH


Y??


	B#//11GW!##AGAAwAAA	B	B	B	B	B	B	B	B$	B	B	B	B	B	B	B	B	B	B	B	B	B	B	B3xx4sF/B+A6B*B6A::B=A:>B
B%B B% B%cZd}	tjgdtjtjd5}|\}}|jdkrd|d|d|cd	d	d	S	d	d	d	n#1swxYwYn&#t
$r}t
|cYd	}~Sd	}~wwxYwd	S)
zx
    Check RPM DB consistency.

    :return: None - No RPM DB errors
            string_message - Error description
    zjhttps://cloudlinux.zendesk.com/hc/en-us/articles/115004075294-Fix-rpmdb-Thread-died-in-Berkeley-DB-library)z/bin/rpmz--dbpathz/var/lib/rpmz
--verifydbT)rrPrqrzRPM DB check error: r6z.
See doc: Nr)doc_linkrrrrs     r"rrAsV	u


BBB??	


		Y
#//11GW!##XgXXXXhXX		Y		Y		Y		Y		Y		Y		Y		Y$		Y		Y		Y		Y		Y		Y		Y		Y		Y		Y		Y		Y		Y		Y		Y3xx4sF.B-A9B-B9A==BA=B
B(B#B(#B(cztjt_tjt_dS)a(
    Upon process exit, Sentry sometimes prints:

        Sentry is attempting to send 1 pending error messages
        Waiting up to 10 seconds
        Press Ctrl-C to quit

    This causes broken JSON in output.
    See also this issue: https://github.com/getsentry/raven-python/issues/904
    N)ioStringIOrOrrPrUr<r"!silence_stdout_until_process_exitr\s"CJCJJJr<cd|dzz
}tj|5tj||ddddS#1swxYwYdS)a
    Create directories with desired permissions

    Changed in version 3.7: The mode argument no longer affects
    the file permission bits of newly-created intermediate-level directories.
    Because it we use umask while creating dirs

    :param mod: desired permissions
    iN)secureio	set_umaskrmakedirs)rmodinverted_mods   r"mod_makedirsrksC%K(L		L	)	)
D#sAAAusernamecT	tj|n#t$rYdSwxYwdS)z,
    Check user existence in the system
    FT)pwdgetpwnamrM)rs r"is_user_presentrzsAXuu4
%%uidcT	tj|n#t$rYdSwxYwdS)z+
    Check uid existence in the system
    FT)rgetpwuidrM)r
s r"is_uid_presentr
sASuu4r	rc	tj|j}n#ttf$rYdSwxYwtj|}|S)z+
    Check that file by path is socket
    N)rlstatrrrrS_ISSOCK)rr2	is_sockets   r"is_socket_filersUx~~%w'tt
d##Is11ctjdddd}|d}|dkrdnt	|}|S)z?
    Get number of system run level by command `runlevel`.
    z/sbin/runlevelT	/bin/bash)rz
executablerqrS)rrrrr)outputrclevels   r"get_system_runlevelrsc
$
	F\\^^
!
!
#
#A
&F3AACKKELr<service_namect}	tjdd|gitjddid}n#tjtf$rYdSwxYw|}|dd	D]V}|d
}|ddk}t|d}||krd|fcSWd
S)z
    Return state of a service (present and enabled) for init.d system.
    Returns False, False if a service doesn't exist
    Returns True, False if a service exists and it's not enabled
    Returns True, True if a service exists and it's enabled
    z/sbin/chkconfigz--listLANGCT)envrqFFrN:rrTF)
rrrrenvironrrrrr)rrunlevelroutput_list
state_info
state_list	is_activestate_runlevels        r"#_get_service_state_on_init_d_systemr)s#$$H(
,7+2:+vs++	



)+<=||,,..&&((K!!""o##
%%''--c22
qMT)	Z]++~%%?"""&;s*;AAc	tjdd|gtjtjdS#tjtf$r	tjdd|gtjtj5}||jdvr	dddYd	S	dddYd
S#1swxYwYYdS#tjtf$rYYd
SwxYwwxYw)z
    Return state of service (present and enabled) for systemd system
    Returns False, False if a service doesn't exist
    Returns True, False if a service exists and it's not enabled
    Returns True, True if a service exists and it's enabled
    z/usr/bin/systemctlz
is-enabled)rrP)TTr)rPr)rNr!r)r
check_callDEVNULLrrrrr)rrs  r"$_get_service_state_on_systemd_systemr.s "<>%%	
	
	
	
z)+<=   	 !( 
")!)
$  """?f,,&
$
$
$
$
$
$
$
$
$$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$ -/@A	 	 	 <<<	 % sW.2C 	.C7B3C$B3%C3B7	7C:B7	;CCC CC ct}|rd|vrt|\}}nt|\}}||fS)zb
    Return state of service (present and enabled)
    :param service_name: name of a service
    r)r)rr)r.)rcl_ver
is_present
is_enableds    r"service_is_enabled_and_presentr3si


F

%6//!D%"
"
"

JJ"F%"
"
"

Jz!!r<process_file_pathstrict_matchcVtj|std|dt	jdgD]`}	|s||vs-|r.|d|krdSL#tj$rY]wxYwdS)a
    Check that a file in path is running.
    You can get false-postive if parameter `strict_match` == False, process is
    not running, but someone on server open file by path `process_file_path`
    in an editor
    :param process_file_path: path to a file which is run
    :param strict_match: we use parameter `process_file_path` as full cmd line
                         with args for comparing if `strict_match` == True.
    :return: True if it's running, False - is not,
    zProcess file in path "" does not existcmdline TF)	rrr~rpsutilprocess_iterr8join
NoSuchProcess)r4r5processs   r"process_is_runningr?	s7>>+,,^ \9J \ \ \]]]&	{33	 
%6'//:K:K%K%K&L!2chhw?P?P6Q6Q!Q!Qtt#			H	5sABB&%B&dtct|tjtjfstdt	|t
|S)z
    Get string representation of weekday from datetime.datetime or datetime.date.
    Returns shortened version of weekday from WEEK_DAYS.
    zFRequire object of type datetime.datetime or datetime.date, but passed )
isinstancedatetimedate	TypeErrortype	WEEK_DAYSweekday)r@s r"get_weekdayrI!sU

rH-x}=>>mkaefhaiaikklllRZZ\\""r<config_pathapache_module_name
param_namedefaultcd|d}g}t|}d}|D]@}|}||krd}|r|dkrn|r||Att	dd|}	fd|	D}
|
s||d	fS|
s|
d
d|d|fS|
d
d}t
|d
}|d	fS)a
    Parse httpd config for details about the mpm module used.

    :param config_path: path for configuration file with modules
    :param apache_module_name: expected mpm module. Can be `event`,
        `worker`, `prefork`
    :param param_name: name of parameter to find
    :param default: default value for parameter, if there won't be record
    :return: tuple with param value and text result of operation

    Example of config file content:
    <IfModule mpm_prefork_module>
    .................
        MaxRequestWorkers   450
    </IfModule>
    --
    <IfModule mpm_worker_module>
    .................
        MaxRequestWorkers      300
    </IfModule>
    --
    <IfModule mpm_event_module>
    .................
        MaxRequestWorkers     2048
    </IfModule>
    z<IfModule mpm_z_module>FTz</IfModule>)rar_rbcg|]=}|)|>SrU)rrY)r8	directiverLs  r"r;z/find_module_param_in_config.<locals>.<listcomp>bsApppiyGXGXGcGcdnGoGop	!!pppr<NOKrz.MaxRequestWorkers directive not found for mpm_z_module module in rFr9)r.rappendlistrerr)
rJrKrLrMif_module_line
section_lines	mpm_linesis_section_foundr:grep_result_listmrw_listpartsmax_request_workerss
  `          r"find_module_param_in_configr\+s\@C&8BBBNM{++I	'	'zz||>!!#	
 5 5E	'  &&& (		
	
	
qppp3CpppH+}

p=Oppcnpp
	

RLs##EeBi..$$r<cPd}tj|sdS	t|d5}|}dddn#1swxYwY|dd\}}n#ttf$rYdSwxYw|S)zp
    Return kmodlve module's version.
    Content of '/sys/module/kmodlve/version' looks like '2.0-30.el8'.
    z/sys/module/kmodlve/versionr|r%r0Nrr)	rrr(r)rrrsplitrr)kmodlve_module_file_pathr-modulemodule_version_s     r"get_kmodlve_module_versionrcus
 =
7>>233r
*W
=
=
=	&VVXX^^%%F	&	&	&	&	&	&	&	&	&	&	&	&	&	&	&"MM#q11Z rrs4B'A)B)A--B0A-1BB#"B#crddi}t}||vrdS||}t}||krdSdS)a
    Find out if system has version of the kernel
    (according to kmodlve module's version)
    where fs.proc_can_see_other_uid and hidepid options are synchronized.
    They are only synchronized if kmodlve module's version
    is equal to version in synced_kmodlve_versions.
    rz2.0-30FT)rrc)synced_kmodlve_versionsrsynced_versioncurrent_versions    r")proc_can_see_other_uid_and_hidepid_syncedrhsU %h/!!J000u,Z8N022O.((t5r<pid_filenamec	t|d5}t|}t	j|ddddn#1swxYwYn#ttf$rd}YnwxYw|S)z
    Detrmines working daemon process pid
    :param pid_filename: PID filename
    :return: PID from file or None if error (file not found, etc)
    r%r0rN)r)rrrrrrr)ripfrs   r"get_process_pidrls
,
1
1
1	Rbggiioo''((CGCOOO															
Z Js5A4A	A(A4(A,,A4/A,0A44B
	B
ct|dd5}|tjddddS#1swxYwYdS)z
    Writes pid file
    r=r%r0N)r)writergetpid)rirks  r"write_pid_filerps
lD7	3	3	3#r
BIKK!"""##################s(AAAcR	tj|dS#t$rYdSwxYw)z
    Remove PID file
    N)rremover)ris r"remove_pid_filerss?

	,



s
&&cfd}|S)a
    Set user's real uid and gid to specified ones.
    Checking equality of real and effective uids is needed
    because this function may be used by root
    with effective uid dropped to user's uid.
    In that case it is needed to set effective uid back to 0 first.
    ctj}tj}||krtj|tjtjdSN)rgetuidrGseteuidsetgidsetuid)real_uideff_uidgidr
s  r"funczdemote.<locals>.funcsR9;;*,,wJx   
	#
	#r<rU)r
r}r~s`` r"demoters)Kr<dirpathcLtj|std|ddd|g}t	|}	|dd}|dd}n%#t$r}td	||d
}~wwxYw|S)zK
    Get mount point for dirpath directory from output of `df` utility
    zDirectory "r7z/bin/dfz-hr6rr9rFz)Utility "df" returned unexpected output:
N)rrisdirrrrrr)rfs_info_cmdfs_infomountpoint_info
mounted_ones      r"get_mount_pointrs7==!!?=G===>>>dG,K+&&G
U!----a0$**3//3

UUUL7LLMMSTTUs6A??
B!	BB!cd}tj|stdkSt	|d5}t|}|dkcdddS#1swxYwYdS)z
    Detect if 'may_detach_mounts' kernel option is enabled.
    More info on the option: https://cloudlinux.atlassian.net/browse/KMODLVE-512
    z/proc/sys/fs/may_detach_mountsrr%r0rN)rrr(rr)rr)may_detach_mounts_filer-vals   r"is_may_detach_mounts_enabledrs
>
7>>011)5((	
$w	7	7	71!&&((mmaxs'A99A=A=devicec^tj}|D]}|j|kr	|jcSdS)z;
    Return the file system type for the given device.
    r|)r:disk_partitionsrfstype)r
partitions	partitions   r"get_filesystem_typersH'))J$$	v%%####&
2r<c	d}d}tj}t|d5}|d|d|zdddn#1swxYwY||dd	}||d
d	}n#ttjf$rYdSwxYw|dkr|	d
rd}||fS)zN
    Detect system name and version.
    :return: tuple (os_name, os_ver)
    z/etc/os-releasetopr%r0[z]
NNAMEr}
VERSION_ID)NN	AlmaLinux10
CloudLinux)
configparserrr)read_stringrgetrrrrY)os_release_filenamesection_nameconfigstreamos_nameos_vers      r"rrs`
/*,,
%
8
8
8	FF4<444v{{}}DEEE	F	F	F	F	F	F	F	F	F	F	F	F	F	F	F**\62288==L,77==cBB\'(zz
+&"3"3D"9"9F?s5(C/A%C%A))C,A)-ACCCc0t\}}|dkS)z~
    Determine whether this system is Ubuntu.

    Reads /etc/os-release file to do so.

    :return: bool flag is_ubuntu
    Ubuntu)r)rrbs  r"rr!s !!JGQhr<cd}tjdr1tjdddtjtjdk}|S)z\
    Determine if secure boot is turned on
    :return: bool flag is_secureboot_enabled
    Fz/sys/firmware/efiz!mokutil --sb-state | grep enabledTr)rzrrrPr)rrr~rcallr-)rs r"is_secureboot_enabledr-s_
G	w~~)**

O3&!)!)



	Nr<c|	tjtjdS#t$rYdSwxYw)z'
    Get username of current user.
    rN)rrrrw	ExceptionrUr<r"get_usernamerAsD|BIKK((++tts*-
;;c&trdSdS)z-
    It differs on Ubuntu and CloudLinux
    z%usr/lib/x86_64-linux-gnu/php/modules/zusr/lib64/php/modules/)rrUr<r"get_modules_dir_for_alt_phprKs{{766##r<rv)NFTFN)\rrCrHrrrrrZrrrOrr	functoolsrtypingrrrr	r
rr:rxml.etree.ElementTreergElementTreeclcommon.utils_cmdrr
rrrirGrrrr#r.r3rBrSrVrerjrrurboolrrrrrrrrrrrrrrrrrrr
rrr)r.r3r?rDrIr\rcrhrlrprsrrrrtuplerrrrrrUr<r"<module>rs



								



				



,,,,,,,,<<<<<<<<<<<<<<<<



%%%%%%%%%2=	?7.***.



 			&$444

,,,,^***
HSM



 666rsTz:)d
))))X#x}####L3"cd>d($$st0			46cd

HTN



S$ c eD$J>O    F# s# uT4Z?P# # # # L""tTz9J"""""#Td0#E(+X]:;#####	G%G%G%G%G%	G%
38_G%G%G%G%TC"4&
#
(3-



 #####
#



,SS,
d



 cDj#*45>	4				t($$$$$r<
Back to Directory File Manager