Your IP : 18.191.238.6


Current Path : /usr/local/lsws/lsns/bin/__pycache__/
Upload File :
Current File : //usr/local/lsws/lsns/bin/__pycache__/common.cpython-36.pyc

3

�Qg�!�@sHddlZddlZddlZddlZddlZddlZddlTddlmZdZdZ	dZ
dZdZdZ
ejeZde_d	e_de_d
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zd<dd�Zd=dd�Zdd�Zdd �Zd!d"�Zd#d$�Z d%d&�Z!d'd(�Z"d)d*�Z#d+d*�Z#d,d-�Z$d.d/�Z%d0d1�Z&d2d3�Z'd4d5�Z(d6d7�Z)d8d9�Z*d:d;�Z+dS)>�N)�*)�PIPEz0.0.1����z/usr/local/lswscCstjddd�dS)Nz%(asctime)s.%(msecs)03dz [%(levelname)s] %(message)sz%Y-%m-%d %H:%M:%S)�formatZdatefmtz3%(asctime)s.%(msecs)03d [%(levelname)s] %(message)s)�loggingZbasicConfig�r
r
�"/usr/local/lsws/lsns/bin/common.py�init_loggingsrcCstjS)N)�this�
serverRootr
r
r
r�server_rootsrcCs
|t_dS)N)r
r)�rootr
r
r�set_server_rootsrcCst�d|S)Nz/lsns/conf/)r)�fileonlyr
r
r�
get_conf_filesrcCst�d|S)Nz
/lsns/bin/)r)rr
r
r�get_bin_filesrcCstj|�tjd�dS)Nr)r	�error�sys�exit)�msgr
r
r�fatal_error"s
rcCsdddddgS)N�cpu�io�iops�mem�tasksr
r
r
r
r�get_options&srFcCs|j�rdytjt|��}Wq�tk
r`}z*|s@td||f�tjd||f�dSd}~Xq�XnVytj|�}WnFtk
r�}z*|s�td||f�tjd||f�dSd}~XnX|j	t
�k�r�|s�td|j	t
�f�tjd|j	t
�f�dS|dfS)	NzError getting UID for %s: %sFzError getting name for %s: %sz#Specified uid: %d < minimum uid: %dT)NF)NF)NF)�isdigit�pwd�getpwuid�int�	Exceptionrr	�debug�getpwnam�pw_uid�get_min_uid)Zparam�no_fatal�	user_info�errr
r
r�get_user)s*r,cCs2g}x(|D] }t||�\}}|r
|j|�q
W|S)N)r,�append)�uidsr)�usersZuidr*Zgotr
r
r�	get_usersAs
r0cCstjjd�rdSdS)Nz/etc/plesk-releaseTF)�os�path�existsr
r
r
r�	get_pleskIsr4cCst�r
dSdS)Ni'i�)r4r
r
r
r�get_def_min_uidNsr5cCstjdkrtjStd�}yt|d�}WnPtk
rv}z4tjdkr^tjd||t�f�dt_t�t_tjSd}~XnXy|j	�}WnRtk
r�}z6tjdkr�tjd||t�f�dt_t
t��}WYdd}~XnX|j�t|�t_tj
dtj�tjS)Nrz	lsns.conf�rz8Error opening %s: %s, continuing with default min uid %dTz8Error reading %s: %s, continuing with default min uid %dzUsing min uid: %d)r
�min_uidr�openr$�loggedr	�infor5�readline�str�closer#r%)Zfullfile�fr+Zuidstrr
r
rr(Ss,



r(cCs
t�dS)Nz/lsns/conf/lscntr.txt)rr
r
r
r�container_fileksr?cCs
t�dS)Nz/conf/httpd_config.conf)rr
r
r
r�
ols_conf_filensr@cCs
t�dS)Nz/conf/httpd_config.xml)rr
r
r
r�lsws_conf_fileqsrAcCs
t�dS)Nz /lsns/conf/ns_disabled_uids.conf)rr
r
r
r�get_disabled_uid_filetsrBcCs
t�dS)Nz /lsns/conf/ns_disabled_uids.conf)rr
r
r
rrBwscCs
t�dS)Nz/lsns/conf/packages)rr
r
r
r�get_pkg_dirzsrCcCsBtjjt��s4tjjt��s$td�tjt�dd�t�d|S)Nz3Missing LiteSpeed high level installation directoryi�)�modez/%s.conf)r1r2�isdirrCrr�mkdir)�pkgr
r
r�pkg_to_filename}s
rHcCstjt�d�dkrtd�dS)Nrz5You must configure LiteSpeed for LiteSpeed Containers)r1�accessr?rr
r
r
r�ls_ok�srJcCsXtjd||f�tjd|gttd�}|jdkrTtd|jjd�d|j	jd��dS)Nz restart_external %s by touch: %sZtouch)�stdout�stderrrz!Error in running: touch, errors: zutf-8� )
r	r%�
subprocess�runr�
returncoderrK�decoderL)�fileZdesc�resultr
r
r�touch_restart_external�s
rTc	Cs
i}y�tjjt��dkr�tt�d�}tj|�}|j�x`|dD]T}tjj|�}x"|D]}|j	|krV|||j
<PqVWtjj|�s�tj|�t
|d�q@W|r�t
dd�n*x(|D] }|j
|kr�q�t
|j	dd�q�WWn0tk
�r}ztd	|�WYdd}~XnXdS)
Nrr6Z
reset_listz
in lscntr.txtz,/usr/local/lsws/admin/tmp/.lsphp_restart.txtzfor allz/.lsphp_restart.txtzfor homezError managing restart: %s)r1r2�getsizer?r8�json�loadr=�dirname�pw_dir�pw_namer3rFrTr$r)	r/�allZ
users_usedr>�datarRZdironly�userr+r
r
r�restart_external�s.






r^cCs�i}i}tjd�}g}x�|D]�}t|�dkr<|dd�dkst|�dkrX|dd�dkst|�dkr�|dd�dks|dd�dkr�qd	|}tj|�}t|j�d
krtjd|dt|��|j	|�|||<qWxn|D]f}d
}x\|�r@d}xL|D]D}	||	k�rq�t|�t|	�kr�||	dt|��kr�|j
|	�d
}Pq�Wq�Wq�WxL|D]D}tj||j�}
tj
||j�}|
|k�r�i||
<|||
|<�qLWtjdt|�dt|��||fS)Nz/devrZloop�ZcdromrZdm�srz/dev/rz
filename: z statinfo: TFzFinal devices: z Block Devices: )r1�listdir�len�stat�S_ISBLK�st_moder	r%r<r-�remove�major�st_rdev�minor)Z
block_devicesZstatinfo_dev�filesZdevicesrR�filenameZstatinfoZdeviceZretryZinnerrgrir
r
r�get_devices�s@

d




$


rlcCs�|dkrdSt|�}|dkr&d}d}n:|dkr8d}d}n(|dkrJd}d}n|dkr\d}d	}n|St||�d
kr�d||tt||d
d
��|f}nd|||f}tt|��|kr�|Stjd
tt|��||f�|S)N�l�Ti@�Gi�Mi�K�
z%d.%d%sz%d%sz%s != %s use %s)�float�roundr#r<�int_num_valuesr	r%)�valstr�valZdivisorZ	qualifierZstr_numr
r
r�str_num_values�s.(rxcCs$|dks|dkrdS|j�r$t|�St|�dkr<td|�|t|�dj�}|j�sbd}|}n|dt|�d�}yt|�}Wn tk
r�td|�YnX|dkr�d}nD|d	kr�d
}n6|dkr�d}n(|d
kr�d}n|dkr�d}ntd|�tj	d|||t||�f�||}t|�S)Nrmz-1rrzSInvalid value specification: %s, must be number optionally followed by T, G, M or Kz\Invalid value specification (prefix): %s, must be number optionally followed by T, G, M or Krnlroi@rpirqiz\Invalid value specification (suffix): %s, must be number optionally followed by T, G, M or Kzint_num %s, %f * %f = %d���)
r r#rbr�upper�isalpharsr$r	r%)rv�suffix�prefixZprefZ
multiplierZflr
r
rru�s:ru)F)F),rVr	r1r!rNrrcr�VERSIONZ
OPTION_CPUZ	OPTION_IOZOPTION_IOPSZ
OPTION_MEMZOPTION_TASKS�modules�__name__r
r9rr7rrrrrrrr,r0r4r5r(r?r@rArBrCrHrJrTr^rlrxrur
r
r
r�<module>sJ0


"

?>