AlkantarClanX12

Your IP : 18.118.149.55


Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/clsummary/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/clsummary/__pycache__/utils.cpython-311.pyc

�

�ug�+��x�ddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZddlm
Z
mZddlmZddlmZmZddlmZddlmZddlmZdd	lmZdd
lmZd�Z	ddl m!Z!dd
l"m#Z#n#e$$reZ!eZ#YnwxYwdZ%dZ&dZ'dZ(ej)�*e(d��Z+dZ,da-dZ.dZ/Gd�d��Z0d�Z1d�Z2d5d�Z3d�Z4d�Z5d6de6d e7d!e7fd"�Z8de6d#e7d!dfd$�Z9d!e7fd%�Z:d!e7fd&�Z;d'e7d!dfd(�Z<d'e7d!dfd)�Z=d*�Z>d+�Z?d,�Z@d-�ZAd.�ZBd/�ZCd0�ZDd1�ZEd6d!ee	e
ee
e7fffd2�ZFd3�ZGd!ee
fd4�ZHdS)7�N)�Optional�Dict�AnyStr�Union)�decode�
exceptions)�DEFAULT_JWT_ES_TOKEN_PATH)�
WhmApiRequest�WhmApiError)�mkdir)�process_is_running)�check_cagefs_initialized)�CL_CONFIG_FILE)�write_file_via_tempfilec��dS)N�)�a�kws  �F/opt/cloudlinux/venv/lib64/python3.11/site-packages/clsummary/utils.py�dummy_none_functionrs���4���"interpreter_versions_short_summary)�is_clpassenger_active�
license_check�cl_statistics_enabled�cl_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/virtualenvc��eZdZdZdZdZdZdS)�
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_progress�failedN)�__name__�
__module__�__qualname__�__doc__�SUCCESS�IN_PROGRESS�FAILEDrrrrr4s)���������G��K�
�F�F�Frrc�J�tj�t��S)zS
    Checks is virtualenv installed
    :return: True/False - installed or not
    )�os�path�exists�ALT_PYTHON_VIRTUALENV_BINrrr�is_virtualenv_installedr/@s��
�7�>�>�3�4�4�4rc	��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)	�struct�pack�fcntl�F_WRLCK�F_GETLK�unpack�OSError�IOError�F_UNLCK)�	lock_file�	lock_data�
lock_query�lock_statuss    r�	is_lockedr?Hs�����H�e�m�Q��1�a��C�C�I���[��E�M�9�E�E�
��m�H�j�9�9�!�<�����W������u�u������%�-�'�'s�;A"�"A7�6A7Fc��ttdd���a|stt��S	t	jttjtjz��n#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
    �w�utf-8��encodingTF)
�open�_CL_STATISTICS_LOCK_PATH�_CL_STATISTICS_LOCK_FILEr?r4�lockf�LOCK_EX�LOCK_NBr8r9)�acquire_locks r�is_sending_process_runningrL]s��� $� �#�� � � ���3��1�2�2�2��
��,�e�m�e�m�.K�L�L�L�L���W������t�t������5s�1A!�!A6�5A6c�~�tjdd���}t|_|�t
��|S)zW
    Retrieves ConfigParser object for /etc/sysconfig/cloudlinux file
    :return:
    NT)�
interpolation�strict)�configparser�ConfigParser�str�optionxform�readr)�configs r�_get_configrVqs?��
�
&�T�.2�4�4�4�F��F��
�K�K������Mrc���	tj��}|�|��|���}t	|t
dd���n#ttf$rYdSwxYwdS)z�
    write config to /etc/sysconfig/cloudlinux file
    :param config: configParser object to write
    return boolean: True|False
    i��cloudlinux_��prefixFT)�io�StringIO�write�getvaluerrr8r9)rU�	string_fp�contents   r�
_write_configra}s{����K�M�M�	����Y�����$�$�&�&������}�U�U�U�U�U���W������u�u������4s�AA�A,�+A,T�	parameter�default�returnc��t��}|}	|�t|��}n'#tjtjtf$rYnwxYw|S)zi
    Retrieves parameter's value from /etc/sysconfig/cloudlinux file, _CL_STATISTICS_SECTION section
    )rV�
getboolean�_CL_STATISTICS_SECTIONrP�NoSectionError�
NoOptionError�
ValueError)rbrcrU�ress    r�_get_config_valuerl�sc���]�]�F�
�C�
���� 6�	�B�B�����'��)C�Z�P�
�
�
���
�����Js�.�!A�A�valuec	��t��}|�t|tt	|������t|��dS)zb
    Sets parameter's value to /etc/sysconfig/cloudlinux file, _CL_STATISTICS_SECTION section
    N)rV�setrgrR�intra)rbrmrUs   r�_set_config_valuerq�sD���]�]�F�
�J�J�%�y�#�c�%�j�j�/�/�B�B�B��&�����rc�*�tt��S)z~
    Retrieves statistic collection status from /etc/sysconfig/cloudlinux file
    :return: True/False - enabled/disabled
    )rl�#_CL_STATISTICS_COLLECT_STATE_OPTIONrrr�is_statistic_enabledrt�s��
�@�A�A�Arc�*�tt��S)z�
    Retrieves rpm statistic collection status from /etc/sysconfig/cloudlinux file
    :return: True/False - enabled/disabled
    )rl�'_CL_STATISTICS_COLLECT_RPM_STATE_OPTIONrrr�is_statistic_rpm_enabledrw�s��
�D�E�E�Er�
is_enabledc�0�tt|��dS)z�
    Set statistic collection status to /etc/sysconfig/cloudlinux file
    :param is_enabled: True/False - enabled/disabled
    N)rqrs�rxs r� set_statistic_collection_enabledr{�s��
�9�:�F�F�F�F�Frc�0�tt|��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��
�=�z�J�J�J�J�Jrc��	tj�t��st	t��tj|��}t|tdd���dS#ttf$rYdSwxYw)z�
    Writes statistics send status to file /var/lve/summary_status.json
    :param status_dict: status dictionary for write to file
    :return:
    i�rXrYN)r+r,r-�_CL_STATISTICS_DIR�mkdir_p�json�dumpsr�_CL_STATISTICS_SEND_STATUS_FILEr8r9)�status_dictr`s  r�$write_statistics_send_status_to_filer��s���
��w�~�~�0�1�1�	(��&�'�'�'��*�[�)�)����)H�%�Xe�f�f�f�f�f�f���W��
�
�
����
���s�A$A(�(A=�<A=c�|�d}	ttd���5}|���}ddd��n#1swxYwYtj|��}|dt
jkr"t��st
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
    NrBrC�resultzaCollecting statistics was failed. Error report has been sent to developers and will be fixed soon�reason)rEr�rTr��loadsrr(rLr)r8r9rj�AttributeError�	TypeError)r��f�	s_contents   r�$get_statistics_send_status_from_filer��s���
�K�
�
�1�G�
D�
D�
D�	!�������I�	!�	!�	!�	!�	!�	!�	!�	!�	!�	!�	!����	!�	!�	!�	!��j��+�+���x� �M�$=�=�=�2�4�4�>�%2�$8�K��!�%`�K��!����W�j�.�)�D�
�
�
���
�����s/�B�;�B�?�B�?�AB�#B9�8B9c�4�d�t|��D��S)z�
    Returns list of installed interpreters
    :param interpreter: str - name of interpreter
    :rtype: List of InterpreterSummary
    c� �g|]}|j�	|��Sr)�	installed)�.0�is  r�
<listcomp>z/installed_interpreters_list.<locals>.<listcomp>�s��V�V�V�!�!�+�V�A�V�V�Vrr)�interpreters r�installed_interpreters_listr��s"��W�V�9�+�F�F�V�V�V�Vrc�:�t��o
t��S)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/rrr�is_python_selector_installedr�����!�"�"�@�'>�'@�'@�@rc�:�t��o
t��S)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
    r�rrr�is_ruby_selector_installedr��r�rc�V�t��ottd����S)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)r�boolr�rrr�is_nodejs_selector_installedr�s&��!�"�"�R�t�,G��,Q�,Q�'R�'R�Rrc�8�tt����S)zn
    Checks that php selector is installed
    Installed if:
    - CageFS is initialized
    :rtype: bool
    )r�rrrr�is_php_selector_installedr�s���(�*�*�+�+�+rc��	td�����}n#t$rgcYSwxYwd�|dD��}|S)z9
    Gets packages with set lve limits via extension
    �listpkgsc�>�g|]}d|v�|ddk�|d��S)�_PACKAGE_EXTENSIONS�lve�namer)r��items  rr�z4get_packages_with_lve_extensions.<locals>.<listcomp>%sD��j�j�j��"7�4�"?�"?�D�I^�D_�ch�Dh�Dh� $�F�|�Dh�Dh�Dhr�pkg)r
�callr)r��lve_extensions_packagess  r� get_packages_with_lve_extensionsr�ss����z�*�*�/�/�1�1���������	�	�	�����j�j��u�
�j�j�j��"�"s�!$�3�3c	�B�	ttd���5}|������}ddd��n#1swxYwYn#tt
f$rYdSwxYw	t
|dgd|ddd�d�	��}|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)�modeN�HS256TF)�require_exp�
verify_exp�
verify_iss�verify_signature�
CloudLinux)�
algorithms�options�issuer)	rEr	rT�stripr8r9rr�
PyJWTError)�check_expiration�file�file_content�	jwt_tokens    r�get_client_data_from_jwt_tokenr�*s���
�+�$�
7�
7�
7�	/�4��9�9�;�;�,�,�.�.�L�	/�	/�	/�	/�	/�	/�	/�	/�	/�	/�	/����	/�	/�	/�	/����W������t�t�����
��<�W�I�37�2B�26�8=�$?�$?�#/�0�0�0�	����� �����t�t����sE�A�'A�A�A�A�A�A�A,�+A,�0B�B�Bc��|sdS|�d��sdSttj����t|�d����kS)z.
    Checks whether license ts is expired
    N�exp)�getrp�time)�
token_datas r�is_active_cloudlinux_licenser�CsW�����t��>�>�%� � ���t��t�y�{�{���c�*�.�.��"7�"7�8�8�8�8rc�`�	ttd��}n#t$rd}YnwxYw|rdndS)z�
    Retrieves data from status of cl_plus_sender service
    :return: status of service, Optional[AnyStr]
    - 'active'
    - 'inactive'
    F�active�inactive)r
�CL_PLUS_SENDER_FILE_PATH�FileNotFoundError)r�s r�get_cl_plus_sender_statusr�NsL���#�$<�e�D�D�����������������-�8�8�:�-s��'�')F)T)IrPr[r+r�r4r2r��typingrrrr�jwtrr�clcommon.lib.constsr	�clcommon.lib.whmapi_libr
r�clcommon.clcaptainrr��clcommon.utilsr
�!clconfig.cagefs_statistics_configr�cldetectlibr�secureiorr�clselect.clselectctlr� clselector.clpassenger_detectlibr�ImportErrorrgrsrvrr,�joinr�rFrGr�r.rr/r?rLrVrarRr�rlrqrtrwr{r}r�r�r�r�r�r�r�r�r�r�r�rrr�<module>r�s������	�	�	�	�	�	�	�	���������
�
�
�
�����0�0�0�0�0�0�0�0�0�0�0�0�"�"�"�"�"�"�"�"�9�9�9�9�9�9�>�>�>�>�>�>�>�>�/�/�/�/�/�/�-�-�-�-�-�-�F�F�F�F�F�F�&�&�&�&�&�&�,�,�,�,�,�,����0�G�G�G�G�G�G�F�F�F�F�F�F�F���0�0�0�)<�&�/����0����
)��&=�#�*E�'���"$�'�,�,�/A�CX�"Y�"Y��B����K��A��	�	�	�	�	�	�	�	�5�5�5�(�(�(�*����(	�	�	�
�
�
� ����t��t��������T��d�����B�d�B�B�B�B�F�$�F�F�F�F�G��G�$�G�G�G�G�K�T�K�d�K�K�K�K�

�

�

� ���*W�W�W�A�A�A�A�A�A�S�S�S�,�,�,�
#�
#�
#���X�d�6�SX�Y_�ae�Ye�Sf�Kf�Fg�=h�����29�9�9�.�8�F�#3�.�.�.�.�.�.s�!A.�.	A:�9A: