hjkhjkjhkhjkgjghjhgjhgjghjhghjghjhgjjnbvnvbnvk
bnmbnmbnhjkhjkhjkhjktyutyutyuytutyutyutyhgjgjghjgjghjguytutyry
/
opt
/
alt
/
python37
/
lib
/
python3.7
/
site-packages
/
xray
/
internal
/
__pycache__
/
Upload FileeE
HOME
B �'Ud� � @ s: d Z ddlZddlZddlZddlmZ G dd� d�ZdS )zx This module contains class implementing part of X-Ray Manager related to User Agent management (enable/disable/status) � N� )�XRayManagerErrorc @ s� e Zd ZdZdd� Zedd� �Zdddd�ejd �d d�Z ddd �Z deejd�dd�Zdd �dd�Z dd �dd�Zdd �dd�ZdS )�ManageUserAgentz0 Manager actions related to user plugin c C s* d| _ d| _t�d�| _tttjf| _ d S )Nzxray-user-agentzxray-user-agent.socketZuser_plugin_manager) �service_name�service_socket�logging� getLogger�logger�OSError� ValueError� subprocess�SubprocessError�subprocess_errors)�self� r �K/opt/alt/python37/lib/python3.7/site-packages/xray/internal/user_manager.py�__init__ s zManageUserAgent.__init__c C s t j�d�S )z- Check for systemd available z/bin/systemctl)�os�path�isfiler r r r � is_systemd s zManageUserAgent.is_systemdTF)�capture_output�text�check)�returnc G s y,t j||||d�}| j�dd�|�h� W n� t jk r� } z^| jjd|j|j|j pZ|j |j|j|j |j d�d� td|j� d|j� d |j p�|j � ���W d d }~X Y n` | jk �r } z>| jjdd�|�dt |�id� td d�|�� d|� ���W d d }~X Y nX |S )z< Call subprocess described with given *args )r r r zCommand '%s' succeeded� z-External command '%s' failed with code %s: %s)�cmd�retcode�stdout�stderr)�extrazExternal command 'z' failed with code z: Nz#Failed to run '%s' external command�errzFailed to run 'z' external command: )r �runr �info�join�CalledProcessError�errorr � returncoder r r r �str)r r r r �args�result�er r r � _run_external% s( 4*zManageUserAgent._run_externalc C sH ddd�}| � � r,| �d|| d | j� n| �d| j|| d � dS ) z, Switch autostart ON or OFF )�enable�on)�disable�off)TFz/bin/systemctlr z/sbin/chkconfigr N)r r, r r )r ZswitchZautostart_selectr r r � _autostart? s zManageUserAgent._autostart)�commandr c C s` |r | j n| j}y| jd|||d�S tk rZ } ztd|� d|j� ���W dd}~X Y nX dS )z� Run /sbin/service utility to make given operation with X-Ray User Agent service :command: command to invoke :check_retcode: whether to run with check or not :return: subprocess info about completed process z /sbin/service)r zX-Ray User Agent 'z ' failed: N)r r r, r �reason)r r2 �socket_unit� check_retcodeZsrvr+ r r r �user_agent_serviceP s z"ManageUserAgent.user_agent_servicezjson strc C sT | � � | �d�}|jrB| �� r2| jdddd� qP| jddd� n| jddd� dS )a Enable X-Ray User Agent: start or restart service if it is accidentally already running For systemd systems -- start socket unit only For SysV -- start the entire service :return: JSON encoded result of enable action �status�startT)r4 r5 )r5 �restartN)r1 r6 r'