ok

Mini Shell

Direktori : /opt/cloudlinux/venv/lib/python3.11/site-packages/xray/manager/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/xray/manager/__pycache__/base.cpython-311.pyc

�

��fz���dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
m
Z
mZddlmZddl	m
Z
mZmZddlZddlmZddlmZmZddlmZmZdd	lmZdd
lmZddlmZddlm Z!d
dl"m#Z#d
dl$m%Z%d
dl&m'Z'd
dl(m)Z)m*Z*m+Z+m,Z,m-Z-d
dl.m/Z/d
dl0m1Z1d
dl2m3Z3d
dl4m5Z5m6Z6m7Z7d
dl8m9Z9d
dl:m;Z;d
dl<m=Z=m>Z>m?Z?d
dl@mAZAmBZBmCZCmDZDmEZEmFZFd
dlGmHZHmIZImJZJmKZKmLZLe	jMrd
dlNmOZOGd�d��ZPdS)zX
This module contains classes implementing X-Ray Manager behaviour
and helper functions
�N)�datetime�	timedelta)�glob)�Iterator�Optional�Tuple)�Feature)�is_panel_feature_supported�get_installed_php_versions)�php_get_vhost_versions�is_wpos_supported)�is_litespeed_running)�drop_privileges)�
disable_quota)�gettext�)�ClWposGetter)�
get_client)�ContinuousManager)�XRayManagerError�XRayAPIError�XRayMissingDomain�XRayManagerExit�XRayManagerExitPHPUnsupported)�FPMReloadController)�open_local_storage)�NginxUserCache)�
DomainInfo�Task�	url_split)�ManageUserAgent)�AdvancedMetrics)�get_xray_exec_user�user_mode_restricted�nginx_user_cache)�no_active_tasks�switch_schedstats�ssa_disabled�_cagefsctl_remount�set_privileges�is_file_recently_modified)�create_ini_files�remove_ini_files�is_global_ini_mode�remove_global_ini_mode_marker�create_global_ini_mode_marker)�	APIClientc��eZdZdZdZddddddd	d
ddd
dd�Zd^dedefd�Zde	e
fd�Zdefd�Z
dedefd�Zdedefd�Zdedefd�Zdedefd�Zdedefd�Zdeddfd�Zd �Zd!edefd"�Zed#edeejfd$���Zd%eddfd&�Zd'edefd(�Zd)edefd*�Zdedefd+�Z d,edefd-�Z!d,eddfd.�Z"ed!ede#ee
ffd/���Z$d0eddfd1�Z%edefd2���Z&d_d4�Z'e(ddd5�d'ed6ed7ed8e
d9ed:edd3fd;���Z)d'edd3fd<�Z*d=d>�d'ed8e
dd3fd?�Z+d@edd3fdA�Z,dB�Z-e(d@edd3fdC���Z.d@edd3fdD�Z/edEedefdF���Z0d_dG�Z1edHe2dIdJfdK���Z3d@edd3fdL�Z4d'edMedd3fdN�Z5d'edd3fdO�Z6d'edd3fdP�Z7d'edd3fdQ�Z8d_dR�Z9d_dS�Z:dTedd3fdU�Z;dTedVe
dd3fdW�Z<d_dX�Z=d_dY�Z>d_dZ�Z?d_d[�Z@d_d\�ZAd_d]�ZBdS)`�BaseManagerz�
    Basic manager abstract class.
    Implements methods common for all managers.
    Requires managers to implement their custom methods.
    z/var/run/xray-agent.pidz/opt/alt/php54/link/confz/opt/alt/php55/link/confz/opt/alt/php56/link/confz/opt/alt/php70/link/confz/opt/alt/php71/link/confz/opt/alt/php72/link/confz/opt/alt/php73/link/confz/opt/alt/php74/link/confz/opt/alt/php80/link/confz/opt/alt/php81/link/confz/opt/alt/php82/link/confz/opt/alt/php83/link/conf)z	alt-php54z	alt-php55z	alt-php56z	alt-php70z	alt-php71z	alt-php72z	alt-php73z	alt-php74z	alt-php80z	alt-php81z	alt-php82z	alt-php83F�	system_id�phpinfo_modec��t��|_||_tjd��|_t
��|_t��|_	||_
td��|j���|_dS)N�manager�lists�r4)r�api_client_class�sys_id�logging�	getLogger�loggerr�continuous_monitoringr!�manage_user_agentr5�
ui_api_client)�selfr4r5s   �H/opt/cloudlinux/venv/lib64/python3.11/site-packages/xray/manager/base.py�__init__zBaseManager.__init__csr��2<���������'�	�2�2���%6�%8�%8��"�!0�!2�!2���(���0�Z��0�0�4�;�G�G�G������returnc��	t|j��5}t|�����cddd��S#1swxYwYdS#tt
f$rt
jd��YdSwxYw)Nz'Unable to read daemon pid from pidfile.)�open�DAEMON_PIDFILE�int�read�OSError�IOErrorr<�warning)rB�fs  rC�_get_daemon_pidzBaseManager._get_daemon_pidns���	G��d�)�*�*�
%�a��1�6�6�8�8�}�}�
%�
%�
%�
%�
%�
%�
%�
%�
%�
%�
%�
%����
%�
%�
%�
%�
%�
%����!�	G�	G�	G��O�E�F�F�F�F�F�F�	G���s3�A�!A�A�A�A�A�A�%A:�9A:c��|jS)z\
        Get supported PHP versions
        :return: a dict with supported versions
        )�VERSIONS�rBs rC�supported_versionszBaseManager.supported_versionsus��
�}�rE�php_versionc�.�||���vS)z�
        Check if given PHP version is supported
        :param php_version: PHP version, e.g. 'alt-phpXY'
        :return: True if version is supported, False otherwise
        )rT)rBrUs  rC�is_version_supportedz BaseManager.is_version_supported|s���d�5�5�7�7�7�7rE�domain_infoc�Z�|����|j��S)zh
        Get a path to directory for additional ini file for based on
        panel-set version
        )rT�get�panel_php_version�rBrXs  rC�	_ini_pathzBaseManager._ini_path�s'��
�&�&�(�(�,�,�[�-J�K�K�KrEc���|�|��}	|jr|j}n&|�|��r|j}n	|jp|}n#t
$rYnwxYw|j�d|��|S)z�
        Resolve a path to directory for additional ini file
        It depends on version set for domain and on selector
        :param domain_info: a DomainInfo object
        :return: path to directory for ini files
        zIni path resolved as %s)r]�php_ini_scan_dir�is_selector_enabled�selector_ini_path�phpd_location_ini_path�
ValueErrorr>�info)rBrX�ini_paths   rC�get_ini_pathzBaseManager.get_ini_path�s����>�>�+�.�.��		��+�
J�&�7����)�)�+�6�6�
J�&�8���&�=�I������	�	�	��D�	����	
����2�H�=�=�=��s�5A
�
A�Ac���|js=|�|��r(|j�d|j��|j}n|j}|j�d|��|S)a
        Get PHP version which serves given domain
        :param domain_info: a DomainInfo object, including user of domain
                            and PHP version set in control panel environment
        :return: real php version of domain (selector or panel one)
        zSelector is enabled for user %szPHP version detected as %s)�is_selector_appliedr`r>rd�user�selector_php_versionr[)rBrX�current_versions   rC�get_php_versionzBaseManager.get_php_version�sy���.�	<��(�(��5�5�	<��K���>�(�-�
/�
/�
/�)�>�O�O�)�;�O�����5��G�G�G��rEc�t�ttj��sdS|j�dS|�|��S)a

        Is selector enabled for given domain
        :param domain_info: a DomainInfo object, including user of domain
                            and PHP version set in control panel
        :return: True if selector is enabled for domain, False otherwise
        F)r
r	�PHP_SELECTORrj�panel_specific_selector_enabledr\s  rCr`zBaseManager.is_selector_enabled�s>��*�'�*>�?�?�	��5��+�3��5��3�3�K�@�@�@rENc��|�|j��|jr|�|��dSt	��r|�|j��dS|�|j��dS)z�
        Reload FPM service or kill all *php* processes of user
        :param domain_info: a ready-to-use DomainInfo object
        N)�reset_criu_imgs�name�	panel_fpm�restart_fpm_servicer�gracefully_restart_litespeedri�
kill_user_phpr\s  rC�php_procs_reloadzBaseManager.php_procs_reload�s���
	
���[�-�.�.�.�� �	1��$�$�[�1�1�1�1�1�
!�
#�
#�	1��-�-�k�.>�?�?�?�?�?����{�/�0�0�0�0�0rEc��tj|��}t|��5t��5	t	t
j�|jd��d���	��n3#ttf$r|j�
dd���YnwxYwddd��n#1swxYwYddd��dS#1swxYwYdS)z�
        Litespeed's graceful restart.
        https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:php:detached_mode#for_a_user
        z.lsphp_restart.txt�wz$Unable to restart lsws after changesT)�exc_infoN)�pwd�getpwnamrrrH�os�path�join�pw_dir�close�FileNotFoundError�PermissionErrorr>rN)rB�username�pws   rCruz(BaseManager.gracefully_restart_litespeed�s���
�\�(�
#�
#��
�X�
&�
&�	[�	[�
���	[�	[�
[��R�W�\�\�"�)�-A�B�B�C�H�H�N�N�P�P�P�P��%��7�
[�
[�
[���#�#�$J�UY�#�Z�Z�Z�Z�Z�
[����		[�	[�	[�	[�	[�	[�	[�	[�	[�	[�	[����	[�	[�	[�	[�	[�	[�	[�	[�	[�	[�	[�	[�	[�	[�	[�	[����	[�	[�	[�	[�	[�	[sX�C�B:�AA;�:B:�;-B+�(B:�*B+�+B:�.C�:B>	�>C�B>	�C�C�Cr�c���t��}|�|��D]P}d|jdvr?|�tj��|�|jd���Q|S)z�
        Kill all PHP processes, which belong to given username
        :param username: name of user
        :return: list of pids of successfully killed processes
        �phprr�pid)�list�
user_procsrd�send_signal�signal�SIGHUP�append)rBr��killed_procs�procs    rCrvzBaseManager.kill_user_php�sr���v�v���O�O�H�-�-�	6�	6�D���	�&�)�)�)�� � ���/�/�/��#�#�D�I�e�$4�5�5�5���rE�	user_namec#��K�tj|��j}gd�}tj|��D],}||jdj|jdjfvr|V��-dS)z�
        Generator yields processes, which belong to given user_name.
        Processes are checked using UID, not user_name
        :param user_name: user name
        :return: a generator object
        )rrr��uidsr�N)r{r|�pw_uid�psutil�process_iterrd�real�	effective)r��uid_by_name�attrs�ps    rCr�zBaseManager.user_procs�su�����l�9�-�-�4��'�'�'���$�U�+�+�	�	�A��q�v�f�~�2�A�F�6�N�4L�M�M�M������	�	rE�domainc��td|�d���}|r=tj|d��|j�d|d��dSdS)zt
        Reset criu images if any found for given domain in order to
        enable/disable X Ray correctly
        z/var/run/mod_lsapi/*�
_criu_imgsrzcriu images in %s droppedN)r�shutil�rmtreer>rd)rBr��
criu_imgs_dirs   rCrqzBaseManager.reset_criu_imgs�sk��
�F�F�F�F�F�G�G�
��	L��M�-��*�+�+�+��K���8�-��:J�K�K�K�K�K�	L�	LrE�urlc�P�t|��\}}|�|��S)z4
        DomainInfo retrieving based on url
        )r �get_domain_info�rBr��domain_name�_s    rC�_domain_info_by_urlzBaseManager._domain_info_by_url�s'��#�3�����Q��#�#�K�0�0�0rEr�c�:�ttd�����)z�
        Retrieve information about given domain from control panel environment
        Required to be implemented by child classes
        :param domain_name: name of domain
        :return: a DomainInfo object
        z0Manager should implement retrieving domain info!��NotImplementedErrorr�)rBr�s  rCr�zBaseManager.get_domain_infos%��"�
�@�A�A�C�C�	CrEc�:�ttd�����)z�
        Check if selector is enabled specifically for panel
        Required to be implemented by child classes
        :param domain_info: a DomainInfo object
        :return: True if yes, False otherwise
        zCManager should implement specific panel check for selector enabled!r�r\s  rCroz+BaseManager.panel_specific_selector_enableds%��"�
�S�T�T�V�V�	VrE�dom_infoc�:�ttd�����)z�
        Get FPM service name for particular panel
        :param dom_info: DomainInfo object
        :return: name of FPM service
        z5Manager should implement FPM service name retrieving!r�)rBr�s  rC�fpm_service_namezBaseManager.fpm_service_names%��"�
�E�F�F�H�H�	HrEc��|�|��}	tjd|dgddd���|j�d|��t|�����d	S#tttj	f$r7}|j�
dt|��|d����Yd	}~d	Sd	}~wwxYw)
zg
        Restart FPM service for particular version
        :param dom_info: DomainInfo object
        z
/sbin/service�reloadT)�capture_output�text�checkzService %s reloadedzFailed to reload FPM service)�errrd��extraN)r��
subprocess�runr>rdr�save_latest_reloadrLrc�SubprocessError�error�str)rBr��fpm_serv�es    rCrtzBaseManager.restart_fpm_service$s��
�(�(��2�2��	?��N� �(�H�5�#���	
�
�
�
�

�K���2�H�=�=�=�
 ��)�)�<�<�>�>�>�>�>����Z�%?�@�	8�	8�	8��K���<�,/��F�F�-5�%7�%7�
�
8�
8�
8�
8�
8�
8�
8�
8�
8�����	8���s�6A0�0C�,B>�>Cc�J�tj|��}d|j�d�}tj�tj�|����s@tjtj�|����t|��||j	fS)z5Resolve path for user and prepare directory if neededz/var/clwpos/uids/z
/info.json)
r{r|r�r}r~�isdir�dirname�makedirsr)�pw_gid)r��_upwd�_paths   rC�prepare_wpos_info_pathz"BaseManager.prepare_wpos_info_path8s�����X�&�&��<�E�L�<�<�<���w�}�}�R�W�_�_�U�3�3�4�4�	)��K������.�.�/�/�/��x�(�(�(��e�l�"�"rEric���t��sdS|�|��\}}t|��r|j�d|��dS|dz}tt
|��t�����}|j�d||��td|d���5	t|d	��5}tj||��ddd��n#1swxYwYtj||��|j�d
��n?#t$r2}|j�dt#|����Yd}~nd}~wwxYwddd��dS#1swxYwYdS)z9Prepare and write info.json file for WPOS (AWP) utilitiesNz*File %s modified recently, skip generatingz.tmp)�vhost_versions�installed_versionszGoing to write file %s with %sr�_)�
target_uid�
target_gid�maskryzWPOS data written successfullyz'Unable to write info for WPOS due to %s)r
r�r+r>rd�dictrr�debugr*rH�json�dumpr��moverLr�r�)rBri�dest�user_gid�working_dest�to_write�	info_jsonr�s        rC�write_wpos_infozBaseManager.write_wpos_infoBs2�� �"�"�	��F��4�4�T�:�:���h�$�T�*�*�	��K���I�!�
#�
#�
#��F��f�}���1�$�7�7�9�;�;�
�
�
��	
����:���	*�	*�	*�
�q�X�E�
J�
J�
J�	*�	*�
*��,��,�,�3�	��I�h�	�2�2�2�3�3�3�3�3�3�3�3�3�3�3����3�3�3�3���L�$�/�/�/��� � �!A�B�B�B�B���
*�
*�
*���!�!�"K�"%�a�&�&�*�*�*�*�*�*�*�*�����
*����
	*�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*����	*�	*�	*�	*�	*�	*s`�2E-�4D!�C&�D!�&C*	�*D!�-C*	�.2D!� E-�!
E�+(E�E-�E�E-�-E1�4E1c��ddi}|r|�|��tjtt	|���������S)z�
        Create JSON response message with result field == success
        and given keyword arguments in other fields
        :return: json packed string
        �result�success)�updater��dumpsr��sorted�items)�kwargs�initials  rC�responsezBaseManager.response^sP���Y�'���	#��N�N�6�"�"�"��z�$�v�g�m�m�o�o�6�6�7�7�8�8�8rE�json strc�b�|�d��r|d�d�|d<|jdi|��S)z�
        Create JSON response message for continuous actions.
        Extends action definition with 'continuous' addition
        :return: json packed string
        �actionz continuous�)rZr�)rBr�s  rC�response_continuouszBaseManager.response_continuousjsI���:�:�h���	@�"(��"2�?�?�?�F�8���t�}�&�&�v�&�&�&rE)�	auto_task�autotracing�	client_ip�
tracing_by�
tracing_countr�r�c
�\�|�|��}|�|j��|�|��}|�|��r|�|��}	n.|j�dd|i���t||���|�	|j
���}
|rdn
t��}t|||||	|||j���}|
�
|��|_|�|���|�|j
���|
�|j��|�|��t)d�	��	t+���|j|j��n1#t0$r$}
t3jd
|
j��Yd}
~
nd}
~
wwxYwt7|j�����t;��rt=��|�d|j�
��S)a

        Start monitoring of given URL.
        Arguments are only allowed by keyword
        :param url: URL to monitor
        :param client_ip: a client IP address
        :param tracing_by: time or qty
        :param tracing_count: a number of minutes|requests to monitor
        :param auto_task: if a task is an auto created one (x-ray 2.0)
        :param autotracing: task is an auto created with
                            user marked as *autotracing*
        :return: JSON encoded result of start action
        zPHP version is unsupported�versionr�r9z
*autotracing*)r�r�r�r��ini_locationr�ri�domain_owner�rUT��enabledz0Failed to send metadata to Smart Advice with: %sN�start�r��tracing_task_id) r�r�rirlrWrfr>rNrr:r;r#r�create�task_id�add�set_cronjobr��	starttimerwr'r�
post_metadatarrrr<�reasonr�disabler.r,r�)rBr�r�r�r�r�r�rX�real_php_version�ini_files_location�clientri�tracing_taskr�s              rCr�zBaseManager.starttsk��$�.�.�s�3�3�����[�-�.�.�.��/�/��<�<���$�$�%5�6�6�	G�!%�!2�!2�;�!?�!?����K��� <�'0�2B�&C�
 �
E�
E�
E�/��5E�F�F�F��&�&���&�=�=��"-�G���3E�3G�3G����y�'1�*7�);�&/�d�)4�)9�;�;�;�� &�}�}�\�:�:������%5��6�6�6�� � �4�;� �7�7�7�	�
�
�l�,�-�-�-����k�*�*�*��$�'�'�'�'�	&��N�N�(�(��)9�;�;K�L�L�L�L���	&�	&�	&��O�N��H�
&�
&�
&�
&�
&�
&�
&�
&�����	&����	�{�'�(�(�0�0�2�2�2����	������}�}�G�-9�-A��C�C�	Cs�2,F�
G
�)G�G
c�6�|�|dddd���S)z�
        Start continuous monitoring of given URL (auto task).
        Arguments are only allowed by keyword
        :param url: URL to monitor
        :return: JSON encoded result of start action
        �*�timei�T)r�r�r�r�r��r�)rBr�s  rC�
start_autozBaseManager.start_auto�s*���z�z�c�S�V�(,���>�>�	>rE�)r�c�8�|�|dd|dd���S)a6
        Start monitoring of given URL (autotracing task).
        Note, user is overridden as *autotracing*
        Arguments are only allowed by keyword
        :param url: URL to monitor
        :param tracing_count: count of requests to capture
        :return: JSON encoded result of start action
        r�request_qtyT)r�r�r�r�r�r�r)rBr�r�s   rC�start_autotracingzBaseManager.start_autotracing�s-���z�z�c�S�]�(5��&*��,�,�	,rEr�c�>�|�|j|���}|���}|���t	|j��5}|�|j���ddd��n#1swxYwYgd�}|j|vr1ttd��t|j��z���	|�|j
��}|�|j��n,#t $r|j�d��d}YnwxYw|���|���|���}|dkr|�|��n|�||��|�;t1|j�����|�|��t7��rt9��rt;d�	��|�d
|j���S)z�
        Stop monitoring of given task ID
        :param tracing_task_id: an ID of task to stop
        :return: JSON encoded result of stop action
        �r4r�)�next_request_idN)�running�stopped�	completed�holdz!Cannot stop task with status '%s'z+Stopping task for an already deleted domainrFr��stopr�) r:r;�get_task�_request_daemon_storage_flushr�fake_id�update_with_local_datar�statusrr�r�r�r��set_domain_ownerrirr>rd�remove�drop_cronjob�recalculate_countsr�	_completer�restorerwr&r(r'r�r�)rBr�rr�storage�try_to_complete_statusesrX�remaining_counts        rCrzBaseManager.stop�s����&�&���7F�'�H�H�����(�(���*�*�,�,�,�
�� 4�
5�
5�	Y���/�/��@W�/�X�X�X�	Y�	Y�	Y�	Y�	Y�	Y�	Y�	Y�	Y�	Y�	Y����	Y�	Y�	Y�	Y�$O�#N�#N� ���&>�>�>�!��5�6�6��\�=P�9Q�9Q�Q�S�S�
S�	��2�2�<�3C�D�D�K��)�)�+�*:�;�;�;�;�� �	�	�	��K���J�K�K�K��K�K�K�	����	�������!�!�#�#�#�'�9�9�;�;���Q����K�K��(�(�(�(��N�N�<��0�0�0��"��;�+�,�,�4�4�6�6�6��!�!�+�.�.�.����	-����	-��e�,�,�,�,��}�}�F�-9�-A��C�C�	Cs$�B�B�B�4D�&D)�(D)c��tjtjtjh��|���}|rK	tj|tj��n*#t$r|j�	d��YnwxYw|j�
d��tjtjhd��}|�tj	d��tjtj
tjh��dS)z�
        Request daemon to flush it's in-memory storage on disk using SIGUSR2
        and wait for getting SIGUSR2 back that daemon sends when it successfully
        flushed data on disk and we are ready to proceed.
        zVUnable to send daemon signal. Some stats will not be flushed. Maybe daemon is stopped?z2Waiting for daemon to signal back about flush end.g.@NzUDaemon did not signal back in given timeout. Some stats may not be flushed. Continue.)r��pthread_sigmask�	SIG_BLOCK�SIGUSR2rPr}�killrLr>rNrd�sigtimedwaitr<�SIG_DFL)rB�
daemon_pid�siginfos   rCrz)BaseManager._request_daemon_storage_flush�s��	��v�/�&�.�1A�B�B�B��)�)�+�+�
��	@�
@���
�F�N�3�3�3�3���
@�
@�
@���#�#�%?�@�@�@�@�@�
@����	
����M�N�N�N��%�v�~�&6��=�=���?��O�G�
H�
H�
H�	��v�~���/?�@�@�@�@�@s�A"�"$B	�B	c��|�|j|���}|���}|jdvr1t	td��t
|j��z���|�|j��}|�	|j
��d|���vr|�|��}nd}|�
|���|�|j���|�|j��t#|j
�����|�|��t)d�	��|�d
|j���S)z�
        Continue monitoring of given task ID
        :param tracing_task_id: an ID of task to continue
        :return: JSON encoded result of continue action
        r�rrz%Cannot continue task with status '%s'�54Nr�r9Tr��continuer�)r:r;rrrr�r�r�r�rrirTrlr�r�r�r�rr�rwr'r�r�)rBr�rrrXrs      rC�	continue_zBaseManager.continue_s����&�&���7F�'�H�H�����(�(����":�:�:�!��9�:�:�S��AT�=U�=U�U�W�W�
W��.�.�|�/?�@�@���%�%�k�&6�7�7�7��4�*�*�,�,�,�,�#�3�3�K�@�@��� $�����%5��6�6�6�� � �4�;� �7�7�7�	�
�
�l�,�-�-�-��{�'�(�(�0�0�2�2�2����k�*�*�*��$�'�'�'�'��}�}�J�-9�-A��C�C�	CrEc�:�|�|j|���}|���}|jdvr1t	td��t
|j��z���|�||��|�d|j	���S)z�
        Complete given tak ID
        :param tracing_task_id: an ID of task to complete
        :return: JSON encoded result of complete action
        rr-z%Cannot complete task with status '%s'�completer�)
r:r;rrrr�r�rr�r��rBr�rrs    rCr2zBaseManager.complete;s����&�&���7F�'�H�H�����(�(����":�:�:�!��9�:�:�S��AT�=U�=U�U�W�W�
W����|�V�,�,�,��}�}�J�-9�-A��C�C�	CrE�taskc��tj��}|d}|dp|d}tj|��}|dkr|td���z|krdS|dkr|t|d	�
��z|krdSdS)zT
        Returns True if task should be completed.
        False otherwise.
        r�r��
createtimerr)�daysTrr�)�minutesF)r�now�
fromtimestampr)r4r9r��	inception�task_start_times     rC�_is_to_completezBaseManager._is_to_completeKs����l�n�n���,�'�
���%�;��l�);�	�"�0��;�;����&�&�?�Y�A�=N�=N�=N�+N�QT�+T�+T��4�����O�i��_�H]�6^�6^�6^�$^�ad�$d�$d��4��urEc��|j����dg��}|j�dt|����|D][}|�|��s�tjdt|d����|�|d���\|�	d���S)z�
        Gets all server tasks and complete those which match following criteria:
         - traced_by requests_qty: if task started 2 days ago - complete
         - traced_by time: if task runs longer than start time + tracing time - complete
        r�z#Check tasks for autocompleting...%sz"Going to complete task with id: %sr�zautocomplete-tasks�r�)
rA�
get_task_listrZr>rdr�r=r<rr�)rB�all_server_tasks�	task_items   rC�autocomplete_taskszBaseManager.autocomplete_tasks[s��� �-�;�;�=�=�A�A�(�B�O�O������>��DT�@U�@U�V�V�V�)�	4�	4�I��'�'�	�2�2�
���L�=�s�9�M^�C_�?`�?`�a�a�a��I�I�i� 1�2�3�3�3�3��}�}�$8�}�9�9�9rE�t_taskrr1c��|���|���|���|jr|���dSdS)z�
        Common complete actions:
        - delete cron job,
        - erase request id file
        - send 'complete' status to mongo
        :param t_task: a tracing task object
        :param client: an APIClient object
        N)r�erase_request_id_storager2r��share)rDrs  rCrzBaseManager._completejs^��	�������'�'�)�)�)���������	��L�L�N�N�N�N�N�	�	rEc�:�|�|j|���}|���}|jdkr1t	td��t
|j��z���|���|�d|j	���S)z�
        Delete given task ID
        :param tracing_task_id: an ID of task to delete
        :return: JSON encoded result of delete action
        rrz#Cannot delete task with status '%s'�deleter�)
r:r;rrrr�r�rIr�r�r3s    rCrIzBaseManager.deletezs����&�&���7F�'�H�H�����(�(����)�+�+�!��7�8�8�3�|�?R�;S�;S�S�U�U�
U��
�
�����}�}�H�-9�-A��C�C�	CrE�emailc��|�|��}|j�|j||��|�d|���S)z�
        Enable continuous monitoring for given URL
        :param url: URL to monitor
        :param email: email to send reports to
        :return: JSON encoded result of enable action
        �enable�r�r�)r�r?rLrrr�)rBr�rJ�d_infos    rC�enable_continuouszBaseManager.enable_continuous�sM���)�)�#�.�.���"�)�)�&�+�s�E�B�B�B��'�'�x�S�'�A�A�ArEc��t|��\}}|j�|��|�d|���S)z�
        Disable continuous monitoring for given URL
        :param url: URL to monitor
        :return: JSON encoded result of disable action
        r�rM)r r?r�r�r�s    rC�disable_continuouszBaseManager.disable_continuous�sC��#�3�����Q��"�*�*�;�7�7�7��'�'�y�c�'�B�B�BrEc��t|��\}}|j�|��|�d|���S)z�
        Start continuous monitoring for given URL
        :param url: URL to monitor
        :return: JSON encoded result of start action
        r�rM)r r?r�r�r�s    rC�start_continuouszBaseManager.start_continuous�sC��#�3�����Q��"�(�(��5�5�5��'�'�w�C�'�@�@�@rEc��t|��\}}|j�|��|�d|���S)z�
        Stop continuous monitoring for given URL
        :param url: URL to monitor
        :return: JSON encoded result of stop action
        rrM)r r?rr�r�s    rC�stop_continuouszBaseManager.stop_continuous�sC��#�3�����Q��"�'�'��4�4�4��'�'�v�3�'�?�?�?rEc�b�|j���}|�d|���S)zq
        Get list of continuous monitoring tasks
        :return: JSON encoded result of get list action
        zget continuous list�r��data)r?�get_tracing_listr�)rB�tracing_lists  rC�continuous_tracing_listz#BaseManager.continuous_tracing_list�s9��
�1�B�B�D�D���}�}�$9�".��0�0�	0rEc�^�|�d|j������S)z#
        Get list of tasks
        z
tasks-listrW)r�rAr@rSs rC�
tasks_listzBaseManager.tasks_list�s6���}�}�L�"&�"4�"B�"B�"D�"D��F�F�	FrEr�c��|�|j|���}|���}|�d|j�|�����S)z@
        Get list of requests for given tracing task id
        rz
requests-listrW)r:r;rr�rA�get_request_list)rBr�rr�s    rC�
requests_listzBaseManager.requests_list�sj��
�&�&���7>�'�@�@���O�O�����}�}�O�"&�"4�"E�"E�g�"N�"N��P�P�	PrE�
request_idc���|�|j|���}|���}|�d|j�||�����S)zO
        Get collected statistics for request ID of given tracing task
        rzrequest-datarW)r:r;rr�rA�get_request_data)rBr�rarr�s     rC�request_datazBaseManager.request_data�sn��
�&�&���7>�'�@�@���O�O�����}�}�N�"&�"4�"E�"E�!(�*�#6�#6��7�7�	7rEc�`�|j���|�d���S)a
        Enable X-Ray User Agent:
            start or restart service if it is accidentally already running
        For systemd systems -- start socket unit only
        For SysV -- start the entire service
        :return: JSON encoded result of enable action
        zenable-user-agentr?)r@rLr�rSs rC�enable_user_agentzBaseManager.enable_user_agent�s.��	
��%�%�'�'�'��}�}�$7�}�8�8�8rEc�`�|j���|�d���S)a7
        Disable X-Ray User Agent:
             stop the entire service
             or do nothing if it is accidentally not running
        For systemd systems -- also check if socket unit is running
                               and stop it too
        :return: JSON encoded result of disable action
        zdisable-user-agentr?)r@r�r�rSs rC�disable_user_agentzBaseManager.disable_user_agent�s.��	
��&�&�(�(�(��}�}�$8�}�9�9�9rEc�|�|j���}|�d|t�����S)zn
        Get status of X-Ray User Agent service
        :return: JSON encoded result of status action
        zuser-agent-status)r�r�user_nginx_cache)r@rr�r%)rB�agent_statuss  rC�user_agent_statuszBaseManager.user_agent_status�sD��
�-�4�4�6�6���}�}�$7��.>�.@�.@��B�B�	BrEc�*�t��}|ddur|���nS|ddur|���n4|ddur*|���}|�|���S|���S)�]
        Advanced metrics tool
        :return: JSON encoded result of status action
        rLTr�r)r)r"rLr�rr�)rB�args�amrs    rC�advanced_metricszBaseManager.advanced_metrics�s���
�
�
����>�T�!�!��I�I�K�K�K�K�
�)�_��
$�
$��J�J�L�L�L�L�
�(�^�t�
#�
#��Y�Y�[�[�F��=�=��=�/�/�/��}�}���rEc�b�t��t��|���S�rn)r0r,r��rBros  rC�enable_serverwide_modez"BaseManager.enable_serverwide_modes*��
	&�'�'�'������}�}���rEc�b�t��t��|���Srs)r-r/r�rts  rC�disable_serverwide_modez#BaseManager.disable_serverwide_modes*��
	����%�'�'�'��}�}���rE)F)rFr�)C�__name__�
__module__�__qualname__�__doc__rIrRr��boolrDrrJrPr�rTrWrr]rfrlr`rwrur�rv�staticmethodrr��Processr�rqr�r�ror�rtrr�r�r�r�r$r�rrrrr0r2r=rCrrrIrOrQrSrUr[r]r`rdrfrhrlrqrurwr�rErCr3r3Ls%��������
/�N�0�/�/�/�/�/�/�/�/�/�/�/�
�
�H�	H�	H�#�	H�T�	H�	H�	H�	H�G��#��G�G�G�G��D�����8��8��8�8�8�8�L�Z�L�C�L�L�L�L��
��s�����*�:��#�����"A�z�A�d�A�A�A�A�1�J�1�4�1�1�1�1�[�[�[��c��d�������c��h�v�~�&>�����\��L�c�L�d�L�L�L�L�1�s�1�z�1�1�1�1�C�3�C�:�C�C�C�C�V�:�V�$�V�V�V�V�H��H��H�H�H�H�?�J�?�4�?�?�?�?�(�#��#��s�C�x��#�#�#��\�#�*�C�*�D�*�*�*�*�8�	9�c�	9�	9�	9��\�	9�'�'�'�'��!&�"'�<C�<C�<C�C�<C�C�<C��<C�.1�<C��<C� �<C�-7�<C�<C�<C���<C�|>��>��>�>�>�>�02�,�,�,��,�),�,�6@�,�,�,�,�/C�C�/C�J�/C�/C�/C�/C�bA�A�A�2�#C��#C��#C�#C�#C���#C�JC��C�
�C�C�C�C� �
�d�
�t�
�
�
��\�
�
:�
:�
:�
:��
�$�
��
�
�
��\�
�C�c�C�j�C�C�C�C� B�S�B��B��B�B�B�B�C�c�C�j�C�C�C�C�A�C�A�J�A�A�A�A�@�3�@�:�@�@�@�@�0�0�0�0�F�F�F�F�	P�S�	P�Z�	P�	P�	P�	P�
7�C�
7�S�
7�Z�
7�
7�
7�
7�	9�	9�	9�	9�
:�
:�
:�
:�B�B�B�B����� ���������rEr3)Qr{r�r<r}r{r�r�r��sys�typingrrrrrrr��clcommon.constr	�clcommon.cpapir
r�clwpos.papirr
�clcommon.utilsr�clcommon.clpwdr�secureior�xrayrr��adviser.clwpos_getr�	apiclientr�continuous.managerr�internal.exceptionsrrrrr�internal.fpm_utilsr�internal.local_countersr�internal.nginx_utilsr�internal.typesrrr �internal.user_managerr!�internal.advanced_metricsr"�internal.user_plugin_utilsr#r$r%�internal.utilsr&r'r(r)r*r+�reconfiguration.global_inir,r-r.r/r0�
TYPE_CHECKING�apiclient.api_clientr1r3r�rErC�<module>r�sl������������	�	�	�	�
�
�
�
�
�
�
�
�
�
�
�
�����
�
�
�
�
�
�
�
�(�(�(�(�(�(�(�(�������,�,�,�,�,�,�,�,�,�,�
�
�
�
�"�"�"�"�"�"���������B�A�A�A�A�A�A�A�/�/�/�/�/�/�*�*�*�*�*�*�"�"�"�"�"�"�������-�-�-�-�-�-�"�"�"�"�"�"�2�2�2�2�2�2���������������
5�4�4�4�4�4�8�8�8�8�8�8�1�1�1�1�1�1�8�8�8�8�8�8�8�8�8�8�3�3�3�3�3�3�7�7�7�7�7�7�����������
������������������������������
��1�0�0�0�0�0�0�R�R�R�R�R�R�R�R�R�RrE

Zerion Mini Shell 1.0