HEX
Server: LiteSpeed
System: Linux cluster02.load-balancer.x2.network 4.18.0-553.51.1.lve.1.el8.x86_64 #1 SMP Wed May 14 14:34:57 UTC 2025 x86_64
User: kbdhpghp (1098)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/__pycache__/wpos_admin.cpython-311.pyc
�

׊�h����ddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZmZmZmZmZmZddlmZddlmZddlmZdd	lmZmZm Z m!Z!m"Z"dd
l#m$Z$ddl%m&Z&ddl'm(Z(m)Z)dd
l*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;ddl<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZIddlJmKZKddlLmMZMddlNmOZOddlPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`ddlambZbddlcmdZemfZfddlgmhZhmiZiddljmkZkmlZlmmZmddlnmoZoddlpmqZqmrZrddlsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZm�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�ddl�m�Z�m�Z�m�Z�m�Z�ddl�m�Z�m�Z�m�Z�m�Z�ddl�m�Z�m�Z�ddl�m�Z�ddl�m�Z�dd l�m�Z�dd!l�m�Z�m�Z�m�Z�eed"��Z�eed#��Z�ehd$d%eid&�'��Z�eke���Z�d(Z�Gd)�d*e���Z�d+e�d,e�d-ee�e+fd.ee�e+ffd/�Z�d0�Z�d1�Z�d+e�d,e�d2ee�d3ee�fd4�Z�d+e�d5eee�e�e�ffd6�Z�d7�Z�			d=d8e�d9e�dzd:e�dzd;e�dzd5df
d<�Z�dS)>�)�absolute_importN)�deepcopy)�asdict)�Dict�Iterator�Set�Tuple�List�Optional)�Enum)�5is_smart_advice_wordpress_plugin_disabled_server_wide)�
pid_exists)�cpusers�userdomains�is_admin�cpinfo�	getCPName)�get_or_create_unique_identifier��migrate_configs)�install_cron_files�clean_clwpos_crons)�
FeatureStatus�FeatureStatusEnum�AdminSuitesConfig�any_suite_visible_on_server�is_module_visible_for_user�StatusSource�extract_suites�is_suite_visible_for_user)�ALL_OPTIMIZATION_FEATURES�OBJECT_CACHE_FEATURE�CDN_FEATURE�enable_without_config_affecting� disable_without_config_affecting�DocRootPath�SITE_OPTIMIZATION_FEATURE�Feature)
�
ALL_SUITES�BILLABLE_SUITES�UNSUPPORTED_SUITES_FOR_RESELLER�any_suite_allowed_on_server�get_suites_allowed_path�get_admin_suites_config�write_suites_allowed�extract_features�is_module_allowed_for_user�PremiumSuite�CDNSuitePro�CDNSuite�AWPSuite)�drop_privileges)�	WposError)�
UserConfig)�ALT_PHP_REDIS_ENABLE_UTILITY�CLWPOS_UIDS_PATH�PHP_REDIS_ENABLE_UTILITY�SUITES_MARKERS�MIGRATION_NEEDED_MARKER�
SCAN_CACHE�ADMIN_ENABLE_FEATURE_STATUS�ADMIN_ENABLE_FEATURE_PID�$ADMIN_UPDATE_OBJECT_CACHE_BANNER_PID�USERS_PLUGINS_SYNCING_PID�CLN_URL�SMART_ADVICE_ROOT_UTILITY�ON_OFF_IDENTIFIERS�XRAY_MANAGER_UTILITY�CLWPOS_WHMCS_STATS_FILE�MANAGE_SUITE_IN_CLN_DOC)�reload_redis)�gettext�billing)�ArgumentParser�CustomFormatter)�
setup_logging�init_wpos_sentry_safely�ADMIN_LOGFILE_PATH)�	NoPackage)�ReportGenerator�ReportGeneratorError)�catch_error�error_and_exit�
print_data�check_license_decorator�set_wpos_icon_visibility�acquire_lock�write_public_options�get_pw�is_redis_configuration_running�install_monitoring_daemon�get_server_wide_options�is_ui_icon_hidden�ServerWideOptions�daemon_communicate�ExtendedJSONEncoder�is_shared_pro_safely�get_supported_suites�jwt_token_check�should_xray_user_agent_enabled�should_xray_user_agent_disabled�get_accelerate_wp_version�is_user_owned_by_reseller)�get_backup_folders�backup_accelerate_wp�+restore_accelerate_wp_public_options_backup�%make_accelerate_wp_backups_deprecated)�install_dynamic_panel_hooks�"install_yum_universal_hook_alt_php�$uninstall_yum_universal_hook_alt_php�uninstall_dynamic_panel_hooks)�setup_mount_dir_cagefs�_remount_cagefs��fill_current_wpos_statistics)�has_wps)�
disable_quota)�configure_accelerate_wp�configure_accelerate_wp_premium�configure_accelerate_wp_cdnz{Unable to run CL AccelerateWP daemon. Caching databases won't start and work. You can find detailed information in log filez�Configuration of PHP redis extension is running in background process. This may take up to several minutes. Until the end of this process functionality of CL AccelerateWP is limited.z/usr/bin/clwpos-adminz3Utility for control CL AccelerateWP admin interfaceF)�formatter_class�allow_abbrev�ALLc�J�eZdZdZGd�de��Zd�Zed���Zd�Z	e
d���Ze
d���Ze
d	���Z
d
edzdedzfd
�Ze���defd���Zee�dd���e�ddd���e�ddd���e���edefd�������������Zee�ddd���e���ed���������Zee���edefd�������Zee���edefd�������Ze
dId ���Zedefd!���Zd"�Zd#�Zd$eefd%�Z d&�Z!edefd'���Z"d(�Z#d)�Z$eed*�����Z%edefd+���Z&defd,�Z'edefd-���Z(ed.���Z)d/�Z*d0�Z+d1�Z,d2�Z-d3�Z.ee���d4�����Z/ee���dJdefd5�����Z0ee���d6�����Z1ee���d7�����Z2e
d8e3d9e4defd:���Z5d;�Z6d<ed=eed>e7d?e8d@e9j:dAe;dBedCede<ee=effdD�Z>dE�Z?dF�Z@dGefdH�ZAdS)K�CloudlinuxWposAdminz6
    Class for run cloudlinux-wpos-admin commands
    c��eZdZdZdZdZdZdS)�"CloudlinuxWposAdmin.EnablingStatuszH
        Basic statuses while feature is enabling in background
        �idle�progress�doneN)�__name__�
__module__�__qualname__�__doc__�IDLE�PROGRESS�DONE���H/opt/cloudlinux/venv/lib64/python3.11/site-packages/clwpos/wpos_admin.py�EnablingStatusr��s)������	�	��������r�r�c�F�d|_|tt��|_t	|j��d|_d|_ttj	�
d����|_|jrtj
|_dStj|_dS)NFz/var/clwposzmodules_allowed.json�CL_WPOS_WAIT_CHILD_PROCESS)�_is_jsonrNr��_loggerrO�clwpos_path�modules_allowed_name�bool�os�environ�get�wait_child_process�
subprocess�run�	exec_func�Popen��selfs r��__init__zCloudlinuxWposAdmin.__init__�s�����
��&�$�X�.�.������-�-�-�(���$:��!�"&�r�z�~�~�6R�'S�'S�"T�"T����"�	.�'�^�D�N�N�N�'�-�D�N�N�Nr�c�8�|�|��|_d|_|j�dt|j����t
||jj�dd������}t|j|��dS)zs
        Run command action
        :param argv: sys.argv[1:]
        :return: clwpos-user utility retcode
        Tz6CloudLinux Admin CLI command called with arguments: %s�-�_N)
�_parse_args�_optsr�r��info�str�getattr�command�replacerV)r��argv�results   r�r�zCloudlinuxWposAdmin.run�s����&�&�t�,�,��
���
�����R�TW�X\�Xb�Tc�Tc�d�d�d�D���t�z�1�9�9�#�s�C�C�D�D�F�F���4�=�&�)�)�)�)�)r�c��t��N)�NotImplementedError)r�r�s  r�r�zCloudlinuxWposAdmin._parse_args�s��!�!r�c��|D]{}tj|��retj�tj|����s4ttj|��d������|dS)N�w)r<r�r��path�isfile�open�close��suites_list�suites  r��_create_markersz#CloudlinuxWposAdmin._create_markers�sw�� �	=�	=�E��!�%�(�(�
=������@R�SX�@Y�@Y�1Z�1Z�
=��^�'��.�.��4�4�:�:�<�<�<��	=�	=r�c���|D]m}tj|��rWtj�tj|����r&tjtj|�����ndSr�)r<r�r�r�r��unlinkr�s  r��_clear_markersz"CloudlinuxWposAdmin._clear_markers�so�� �	5�	5�E��!�%�(�(�
5�R�W�^�^�"�&�u�-�-�./�./�
5��	�.�,�U�3�3�4�4�4��	5�	5r�c��|dkS)N�onr�)�opts r��_is_truezCloudlinuxWposAdmin._is_true�s���d�{�r�r�N�returnc�4�|�dn|�|��Sr�)r�)r�r�s  r��_nullable_bool_from_optz+CloudlinuxWposAdmin._nullable_bool_from_opt�s���{�t�t��
�
�c�(:�(:�:r�c�<�	t��}nT#ttttf$r4}|j�dt|����icYd}~Sd}~wwxYw|D]�}t|��}t|��5t|��D]k\}}}t|tj
�tj|��j|����}t%t'|��|||����l	ddd��n#1swxYwY��iS)zy
        This command used during downgrade to lve-utils, which version does not support clwpos
        :return:
        z"Can't get user list from panel: %sN��module�domain)r�OSError�IOError�
IndexErrorrQr��warningr�rr6�_enabled_modules�_extract_domainr�r��join�pwd�getpwnam�pw_dirr%r&)	r��users�e�username�user_domains�doc_root�wp_pathr�r�s	         r��uninstall_cache_for_all_domainsz3CloudlinuxWposAdmin.uninstall_cache_for_all_domains�s���	��I�I�E�E����*�i�8�	�	�	��L� � �!E�s�1�v�v�N�N�N��I�I�I�I�I�I�����	�����	s�	s�H�&�x�0�0�L� ��*�*�
s�
s�1A�(�1K�1K�s�s�-�H�g�v�,�\�-/�W�\�\�#�,�x�:P�:P�:W�Ya�-b�-b�d�d�F�4�[��5J�5J�G�\b�kq�r�r�r�r�r�s�
s�
s�
s�
s�
s�
s�
s�
s�
s�
s�
s����
s�
s�
s�
s��
�	s-��A"�)A�A"�A"�A<D�D	�D	�--suiteszPass suites to be configured)�helpz--setupz3Configures AccelerateWP for further suites allowing�
store_true)r��actionz--backupz+Create backup of AccelerateWP configurationc
��|jjr�	t��nq#t$rd}|j�d��t
|jtd��tt|�����d���Yd}~nd}~wwxYw|jjrEtj
�tt j��st%dd���|jjred	�|jj�d
��D��}t*j|vrt-d���t.j|vrt1d���iS)zV
        Internal command to be used from WHMCS to preconfigure needed suites
        z"Cannot backup AccelerateWP configsz.Cannot backup AccelerateWP configs: %(reason)s)�reason�r��contextNT�BILLING_OVERRIDE)�async_set_suite�sourcec�6�g|]}|�����Sr���strip��.0r�s  r��
<listcomp>z1CloudlinuxWposAdmin.set_whmcs.<locals>.<listcomp>	s ��N�N�N��e�k�k�m�m�N�N�Nr��,)r�)r��backuprk�	Exceptionr��	exceptionrUr�r��dictr��setupr�r��existsr<r5�namerx�suites�splitr2ryr3rz)r�r�r�s   r��	set_whmcszCloudlinuxWposAdmin.set_whmcs�s}�� �:��	P�
P�$�&�&�&�&���
P�
P�
P���&�&�'K�L�L�L��t�}��;k�9l�9l�:>�c�!�f�f�:M�:M�:M�/O�/O�P�P�P�P�P�P�P�P�����
P����
�:��	U�B�G�N�N�>�(�-�3P�$Q�$Q�	U�#�D�AS�T�T�T�T��:��	G�N�N���1B�1H�1H��1M�1M�N�N�N�F�� �F�*�*�/�7I�J�J�J�J���6�)�)�+�3E�F�F�F�F��	s��
B�AB�Bz--jsonzPass statistics in json formatT)r��requiredc�D�	tj|jj��n3#tj$r!}t	|jddi��Yd}~nd}~wwxYwt
td��5}|�|jj��ddd��n#1swxYwYiS)zn
        Saves statistics in json file in order to be later
        utilized by the get-stat command.
        r�zMalformed json passedNr�)	�json�loadsr��JSONDecodeErrorrUr�r�rG�write)r�r��fs   r��set_whmcs_statz"CloudlinuxWposAdmin.set_whmcs_stats���	O��J�t�z��'�'�'�'���#�	O�	O�	O��4�=�8�5L�*M�N�N�N�N�N�N�N�N�����	O�����)�3�
/�
/�	%�1�
�G�G�D�J�O�$�$�$�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%����	%�	%�	%�	%��	s&�!�A�A�A�) B�B�Bc���t��}g}	d�t��D��}n�#t$r%}|j�d|��Yd}~n[d}~wt
$rK}|j�d|��t
|jdt|���d���Yd}~nd}~wwxYwt��|tj|jtj|jid�S)	zM
        Internal command to be used from WHMCS to get server config
        c��g|]	}|j��
Sr��r�)r��entrys  r�r�z8CloudlinuxWposAdmin.get_whmcs_config.<locals>.<listcomp>1s��K�K�K�U�e�j�K�K�Kr�z5The folder with backups does not exist yet, error: %sNz4Cannot get backup folders of AccelerateWP, error: %sz4Cannot get backup folders of AccelerateWP: %(error)s)�errorr�)�accelerate_wp_version�backup_folders�upgrade_url)r^rj�FileNotFoundErrorr�r�r�rUr�r�rhr2r�rr3�upgrade_url_cdn)r��server_wide_optionsrr�s    r��get_whmcs_configz$CloudlinuxWposAdmin.get_whmcs_config&s2��6�7�7����	7�K�K�6H�6J�6J�K�K�K�N�N�� �	_�	_�	_��L�"�"�#Z�\]�^�^�^�^�^�^�^�^������	7�	7�	7��L�"�"�#Y�[\�]�]�]��4�=�&\�'+�!�}�}�}�6�6�
7�
7�
7�
7�
7�
7�
7�
7�����	7����&?�%@�%@�,��!�#6�#B�� �"5�"E��
�
�	
s!�+�
B-�A�
B-�"AB(�(B-c�>�t��t��iS)z`
        Internal command to be used from WHMCS to restore previous states from backups
        )rlrmr�s r��restore_whmcs_backupz(CloudlinuxWposAdmin.restore_whmcs_backupCs!��	4�5�5�5�-�/�/�/��	r�c�F�|s	||jvSt||d���S)zq
        if not users passed -> check default visibility value
        otherwise check for specific user
        r�r�)�visible_suitesr )�
suite_name�defaults�users   r��_could_be_allowedz%CloudlinuxWposAdmin._could_be_allowedNs1���	9���!8�8�8�(��d�1�g�F�F�F�Fr�c���t��}|jjtkr!t	tj����}n)d�|jj�d��D��}d}g}t��}d\}}d}|D]}	|	tvrd}n�tj|vrttd���}tj|vrttd���}|j�dt%|��t%|��t%|��t%|����|jjr)d�|jj�d��D��}|D�]2}
|
t
vr3t)|jt-d	��t/|
�
��d���|jjs$|jjs|jjs|jjrI|
t9��vr9t)|jt-d��t/|
t:�
��d���i}t
|
j}|D]�}
|jjrS|
j|jjvr@|
j �9t)|jt-d��t/|
j���d����a|jjs|
j �|
j ||
j<��|
j|jjvr2|
�!|jj|
j��||
j<��|jjr�|jj"r�tGtH|jj"��tHj%krU|�&tNj||���s3t)|jt-d��t/|
�
��d�����4|jj r7tQ|��dkr$t)|jdt-d��i��|jjr7tQ|��dkr$t)|jdt-d��i��|jjr0|jjr$t)|jdt-d��i��d�|D��}|jjr^|j�d��tRj*�+tX��s t[���.��|jjr*t_��}dx}}|�0|��d}n�|jj1r*t_��}dx}}d}|�2|��n�|jjr*t_��}d}d}|�2|��d}nb|jj r-t��}|d|j3v}|d|j4v}n)|jjr|jj}d}n|jjx}}|o|}|ot|vo|}|ot|vo|}i}|rMtkd��\}}}|r8|j�6d||��|�7dtpi��d}|otQ|��dk}|jj"r tGtH|jj"��}nd}|jj9rtu��}|D�]W}	|�;|||rtxj=n|rtxj>ntxj?|pRt�|jj|jj1|jj|jj f��rtHjAntHjB|jjC|||��\}}np#t�$rc}|r*|j�6d|t%|�����|j�Ed|t%|����d}i}Yd}~nd}~wwxYw|rd}��|jjr.|�Fd|gt�jHt�jH� ����Y|rKt���r=t�d�!��t���5}d|_Lddd��n#1swxYwYt�|��r3|�Ft�d"gt�jHt�jH� ��|jjr;|�Fdgt�jHt�jH� ��t���|r,t�t�d#d|jR�$��t���|r�|�7dt�i��|�Ft�gt�jHt�jH� ��|�Ft�gt�jHt�jH� ��t���n5|r3t|vr*t���r|�7dt�i��|s|r9t�t�j[t�ttg|||g��d�%��|jjs|jjrWtRj*�+t���r3|j�d&��tSj^t���t���sY|jjrMtRj*�`d'��r.|�Fd'd(gt�jHt�jH� ��|r,t)|jt-d)��d*t�id���|�b||��|jj1rt���|�st��s�t���t���t���t�d�!��tRj*�`d'��r.|�Fd'd(gt�jHt�jH� ��t���5}d|_Lddd��n#1swxYwYt���r3|�Ft�d+gt�jHt�jH� ��|jjs|jjrW|rC|j�d,��|�g��|�h|��t�d-dd.���|jjro|jj"rctGtH|jj"��tHj%kr6|�jd�k|��d/d0|jj�1��|�Fd2d3gt�jHt�jH� ��|S)4zG
        Write info related to module allowance into user file
        c�6�g|]}|�����Sr�r�r�s  r�r�z2CloudlinuxWposAdmin._set_suite.<locals>.<listcomp>as ��S�S�S�U�5�;�;�=�=�S�S�Sr�r�F)FFT)�	use_cachez�Initial AccelerateWP statuses: fist_activation=%s, is CDN already visible=%s, is AccelerateWP Premium already visible=%s,server wide defaults=%sc�6�g|]}|�����Sr�r�)r�rs  r�r�z2CloudlinuxWposAdmin._set_suite.<locals>.<listcomp>�s ��#Y�#Y�#Y�T�D�J�J�L�L�#Y�#Y�#Yr�zUnsupported suite: %(suite)s)r�r�z�Suite %(suite)s is disabled on the license level. To resolve the issue, please, enable it in CLN by following this article: %(link)s)r��linkNzHAttribute %(attr_name)s does not have default value and must be included)�	attr_name)rz�AccelerateWP is not visible for users and so %(suite)s cannot be allowed in billing. Activate the AccelerateWP on server first. Contact your hoster if you don`t have an access to the server.�r�z0Only one suite is possible with --default optionz.Only one suite is possible with --attrs optionz?Only default suite configuration can be activated for all usersc�<�g|]}t|jD]}|���Sr�)r)�feature_set)r�r�r�s   r�r�z2CloudlinuxWposAdmin._set_suite.<locals>.<listcomp>�s.��d�d�d�5�j�QV�FW�Fc�d�d�F��d�d�d�dr�zGoing to generate users reportrz)Starting service ended with error: %s, %sr�z*Error while processing module for '%s': %szTError while processing module for '%s', processing other users will be continued: %sz'/usr/sbin/clwpos_collect_information.py��stdout�stderr��hidezenable-user-agent�*)�prefix�remount_cagefs�remount_in_background�r�z7set-suite for all was called, removing migration markerz/usr/sbin/cl-smart-advicezwordpress-plugin-installz8User(s) process error. Please check log file %(logfile)s�logfilezdisable-user-agentzETriggering syncing of billable suites statuses with external services�suite_allowed_callback)r��uid�feature_allowed�whmcs)r��eventr��featurez)/usr/sbin/generate_accelerate_wp_cache.pyr�)lr^r�r��ALL_SUITES_OPTION�listr)�keysr�rr*r4r�rr#r2r"r�r�r�r�rUr�r�r��allowed�visible�visible_for_all�allowed_for_allrdrH�allowed_attrubites�attrs�default�typer�r�rr�rr5�lenr�r�r�r>rR�scanrr��disallowed_for_allr�r�allowed_suitesr]r�update�WPOS_SERVICE_ENABLE_ERR_MSG�preserve_user_settings�tuple�_process_user_suitesr�ALLOWED�VISIBLE�DISABLED�any�DEFAULT�COMMAND_LINE�
purchase_dater�r�r�r��DEVNULLr_rXrZ�	show_iconrfrFrsrrr:r�rn�REDIS_CONFIGURATION_WARNING_MSGr9r;ror\r�	itertools�compressr'r=�remover
r�rP�$_save_suites_list_to_public_settingsrprqrrg�_trigger_cln_sync�_force_user_syncra�_send_analytics_reportr�) r�rr��for_all_operation�user_list_to_process�any_suite_already_visible�is_cdn_feature_already_visible�is_object_cache_already_visible�billable_suite_passedrr��valid_attributes�
allowed_attrs�	attribute�modules_list�module_allowed�module_visible�first_user_wpos_visible�first_user_cdn_allowed�first_user_obj_cache_visible�warning_dict�retcoderr�
error_flag�is_one_user_processing�source_overrider��_error_flag�	warning_dr��optionss                                 r��
_set_suitezCloudlinuxWposAdmin._set_suiteXs@��
+�,�,���:�� 1�1�1��z��0�0�1�1�K�K�S�S�d�j�6G�6M�6M�c�6R�6R�S�S�S�K�!��!��%@�$A�$A�!�JV�G�&�(G� %��%�	�	�J��_�,�,�(,�%���-�
�=�K�'�'�-G��_c�-d�-d�-d�*����+�+�.H�I]�im�.n�.n�.n�+�����4��";�;�<�<��<�=�=��=�>�>��h�-�-�	)�	)�	)��:��	Z�#Y�#Y�T�Z�=M�=S�=S�TW�=X�=X�#Y�#Y�#Y� � �(	3�(	3�E��J�&�&��t�}�*+�,J�*K�*K�+/�e�+<�+<�+<� >� >�?�?�?��
�"�
l��:�%�
l��:�-�
l��:�-�
l��!5�!7�!7�7�7��t�}��<k�:l�:l�;?�U�Qh�:i�:i�:i�/k�/k�l�l�l�
 "��&�u�-�@�M�*�
l�
l�	��:�#�
l�%�N�$�*�2B�B�B�%�-�5�"�4�=�Q�@\�>]�>]�>B�Y�^�>\�>\�>\�3^�3^�_�_�_�_���)�l�i�.?�.K�7@�7H�$�Y�^�4�4� �~���)9�9�9�;D�>�>�$�*�JZ�[d�[i�Jj�;k�;k�(���8���z�!�
3�d�j�&7�
3��L�$�*�*;�<�<��@]�]�]� �2�2�8�=�(�Qe�2�f�f�^��t�}��!a�b�b� $�%�0�0�0�/2�/2�3�3�3���:��	m�#�k�"2�"2�Q�"6�"6��4�=�8�Q�7i�5j�5j�*k�l�l�l��:��	k��K� 0� 0�1� 4� 4��4�=�8�Q�7g�5h�5h�*i�j�j�j��:��	\��
� :�	\��4�=�8�Q�8Y�6Z�6Z�+[�
\�
\�
\�e�d�K�d�d�d���:�%�	)�
�L���>�?�?�?��7�>�>�*�-�-�
)��!�!�&�&�(�(�(��:�%�	I�#*�9�9� �.2�2�N�^�� � ��-�-�-� $���
�Z�
*�	I�#*�9�9� �.3�3�N�^� $������,�,�,�,�
�Z�
'�	I�#*�9�9� �"�N�!�N�����,�,�,� $����z�!�	
I�2�4�4��!,�Q��8�3J�!J��!,�Q��8�3J�!J����:�%�I�%)�Z�%7�N�%*�N�N�6:�j�6H�H�N�^�"0�"R�9R�5R��!/�"3�K�<�4O�"3�2�2�	�'5�(4�:N�R^�:^�(4�3�3�	%����	N�&?��&E�&E�#�G�V�V��
N���"�"�#N�PV�X^�_�_�_��#�#�Y�0K�$L�M�M�M��
�%6�!6�!Y�3�?S�;T�;T�XY�;Y���:��	#�%�l�D�J�4E�F�F�O�O�"�O��:�,�	+�#(�7�7� �,�0	�0	�H�#
�)-�)B�)B���*�3�)�1�1�9G�3�-�5�5�)�2�#��03� �J�6� �J�9� �J�6� �J�.�	50�1�1�9��,�,�
 ,�8��J�,�$�*�%�)*'�*'�&��Y�Y��*�

�

�

�*���L�&�&�D� �#�a�&�&�*�*�*����&�&�j��c�!�f�f�&�&�&�#���	�	�	�	�	�	�����

�����
�!�
���z�!�
����>��I�%�-�%�-�������	)�/�1�1�	)�$�%�0�0�0�0�%�'�'�
)�7�$(��!�
)�
)�
)�
)�
)�
)�
)�
)�
)�
)�
)����
)�
)�
)�
)�*�.�9�9�	6��N�N�0�2E�F�",�"4�",�"4�
�
6�
6�
6�
�:�%�	��N�N�E�F�z�Oa�",�"4�
�
6�
6�
6�����"�	*�"� ��T�*.�*A�&A�
�
�
�
�
(�)�)�)�'�	N�
����,K� L�M�M�M��N�N�8�9�*�BT�]g�]o�N�p�p�p��N�N�4�5�j�>P�Yc�Yk�N�l�l�l�.�0�0�0�0�
�	N� 4�� D� D�Ig�Ii�Ii� D�����,K� L�M�M�M�"�	,�&B�	,���"�.�0D�k�R�,�.J�Lb�c���'+�	
,�
,�
,�
,�
�J�&�	/�$�*�*D�	/�"�'�.�.�Yp�Jq�Jq�	/��L���W�X�X�X��I�-�.�.�.�E�F�F�	/�4�:�Ke�	/��w�~�~�9�:�:�
/����/�1K� M�%�-�%�-��/�/�/�
�	���
�� Z�[�[� )�+=�>���
�
�
�	
�1�1�+��O�O�O��:�(�	������	:�&A�&C�&C�	:�0�2�2�2�)�+�+�+�� � � �$�$�/�/�/�/��w�~�~�9�:�:�
/����/�1K� M�%�-�%�-��/�/�/�&�'�'�
*�7�$)��!�
*�
*�
*�
*�
*�
*�
*�
*�
*�
*�
*����
*�
*�
*�
*�/�0�0�
:���� 4�6J�K�&0�&8�&0�&8��:�:�:�
�:�%�	���);�	�$�
<���!�!�"i�j�j�j��&�&�(�(�(��%�%�&:�;�;�;�
�3�� � �
�
�
�
�:��	C�$�*�"3�	C��L�$�*�*;�<�<��@]�]�]��'�'����:N�1O�1O�.?�/6�04�
�0A�
(�
C�
C�
C�	
���
8�*�E��%��%�	�	�	�	��s>�3B"]�
_� A^>�>_�6a
�
a�a�)o=�=p�pc��tj�t��s|j�d��dS	t
jtdd|d|d|d|g
tjd���dS#tj	$rB}|j�d	t|��||||j|j��Yd}~dSd}~wwxYw)
NzKSending analytics is skipped, because alt-php-xray package is not installedzreport-analytics�	--featurez--eventz
--usernamez--sourceT�r�textz\Unable to send analytics username=%s, feature=%s, source=%s, event=%s stderr: %s; stdout: %s)
r�r�r�rDr�r�r��check_output�PIPE�CalledProcessErrorr�rr)r�r�r,r�r+r�s      r�rQz*CloudlinuxWposAdmin._send_analytics_report�s���w�~�~�7�8�8�	��L� � �!n�o�o�o��F�	<��#�%>�%7�%0�'�%.��%1�8�%/��%9�,6�?��

G�
G�
G�
G�
G�
G���,�	<�	<�	<��L� � �":�!$�X���!(�!'�!&���!�(�
<�
<�
<�
<�
<�
<�
<�
<�
<�����	<���s�0A4�4C�7C�Cc�b�|�ddgtjtj���dS)Nz/usr/bin/cloudlinux-awp-adminzcln-syncr)r�r�rHr�s r�rOz%CloudlinuxWposAdmin._trigger_cln_sync�s;�����
,�j�9��%��%�	�	
�	
�	
�	
�	
r��userlistc��tj�t��s|j�d��dSg}|D]P}	|�t|�����&#t$r|j�	d|��Y�MwxYw|s|j�d��dS	tjtddd�|��gtj
d�	��dS#tj$r?}|j�d
t|��|j|j��Yd}~dSd}~wwxYw)za
        Communicates with AWP provision server asking it to fetch data about user ASAP.
        zGForce syncing is skipped, because alt-php-xray package is not installedNz)Unable to obtain account_id for user %s. zNo account_ids to be syncedzawp-syncz--account_idr�TrlzKUnable to force synchronization of data for user %s. stderr: %s; stdout: %s)r�r�r�rDr�r��appendrr�r�r�rnr�rorpr�rr)r�rr�account_idsr�r�s     r�rPz$CloudlinuxWposAdmin._force_user_sync�s����w�~�~�7�8�8�	��L� � �!j�k�k�k��F��� �	�	�H�
��"�"�#B�8�#L�#L�M�M�M�M���
�
�
���&�&�'R�T\�]�]�]���
�����	��L� � �!>�?�?�?��F�	^��#�%>�%/�%3�%(�X�X�k�%:�%:�%<�,6�?��	
G�
G�
G�
G�
G�
G��
�,�	^�	^�	^��L� � �":�;>�x�=�=�!�(�TU�T\�
^�
^�
^�
^�
^�
^�
^�
^�
^�����	^���s*�"A+�+%B�B�5=C4�4E�4D=�=Ec�0�t��5}|r|tjkr|j}n|}d�|D��D�]C}|jjr_t
t|j��|j	hz��|_t
t|j
��|j	hz��|_
�n|jjr_t
t|j��|j	hz
��|_t
t|j
��|j	hz��|_
��|jjr^t
t|j��|j	hz
��|_t
t|j
��|j	hz
��|_
��E	ddd��dS#1swxYwYdS)z�
        Saves list of suites that are currently allowed/visible/disallowed
        to config which each user on server can read.
        c�(�g|]}t|��Sr�)r)r�s  r�r�zLCloudlinuxWposAdmin._save_suites_list_to_public_settings.<locals>.<listcomp>�s��E�E�E��*�U�+�E�E�Er�N)
rZrr��
whmcs_optionsr�r3r.�setr;r�rr2r:)r�r�r��server_options�target_suites_optionsr�s      r�rNz8CloudlinuxWposAdmin._save_suites_list_to_public_settings�s���
"�
#�
#�	z�~��
7�&�L�$A�A�A�(6�(D�%�%�(6�%�E�E��E�E�E�	
z�	
z���:�-�z�;?��DY�Dh�@i�@i�mr�mw�lx�@x�;y�;y�)�8�;?��DY�Dh�@i�@i�mr�mw�lx�@x�;y�;y�)�8�8��Z�/�z�;?��DY�Dh�@i�@i�mr�mw�lx�@x�;y�;y�)�8�;?��DY�Dh�@i�@i�mr�mw�lx�@x�;y�;y�)�8�8��Z�2�z�;?��DY�Dh�@i�@i�mr�mw�lx�@x�;y�;y�)�8�;?��DY�Dh�@i�@i�mr�mw�lx�@x�;y�;y�)�8��	
z�	z�	z�	z�	z�	z�	z�	z�	z�	z�	z�	z�	z����	z�	z�	z�	z�	z�	zs�E.F�F�Fc	�V�|jjr\|�|jj��}t|���\}}|r't	|jt
d��d|id���t��5}|jj�.|�|jj��rd|_nd|_|jj	�.|�|jj	��rd|_
nd|_
t||�|jj
��|�|jj��|�|jj�����|jj�[|jjt$jkr|jjpd|_n-|jjt(jkr|jjpd|_ddd��n#1swxYwY|jjrI|jjr=|�|jj|�|jj����iS)	z~
        Set global options that affect all users.
        For v1 it is only allowed to control WPOS icon visibility.
        rzAError during changing of AccelerateWP icon visibility: 
%(error)srr�NTF)�enable_notifications�enable_reminders�enable_wordpress_plugin)r��icon_visibler�rXrUr�r�rZrI�object_cache_banner_visible�disable_object_cache_banners�#_switch_smart_adive_related_optionsr��smart_advice_notifications�smart_advice_reminders�smart_advice_wordpress_pluginrr�r2r�r3r�feature_visible�features�set_feature)r��
is_visiblerbrrhs     r��_set_optionsz CloudlinuxWposAdmin._set_options�s]���:�"�
	����t�z�'>�?�?�J�6�
�N�K�K�K�O�G�V��
���M�"#�$h�"i�"i�$+�V�#4������"�
#�
#�	M�w��z�&�2��=�=���!8�9�9�.�(,�G�%�%�(-�G�%��z�5�A��=�=���!G�H�H�@�;@�G�8�8�;?�G�8�/��%)�%A�%A�$�*�Bg�%h�%h�!%�!=�!=�d�j�>_�!`�!`�(,�(D�(D�T�Z�Em�(n�(n�	
�
�
�
��z�%�1��:�#�|�'8�8�8�*.�*�*@�*H�D�G�'�'��Z�%��)9�9�9�.2�j�.D�.L��G�+�+	M�	M�	M�	M�	M�	M�	M�	M�	M�	M�	M����	M�	M�	M�	M�.�:�%�	]�$�*�*=�	]����T�Z�0�$�-�-��
�@Z�2[�2[�\�\�\��	s�7EG	�	G
�G
c�F�d�|�d��D��}d�tD��}|D].}||vr(t|jt	d��||d�d����/td�|D����}tt
��j��}|s�t|�	|����}tj}tj�	tj��}	|�|��r't|jt	d��d	|id���|	�|��r't|jt	d
��d	|id���n"t|�|����}t!��5}
||
_|sb|r`tt#����D]D}	|�||���#t&$r|j�d|��Y�AwxYwddd��dS#1swxYwYdS)Nc�6�g|]}|�����Sr�r��r�r,s  r�r�z3CloudlinuxWposAdmin.set_feature.<locals>.<listcomp>,s ��G�G�G��G�M�M�O�O�G�G�Gr�r�c�d�g|]-}|tj��k�|�����.Sr�)r'�optimization_feature�to_interface_name�r�r�s  r�r�z3CloudlinuxWposAdmin.set_feature.<locals>.<listcomp>0sE��V�V�V�a� �$=�$R�$T�$T�T�T��/�/�1�1�T�T�Tr�zZInvalid feature name passed: 
%(feature)s.
 You may set only those features: %(supported)s)r,�	supportedr�c�P�g|]#}t|�������$Sr�)r(r�r�s  r�r�z3CloudlinuxWposAdmin.set_feature.<locals>.<listcomp>>s*��S�S�S�Q�w�q�z�z�>�>�@�@�S�S�Sr�z�Hiding all features of AccelerateWP Premium is not permitted, please use 'set-suite' command instead to disallow all Premium features to users: 
%(feature)sr,z�Hiding all features of AccelerateWP is not permitted, please use 'set-suite' command instead to disallow all Premium features for users: 
%(feature)sz;Unable to disable feature on set-feature --hide for user %s)r�r!rUr�r�ryr^�hidden_featuresr.�unionr2rr5r4�issubset�
differencerZr�_disable_featurer�r�r�)r�r�r��possible_to_hider,�target_features�already_hidden�features_to_hide�all_premium_features�all_free_featuresrhrs            r�r�zCloudlinuxWposAdmin.set_feature+s���G�G�8�>�>�#�3F�3F�G�G�G��V�V�;T�V�V�V�� �		�		�G��.�.�.���M�"#�%V�#W�#W�/6�EU�#V�#V��������S�S�(�S�S�S�T�T���4�6�6�F�G�G���"	P�#�O�$9�$9�.�$I�$I�J�J��#/�#;� � (� 4� :� :�8�;O� P� P��$�,�,�-=�>�>�	
���M�"#�%O�#P�#P�%.�/?�#@�	�����!�)�)�*:�;�;�	
���M�"#�%P�#Q�#Q�%.�/?�#@�	������ $�N�$=�$=�o�$N�$N�O�O��
!�
#�
#�	!�w�&6�G�#��
!�"2�
!� ����O�O�!�!�D�!��-�-�.>��E�E�E�E��$�!�!�!���.�.�0=�>B�D�D�D� ��!����	!�	!�	!�	!�	!�	!�	!�	!�	!�	!�	!�	!����	!�	!�	!�	!�	!�	!s6�)H�G�H�%H�H�H�H�H�Hc��t|��}t|��5t|�����}ddd��n#1swxYwY|D]�\}}}t	|t
j�tj	|��j
|����}||vr�Pdd|dd|d|d|g
}	tj|	dd���}
|j
�|
j��|j
�|
j����dS)	N�/usr/bin/clwpos-user�--user�disablerk�	--wp-path�--domainT)rm�capture_output)rr6r8�enabled_modulesr�r�r�r�r�r�r�r�r�r�r�rr)r�r�rr��enabled_featuresr�r�r�r�r�r�s           r�r�z$CloudlinuxWposAdmin._disable_featurersf��"�4�(�(��
�T�
"�
"�	B�	B�)�$�/�/�?�?�A�A��	B�	B�	B�	B�	B�	B�	B�	B�	B�	B�	B����	B�	B�	B�	B�)9�		-�		-�%�H�g�v�$�\�%'�W�\�\�#�,�t�2D�2D�2K�X�%V�%V�X�X�F��X�%�%��-�x��y�+�W]�"�G�Z��A�G��^�G�$�t�L�L�L�F��L���f�m�,�,�,��L���f�m�,�,�,�,�		-�		-s�"A
�
A�Ac�>�	tt����}|���}d�|�dg��D��}||d<|S#tjj$r0}ttd��t|������d}~wwxYw)Nc�0�g|]}t|���|��Sr�)r r�s  r�r�z4CloudlinuxWposAdmin._get_options.<locals>.<listcomp>�s'��z�z�z��Yr�sx�Yy�Yy�z�e�z�z�zr��supported_suitesrzUFile is corrupted: Please, delete file mentioned in details or fix the corrupted line)�message�details)
rr^�copyr�r��decoderr�r7r�r�)r�rrhr�errs     r��_get_optionsz CloudlinuxWposAdmin._get_options�s���	"��5�7�7�8�8�H��m�m�o�o�G�z�z����>P�RT�1U�1U�z�z�z�N�(6�G�$�%��N���|�+�	"�	"�	"���k�m�m��C���"�"�"�
"�����	"���s�AA�B�,+B�Bc��i}	|jjr|jj�d��nd}t���|���}nr#t
$r,}t
|j|j|j	d���Yd}~nAd}~wt$r1}t
|jtd��d|id���Yd}~nd}~wwxYw|S)z)
        Print report in stdout.
        r�N)�target_usersr�z&Error during getting report: %(error)sr)r�r�r�rRr�rSrUr�r�r�r�r�)r��reportr�r�s    r��_get_reportzCloudlinuxWposAdmin._get_report�s"��
��	�37�:�3C�M�D�J�$�*�*�3�/�/�/��E�$�&�&�*�*��*�>�>�F�F��#�	�	�	���
��i� �y���
�
�
�
�
�
�
�
������	�	�	���
�� H�I�I� '��|���
�
�
�
�
�
�
�
�����	�����
s$�AA�
C�"B�
C�'B>�>Cc	��t��}	|jjr|���}n|���}ddi|�S#t
$r-}t
|j|j|j	d���Yd}~dSd}~wt$r?}t
|jtd��dt|��id���Yd}~dSd}~wwxYw)Nr��successr�z)Error during generating report: %(error)sr)
rRr��status�
get_statusr9rSrUr�r�r�r�r�r�)r��rg�scan_statusr�s    r��_generate_reportz$CloudlinuxWposAdmin._generate_report�s/��
�
�
��	��z� �
(� �m�m�o�o���!�g�g�i�i���)����
��$�	�	�	���
��i� �y���
�
�
�
�
�
�
�
�
������	�	�	���
�� K�L�L� '��Q���0���
�
�
�
�
�
�
�
�
�����	���s#�:A�
C	�"A=�=
C	�
4C�C	c��t��S)zAccelerateWP statisticsrtr�s r��	_get_statzCloudlinuxWposAdmin._get_stat�s��,�-�-�-r�c�Z�d}|jjr |jj�d��}ntt	����}|jjr|���Stj�	t��r,t|jtd��dtid���tj�	t��rtjt��|�t|j||��}|�"d|jjjt+|��d�S|\}}t-td	��5}t/j||t+|��d
�|d���ddd��n#1swxYwYt3jd
��dS)zt
        cli command for enabling optimization feature for all sites on the server
        (where possible)
        �
accelerate_wpr�z�Feature enabling is already in progress.  Process pid is stored in %(progress_marker)s.If process with such pid does not exist - please, remove file "%(progress_marker)s" and re-run command�progress_markerr�Nr�)r�r��total_users_countr�)�!wordpress_sites_to_enable_feature�$wordpress_sites_with_enabled_featurer��)�indentr)r�r�r�r.rr��_feature_enable_statusr�r�r�r@rUr�r�r?rM�run_in_background�_enable_feature_for_usersr�r��valuer8r�r��dump�sys�exit)r�r,r��
enable_result�total_websites_to_enable�total_enabled_websitesr�s       r��_enable_featurez#CloudlinuxWposAdmin._enable_feature�s���"���:��	$��J�$�*�*�3�/�/�E�E�����O�O�E��:��	1��.�.�0�0�0�
�7�>�>�2�3�3�
	���
��!5�6�6�!2�3K�L���	
�	
�	
��7�>�>�5�6�6�	3��I�1�2�2�2��.�.�/G��Ig�in�pw�x�x�
�� �'�4�3F�3O�3U�lo�pu�lv�lv�w�w�w�;H�8� �"8�
�-�s�
3�
3�	�q��I�5M�8N�%(��Z�Z�����	
�
�
�
�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�������s�)F�F�Fc��ddi}|jjj}tj�t��rtt��5}|����	��}ddd��n#1swxYwYtt|����r|jjj}tj�t��r�|jjj}tt��5}|�t!j|����ddd��n#1swxYwY|�d��|�d��kr
dt&��|d<||d<|S)	a
        Check current status of enabling feature process
        - idle: if no pid file
        - in progress: if pid file exists and such pid really exists in process list
        - done: is enabling status file exists (which is created when process finishes)
        r�r�Nr�r�z`Feature was enabled not for all sites on the server, due to some errors. Please, take a look at r�r�)r�r�r�r�r�r�r@r��readliner�r�intr�r?r�r<r��loadr�rP)r��datar�r��pids     r�r�z*CloudlinuxWposAdmin._feature_enable_status�s����)�$���$�)�/��
�7�>�>�2�3�3�	=��.�/�/�
+�1��j�j�l�l�(�(�*�*��
+�
+�
+�
+�
+�
+�
+�
+�
+�
+�
+����
+�
+�
+�
+��#�c�(�(�#�#�
=��-�6�<��
�7�>�>�5�6�6�	Q��(�-�3�F��1�2�2�
*�a����D�I�a�L�L�)�)�)�
*�
*�
*�
*�
*�
*�
*�
*�
*�
*�
*����
*�
*�
*�
*��x�x�;�<�<����Io�@p�@p�p�p�#Q�<N�#Q�#Q��Y����X���s$�'B�B�B�(D6�6D:�=D:c��d}tj��}|rdSttjd��}ttjd��}ttjd��}	tj|���tj�����tj|���tj�����tj|	���tj	�����tj
��}
t|d��5}|�t|
����ddd��n#1swxYwY	||i|��}|�|n|	tj
�|��rtj|��SS#tj
�|��rtj|��wwxYw)zb
        Forks child process in background if needed and created pid file with forked pid
        TN�rza+r�)r��forkr��devnull�dup2�filenor��stdinrr�getpidr�r�r�r�rM)
r��pidfile�func�args�kwargs�dummy_result�fp�si�so�se�	child_pidr��func_results
             r�r�z%CloudlinuxWposAdmin.run_in_backgrounds���
��
�W�Y�Y��
�	��F��"�*�c�
"�
"��
�"�*�d�
#�
#��
�"�*�d�
#�
#��
���	�	���S�Y�-�-�/�/�0�0�0�
���	�	���S�Z�.�.�0�0�1�1�1�
���	�	���S�Z�.�.�0�0�1�1�1��I�K�K�	�
�'�3�
�
�	$�1�
�G�G�C�	�N�N�#�#�#�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$����	$�	$�	$�	$�	#��$��/��/�/�K�"-�"9�;�;�|�K��w�~�~�g�&�&�
#��	�'�"�"�"�"�
#��r�w�~�~�g�&�&�
#��	�'�"�"�"�"�
#���s�#F�F�
F�
G�6Hc�^�d\}}|D�]!}	|�||��}n+#t$r|j�d|��Y�BwxYw|t	d�|���D����z
}|���D]�\}}|D]�}	|j�d|||	��	|�|||	||j	j
|j	j��}
|
dd}n,#t$r|j�d||	��Y��wxYw|r|dz
}������#||fS)	a�
        Enables passed feature for passed username`s sites
        domains and target sites are obtained via user cli utility get (which  knows all
        about incompatibilities and able to detect sites/domains correctly)

        for those sites which do not have any incompatibilities - run user cli command enable feature

        returns <how many sites we should enable> and <how many sites were in fact enabled w/o errors>
        )rrz5Unable to get websites info for enabling feature "%s"c3�4K�|]}t|��V��dSr�)r8)r��websitess  r��	<genexpr>z@CloudlinuxWposAdmin._enable_feature_for_users.<locals>.<genexpr>Gs(����+^�+^�h�C��M�M�+^�+^�+^�+^�+^�+^r�z=Enabling optimization feature "%s" for user "%s" website "%s"r,�enabledz0Failed to enable feature "%s" for website "%s". r)�_get_target_websitesr�r�r��sum�values�itemsr��_enable_for_siter��
ignore_errors�skip_dns_check)r��	usernamesr,r�r�r��
target_wpsr�r��wp_siter��enabled_statuss            r�r�z-CloudlinuxWposAdmin._enable_feature_for_users4s���<@�8� �"8�!�	4�	4�H�
�!�6�6�x��I�I�
�
���
�
�
���&�&�'^�'.�0�0�0���
����

%��+^�+^�*�J[�J[�J]�J]�+^�+^�+^�(^�(^�^�$�$.�$4�$4�$6�$6�
4�
4� ���'�4�4�G��L�%�%�&e�&-�&.�&-�/�/�/�	!�(,�(=�(=�h��QX�Z`�>B�j�>V�>B�j�>W�)Y�)Y�
�*7�y�)A�)�)L����$�!�!�!���.�.�/a�/6�/6�8�8�8�!��	!����&�4�.�!�3�.��#4�
4�&(�)?�?�?s!�#�%A�
A�7<C4�4&D	�D	c����i}t|��retjdd|dgddd���}tj|j��d}|D]'}|dd	}�fd
�|dD��||<�(|S)z;
        Gets target websites via user command GET
        r�r�r�TiX)r�rm�timeout�docroots�domainsrc���g|]?}|d�d�|d��d���7|d��@S)r�r��issuesr�)r�)r��wpr,s  �r�r�z<CloudlinuxWposAdmin._get_target_websites.<locals>.<listcomp>lsf���&�&�&���j�>�'�2�9�=�&�GI��n�U\�F]�Fa�Fa�bj�Fk�Fk�&��v�J�&�&�&r��wps)rvr�r�r�r�r)r�r�r,r�r��
docroots_info�docrootr�s  `     r�r�z(CloudlinuxWposAdmin._get_target_websites^s�����
��8���	��^�'��8�U�C�#�$��=�=�=�F�!�J�v�}�5�5�j�A�M�(�
�
�� ��+�A�.��&�&�&�&�%�e�n�&�&�&�
�6�"�"�
�r�c
�V�dd|dd|d|d|g
}|r|�d��n|r|�d��tj|d	d	d
���}|j�|j��|j�|j��tj|j��S)z=
        Enables feature via user cli command ENABLE
        r�r��enablerkr�r�z--ignore-errorsz--skip-dns-checkT��rmr�r�)	rtr�r�r�r�rrr�r�)	r�r�r,r�r�r�r�r�r�s	         r�r�z$CloudlinuxWposAdmin._enable_for_sitess���*�8�X�x��V]�
�'�:�v�7���	/��N�N�,�-�-�-�-�
�	/��N�N�-�.�.�.����d�4�QT�U�U�U������&�-�(�(�(�����&�-�(�(�(��z�&�-�(�(�(r�c
��t��}ttj����t|��z
}|sdSt	jd|��t
jdddd�t|����dgddd	�
��}|j
�|j��|j
�|j��dS)zU
        Automatically turn off suites that are not suppoted on this server.
        Nz-Suites %s need to be turned off on the serverzcloudlinux-awp-adminz	set-suiter�r�z--disallowed-for-allTir)
rdryr)r/�loggingr�r�r�r��sortedr�rr)r�r��suites_to_turn_offr�s    r��
billing_checkz!CloudlinuxWposAdmin.billing_check�s���0�1�1�� ���!2�!2�3�3�c�:J�6K�6K�K��!�	��F���D�FX�Y�Y�Y���!7��!+�S�X�X�f�=O�6P�6P�-Q�-Q�!7�!9�&*�$��N�N�N��	
����&�-�(�(�(�����&�-�(�(�(�(�(r�c
�2�tj��}|s|j�d��|St�d�}t��\}}}|s|j�d|��n�tj|tj
|t���d|�d����dd��	��}|j
d
krW|j�dt|j
��|jdtj
|t���|j
d
����|S)zAccelerateWP cln integrationz3CLN report is empty, report to CLN will not be sentz/cln/api/clos/server/addons/v2z-JWT error: %s, report to CLN will not be sent)�clszJWT zutf-8zapplication/json)�
AuthorizationzContent-Type)r��headers��z<CLN report sending failed with status: %s, http response: %sT)r��fingerprint)�exc_info�extra)rK�
get_reportr�r�rCrer��requests�postr��dumpsrb�decode�status_coderr�rm)r�r�r��cln_report_urlr�r��jwt_strr�s        r��cln_synczCloudlinuxWposAdmin.cln_sync�s?���#�%�%���	��L���S�T�T�T��M�#�C�C�C�� /� 1� 1����g��	%��L� � �!P�RU�V�V�V�V��
�n�#'�:�f�:M�#N�#N�#N�8X�w�~�~�g�?V�?V�8X�8X�7I�'K�'K�L�L�L�A�
�}��#�#���"�"�#a�#&�q�}�#5�#5�q�v�,0�26�*�V�I\�2]�2]�2]�9:��*H�*H�#�%�%�%��
r�c�"�t��dS)NTrr�s r�rz#CloudlinuxWposAdmin.migrate_configs�s��	�����tr�c
���ttjttt
gt
��tt��tt
��g��d���dS)z�
        Install cron files based on current status of wpos.

        This code is executed after updates to add new
        cron files that might be missing.
        Tr%)rrKrLr'r#r"rr1r�s r��sync_cron_filesz#CloudlinuxWposAdmin.sync_cron_files�sl��	���-��(��0�1�1�.�{�;�;�.�/C�D�D��

�
�#'�	(�	(�	(�	(��tr��suites_admin_config�default_configc��|j���D]k\}}|tjtjfvrdS|tjkr9t
t|j��t
|j	��z}|rdS�ldS)z;
        Check if all feature suites are disabled.
        FT)
r�r�rrBrArEryr)r�allowed_features)r"r#r�r��any_feature_enabled_by_defaults     r��all_suites_disabledz'CloudlinuxWposAdmin.all_suites_disabled�s���1�7�=�=�?�?�	!�	!�M�E�6��+�3�5F�5N�O�O�O��u�u��*�2�2�2��
�5�)�5�6�6��^�=\�9]�9]�]�/�1�!� �5�5���tr�c�t�t|��}t��dko|dk}t||g��S)N�DirectAdmin�admin)rirrD)r�r��is_owned_by_admin�should_be_whitelisteds    r��_is_supported_for_userz*CloudlinuxWposAdmin._is_supported_for_user�sA�� 9�(� C� C�C�� )���}� <� T��W�AT���%�'<�=�>�>�>r��	user_namer��
allowed_state�state_sourcerG�
attributes�is_one_userrRc	
�F�	t|���}	|	j|	j}}
nU#t$rH|r't	|jt
d��d|id���|j�d|��YdSwxYwd�|D��}|rw|tj
krg|�|��sR|j�d|t|����|r't	|jt
d	��d|id���tj�t#jt|
���
����rg|rHt	|jt
d��|t#jt|
���
��d�d���|j�d
|��dSt'|
��}
i}	tjtj�|
��dd���|st-|��n#t.$rYnwxYw|tjkrt3|��t5|
��5t7��}t9|
��}t;|
t=|��||��}|D]�}|t>vra|tj
krQ|�|��s<|j� d|��tj
|j!|<tj
}n%|tDj#kr||j$|<n
||j!|<|r
||j%|<|rt|��|j&|<��t;|
t=|��||��}	tO|
||��n�#tPt.f$r{}|r:tSt
d��t|��tU|
�������|j�d|
t|����Yd}~ddd��dSd}~wwxYw|�+||||
||��ddd��n#1swxYwYd|fS)a4
        Enable/disable modules for user.
         - write admin config for user with new state
         - install/uninstall WP plugin
         - reload deamon to start/stop redis
        :param user_name: username
        :param suites: Suites list to process
        :param allowed_state: Suite state
        :param purchase_date: Date when user last payed for the product
        :param is_one_user: True - utility processes one user, False - some users
            For messages backward compatibility
        :return: Tuple: (error_flag, warning_flag)
        r
z!User %(username)s does not exist.r�r�zUser %s does not exist.)TNc�$�g|]
}|tv�|��Sr�)r+r�s  r�r�z<CloudlinuxWposAdmin._process_user_suites.<locals>.<listcomp>s#�� g� g� g�5�e�Gf�>f�>f��>f�>f�>fr�zFUser username="%s" is owned by reseller, suites="%s" cannot be allowedzSUser %(username)s is owned by reseller, --visible or --allowed states cannot be set�r(z�Plugins syncing in currently running for user %(username)s, please wait and try again. If issue persists - check file presence %(sync_pid)s and try to remove it)r��sync_pidz0Plugins syncing in currently running for user %si�F)�exist_okz9Silently disallow %s user because it is owned by resellerz,Configuration file '%(path)s' update failed.r)r�r�r�z0Configuration file %s update failed. Error is %sN),r[�pw_uid�pw_gid�KeyErrorrUr�r�r�rrrCr-r�r�r�r�r�rB�formatr-�makedirs�dirnamersr�rArrYr^r.r0rr+r�r�rr��whmcs_suitesr1�purchase_datesr/r�r7r��synchronize_plugins_if_needed)r�r.r�r/r0rGr1r2rR�pw_infor(�gid�requested_unsupported�suites_allowed_pathrar#�config_contents�features_old_stater��features_new_stater�s                     r�r@z(CloudlinuxWposAdmin._process_user_suites�sy��*
	��i�0�0�0�G��~�w�~��C�C���
	�
	�
	��
���M�"#�$G�"H�"H�$.�	�#:������
�L���8�)�D�D�D��:�:�
	����!h� g�F� g� g� g�� �	�]�6G�6P�%P�%P��/�/�	�:�:�&Q�
�L� � �!i�'�!�"7�8�8�
:�
:�
:��
���M�"#�%R�#S�#S�$.�	�#:�������7�>�>�3�:�s�3�x�x�H�H�H�I�I�
	��

���M�"#�%;�#<�#<�1:�0I�0P�UX�Y\�U]�U]�0^�0^�0^�$`�$`�	��	�	�	�
�L���Q�S\�]�]�]��:�5�c�:�:����	+��K�����(;�<�<�e�e�T�T�T�T�
%�
+��	�*�*�*����	�	�	��D�	�����-�5�5�5�+�I�6�6�6�
�-�
.�
.�1	b�1	b�4�6�6�N�5�c�:�:�O�!1����)�)���	"�"�� �
O�
O���;�;�;�%�):�)C�C�C� �7�7�	�B�B�D��L�%�%�&a�cl�m�m�m�4E�4N�O�*�5�1�$5�$>�M�M�#�|�'D�D�D�>K��4�U�;�;�8E��.�u�5��C�8B�O�.�u�5� �O�<?�
�<N�<N�O�2�5�9��!1����)�)���	"�"��
"�$�S�#��?�?�?�?���W�%�	
"�	
"�	
"���#� !�"P� Q� Q� #�C��� $�*=� >� >� >�����
��"�"�#U�#6��C���B�B�B�!�z�z�z�]1	b�1	b�1	b�1	b�1	b�1	b�1	b�1	b�����J	
"����
�.�.�}�l�*3�S�:L�N`�
b�
b�
b�a1	b�1	b�1	b�1	b�1	b�1	b�1	b�1	b�1	b�1	b�1	b����1	b�1	b�1	b�1	b�d�l�"�"s`�!�AA3�2A3�34G9�9
H�H�7DP�
M�P�O+�0A%O&�P�&O+�+P�P�Pc��|tjkr�t�d|��|�tjt|�����t||||��}|�M|j�d|t|��t|����tj
d��dSdSt�d|t|��t|����t||||��dS)a.
        1. does not sync plugins if source == BILLING (WHMCS CALL) and state == allowed
        2. start syncing plugins in background if source == BILLING (WHMCS CALL) and state != allowed
        3. it syncs plugins in regular regime for both allowed/non-allowed states if source != BILLING
        z*Syncing plugins in background for user: %sr5NzTForked syncing plugins for user %s, features old states: %s, features new states: %srz9Start syncing plugins for user: %s, source: %s, state: %s)rr�r�r�r�rBr;r��#synchronize_plugins_status_for_userr�r�)r��stater�r�r(rFrG�sync_results        r�r@z1CloudlinuxWposAdmin.synchronize_plugins_if_neededxs���\�2�2�2��L�L�E�x�P�P�P��0�0�1J�1Q�VY�Z]�V^�V^�1_�1_�1_�1T�19�14�1C�1C�E�E�K��&���!�!�#U�"*�"%�&8�"9�"9�"%�&8�"9�"9�	;�;�;���������'�&�
�L�L�T�!��V����U���
%�
%�
%�
0��#�?Q�Se�f�f�f�f�fr�c���|jjrd}nd}|jjr7t��}|s$t	|jdt
d��i��|}n|jj�d��}tj
�t��r,t	|jt
d��dtid���|�
t|j||��iS)	NTFr�z(There are no users in the control panel.r�z�Updating visibility of Object Cache PRO banners is already in progress.  Process pid is stored in %(progress_marker)s.If process with such pid does not exist - please, remove file "%(progress_marker)s" and re-run commandr�r�)r�r��allrrUr�r�r�r�r�r�r�rAr��%_update_object_cache_banner_for_users)r�r�r�rSs    r��_object_cache_bannerz(CloudlinuxWposAdmin._object_cache_banner�s���:��	1�+/�(�(�+0�(��:�>�
	?��I�I�E��
���M��q�!K�L�L�M����
$)� � �#'�:�#3�#9�#9�#�#>�#>� �
�7�>�>�>�?�?�
	���
��!5�6�6�!2�3W�X���	
�	
�	
�	
���C�T�Eo�3�5Q�	S�	S�	S��	r�r�c���|rd}nd}|D]`}dd|dd|g}tj|ddd�	��}|j�|j��|j�|j���adS)
Nz	--disablez--enabler�r�zobject-cache-bannerz--allTrr)r�r�r�r�rr)r�r�r�r�r�r�r�s       r�rNz9CloudlinuxWposAdmin._update_object_cache_banner_for_users�s���'�	 � �F�F��F�!�	-�	-�H�-�x��CX�Za�ci�j�G��^�G�$�t�UX�Y�Y�Y�F��L���f�m�,�,�,��L���f�m�,�,�,�,�		-�	-r�r�)T)Br�r�r�r�rr�r�rTr�r��staticmethodr�r�r�r�r�r��parserr�r�r��argumentrWr�r�r	rrrirQrOr
rPrNr�r�r�r�r�r�r�r�r�r�r�r�r�r
rrr!rr`r'r-rr�datetime�daterr	rr@r@rOrNr�r�r�rr�s������������������.�.�.��
*�
*��[�
*�"�"�"��=�=��\�=�
�5�5��\�5�
����\��;�3��:�;�$��+�;�;�;�;��^�^�����������&��_�_�Z�8��:�:��_�_�Y�O�(��*�*��_�_�Z�G�(��*�*��^�^�����4��������*�*�*�*�:�:��[��2��_�_�X�:�"��$�$��^�^����
�
�����$�$��[�
���^�^����
�$�
�
�
������[�
�4��^�^�����d���������[���G�G�G��\�G��R�D�R�R�R���R�h
<�<�<�*
�
�
�^��c��^�^�^�^�<z�z�z�*�,�d�,�,�,���,�\E!�E!�E!�N
-�
-�
-���"�"����[�"���T�����[��6�$�����:�.�4�.�.�.��[�.��,�,��[�,�\���0#�#�#�<(@�(@�(@�T���*)�)�)�$��^�^���)�)����[�)�$��^�^�����T�������[��:��^�^��������[����^�^��������[��,��1B��,=��BF�����\��"?�?�?�H#�c�H#�4��9�H#�,=�H#�+7�H#�-5�M�H#�*.�	H#�
+/�H#�15�
H#�:?�t�X�d�^�?S�9T�
H#�H#�H#�H#�Tg�g�g�@ � � �D
-�]a�
-�
-�
-�
-�
-�
-r�rr�r(�	old_state�	new_statec��d�|���D��}d�|���D��}||z
}||z
}t||||��dS)z�
    Compare old and new states of modules in admin's wpos config,
    determine what modules should be enabled and disabled
    and synchronize new state for each panel's user.
    c�B�h|]\}}|jtjk�|��Sr��r�rrA�r��keyr�s   r��	<setcomp>z6synchronize_plugins_status_for_user.<locals>.<setcomp>��,��f�f�f���e�E�L�L]�Le�<e�<e��<e�<e�<er�c�B�h|]\}}|jtjk�|��Sr�rZr[s   r�r]z6synchronize_plugins_status_for_user.<locals>.<setcomp>�r^r�N)r��synchronize_plugins_for_user)r�r(rVrWr��disabled_moduless      r�rIrI�so��g�f�y���'8�'8�f�f�f�I�f�f�y���'8�'8�f�f�f�I��)�+�O� �9�,�� ��3��AQ�R�R�R�R�Rr�c�<�|D]}||dkr
|dcS�dS)Nrrr�)�all_domainsr�domain_infos   r�r�r��s?��"�"�"���k�!�n�$�$��q�>�!�!�!�%�"�"r�c�X�t�dt|����	t|��dS#t$r7}t�d|j|j|j��Yd}~dSd}~wt$r%}t�|��Yd}~dSd}~wwxYw)NzReloading redis for uid=%sz@CL AccelerateWP daemon error: '%s'; details: '%s'; context: '%s')
r�r�r�rIr7r�r�r�r�r�)r(r�s  r��
_reload_redisrf�s����L�L�-�s�3�x�x�8�8�8���S��������������N�PQ�PY�[\�[d�fg�fo�	�	�	�	�	�	�	�	�	������������!�����������������s!�;�
B)�,A7�7
B)�B$�$B)r�rac�B�t|��}t|��5t��5t|���}t	|�����}d�|D��}d�t
|��t
t��zD��}|���ot
|��t
|��z}	|���ot
|��t
|��z}
|	rt|��|D]�\}}}
t|tj�
tj|��j|����}|
|vr;t"�d|
��t't)|��||
|���|
|vr;t"�d|
��t+t)|��||
|�����|
rt|��ddd��n#1swxYwYddd��dS#1swxYwYdS)z�
    Iterate through user's docroots and wp_paths
    and enable/disable modules with wp-cli
    not modifying user's wpos config.
    r
c��g|]
}|d��S)�r�r�s  r�r�z0synchronize_plugins_for_user.<locals>.<listcomp>�s��&Y�&Y�&Y�g�w�q�z�&Y�&Y�&Yr�c�n�g|]2}t|������#t|����3Sr�)r(�redis_daemon_requiredr�)r�r�s  r�r�z0synchronize_plugins_for_user.<locals>.<listcomp>�sF��&
�&
�&
�"��v���4�4�6�6�&
���K�K�&
�&
�&
r�zHRestoring feature="%s" to previously enabled state upon suite activationr�z0Turning off feature="%s" upon suite deactivationN)rr6rwr8r.r�ryr!�is_default_configrfr�r�r�r�r�r�r�r�r�r$r&r%)r�r(r�rar��user_config�previously_enabled_data�previously_enabled_features�modules_that_require_redis�redis_requires_reload_pre�redis_requires_reload_postr�r�r�r�s               r�r`r`�s����x�(�(�L�	��	"�	"�2�2�M�O�O�2�2� �(�3�3�3��"&�{�'B�'B�'D�'D�"E�"E��&Y�&Y�AX�&Y�&Y�&Y�#�&
�&
�&)�*E�&F�&F��Mf�Ig�Ig�&g�&
�&
�&
�"�)4�(E�(E�(G�(G�$G�%[�$'�(B�$C�$C�c�/�FZ�FZ�$Z�	"�*5�)F�)F�)H�)H�%H�&`�(+�,F�(G�(G�#�N^�J_�J_�(_�	#�
%�	��#����+B�	�	�'�X�w��$�\�%'�W�\�\�#�,�x�2H�2H�2O�QY�%Z�%Z�\�\�F���(�(����g�#�%�%�%�/���)�)��!�!�	�����)�)�)����O�#�%�%�%�0���)�)��!�!�	�����&�	��#����e2�2�2�2�2�2�2�2�2�2�2����2�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2����2�2�2�2�2�2s5�H�GG<�0H�<H	�H�H	�H�H�Hr�c�F�t|������S)Nr
)r8r�r
s r�r�r�&s���x�(�(�(�8�8�:�:�:r�c�x�t��5}t|ddd��ddd��dS#1swxYwYdS)NF)rZr�)rhs r��"disable_smart_advice_functionalityru*s���	�	�	�J�7�+�G�U�E�5�I�I�I�J�J�J�J�J�J�J�J�J�J�J�J����J�J�J�J�J�Js�/�3�3rhr}r~rc��t|t��r||_t|t��r||_t|t��r
||_dSdSr�)�
isinstancer��"disable_smart_advice_notifications�disable_smart_advice_reminders�%disable_smart_advice_wordpress_plugin)rhr}r~rs    r�r�r�/ss���&��-�-�N�9M�5M��2��"�D�)�)�F�5E�1E��.��)�4�0�0�T�<S�8S��5�5�5�T�Tr�)NNN)��
__future__r�argparserTrKr�r
r�r�r�r�rr�r�dataclassesr�typingrrrr	r
r�enumr�clwpos.papir
�psutilr�clcommon.cpapirrrrr�clwpos.billingr�clwpos.migrationsr�clwpos.cronrr�$clwpos.feature_suites.configurationsrrrrrrrr �clwpos.optimization_featuresr!r"r#r$r%r&r'r(�clwpos.feature_suitesr)r*r+r,r-r.r/r0r1r2r3r4r5�clcommon.clpwdr6�clwpos.cl_wpos_exceptionsr7�clwpos.user.configr8�clwpos.constantsr9r:r;r<r=r>r?r@rArBrCrDrErFrGrH�clwpos.object_cache.redis_utilsrI�clwposrJr�rK�clwpos.parserLrM�clwpos.logsetuprNrOrP�clcommon.cpapi.cpapiexceptionsrQ�clwpos.report_generatorrRrS�clwpos.utilsrTrUrVrWrXrYrZr[r\r]r^r_r`rarbrcrdrerfrgrhri�clwpos.whmcs_utilsrjrkrlrm�clwpos.wpos_hooksrnrorprq�clcommon.clcagefsrrrs�clwpos.statsru�clwpos.data_collector_utilsrv�secureiorw�clcommon.clwpos_librxryrzr=rJrRr�r�r-�objectrr�r�rIr�rfr`r�rur�r�r�r�r��<module>r�sB��'�&�&�&�&�&���������������������	�	�	�	�
�
�
�
�����
�
�
�
�����������������=�=�=�=�=�=�=�=�=�=�=�=�=�=�=�=�������M�M�M�M�M�M�������L�L�L�L�L�L�L�L�L�L�L�L�L�L�:�:�:�:�:�:�-�-�-�-�-�-�>�>�>�>�>�>�>�>�u�u�u�u�u�u�u�u�u�u�u�u�u�u�u�u�u�u�u�u�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�������������������������������+�*�*�*�*�*�/�/�/�/�/�/�)�)�)�)�)�)�������������������������������������$9�8�8�8�8�8�(�(�(�(�(�(�(�(�8�8�8�8�8�8�8�8�V�V�V�V�V�V�V�V�V�V�4�4�4�4�4�4�I�I�I�I�I�I�I�I�������������������������������������������������0������������������������F�E�E�E�E�E�E�E�5�5�5�5�5�5�/�/�/�/�/�/�"�"�"�"�"�"����������� �a�!P�Q�Q��"#�!�%S�#T�#T��
���9�#��	
�
�
���-��
!�
!����h-�h-�h-�h-�h-�&�h-�h-�h-�V)S�#�S�C�S�37��]�8J�3K�S�37��]�8J�3K�S�S�S�S�""�"�"�

�
�
�:�3�:�S�:�3�s�8�:�gj�kn�go�:�:�:�:�z;�s�;�x��c�3��m�0D�'E�;�;�;�;�J�J�J�)-�$(�+/�	T�T�
�T���+�T��T�k�T�"�D�[�	T�

�T�T�T�T�T�Tr�