Edit File: utils.cpython-311.pyc
� �����e�p��������������� ������������d�dl�mZ�d�dl�mZ�d�dl�mZ�d�dlZd�dlZd�dlZd�dlZd�dlZd�dl Z d�dl Z d�dlZd�dlZd�dl Z d�dlmZ�d�dlmZmZ�d�dlmZmZmZmZmZmZ�d�dlZd�dlmZ�d�dlZd�d lmZ�d�d l m!Z!m"Z"m#Z#m$Z$�dZ%dZ&d Z'd��Z(dKd�Z)d��Z*d��Z+d��Z,d��Z- � � � � �dLd�Z.d��Z/dee0���������fd�Z1d��Z2de3fd�Z4dee0���������fd�Z5�ed�������������dee0���������fd���������������Z6de7fd �Z8d!e0de3fd"�Z9de3fd#�Z:de3fd$�Z;d%��Z<d&��Z=d'��Z>d(��Z?d)��Z@d*��ZAd+��ZBd,e0de3fd-�ZCd.e7de3fd/�ZDd0edee3���������fd1�ZEde7fd2�ZFd3e0dee3e3f���������fd4�ZGd3e0dee3e3f���������fd5�ZHd3e0dee3e3f���������fd6�ZId7e0d8e3de3fd9�ZJd:ee j ��������e jK��������f���������de0fd;�ZL �dKd<e0d=e0d>e0d?e7dee7e0f���������f d@�ZMde0fdA�ZNde3fdB�ZOdCe0dee7���������fdD�ZPdCe0fdE�ZQdCe0fdF�ZRdG��ZSdHe0de0fdI�ZTde3fdJ�ZUdS�)M�����)�print_function)�absolute_import)�divisionN)� lru_cache)�ConfigParser�Error)�Dict�Any�AnyStr�Optional�Tuple�Union)�etree)� is_ubuntu)� check_command�run_command�exec_utility�ExternalProgramFailedz/etc/sysconfig/rhn/systemid)�Mon�Tue�Wed�Thu�Fri�Sat�Sunz /opt/cloudlinux/litespeed_statusc����������������������d}t�����������j�����������������������������|������������r& �t����������j��������|������������}n#�t����������$�r�Y�nw�xY�w|�|k����r= �t����������j��������|�������������n#�t����������$�r�Y�nw�xY�wt����������j��������|�|�������������dS�dS�)a�� Create symlink link_path -> link_value if it does not exist or points to different location :param link_value: path that symlink should point to (symlink value) :type link_value: str :param link_path: path where to create symlink :type link_path: str N)�os�path�islink�readlink�OSError�unlink�symlink)� link_value� link_path�link_tos��� ��/builddir/build/BUILDROOT/alt-python27-cllib-3.3.5-1.el8.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/utils.py�create_symlinkr(���2���s���������G� �w�~�~�i� � ��� ��k�)�,�,�G�G���� �� �� ��D� �����W��� ��I�i� � � � ���� �� �� ��D� ���� � �:�y�)�)�)�)�)���s!����8�� A�A�A$��$ A1�0A1c������������������������g�}t�����������j�����������������������������|�������������r>t����������|�d|�������������5�}|�����������������������������������}ddd�������������n#�1�swxY�w�Y���|S�)a�� Read file and return file's lines errors param may be passed to define how handle unicode errors, errors=None is default value of open() :param path: path to file :param unicode_errors_handle: how to handle unicode errors :return: list of file's lines �r)�errorsN)r���r����isfile�open� readlines)r����unicode_errors_handle�content�fs��� r'����get_file_linesr2���I���s���������G� �w�~�~�d����$� �$��$9� :� :� :�� $�a��k�k�m�m�G� $�� $�� $�� $�� $�� $�� $�� $�� $�� $�� $����� $�� $�� $�� $��Ns����A�A�Ac�����������������������t����������|�|������������5�}|���������������������|�������������ddd�������������dS�#�1�swxY�w�Y���dS�)z� Write lines to file :param content: list of lines for writing to file :param path: path to file :param mode: open mode :return: None N)r-���� writelines)r���r0����moder1���s��� r'����write_file_linesr6���Z���s�������� �d�D� � ���Q� ���W�����������������������������������������s����4�8�8c������������������������t����������|�������������}�fd�|D���������������}t����������|������������t����������|������������k����}t����������|�|d�������������|S�)a�� Delete line from file. Return True when line(s) have been deleted, False otherwise (specified line is not found) :param path: path to file :type path: string :param line: line to delete without EOL (' ') :type line: string :rtype bool c������������������F������g�|�]}�|����������������������d�������������k�����|��S�)� )�rstrip)�.0�item�lines��� �r'���� <listcomp>z)delete_line_from_file.<locals>.<listcomp>q���s/�������O�O�O�t�T�T�[�[��=N�=N�5N�5N�d�5N�5N�5N������w+)r2����lenr6���)r���r=���� file_lines�out_file_lines�founds��� ` r'����delete_line_from_filerE���g���sZ�������� ��%�%�J�O�O�O�O�z�O�O�O�N�� �O�O�s�>�2�2�2�E��T�>�4�0�0�0��Lr?���c�������������������L����t����������j����������������������}�|�dk����r� �t����������j��������d������������j��������}|t����������j����������������������v�st����������j����������������������|k����rdS�n#�t����������$�r�Y�nw�xY�wt����������dt����������j ����������������������t����������j��������d�������������dS�dS�)zH Check whether current user is effectively root and exit if not r���� clsupergidNz'Error: root privileges required. Abort.)�file���)r����geteuid�grp�getgrnam�gr_gid� getgroups�getegid�KeyError�print�sys�stderr�exit)�euidrM���s��� r'����is_root_or_exitrV���x���s���������:�<�<�D��q�y�y� ���\�,�/�/�6�F������'�'�2�:�<�<�6�+A�+A����,B���� �� �� ��D� ���� �7�c�j�I�I�I�I�����������ys����AA#��# A0�/A0c�������������������@�����t�����������j�����������������������������d������������S�)zV Detects is EA4 installed :return: True - EA4 present; False - EA4 absent z/etc/cpanel/ea4/is_ea4)r���r���r,�����r?���r'����is_ea4rY�������s������ ��7�>�>�2�3�3�3r?���FTc��������������#������K����|�t����������|������������}d}|sA|����������������������d������������s|sd���������������������|�������������}�t����������j��������|�������������}nd}|D�]`}|r6|r|���������������������|�������������dk����r|}n/|���������������������|�������������r|}n|���������������������|������������r|}|r|�|V���n|��nd}�a|�|V���dS�dS�)a�� Grep pattern in file :param multiple_search: if True - search all match, False - search first match :param pattern: pattern for search :param path: path to file :param data_from_file: read data from file for parsing :param fixed_string: if True - search only fixed string, False - search by regexp :param match_any_position: if True - search any match position, False - search only from string begin :return: Generator with matched strings N�^z^{}rI���)r2���� startswith�format�re�compile�find�search) �patternr����fixed_string�match_any_position�multiple_search�data_from_file�result�pattern_compr=���s ��� r'����grepri�������s%���������*���'��-�-�� �F������!�!�#�&�&�� ,�/A�� ,��l�l�7�+�+�G��z�'�*�*������� �� ���� �!�� �d�i�i��&8�&8�B�&>�&>��������)�)�� �����"�"�4�(�(�� ����� �v�1��L�L�L�L� � ��E���� ����������r?���c�������������������4�����t����������j��������t����������������������S�)z- :rtype: lxml.etree._ElementTree obj )r����parse�RHN_SYSTEMID_FILErX���r?���r'����_parse_systemid_filerm�������s��������;�(�)�)�)r?����returnc������������������(���� �t������������������������}|���������������������d������������D�]B}|���������������������d������������j��������|�k����r"|���������������������d������������d���������j��������c�S��Cn)#�t����������t ����������t����������t����������j��������f$�r�Y�dS�w�xY�wdS�)z` find a member in xml by name and return value :type name: str :rtype: str|None �member�name�valuer���N) rm����iterr`����text�IOError� IndexErrorrP���r���� ParseError)rq����rhn_systemid_xmlrp���s��� r'����get_rhn_systemid_valuery�������s��������/�1�1��&�+�+�H�5�5�� 4�� 4�F��{�{�6�"�"�'�4�/�/��{�{�7�+�+�A�.�3�3�3�3��0� 4��� �Z��5�+;�<��������t�t������4s����A$A)��'A)��)"B�Bc����������������������dd|�z��d�}t�����������j�����������������������������|�������������s|S� �t����������j��������d|�z��gddd������������������������������������������������}t����������j��������d|z��gddd������������������������������������������������}d|d <���||d <���n1#�t����������j��������t����������f$�r}d|��d|�d �}||d <���Y�d}~nd}~ww�xY�w|S�)aZ�� This function is written for detect file system in which file is stored on. E.g., the file can be stored in NFS and this can affect the normal operation of the file. We want to receive information about FS in emergency situations during reading or writing :param file_path: path to file, for which we want to detect file system :return: dict, which contains two keys: key 'success' can be equals to False if we got error or True if we got normal result key 'details' can contais error string if key 'success' is False or result if key 'success' is True FzFile "%s" isn't exists)�success�detailsz%df %s | tail -n 1 | awk '{print $NF}'T� /bin/bash��shell� executablert���zmount | grep "on %s type"r{���r|���z#We can't get file system for file "z". Exception "�"N)r���r����exists� subprocess�check_output�strip�CalledProcessErrorr!���)� file_pathrg����mount_point�data�errs��� r'����*get_file_system_in_which_file_is_stored_onr��������s-�������,�y�8����F���7�>�>�)�$�$���� �!� �-� 4�y� @�A��"�� �� �� � ��%�'�'�� ���&� (�;� 6�7��"�� �� �� � ��%�'�'�� ��!��y�� ��y�����)�7�3��!��!��!��!��I�I��C�C� ���!��y�����������!������Ms����A&B��C��(B;�;C�c������������������������t����������dd�������������}� �|����������������������d�������������|����������������������dd������������}n#�t����������$�r�d}Y�nw�xY�w|S�)z� Checks if testing is enabled in /etc/yum.repos.d/cloudlinux.repo config :return: bool value if testing enabled or not NF)� interpolation�strictz /etc/yum.repos.d/cloudlinux.repozcloudlinux-updates-testing�enabled)r����read� getbooleanr���)�parser�ress��� r'����is_testing_enabled_repor������so������ ���U� ;� ;� ;�F�����6�7�7�7���� <�i�H�H��������������������Js����+?��A� Ac�������������������������t������������������������rdS�ddddddd�}�t����������j����������������������}|�D�]}|r||v�r |�|���������c�S��t����������d������������}d }|�d }nd |v�rd}nd|v�rd}n d|v�rd}nd |v�rd}|S�)a�� Returns cl version taking into account release version E.g: release = 2.6.32-896.16.1.lve1.4.54.el6.x86_64 5.14.0-162.6.1.el9_1.x86_64 el6 = cl6 el8 = cl8 ........ ubuntu+cl_extesions = cl8 :return appropriate version string �cl8�cl6�cl6h�cl7�cl7h�cl9)zel6.zel6h.zel7.zel7h.zel8.z.el9� os_releaseN�6�7�8�9)r����platform�releasery���)�check_vals_decoderr����� check_val�ret_vals��� r'����get_cl_versionr������s���������{�{����u������� �����&�-�/�/�G�'��1��1� ��� 1�y�G�+�+�%�i�0�0�0�0��$�\�2�2�G��G������ ������� ������� ������� �������Nr?���)�maxsizec������������������������� �t����������dg�����������������������������������������������}�n#�t����������j��������t����������f$�r�Y�dS�w�xY�w|�dk����r|����������������������d������������d���������S�dS�)a��� Returns virtualization type on current system. It is reachable via virt-what utility. E.g.: 'kvm', 'bhyve', 'openvz', 'qemu' All acceptable outputs are listed here: https://people.redhat.com/~rjones/virt-what/virt-what.txt Output will be returned with at least two rows Sample: > kvm > Furthermore, there is a possibility for multiple text rows Sample: > xen > xen-domU That's why, the result will be taken from a first row. If the output is empty, and there were no errors, the machine is either non-virtual, or virt-what tool isn't familiar with it's hypervisor. But the list of supported hypervisors and containers covers all popular VMs types. :return: virt_type - Optional[AnyStr] - appropriate virtualization type string, - 'physical' if there is no virtualization, - None if there was an error z/usr/sbin/virt-whatN��r9���r����physical)r���r����r����r�����FileNotFoundError�split)�virt_what_outputs��� r'���� get_virt_typer����@��s~������8�&�(=�'>�?�?�E�E�G�G�����)�+<�=��������t�t�������2����%�%�d�+�+�A�.�.��zs����"%��?�?�pidc������������������T����� �t����������j��������|�d�������������dS�#�t����������$�r�Y�dS�w�xY�w)z� Checks for a process existence by os.kill command If os.kill will be used as os.kill(pid, 0), it will just check for a presence of such PID And if such pid can't be reached with kill method, there will be raised OSError r���TF)r����killr!���)r����s��� r'���� check_pidr����g��sA������� ���Q������t�����������u�u����s������ '�'� pid_file_pathc������������������N����t�����������j�����������������������������|�������������r�t����������|�������������5�} �t ����������t����������|����������������������������������������������������������������������������������������������cddd�������������S�#�t����������$�r�Y�nw�xY�w �ddd�������������n#�1�swxY�w�Y���dS�)z�Check if process running using pid file Arguments: pid_file_path: path to the pid file of service Returns: bool: True or False NF) r���r���r,���r-���r�����intr����r����� ValueError)r����r1���s��� r'����is_process_runningr����x��s�������� �w�~�~�m�$�$��� �-� � �� �A� � ��Q�V�V�X�X�^�^�%5�%5�!6�!6�7�7� �� �� �� �� �� �� �� ����� �� �� ��� ����� �� �� �� �� �� �� �� �� �� �� ����� �� �� �� � ��5s.����B�?A=�= B �B� B � B�B�!Bc�������������������N����t����������j����������������������dk����rd}�t����������|�������������S�t�����������j�����������������������������t ����������������������sdS�t ����������t ����������������������5�}|����������������������������������������������������������������������}ddd�������������n#�1�swxY�w�Y���|dk����S�)a�� Detects that server works under Litespeed. Note: be careful when modifying this method. It is used in X-Ray, ask @dkavchuk or someone else from C-Projects team for details. return: True - LS working; False - LS not running (stopped or absent) r���z/tmp/lshttpd/lshttpd.pidFN�0) r���rJ���r����r���r�����LITESPEED_STATUS_FOR_USERSr-���r����r����)r����r1����statuss��� r'����is_litespeed_runningr�������s�������� �z�|�|�q���2� �!�-�0�0�0��w�~�~�8�9�9�� !��5��0�1�1�� *�Q��������)�)�� *�� *�� *�� *�� *�� *�� *�� *�� *�� *�� *����� *�� *�� *�� *��S�=� s����#'B�B�Bc�������������������$�����d}�t����������|�������������S�)zHCheck if nginx is running Returns: Bool: True or False z/run/nginx.pid)r����)r����s��� r'����is_nginx_runningr�������s�������%�M��m�,�,�,r?���c�������������������&�����t������������������������rdS�dS�)zU Return proper passenger package according to apache version :rtype: str zapache24-passengerzalt-mod-passenger)rY���rX���r?���r'����get_passenger_package_namer�������s������ ��x�x��$��$�#��r?���c����������������������� �t������������������������rt����������dd|�g�������������nt����������dd|�g�������������n#�t����������$�r�Y�dS�w�xY�wdS�)z_ Checks that package installed on server :param package_name: str :rtype: bool �dpkgz-s�rpmz-qFT)r���r���r���)�package_names��� r'����is_package_installedr�������sh��������;�;�� 5����|�4�5�5�5�5����l�3�4�4�4��� ��������u�u������4s����36�� A�Ac�������������������V�����t������������������������rt������������������������S�t������������������������S�)z� Pick the package manager to check depending on the OS. If we're not on Ubuntu, assume a CL variant with RPM. :return: Error string, if any, None otherwise. )r����get_apt_db_errors�get_rpm_db_errorsrX���r?���r'����get_package_db_errorsr�������s(��������{�{��#� �"�"�"� �"�"�"r?���c����������������������� �t����������j��������ddgdt�����������j��������t�����������j��������d�������������}�|������������������������������������\��}}|�j��������dk����r d|��d|��d �S�n-#�t ����������t����������f$�r}t����������|������������cY�d }~S�d }~ww�xY�wd S�)z� Check the dpkg DB as described in https://man7.org/linux/man-pages/man1/dpkg.1.html See `--audit`. :return: Error string, if any, None otherwise. r����z--auditFT)r����stdoutrS���rt���r���zdpkg audit error: r9����.N�r�����Popen�PIPE�communicate� returncoder!���ru����str)�prc�std_out�std_errr����s��� r'���r����r�������s���������� �Y����?��?�� �� �� ����?�?�,�,�����>�Q���=��=�=�7�=�=�=�=����� �W���������3�x�x�����������������4s����AA��B�.B�<B�Bc�����������������������d}� �t����������j��������g�d�t�����������j��������t�����������j��������d�������������}|�����������������������������������\��}}|j��������dk����rd|��d|��d|����S�n-#�t ����������t����������f$�r}t����������|������������cY�d }~S�d }~ww�xY�wd S�) zx Check RPM DB consistency. :return: None - No RPM DB errors string_message - Error description zjhttps://cloudlinux.zendesk.com/hc/en-us/articles/115004075294-Fix-rpmdb-Thread-died-in-Berkeley-DB-library)z/bin/rpmz--dbpathz/var/lib/rpmz --verifydbT)r����rS���rt���r���zRPM DB check error: r9���z. See doc: Nr����)�doc_linkr����r����r����r����s��� r'���r����r�������s������� D�� ����B�B�B��?��?�� �� �� ����?�?�,�,�����>�Q���T�'�T�T�W�T�T�(�T�T�T����� �W���������3�x�x�����������������4s����AA �� B �1B�?B �B c�������������������z�����t����������j����������������������t����������_��������t����������j����������������������t����������_��������dS�)a(�� Upon process exit, Sentry sometimes prints: Sentry is attempting to send 1 pending error messages Waiting up to 10 seconds Press Ctrl-C to quit This causes broken JSON in output. See also this issue: https://github.com/getsentry/raven-python/issues/904 N)�io�StringIOrR���r����rS���rX���r?���r'����!silence_stdout_until_process_exitr���� ��s"�����������C�J�����C�J�J�Jr?���c�����������������������d|dz��z ��}t����������j��������|������������5��t����������j��������|�|�������������ddd�������������dS�#�1�swxY�w�Y���dS�)a�� Create directories with desired permissions Changed in version 3.7: The mode argument no longer affects the file permission bits of newly-created intermediate-level directories. Because it we use umask while creating dirs :param mod: desired permissions i���N)�secureio� set_umaskr����makedirs)r����mod�inverted_mods��� r'����mod_makedirsr������s���������C�%�K�(�L� � �L� )� )����� ��D�#�����������������������������������������s����A���A�A�usernamec������������������T����� �t����������j��������|��������������n#�t����������$�r�Y�dS�w�xY�wdS�)z, Check user existence in the system FT)�pwd�getpwnamrP���)r����s��� r'����is_user_presentr����'��sA���������X��������������u�u������4������� %�%�uidc������������������T����� �t����������j��������|��������������n#�t����������$�r�Y�dS�w�xY�wdS�)z+ Check uid existence in the system FT)r�����getpwuidrP���)r����s��� r'����is_uid_presentr����2��sA���������S��������������u�u������4r����r���c����������������������� �t����������j��������|�������������j��������}n#�t����������t����������t ����������f$�r�Y�dS�w�xY�wt ����������j��������|������������}|S�)z+ Check that file by path is socket N)r����lstat�st_moder����ru���r!����stat�S_ISSOCK)r���r5���� is_sockets��� r'����is_socket_filer����=��sW��������x��~�~�%�����w��0��������t�t������ �d�#�#�I��s������7�7c������������������������t����������j��������dddd�������������}�|�����������������������������������������������������������������������d���������}|dk����rdnt ����������|������������}|S�)z? Get number of system run level by command `runlevel`. z/sbin/runlevelTr}���r~��������S)r����r����r����r����r����)�outputrg����levels��� r'����get_system_runlevelr����J��sc������ �� $���� � �����F���\�\�^�^� !� !� #� #�A� &�F��3���A�A�C��K�K�E��Lr?����service_namec����������������������t������������������������} �t����������j��������d|����ddd�������������}n#�t����������j��������t����������f$�r�Y�dS�w�xY�w|����������������������������������������������������������������������}|dd����������D�]V}|��������������������������������������������������������d������������}|d���������d k����}t����������|d ���������������������}||k����rd|fc�S��WdS�)z� Returns state of a service (present and enabled) for init.d system. Returns False, False if a service doesn't exist Returns True, False if a service exists and it's not enabled Returns True, True if a service exists and it's enabled zLANG=C /sbin/chkconfig --list Tr}���r~����FFr����N�:�onr����TF)r����r����r����r����r����r����r����r����)r�����runlevelr�����output_list� state_info� state_list� is_active�state_runlevels��� r'����#_get_service_state_on_init_d_systemr��]��s������#�$�$�H����(�;�\�;�;��"�� �� �� ����� �)�+<�>��������|�|�������,�,�.�.�&�&�(�(�K�!�!�"�"�o��#��#� ��%�%�'�'�-�-�c�2�2� ��q�M�T�)� ��Z��]�+�+���~�%�%���?�"�"�"��&��;s����,��A�Ac������������������R���� �t����������j��������d|���d�dd��������������dS�#�t�����������j��������t����������f$�rq� �t����������j��������dd|�gt�����������j��������t�����������j��������� ������������}|������������������������������������|j��������d v�rY�dS�Y�dS�#�t�����������j��������t����������f$�r�Y�Y�dS�w�xY�ww�xY�w) z� Returns state of service (present and enabled) for systemd system Returns False, False if a service doesn't exist Returns True, False if a service exists and it's not enabled Returns True, True if a service exists and it's enabled z/usr/bin/systemctl is-enabled z &> /dev/nullTr}���)r���r����)TTz/usr/bin/systemctlr����)rS���r����)r�������r����r����)r����� check_callr����r����r�����DEVNULLr����r����)r�����ps��� r'����$_get_service_state_on_systemd_systemr����s������� ���� I�\�H�H�H��"� �� �� �� ���z���)�+<�>�� �� �� � �� �(�� �� �"�)�!�)������A�� �M�M�O�O�O���|�v�%�%�"�{�{�#�|�|���-�/@�B�� �� �� ��<�<�<� ����' ���s'������B&�AB�B"�B&�!B"�"B&c�����������������������t������������������������}|rd|v�rt����������|��������������\��}}nt����������|��������������\��}}||fS�)zc Returns state of service (present and enabled) :param service_name: name of a service r����)r����)r����r��r��)r�����cl_ver� is_present� is_enableds��� r'����service_is_enabled_and_presentr�����si������ �� � �F� �� �%�6�/�/�!D�%�" ��" ��" �� �J�J��"F�%�" ��" ��" �� �J���z�!�!r?����process_file_path�strict_matchc������������������V����t�����������j�����������������������������|�������������st����������d|���d��������������t ����������j��������dg������������D�]`} �|s|�|�����������������������������������v�s-|r.|�d���������������������|�����������������������������������������������k����r�dS��L#�t����������j��������$�r�Y��]w�xY�wdS�)a��� Check that a file in path is running. You can get false-postive if parameter `strict_match` == False, process is not running, but someone on server open file by path `process_file_path` in an editor :param process_file_path: path to a file which is run :param strict_match: we use parameter `process_file_path` as full cmd line with args for comparing if `strict_match` == True. :return: True if it's running, False - is not, zProcess file in path "�" does not exist�cmdline� TF) r���r���r����r�����psutil�process_iterr���join� NoSuchProcess)r��r���processs��� r'����process_is_runningr�����s���������7�>�>�+�,�,�� ��H�%6�H�H�H� �� �� ���&� �{�3�3������ � � �%����):�):�:�:���;��&����'�/�/�2C�2C�)D�)D�D�D��t�t����#�� �� �� ��H� �����5s����AB�B&�%B&�dtc������������������������t����������|�t����������j��������t����������j��������f������������st����������dt ����������|�����������������������������t ����������|���������������������������������������������S�)z� Getting string representation of weekday from datetime.datetime or datetime.date. Returns shortened version of weekday from WEEK_DAYS. zFRequire object of type datetime.datetime or datetime.date, but passed )� isinstance�datetime�date� TypeError�type� WEEK_DAYS�weekday)r��s��� r'����get_weekdayr'�����s\������ � �r�H�-�x�}�=�>�>�� ��_�UY�Z\�U]�U]�_�_� �� �� ���R�Z�Z�\�\�"�"r?����config_path�apache_module_name� param_name�defaultc�����������������������d|��d�}g�}t����������|�������������}d}|D�]@}|�����������������������������������}||k����rd}�|r|dk����r�n|r|���������������������|��������������At����������t �����������dd|�������������������������} �fd�| D���������������} | s|�|d fS�| s|� d d|��d|����fS�| d ������������������������������d������������}t ����������|d ���������������������}|d fS�)a�� Helper to parse httpd config for details about mpm module used :param config_path: path for configuration file with modules :param apache_module_name: expected mpm module. Can be `event`, `worker`, `prefork` :param param_name: name of parameter to find :param default: default value for parameter, if there won't be record :return: tuple with param value and text result of operation Example of config file content: <IfModule mpm_prefork_module> ................. MaxRequestWorkers 450 </IfModule> -- <IfModule mpm_worker_module> ................. MaxRequestWorkers 300 </IfModule> -- <IfModule mpm_event_module> ................. MaxRequestWorkers 2048 </IfModule> z<IfModule mpm_z_module>FTz</IfModule>)re���rc���rf���c������������������������g�|�]=}|�����������������������������������������������������������������������)|��������������������������������������>S�rX���)r����r\���)r;���� directiver*��s��� �r'���r>���z/find_module_param_in_config.<locals>.<listcomp>��sQ���������������?�?���'�'� �3�3�����������r?���N�OKr���z.MaxRequestWorkers directive not found for mpm_z_module module in rI���r��)r2���r�����append�listri���r����r����) r(��r)��r*��r+���if_module_line� section_lines� mpm_lines�is_section_foundr=����grep_result_list�mrw_list�parts�max_request_workerss ��� ` r'����find_module_param_in_configr:�����su������>�C�&8�B�B�B�N��M��{�+�+�I����� '�� '���z�z�|�|���>�!�!�#����� �� � 5� 5��E��� '�� � ��&�&�&����� ��(� �� �� ������������)������H���� ��+���}�� �� �'�/�� � G�%� G�� G�9D� G�� G� �� �� �R�L���s�#�#�E��e�B�i�.�.����$�$r?���c�������������������Z����d}�t�����������j�����������������������������|�������������sdS� �t����������|�d������������5�}|����������������������������������������������������������������������}ddd�������������n#�1�swxY�w�Y���|���������������������dd������������\��}}n#�t����������t����������t����������f$�r�Y�dS�w�xY�w|S�)zp Return kmodlve module's version. Content of '/sys/module/kmodlve/version' looks like '2.0-30.el8'. z/sys/module/kmodlve/versionr����r*���Nr����r����) r���r���r,���r-���r����r�����rsplitr!���ru���r����)�kmodlve_module_file_pathr1����module�module_version�_s��� r'����get_kmodlve_module_versionrA��/��s������� � =�� �7�>�>�2�3�3����r�� �*�C� 0� 0�� &�A��V�V�X�X�^�^�%�%�F� &�� &�� &�� &�� &�� &�� &�� &�� &�� &�� &����� &�� &�� &�� &�"�M�M�#�q�1�1�������W�j�)��������r�r������s4����B ��'A(�B ��(A,�,B ��/A,�0B �� B(�'B(c�������������������r�����ddi}�t������������������������}||�vrdS�|�|���������}t������������������������}||k����rdS�dS�)a�� Find out if system has version of the kernel (according to kmodlve module's version) where fs.proc_can_see_other_uid and hidepid options are synchronized. They are only synchronized if kmodlve module's version is equal to version in synced_kmodlve_versions. r����z2.0-30FT)r����rA��)�synced_kmodlve_versions� cl_version�synced_version�current_versions��� r'����)proc_can_see_other_uid_and_hidepid_syncedrG��@��sU������� %�h�/���!�!�J��0�0�0��u�,�Z�8�N�0�2�2�O��.�(�(��t��5r?����pid_filenamec������������������(���� �t����������|�d������������5�}t����������|����������������������������������������������������������������������������������}t ����������j��������|d�������������ddd�������������n#�1�swxY�w�Y���n#�t����������t����������t����������f$�r�d}Y�nw�xY�w|S�)z� Detrmines working daemon process pid :param pid_filename: PID filename :return: PID from file or None if error (file not found, etc) r*���r���N) r-���r����r����r����r���r����r!���ru���r����)rH���pfr����s��� r'����get_process_pidrK��S��s�������� �,�� $� $�� ���b�g�g�i�i�o�o�'�'�(�(�C��G�C��O�O�O� �� �� �� �� �� �� �� �� �� �� ����� �� �� �� ���� �W�j�)����������������Js5����A3��A A'�A3��'A+�+A3��.A+�/A3��3B�Bc�����������������������t����������|�d������������5�}|���������������������t����������j�������������������������������������ddd�������������dS�#�1�swxY�w�Y���dS�)z Writes pid file r@���N)r-����writer����getpid)rH��rJ��s��� r'����write_pid_filerO��c��s�������� �l�D� !� !��#�R� ���B�I�K�K�!�"�"�"�#��#��#��#��#��#��#��#��#��#��#��#�����#��#��#��#��#��#s����(A�A � A c������������������`����� �t����������j��������|��������������dS�#�t����������t����������f$�r�Y�dS�w�xY�w)z Remove PID file N)r����remover!���ru���)rH��s��� r'����remove_pid_filerR��k��sD������ � � �,��������W��� �� �� ���� ���s������-�-c�����������������������������fd�}|S�)a�� Set user's real uid and gid to specified ones. Checking equality of real and effective uids is needed because this function may be used by root with effective uid dropped to user's uid. In that case it is needed to set effective uid back to 0 first. c��������������������������t����������j����������������������}�t����������j����������������������}|�|k����rt����������j��������|��������������t����������j����������������������t����������j����������������������d�S��N)r����getuidrJ����seteuid�setgid�setuid)�real_uid�eff_uid�gidr����s��� ��r'����funczdemote.<locals>.func~��sR��������9�;�;���*�,�,���w����J�x� � � � � �#���� � �#�����r?���rX���)r����r\��r]��s���`` r'����demoter^��u��s)���������������������Kr?����dirpathc������������������B����t�����������j�����������������������������|�������������st����������d|���d��������������dd|�g}t ����������|������������} �|���������������������d������������d���������}|���������������������d������������d���������}n #�t����������$�r�t����������d |����������������w�xY�w|S�) zK Get mount point for dirpath directory from output of `df` utility zDirectory "r��z/bin/dfz-hr9���r����r��rI���z)Utility "df" returned unexpected output: )r���r����isdirr!���r���r����rv���)r_���fs_info_cmd�fs_info�mountpoint_info� mounted_ons��� r'����get_mount_pointrf�����s���������7�=�=��!�!��?��=�G�=�=�=�>�>�>��d�G�,�K��+�&�&�G� N�!�-�-��-�-�a�0��$�*�*�3�/�/��3� � ����N��N��N��L�7�L�L�M�M�M�N������s����6A?��?Bc�����������������������d}�t�����������j�����������������������������|�������������st������������������������dk����S�t ����������|�������������5�}t����������|�����������������������������������������������}|dk����cddd�������������S�#�1�swxY�w�Y���dS�)z� Detect if 'may_detach_mounts' kernel option is enabled. More info on the option: https://cloudlinux.atlassian.net/browse/KMODLVE-512 z/proc/sys/fs/may_detach_mountsr����r����N)r���r���r,���r����r-���r����r����)�may_detach_mounts_filer1����vals��� r'����is_may_detach_mounts_enabledrj�����s������� �>�� �7�>�>�0�1�1��)����5�(�(� �$� %� %�����!�&�&�(�(�m�m���a�x��������������������������������������s����'A7�7A;�>A;rU��)NFTFN)V� __future__r���r���r���r����r����r^���r����r���rR���rK���r����r����r!��� functoolsr����configparserr���r����typingr ���r ���r���r���r ���r���r���lxmlr���r�����clcommon.lib.cleditionr����clcommon.utils_cmdr���r���r���r���rl���r%��r����r(���r2���r6���rE���rV���rY���ri���rm���r����ry���r�����boolr����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r��r��r��r��r"��r'��r:��rA��rG��rK��rO��rR��r^��rf��rj��rX���r?���r'����<module>rs�����s6�����&��%��%��%��%��%��&��&��&��&��&��&�������������� � � � ������� � � � �� � � � �� � � � �� � � � �� � � � ��������������������������������,��,��,��,��,��,��,��,��<��<��<��<��<��<��<��<��<��<��<��<��<��<��<��<�� � � � �������������������,��,��,��,��,��,�������������������������2���=� �?���*��*��*�.�������" �� �� ������"�����$4��4��4������� /��/��/��/�d*��*��*� �H�S�M�� �� �� �� � )��)��)�X����������'��� ��'��'��'��'�T���4����#�x��}��#��#��#����#�L�3���������"�c���d���������"!�d��!��!��!��!�(-�$��-��-��-��-������ �� �� � #�� #�� #������4�����8�����������c���d���������������������� ��� �H�T�N�� �� �� �� ��S���������&�c���e�D�$�J�>O���������D$ �s��$ �u�T�4�Z�?P��$ ��$ ��$ ��$ �N"���"��t�T�z�9J��"��"��"��"�"�#���T���t���������< #�E�(�+�X�]�:�;�� #��� #�� #�� #�� #� �� K%��K%��K%��K%���K%��� K%� ��3��8�_�K%��K%��K%��K%�\�C���������"�4���������& �#�� �(�3�-�� �� �� �� � #���#��#��#��#� �#�� �� �� �� ������,�S���S���������, �d�� �� �� �� �� �� r?���