https://t.me/AnonymousX5
Server : Apache
System : Linux cvar2.toservers.com 3.10.0-962.3.2.lve1.5.73.el7.x86_64 #1 SMP Wed Aug 24 21:31:23 UTC 2022 x86_64
User : njnconst ( 1116)
PHP Version : 8.4.18
Disable Function : NONE
Directory :  /opt/alt/python37/lib/python3.7/site-packages/ssa/internal/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/alt/python37/lib/python3.7/site-packages/ssa/internal/__pycache__/utils.cpython-37.pyc
B

��c�6�@s�dZddlZddlZddlZddlZddlZddlZddlmm	Z
ddlmZddl
mZddlmZmZddlmZddlmZmZmZmZmZmZmZddlmZmZdd	lmZddlZdd
l m!Z!ddl"m#Z#ddl$m%Z%dd
l&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-e�.d�Z/edddg�Z0e1e0d�dd�Z2dd�dd�Z3dSe1e4e1d�dd�Z5e1e1d �d!d"�Z6e1d#d$�d%d&�Z7e1d�d'd(�Z8dTe1e1d*�d+d,�Z9e1d�d-d.�Z:e;e<d/�d0d1�Z=e1ee1d2�d3d4�Z>ee1d�d5d6�Z?ee1d�d7d8�Z@e4d�d9d:�ZAe4d�d;d<�ZBe4d�d=d>�ZCe4dd?�d@dA�ZDe4d�dBdC�ZEe1d�dDdE�ZFe1ee1efe4dF�dGdH�ZGedUe;ddI�dJdK��ZHedVe;e;e;ddN�dOdP��ZIdMZJdQdR�ZKdS)Wz>
This module contains helpful utility functions for SSA Agent
�N)�
namedtuple)�contextmanager)�date�	timedelta)�LooseVersion)�socket�fromfd�AF_UNIX�SOCK_STREAM�AF_INET�AF_INET6�
SOCK_DGRAM)�Optional�Union)�urlparse)�AtexitIntegration)�LoggingIntegration)�Feature)�is_panel_feature_supported)�get_kmodlve_module_version�)�
sentry_dsn)�SSAErrorZutils�URLZdomain_nameZuri_path)�url�returncCsJt|�}|jrd|j��nd}|jr2|j�|��nd}t|j�dd�|�S)z�
    Split URL into domain_name and uripath including query string
    :param url: URL of format protocol://domain/path;parameters?query#fragment
    :return: namedtuple URL(domain_name, uripath)
    �?��/zwww.)rZquery�pathrZnetloc�replace)rZ	fragmentsZqsZuri�r!�C/opt/alt/python37/lib/python3.7/site-packages/ssa/internal/utils.py�	url_split,sr#)rc	s�tttd�dd�}dd���fdd�}dd	�d
d�}ttjtjd�}t|d
�}tjt|d||gd�t�	��}d|�i|_
WdQRXdS)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�hintrcSs|d�ddi�|S)z�
        Add extra data into sentry event
        :param event: original event
        :param hint: additional data caught
        :return: updated event
        �extrazssa.versionz	0.3-4.el7)�update)r$r%r!r!r"�add_infoEszsentry_init.<locals>.add_infoc	SsTy0t|t��}|�|df�|��dSQRXWntk
rNt�d�YnXdS)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::
        rrNzCannot retrieve IP address)rr
�connectZgetsockname�	Exception�logger�info)Zaddress_familyZ
private_ip�sr!r!r"�
try_get_ipOszsentry_init.<locals>.try_get_ipcs8tdftdff}x"|D]\}}�||�}|r|SqWdS)zq
        We are trying to get an IPv4 or IPv6 address.
        In case of failure we'll return 127.0.0.1
        z10.255.255.255zfc00::z	127.0.0.1)rr)Z
ipversionsZaddr_famZpriv_ipZip)r.r!r"�get_ip^s
zsentry_init.<locals>.get_ipN)rcSsdS)Nr!)�pending�timeoutr!r!r"�nopej�zsentry_init.<locals>.nope)�levelZevent_level)�callbackzalt-php-ssa@0.3-4.el7)ZdsnZbefore_send�releaseZintegrationsZ
ip_address)�dictr�logging�INFO�WARNINGr�
sentry_sdkZinitr�configure_scope�user)r(r/r2Zsentry_loggingZ
silent_atexit�scoper!)r.r"�sentry_init9s



r?F)�fname�as_errorrc
Cs�y>tj|tjddd�yt�|d�Wntk
r:YnX|Stk
r~}z"t�|r^tj	ntjdt
|��Wdd}~XYnXdS)zz
    Try to configure logging into given fname
    If as_error True, log the exception as ERROR, otherwise -- as INFO
    z%(asctime)s %(message)sz%m/%d/%Y %I:%M:%S %p)�filenamer4�format�datefmti�z$No logging configuration applied: %sN)r8�basicConfigr9�os�chmod�PermissionError�OSErrorr+�log�ERROR�str)r@rA�er!r!r"�set_logging_into_filevs
rN)�lognamerc
Cslt�t|�dkrhyt�tj�|��Wn2tk
rZ}zt�dt	|��dSd}~XYnXt|dd�}|S)zP
    Configure logging
    :param logname: path to log
    :return: logpath
    NzFailed to create logdir %srT)rA)
r?rNrF�makedirsr�dirnamer*r+�warningrL)rOrMr!r!r"�configure_logging�srSz
socket object)�
sock_locationrc	Cs`ttj�dd��}|dkrHt�� tt�}|�|�|��WdQRXnt	dtt
�}|��|S)z�
    Create world-writable socket in given sock_location
    or reuse existing one
    :param sock_location: socket address
    :return: socket object
    �
LISTEN_FDSrN�)�intrF�environ�get�umask_0rr	Zbind�listenrr
)rTrUZsockobjr!r!r"�
create_socket�s
r\cCst��tdd�}|�d�S)zC
    Returns date of previous day in a format "day.month.year"
    r)Zdaysz%d.%m.%Y)rZtodayr�strftime)Z	yesterdayr!r!r"�previous_day_date�sr^�%d.%m.%Y)�datestrrcCstj�||�}|�d�S)z+
    Convert date to format YYYY-mm-dd
    z%Y-%m-%d)�datetime�strptimer])r`Z	formatstrZ_dater!r!r"�format_date�srcc
Cs�yHt�d�}|��}|�d�j}t���}|�d|�WdQRX|�d�St	tj
fk
r�}zt�dt
|��Wdd}~XYnXdS)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/stringZ	system_idNzID-z Failed to retrieve system_id: %s)�ET�parseZgetroot�find�textr;r<Zset_tag�lstriprIZ
ParseErrorr+rRrL)Ztree�rootZwhole_idr>rMr!r!r"�read_sys_id�s


rj)�durationrcCstt|dd��S)zQ
    Cast duration from microseconds to seconds leaving 2 digits after point
    i@Bz0.2f)�floatrC)rkr!r!r"�
duration_cast�srm)�filepathrc	CsVy$t|��}|����}WdQRXWntk
r8dSXd�|�d�dd��pTdS)zDGet version of package from file. alt-php-ssa/alt-php-xray supportedN�.�z0.0-0)�open�read�striprI�join�split)rnZv_file�versionr!r!r"�pkg_version�s
rwcCstd�S)z"Get version of alt-php-ssa packagez/usr/share/clos_ssa/version)rwr!r!r!r"�ssa_version�srxcCstd�S)z#Get version of alt-php-xray packagez/usr/share/alt-php-xray/version)rwr!r!r!r"�xray_version�sryc	Cs@t�}|dkrdSyt|�td�kSttfk
r:dSXdS)zb
    Check version of alt-php-xray package.
    Autotracing in X-Ray is supported since 0.4-1
    NFz0.4-1)ryr�	TypeError�AttributeError)Zversion_numberr!r!r"�is_xray_version_supported�sr|c
CsFd}ttt��.}y|�|�Wnttfk
r6dSXWdQRXdS)z Check if User Agent is listeningz$/opt/alt/php-xray/run/xray-user.sockFNT)rr	r
r)�ConnectionErrorrI)Zuser_agent_sockr-r!r!r"�is_xray_user_agent_active�sr~c	CsXd}tj�|�sdSy(t�|d��}t|���dkSQRXWntjk
rRdSXdS)z@Check if there are no active X-Ray tasks (== empty task storage)z/usr/share/alt-php-xray/tasksT�crNF)rFr�isfile�dbmrq�len�keys�error)Zxray_tasks_storageZ
xray_tasksr!r!r"�no_xray_active_taskssr�)�enabledrc
Cs�ttj�sdSt�d|�y:tdddd��"}|�|r8dnd�t�d	�WdQRXWn4tk
r�}zt�d
|t|��Wdd}~XYnXdS)zb
    Switch on/off throttle statistics gathering by kmodlve
    :param enabled: True or False
    NzSwitching schedstats: %sz!/proc/sys/kernel/sched_schedstats�wbr)�mode�	buffering�1�0zDone OKz(Failed to set sched_schedstats to %s: %s)	rrZLVEr+r,rq�writerIrL)r��frMr!r!r"�switch_schedstatss

r�cCs0td�}td�}t�}|r$t||�Stt�|�S)z�
    Check kmodlve module version or kernel version in order to determine
    if it provides the detection of IO throttling
    z2.0-23z1.5.58)rr�compare_versions_ge�extract_kernel_version)Zkmod_min_versionZkernel_min_versionZkmod_currentr!r!r"�$is_io_throttling_detection_available(s
r�cCs@t�d�}t��}y|�|��d�}Wntk
r:dSX|S)zO
    Get kernel version in the form of "major-minor" from current platform
    zlve([.0-9]*).elrz0.0.0)�re�compile�platformr6�search�groupr{)�patternr6Zversion_numr!r!r"r�5s
r�)�
first_version�second_versionrc
CsJyt|�|kStk
rD}ztd|�d|�d���Wdd}~XYnXdS)zE
    Comparing two versions using the greater or equal operator.
    zAUnable to compare required versions: unexpected versions format "z" and "�"N)rrzr)r�r�rMr!r!r"r�Bs
r�)�maskrccst�|�}dVt�|�dS)z,
    Context manager for dropping umask
    N)rF�umask)r��prevr!r!r"rZOs
rZroT)�
target_uid�
target_gidr�rc	csdt��}t��}yt�|�}Wntk
r6d}YnX|dkrT|dkrN|}n|j}|dkrp|dkrj|}n|j}|dk	r�t�|�}||kr�t�|�t	�
d|�|r�t��|kr�td��||k�rt�
|�t	�
d|�|�rt��|k�r||kr�t�|�td��dV||k�r,t�
|�t	�
d|�||k�rLt�|�t	�
d|�|dk	�r`t�|�dS)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
    NzDropped GID privs to %sz6Unable to execute required operation: permission issuezDropped UID privs to %szRestored UID privs to %szRestored GID privs to %s)rF�getuid�getgid�statrI�st_uid�st_gidr��setegidr+�debug�getegidr�seteuid�geteuid)	r�r�Ztarget_pathr�Z
with_checkZprev_uidZprev_gid�	stat_infor�r!r!r"�set_privilegesYsN










r�cCsGdd�d�}||�S)Nc@s eZdZdZdd�Zdd�ZdS)zsingleton.<locals>.__Singletonzm
        A singleton wrapper class. Its instances would be created
        for each decorated class.
        cSs||_d|_dS)N)�_wrapped�	_instance)�self�_clsr!r!r"�__init__�sz'singleton.<locals>.__Singleton.__init__c_s"|jdksts|j||�|_|jS)z,Returns a single instance of decorated classN)r��IS_SINGLETON_ENABLEDr�)r��args�kwargsr!r!r"�__call__�sz'singleton.<locals>.__Singleton.__call__N)�__name__�
__module__�__qualname__�__doc__r�r�r!r!r!r"�__Singleton�sr�r!)Zsome_clsr�r!r!r"�	singleton�sr�)F)r_)r)NNroNT)Lr�rar�r8rFr�r�Zxml.etree.ElementTreeZetreeZElementTreerd�collectionsr�
contextlibrrrZdistutils.versionrrrr	r
rrr
�typingrrZurllib.parserr;Zsentry_sdk.integrations.atexitrZsentry_sdk.integrations.loggingrZclcommon.constrZclcommon.cpapirZclcommon.utilsr�	constantsr�
exceptionsr�	getLoggerr+rrLr#r?�boolrNrSr\r^rcrjrWrlrmrwrxryr|r~r�r�r�r�r�rZr�r�r�r!r!r!r"�<module>
sd$

=


	F

https://t.me/AnonymousX5 - 2025