File: //opt/cloudlinux/venv/lib/python3.11/site-packages/xray/internal/__pycache__/utils.cpython-311.pyc
�
�Pcj�s �
� � d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
Z
ddlZddlZddl
Z
ddlZddlmc mZ ddlmZ ddlmZmZ ddlmZ ddlmZ ddlmZmZmZmZ ddlm Z m!Z!m"Z" ddl#Z#dd l$m%Z% dd
l&m'Z' ddl(m)Z) ddl*m+Z+m,Z,m-Z-m.Z. dd
l/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z; ddl<m=Z=m>Z>m?Z?m@Z@mAZAmBZB ddlCmDZDmEZE ejF d� � ZGeHeIejJ fZKde de fd�ZLde de fd�ZMde de fd�ZNdeOfd�ZPdefd�ZQdeOdefd�ZRdeSfd �ZTd!e!eU deSfd"�ZVd!e!eU deSfd#�ZWdeSfd$�ZXe?fd%eSd&eSddfd'�ZYdeSfd(�ZZde"e[ fd)�Z\eNdeSfd*�� � Z]d+eSde"eS fd,�Z^de"eS fd-�Z_dXd.�Z`e@fd/eSde"eS fd0�Za ejb d1� � Zcd2eSddfd3�Zdd2eSd4eedeefd5�Zfd6eSd7eSddfd8�Zgd9eSdefd:�Zhd;eOdeOfd<�Zid2eSde"ej fd=�Zkd2eSde"eS fd>�ZldYd2eSddfd?�Zmd2eSde[fd@�Znde[fdA�Zode[fdB�ZpdCe[ddfdD�Zqde[fdE�Zrde[fdF�Zsde[fdG�Ztd+eSde[fdH�ZudI� ZvedXdJ�� � ZwedZdLeSdMe[fdN�� � Zxed[dOeOddfdP�� � Zye d\dSeOdTeOdOeOddfdU�� � ZzedV� � � Z{dW� Z|dS )]zB
This module contains helpful utility functions for X-Ray Manager
� N)�contextmanager)�date� timedelta��wraps)�glob)�socket�fromfd�AF_UNIX�SOCK_STREAM)�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 � � t j � | d j d� � }|� d� � r8t d� � r)t j � d|dd� � � }n�|� d� � r�t d � � r�t j � d |dd� � � }t j � t j � |� � � � s1t j t j � |� � � � ndS t j � |� � s�t j � |� � r�t j �
|� � r t � d
d|i�� � dS t j
|� � dS # t $ r7}t � d
|t |� � d��� � Y d}~dS d}~ww xY wdS t j �
|� � r t � dd|i�� � dS t! |d� � 5 }|� � � }ddd� � n# 1 swxY w Y t j |t j t j z t j z t j z d� � } t j ||� � t j |� � dS # t j |� � w xY w# t $ r7}t � d|t |� � d��� � Y d}~dS d}~ww xY w)zd
Copy ini file to cagefs-skeleton
Action takes place for cPanel ea-php only
r zxray.iniz/opt/cpanelz/usr/share/cagefsz"/usr/share/cagefs/.cpanel.multiphpr Nz
/usr/localz/usr/share/cagefs-skeletonz-Refusing to unlink symlink in cagefs-skeleton�xray_ini��extraz'Failed to unlink ini in cagefs-skeleton)r+ �errz0Refusing to copy over symlink in cagefs-skeleton�rbi� z'Failed to copy ini into cagefs-skeleton)�os�path�join�ini_location�
startswithr �exists�dirname�mkdir�lexists�islink�logger�warning�unlink�OSError�str�open�read�O_WRONLY�O_CREAT�O_TRUNC�
O_NOFOLLOW�write�close)�args�original_ini�skeleton_ini�e�src� src_bytes�fds �J/opt/cloudlinux/venv/lib64/python3.11/site-packages/xray/internal/utils.py�updatezskeleton_update.<locals>.updateB sz � �
�w�|�|�D��G�$8�*�E�E���"�"�=�1�1� �d�;N�6O�6O� ��7�<�<�(L�l�[\�[]�[]�N^�_�_�L�L�
�
$�
$�\�
2�
2� �t�<X�7Y�7Y� ��7�<�<�(D�l�ST�SU�SU�FV�W�W�L��7�>�>�"�'�/�/�,�"?�"?�@�@�
8��������6�6�7�7�7���F��w�~�~�l�+�+� ��w���|�,�,�
��7�>�>�,�/�/� ��N�N�#R�[e�gs�Zt�N�u�u�u��F���I�l�+�+�+�+�+��� � � ��N�N�A�Vb�kn�op�kq�kq�Ir�Ir� #� � � � � � � � � ���������
�
�
��7�>�>�,�/�/� ��N�N�#U�^h�jv�]w�N�x�x�x��F� �,��-�-� +�� #���
�
�I�+� +� +� +� +� +� +� +� +� +� +���� +� +� +� +��W�\�2�;���+C�b�j�+P�SU�S`�+`�bg�h�h��!��H�R��+�+�+��H�R�L�L�L�L�L��B�H�R�L�L�L�L������
�
�
����=�R^�gj�kl�gm�gm�En�En� � � � � � � � � � �����
���ss �3G �
H
�,H�H
�=L �L �J �4L � J�L �J�A
L �K>