hjkhjkjhkhjkgjghjhgjhgjghjhghjghjhgjjnbvnvbnvk
bnmbnmbnhjkhjkhjkhjktyutyutyuytutyutyutyhgjgjghjgjghjguytutyry
/
opt
/
alt
/
python37
/
lib
/
python3.7
/
site-packages
/
xray
/
reconfiguration
/
__pycache__
/
Upload FileeE
HOME
B �'Ud7 � @ s� d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlm Z d dl mZ e �d�Z ed�dd �Zd d� Zeed�d d�Zdd�dd�Zdd�dd�Zdd�dd�Zdd�dd�Zdd�dd�Zdd� Zdd� Zdd� ZdS )� N)�iglob)�request_data_storage�local_tasks_storage)�dbm_storage)�Task�reconfiguration)�returnc C s dS )za Return all possible locations of xray.ini files in glob-like form Panel independent )z/opt/alt/php*/link/confz%/var/cagefs/*/*/etc/cl.php.d/alt-php*z"/opt/cpanel/ea-php*/root/etc/php.dz/opt/plesk/php/*/etc/php.dz/usr/local/php*/lib/php.conf.dzD/usr/share/cagefs/.cpanel.multiphp/opt/cpanel/ea-php*/root/etc/php.dz8/usr/share/cagefs-skeleton/usr/local/php*/lib/php.conf.d� r r r �U/opt/alt/python37/lib/python3.7/site-packages/xray/reconfiguration/system_id_shift.py� get_locations s r c C sD yt �| � W n0 tk r> } zt�d| |� W dd}~X Y nX dS )zWrapped unlinkz%s not removed, reason: %sN)�os�unlink�OSError�logger�warning)Z_fpath�er r r �safe_unlink$ s r )�globpathr c c sB x<t | �D ]0}x*t�|�D ]}d|krtj�||�V qW q W dS )zp Find xray.ini files in every directory matching given glob-like path. Return full path to xray.ini zxray.iniN)r r �listdir�path�join)r �conf_dir�namer r r �find_xray_inis, s r c C s: x4t � D ]*} x$t| �D ]}t�d|� t|� qW qW dS )z7 Remove all xray.ini files found in filesystem zRemoving %sN)r r r �infor )�location�xray_inir r r �remove_xray_inis7 s r c C s* x$t d�D ]} t�d| � t| � q W dS )z9 Remove all xray.tasks files found in filesystem z*/usr/share/alt-php-xray-tasks/*/xray.taskszRemoving %sN)r r r r )� tasks_filer r r �remove_xray_tasksA s r c C s@ t t��.} x&| �� D ]}t�d|�� � | |= qW W dQ R X dS )zF Remove all entries from local dbm file with fake_ids mapping z Clear task %sN)r r �keysr r �decode)�task_storage�itemr r r �clear_dbm_fileJ s r$ c C s6 x0t �t�D ]"} t�d| � tt j�t| �� qW dS )z% Remove all request_id files zClear request_id for %sN)r r r r r r r r )r r r r �remove_req_id_filesT s r% c C sj y$t jdddgddd� t�d� W n@ ttt jfk rd } ztjddt| �id � W d d } ~ X Y nX d S )z Restart X Ray Agent z /sbin/servicez xray-agent�restartT)�capture_output�textzX Ray Agent restartedzFailed to restart X-Ray Agent�err)�extraN) � subprocess�runr r r � ValueError�SubprocessError�error�str)r r r r � restart_agent] s r1 c C s6 t �d� t� t� t� t� t� t �d� dS )z! Perform reconfiguration zsystem_id shift: reconfigure...z2reconfiguration for system_id shift case completedN)r r r r r% r$ r1 r r r r �reconfigurel s r2 c C s� t j�t�st�dt� dS tt��} t| �� �}W dQ R X x�t d�D ]�}g }t �|�}x6|�d�D ](}|�d�d }|� � |krd|�|� qdW |r�t�dd�|�|� t j|d�|�dt �|�jd d � qFt�d|� t �|� qFW dS )a$ 1. Get all tasks through /usr/share/alt-php-xray-tasks/*/xray.tasks ncuser.com:/*:*:e754fbfdea1eb6f75247 2. Check that fake_id is present in local storage: /usr/share/alt-php-xray/tasks 3. If it is not -> task is broken/garbage and must be removed z)Local storage %s is absent, nothing to doNz*/usr/share/alt-php-xray-tasks/*/xray.tasks�,�:� zWriting tasks %s to %sr �_ )� target_uid� target_gid�maskz"No real tasks in %s, removing file)r r �existsr r r r �listr r r � read_file�split�encode�appendr � unified_write�stat�st_gid� unified_erase)r"