?Hg+xddlZddlZddlZddlZddlZddlZddlZddlmZm Z m Z m Z ddl m Z mZddlmZddlmZmZddlmZddlmZddlmZdd lmZdd lmZd Z dd l m!Z!dd l"m#Z#n#e$$reZ!eZ#YnwxYwdZ%dZ&dZ'dZ(ej)*e(dZ+dZ,da-dZ.dZ/GddZ0dZ1dZ2d5dZ3dZ4dZ5d6de6d e7d!e7fd"Z8de6d#e7d!dfd$Z9d!e7fd%Z:d!e7fd&Z;d'e7d!dfd(Zd+Z?d,Z@d-ZAd.ZBd/ZCd0ZDd1ZEd6d!ee e e e e7fffd2ZFd3ZGd!ee fd4ZHdS)7N)OptionalDictAnyStrUnion)decode exceptions)DEFAULT_JWT_ES_TOKEN_PATH) WhmApiRequest WhmApiError)mkdir)process_is_running)check_cagefs_initialized)CL_CONFIG_FILE)write_file_via_tempfilecdS)N)akws D/opt/cloudlinux/venv/lib/python3.11/site-packages/clsummary/utils.pydummy_none_functionrs 4"interpreter_versions_short_summary)is_clpassenger_active license_checkcl_statistics_enabledcl_statistics_rpm_enabledz/var/lvezsummary_status.jsonz%/var/run/cloudlinux_summary.send.lockz./usr/share/cloudlinux/cl_plus/clplus_sender.pyz#/opt/cloudlinux/venv/bin/virtualenvceZdZdZdZdZdZdS) SummaryStatusz Status of both, collecting and sending statistics If process still collects statistics -> IN_PROGRESS If statistics collected and sent correctly -> SUCCESS If any error during collecting or sending -> FAILED success in_progressfailedN)__name__ __module__ __qualname____doc__SUCCESS IN_PROGRESSFAILEDrrrrr4s) GK FFFrrcJtjtS)zS Checks is virtualenv installed :return: True/False - installed or not )ospathexistsALT_PYTHON_VIRTUALENV_BINrrris_virtualenv_installedr/@s 7>>3 4 44rc tjdtjddddd} tj|tj|}tjd|d}n#t tf$rYdSwxYw|tjkS)a$ Check if file is locked by another process without acquiring lock. IMPORTANT! This function should NOT be used to check lock acquired by the same process that executes the is_locked() function. For example, when process executes fcntl.lockf(LOCK_FILE), and then the same process executes is_locked(LOCK_FILE), the is_locked(LOCK_FILE) call returns False. Use is_locked() function to check lock acquired by another process only. :param lock_file: file to check lock on :type lock_file: file object or descriptor hhllhhrF) structpackfcntlF_WRLCKF_GETLKunpackOSErrorIOErrorF_UNLCK) lock_file lock_data lock_query lock_statuss r is_lockedr?Hs HemQ1aCCI[EM9EE mHj99!< W uu %- ''s;A""A76A7Fcttdda|sttS t jttjtjzn#ttf$rYdSwxYwdS)z Check if processes collecting stats are running already (with --send option in command line) :param acquire_lock: True = acquire lock when possible :type acquire_lock: bool :return bool: True = Processes are running wutf-8encodingTF) open_CL_STATISTICS_LOCK_PATH_CL_STATISTICS_LOCK_FILEr?r4lockfLOCK_EXLOCK_NBr8r9) acquire_locks ris_sending_process_runningrL]s $ #    31222 ,emem.KLLLL W tt 5s1A!!A65A6c~tjdd}t|_|t |S)zW Retrieves ConfigParser object for /etc/sysconfig/cloudlinux file :return: NT) interpolationstrict) configparser ConfigParserstr optionxformreadr)configs r _get_configrVqs?  &T.2444FF KK Mrc tj}|||}t |t ddn#t tf$rYdSwxYwdS)z write config to /etc/sysconfig/cloudlinux file :param config: configParser object to write return boolean: True|False i cloudlinux_prefixFT)ioStringIOwritegetvaluerrr8r9)rU string_fpcontents r _write_configra}s{ KMM  Y$$&&}UUUUU W uu 4sAAA,+A,T parameterdefaultreturnct}|} |t|}n'#tjtjt f$rYnwxYw|S)zi Retrieves parameter's value from /etc/sysconfig/cloudlinux file, _CL_STATISTICS_SECTION section )rV getboolean_CL_STATISTICS_SECTIONrPNoSectionError NoOptionError ValueError)rbrcrUress r_get_config_valuerlsc]]F C  6 BB  ')CZ P      Js.!AAvaluec t}|t|tt |t |dS)zb Sets parameter's value to /etc/sysconfig/cloudlinux file, _CL_STATISTICS_SECTION section N)rVsetrgrRintra)rbrmrUs r_set_config_valuerqsD]]F JJ%y#c%jj//BBB&rc*ttS)z~ Retrieves statistic collection status from /etc/sysconfig/cloudlinux file :return: True/False - enabled/disabled )rl#_CL_STATISTICS_COLLECT_STATE_OPTIONrrris_statistic_enabledrts @ A AArc*ttS)z Retrieves rpm statistic collection status from /etc/sysconfig/cloudlinux file :return: True/False - enabled/disabled )rl'_CL_STATISTICS_COLLECT_RPM_STATE_OPTIONrrris_statistic_rpm_enabledrws D E EEr is_enabledc0tt|dS)z Set statistic collection status to /etc/sysconfig/cloudlinux file :param is_enabled: True/False - enabled/disabled N)rqrsrxs r set_statistic_collection_enabledr{s 9:FFFFFrc0tt|dS)z Set rpm statistic collection status to /etc/sysconfig/cloudlinux file :param is_enabled: True/False - enabled/disabled N)rqrvrzs r$set_statistic_rpm_collection_enabledr}s =zJJJJJrc tjtst tt j|}t|tdddS#ttf$rYdSwxYw)z Writes statistics send status to file /var/lve/summary_status.json :param status_dict: status dictionary for write to file :return: irXrYN) r+r,r-_CL_STATISTICS_DIRmkdir_pjsondumpsr_CL_STATISTICS_SEND_STATUS_FILEr8r9) status_dictr`s r$write_statistics_send_status_to_filers  w~~011 ( & ' ' '*[)))H%Xeffffff W      sA$A((A=<A=c|d} ttd5}|}dddn #1swxYwYtj|}|dt jkr"tst j|d<d|d<n)#tttttf$rYnwxYw|S)z Retrieves statistics send status from file /var/lve/summary_status.json :return: Dictionary with last send status. None if any error NrBrCresultzaCollecting statistics was failed. Error report has been sent to developers and will be fixed soonreason)rErrTrloadsrr(rLr)r8r9rjAttributeError TypeError)rf s_contents r$get_statistics_send_status_from_filers K  1G D D D !I ! ! ! ! ! ! ! ! ! ! ! ! ! ! !j++ x M$= = =244 >%2$8K !%`K ! Wj.) D     s/B; B?B?AB#B98B9c4dt|DS)z Returns list of installed interpreters :param interpreter: str - name of interpreter :rtype: List of InterpreterSummary c g|] }|j | Sr) installed).0is r z/installed_interpreters_list..s V V V!!+ VA V V Vrr) interpreters rinstalled_interpreters_listrs" W V9+FF V V VVrc:to tS)z Checks that python selector is installed Installed if: - ea-apache24-mod-alt-passenger or alt-mod-passenger is installed - alt-python-virtualenv is installed :rtype: bool rr/rrris_python_selector_installedr ! " " @'>'@'@@rc:to tS)z Checks that ruby selector is installed Installed if: - ea-apache24-mod-alt-passenger or alt-mod-passenger is installed - alt-python-virtualenv is installed :rtype: bool rrrris_ruby_selector_installedrrrcVtottdS)z Checks that nodejs selector is installed Installed if: - ea-apache24-mod-alt-passenger or alt-mod-passenger is installed - At least one version is installed :rtype: bool nodejs)rboolrrrris_nodejs_selector_installedrs& ! " " Rt,G,Q,Q'R'RRrc8ttS)zn Checks that php selector is installed Installed if: - CageFS is initialized :rtype: bool )rrrrris_php_selector_installedrs (** + ++rc td}n#t$rgcYSwxYwd|dD}|S)z9 Gets packages with set lve limits via extension listpkgsc>g|]}d|v|ddk|dS)_PACKAGE_EXTENSIONSlvenamer)ritems rrz4get_packages_with_lve_extensions..%sDjjj"74"?"?DI^D_chDhDh $F|DhDhDhrpkg)r callr )rlve_extensions_packagess r get_packages_with_lve_extensionsrssz**//11  jju jjj ""s !$ 33c B ttd5}|}dddn #1swxYwYn#tt f$rYdSwxYw t |dgd|dddd }|S#tj$rYdSwxYw) z Gets (if any) fields cl_plus and client_id from jwt token :return: decoded jwt_token value, None if error jwt_token: result of the successful decoding rb)modeNHS256TF) require_exp verify_exp verify_issverify_signature CloudLinux) algorithmsoptionsissuer) rEr rTstripr8r9rr PyJWTError)check_expirationfile file_content jwt_tokens rget_client_data_from_jwt_tokenr*s  +$ 7 7 7 /499;;,,..L / / / / / / / / / / / / / / / W tt >% t ty{{  c*.."7"788 88rc` ttd}n#t$rd}YnwxYw|rdndS)z Retrieves data from status of cl_plus_sender service :return: status of service, Optional[AnyStr] - 'active' - 'inactive' Factiveinactive)r CL_PLUS_SENDER_FILE_PATHFileNotFoundError)rs rget_cl_plus_sender_statusrNsL#$rs 000000000000""""""""999999>>>>>>>>//////------FFFFFF&&&&&&,,,,,,0GGGGGGFFFFFFF000)<&/0 )&=#*E'"$',,/ACX"Y"YBKA        555(((*(         t t    TdBdBBBBF$FFFFGG$GGGGKTKdKKKK    *WWWAAAAAASSS,,, # # #Xd6SXY_aeYeSfKfFg=h2999 .8F#3 . . . . . .s! A.. A:9A: