asda?‰PNG  IHDR ? f ??C1 sRGB ??é gAMA ±? üa pHYs ? ??o¨d GIDATx^íüL”÷e÷Y?a?("Bh?_ò???¢§?q5k?*:t0A-o??¥]VkJ¢M??f?±8\k2íll£1]q?ù???T 3 Ui:@sddlZddlZddlZddlZddlZddlZddlmZddlm Z ddlm Z ddlm Z ddl m Z mZmZmZmZddl mZmZmZmZmZmZmZddlZGdd d eZdd d ZdddZdddZdddZddZ ddZ!ddZ"dS)N)get_cp)criu_settings_malfunctions)lsapi_settings_malfunctions)liblsapi_malfunctions) cpanel_whmapiplesk_bin_php_handlerdump_loaded_modules dump_lsapi query_strings)get_da_domainsget_da_php_optionsread_da_config liblsapi_pathpretty_version_keys count_domainsStatUtilsExceptionc@s eZdZdS)ModLsapiStatExceptionN)__name__ __module__ __qualname__rr//usr/share/lve/modlscapi/user/mod_lsapi_stat.pyrsrFcCsd}i}t}yd|jdkr8tjjdr2t|d<qpd}n8|jdkrNt|d<n"|jdkrdt|d<n dj|j}Wn*t k r}zt |}WYdd}~XnX|dk rt |d<||d <t ||d <|j t |j t|j d t|djit||rtj|d d S|SdS)a Return statistics data :param as_json: return json string if True, dict otherwise :return: statistics data dict( `controlPanel`: EA3/EA4/Plesk/DirectAdmin/Unknown CP, `criu`: dict( `status`: running/stopped, `version`: version ), `domainStat`: dict( `version`: `domains_num`, ... ) or dict(`error`: description) if some error occurred, `lsapiConf`: dict( lsapi_with_connection_pool: on/off, lsapi_criu: on/off ) ) or its json-packed version NcPanelz/etc/cpanel/ea4/is_ea4Z domainStatz7mod_lsapi domains stat is currently unsupported for EA3Plesk DirectAdminz7mod_lsapi domains stat is currently unsupported for {0}ZdomainStatErrorZ controlPanelZ totalDomainT)Z sort_keys)rnameospathexistsget_cpanel_ea4_statget_plesk_stat get_da_statformatrstrdictupdateget_lsapi_conf get_crui_statsumvaluesanalyze_malfunctionsjsondumps)as_jsonerrorZstatsZ control_panelerrrget"s4           r0Tc Cs`t}t}t}y tdjd}x@|D]8}|j|jdtj|jd|jd||jd<q*Wtdjd}tdd |D}t|j} x6|jD]*\} } |j| tj | |j| tiqW|rt j |||} | }x:|jD].\} }|j tj t| j t|jtqWWn4tttfk rRtd jtjjd YnXt|| |S) aY Collect mod_lsapi statistics for cPanel EA4 through WHM API :param lsapi_only: return only lsapi domains statistics if True, or full statistics if False :param with_selector: take into account the statistics of php selector :return: if lsapi_only return lsapi domains per version stat dict( `version`: `domains_num`, ... ) else return full statistics per handler stat dict( `handler`: {`version`: `domains_num`, ... } ... ) Zphp_get_vhost_versionsZversionsversionvhostZaccountZphp_get_handlersversion_handlerscSs g|]}|jd|jdfqS)r1Zcurrent_handler)r0).0hrrr tsz'get_cpanel_ea4_stat.. )r$rr0 setdefaultsetaddlistkeysitemsr%selector_usage_libZea4_selector_checkfromkeys differenceKeyError TypeErrorrrjoin traceback format_excsplitr) lsapi_only with_selectorZdomains_per_versionZ handlers_statZ domain_usersZ vhosts_datar2Z handlers_datar3Z all_versionsZverhandlerZs_checked_version_handlersr5vrrrrYs*   &.rc Csd}d}t}ytd}dd|D}x||D]t}|jd}dj|jdjd d d} td dtd |dD} d|krd} |j| d}n |j| d} | || <q,W|rtj||}Wn8t t t t tj fk rtdjtjjdYnXddd|jDi} |r| dS| S)a Collect mod_lsapi statistics for Plesk Collects lsapi domains ONLY :param lsapi_only: return only lsapi domains statistics if True, or full statistics if False :param with_selector: take into account the statistics of php selector :return: if lsapi_only return lsapi domains per version dict( `version`: `domains_num` ... ) else return stats with handler dict( `lsapi`: {`version`: `domains_num`, ... } ) z alt-php{v}z alt-php56r<cSsg|]}d|jdkr|qS)Zlsphpid)r0)r4r5rrrr6sz"get_plesk_stat..rLr7Z fullVersion.NcSsg|]}|jdqS)domain)r0)r4drrrr6sz get-usage)rLZcustom)rKr8ZlsapicSsi|]\}}t||qSr)len)r4krKrrr sz"get_plesk_stat..)r$rr0rDrGr:r"r?Zplesk_selector_checkrBrCAttributeErrorrZSelectorStatExceptionrrErFr>) rHrIZ handler_tmplZcustom_versionZdomain_version_statZ all_handlersZlsphp_handlersrJZ handler_idZ php_versiondomainsZ version_idZ result_statrrrr s*    r cs d}t}yt}|dd}|dd}|dd}|dd}t|} t|} t} tfdd| jD|dkr| i} | i||<n|dkr| i} | i||<n| t| ti} x| jD]\} }x|D]x}|j| |d }y/usr/local/directadmin/data/users/{user}/domains/{domain}.confrNr1rJcsg|]}j|qSr)r%)r4rK)joinedrrr6szget_da_stat..no)userrOZ php1_selectr7r8)r$r rr r:r)r>r"r Zgetintr0r; configparserZ NoOptionErrorr?Zda_selector_checkr%rBrCrUrrrDrErFrGr)rHrIZdomain_conf_pathZ handler_statZ php_optionsZphp1_verZphp2_verZ php1_handlerZ php2_handlerZ php1_labelZ php2_labelZ user_domainsZ version_statrZrVrOZ config_pathZ conf_parserZglobal_sectionZ php_settingr1Zselector_updatedr)rXrr!sV        r!c Csndjtjd}y"tjdddgtjtjdd}Wntjk rLd}YnXd||rd|jd d nd d iS) z Get criu service info :return: dict( `criu`: dict( `status`: running/stopped, `version`: version ) ) r7z/usr/sbin/criu -Vz /sbin/servicecriustatus)stdoutstderrZrunningstopped rNz not installed)r]r1)rD exec_command subprocessZ check_callZDEVNULLZCalledProcessErrorrG)Z criu_versionZcriu_service_statusrrrr's  r'cCsTt}t}|jdd}|jdd|jddd|jddttd|sLd nd d S) al Retrieve lsapi configuration: - crui - connection pool and versions of module and library :return: dict( lsapiConf: dict( lsapi_with_connection_pool: on/off, lsapi_criu: on/off ), modVersion: version, libVersion: version ) Z lsapi_moduleN lsapi_criuZofflsapi_with_connection_pool)rdrer1Zliblsapi_versionZdisabledZenabled) lsapiConfZ modVersion libVersion modStatus)r rr0r r)Z apache_confZapache_modulesZ mod_statusrrrr&s    r&csttfdd}dj|dd|ddd}|d }|t|d |t||t|sbd S|jd id S) z Detect configuration malfunctions and update resulting statistics dict accordingly For now only criu malfunctions are presented See malfunctions in dashboard_malfunctions.py module :param stats_dict: resulting statistics dict c s,yj||Wntk r&YnXdS)N)appendrB)Z malfunc_dictkey) malfunctionsrradd_malfunctionHsz-analyze_malfunctions..add_malfunctionz {opt}_{serv}rfrdr\r])optZservrhrgNrk)r<r"rrrr%)Z stats_dictrlZ criu_settingsZlsapi_settingsr)rkrr*?s   r*)F)TT)TT)TT)#rr+rErcr[rblve_diagnosticrZdashboard_malfunctionsrrr stat_utilsrrrr r r r r rrrrr? Exceptionrr0rr r!r'r&r*rrrrs(    $ 7 1 , O