403 Forbidden


Disable Functions:
Path : /usr/share/lve/modlscapi/user/
File Upload :
Command :
Current File : //usr/share/lve/modlscapi/user/stat_utils.pyo

�
w1fc@sddlZddlZddlZddlZddlZddlZddlZddlmZddlm	Z	de
fd��YZd�Zd�Z
d�Zd	�Zd
d�Zdd
�Zdd�Zdd�Zd�Zd�Zd�Zdd�Zed�ZdS(i����N(tStringIO(tquotetModLsapiStatExceptioncBseZRS((t__name__t
__module__(((s+/usr/share/lve/modlscapi/user/stat_utils.pyRscKs�djg|j�D]$\}}tdj||��^q�}tjdjd|d|��}ytjdj|��}Wn5tk
r�tdj||dj|����nXy|dSWn&t	k
r�td	j|���nXd
S(s�
    Perform cPanel WHM API console request and return data from result
    :param cmd: whm api command
    :return: data dict from result
    t s{0}={1}s*/usr/sbin/whmapi1 {cmd} {kw} --output jsontcmdtkwts>Failed to get JSON from this API request: {0} {1}; output: {2}tdatas,Failed to get data from this API result: {0}N(
tjoint	iteritemsRtformattexec_commandtjsontloadst
ValueErrorRtKeyError(Rtkwargstktvt
joined_kwargstresulttdict_result((s+/usr/share/lve/modlscapi/user/stat_utils.pyt
cpanel_whmapis@!
	
cKs�djg|j�D]$\}}dj|t|��^q�}tjdjd|d|��}ytjdj|��SWn5tk
r�tdj||dj|����nXdS(	s�
    Perform Plesk php_handler utility console request and return result
    :param cmd: php_handler command
    :return: dict result
    Rs-{0} {1}s6/usr/local/psa/bin/php_handler --{cmd} {kw} -json trueRRRsJFailed to get JSON from this API request: php_handler {0} {1}; output: {2}N(	R
RRRR
RRRR(RRRRRR((s+/usr/share/lve/modlscapi/user/stat_utils.pytplesk_bin_php_handler(s@
	c	Cs�d}d}tj|�}tj|�}yhxa|D]Y}t|jd|�d��6}tg|j�D]}|j�^qh�||<WdQXq4WWn;t	t
fk
r�tdjt
j�jd����nX|S(se
    Get domains per user
    :return: dict(
                user: list of domains
            )
    s!/usr/local/directadmin/data/userss5/usr/local/directadmin/data/users/{user}/domains.listtusertrbNRs
(tostlistdirtdicttfromkeystopenRtsett	readlineststriptOSErrortIOErrorRR
t	tracebackt
format_exctsplit(t
da_users_pathtda_domains_pathtda_userstdomainsRtdomains_list_filetl((s+/usr/share/lve/modlscapi/user/stat_utils.pytget_da_domains;s
=(cCs�d}y^t|�\}}|j|d�}|j|d�}|j|d�}|j|d�}WnAtjk
r�tdjdjtj�j	d�����nXii|d	6|d
kr�dn|d6d
6i|d	6|d
kr�dn|d6d6S(s�
    Get php settings from options.conf
    :return: dict(
                first php setting: {version, mode},
                second php setting: {version, mode},
            )
    s//usr/local/directadmin/custombuild/options.conftphp1_releasetphp2_releaset	php1_modet	php2_modesNo option found: {0}Rs
tversiontlsphptlsapithandlerii(
tread_da_configtgettConfigParsert
NoOptionErrorRRR
R&R'R((toptions_patht
config_parsertglobal_sectiontphp1_vertphp2_vertphp1_handlertphp2_handler((s+/usr/share/lve/modlscapi/user/stat_utils.pytget_da_php_optionsPs 1t
dummy_sectioncCs�yTt|��)}tdjd|�|j��}WdQXtj�}|j|�Wn;ttfk
r�t	dj
tj�j
d����nX||fS(s�
    Read DA config file with ConfigParser.
    Need to add dummy section for success
    :param conf_file: config file name
    :param append_section_name: name of section to place in the beginning of file
    :return: RawConfigParser instance
    s[{s}]
tsNRs
(R RRtreadR:tRawConfigParsertreadfpR$R%RR
R&R'R((t	conf_filetappend_section_nametftfile_contentR=((s+/usr/share/lve/modlscapi/user/stat_utils.pyR8os((tphpcCsCdj|�}y|t|jd��SWntk
r>|SXdS(s�
    Convert simple php versions to pretty format
    :param php_ver: {major}.{minor} version
    :param pre: desired key start
    :return: alt-php{major}{minor} or desired `pre`{major}{minor}
    s{0}%s%st.N(RttupleR(t	Exception(tphp_vertprettemplate((s+/usr/share/lve/modlscapi/user/stat_utils.pytpretty_version_keys�s

s/usr/sbin/httpdcCs]tjdjd|��}y0tg|D]}|j�jd�^q(�SWnt�SXdS(s+
    Get `httpd -t -D DUMP_RUN_LSAPI` info
    For httpd24 this default path is `/opt/rh/httpd24/root/usr/sbin/httpd`, generated in make_from_templates.sh script
    :param ctl_path: path to httpd (also apachectl may be used)
    :return: dict(
                lsapi_option: value
            )
    s{ctl} -t -D DUMP_RUN_LSAPItctlRN(R
RRtlowerR((tctl_pathtapache_conf_dataR.((s+/usr/share/lve/modlscapi/user/stat_utils.pyt
dump_lsapi�s
	0cCs]tjdjd|��}y0tg|D]}|j�jd�^q(�SWnt�SXdS(s
    Get `httpd -M`
    For httpd24 this default path is `/opt/rh/httpd24/root/usr/sbin/httpd`, generated in make_from_templates.sh script
    :param ctl_path: path to httpd (also apachectl may be used)
    :return: dict(
                apache_module: value
            )
    s{ctl} -MRURN(R
RRRVR((RWtapache_modulesR.((s+/usr/share/lve/modlscapi/user/stat_utils.pytdump_loaded_modules�s
	0cCs+tjdk}djd|r$dnd�S(sR
    Retrieve path to liblsapi, depends on arch
    :return: path to liblsapi
    ii s/usr/lib{a}/liblscapi.sotat64RI(tsystmaxsizeR(t	is_64bits((s+/usr/share/lve/modlscapi/user/stat_utils.pyt
liblsapi_path�scCsoyVdjtjd|d��jd�\}}djd|d|jd�d	�SWntk
rjd
SXd
S(sr
    Get version-release from rpm -q `pkg`
    :param pkg: package name to query
    :return: version-release
    Rs/bin/rpm -q s --qf %{v}-%{r}t-s{ver}-{rel}tvertrelRNiN(R
R
R(RRtNone(tpkgRcRd((s+/usr/share/lve/modlscapi/user/stat_utils.pyt	rpm_query�s
/'
cCsfyDgt|�D]}||kr|^qdj|�dj�SWntttfk
radSXdS(s�
    Filter strings by given template
    Also split string upon given template
    :param fname: path to file
    :param template: template to find in string
    :return: first template occurrence splitted by template
    iiN(tstringsR(R#t
IndexErrorR%R$Re(tfnameRSR.((s+/usr/share/lve/modlscapi/user/stat_utils.pyt
query_strings�sDiccs�t|d��}}d}xS|j�D]E}|tjkrJ||7}q%nt|�|krd|Vnd}q%Wt|�|kr�|VnWdQXdS(s�
    Strings utility analog.
    Finds printable strings in executable
    :param fname: path to file
    :param n: minimum string length
    :return: generator, yeilds string
    RRN(R RFtstringt	printabletlen(RjtnRKRtc((s+/usr/share/lve/modlscapi/user/stat_utils.pyRh�s

cCs�t�}x:|j�D],\}}td�|j�D��||<qWy|rW|dS|SWntk
r|tj|d�SXdS(s�
    Count domains
    :param handler_struct: handler: version: set_of_domains structure
    :param default_keys: sequence of keys to add as default if no `lsapi` found
    :param only_lsapi: return only lsapi statistics
    :return: statistics - number of lsapi domains per version if only_lsapi=True
                          number of lsapi domains per version per handler otherwise
    css'|]\}}|t|�fVqdS(N(Rn(t.0RR((s+/usr/share/lve/modlscapi/user/stat_utils.pys	<genexpr>�sR6iN(RRRR(thandler_structtdefault_keyst
only_lsapitresult_statthR	((s+/usr/share/lve/modlscapi/user/stat_utils.pyt
count_domains�s		$
(RlR^RR&RR:R
RtpipesRRPRRRR/RCR8RTRYR[RaRgRkRhtTrueRw(((s+/usr/share/lve/modlscapi/user/stat_utils.pyt<module>s,							
	

404 Not Found
[ LogOut ]