HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/plogical/__pycache__/processUtilities.cpython-310.pyc
o

��h~Y�@sbddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZGdd�dej�Z
dS)�)�CyberCPLogFileWriterNc@s6eZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZdZdZd	Zd
d�Zdd
�Zedd��Zedd��Zedd��Zedd��Zed4dd��Zedd��Zedd��Zedd��Zed d!��Zed"d#��Zed5d$d%��Zed6d&d'��Z ed7d(d)��Z!d*d+�Z"ed8d,d-��Z#ed.d/��Z$ed0d1��Z%ed2d3��Z&dS)9�ProcessUtilitiesz/usr/local/CyberCP/debug�	litespeed�r��z /usr/local/lscpd/admin/comm.sock�unsetz/usr/local/lscp/conf/bind.confcCstj�|�||_||_dS�N)�multi�Thread�__init__�function�	extraArgs)�selfr
r�r�//usr/local/CyberCP/plogical/processUtilities.pyrs
zProcessUtilities.__init__c
CsXz|jdkr
|��WdSWdSty+}zt�t|�d�WYd}~dSd}~ww)N�popenz [ApplicationInstaller.run])r
�
customPoen�
BaseException�logging�writeToFile�str)r�msgrrr�run!s
� ��zProcessUtilities.runcCs:dtj}t�|�}|�d�dkr|�d�d�d�SdS)Nzcat %s�*����:r�
�8090)r�portPath�outputExecutioner�find�split�rstrip)�command�portrrr�fetchCurrentPort(s


z!ProcessUtilities.fetchCurrentPortc
Cs�g}zddl}|��D]}|���tj�dkr|�|j�qWnty;}zt	�
t|�d�WYd}~dSd}~wwt|�dkrD|SdS)Nrrz [getLitespeedProcessNumber])
�psutil�process_iter�namer!r�litespeedProcess�append�pidrrrr�len)�finalListOfProcessesr'�procrrrr�getLitespeedProcessNumber2s$��
���z*ProcessUtilities.getLitespeedProcessNumberc
C�|z t��tjkrd}nd}t�|�}t�|�}|dkrWdSWdStjy=}zt�	t
|�d�WYd}~dSd}~ww)Nzsystemctl restart lswsz$/usr/local/lsws/bin/lswsctrl restartrrz[restartLitespeed]�r�decideServer�OLS�shlexr"�
subprocess�call�CalledProcessErrorrrr�r$�cmd�resrrrr�restartLitespeedF�

 ��z!ProcessUtilities.restartLitespeedc
Cr1)N�systemctl stop lswsz!/usr/local/lsws/bin/lswsctrl stoprrz[stopLitespeed]r2r9rrr�
stopLitespeedYr=zProcessUtilities.stopLitespeedFNc
CsNznttjd�}|dkr%|dkrtjt�|�||d�}n8tj||||d�}n.|�d�dkr-n
|�d�dkr:d||f}|dkrJtjt�|�||d�}n	tj||||d�}tj�	t
j�ret�
|�d	|�d
��|dkrlWdSWdStjy�}zt�
d
t|��WYd}~dSd}~wty�}zt�
dt|��WYd}~dSd}~ww)N�wF)�stdout�stderr)�shellrArB�exportr�sudoz
sudo -u %s %s�
 [Exit Code: �]rrz(%s. [ProcessUtilities.normalExecutioner]z-%s. [ProcessUtilities.normalExecutioner.Base])�open�os�devnullr6r7r5r"r!�path�existsr�	debugPathrrr8rr)r$rC�User�fr;rrrr�normalExecutionerls6���z"ProcessUtilities.normalExecutionercCsbz	d}t�|�WnYt��}|dkr-|D]}z
dt|�}t�|�WqYqdSdS)Nr>rz
sudo kill -9 )rrPr0r)r$�pids�itemsrrr�
killLiteSpeed�s�zProcessUtilities.killLiteSpeedcCstj�d�r	tjStjS)Nz!/usr/local/lsws/bin/openlitespeed)rIrKrLrr4�entrrrrr3�szProcessUtilities.decideServercs\d}d}tj�d�rgtdd��P}|���d�vrXd�vr/dt_dt_dt_tj	Wd�Sd�vr@dt_tj	Wd�Sd	�vrNtj	Wd�Stj
Wd�SWd�n1sbwYtj�|�r�t|d��1}|���t�fd
d�dD��r�t�fd
d�dD��r�dt_tjWd�SWd�tj
S1s�wYtj
S)Nz/etc/lsb-releasez/etc/redhat-releasez/etc/os-release�r�Ubuntuz24.04rz22.04z20.04c3��|]}|�vVqdSr	r��.0�x��contentrr�	<genexpr>���z0ProcessUtilities.decideDistro.<locals>.<genexpr>)zCentOS Linux release 8zAlmaLinux release 8zRocky Linux release 8�Rocky Linux release 9�AlmaLinux release 9zCloudLinux release 9zCloudLinux release 8c3rWr	rrXr[rrr]�r^)r`r_)
rIrKrLrH�readr�
ubuntu22Check�
ubuntu24Check�
alma9check�ubuntu20�ubuntu�any�cent8)�
distroPath�distroPathAlmarOrr[r�decideDistro�sH�	�����
�
�
zProcessUtilities.decideDistrocCs>zd}t�|�}|�d�dkrWdSWdStyYdSw)Nzcat /etc/cgrules.confzNo suchrrr)rr r!r)r$�outputrrr�containerCheck�s
�zProcessUtilities.containerCheckc
Cs�d}	zt�tjtj�}|�tj�|dgWStyW}z5|dkr3t�d�dt	|�gWYd}~S|d}t�dt	|�dt	|�d	�t
�d
�WYd}~nd}~wwq)Nrr�NonerzcFailed to connect to LSCPD socket, run 'systemctl restart lscpd' on command line to fix this issue.rz.Failed to connect to LSCPD UDS, error message:z
. Attempt z>, we will attempt again in 2 seconds. [setupUDSConnection:138]r)�socket�AF_UNIX�SOCK_STREAM�connectr�server_addressrrrr�time�sleep)�count�sockrrrr�setupUDSConnection�s 

"���z#ProcessUtilities.setupUDSConnectioncCs�d}d}d}||kr�zst��}|ddkr||d7}|d}||krkt�d|�d|�d��t�d�|dkrit�d	�ztjgd
�ddd�t�d
�Wntyh}zt�dt	|����WYd}~nd}~wwWqt�d|���d|�d|��WSWn?ty�}z3|d7}t	|�}||kr�t�d|�d|�d|���t�d�WYd}~qd|�d|��WYd}~Sd}~ww�zj|dur�WdS|d}tj
dkr�tj�
d�t_
tjd=|dk�r |�d�dkr�n|�d�dkr�d|}tj�tj�r�t�|�|dk�r|�tj
|�d��nJdtj
||f}|�|�d��n9|�d��r-|�ddd�}|dk�r;dtj
||f}n	dtj
|||f}tj�tj��rQt�|�|�|�d��d }		|�d!�}
t|
�dk�sm|
dk�rnn|	|
7}	�q\z	|	jdd"d#�}Wnt�y�}zt�d$t	|��d}WYd}~nd}~ww|��tj�tj��r&t|�dk�r�t�d%�|WSzO|d}
t�d&t|��d't|
����t|
t	��r�t|
�}nd(}|�tj
d��|�r�d)|ndd��|�r�d*|ndd���}t�d+|�d,|�d-��W|WSt�y%}zt�d.t	|����WYd}~|WSd}~ww|WSt�yJ}zt�t	|�d/�d0t	|�WYd}~Sd}~ww)1a
        Send command to lscpd with retry mechanism
        
        :param command: Command to execute
        :param user: User to run command as
        :param dir: Directory to run command in
        :param retries: Number of retry attempts if connection fails
        rNrrz)[sendCommand] Connection failed, attempt �/z. Retrying in 2 seconds...rz4[sendCommand] Attempting to restart lscpd service...)�	systemctl�restart�lscpdT)�capture_output�textrz'[sendCommand] Failed to restart lscpd: z:[sendCommand] All connection attempts failed. Last error: z-1Connection failed after z attempts: z([sendCommand] Unexpected error, attempt z: z-1Error after z+-1Internal error: connection result is Noner�TOKENrDrEzsudo %s�utf-8z
%s-d %s %s�z
%s-u %s %sz%s-u %s -d %s %s�� �replace)�errorsz8Some data could not be decoded to str, error message: %su$    └─ Empty response from lscpdu    └─ Response length: z
, last char: �unknownz-u %s z-d %s u    └─ rFrGu$    └─ Failed to log exit code: z [hey:sendCommand]�0)rrxrrrtrur6r�	Exceptionr�tokenrI�environ�getr!rKrLrM�sendall�encode�
startswithr��recvr-�decoder�close�repr�
isinstance�ord�strip)r$�user�dir�retries�attempt�
last_error�ret�erw�raw_data�currentData�datar�	exit_char�	exit_code�
clean_commandrrr�sendCommand�s�


 ��
��







���
�
>�����zProcessUtilities.sendCommandc
Cs�z�tj�tj�rt�d|�d|�d|���t��dkr2tj�tj�r(t�d�t�	|||�WdStj�tj�r>t�d�t�
||�}|rLt|�dkrVt�d	|�WdSzH|d
}t|t
�ret|�}nt|t�rwt|�dkrt|dnd}n
tt�|��d��}tj�tj�r�t�d|�d
|���|dkr�WWdSWWdSty�}zt�dt
|��d
|���WYd}~WdSd}~wwty�}zt�t
|�d�WYd}~dSd}~ww)Nz#[executioner] Called with command: z, user: z	, shell: �rootz6[executioner] Running as root, using normalExecutionerrz3[executioner] Not root, using sendCommand via lscpdrz)Empty response from lscpd for command: %sr�hexzExit code from lscpd: � for command: zFailed to parse exit code: z [executioner])rIrKrLrrMrr�getpass�getuserrPr�r-r�rr��bytes�int�codecsr�r�r)r$r�rCr��exitCoder�rrrr�executionertsH




����zProcessUtilities.executionerc
Cs�zlt��dkr�tj�tj�rt�|�|dkr%|�	d�s%d|�d|��}tj
��}d|d<d|d<d|d	<|dks>|d
krMtj
|d
tjtj|ddd�}ntj
t�|�tjtj|ddd
�}|r�|��\}}|j}	tj�tj�rxt�d|	�d��|	dkr�d|fWSd|fWS|��d}|j}	tj�tj�r�t�d|	�d��|WSt|�tkr�d�|�}|�rbt�||�}
|
r�t|
�dkr�t�d|�WdSzg|
d}tj�tj�r�t�dt|����t|t�r�t|�}nt|t�r�t|�dkr�|dnd}n
tt� |� �d��}tj�tj��rt�d|�d|���|dk�r&d|
dd�fWWSd|
dd�fWWSt!�ya}z%t�dt|��d|���dt|
�dk�rS|
dd�ndfWYd}~WSd}~wwt�|||�dd�WSt"�y�}
zt�t|
�d�WYd}
~
dSd}
~
ww)Nr�rEzsudo -u � zC.UTF-8�LC_ALL�LANGr��PYTHONIOENCODINGTr�)rCrArB�env�encodingr�)rArBr�r�r�u    └─ [Exit Code: rGrrz>Empty response from lscpd in outputExecutioner for command: %s)rr�rz.Raw exit code character in outputExecutioner: r�z'Parsed exit code in outputExecutioner: r�z0Failed to parse exit code in outputExecutioner: r�z[outputExecutioner:188])#r�r�rIrKrLrrMrrr�r��copyr6�Popen�PIPE�STDOUTr5r"�communicate�
returncode�type�list�joinr�r-r�r�rr�r�r�r�r�r�r)r$r�rCr��retRequiredr��prl�_r�r�r�r�rrrrr �st


 






0�� ��z"ProcessUtilities.outputExecutionerc
Cs�z<t|jd�tkst|jd�tkr|jd}nd�|jd�}t��dkr1tj|dd�WdSt	�
||jd�WdStyX}zt�
t|�d�WYd}~dSd}~ww)	Nr$r�r�T)rCr�rz
 [customPoen])r�rrr�r�r�r�r6r7rr�rrr)rr$rrrrr�s$� ��zProcessUtilities.customPoenc
Csfzi}||d<||d<td|�}|��WdSty2}zt�t|�d�WYd}~dSd}~ww)Nr$r�rz [popenExecutioner])r�startrrrr)r$r�r�purrrr�popenExecutioners
 ��z!ProcessUtilities.popenExecutionercCs2d||f}|��D]\}}|d||f}q
|S)Nz$/usr/local/CyberCP/bin/python %s %s z --%s %s)rR)rK�functionName�
parameters�execPath�key�valuerrr�BuildCommandszProcessUtilities.BuildCommandc
Cs�ddl}d}z7|�|�}|jdkr5|��}|D]}|�d�dkr1d|�d�vr1|�d�}|WSqWdStd	|j�WdStyU}ztd
|�WYd}~dSd}~ww)Nrz1https://api.github.com/repos/nodejs/node/releases���
prereleaseF�LTSr)�tag_namez&Failed to fetch releases. Status code:�An error occurred:)�requestsr��status_code�json�printr�)r��url�response�releases�release�lts_versionr�rrr�!fetch_latest_lts_version_for_nodes(



������z2ProcessUtilities.fetch_latest_lts_version_for_nodec
Cs�ddl}d}z(|�|�}|jdkr|��}|d�d�WSt�d|j���td|j�WdStyP}ztd|�t�dt|����WYd}~dSd}~ww)	Nrz;https://api.github.com/repos/PrestaShop/PrestaShop/releasesr�r�z'Failed to fetch releases. Status code: zH[fetch_latest_prestashop_version] Failed to fetch releases. Status code:r�z5[fetch_latest_prestashop_version] An error occurred: )	r�r�r�r�rrr�r�r)r�r�r�r�r�rrr�fetch_latest_prestashop_version,s 

�
��z0ProcessUtilities.fetch_latest_prestashop_version)FN)NNr)NF)NNNNr	)'�__name__�
__module__�__qualname__rMr*rTr4�centosrh�cent9rfrerbrdrcrsr�rrr�staticmethodr&r0r<r?rPrSr3rkrmrxr�r�r rr�r�r�r�rrrrrsl
	


#


$

	0N

	
r)�plogical.CyberCPLogFileWriterrrr6r5rIro�	threadingr
rtr�r�rrrrrr�<module>s