403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /lib/python3.9/site-packages/tuned/exports/__pycache__/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /lib/python3.9/site-packages/tuned/exports/__pycache__/unix_socket_exporter.cpython-39.pyc
a

,�g��@s�ddlZddlZddlZddlZddlmZddlZddlm	Z	ddl
mZddlZddl
Z
ddlZej��ZGdd�dej�ZdS)�N�)�
interfaces)�ismethodc@s�eZdZdZejejejejej	fdd�Z
dd�Zdd�Zdd	�Z
d
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zd$dd�Zd%dd�Zdd�Zdd�Zd d!�Zd"d#�ZdS)&�UnixSocketExportera9
	Export method calls through Unix Domain Socket Interface.

	We take a method to be exported and create a simple wrapper function
	to call it. This is required as we need the original function to be
	bound to the original object instance. While the wrapper will be bound
	to an object we dynamically construct.
	cCs�||_d|_||_g|_ddg|_|r�|��}t|dd��D]�\}}zt|�|j|<Wq>ty�z2|dkr�t	�
|�j|j|<nt�
|�j|j|<Wn0ty�t�d|dkr�dnd|f�Yn0Yq>0q>||_||_i|_t�|_d|_d|_dS)N����rz(%s '%s' does not exists, leaving defaultZUserZGroup)�_socket_path�_socket_object�_socket_signal_pathsZ_socket_signal_objects�
_ownership�split�	enumerate�int�
ValueError�pwd�getpwnam�pw_uid�grp�getgrnam�gr_gid�KeyError�log�error�_permissions�_connections_backlog�_unix_socket_methods�set�_signalsZ_connZ_channel)�selfZsocket_pathZsignal_pathsZ	ownershipZpermissionsZconnections_backlog�i�o�r!�F/usr/lib/python3.9/site-packages/tuned/exports/unix_socket_exporter.py�__init__s.
,zUnixSocketExporter.__init__cCs
|jduS�N)r	�rr!r!r"�running;szUnixSocketExporter.runningcsTt��std���j}||jvr,td|��G�fdd�dt�}|||�|j|<dS)N�#Only bound methods can be exported.�/Method with this name (%s) is already exported.cs eZdZdd�Z�fdd�ZdS)z*UnixSocketExporter.export.<locals>.wrappercSs||_||_dSr$)Z
_in_signature�_out_signature)r�in_signature�
out_signaturer!r!r"r#Gsz3UnixSocketExporter.export.<locals>.wrapper.__init__cs�|i|��Sr$r!�r�args�kwargs��methodr!r"�__call__Ksz3UnixSocketExporter.export.<locals>.wrapper.__call__N��__name__�
__module__�__qualname__r#r1r!r/r!r"�wrapperFsr6)r�	Exceptionr3r�object)rr0r*r+�method_namer6r!r/r"�export>s
zUnixSocketExporter.exportcs^t��std���j}||jvr,td|��G�fdd�dt�}||�|j|<|j�|�dS)Nr'r(cs eZdZdd�Z�fdd�ZdS)z*UnixSocketExporter.signal.<locals>.wrappercSs
||_dSr$)r))rr+r!r!r"r#Ysz3UnixSocketExporter.signal.<locals>.wrapper.__init__cs�|i|��Sr$r!r,r/r!r"r1\sz3UnixSocketExporter.signal.<locals>.wrapper.__call__Nr2r!r/r!r"r6Xsr6)rr7r3rr8r�add)rr0r+r9r6r!r/r"�signalPs
zUnixSocketExporter.signalcOs�||jvrtd|��|jD]�}t�d|�zDt�tjtj�}|�d�|�	|�|�
|d||d��|��Wqty�}z t�
d|||f�WYd}~qd}~00qdS)NzSignal '%s' doesn't exist.zSending signal on socket %sF�2.0)�jsonrpcr0�paramsz2Error while sending signal '%s' to socket '%s': %s)rr7r
r�debug�socket�AF_UNIX�SOCK_STREAMZsetblockingZconnect�
_send_data�close�OSError�warning)rr<r-r.�p�s�er!r!r"�send_signalbs



zUnixSocketExporter.send_signalcCs|j�|�dSr$)r
�append)r�pathr!r!r"�register_signal_pathpsz'UnixSocketExporter.register_signal_pathcCs�|jr�tj�|j�r t�|j�t�tjtj�|_|j�	|j�|j�
|j�t�|j|j
d|j
d�|jr�t�|j|j�dS)Nrr)r�osrM�exists�unlinkrArBrCr	ZbindZlistenr�chownrr�chmodr%r!r!r"�_construct_socket_objectssz+UnixSocketExporter._construct_socket_objectcCs |��rdS|��|��dSr$)r&�stoprTr%r!r!r"�start~szUnixSocketExporter.startcCs|jr|j��dSr$)r	rEr%r!r!r"rU�szUnixSocketExporter.stopc
Csdt�d|�z|�t�|��d��Wn6ty^}zt�d||f�WYd}~n
d}~00dS)NzSending socket data: %s)zutf-8zFailed to send data '%s': %s)rr@�send�json�dumps�encoder7rG)rrI�datarJr!r!r"rD�s
zUnixSocketExporter._send_dataFcCs$d|d�}|r||d<n||d<|S)Nr=)r>�idr�resultr!)rr[r\r�resr!r!r"�_create_response�s�
z#UnixSocketExporter._create_responseNcCs|j|||d�d|d�S)N)�code�messager[T)rr\�r_)rr`rar\r[r!r!r"�_create_error_responce�s��z)UnixSocketExporter._create_error_responcecCs|�||�Sr$rb)rr]r\r!r!r"�_create_result_response�sz*UnixSocketExporter._create_result_responsecCs|�d�r|SdS)Nr\)�get)rr[r!r!r"�	_check_id�s
zUnixSocketExporter._check_idcCs�t|�tks$|�d�dks$|�d�s0|�dd�S|�d�}d}|d|jvr`|�|�dd|��Sz�|�d	�s~|j|d�}npt|d	�ttfvr�|j|d|d	�}nDt|d	�tkr�|j|dfi|d	��}n|�|�dd|��WSWn~t�y0}z&|�|�d
d|t	|���WYd}~Sd}~0t
�yn}z&|�|�dd
|t	|���WYd}~Sd}~00|�|�||��S)Nr>r=r0騀���Invalid Requestr\i����zMethod not foundr?i����zInvalid paramsr�Error)�type�dictrercrrf�list�tuple�	TypeError�strr7rd)r�reqr\�retrJr!r!r"�_process_request�s&$

.0z#UnixSocketExporter._process_requestc	Cs�|��sdSt�|jgddd�\}}}|�r�|j��\}}z&d}|�d���}|sTq^||7}q@Wn>ty�}z&t�d|�WYd}~qWYd}~n
d}~00|�r�zt	�
|�}Wn^t�y}zDt�d||f�|�||�dd	t
|���WYd}~qWYd}~n
d}~00t|�tttfv�rNt�d
�|�||�dd	t
|���qt|�ttfv�r�t|�dk�r�|�||�ddt
|���qg}|D] }|�|�}|�r�|�|��q�|�r�|�||�n|�|�}|�r�|�||�qdSqdS)
a�
		Periodically checks socket object for new calls. This allows to function without special thread.
		Interface is according JSON-RPC 2.0 Specification (see https://www.jsonrpc.org/specification)
		
		Example calls:
		
		printf '[{"jsonrpc": "2.0", "method": "active_profile", "id": 1}, {"jsonrpc": "2.0", "method": "profiles", "id": 2}]' | nc -U /run/tuned/tuned.sock
		printf '{"jsonrpc": "2.0", "method": "switch_profile", "params": {"profile_name": "balanced"}, "id": 1}' | nc -U /run/tuned/tuned.sock
		Nr!r�iz"Failed to load data of message: %sz!Failed to load json data '%s': %siD���zParse errorzWrong format of callrgrh)r&�selectr	ZacceptZrecv�decoder7rrrX�loadsrDrcrorjrmrlrk�lenrrrL)	r�r�_Zconnr[Zrec_datarJr^rpr!r!r"�period_check�sP
""


zUnixSocketExporter.period_check)F)NN)r3r4r5�__doc__�constsZCFG_DEF_UNIX_SOCKET_PATHZ CFG_DEF_UNIX_SOCKET_SIGNAL_PATHSZCFG_DEF_UNIX_SOCKET_OWNERSHIPZCFG_DEF_UNIX_SOCKET_PERMISIONSZ'CFG_DEF_UNIX_SOCKET_CONNECTIONS_BACKLOGr#r&r:r<rKrNrTrVrUrDr_rcrdrfrrrzr!r!r!r"rs,	�
"

r)rO�rerrrsrZ
tuned.logsZtunedZtuned.constsr|�inspectrrArXrtZlogsrerZExporterInterfacerr!r!r!r"�<module>s


Youez - 2016 - github.com/yon3zu
LinuXploit