ѠgCddlZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z dZ dZdZd ZGd d ZdS) N)getpwuid)Feature) NotSupportedCPAPIExternalProgramFailed) acquire_lockcfd}|S)Nc4tdjd)N"z" api not supported)r__name__)akwfuncs /builddir/build/BUILDROOT/alt-python27-cllib-3.4.22-1.el8.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/cpapi/GeneralPanel/general_panel.py _exceptionz"_not_supported.._exceptionsAt}AAABBB)rrs` r_not_supportedrs'CCCCC rz%/usr/bin/getcontrolpaneluserspackagesz/var/lve/panel_users_countz /var/clcpapicheZdZdZdZedZedZedZdZ dZ d:d Z d Z d;d Z d:d Zd:dZd:dZdZdZdZedZedZedZedZedGeneralPanelPluginV1ct|_dSN)GET_CP_PACKAGE_SCRIPT_custom_script_nameselfs r__init__zGeneralPanelPluginV1.__init__)s#8   rcdSrrrs rinvalidate_cpapi_cachez+GeneralPanelPluginV1.invalidate_cpapi_cache-s rc&|D]$}tj|sdS%tj|sdS|D]E}tj|tj|krdSFdS)NFT)ospathexistsgetmtime) cpapi_cache panel_markersmarkers ris_cache_validz#GeneralPanelPluginV1.is_cache_valid0s#  F7>>&)) uu w~~k** 5#  Fw''"'*:*:;*G*GGGuuHtrc t|dz5t|ddd5}tjd|i|ddddn #1swxYwYddddS#1swxYwYdS#t$rYdSwxYw) Nz.lockwutf-8surrogateescapeencodingerrorsdata)indent)ropenjsondumpPermissionError) actual_data cache_filefs rrewrite_cpapi_cachez(GeneralPanelPluginV1.rewrite_cpapi_cache>sM j7233 B B*cGDUVVVBZ[Iv{3QqAAAABBBBBBBBBBBBBBB B B B B B B B B B B B B B B B B B B    DD sWA3A&A A&A A&A A& A3&A**A3-A*.A33 BBc fd}|S)Nc$fd}|_|S)Nc tjtjdz}t |d}tj|r||rz t|ddd5}tj |d}dddn #1swxYwYnV#t$r&|i|}t ||Yn'wxYw|i|}t |||S)Nz.cache panel_parkerrr*r+r,r/) r r!joinCPAPI_CACHE_STORAGEr rr'r"r2r3load Exceptionr9)argskwargsr7 cache_validr8r/decorator_kwargsrs rwrapperzCGeneralPanelPluginV1.cache_call..decorator..wrapperKs_W\\*=t}x?WXX 2AA*N^_mNnoo 7>>*-- O+ OS!*cGL]^^^8bc#'9Q<<#7D888888888888888$SSS#tT4V44,@@zRRRRRS  4000D(<.decoratorJs1       '+G #Nrr)rFrIs` r cache_callzGeneralPanelPluginV1.cache_callHs$     &rcdS)zV Return panel name :rtype: str :return: Name of panel GeneralPanelrrs r getCPNamezGeneralPanelPluginV1.getCPName_s ~rctj|jg|ztjtjd5}|\}}|j}dddn #1swxYwY|||fS)zv Just wraps long script calls. :param args: arguments to pass :return: stdout, stderr T)stdoutstderrtextN) subprocessPopenrPIPE communicate returncode)rrCpouterrrVs r_run_long_scriptz%GeneralPanelPluginV1._run_long_scriptgs    % & -??     & }}HCJ & & & & & & & & & & & & & & &C##sA!!A%(A%Fcg}|dg\}}}|r|dkrt|pd||dD]}|dkr|||S)z Return list of available admin's packages :param raise_exc: raise exception on exit code != 0 :return: List of packages. For example ['BusinessPackage', 'Package2'] z--list-packagesrz*Failed to get information about packages:  )rZrstripsplitappend)r raise_exc packages_listrOrPrVlines radmin_packagesz#GeneralPanelPluginV1.admin_packagesxs %)%:%:|S)Nz--list-reseller-users=r\,packageresellerr)rZstrr^r_int)rrjreseller_usersrX_rcs rget_reseller_usersz'GeneralPanelPluginV1.get_reseller_userss))+Cc(mm+S*TUU QIIKK%%d++ & &D$::c??D7$,&,&N3tAw<< ( (rNc>g} dt|zg}|%|dt|z||\}}}|d}|t |dz =n#t t tf$rYnwxYw|S)a Retrieves uid list for package :param package_name: Package name :param reseller_name: Reseller name. None for admin's package :rtype: List :return: List of uids Example: [1000, 1002, 1006, 1007, 1008] z --package=Nz --reseller=r\rg)rkr`rZr_lenOSErrorIOErrorAttributeError)r package_name reseller_nameuid_listrCrOrns rget_uids_list_by_packagez-GeneralPanelPluginV1.get_uids_list_by_packages  3|#4#445D( M#m*<*<<===0066LFAq||D))HX*++.1    D sA;BBBc8i}|dg\}}}|r|dkrtd|d|vr_|dD]I}|dd}t|dkr|d|t |d<J|S) Nz --list-allrz0Failed to get list of users and their packages: zerror:r\ rg)rZrr_rqrl)rrauid_package_maprXrnrVrcs rlist_allzGeneralPanelPluginV1.list_alls!22L>BBQ  Jq,H3HHJJ J 3   $ < <zz#q))t99>>48GOCQLL1rcLi}|dg\}}}|r|dkrt|pd||dD]C}d|vr|d}|d|dd|t |d<D|S) Nz --list-usersrz'Failed to get information about users: r\rfrgr{rh)rZrr^r_rl)rrausersrXrYrVrcs r list_userszGeneralPanelPluginV1.list_userss#44n5EFFS*  Hq,FFFFHH HIIKK%%d++ L LD$::c??D.21g47"K"KE#d1g,,   rctjt}|dg\}}}|r|dkrt |pd||d}|D]n}|}|s|dd}t|dkrC|d|d} } || | o|S)a  Return dictionary, contains available resellers packages, grouped by resellers :return: Dictionary. Example: {'res1': ['BusinessPackage', 'UltraPackage', 'Package'], 'res2': ['SimplePackage', 'Package'] } z--list-resellers-packagesrz2Failed to get information about reseller package: r\rzrgr{) collections defaultdictlistrZrr_r^rqr`) rraresellers_packagesrXrYrVlinesrc line_partsres_name pack_names rrz'GeneralPanelPluginV1.resellers_packagess)4T::#446Q5RSSS*  Sq,QQCQQSS S  $ ; ;D::< domain Nrrs rreseller_domainsz%GeneralPanelPluginV1.reseller_domainssrrcdS)z Get login url for current panel; :type domain: str :rtype: str :return: Panel login URL Nrrs rget_user_login_urlz'GeneralPanelPluginV1.get_user_login_url}rrcdS)z Get dict reseller => id Optional method for panels without hard link reseller <=> system user :rtype: dict[str,int] - {'res1': id1} :return: Nrrs rget_reseller_id_pairsz*GeneralPanelPluginV1.get_reseller_id_pairsrrcdS)a Retrives dictionary information about php versions for each domain { 'domain.com': { 'php_version_id': 'ea-php70' 'php_handler': lsapi | fpm | cgi | fastcgi }} :rtype: dict Nrrs rget_domains_php_infoz)GeneralPanelPluginV1.get_domains_php_infos  rcdS)zW Retrives list of php versions installed in panel :rtype: list Nrrs rget_installed_php_versionsz/GeneralPanelPluginV1.get_installed_php_versionsrrcdS)z\ Retrives dictionary with system information about php :rtype: dict Nrrs rget_system_php_infoz(GeneralPanelPluginV1.get_system_php_inforrcdS)z :rtype: str Nrrs rget_admin_localez%GeneralPanelPluginV1.get_admin_locales rcdS)ze Retrive encoding name, used for package/reseller names, from panel :return: Nrrrrget_encoding_namez&GeneralPanelPluginV1.get_encoding_namerrreturn.ct)zl Return list of CloudLinux features that cannot be used with current control panel. )NotImplementedErrorrs rget_unsupported_cl_featuresz0GeneralPanelPluginV1.get_unsupported_cl_featuress "###rcdgS)zl Retrieves active httpd's ports from httpd's config :return: list of apache's ports Prrrrget_apache_ports_listz*GeneralPanelPluginV1.get_apache_ports_lists t rcdS)zX Retrieves Apache's connections number (from mod_status) For CM rOKrrrrget_apache_connections_numberz2GeneralPanelPluginV1.get_apache_connections_numbers wrcdS)z Get current maximum request apache workers from httpd's config :return: tuple (max_req_num, message) max_req_num - Maximum request apache workers number or 0 if error message - OK/Trace rrrrrget_apache_max_request_workersz3GeneralPanelPluginV1.get_apache_max_request_workerss wruidcP t|jS#t$rYnwxYwdS)zd Get "main" panel username by uid. :param uid: uid :return Username zN/A)rpw_nameKeyError)rs rget_main_username_by_uidz-GeneralPanelPluginV1.get_main_username_by_uids; C==( (    D us  ##rrcdSNr]r)rrs rget_user_emails_listz)GeneralPanelPluginV1.get_user_emails_listrrcdSrrrs rpanel_login_linkz%GeneralPanelPluginV1.panel_login_linkrrcdSrrrs rpanel_awp_linkz#GeneralPanelPluginV1.panel_awp_linkrrctjtrTt tdd5}|}dddn #1swxYwY|rt |SdS)zB Get users count :return: number of users r>r*)r-Nr)r r!isfilePANEL_USERS_COUNT_FILEr2readrl)r8counts rget_hosting_accounts_countz/GeneralPanelPluginV1.get_hosting_accounts_counts 7>>0 1 1 ",cGDDD ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! "5zz!qsAA!$A!c|S)zs 99% of control panels log-in user with same username as system user has, except for Plesk rrs rget_customer_loginz'GeneralPanelPluginV1.get_customer_login  rc|S)z 99% of control panels log-in user with same username as system user has, in the Plesk panel we need a subscription login r)rrrs rget_domain_loginz%GeneralPanelPluginV1.get_domain_loginrrc td)zX Get ip of the server that is configured in control panel to be "main". zZUnable to detect main ip for this server. Contact CloudLinux support and report the issue.)rrs r get_server_ipz"GeneralPanelPluginV1.get_server_ipsNOO OrcgSrrrs rsuspended_users_listz)GeneralPanelPluginV1.suspended_users_list s r)Fr)NF)NrT)9r __module__ __qualname__rr staticmethodr'r9rJrMrZrdrorxr}rrrrrrrrrrrrrrrrrmrrrrrrrrtuplerrrrrrlrkrrrrrrrrrrrrrr's999     \ \\,$$$""   *        """"<!!!)))  ^   ^   ^   ^     ^  (Y $   ^ &  ^   ^   ^   ^    ^    ^   ^   ^    ^    ^   ^   ^   ^\ $U7C<-@$$$$\\\ c c   \ sCC\\\    \ OOOrr)r3r rRrpwdrclcommon.featuresrclcommon.cpapi.cpapiexceptionsrr clcommon.lockrrrrr@rrrrrs '&&&&& @5$zzzzzzzzzzr