%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/opt/alt/python27/lib/python2.7/site-packages/clselector/
Upload File :
Create Path :
Current File : //proc/self/root/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyc

�
i�B^c@`sddlmZddlmZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlmZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZdd	l m!Z!m"Z"dd
l#m$Z$m%Z%m&Z&ddl'm(Z(ddlm)Z)dd
lm*Z*ddlm+Z+m,Z,m-Z-ddl.m/Z/m0Z0m1Z1m2Z2ddlm3Z3ddl4m5Z5m6Z6ddlm7Z8ddl9m:Z:ddl;m<Z<ddl=m>Z>m?Z?ddl@mAZAddlBmCZDddlEmCZFddlGmHZHmIZImJZJmKZKmLZLmMZMddlNmOZOddlPmQZQmRZRdefd��YZ7idd6ZSdeTfd ��YZUdS(!i(tprint_function(tdivision(tabsolute_importN(tSet(t	iteritems(tFormattedException(tresolve_username_and_doc_root(tCP_NAMEtdocroot(tNoDomaintNotSupportedt
IncorrectData(texec_utility(tclselectctl(tclpassenger(tClUserSelecttClSelecttClExtSelect(tAPP_STARTED_CONSTtENABLED_STATUStDISABLED_STATUStBaseSelectorError(tvalidate_env_vars(tformat_summarytAPI_1(tClSelectExcept(tNodeJSConfigError(tNodeManager(tPythonAppFormatVersiontget_venv_rel_path(t
PythonManager(tEnvironment(tmkdir_pt	file_readt
file_writetget_using_realpath_keystget_abs_reltdelete_using_realpath_keys(tget_perm(t_set_ui_configtUIConfigExceptionRcB`seZRS((t__name__t
__module__(((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyRFstoktstatustCloudlinuxSelectorLibcB`sPeZd�Zd�ZedFdFd��Zed��Zed��ZedFd��Z	edFdFd��Z
ed��ZedFd��Zd	�Z
ed
��Zd�Zd�Zed
��Zed��Zd�ZdFd�Zed��Zd�Zed��Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d �Z$d!�Z%d"�Z&d#�Z'dFdFdFdFdFdFdFd$�Z(ed%��Z)dFd&�Z*dFd'�Z+ed(��Z,dFdFe-d)�Z.dFdFe-dFdGd*�Z/d+�Z0d,�Z1d-�Z2d.�Z3ed/��Z4d0�Z5ed1��Z6d2�Z7d3�Z8ed4��Z9dFd5�Z:dFdFd6�Z;d7�Z<ed8��Z=dFe-d9�Z>d:�Z?d;�Z@d<�ZAd=�ZBdFd>�ZCd?�ZDd@�ZEdA�ZFedB��ZGedC��ZHdD�ZIdE�ZJRS(HcC`s�||_t|_d|_d|_d|_d|_d|_d|_d|_	d|_
|jdfg}x�|D]�\}}|j|j
kr�|dd	kr�qsntjj
|�sst|_|jd|dd
i|d|d6�|_PqsqsWd|_d|_d|_d|_|j|jkrrddlm}|�|_t�|_tj|_tj|_n�|j|jkr�ddlm}|�|_t�|_tj|_tj|_n1|j|j
kr�ddl m!}|�|_ndS(Ns/usr/bin/selectorctls/usr/sbin/cagefsctls+/usr/share/l.v.e-manager/utils/dynamicui.pys/usr/sbin/cloudlinux-selectortnodejstpythontrubytphptcagefss>http://docs.cloudlinux.com/index.html?cagefs_installation.htmlisplease install or reinstall %stlinki(tApplicationsManager(t
PhpManager(R2s>http://docs.cloudlinux.com/index.html?cagefs_installation.html("tinterpretertTruetselector_is_readyt_SELECTORCTL_UTILITYt_CAGEFSCTL_UTILITYtDYNAMIC_UI_CTL_CMDtCLOUDLINUX_SELECTOR_UTILITYtNODEJS_INTERPRETERtPYTHON_INTERPRETERtRUBY_INTERPRETERtPHP_INTERPRETERtostpathtexiststFalset
_return_errortselector_error_reasontNonetselector_managertapps_managertselector_user_libtselector_old_libt$clselect.clselectnodejs.apps_managerR4Rtclselecttclselectnodejsusertclselectctlnodejsusert$clselect.clselectpython.apps_managerRtclselectpythonusertclselectctlpythont clselect.clselectphp.php_managerR5(tselfR6t	utilitiesRBtpackageR4R5((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt__init__NsP										"					cC`s1|jj||�}|j||�\}}|S(s7Get doc_root from application config or raise exception(RItget_app_domaint$safely_resolve_username_and_doc_root(RTtusernametapp_roottdomaint_tdoc_root((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytsafely_resolve_doc_root_for_app�scC`s�ytd|d|�\}}Wn�tk
rlti|d
k	rGdndd6i|d6|d6d6��njtk
r�tidd6itd6d6��n9tk
r�tid	d6i|d6|d6d6��nX||fS(s8
        Safely resolve username and doc_root by domain,
        or resolve document root by username,
        or resolve document root and username by effective uid
        :param user: str -> name of unix user
        :param domain: str -> domain of panel user
        :return: tuple -> user, doc_root
        tuserR\sNo such domain: %(domain)ssNo such user: %(user)stmessagetcontexts+Nodejs selector not supported for %(panel)stpanels3Domain %(domain)s is not owned by the user %(user)sN(RR	RRGR
RR(R`R\tresult_usertresult_doc_root((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyRY�s2


cC`s�t}t�\}}|dkr*t}n{t|t�sBt}nc|ddkrk|ddkrkt}n:|dkr�|dkr�t}n|ddkr�t}n|S(s�
        Check whether selector should be run through "su - user"
        :param opts: dict of parsed cli params
        :return: True if should be run through su or False if not
        s--users--domainis
--interpreterR1N(R7R&RGRDt
isinstancetdict(toptstresultteuidtegid((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytshould_be_runned_as_user�s		 			cC`s0|ddko/|ddk	o/tj�dkS(Ns
--interpreterR1s--useri(RGRAtgeteuid(Rh((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytshould_run_user_without_cagefs�scC`stj|�}|S(s�
        Resolves user eigher with passed username or with getting current
        user ID
        :param user: str or None -> username to be resolved
        :return: obj -> pwd user object
        (tpwdtgetpwnam(R`tuserdata((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt_get_user_pwd_data�scC`s9|dkr5|dkr5tidd6id6��ndS(s�
        Check if user and domain are None
        :param user: name of unix user
        :param domain: domain of panel user
        :return: None
        sBUser or domain parameter must be specified if current user is rootRaRbN(RGR(R`R\((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytuser_and_domain_checker�s
cK`s7id|d6}t|�dkr3|j|�n|S(Ns	ERROR: %sR,i(tlentupdate(Ritkwargsterr((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyRE�scC`s5idd6|d6}|r1|ji|d6�n|S(s�
        Construct error dict in one place
        :param result: error string
        :return: dict with 'status':'error' and error message
        terrorR,Ritdetails(Ru(RiRyRw((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt_return_with_status_error�s
cC`s�|ttfkr(|jdj|��Sy|tk|j_Wntk
r]}|j|�SX|j|jkr�ii|tkd6d6}yt	|�t
SWq�tk
r�q�Xn|j�t
S(s�
        Set CL selector status in it's config
        :param status: set status of selector
        :return: error or ok message
        sKUnknown selector status provided: "{}". Can be only 'enabled' or 'disabled't
hidePythonAppt
uiSettings(
RRREtformatRHtselector_enabledRR6R>R'tOK_RESR(t	update_ui(RTR,tetconfig_dict((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt_change_selector_statuss"



cC`s*itd6}t�jr&t|d<n|S(NR~(RDRR~R7(tres((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytget_nodejs_selector_status"s

cC`si|jjrtntd6S(NtPHPSelector(RHR~RR(RT((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytget_php_selector_status)scC`sNy*|jj�}|j|j��|SWntk
rI}|j|�SXdS(N(RHtget_summaryRutget_selector_statusRRE(RTR�R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyR�,scC`s*itd6}t�jr&t|d<n|S(NR~(RDRR~R7(R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytget_python_selector_status4s

cC`s?ytj|�jSWn$tk
r:tidd6��nXdS(NsNo such user: `%(user)s`Ra(RoRptpw_dirtKeyErrorR(R`((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt
get_user_home;s

cC`s&t�j�}|j|j��|S(N(RR�RuR�(RTR�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytget_nodejs_summaryDsc	C`s|j|�}|j|jkr?|jj|||d�}n9|j|jkro|jj|||d�}n	t��|g}|j|jkr�|jd�n|j|�|dk	r�|j|jkr�|jd�n|j	|�n|j
|||�}|S(sD
        Runs script to execute other script inside user app environment
        :param user: str -> owner of application
        :param app_root: str -> application directory
        :param script_name: str -> name of script
        :param script_args: list of str -> arguments for the script
        :return: dict
        tnpmR/s
run-scripts--N(R�R6R=RItget_binary_pathR>tNotImplementedErrortappendRGtextendt_run_interpreter(	RTR`R[tscript_nametscript_argst	user_hometinterpreter_pathtcmdRi((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt
run_scriptIs$					
c		C`s�tjd|dtjj||�dtjdtj�}y|j�\}}Wn;tk
r�}tidd6i|d6|d6d6��nXd	j	|j
|j�|j��}itj
|�d
6}|jidd6�|S(
s�
        Run interpreter in users environment
        :param cmd: list -> command to execute
        :param user_home: -> user home directory
        :param app_root: -> app path
        :return: dict
        targstcwdtstdouttstderrs6run-script call: `%(args)s` failed with error: %(err)sRaRwRbs%returncode: {}
stdout:
{}
stderr:
{}
tdatatsuccessR,(t
subprocesstPopenRARBtjointPIPEtcommunicatetOSErrorRR}t
returncodetstriptbase64t	b64encodeRu(	R�R�R[tpR�R�R�t
output_stringRi((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyR�fs 			cC`s,|j|j|jfkr(|jj�SdS(N(R6R=R@RHR�(RT((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytget_full�scC`sot�j�}tj�}x*t|�D]\}}||cd7<q(Wx |D]}||d|d<qOW|S(s_
        Add selector usage statistics (amount of
        domains that use some version, etc)
        Fist parameter is an array with such format:
        [{'version': '5.6'}, {'version': '7.6'}]
        Output is an array with such format:
        [{'version': '5.6', 'users': 10}, ...]
        :type versions_list: list
        :rtype: list
        itversionttotal_users(Rtget_user_version_maptcollectionstCounterR(t
versions_listtuser_version_maptversion_user_mapR`R�titem((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt_add_statistics_field�s
cC`s�|j|jkrTt|j�jt�}t|dddt�}tj|�}n'|j	dk	ru|j	j�}ni}|jd�dkr�i|dd6}n|}|S(sG
        Retrieves supported versions list and default version
        R}tjsontapi_versionR,tERRORRaN(R6R@RR�RDRRR�tloadsRHRGtget(RTR�t	json_datatselectorctl_resultRi((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytget_supported_versions�scC`sh|j�}y|d}Wn@tk
r\d|krG|j|d�Sidd6|d6SnXi|d6S(Ntdefault_versionRaR�R,R�(R�R�RE(RTt	json_dictR�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytget_default_version�s
cC`sX|j|jkr|j�S|j|jkr8|j�S|j|jkrT|j�SdS(N(R6R=R�R>R�R@R�(RT((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyR��s

cC`s|jjS(N(RHR~(RT((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytphp_selector_is_disabled�scC`s
|jjS(N(RHR~(RT((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytphp_selector_is_enabled�scC`s�|j|jkrtSy<dtjkr;tjjd�nddlm}m}Wnt	k
rftSX|�r�|j
�r�|�}|r�y!|d}|jd�s�tSWq�t
k
r�q�Xq�ntS(s�
        Returns True when MultiPHP system default PHP version is alt-php and PHP Selector is NOT disabled
        For details please see LVEMAN-1170
        s/usr/share/cagefsi(tis_ea4_enabledtread_cpanel_ea4_php_conftdefaultsea-php(R6R@RDtsysRBR�t	cagefsctlR�R�tImportErrorR�t
startswithR7R�(RTR�R�tconftdefault_php((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytcheck_multiphp_system_default�s$
	


cC`s�|j|j|jfkr�x`t|�D]R\}}y|j||�}Wntk
ri}|j|�SX|tkr(|Sq(WtS|j�}y|d}Wn+t	k
r�|jd|j
|jf�SXd�|D�}t|j��|r)|jddj
t|j��|�|j
|jf�Sd}	g}
xet|�D]W\}}|rst|j�jt|��nt|j�jt|��|	d7}	qBW|	t|�kr�tS|	dkr�idj|	t|�|
�d	6S|jd
j|
��SdS(Ntavailable_versionss:corrupted answer from %s --json --summary --interpreter %scS`sh|]}|d�qS(R�((t.0tx((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pys	<setcomp>�s	sWinvalid alternative versions (%s), see %s --summary --interpreter %s for valid versionss, iis>WARNING: only {} of {} commands was successful. Errors was: {}R,s&All commands were failedErrors was: {}(R6R=R>Rtset_version_statusRRERR�R�R9tsettkeysR�Rtenable_versiontstrtdisable_versionRtR}(RTtversionsR�tenable_disableRiR�R�talternatives_listtalternatives_versionsR�terrors_listt	to_enable((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytset_supported_versions�sH
	"cC`s�y&|jdk	r%|jj|�nWnftjjjk
rctidd6i|d6d6��n,tjjtfk
r�}|j	|j
�SXtS(NsNo such php version: %(ver)sRatverRb(RHRGtswitch_default_versionRMtclselectexceptRtNoSuchAlternativeVersiontBaseClSelectExceptionRRzRaR(RTR�R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytset_default_versions
cC`s3|r|jj|t�n|jj|t�tS(s�
        Disable or enable version of selector
        :param target_version_status: disable or enable version of interpreter
        :param version: version of interpreter
        :return: OK_RES
        (RHR�RRR(RTttarget_version_statusR�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyR� scC`s�y)|j|jkr(|jj|�nWn`tjjjk
rftidd6i|d6d6��n&tjjk
r�}|j	|j
�SXtS(NsNo such php version: %(ver)sRaR�Rb(R6R@RHtswitch_current_versionRMR�RR�R�RzRaR(RTR�R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytset_current_version/s
cC`s�i}y+|j|jkr0|jj|�}nWn`tjjjk
rntidd6i|d6d6��n&tjjk
r�}|j	|j
�SX|S(NsNo such php version: %(ver)sRaR�Rb(R6R@RHtreset_extensionsRMR�RR�R�RzRa(RTR�t
extensionsR�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyR�;s
cC`s2|j|j|j|jfkr.|j|�SdS(N(R6R=R>R@R�(RTR,((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytset_selector_statusHs!cC`sttj�s$tj�s$tj�rpt|jdgdt�\}}}|dkrp|jdj||��SndS(Ns--sync-conf=allR�is"Can not sync UI with reason: {} {}(
tdetectt	is_cpaneltis_plesktis_daRR;R7RER}RG(RTtretcodetoutRw((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyR�Ls$!cC`s~tj�}|j|jkrzy/|jj||�}|rL|j|�nWn&tjj	k
ru}|j
|j�SX|SdS(N(RtcopyR6R@RHtset_extensionsRuRMR�R�RzRa(RTR�R�RiR�R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyR�UscC`sY|j|jkrUy|jj||�WqUtjjk
rQ}|j|j�SXnt	S(N(
R6R@RHtset_optionsRMR�R�RzRaR(RTtoptionsR�R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyR�`scC`s1|dkr�|j�jdd�}|dks<|dkrWtdj|j���n|j|jkr�tjd|�}|s�tidd6i|d6d6��n|j	d	�S|Snt
|ttf�r�|j|jkr�t
t|��St
|�Sn|d
kr-tidd6i|d6d6��n|S(
s3
        Attempts to get or verify version to be passed to external program
        Currently supported version is one digit (6 or 8).
        If version is None, return a default version
        :param version: str or None -> version to be verified or found
        :return: str -> digit as string
        R�ts{} default version not defineds(?P<version>\d+)s#Incorrect selector version: %(ver)sRaR�RbR�tnativesUnsupported version: %(ver)sN(RGR�R�RR}R6R=tretmatchtgroupRftinttfloatR�(RTR�R�tm((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytresolve_versionhs&



c
C`s�|j||�|j|�}|dk	rCttj|��}n|j||�\}}y�|j|jkr�|j	j
||||d|d|d|d|d|	d|jd|
�n�|j|jkr�t
jj
||||d|�n^|j|jkrK|j	j
|||d|d|d	|d|d|d|d|jd|
�nWn2t
jjk
r�}|jd
|jd|j�SXtS(
s�
        Creates application for specified user, interpreter and version
        If user is None we hope that the external application resolves a user
        Currently NodeJS supported only
        :param domain: str -> domain of the application
        :param app_root: str -> app path relative to user home
        :param app_uri: str -> URI path of the application
        :param version: str or None -> version of the interpreter
        :param user: str or None -> username of user who owns the app
        :param app_mode: str or None -> application mode (development or production)
        :param startup_file: str or None -> main application file
        :param env_vars: json_string or None -> enviroment variables for application
        :param entry_point: Application entry point (used only for python interpreter).
        :param passenger_log_file: Passenger log filename
        :return: dict
        R^tenv_varststartup_filetdomain_nametentry_pointRItpassenger_log_fileR�tapp_modeRiRyN(RsR�RGRR�R�RYR6R>RKtcreateRIR?RMtclselectctlrubyR=R�R�RzRaRyR(
RTR[tapp_uriR�R`R\RR�R�RRR^R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt
create_app�s*"	cC`sRtjj|j|�}tjj|�sNtidd6i|d6d6��n|S(s�
        Resolve app root to absolute path and checks if it exists
        :param app_root: str -> relative a user homedir app path
        :param userdata: obj -> pwd user object
        :return: str -> absolute path to app
        sNo such application: %(app)sRatappRb(RARBR�R�tisdirR(R[Rqtapp_path((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt_get_application_path�s

cC`s�t}|j|d�|j|�}|j||�}tjj||�}tjj|�s�t	idd6i|d6d6��nyFt
|��0}|j�}	|jit
j|	�d6�WdQX|SWn)tk
r�}
|jt|
dd��SXdS(	s 
        Reads file and returns its content as Base64 string
        :param app_root: str -> path to app relative to user home
        :param user: str -> username to resolve app path
        :param config_path: str -> file to be read (relative to app path)
        :return: dict
        s&Configuration file not found: %(path)sRaRBRbR�NtstrerrorR�(RRsRGRrRRARBR�RCRtopentreadRuR�R�t	ExceptionRztgetattr(RTR[tconfig_pathR`RiRqR
tfull_config_pathtfR�R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytread_app_config�s"#c
C`s�|j|d�|j|�}|j||�}tjj||�}y6t|d��}|jt	j
|��WdQXtSWn)tk
r�}	|j
t|	dd��SXdS(s�
        Saves data passed as Base64 string to specified file
        :param content: data for saving in app's config
        :param app_root: str -> path to app relative to user home
        :param user: str -> username to resolve app path
        :param config_path: str -> file to be read (relative to app path)
        :param content: str -> Base64-encoded string
        :return: dict
        twNRR�(RsRGRrRRARBR�R
twriteR�t	b64decodeRRRzR(
RTR[RtcontentR`RqR
RRR�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytsave_app_config�s
cC`s`t|�}|dk	r.|jd|g�n.|dk	rP|jd|g�ntd��|S(Ns--domains--usersBUser or domain parameter must be specified if current user is root(tlistRGR�R(R`R\R�tresult_args((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt_add_user_or_domain�scC`s�|j||�|j|jkrItidd6i|jd6d6��ny+x$|D]}|jj|||�qSWWn&tjjk
r�}|j	|j
�SXtSdS(sn
        Uninstall described modules for user's webapp
        :param app_root: directory with webapp
        :param modules: comma-separated list of modules to uninstall
        :param user: name of unix user
        :param domain: domain of user
        :param skip_web_check: skip check web application after changing its properties
        :return: None
        sJUninstall command is available only for python interpreter, not %(interp)sRatinterpRbN(RsR6R>RRKt	uninstallRMR�R�RzRaR(RTR[tmodulesR`R\tskip_web_checktmoduleR�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytuninstall_modules�s

c

C`sl|j||�|j|jkrxy&|jj||d|d|j�Wn&tjjk
rp}|j	|j
�SXtSn�|j|jkrDy�|r�x}|D].}|jj|||dd|d|j�q�WnD|r|jj||d|d|d|j�nd}	|j	|	�SWn&tjjk
r<}|j	|j
�SXtSn$tidd6i|jd6d6��dS(	s�
        Install described modules for user's webapp
        :type domain: domain of user
        :param user: name of unix user
        :param app_root: directory with webapp
        :param skip_web_check: skip check web application after change it's properties
        :param spec_file: file containing modules and their versions to install
        :param modules: list of installed modules
        :return: None
        R RIs9Please, specify modules or requirements file with modulessUnknown interpreter: %(interp)sRaRRbN(RsR6R=RKtinstallRIRMR�R�RzRaRR>RGR(
RTR[R`R\R t	spec_fileRR�R!Rw((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytinstall_moduless4
cC`s|j|d	�y�|j|jkr;tjj||�n�y|j||�}Wn5tk
r�t	j
idd6i|d6d6��nX|j|j|jfkr�|j
j||d|d|j�n't	jidd6i|jd6d6��Wn&tjjk
r}|j|j�SXtS(
s�
        Destroy specified application root directory and user name
        :param app_root: Application directory
        :param user: name of unix user
        :return: dict
        s[No such application or it's broken. Unable to find app-root folder by this path %(app_root)RaR[RbR^RIsUnknown interpreter: %(interp)RN(RsRGR6R?RMRtdestroyR_t	TypeErrortClSelectExceptionst	WrongDataR=R>RKRItInterpreterErrorR�R�RzRaR(RTR[R`R^R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytdestroy_appEs(
	
	cC`s�|j|d�y{|j||�}|j|j|jfkr_|jj||||j�n't	j
idd6i|jd6d6��tSWn&tj
jk
r�}|j|j�SXdS(s�
        Start specified application root directory and user name
        :param app_root: Application directory
        :param username: name of unix user
        :return: dict
        sUnknown interpreter: %(interp)RaRRbN(RsRGR_R6R=R>RKtstartRIR(R*RRMR�R�RzRa(RTR[RZR^R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt	start_appgs	cC`s�|j|d�y�|j||�}|j|jkrV|jj||||j�nX|j|jkr�|jj||||j�n't	j
idd6i|jd6d6��tSWn&tj
jk
r�}|j|j�SXdS(s�
        Destroy specified application root directory and user name
        :param app_root: Application directory
        :param username: name of unix user
        :return: dict
        sUnknown interpreter: %(interp)RaRRbN(RsRGR_R6R=RKtrestartRIR>R(R*RRMR�R�RzRa(RTR[RZR^R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytrestart_app|s	cC`s�|j|d�y�|j||�}|j|jkrV|jj||||j�nX|j|jkr�|jj||||j�n't	j
idd6i|jd6d6��tSWn&tj
jk
r�}|j|j�SXdS(s�
        Start specified application root directory and user name
        :param app_root: Application directory
        :param user: name of unix user
        :return: dict
        sUnknown interpreter: %(interp)RaRRbN(RsRGR_R6R=RKtstopRIR>R(R*RRMR�R�RzRa(RTR[R`R^R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytstop_app�s	cC`sd|d}d|d}x�tjtjj|ddd��D]�}tjj|�sAy_t|�}||ks�||kr�|j||�}|j||�}	t||	d�nWqtk
r�t	j
�\}
}
}t	jjt
tj|���qXqAqAWdS(sO
        Replace old prompt and env_var in binaries in new environment
        t(t:t*tbinRN(tglobRARBR�R	R!treplaceR"tIOErrorR�texc_infoR�RR�t	tracebacktprint_tb(tnew_envtold_envtnew_reltold_relt
old_promptt
new_prompttactivatetold_activatet
_new_activatetnew_activateR]t
traceback_((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt6_replace_old_env_and_prompt_in_binaries_in_environment�s+
cC`s�y�t|||�}tj|�j}t|d�d}ii|jjd6|jj|||�d6|dd6|dd6|d6dj||dd	g�d
6dj||g�d6|dgd6|6}|SWnt	k
r�iSXd
S(s�
        Retrieve application info from user's applications config. Analog of function clpassenger.summary
        :param username: User name
        :param app_config_dict_full: Full user's application config.
        :param app_root: Application root
        :return: Dictionary with application info
         Example:
         { 'binary': '/home/cltest1/virtualenv/new_app_root/2.7/bin/python',   # +
           'domain': 'cltest1.com',                                            # +
           'alias': 'app1',                                                    # +
           'htaccess': '/home/cltest1/public_html/app1/.htaccess',             # +
           'interpreter': 'python',                                            # +
           'directory': '/home/cltest1/new_app_root',                          # +
           'docroot': '/home/cltest1/public_html',                             # +
           'domains': ['cltest1.com']
         }
        R\iR6tbinaryRtaliasRt/s	.htaccessthtaccesst	directorytdomainsN(
R#RoRpR�RRItINTERPRETERR�R�R�(RTRZtapp_config_dict_fullR[tapp_config_dictR�R^t
app_info_dict((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytget_app_summary�s"

cC`sytjj|�s/t|�tj||�nFx6tj|�D]%}tjtjj||�|�q?Wtj	|�dS(s�
        Move all items from old directory of application to new directory
        :param old_directory: full real path to old directory of applicaton
        :param new_directory: full real path to new directory of applicaton
        N(
RARBRCR trenametlistdirtshutiltmoveR�trmdir(t
old_directoryt
new_directoryR�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt_move_app_from_old_dir_to_new�s	
#cC`sS|jj|�}yt|||�}Wn$tk
rNtjd|��nXt||�\}}t||�\}}	ytj|	�Wn%t	k
r�}
tj
|
j��nX|j|||	�}yt||	|�Wntk
r�nXtj
|��|j|||�}yt|||�}
Wn$tk
rOtj
d|��nX|
d}|
d}|jj||d||�j}|j|jkr�t||�\}}t||�\}}t|t||d|�d�\}}nx|j|jkr\t|tjj|jjj|��\}}t|tjj|jjj|	��\}}n	t��tjj|d�}tjj|d�}tjj|�}tjj|�s�tj|�ntj ||�|j!||�|j|jkr|j"|||	|�n|j|jkr8t||�\}}n3|j|jkrb|jj#||�}n	t��|jjj$|||�}|j�j%}t|||�d}|t&kr"t'j(||�||j)d	d�}t'j+||||j|d
|d|dd	|�t'j,||�nt-|||�|||<|jj.||�dS(
s
        Move user's application from directory to new_directory
        :param user:  application owner. unix like user name
        :param old_directory: current directory with application
        :param new_directory: new directory for application
        :return: None
        s8No such application (or application not configured) "%s"RRItapp_summaryR�iR�t
app_statusRR^R�N(/RItget_user_config_dataR#R�R(tNoSuchApplicationR$R
tcheck_directoryt
ValueErrorR)RaRRtAppRootBusyRKt_get_environmenttnameR6R>RR=RARBR�RJtenvironmentstDEFAULT_PREFIXR�tdirnameRCtmakedirsRURVRZRGt_get_prefixRRHRRtunconfigureR�RGt	configureR.R%twrite_full_user_config_data(RTR`RXRYtfull_configt
app_configtold_absR?tnew_absR>R�tnew_user_summarytold_user_summarytold_user_app_summaryR^RItenv_nameR�trel_venvt_old_envR]t_new_envR=R<tnew_env_dirtprefixtenvironmentRHR\tpassenger_log_file_to_set((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt	_relocate�s�


	

	(!		!

cC`s�yc|j|j|jfkr4|j|||�n.|j|jkrbtjj|||d�nWn&tj	j
k
r�}|j|j�SXt
S(s=
        Call selectorctl to relocate application from old_app_root to new_app_root
        :param user: application owner
        :param old_app_root: current application directory (current application name)
        :param new_app_root: new application directory (new application name)
        :return: json
        N(R6R>R=R{R?RMRtrelocateRGR�R�RzRaR(RTR`told_app_roottnew_app_rootR�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyR|ks cC`s�d}tjj|||�}tjj|||�}tjj|�tjj|�kr^dStjj|�}tjj|�s�tj|�ntj||�dS(s
        :param old_doc_root: path to old doc root of application
        :param old_alias: old alias (uri) of application
        :param new_doc_root: path to new doc root of application
        :param new_alias: new alias (uri) of application
        :return: None
        s	.htaccessN(	RARBR�trealpathRfR	RgRUR�(told_doc_roott	old_aliastnew_doc_roott	new_aliasRKtold_htaccess_filetnew_htaccess_filetnew_htaccess_path((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt_transit_htaccess_filescC`s
|jj|�}yt|||�}Wn)tk
rStjdj|���nX|j|||�}yt|||�}	Wn)tk
r�tjdj|���nX|	d}
|	d}|dkr�|
nt
j|�}|jj
||d||�}
|
j�j}||dtkr�||jdd�}tj||||j|tdd|d	|d	d|�tj|||
|d
|d|�tj||�n+|dkr�|}n|j||
||�||d<|dk	r�||d
<n|jj||�dS(s�
        Change application URI
        :param user: application owner. unix like user name
        :param directory: directory with application. (app-root)
        :param alias: new alias (app-uri) for application or None if change only the domain
        :param new_doc_root: NEW doc_root to transit application to
        :param new_domain: NEW domain to transit application to
        :return: None
        s8No such application (or application not configured) "{}"RIRR[R\RttransitR^R�R�R�RR\N(RIR]R#R�R(R^R}RRR)RGR
t	get_aliasRKRbR6RHRR�RRjR7RVR.R�Rk(RTR`RLR�t
new_domainRIRlRmtapps_summarytold_app_summaryR�R�R�RyRHRz((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt_transit�sD




!	!"	

cC`s�y�|dkrd}n|j||�\}}|j|j|jfkrg|j|||||�n:|j|jkr�tjj	|||d|�n	t
��Wn&tjjk
r�}|j
|j�SXtS(sV
        Call selectorctl to transit application to new_app_uri
        :param user: application owner
        :param app_root: application directory (application name)
        :param new_app_uri: new uri or None if change only the domain
        :param new_domain: new domain or None if change only the app_uri
        :return: json
        R^N(RGRYR6R>R=R�R?RMRR�R�R�R�RzRaR(RTR`R[tnew_app_uriR�R�R]R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyR��s		
cC`std}|r9y|j|�}Wq9tjk
r5q9Xn|jj||j|�|dkrptjd��ndS(s�
        Install nodejs extensions to new nodejs environment and change
        symlink <user_homedir>/<app-root>/node_modules to new environment.
        Raise exception `WebAppError` if npm will return non-zero code
        is<Module installation has been failed. Please, check npm logs.N(textension_install_single_callR(tFileProcessErrorRKt_create_symlink_to_node_modulesRBtWebAppError(RTR`R[R<told_extensionstnpm_ret_code((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt_relocate_nodejs_extensions�scC`s�t|j��}x:||D].}y|j|�Wqtjk
rJqXqWx:||D].}y|j|�WqZtjk
r�qZXqZWdS(s�
        Install python extensions to new python environment.
        They are equivalent to extensions from old environment.
        Remove python extensions which not existing
        in old environment from new environment
        N(R�R�textension_uninstallR(tExternalProgramFailedtextension_install(R<R�tnew_extensionst	extension((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt_relocate_python_extensions�s
c
	`s��jj���yt�����Wn$tk
rNtjd���nX�jj���}�s�i|j�j	�|j
6S�jj����}�j���t
|j��}�j�jkr��j||�n+�j�jkr�j��||�ntj��}t��|�}	|	d�|j�j��jj|	��\�}
���������f	d�}|s�y#�jjd|
d�d|�Wq�tjk
r�}tjd|��q�Xn|�dS(	s�
        Set current interpreter version for the application

        :param user: application owner. unix like user name
        :param directory: app_root - main directory with user application
        :param version: new version of python interpreter or None if we get current
        :param skip_web_check: skip check web application after change it's properties
        :return: None
        s8No such application (or application not configured) "%s"Rc`s�tj�����jdd�}tj����j�d�d�dd|�tj������d�j<�jj���dS(NRR^R�s
%s_version(	RRiR�RGRjR6R.RIRk(Rz(	RIRmRHRLR^RlRTR`R�(sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytaction?s!
R\RIR�s,An error occured during changing version. %sN(RIR]R#R�R(R^RKRbR6tas_dictRct_create_environmentt_ensure_version_enabledR�R�R>R�R=R�RtsummaryRHt_get_info_about_webapptcheck_response_from_webappR�(
RTR`RLR�R told_environmenttnew_environmenttinstalled_extensionstuser_summary_dataR[t
app_domainR�Rw((	RIRmRHRLR^RlRTR`R�sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt_change_versions@

'
cC`s�y�|j|j|jfkr't�n|j|jkrz|jj||�jdtj�}|tjkrzidd6Sn|jj	||�t
kr�|j|||d|�n|j|||�t
SWn&tjjk
r�}|j|j�SXdS(sx
        Call selectorctl to change current interpreter version to new_version for application
        :param user: application owner
        :param app_root: application directory (application name)
        :param new_version: new nodejs interpreter version
        :param skip_web_check: skip check web application after change it's properties
        :return: json
        tapp_versions�This application was created by too old version of python selector and we cannot change version without migration to the new application format. To do that you can use `cloudlinux-selector migrate` command or just click button in web UI.R,R N(R6R=R>R�RItget_app_configR�RtLEGACYtget_app_statusRR�t_change_version_for_stopped_appRRMR�R�RzRa(RTR`R[tnew_versionR R�R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytchange_versionXs		cC`sv|j|jkrr|j||�}y|jj||||�Wqrtk
rn}tjdj|���qrXndS(NsRUnable to set environment variables in htaccess file for the application.Error: {}(	R6R>R_RItadd_env_vars_for_htaccessRR(R�R}(RTR`R[R�R^Rw((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytset_variables_for_litespeed|sc	
C`s|jj|�}	yt|||	�}
Wn$tk
rNtjd|��nX|j|jkr�|dk	r�|
d|kr�|
dt	j
kr�tjd��n|dk	r�||
d<n|dk	r�||
d<n|dk	r�||
d<n|dk	r||
d<n|dk	r||
jd�kr||
d<|j|jkrw|j
j|||�}|j
j||||�ntj|�}|j
j||�}
t|||�}|d	}|d
}|d}|
j�j}tjd	|�tj||||j|d|d|�n|dk	r�|d
kr:d|
d<n
||
d<|j
j||�}
tj|�}t|||�}|d}|
j�j}|d
}|d	}tjd	|�tj||||j|d|d|�ntj||�|jj||	�|j|||�dS(sl
        Set application mode, environment variables and startup_file for application
        :param config_files: names of config files (such as requirements.txt or etc)
        :param entry_point: the specified entrypoint for application
        :param user: application owner. unix like user name
        :param directory: directory with application
        :param app_mode: expected application mode
        :param env_vars: dict with environment variables for application
        :param startup_file: main file for application
        :param passenger_log_file: Passenger log filename
        :return: None
        s8No such application (or application not configured) "%s"R�R�s�Unable to set environment variables. Application was created too long time ago. Please, migrate your application to newer version before changing interpreter versionRRtconfig_filesR�RKRRIR^R�RN(RIR]R#R�R(R^R6R>RGRR�R�R�RKt_get_full_path_to_startup_filet
setup_wsgiRR�RbRHt_unconfigureRjR.RkR�(RTR`RLRR�R�RR�RRltapp_config_datatstartup_file_full_pathtuser_summarytenvtuser_app_summaryt
htaccess_pathR^RIRH((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt_set_variables�sp




!
		


!





!
c		C`s|dk	rLyttj|��}	WqRttfk
rH|jd�SXnd}	y�|j|j|j	fkr�|j
j||�tkr�|j
||||	||||�n"|j||||	||||�tSWn&tjjk
r�}
|j|
j�SXdS(sk
        Call selectorctl to set variables for application
        :param config_files: names of config files (such as requirements.txt or etc) (only for python)
        :param entry_point: the specified entrypoint for application (only for python)
        :param user: application owner
        :param app_root: application directory (application name)
        :param app_mode: application mode
        :param env_vars: json_string with environment variables for application
        :param startup_file: main file for application
        :param passenger_log_file: Passenger log filename
        :return: json
        s/wrong json format for environment variable listN(RGRR�R�R'R`RzR6R=R>RIR�RR�t_set_variables_for_stopped_appRRMR�R�Ra(RTR`R[RR�R�RR�Rtenv_dictR�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt
set_variables�s 

cC`sIy|jj|�}|SWn(tk
rD}i|jd6|jd6SXdS(s�
        Retrieves info about all installed interpreters and user(s) applictions
        :param user: User name for read applictions. If None all users will be processed
        :return: Dict with info
        RiRbN(RItget_applications_users_infoRRaRb(RTR`tresult_dictR�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytget_apps_users_infos
cC`s1|jj|�s-tjj||d��ndS(s�
        Check whether particular interpreter version is enabled and raises
        exception if not
        :param username: user to include in exception
        :param new_version: new interpreter version
        sversion is not enabledN(RHtis_version_enabledRMRtUnableToSetAlternative(RTR�RZ((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyR�sc
C`s�|j||�|jj||�}|jj|||d�}t|j��}|jj|||d�}x<|D]4}y|j|�Wqtt	j
jjk
r�qtXqtW|jj
|�}	||	|d|j<|jj||	�dS(s�
        Changes version for stopped application
        :param username: application owner
        :param app_root: application directory (application name)
        :param new_version: new nodejs interpreter version
        :return: None
        s
%s_versionN(R�RItget_interpreter_version_for_appRKR�RGR�R�R�RMR�RR�R]R6Rk(
RTRZR[R�told_versionR�R�R�R�Rm((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyR�s	
c	
C`s�|jj|�}	|r)||	|d<n|r@||	|d<n|rp||	|jd�krp||	|d<n|r�||	|d<n|r�||	|d<n|dk	r�|dkr�||	|d<nd|	|d<|jj||	�|j|||�dS(	s�
        Sets new app_mode, environment variables and startup file for stopped NodeJS application
        :param config_files: names of config files (such as requirements.txt or etc) (only for python)
        :param entry_point: the specified entrypoint for application (only for python)
        :param str username: application owner
        :param str app_root: application directory (application name)
        :param str app_mode: New application mode, can be None
        :param dict env_vars_dict: New environment variables, can be None
        :param startup_file: New startup file, can be None
        :param passenger_log_file: Passenger log filename
        :return: None
        RR�R�RR�R�RN(RIR]R�RGRkR�(
RTRZR[Rt
env_vars_dictR�RR�RRm((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyR�6s cC`stt|jd�d��S(s�
        Retrieves major version from full. If already short, return it with no difference
        :param version: Full/short
        :return: Short version as string
        t.i(R�R�tsplit(R�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytget_major_version_from_shortWscC`sIttd�j�j��}t�}x|D]}|j|�q.WdS(s�
        Replace mysqli extension to nd_mysqli for defaults.
        Warning: only for PHP. See LVEMAN-1399 for details
        :return:
        R1N(RRtget_all_alternatives_dataR�Rtlist_extensions(talt_php_versions_listt
cl_ext_selecttalt_php_ver((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytreplace_mysqli`s		
cC`sg|j|jkrt�ntj�r+tSy|jj�tSWn tk
rb}|j	|j
�SXdS(sn
        Scan users home dirs for .htaccess files and import
        applications to new config file.
        N(R6R>R�R�R�RRIt$import_legacy_applications_to_configRRzRa(RTR�((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytrun_import_applicationsos	
cC`s8|j|jkr!td��n|jj||�tS(s_
        Convert applications created in older selector
        versions to new format
        s/Migration is only available for python selector(R6R>R�RItmigrate_applicationR(RTR`R[((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pytrun_migrate_applicationsN((KR)R*RWR_tstaticmethodRGRYRlRnRrRsRERzR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�RRRRRRDR"R%R+R-R/R1RGRRRZR{R|R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�(((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyR-Ms�	2	0
					 								,				
						!+,	"				'	r	5	C	$		\	"	
		!		(Vt
__future__RRRRoR�RUR�R�R�RAR�R�R:R6ttypingRtfuture.utilsRtcldetectlibR�tclselect.clselectctlnodejsuserRMtclselect.clselectexcepttclselect.clselectctlpythontclselect.clselectctlrubytclselect.clselectpythonusertclselect.clselectnodejsusertclcommon.clexceptionRtclcommon.clpwdRtclcommon.cpapiRRtclcommon.cpapi.cpapiexceptionsR	R
Rtcllimits.libRR
RRRRtclselect.baseclselectRRRRRtclselect.clselectctlphpRRRR(tclselect.clselectnodejsRt$clselect.clselectnodejs.node_managerRRPRRt&clselect.clselectpython.python_managerRt(clselect.clselectpythonuser.environmentsRtPythonEnvironmentt(clselect.clselectnodejsuser.environmentstNodeJsEnvironmenttclselect.utilsR R!R"R#R$R%tsecureioR&tclconfig.ui_config_libR'R(RtobjectR-(((sG/opt/alt/python27/lib/python2.7/site-packages/clselector/selectorlib.pyt<module>s\".


Zerion Mini Shell 1.0