ok

Mini Shell

Direktori : /opt/cloudlinux/venv/lib/python3.11/site-packages/xray/internal/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/xray/internal/__pycache__/utils.cpython-311.pyc

�

��f�l�
���dZddlZddlZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mcmZddlmZddlmZmZddlmZddlmZddlmZmZmZmZmZmZmZdd	l m!Z!m"Z"m#Z#ddl$Z$dd
l%m&Z&ddl'm(Z(ddl)m*Z*dd
l+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z<ddl=m>Z>m?Z?m@Z@mAZAmBZBmCZCddlDmEZEmFZFejGd��ZHeIeJe
jKfZLde!de!fd�ZMde!de!fd�ZNde!de!fd�ZOdePfd�ZQdefd�ZRdePdefd �ZSdeTfd!�ZUd"e"eVdeTfd#�ZWd"e"eVdeTfd$�ZXdeTfd%�ZYe@fd&eTd'eTddfd(�ZZe@fd'eTdeTfd)�Z[deTfd*�Z[de#e\fd+�Z]eOdeTfd,���Z^d-eTde#eTfd.�Z_de#eTfd/�Z`dYd0�ZaeAfd1eTde#eTfd2�Zbd3eTd4eTddfd5�Zcd6eTdd7fd8�Zdd9ePdePfd:�Zed;eTde#effd<�Zgd;eTde#eTfd=�ZhdZd;eTddfd>�Zid;eTde\fd?�Zjde\fd@�Zkde\fdA�ZldBe\ddfdC�Zmde\fdD�Znde\fdE�Zode\fdF�Zpd-eTde\fdG�ZqdH�Zred[dK���Zsed\dMeTdNe\fdO���Zted]dPePddfdQ���Zue		d^dTePdUePdPePddfdV���ZvedW���ZwdX�ZxdS)_zB
This module contains helpful utility functions for X-Ray Manager
�N)�getuser)�contextmanager)�date�	timedelta��wraps)�glob)�socket�fromfd�AF_UNIX�SOCK_STREAM�
SOCK_DGRAM�AF_INET�AF_INET6)�Callable�List�Optional)�AtexitIntegration)�LoggingIntegration)�Feature)�is_panel_feature_supported�get_cp_description�	getCPName�is_wp2_environment)�get_cl_edition_readable)�UIConfig)�drop_privileges)�get_rhn_systemid_value)�php_get_vhost_versions_user)�gettext�)�
sentry_dsn�local_tasks_storage�
agent_file�
logging_level�jwt_token_location�user_agent_sock)�	XRayError�XRayManagerExit�utils�func�returnc�F���d��t�����fd���}|S)zf
    Decorator aimed to update ini file in cagefs-skeleton
    Applies to task.add nd task.remove
    c�X�tj�|djd��}|�d��r8td��r)tj�d|dd���}n�|�d��r�td	��r�tj�d	|dd���}tj�tj�|����s1tjtj�|����ndStj�|��s|tj�|��r[	tj	|��dS#t$r7}t�d
|t|��d����Yd}~dSd}~wwxYwdS	tj||��dS#t$r7}t�d
|t|��d����Yd}~dSd}~wwxYw)zd
        Copy ini file to cagefs-skeleton
        Action takes place for cPanel ea-php only
        rzxray.iniz/opt/cpanelz/usr/share/cagefsz"/usr/share/cagefs/.cpanel.multiphpr!Nz
/usr/localz/usr/share/cagefs-skeletonz'Failed to unlink ini in cagefs-skeleton)�xray_ini�err��extraz'Failed to copy ini into cagefs-skeleton)�os�path�join�ini_location�
startswithr	�exists�dirname�mkdir�unlink�OSError�logger�warning�str�shutil�copy)�args�original_ini�skeleton_ini�es    �J/opt/cloudlinux/venv/lib64/python3.11/site-packages/xray/internal/utils.py�updatezskeleton_update.<locals>.updateHsV��
�w�|�|�D��G�$8�*�E�E���"�"�=�1�1�	�d�#�7%�7%�	��7�<�<�(L�(4�Q�R�R�(8�:�:�L�L�
�
$�
$�\�
2�
2�	�t�,�8.�8.�	��7�<�<�(D�(4�Q�R�R�(8�:�:�L��7�>�>�"�'�/�/�,�"?�"?�@�@�
8��������6�6�7�7�7���F��w�~�~�l�+�+�	6��w�~�~�l�+�+�
:�:��I�l�+�+�+�+�+���:�:�:��N�N�#L�6B�14�Q���*9�*9�#�:�:�:�:�:�:�:�:�:�����:����
:�
:�
6���L�,�7�7�7�7�7���
6�
6�
6����H�2>�-0��V�V�&5�&5��6�6�6�6�6�6�6�6�6�����
6���s0�4F
�

G�,G�G�G(�(
H)�2,H$�$H)c�"���|i|���|�dS)�
        Wraps func
        N�)rB�kwargsr+rGs  ��rF�wrapperz skeleton_update.<locals>.wrapperks)���
	
��d��f�������
�
�
�
�r)r+rLrGs` @rF�skeleton_updaterNBsK����!6�!6�!6�F�4�[�[�������[���NrMc�P����d��d��t������fd���}|S)zs
    Decorator aimed to update DBM storage with fake_id:real_id mapping
    Applies to task.add nd task.remove
    c��|d}tt��5}|j||j<ddd��dS#1swxYwYdS)z-
        Update DBM storage contents
        rN)�dbm_storager#�task_id�fake_id)rB�
task_instance�task_storages   rFrGz"dbm_storage_update.<locals>.update|s����Q��
�
�,�
-�
-�	H��2?�2G�L��.�/�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H����	H�	H�	H�	H�	H�	Hs
�:�>�>c���tt��5}	||dj���=n#t$rYnwxYwddd��dS#1swxYwYdS)z.
        Remove task from DBM storage
        rN)rQr#rS�encode�KeyError)rBrUs  rF�removez"dbm_storage_update.<locals>.remove�s����,�
-�
-�	��
� ��a���!7�!7�!9�!9�:�:���
�
�
���
����	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s1�A� 8�A�
A�A�A�A�A�Ac�\��	�jdkr�|�n.#t$r!}tt|�����d}~wwxYw	�|i|��n#t$r�jdkr�|��wxYw	�jdkr�|�dSdS#t$r!}tt|�����d}~wwxYw)rI�addNrY)�__name__�RuntimeErrorr(r?�	Exception)rBrKrEr+rYrGs   ���rFrLz#dbm_storage_update.<locals>.wrapper�s���	$��}��%�%����
�
����	$�	$�	$��C��F�F�#�#�#�����	$����	��D�$�!�&�!�!�!�!���	�	�	��}��%�%����
�
��	����	$��}��(�(����
�
�
�
�)�(���	$�	$�	$��C��F�F�#�#�#�����	$���s4��
?�:�?�A�A(�,B�
B+�
B&�&B+r)r+rLrYrGs` @@rF�dbm_storage_updater_vsb�����H�H�H�	�	�	��4�[�[�$�$�$�$�$�$��[�$�6�NrMc�F���d��t�����fd���}|S)z5
    Decorator aimed to validate given JWT token
    c�"�t��dS)z7
        Check if retrieved JWT token is valid
        N)�is_xray_supportedrJrMrF�checkzcheck_jwt.<locals>.check�s��	�����rMc�,���|i|��}���|S)rIrJ)rBrK�tokenrcr+s   ��rFrLzcheck_jwt.<locals>.wrapper�s)���
��d�%�f�%�%��
������rMr)r+rLrcs` @rF�	check_jwtrf�sJ����
����4�[�[�������[���NrMc�B�ttj����S)zJ
    Get current epoch timestamp as int
    :return: timestamp as int
    )�int�timerJrMrF�	timestamprj�s��
�t�y�{�{���rMc�J�tj��td���z
S)zC
    Pick a yesterday date
    :return: a datetime.date object
    r!)�days)r�todayrrJrMrF�	prev_datern�s ��
�:�<�<�)��+�+�+�+�+rM�tsc�*�tj|��S)zy
    Get the datetime.date object for given int timestamp
    :param ts: timestamp
    :return: datetime.date object
    )r�
fromtimestamp)ros rF�date_of_timestamprr�s����b�!�!�!rMc�D�t���d��S)zj
    Get a formatted representation of yesterday date
    :return: str date in the form of dd/mm/YYYY
    z%d/%m/%Y)rn�strftimerJrMrF�get_formatted_dateru�s��
�;�;���
�+�+�+rM�linksc�f��d�d��fd�t|d��D����S)z
    HTML formatted links
    z)<p>{num}) <a href={link}>{domain}</a></p>�
c�z��g|]7\}}|���D]\}}��|||������8S))�num�link�domain��items�format)�.0�i�l�k�v�	html_items     �rF�
<listcomp>z,get_html_formatted_links.<locals>.<listcomp>�sk���A�A�A�D�A�q�67�g�g�i�i�A�A�.2�a�� �&�&�1�1�Q�&�?�?�A�A�A�ArMr!�r5�	enumerate)rvr�s @rF�get_html_formatted_linksr��sZ���<�I��9�9�A�A�A�A���q�)�)�A�A�A�B�B�BrMc�f��d�d��fd�t|d��D����S)z
    Formatted links
    z{num}) {dom}: {link}rxc�z��g|]7\}}|���D]\}}��|||������8S))rz�domr{r})r�r�r�r�r��	text_items     �rFr�z,get_text_formatted_links.<locals>.<listcomp>�sk���A�A�A���A�67�g�g�i�i�A�A�.2�a�� �&�&�1�!�!�&�<�<�A�A�A�ArMr!r�)rvr�s @rF�get_text_formatted_linksr��sZ���'�I��9�9�A�A�A�A���q�)�)�A�A�A�B�B�BrMc��	tjd��}|���}|�d��j}tj��5}|�d|��ddd��n#1swxYwY|�d��S#ttj
f$r"}ttd����|�d}~wwxYw)ze
    Obtain system ID from /etc/sysconfig/rhn/systemid
    :return: system ID without ID- prefix
    z/etc/sysconfig/rhn/systemidz(.//member[name='system_id']/value/string�	system_idNzID-zFailed to retrieve system_id)
�ET�parse�getroot�find�text�
sentry_sdk�configure_scope�set_tag�lstripr<�
ParseErrorr(�_)�tree�root�whole_id�scoperEs     rF�read_sys_idr��s��
B��x�5�6�6���|�|�~�~���9�9�G�H�H�M��
�
'�
)�
)�	1�U��M�M�+�x�0�0�0�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1����	1�	1�	1�	1����u�%�%�%���R�]�#�B�B�B���8�9�9�:�:��A�����B���s<�AB�A:�.B�:A>�>B�A>�B�C�0C
�
C�sys_id�agent_system_id_pathc��t|d��5}|�|��ddd��dS#1swxYwYdS)zH
    Write system_id into file /usr/share/alt-php-xray/agent_sys_id
    �wN)�open�write)r�r��outs   rF�write_sys_idr�s���
�"�C�	(�	(��C��	�	�&������������������������s�4�8�8c�B�	t|��5}|������cddd��S#1swxYwYdS#t$rC}t�ddt
|��i���t��cYd}~Sd}~wwxYw�zA
    Read system_id saved by agent during its initialization
    Nz8Failed to retrieve agent's system_id, returning real oner0r1)r��read�stripr<r=�infor?r�)r��agent_sysid_filerEs   rF�read_agent_sys_idr�s����
�&�
'�
'�	3�+;�#�(�(�*�*�0�0�2�2�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3����	3�	3�	3�	3�	3�	3���������F��#�a�&�&�/�	�	#�	#�	#��}�}�����������	���s?�A�&A�A�A�A�A�A�
B�8B�B�Bc�L�	tt��5}|������cddd��S#1swxYwYdS#t$rC}t
�ddt|��i���t��cYd}~Sd}~wwxYwr�)	r�r$r�r�r<r=r�r?r�)r�rEs  rFr�r�!s����
�*�
�
�	3�!1�#�(�(�*�*�0�0�2�2�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3����	3�	3�	3�	3�	3�	3���������F��#�a�&�&�/�	�	#�	#�	#��}�}�����������	���s?�A�&A	�A�	A
�
A�A
�A�
B#� 8B�B#�B#c�@�ttj��}|s�t��}t	��}t
�dt|��t|����ttd�
||�������dS)z9Raise XRayError in case of detected non-supported editionzMCurrent CloudLinux edition: %s or Control Panel: %s is not supported by X-RayzMCurrent CloudLinux edition: {} or Control Panel: {} is not supported by X-RayT)rr�XRAYrrr=r�r?r)r�r)�is_supported�current_edition�
current_panels   rFrbrb0s���-�g�l�;�;�L��f�1�3�3��!���
����c���(�(�#�m�*<�*<�	>�	>�	>��a�!N�NT�f�Ud�Ub�Od�Od�e�e�f�f�	f��4rMc�8�	tt��5}|������cddd��S#1swxYwYdS#tt
f$r2t
td��tt��z���wxYw)zT
    Obtain jwt token from /etc/sysconfig/rhn/jwt.token
    :return: token read
    NzJWT file %s read error)	r�r&r�r�r<�IOErrorr(r�r?)�
token_files rF�read_jwt_tokenr�>s���O�
�$�
%�
%�	-���?�?�$�$�*�*�,�,�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-����	-�	-�	-�	-�	-�	-���W��O�O�O���2�3�3�c�:L�6M�6M�M�N�N�N�O���s.�A�&A	�A�	A
�
A�A
�A�AB�filepathc�&�	t|��5}|������}ddd��n#1swxYwYn#t$rYdSwxYwd�|�d��dd���pdS)z8Get version of package from file. alt-php-xray supportedN�.�z0.0-0)r�r�r�r<r5�split)r��v_file�versions   rF�pkg_versionr�Ks����
�(�^�^�	,�v��k�k�m�m�)�)�+�+�G�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,����	,�	,�	,�	,���������������8�8�G�M�M�#�&�&�r��r�*�+�+�6�w�6s3�A�'A�A�A�A�A�A�
A�Ac� �td��S)z#Get version of alt-php-xray packagez/usr/share/alt-php-xray/version)r�rJrMrF�xray_versionr�Us���8�9�9�9rMc���dtdtdtfd�}d�}dd�}d��dtf�fd	�}ttjtj�
��}t
��pd}t|���}tj	t||d
||g���tj��5}|��t��d�|_
	||��n#t$rYnwxYwddd��dS#1swxYwYdS)u�
    Initialize Sentry client
    shutdown_timeout=0 disables Atexit integration as stated in docs:
    'it’s easier to disable it by setting the shutdown_timeout to 0'
    https://docs.sentry.io/platforms/python/default-integrations/#atexit
    On the other hand, docs say, that
    'Setting this value too low will most likely cause problems
    for sending events from command line applications'
    https://docs.sentry.io/error-reporting/configuration/?platform=python#shutdown-timeout
    �event�hintr,c��|d�ddi��|�di��}|�dd��}|r|g|d<|S)z�
        Add extra data into sentry event
        :param event: original event
        :param hint: additional data caught
        :return: updated event
        r2zxray.versionz
0.6-27.el8�fingerprintN)rG�get)r�r��
extra_datar�s    rF�add_infozsentry_init.<locals>.add_infoes`��	�g����~�|�<�=�=�=��Y�Y�w��+�+�
� �n�n�]�D�9�9���	1�$/�=�E�-� ��rMc
�d�t��}|r|�d��nd}|r|�d��nd}t��rdnd}d|fd|fd|fdtj��fdtd	��fd
t
��fdtd��ff}|D]}|j|��
dS)
Nr��name�WP2zControl Panel NamezControl Panel VersionzControl Panel Product�kernelzCloudLinux version�
os_releasezCloudlinux edition�Architecture�architecture)rr�r�platform�releaserrr�)�sentry_scope�cp_description�
cp_version�cp_name�
cp_product�tags�tags       rF�set_tagszsentry_init.<locals>.set_tagsvs���+�-�-��6D�N�^�'�'�	�2�2�2�$�
�0>�H�.�$�$�V�,�,�,�D��0�2�2�<�U�U��
�%�w�/�(�*�5�(�*�5��8�+�-�-�.�%�'=�l�'K�'K�L�%�'>�'@�'@�A��!7��!G�!G�H�
J���	'�	'�C� �L� �#�&�&�&�	'�	'rMNc��dS�NrJ)�pending�timeouts  rF�nopezsentry_init.<locals>.nope�s���rMc���t|t��5}	|�|df��|���d}n#t$rd}YnwxYwddd��n#1swxYwY|S)aI
        address_family - we can choose constants represent the address
                           (and protocol) families
                           (AF_INET for ipv4 and AF_INET6 for ipv6)
        private_ip - specify some private ip address. For instance:
                     ipv4 -> 10.255.255.255 or ipv6 -> fc00::
        r!rN)r
r�connect�getsocknamer^)�address_family�
private_ip�s�IPs    rF�
try_get_ipzsentry_init.<locals>.try_get_ip�s����N�J�
/�
/�	�1�
��	�	�:�q�/�*�*�*��]�]�_�_�Q�'�����
�
�
�����
����		�	�	�	�	�	�	�	�	�	�	����	�	�	�	��	s4�A(�1A
�	A(�
A�A(�A�A(�(A,�/A,c�`��tdftdff}|D]\}}�||��}|r|cS�dS)z&
        Retrieve server's IP
        z10.255.255.255zfc00::z	127.0.0.1)rr)�
ipversions�addr_fam�priv_ip�ipr�s    �rF�ip_addrzsentry_init.<locals>.ip_addr�sZ����/�0�8�X�2F�F�
�!+�	�	��H�g���H�g�.�.�B��
��	�	�	�
��{rM)�level�event_levelzalt-php-xray@0.6-27.el8)�callbacki')�dsn�before_sendr��max_value_length�integrations)�
ip_address�username�r,N)�dictr?r�logging�INFO�WARNINGr�rr��initr"r�r�userr^)	r�r�r�r��sentry_logging�xray_ver�
silent_atexitr�r�s	        @rF�sentry_initrYs�������D��T�����"'�'�'�$
�
�
�
���� 	�S�	�	�	�	�	�	�(�g�l�4;�O�E�E�E�N��~�~�:�!:�H�%�t�4�4�4�M��O�
��$�%*�"0�-�!@�B�B�B�B�
�	#�	%�	%���!�'�)�)��	�	�
�
��
�	��H�U�O�O�O�O���	�	�	��D�	������������������������s6�*C3�
C�C3�
C#� C3�"C#�#C3�3C7�:C7�lognamec�H�tjtjtjtjtjd�}t
��	tj|���g}|dkr&|�tj	����tj
|�|tj��dd|���n8#t$r+tj
tj
��g���YdSwxYw	tj|d	��n#t $rYnwxYw|S)
z[
    Configure logging and Sentry
    :param logname: path to log
    :return: logpath
    )�debugr�r>�error�critical)�filenamerz1%(asctime)s [%(threadName)s:%(name)s] %(message)sz%m/%d/%Y %I:%M:%S %p)r�r�datefmt�handlers)rNi�)r��DEBUGr�r��ERROR�CRITICALr�FileHandler�append�
StreamHandler�basicConfigr�r<�NullHandlerr3�chmod�PermissionError)rr��levelsrs    rF�configure_loggingr�s7�������?����$���F��M�M�M�
����1�1�1�
���G����O�O�G�1�3�3�4�4�4���&�*�*�U�G�L�"A�"A�#V�$:�%-�	/�	/�	/�	/�	/��������g�&9�&;�&;�%<�=�=�=�=��������

�
���%� � � � ���
�
�
���
�����Ns%�
A8C�1C8�7C8�<D�
D�D�src�dstc���	tj||��dS#t$rD}tt	d�||t
|��������|�d}~wwxYw)zZ
    Move file with error catching
    :param src: source
    :param dst: destination
    z Failed to move file {} to {}: {}N)r@�mover<r(r�rr?)rrrEs   rF�	safe_mover�sv��_���C���������_�_�_���<�C�C�C��c�RS�f�f�U�U�V�V�W�W�]^�^�����_���s��
A'�?A"�"A'�
sock_locationz
socket objectc���ttj�dd����}|dkr�t	��5	tj|��n#t$rYnwxYwtt��}|�	|��|�
��ddd��n#1swxYwYn/tdtt��}|�
��|S)z�
    Create world-writable socket in given sock_location
    or reuse existing one
    :param sock_location: socket address
    :return: socket object
    �
LISTEN_FDSrN�)
rhr3�environr��umask_0r;�FileNotFoundErrorr
r�bind�listenrr
)r�
listen_fds�sockobjs   rF�
create_socketr(�s���R�Z�^�^�L�!�4�4�5�5�J��Q���
�Y�Y�	�	�
��	�-�(�(�(�(��$�
�
�
���
�����W�o�o�G��L�L��'�'�'��N�N����	�	�	�	�	�	�	�	�	�	�	����	�	�	�	����G�[�1�1���������Ns7�B2�A�B2�
A&�#B2�%A&�&AB2�2B6�9B6�lve_idc�>�ttj��sdSd}d|�d�}	t|��5}|D]�}|�|��rut
�d|��t|����	|��d�����ccddd��S��	ddd��n#1swxYwYn@#t$r3}t
�d|t|����Yd}~nd}~wwxYwdS)	zX
    Retrieve current value of CPU throttled time.
    Return 0 in case of failures
    r�throttled_timez/sys/fs/cgroup/cpu,cpuacct/lvez	/cpu.statz%s���NzFailed to open %s: %s)
rr�LVEr�r7r=rrhr�r�r<rr?)r)�marker�	stat_file�stat_values�valuerEs      rF�get_current_cpu_throttling_timer2s���
&�g�k�2�2���q�
�F�B��B�B�B�I�A�
�)�_�_�	H��$�
H�
H���#�#�F�+�+�H��L�L��u�-�-�-��u�{�{�}�}�2�2�6�:�:�2�>�D�D�F�F�G�G�G�G�		H�	H�	H�	H�	H�	H�	H�	H�H�
H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H����	H�	H�	H�	H���
�A�A�A����,�i��Q���@�@�@�@�@�@�@�@�����A�����1sG�C�BC�6C�C�C�C�C�C�C�
D�')D�Dr�c���d}tj�|��sdS	tj|d|dgddd���}|j���|j���fS#tj$r6}t�
ddt|��i�	��Yd}~dSd}~wt$r3}t�
d
t|����Yd}~dSd}~wwxYw)z�
    'selectorctl -u username --user-current' command
    :param username: name of user
    :return: tuple(stdout, stderr) or None if command fails
    z/usr/bin/selectorctlNz-uz--user-currentT��capture_outputr�rcz&Failed to get selectorctl user-currentr0r1z%selectorctl --user-current failed: %s)r3r4�isfile�
subprocess�run�stdoutr��stderr�CalledProcessErrorr=r>r?�subprocess_errorsr)r��_selectorctl�resultrEs    rF�_selectorctl_get_versionr?sE��*�L�
�7�>�>�,�'�'���t�����!%�!)�!1�!3�04�$�d�	L�L�L��
�}�"�"�$�$�f�m�&9�&9�&;�&;�;�;���(�.�.�.����?�#�S��V�V�_�	�	.�	.�	.�	.�	.�	.�	.�	.�	.������������<���V�V�	�	�	�	�	�	�	�	�	��������s$�A
A3�3C3�+B3�3
C3�(C.�.C3c��d}tj�|��sdS	tj|d|gddd���}|j���S#tj$r6}t�	ddt|��i���Yd}~dSd}~wt$r3}t�d	t|����Yd}~dSd}~wwxYw)
z�
    'cagefsctl --get-prefix username' command
    :param username: name of user
    :return: cagefsctl prefix for given username
            or None if command fails
    �/usr/sbin/cagefsctlNz--getprefixTr4zFailed to get cagefsctl prefixr0r1z cagefsctl --getprefix failed: %s)
r3r4r6r7r8r9r�r;r=r>r?r<r�r��
_cagefsctlr>rEs    rF�cagefsctl_get_prefixrD.s/��'�J�
�7�>�>�*�%�%���t�����!.�!)�!+�04�$�d�L�L�L���}�"�"�$�$�$���(�.�.�.����7�#�S��V�V�_�	�	.�	.�	.�	.�	.�	.�	.�	.�	.������������7���V�V�	�	�	�	�	�	�	�	�	��������s#�3A�C�(+B�
C�&(C�Cc���d}tj�|��sdS|�|ddg}n|d|g}	tj|dd���t
�d|��dS#tj$r6}t
�d	d
t|��i���Yd}~dSd}~wt$r3}t
�dt|����Yd}~dSd}~wwxYw)
z�
    'cagefsctl --remount username' or 'cagefsctl --remount-all' command
    :param username: name of user or None (for remount-all)
    rANz--wait-lockz
--remount-allz	--remountT)rcr5zRemounted %szFailed to remount cagefsr0r1zcagefsctl --remount failed: %s)r3r4r6r7r8r=r�r;r>r?r<r)r�rCrBrEs    rF�_cagefsctl_remountrFFs;��
'�J�
�7�>�>�*�%�%�������M�?�;����K��2�����t�4��=�=�=�=����N�H�-�-�-�-�-���(�.�.�.����1�#�S��V�V�_�	�	.�	.�	.�	.�	.�	.�	.�	.�	.������������5���V�V�	�	�	�	�	�	�	�	�	��������s#�2A&�&C&�5+B&�&
C&�3(C!�!C&c�4�d}tj�|��sdS	tj|d|gdd���}d|j���vS#t$r3}t�	dt|����Yd}~dSd}~wwxYw)	z�
    'cagefsctl --user-status username' command
    :param username: name of user
    :return: True if user has Enabled status, False otherwise
    rAFz
--user-statusT)r5r��Enabledz"cagefsctl --user-status failed: %sN)r3r4r6r7r8r9r�r<r=rr?rBs    rF�_is_cagefs_enabledrI]s���'�J�
�7�>�>�*�%�%���u�����!0�!)�!+�04�$�@�@�@���F�M�/�/�1�1�1�1���������9���V�V�	�	�	�	�	�	�	�	�	��������s�4A�
B�$(B�Bc��	td��5}|���}ddd��n#1swxYwYn#t$rYdSwxYwd|vS)z`
    Check if there is php.d.location = selector
    set in /etc/cl.selector/symlinks.rules
    z/etc/cl.selector/symlinks.rulesNF�selector)r�r�r<)�
rules_file�contentss  rF�_is_selector_phpd_location_setrNqs���
�
�3�
4�
4�	)�
�!���(�(�H�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)����	)�	)�	)�	)��������u�u�������!�!s'�>�2�>�6�>�6�>�
A�Ac��tt��5}t|�����dkcddd��S#1swxYwYdS)z:Check if there are no active tasks (== empty task storage)rN)rQr#�len�keys)rUs rF�no_active_tasksrR~s���	�(�	)�	)�-�\��<�$�$�&�&�'�'�1�,�-�-�-�-�-�-�-�-�-�-�-�-����-�-�-�-�-�-s�%A�A�A�enabledc�H�ttj��sdS	tddd���5}|�|rdnd��ddd��dS#1swxYwYdS#t
$r4}t�d|t|����Yd}~dSd}~wwxYw)	zb
    Switch on/off throttle statistics gathering by kmodlve
    :param enabled: True or False
    Nz!/proc/sys/kernel/sched_schedstats�wbr)�mode�	buffering�1�0z(Failed to set sched_schedstats to %s: %s)	rrr-r�r�r<r=r�r?)rS�frEs   rF�switch_schedstatsr[�s��
&�g�k�2�2����%�
�5�D�����	/�"#�
�G�G�G�-�D�D��.�.�.�	/�	/�	/�	/�	/�	/�	/�	/�	/�	/�	/�	/����	/�	/�	/�	/�	/�	/���%�%�%����>��S��V�V�	%�	%�	%�	%�	%�	%�	%�	%�	%�����%���s:�A#�A�	A#�A�A#�A�A#�#
B!�-)B�B!c�J�t���dd��duS)zG
    Check if end-users have access to X-Ray UI of End-User plugin
    �hideXrayApp�
uiSettingsF)r�	get_paramrJrMrF�is_xray_app_availabler`�s#���:�:���
�|�<�<��E�ErMc���ttt��5}	|�t��n##t
tf$rYddd��dSwxYw	ddd��n#1swxYwYdS)z Check if User Agent is listeningNFT)r
rr
r�r'�ConnectionErrorr<)r�s rF�is_xray_user_agent_activerc�s���	���	%�	%���	�
�I�I�o�&�&�&�&����)�	�	�	��	��������	����
'�������������������
�4s1�A(�8�A(�A�	A(�A�A(�(A,�/A,c�B�tj�d��S)z2Check if SSA is disabled by its internal flag-filez/usr/share/clos_ssa/ssa_enabled)r3r4r6rJrMrF�ssa_disabledre�s���w�~�~�?�@�@�@�@rMc�~�	t��tj|��jz
dkS#t$rYdSwxYw)z.Check is file was modified during the last dayi�QF)rjr3�stat�st_mtimer<)r�s rF�is_file_recently_modifiedri�sJ����{�{�R�W�X�.�.�7�7�%�?�?�������u�u����s�+.�
<�<c�p�t|��5t��}ddd��n#1swxYwY|Sr�)rr)r�r>s  rF�get_user_php_versionrk�su��	��	�	�/�/�,�.�.��/�/�/�/�/�/�/�/�/�/�/����/�/�/�/��Ms�+�/�/�fd�'file object providing a fileno() methodc#��K�td��D]�}	tj|tjtjz��t
�d|��n�#t$rf}t
�dt|����|j	tj
tjfvr�tj
d��Yd}~��d}~wwxYwt|d��d����	dV�tj|tj��t
�d	|��dS#tj|tj��t
�d	|��wxYw)
uq
    Context manager for locking given file object
    :param fd: а file object providing a fileno() method
    �xzFile %s lockedzFailed to lock: %sg�?Nz%Failed to lock at all. Exiting threadr>)�flagzFile %s unlocked)�range�fcntl�flock�LOCK_EX�LOCK_NBr=r�r<r?�errno�EAGAIN�EACCESri�sleepr(�LOCK_UN)rlr�rEs   rF�filelockr{�s[�����3�Z�Z�
(�
(��		��K��E�M�E�M�9�:�:�:��K�K�(�"�-�-�-��E���	�	�	��K�K�,�c�!�f�f�5�5�5��w�u�|�U�\�:�:�:���J�s�O�O�O�O�O�O�O�O�����	�������A�B�B�&�(�(�(�	(�,�
����	��B��
�&�&�&����&��+�+�+�+�+��	��B��
�&�&�&����&��+�+�+�+���s%�AA�
C�(AC	�	C�,D,�,<E(Fr	�	is_shelvec#�K�tj�|��}d}td��D]�}	|rt	j|��}nt
j|d��}t�d|��nd#tj	$r=}t�
d|||��|}tjd��Yd}~��d}~wwxYwtd|�d|�����	|V�|���t�d	|��dS#|���t�d	|��wxYw)
a1
    Context manager for waiting for lock to be released for DBM file storage,
    either plain DBM or a Shelf object
    (desired return value is controlled by _shelve_instance flag)
    :param filename: a DBM file to open
    :param is_shelve: if a shelve file should be opened instead of plain DBM
    N�d�czStorage %s openedz#[#%i] Failed to open storage %s: %sg333333�?zFailed to open z
 storage: zStorage %s closed)r3r4�basenamerq�shelver��dbmr=rrr�riryr]�close)r	r|�_file�_errr��storagerEs       rFrQrQ�se����
�G���X�&�&�E��D�
�3�Z�Z�7�7��	��
2� �+�h�/�/����(�8�S�1�1���L�L�,�e�4�4�4��E���y�	�	�	��K�K�=�q��q�
"�
"�
"��D��J�s�O�O�O�O�O�O�O�O�����		�����5�e�5�5�t�5�5�7�7�	7�1��
�
�
��
�
�������(�%�0�0�0�0�0��	�
�
�������(�%�0�0�0�0���s$�AA?�?C�3C�C�$D�1E
�maskc#�bK�tj|��}dV�tj|��dS)z,
    Context manager for dropping umask
    N)r3�umask)r��prevs  rFr"r"�s/����
�8�D�>�>�D�	�E�E�E��H�T�N�N�N�N�NrMr�T�
target_uid�
target_gidc#��K�tj��}tj��}td��}	tj|��}n#t
$rd}YnwxYw|�|�|}n|j}|�|�|}n|j}|�tj|��}	||krWtj	|��t�d|��|r&tj��|krt|���||krqtj|��t�d|��|r@tj��|kr)||krtj	|��t|���dV�||kr/tj|��t�d|��||kr/tj	|��t�d|��|�tj|	��dSdS)aH
    Context manager to drop privileges during some operation
    and then restore them back.
    If target_uid or target_gid are given, use input values.
    Otherwise, stat target_uid and target_gid from given target_path.
    If no target_path given, use current directory.
    Use mask if given.
    :param target_uid: uid to set
    :param target_gid: gid to set
    :param target_path: directory or file to stat for privileges,
                       default -- current directory
    :param mask: umask to use
    :param with_check: check the result of switching privileges
    z6Unable to execute required operation: permission issueNzDropped GID privs to %szDropped UID privs to %szRestored UID privs to %szRestored GID privs to %s)r3�getuid�getgidr�rgr<�st_uid�st_gidr��setegidr=r�getegidr(�seteuid�geteuid)
r�r��target_pathr��
with_check�prev_uid�prev_gid�permission_issue_message�	stat_infor�s
          rF�set_privilegesr�s����"�y�{�{�H��y�{�{�H� �!Y�Z�Z����G�K�(�(�	�	�������	�	�	���������!�J�J�"�)�J�����!�J�J�"�)�J����x��~�~���:���
�
�:�������.�
�;�;�;��	6�"�*�,�,�*�4�4��4�5�5�5��:���
�
�:�������.�
�;�;�;��	6�"�*�,�,�*�4�4��:�%�%��
�8�$�$�$��4�5�5�5�	�E�E�E��:���
�
�8�������/��:�:�:��:���
�
�8�������/��:�:�:���
���������s�A�A�Ac#�K�	tj|��tj|��dV�tjd��tjd��dS#tjd��tjd��wxYw)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)r3r�r�)�uid�gids  rF�user_contextr�Ksn�����
�
�3����
�
�3����
����
�
�1�
�
�
�
�
�1�
�
�
�
�
��	�
�1�
�
�
�
�
�1�
�
�
�
���s�,A�*Bc������fd�}|S)z:
    Decorator to retry method on specific exceptions
    c�������fd�}|S)Nc�F��d}ttd��t���z��}|�krk	�|i|��S#t���$rG}|dz
}t	jdt|����|}t
jd��Yd}~nd}~wwxYw|�k�k|�)Nrz0Request to website failed even after %s retries.r!z'Retry to request website, exception: %s)�
ValueErrorr�r?�tupler�r>riry)rBrK�retries�	exceptionrE�exceptions_to_retryr+�max_retriess     ���rFrLz7retry_on_exceptions.<locals>.decorator.<locals>.wrapperds�����G�"�1�%W�#X�#X�[^�_j�[k�[k�#k�l�l�I��K�'�'�"��4��0��0�0�0���0�1�1�"�"�"��q�L�G��O�$M�s�ST�v�v�V�V�V� !�I��J�q�M�M�M�M�M�M�M�M�����	"�����K�'�'��Os�?�B�=B�BrJ)r+rLr�r�s` ��rF�	decoratorz&retry_on_exceptions.<locals>.decoratorcs.����	�	�	�	�	�	�	��rMrJ)r�r�r�s`` rF�retry_on_exceptionsr�_s*����
�
�
�
�
�
��rMr�r�)rlrmr,N)F)r)NNr�NT)y�__doc__r�rv�getpassrrrr�r3r�r@r7r�ri�xml.etree.ElementTree�etree�ElementTreer��
contextlibr�datetimerr�	functoolsrr	r
rrr
rrr�typingrrrr��sentry_sdk.integrations.atexitr�sentry_sdk.integrations.loggingr�clcommon.constr�clcommon.cpapirrrr�clcommon.lib.cleditionr�clcommon.ui_configr�clcommon.clpwdr�clcommon.utilsr�clwpos.papir�xrayr r��	constantsr"r#r$r%r&r'�
exceptionsr(r)�	getLoggerr=r<r��SubprocessErrorr<rNr_rfrhrjrnrrr?rur�r�r�r�r�r��boolrbr�r�r�rrrr(r2r�r?rDrFrIrNrRr[r`rcrerirkr{rQr"r�r�r�rJrMrF�<module>r�s]�����
�
�
�������������������	�	�	�	�
�
�
�
�
�
�
�
�������������"�"�"�"�"�"�"�"�"�%�%�%�%�%�%�$�$�$�$�$�$�$�$�������������'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�+�+�+�+�+�+�+�+�+�+�����<�<�<�<�<�<�>�>�>�>�>�>�"�"�"�"�"�"�h�h�h�h�h�h�h�h�h�h�h�h�:�:�:�:�:�:�'�'�'�'�'�'�*�*�*�*�*�*�1�1�1�1�1�1�3�3�3�3�3�3�����������������������3�2�2�2�2�2�2�2�
��	�7�	#�	#���Z��3���1�(�1�x�1�1�1�1�h5�X�5�(�5�5�5�5�p�H�������4�3�����,�4�,�,�,�,�"�#�"�$�"�"�"�"�,�C�,�,�,�,�B�D��J�B�3�B�B�B�B�B�D��J�B�3�B�B�B�B�
B�S�
B�
B�
B�
B� ;E�����C�������3=���C��������3������8�D�>������	O��	O�	O�	O���	O�7�#�7�(�3�-�7�7�7�7�:�h�s�m�:�:�:�:�]�]�]�]�@+8�"�"�s�"�H�S�M�"�"�"�"�J	_�3�	_�S�	_�T�	_�	_�	_�	_���������0
�C�
�C�
�
�
�
�(�s��x�������0�3��8�C�=�����0���������.��������(
"��
"�
"�
"�
"�-��-�-�-�-�%�t�%��%�%�%�%�$F�t�F�F�F�F��4�����A�d�A�A�A�A�
������������,�,�,���,�<�1�1�#�1�$�1�1�1���1�B���#��d��������=A�AE�?�?�s�?�s�?�*-�?�JN�?�?�?���?�D������&����rM

Zerion Mini Shell 1.0