%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python27/lib/python2.7/site-packages/clselect/
Upload File :
Create Path :
Current File : //opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyc

�
i�B^c@`s*ddlmZddlmZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZm
Z
mZddlmZddlmZdd	lmZdd
lmZmZddlmZddlmZdd
lmZdefd��YZdS(i(tprint_function(tabsolute_import(tdivisionN(tS_IRUSRtS_IWUSRtS_IRGRPtS_IROTH(t	iteritemsi(tClSelect(tClSelectExcept(tClPwdt	clcaptain(tclprint(tutils(tExternalProgramFailedtClUserSelectcB`s�eZdZdZdZdZdZd%d�Ze	e
e
d��Zd�Zdd%d	�Z
ed
�Zd�Zd�Zd
�Zd�Zeee
d�Zed�Zd�Zd�Zd�Zd�Zd�Zd�Zd%d%ed�Ze	e�Zd�Zd�Zd�Zd�Z d�Z!d�Z"e	e"�Z"d�Z#d�Z$e	e$�Z$e
d �Z%d!�Z&d"�Z'e	e'�Z'd#�Z(d$�Z)RS(&s/var/cagefss'/usr/share/cagefs-skeleton/usr/selectors
/usr/selectors/etc/cagefs/excludes.cl.selector/selector.pathcC`s�tjjd�sdSx�|D]�}|jj|�}tjj|jd�}tjj|�s|j|�}zCytj	|�Wn+t
tfk
r�}tj
||��nXWdtj|�XqqWdS(s�
        Creates flags mod_lsapi_reset_me in users' home directories in order
        to recreate CRIU images when php version/extensions/options have changed
        For details see LVEMAN-1210
        :param users: list of usernames (strings)
        s/var/run/mod_lsapi/criu.enabledNtmod_lsapi_reset_me(tostpathtisfilet_clpwdtget_pw_by_nametjointpw_dirt_change_uidRtwritetOSErrorRR	tUnableToSaveDataRt_restore_uid(tselftuserstusertpwRtprevious_user_datate((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pytclean_crui_images%s
c
	C`sCyBdtjkr%tjjd�nddlm}m}m}Wn5tk
rytd�|rrtj	d�qzt
SnX|r�|�r�|�}|r�yD|d}|jd�s�td�|r�tj	d�q�t
SnWq�tk
r�q�Xq�n|||d	t
d
tj�dkd|�}	|	r?|r?tj	d�n|	S(s�
        Switch symlink for alt php.
        Create .cagefs directory if not created
        Rerurn True if error has occured
        s/usr/share/cagefsi(tconfigure_alt_phptis_ea4_enabledtread_cpanel_ea4_php_confsERROR: CageFS not installed.itdefaultsea-phpslERROR: system default PHP version is alt-php. PHP Selector is disabled. Use cPanel MultiPHP manager instead.t	write_logt	drop_permtconfigure_multiphp(tsysRtappendt	cagefsctlR$R%R&tImportErrortprinttexittTruet
startswithtKeyErrortFalseRtgeteuid(
tversionR t
exit_on_errorR*R$R%R&tconftdefault_phpterror((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pytswitch_symlink_for_alt_php;s2 

	



-cC`s�|jr#td�tjd�ntj�dkrOtd�tjd�n|j�}xUt|�D]G\}}td|�|jj	|�}t
j||dtdt�qhWdS(NsPERROR: this option does not work in "single user" mode (when CageFS is disabled)iisERROR: root privileges requiredsProcessing userR7R*(
twithout_cagefsR/R+R0RR5tget_user_version_mapRRRRR;R4(Rtusers_vers_dictRR6R ((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pytapply_symlinks_rulesds	


tphpcC`sGtj||�t�|_t�|_|r:||_n	g|_dS(N(Rt__init__R
Rtsett_user_excludestexclude_pid_list(RtitemRD((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyRAqsc`sf�j|��j|�}�j|�}tjj|�sA|S�j��tjj|�j�}tjj	|�s{|Stj
|���jr��js��j
�j�n��j�jkr�|Sntjj���jkr�|Sy\tt���fd�t�j����d}|�|d�|d�jfSWnttfk
ra|SXdS(sl
        Returns alternative version for a user
        @param user: string
        @return: string
        c`s�|d�j�kS(Ntdata(t_item(ti(talternativestlink_dstR(sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyt<lambda>�siR6RFN(t_check_user_in_cagefst_compose_user_alt_patht_compose_native_infoRRtisdirtget_all_alternatives_dataRRGtislinktreadlinkR<t_native_contentst_load_native_contentstdirnamet
SELECTOR_PATHtlisttfiltertkeyst
IndexErrorR3(RRtshow_native_versiontalt_pathtnativet	full_pathR6((RIRJRsF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pytget_versionzs4
		cC`s|tjj|�sx|j|�}zCytj|�Wn+ttfk
rb}tj	||��nXWdt
j|�XndS(N(RRRORRtmkdirRRR	RRR(RRRR!R"((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyt
create_dir�scC`s�|jj|�}tjj||j�}|j|�}|j||�|jd|ddt	�|jd|ddt	�|j
|�dS(s\
        Creates additional directory and symlinks for use in "without CageFS" mode
        s
../php-clis/phptcheck_existences../phps/php-cgiN(Rtget_homedirRRRt
SELECTOR2_DIRRRat_create_symlinkR1R(RRthomedirtpath_in_hometcur_user((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pytcreate_selector_symlinks�scC`sWtjjtj�rSy|jjd|j�SWqStj	t
tfk
rOdSXndS(NtversionsR](RRRRt
DEFAULTS_PATHt_dhtgetRGtConfigParsertErrortIOErrorR3(R((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pytget_default_version�scC`s�tjj|jj|�dd�}tjj|�sO|j||j��nty2|j|�}|j||j	d|j
��Wn?tjt
tfk
r�}tdt|��tjd�nXdS(Ns.cl.selectorsdefaults.cfgRjs*Error while restoring settings from backupi(RRRRRcRtset_versionRqt_get_default_config_handlerRmRGRnRoRpR3R/tstrR+R0(RRtuser_backup_pathtdhR"((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pytset_version_from_backup�s$#cC`s|jr|j|�}n|j|�|j|�}tjj|�sw|jre|j||�qwtj	|��n|j
�}|j|�|jj
|�}	|dkr4|jr|js�|j|j�nx[t|j�D]*\}
}|j||d|
||�q�Wq�d}t}
tjjd|jf|�}tjj|�r�tjjd|j|�}tjj||�}|j||||�t}
nx�tj|j�D]y}|j|kr�q�n|jd�r�|
r�q�ntjj||�}tjj|j|�}|j||||�q�Wnh||krRtj|��nxGt||d�D]1\}
}|j|tjj||
�||�qgW|jr�tj|�n&tj||	d|�|j||�|j |�|j!|�|r|j"||�SdS(	sg
        Sets alternative version for a user
        @param user: string
        @return: None
        R]t/sphp.inis%s.etcs.iniRFR7N(#R<RRLRMRRRORaR	tNoUserSelectorRPt_remove_alternatives_linksRRRSRTRGRReR4RtNATIVE_PATHtexistsRVR1tlistdirtendswithtNoSuchAlternativeVersionRRR;t_switch_php_da_ispt_reload_processest_backup_settingstget_summary(RRR6treturn_summaryR[R7R!R\RIR REtnative_pathtinitnew_ini_createdtnew_ini_pathtsrctdsttfilenameR((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyRr�sZ	
	
		%	!)	

cC`s	|j|�|j�}|j|�}iitd6td6td6d6}t|j��}|jd�|j|�d}xn|D]f}||kr�i||<n|j	j
d|j|fd�||d<t||d<t||d<q�Wy|j	jd|j�}	Wn#t
jt
jfk
r.d}	nXy t||	d<t||d<Wn tk
rqtj|	��nX|jd�||d<|jd�|j|d�xUtt|��D]A}
||
}|||d||d||dff||
<q�Wt|�S(	sb
        Returns state of alternatives
        @param user: string
        @return: tuple
        tenabledR'tselectedR]is%s%ststateRj(RLRPRNR1R4tsortedRYR,R_Rlt
has_optionRGRmRntNoSectionErrort
NoOptionErrorR3R	Rtpoptremovetrangetlenttuple(RRR[RItnative_infotsummarytalt_versionstselected_versionR6tdefault_versiontidxtv((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyR�sD



	"



cC`s�|j|�}xb|D]Z}y|j||dt�Wqtk
ro}tjdidd6t|�d6�qXqW|j|�dS(s�
        Changes users of a supplied version to specified_version
        @param version: string
        @param current_version: string
        R7ttexttERRORtstatustmessageN(t
list_usersRrR4t	ExceptionRt
print_diagRtR#(Rtnew_versiontcurrent_versionRRR"((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pytchange_to_version2s
$cC`s$|j�}||kr ||SgS(s8
        Returns users of a certain alternative
        (t_get_version_user_map(RR6RF((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyR�AscC`sB|jr#ddlm}|�gSt|j�j|j���S(sF
        Returns all valid system users
        @return: list
        i(tget_cpanel_user(R<tclselectctlphpR�RWt_get_system_userst
differencet_get_user_excludes(RR�((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pytlist_all_usersJs
	
cC`s�t�}d|d<d|d<d|d<d}tjj|�yddl}Wn(tk
rwtd�tjd�nXtjj	|j
|j|�|d�}tjj|d	�s�tjj|d
�r�|j
||�ndS(Nitinittreinittverboses/usr/share/cagefssERROR: CageFS not installed.itetcs/cl.selectors	/cl.php.d(tdictR+RR,R-R.R/R0RRtBASEDIRtget_user_prefixR|tcpetc_for_user(RRtconfigtLIBDIRR-tcagefs_etc_path((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pytcagefs_copy_etcUs	




'cC`s_|j�}i}xF|D]>}y|j|t�d||<Wqtjk
rVqqXqW|S(sH
        Returns user version map as dict
        @return: dict
        i(R�R_R4R	t
NotCageFSUser(Rtactual_usersRFR((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyR=hs
cC`s�|j�}i}xl|D]d}yD|j|t�d}||krQg||<n||j|�Wqtjk
r|qqXqW|S(sH
        Returns users grouped by version
        @return: dict
        i(R�R_R4R,R	R�(RR�RFRR6((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyR�vs

cC`s�yh|rWtjj|�rGtj|�|kr@tj|�qTdSqWtj|�ntj||�Wn_t	k
r�}|dk	r�|dk	r�tj|||��ntj
d|||f��nXdS(s�
        Creates symlink from src to dst
        @param src: string
        @param dst: string
        @param user: string
        @param version: string
        @param check_existence: bool
        @return: None
        Ns(Cannot create symlink from %s to %s (%s)(RRRQRRtunlinkR
tremove_file_or_dirRtsymlinkR�tNoneR	tUnableToSetAlternativetSelectorException(R�R�RR6RbR"((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyRe�s
cC`s�|jr|jStjj|j�s,t�Sxctj|j�D]O}tjj|j|�}|jjtt	d�t
j|�j����q?W|jS(sE
        Returns list of user excludes
        @return: list
        cS`s
|j�S(N(tstrip(tx((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyRK�t(
RCRRROtCAGEFS_EXCLUDERBR}RtupdatetmapR
tread_file_as_stringt
splitlines(RREtfull_item_path((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyR��s			 cC`s�|jr
dSd}tjj|�yddl}Wn(tk
r]td�tjd�nXy%|j|�s�t	j
|��nWn(tk
r�td�tjd�nXdS(s4
        Check that cagefs enabled for user
        Ns/usr/share/cagefsisERROR: CageFS not installed.is;ERROR: CageFS version is unsupported. Please update CageFS.(R<R+RR,R-R.R/R0tis_user_enabledR	R�tAttributeError(RRR�R-((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyRL�s	



cC`smxftj|�D]U}|j|kr+qntjj||�}tjj|�sXqntj|�qWdS(sg
        Removes all symlinks from directory
        @param path: string
        @return: None
        N(RR}RGRRRQR�(RRR�R^((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyRz�scC`s^|jr#|jj|�}|dSt|jj|��}tjj|j|d|dd�S(sz
        Composes and returns user alternative directory path
        @param user: string
        @return: string
        s
/.cl.selectori����R�scl.selector(	R<RRcRttget_uidRRRtCAGEFS_PATH(RRRftuid((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyRM�s		cC`s|jj�}t|j��S(sB
        Returns set of system users
        @return: set
        (Rt
get_user_dictRBRY(Rt
users_dict((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyR��scC`sPtjj|�rLytj|�WqLtk
rHtj|d��qLXndS(s?
        Deletes file to be written if it is a symlink
        s'Cannot delete symlink while saving dataN(RRRQR�RR	R(t	file_path((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyt_delete_if_symlink�s
cC`s�|jj|�}|j}|j}tj�}tj�}||krR||fSy2tj|�tj|�t	j
�||fSWn%tk
r�}tj
||��nXdS(s�
        Changes to another uid and returns tuple of previous euid and egid
        @param user: string
        @return: tuple
        N(RRtpw_uidtpw_gidRR5tgetegidtsetegidtseteuidtsecureiotset_capabilityRR	tUnableToChangeToAnotherUser(RRtentrytnew_uidtnew_gidtcur_euidtcur_egidR"((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyR�s		



cC`s�|dtj�kr�tjdt�y&tj|d�tj|d�Wq�tk
r}}tj	t
|d�|��q�XndS(sw
        Restores changed uid and gid to original ones
        @param uid_and_gid: tuple
        @return: None
        itcleariN(RR5R�R�R1R�R�RR	R�Rt(tuid_and_gidR"((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyR
scC`s[|rtjj|�rdS|j|�|j|�}tjj|�}yFdttj��}tjj	||�}t
j|d|f�Wnktt
tfk
r�}	y&tjj|�r�tj|�nWnnXtj|�tj||	��nKXy6ttBtBtB}
tj||�tj||
�Wnt
k
rInXtj|�dS(s�
        Saves data to file
        @param user: string
        @param file_contents: string
        @param file_path: string
        @return: None
        Nsclseltmp_%ss%s
(RRR|R�RRURttuuidtuuid4RRRRpRRR�RRR	RRRRRtrenametchmod(RRt
file_contentsR�tcreateR!tfile_directoryRUt	temp_pathR"tmask((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyt_write_to_files0


cC`s�dd|d|g}y�tj|�}x�|j�D]�}|j�j�}yM|dj|j�t|d�}||jkr�t	j
|tj�nWq4t
tfk
r�q4q4Xq4WWn&tjk
r�}|dkr�dSnXdS(s&
        Reloads user process
        s/bin/pss-Us-ui����iN(R
trun_commandR�trstriptsplittindexRGtintRDRtkilltsignaltSIGHUPRZt
ValueErrorR	RR�(RRtcmdRFtrowtpartstpidR"((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyR�?scC`s�g}y`t|�}xC|D];}|jd�r|d|jd�!}|j|�qqW|j�Wnttfk
rnX|S(sH
        Get extension names from user extensions file comments
        s;---is---(topenR2trfindR,tcloseRRp(Rt
extensionsR�tlinetext((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyt_skim_over_extensionsSs
cC`s!|j|�g}|j|�}tjjtjj|�d�}|j�}tjj|jj|�d�}tjj	|�s�|j
|�}ytj|�Wn8t
tfk
r�}tj|�tj||��nXtj|�ntjj|d�}	tjj	|�r7d|j|j|�df}
nd|jf}
|j|
�x�t|j��D]�}|jr�|d|jdd	�d
}n+tjj|d|jdd	�fd�}|j|�}
|jd
|j|djt|
��f�qgW|j|dj|�|	�dS(sk
        Scans all user settings and backups'em in homedir as INI file
        @param user: string
        scl.php.ds.cl.selectorsdefaults.cfgs[versions]
%s = %s
is[versions]
%s = native
s/alt_phpt.R�s.inis	alt-php%ssalt_php.inis[%s%s]
modules = %s
t,s
N(RLRMRRRRURPRRcRORRR`RRRRR	RRGR_R,R�RYR<treplaceRR�(RRtbackup_contentst
user_alt_patht
user_ext_pathRIRuR!R"tuser_backup_fileR6taltt
curr_ext_pathR�((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyR�dsD
!	
	 
	!	'cC`s[|jr
dStjjd�ddlm}ddlm}|||�|||�dS(Ns/usr/share/cagefsi(tda_change_user_php_ini(tispmanager_create_user_wrapper(R<R+RR,t
cagefs_da_libRtcagefs_ispmanager_libR
(RRR6RR
((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyR��s	
N(*t__name__t
__module__R�R{RVR�RdR�R#tstaticmethodR1R;R?RAR4R_RaRiRqRwRrR�R�R�R�R�R=R�ReR�RLRzRMR�R�RRR�R�RR�R�(((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyRsR(	
	#		
			
=*											
				
#			*(t
__future__RRRRR+R�R�R�RntstatRRRRtfuture.utilsRtclselectRtclselectexceptR	tclcommonR
Rt
clselectprintRR�R
tclcommon.utilsRR(((sF/opt/alt/python27/lib/python2.7/site-packages/clselect/cluserselect.pyt<module>s""

Zerion Mini Shell 1.0