fjddlZddlZddlZddlmZddlmZmZmZm Z ddl m Z ddl m Z ejdZdefdZd Zd edefd Zdd Zdd ZddZddZddZdZdZdZdS)N)iglob)request_data_storagelocal_tasks_storagepart_delimitertask_delimiter) dbm_storage)TaskreconfigurationreturncdS)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.dr [/opt/cloudlinux/venv/lib64/python3.11/site-packages/xray/reconfiguration/system_id_shift.py get_locationsrs   rc tj|dS#t$r'}td||Yd}~dSd}~wwxYw)zWrapped unlinkz%s not removed, reason: %sN)osunlinkOSErrorloggerwarning)_fpathes r safe_unlinkr$sj@ & @@@3VQ?????????@s A AA globpathc#Kt|D]?}tj|D](}d|vr"tj||V)@dS)zp Find xray.ini files in every directory matching given glob-like path. Return full path to xray.ini zxray.iniN)rrlistdirpathjoin)rconf_dirnames rfind_xray_inisr!,sm (OO33Jx(( 3 3DT!!gll8T22222 333rctD]>}t|D],}td|t |-?dS)z7 Remove all xray.ini files found in filesystem Removing %sN)rr!rinfor)locationxray_inis rremove_xray_inisr'7sb"OO""&x00 " "H KK x 0 0 0  ! ! ! ! """rc~tdD],}td|t|-dS)z9 Remove all xray.tasks files found in filesystem */usr/share/alt-php-xray-tasks/*/xray.tasksr#N)rrr$r) tasks_files rremove_xray_tasksr+AsKHII   M:...J  rctt5}|D]2}td|||=3 ddddS#1swxYwYdS)zF Remove all entries from local dbm file with fake_ids mapping z Clear task %sN)rrkeysrr$decode) task_storageitems rclear_dbm_filer1Js ( ) )#\ %%'' # #D KK 7 7 7T"" ###################sAA++A/2A/ctjtD]O}td|t tjt|PdS)z% Remove all request_id files zClear request_id for %sN)rrrrr$rrr)r s rremove_req_id_filesr3Ts_ /00>> -t444BGLL!5t<<====>>rc tjgdddtddS#tt tjf$r6}tddt|iYd}~dSd}~wwxYw) z Restart X Ray Agent )z /sbin/servicez xray-agentrestartT)capture_outputtextzX Ray Agent restartedzFailed to restart X-Ray Agenterr)extraN) subprocessrunrr$r ValueErrorSubprocessErrorerrorstr)rs r restart_agentr@]s,###'+ 7 7 7 7  +,,,,, Z!; <,,, 4!3q66?  , , , , , , , , ,,s37B +BB ctdttt t t tddS)zv Perform reconfiguration. Only callable from CLI entry point (run_manager.py), not from socket handlers. zsystem_id shift: reconfigure...z2reconfiguration for system_id shift case completedN)rr$r'r+r3r1r@r rr reconfigurerBlsi  KK1222OOO KKDEEEEErc dtjts"tdtdSt t5}t|}dddn #1swxYwYtdD] }g}tj |}|D]M}| td}||vr||N|rqtdt!j||tj|t!j|dtj|jdtd |tj| 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 doNr)zWriting tasks %s to %sr_) target_uid target_gidmaskz"No real tasks in %s, removing file)rrexistsrrr$rlistr-rr read_tasks_filersplitrencodeappendrr unified_writestatst_gid unified_erase)r/fake_tasks_ids task_file alive_taskstaskstaskfake_ids r_clean_garbage_tasksrY{s 7>>- . . ?ATUUU ( ) )3\l//1122333333333333333GHH**  $Y// ) )Dkk.11!4G~~>11""4(((  * KK0.2Ek2R2RT] ^ ^ ^  y.*=k*J*JWX*,')*<*<*C% Q Q Q Q Q KKres mmmmmmmmmmmm++++++$$$$$$  , - - u     @@@3S3S3333""""    ####>>>> , , , , F F F***<FFFFFr