????

Your IP : 3.147.70.194


Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/__pycache__/wpos_admin.cpython-311.pyc

�

tfP���b�ddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZmZmZmZmZmZddlmZddlmZddlmZmZmZmZm Z dd	l!m"Z"dd
l#m$Z$ddl%m&Z&m'Z'ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0dd
l1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9ddl:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEddlFmGZGddlHmIZIddlJmKZKddlLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\ddl]m^Z^ddl_m`ZambZbddlcmdZdmeZeddlfmgZgmhZhmiZiddljmkZkddllmmZmmnZnddlompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZm�Z�m�Z�m�Z�m�Z�ddl�m�Z�m�Z�m�Z�m�Z�ddl�m�Z�m�Z�m�Z�ddl�m�Z�m�Z�ddl�m�Z�ddl�m�Z�ddl�m�Z�dd l�m�Z�m�Z�m�Z�ead!��Z�ead"��Z�edd#d$eed%�&��Z�ege���Z�Gd'�d(e���Z�d)e�d*e�d+ee�e)fd,ee�e)ffd-�Z�d.�Z�d)e�d*e�d/ee�d0ee�fd1�Z�d)e�d2eee�e�e�ffd3�Z�d4�Z�			d:d5e|d6e�dzd7e�dzd8e�dzd2df
d9�Z�dS);�)�absolute_importN)�deepcopy)�asdict)�Dict�Iterator�Set�Tuple�List�Optional)�Enum)�
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�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_backup_folders�backup_accelerate_wp�+restore_accelerate_wp_public_options_backup�%make_accelerate_wp_backups_deprecated)�install_panel_hooks�"install_yum_universal_hook_alt_php�_uninstall_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_abbrevc��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���edefd�����������Zee�ddd���e���ed���������Zee���edefd�������Zee���edefd�������Ze
dFd���Zedefd���Zd �Zd!eefd"�Zd#�Z edefd$���Z!d%�Z"d&�Z#eed'�����Z$edefd(���Z%defd)�Z&edefd*���Z'ed+���Z(d,�Z)d-�Z*d.�Z+d/�Z,d0�Z-ee���d1�����Z.ee���dGdefd2�����Z/ee���d3�����Z0ee���d4�����Z1e
d5e2d6e3defd7���Z4d8�Z5d9ed:eed;e6d<e7d=e8j9d>e:d?ed@ede;ee<effdA�Z=dB�Z>dC�Z?dDefdE�Z@dS)H�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�EnablingStatusrz�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_jsonrKr~�_loggerrL�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���|�|��|_d|_t||jj�dd������}t
|j|��dS)zs
        Run command action
        :param argv: sys.argv[1:]
        :return: clwpos-user utility retcode
        T�-�_N)�_parse_args�_optsr��getattr�command�replacerS)r��argv�results   r�r�zCloudlinuxWposAdmin.run�sd���&�&�t�,�,��
���
�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)r9r�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�)r9r�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�
IndexErrorrNr��warning�strrr3�_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��actionc
��	t��nq#t$rd}|j�d��t	|jt
d��tt|�����d���Yd}~nd}~wwxYw|j	j
rCtj�
ttj��st#d��|j	jrad�|j	j�d��D��}t(j|vrt+��t,j|vrt/��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��contextNTc�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��,)rf�	Exceptionr��	exceptionrRr�r��dictr�r��setupr�r��existsr9r2�namerr�suites�splitr/rsr0rt)r�r�r�s   r��	set_whmcszCloudlinuxWposAdmin.set_whmcs�sX��	L� �"�"�"�"���	L�	L�	L��L�"�"�#G�H�H�H��4�=�Q�7g�5h�5h�6:�#�a�&�&�6I�6I�6I�+K�+K�
L�
L�
L�
L�
L�
L�
L�
L�����	L����
�:��	*�B�G�N�N�>�(�-�3P�$Q�$Q�	*�#�D�)�)�)��:��	.�N�N���1B�1H�1H��1M�1M�N�N�N�F�� �F�*�*�/�1�1�1���6�)�)�+�-�-�-��	s��
A?�AA:�:A?z--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��JSONDecodeErrorrRr�r�rD�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}~wwxYw|tj
|jtj
|j
id�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>#s��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�)�backup_folders�upgrade_url)r[re�FileNotFoundErrorr�r�r�rRr�r�r/r�r�r0�upgrade_url_cdn)r��server_wide_optionsr�r�s    r��get_whmcs_configz$CloudlinuxWposAdmin.get_whmcs_configs)��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
        )rgrhr�s r��restore_whmcs_backupz(CloudlinuxWposAdmin.restore_whmcs_backup4s!��	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_allowed?s1���	9���!8�8�8�(��d�1�g�F�F�F�Fr�c��t��}d�|jj�d��D��}d}g}|jjr)d�|jj�d��D��}|D�]2}|t
vr3t
|jtd��t|���d���|jj
s$|jjs|jjs|jj
rI|t��vr9t
|jtd��t|t�	��d���i}t
|j}|D]�}|jjrS|j|jjvr@|j�9t
|jtd��t|j���d����a|jjs|j�|j||j<��|j|jjvr2|�|jj|j��||j<��|jj
r�|jjr�t-t.|jj��t.jkrU|�t4j||�
��s3t
|jtd��t|���d�����4|jjr7t7|��dkr$t
|jdtd��i��|jjr7t7|��dkr$t
|jdtd��i��|jjr0|jj
r$t
|jdtd��i��d�|D��}	|jj
r^|j�d��t<j� tB��s tE���#��|jj
r*tI��}dx}
}|�%|��d}n�|jj&r*tI��}dx}
}d}|�'|��n�|jjr*tI��}d}
d}|�'|��d}nb|jjr-t��}|d|j(v}|d|j)v}
n)|jjr|jj}d}
n|jj
x}
}|otU��}|
otV|	votYtV��}
|otZ|	votYtZ��}i}|
rMt]d��\}}}|r8|j�/d||��|�0dtbi��d}|ot7|��dk}|jjr t-t.|jj��}nd
}|jj2rtg��}|D�]W}	|�4|||
rtjj6n|rtjj7ntjj8|pRts|jj
|jj&|jj|jjf��rt.j:nt.j;|jj<|||��\}}np#tz$rc}|r*|j�/d|t}|�����|j�?d|t}|����d}i}Yd
}~nd
}~wwxYw|rd}��|jj
r.|�@d|gt�jBt�jB�����Y|rKt���r=t�d���t���5}d|_Fd
d
d
��n#1swxYwYt�|��r3|�@t�dgt�jBt�jB���|jj
r;|�@dgt�jBt�jB���t���|r,t�t�d d|jL�!��t���|r�|�0dt�i��|�@t�gt�jBt�jB���|�@t�gt�jBt�jB���t���n5|
r3tZ|	vr*t���r|�0dt�i��|s|r9t�t�jUt�tZtVg|||
g��d�"��|jj&rt���|s�tU��s�t���t���t�d���t���5}d|_Fd
d
d
��n#1swxYwYt���r3|�@t�d#gt�jBt�jB���|jj
s|jjrWt<j� t���r3|j�d$��t=j[t���|r,t
|jtd%��d&t�id���|�]|��|jj
s|jj
r<|�^d��|�_|��t�d'dd(���|jj
ro|jjrct-t.|jj��t.jkr6|�ad�b|��d)d*|jj�+��|S),zG
        Write info related to module allowance into user file
        c�6�g|]}|�����Sr�r�r�s  r�r�z2CloudlinuxWposAdmin._set_suite.<locals>.<listcomp>Os ��O�O�O��u�{�{�}�}�O�O�Or�r�Fc�6�g|]}|�����Sr�r�)r�rs  r�r�z2CloudlinuxWposAdmin._set_suite.<locals>.<listcomp>Us ��#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 reportTrz)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�zdisable-user-agentz7set-suite for all was called, removing migration markerz8User(s) process error. Please check log file %(logfile)s�logfile�suite_allowed_callback)r��uid�feature_allowed�whmcs)r��event�source�feature)cr[r�r�r�r�r(rRr�r�r��allowed�visible�visible_for_all�allowed_for_allrarE�allowed_attrubites�attrsr��default�typerr�r�BILLING_OVERRIDErr2�lenr��infor�r�r�r;rO�scanrr��disallowed_for_allr�r�allowed_suitesrr"rr!rZr��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�r��DEVNULLr\rUrW�	show_iconrcrCrmrlr7r�ri�REDIS_CONFIGURATION_WARNING_MSGr6r8rjrYr�	itertools�compressr&rkrrdr:�removerM�$_save_suites_list_to_public_settings�cln_sync�_force_user_syncr^�_send_analytics_reportr�)r�rr��for_all_operation�user_list_to_processr��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_suiteIs6
��
+�,�,��O�O�$�*�2C�2I�2I�#�2N�2N�O�O�O��!��!���:��	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�"V�9T�9V�9V�5V��!/�"<�K�<�4O�"<�.�{�;�;�;�	�'5�(E�:N�R^�:^�(E�.�/C�D�D�D�	%����	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���'+�	
,�
,�
,�
,��:�(�	������
	:�&A�&C�&C�
	:������ � � �$�$�/�/�/�/�%�'�'�
*�7�$)��!�
*�
*�
*�
*�
*�
*�
*�
*�
*�
*�
*����
*�
*�
*�
*�/�0�0�
:���� 4�6J�K�&0�&8�&0�&8��:�:�:�
�J�&�	/�$�*�*D�	/�"�'�.�.�Yp�Jq�Jq�	/��L���W�X�X�X��I�-�.�.�.��	���
�� Z�[�[� )�+=�>���
�
�
�	
�1�1�+�>�>�>��:�%�	���);�	�
�M�M�%� � � ��!�!�"6�7�7�7�
�3�� � �
�
�
�
�:��	C�$�*�"3�	C��L�$�*�*;�<�<��@]�]�]��'�'����:N�1O�1O�.?�/6�04�
�0A�
(�
C�
C�
C�
�s>�+B"Z�
[;�A[6�6[;�.^�^�	^�+f?�?g�gc��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�rAr�r�r��check_output�PIPE�CalledProcessErrorr�rr)r�r�rrrr�s      r�rBz*CloudlinuxWposAdmin._send_analytics_reportgs���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�C�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�TrYzKUnable to force synchronization of data for user %s. stderr: %s; stdout: %s)r�r�r�rAr�r��appendrr�r�r�r[r�r\r]r�rr)r�r^�account_idsr�r�s     r�rAz$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��t��5}d�|D��D�]C}|jjr_tt	|j��|jhz��|_tt	|j��|jhz��|_�n|jjr_tt	|j��|jhz
��|_tt	|j��|jhz��|_��|jj	r^tt	|j��|jhz
��|_tt	|j��|jhz
��|_��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)
rWr�r"�list�setr,r�rr!r+)r�r�rUr�s    r�r?z8CloudlinuxWposAdmin._save_suites_list_to_public_settings�s���
"�
#�
#�
	^�w�E�E��E�E�E�	
^�	
^���:�-�^�-1�#�g�6L�2M�2M�QV�Q[�P\�2\�-]�-]�G�*�-1�#�g�6L�2M�2M�QV�Q[�P\�2\�-]�-]�G�*�*��Z�/�^�-1�#�g�6L�2M�2M�QV�Q[�P\�2\�-]�-]�G�*�-1�#�g�6L�2M�2M�QV�Q[�P\�2\�-]�-]�G�*�*��Z�2�^�-1�#�g�6L�2M�2M�QV�Q[�P\�2\�-]�-]�G�*�-1�#�g�6L�2M�2M�QV�Q[�P\�2\�-]�-]�G�*��	
^�
	^�
	^�
	^�
	^�
	^�
	^�
	^�
	^�
	^�
	^�
	^�
	^����
	^�
	^�
	^�
	^�
	^�
	^s�EE/�/E3�6E3c	�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)sr�r�NTF)�enable_notifications�enable_reminders�enable_wordpress_plugin)r��icon_visibler�rUrRr�r�rWr:�object_cache_banner_visible�disable_object_cache_banners�#_switch_smart_adive_related_optionsr��smart_advice_notifications�smart_advice_reminders�smart_advice_wordpress_pluginr�r�r/r�r0r��feature_visible�features�set_feature)r��
is_visiblerOrrUs     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�rs  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>�sE��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'ryr{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)srz�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 rRr�r�rer[�hidden_featuresrd�unionr/r
r2r1�issubset�
differencerWr�_disable_featurer�r�r�)r�rrrt�possible_to_hider�target_features�already_hidden�features_to_hide�all_premium_features�all_free_featuresrUrs            r�rszCloudlinuxWposAdmin.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�disablerX�	--wp-path�--domainT)rZ�capture_output)rr3r5�enabled_modulesr�r�r�r�r�r�r�r�r�r�r)rr)r�rrrr��enabled_featuresr�r�r�r�r�r�s           r�r�z$CloudlinuxWposAdmin._disable_feature!sf��"�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�)rr�s  r�r�z4CloudlinuxWposAdmin._get_options.<locals>.<listcomp>7s'��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�r4r�r�)r�rrUr�errs     r��_get_optionsz CloudlinuxWposAdmin._get_options0s���	"��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�rOr�rPrRr�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�)
rOr��status�
get_statusr*rPrRr�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 statisticsrnr�s r��	_get_statzCloudlinuxWposAdmin._get_statys��,�-�-�-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�rdrr��_feature_enable_statusr�r�r�r=rRr�r�r<r>�run_in_background�_enable_feature_for_usersr�r��valuer(r�r��dump�sys�exit)r�rr��
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�rM)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�r>)
r��pidfile�func�args�kwargs�dummy_result�fp�si�so�se�	child_pidr��func_results
             r�r�z%CloudlinuxWposAdmin.run_in_background�s���
��
�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�)r()r��websitess  r��	<genexpr>z@CloudlinuxWposAdmin._enable_feature_for_users.<locals>.<genexpr>�s(����+^�+^�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��	usernamesrr�r�r��
target_wpsr�r��wp_siter��enabled_statuss            r�r�z-CloudlinuxWposAdmin._enable_feature_for_users�s���<@�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�rZ�timeout�docroots�domainsrc���g|]?}|d�d�|d��d���7|d��@S)rrr��issuesr�)r�)r��wprs  �r�r�z<CloudlinuxWposAdmin._get_target_websites.<locals>.<listcomp>sf���&�&�&���j�>�'�2�9�=�&�GI��n�U\�F]�Fa�Fa�bj�Fk�Fk�&��v�J�&�&�&r��wps)rpr�r�r�r�r)r�r�rr�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��enablerXr�r�z--ignore-errorsz--skip-dns-checkT��rZr�r�)	r`r�r�r�r)rrr�r�)	r�r�rr�r�r�r�r�r�s	         r�r�z$CloudlinuxWposAdmin._enable_for_site"s���*�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�)
rarer(�keys�loggingr)r�r�r��sortedr�rr)r�r��suites_to_turn_offr�s    r��
billing_checkz!CloudlinuxWposAdmin.billing_check4s���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���tj��}t�d�}t��\}}}|s|j�d|��n�t
j|tj	|t���d|�d����dd����}|jd	krQ|j�
d
t|j��|jddtj	|t���i�
��|S)zAccelerateWP cln integrationz/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: %sTr�)�exc_info�extra)rH�
get_reportr@rbr�r��requests�postr��dumpsr_�decode�status_coder�r�rZ)r�r�r��cln_report_urlr�r��jwt_strr�s        r�r@zCloudlinuxWposAdmin.cln_syncHs���#�%�%��#�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�*0�$�*�V�I\�2]�2]�2]�)^�#�`�`�`�
�
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)rr<r=r&r"r!rr.r�s r��sync_cron_filesz#CloudlinuxWposAdmin.sync_cron_filesfsl��	���-��(��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�rr3r2r6rer(r
�allowed_features)r
rr�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|d���dd}t��dko|dk}tt|��|g��S)N)�reseller)�cpuser�keylsr�DirectAdmin�admin)rrr5r)r�r��
user_owner�should_be_whitelisteds    r��_is_supported_for_userz*CloudlinuxWposAdmin._is_supported_for_user�sS���8�=�A�A�A�!�D�Q�G�
� )���}� <� T��W�AT���H�Z�(�(�*?�@�A�A�Ar��	user_namer��
allowed_state�state_sourcer8�
attributes�is_one_userrCc	
�b��	t|���}	|	j|	j}}
nU#t$rH|r't	|jt
d��d|id���|j�d|��YdSwxYwtj
tj
tj
g��fd�|D��}|rw|tjkrg|�|��sR|j�d|t#|����|r't	|jt
d	��d|id���t$j�t+jt#|
���
����rg|rHt	|jt
d��|t+jt#|
���
��d�d���|j�d
|��dSt/|
��}
i}	t%jt$j�|
��dd���|st5|��n#t6$rYnwxYw|tjkrt;|��t=|
��5t?��}tA|
��}tCtE|��||��}|D]�}|�vra|tjkrQ|�|��s<|j�#d|��tj|j$|<tj}n
||j$|<||j%|<|r
||j&|<|rt#|��|j'|<��tCtE|��||��}	tQ|
||��n�#tRt6f$r{}|r:tUt
d��t#|��tW|
�������|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)
        rz!User %(username)s does not exist.r�r�zUser %s does not exist.)TNc���g|]}|�v�|��	Sr�r�)r�r��unsupported_suites_for_resellers  �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�rz�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)-rX�pw_uid�pw_gid�KeyErrorrRr�r�r�r�r/r�r0r1rr4rr�r�r�r�r�r?�formatr*�makedirs�dirnamermr�r2rrVr[r+r-rr)r��sourcesr�purchase_datesr,r�r4r��synchronize_plugins_if_needed)r�rr�rrr8rrrC�pw_infor�gid�requested_unsupported�suites_allowed_pathrNr�config_contents�features_old_stater��features_new_stater�r s                     @r�r1z(CloudlinuxWposAdmin._process_user_suites�s���*
	��i�0�0�0�G��~�w�~��C�C���
	�
	�
	��
���M�"#�$G�"H�"H�$.�	�#:������
�L���8�)�D�D�D��:�:�
	����,8�+<�k�>N�PX�P]�*^�'� g� g� g� 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�
�-�
.�
.�,	b�,	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�4A�O�*�5�1�1=��'��.��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�S,	b�,	b�,	b�,	b�,	b�,	b�,	b�,	b�����@	
"����
�.�.�}�l�*3�S�:L�N`�
b�
b�
b�W,	b�,	b�,	b�,	b�,	b�,	b�,	b�,	b�,	b�,	b�,	b����,	b�,	b�,	b�,	b�Z�l�"�"s`�"�AA4�3A4�4H�
H,�+H,�C=P"�M-�,P"�-O9�>A%O4�#P"�4O9�9P"�"P&�)P&c��|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: %sr!NzTForked 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�r?r'r��#synchronize_plugins_status_for_userr�r�)r��staterr�rr2r3�sync_results        r�r,z1CloudlinuxWposAdmin.synchronize_plugins_if_neededs���\�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��allrrRr�r�r�r�r�r�r�r>r��%_update_object_cache_banner_for_users)r�rlr�rDs    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�rlc���|rd}nd}|D]`}dd|dd|g}tj|ddd�	��}|j�|j��|j�|j���adS)
Nz	--disablez--enabler�r�zobject-cache-bannerz--allTr�r�)r�r�r�r)rr)r�r�rlr�r�r�r�s       r�r:z9CloudlinuxWposAdmin._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)Ar~rr�r�rr�r�rQr�r��staticmethodr�r�r�r�r�r��parserr�r�r��argumentrTr�r�r�r�rrVrBr
rAr?rursr�r�r�r�r�r�r�r�r�r�r�r�r@rr	rr]rrrr�datetime�daterr	rr1r,r;r:r�r�r�rxrx�ss�����������������.�.�.��	*�	*��[�	*�"�"�"��=�=��\�=�
�5�5��\�5�
����\��;�3��:�;�$��+�;�;�;�;��^�^�����������&��_�_�Z�8��:�:��_�_�Y�O�(��*�*��^�^�����4��������*�*�:�:��[��0��_�_�X�:�"��$�$��^�^����
�
�����$�$��[�
���^�^����
�$�
�
�
������[�
�2��^�^�����d���������[���G�G�G��\�G��[�D�[�[�[���[�z<�<�<�*^��c��^�^�^�^�<^�^�^�"�,�d�,�,�,���,�\E!�E!�E!�N
-�
-�
-���"�"����[�"���T�����[��6�$�����:�.�4�.�.�.��[�.��,�,��[�,�\���0#�#�#�<(@�(@�(@�T���*)�)�)�$��^�^���)�)����[�)�$��^�^�����T�������[��,��^�^��������[����^�^��������[��,��1B��,=��BF�����\��"B�B�B�D#�c�D#�4��9�D#�,=�D#�+7�D#�-5�M�D#�*.�	D#�
+/�D#�15�
D#�:?�t�X�d�^�?S�9T�
D#�D#�D#�D#�Lg�g�g�@ � � �D
-�]a�
-�
-�
-�
-�
-�
-r�rxr�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�rr2�r��keyr�s   r��	<setcomp>z6synchronize_plugins_status_for_user.<locals>.<setcomp>s�,��f�f�f���e�E�L�L]�Le�<e�<e��<e�<e�<er�c�B�h|]\}}|jtjk�|��Sr�rFrGs   r�rIz6synchronize_plugins_status_for_user.<locals>.<setcomp>trJr�N)r��synchronize_plugins_for_user)r�rrBrCr��disabled_moduless      r�r5r5kso��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�r�rMc��t|��}t|��5t��5t|���}|���D]�\}}}t|tj�tj
|��j|����}	||vr tt|��|||	���||vr tt|��|||	�����	ddd��n#1swxYwYddd��n#1swxYwYd�tD��}
|���s�t#|
��||zzr�	t%|��dS#t&$r7}t(�d|j|j|j��Yd}~dSd}~wt2$r%}t(�|��Yd}~dSd}~wwxYwdSdS)z�
    Iterate through user's docroots and wp_paths
    and enable/disable modules with wp-cli
    not modifying user's wpos config.
    rr�Nc�T�g|]%}|����t|����&Sr�)�redis_daemon_requiredr�)r�r�s  r�r�z0synchronize_plugins_for_user.<locals>.<listcomp>�s@��"�"�"���'�'�)�)�"��F���"�"�"r�z@CL AccelerateWP daemon error: '%s'; details: '%s'; context: '%s')rr3rqr5r�r�r�r�r�r�r�r�r#r%r$r �is_default_configrerFr4r�r�r�r�r�r�)r�rr�rMr��user_configr�r�r�r��modules_that_require_redisr�s            r�rLrL�s����x�(�(�L�
��	"�	"���M�O�O��� �(�3�3�3��)4�)D�)D�)F�)F�	�	�%�H�g�v�$�\�%'�W�\�\�#�,�x�2H�2H�2O�QY�%Z�%Z�\�\�F���(�(�/���)�)��!�!�	�����)�)�)�0���)�)��!�!�	�����	�������������������������������������,"�"�";�"�"�"��
�(�(�*�*�!��.�/�/�?�EU�3U�V�!�	!����������	C�	C�	C����`�bc�bk�mn�mv�xy�yB�
C�
C�
C�
C�
C�
C�
C�
C�
C������	!�	!�	!����a� � � � � � � � � �����	!����!�!�!�!sY�D�B9C4�(D�4C8	�8D�;C8	�<D�D�D�E"�"
G�,,F�
G�+G�Gr�c�F�t|������S)Nr)r5r�rs r�r�r��s���x�(�(�(�8�8�:�:�:r�c�x�t��5}t|ddd��ddd��dS#1swxYwYdS)NF)rWrm)rUs r��"disable_smart_advice_functionalityrY�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�3rUrgrhric��t|t��r||_t|t��r||_t|t��r
||_dSdSr�)�
isinstancer��"disable_smart_advice_notifications�disable_smart_advice_reminders�%disable_smart_advice_wordpress_plugin)rUrgrhris    r�rmrm�ss���&��-�-�N�9M�5M��2��"�D�)�)�F�5E�1E��.��)�4�0�0�T�<S�8S��5�5�5�T�Tr�)NNN)��
__future__r�argparser@r<r�r�r�r�r�r�rr�r�dataclassesr�typingrrrr	r
r�enumr�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.r/r0r1r2�clcommon.clpwdr3�clwpos.cl_wpos_exceptionsr4�clwpos.user.configr5�clwpos.constantsr6r7r8r9r:r;r<r=r>r?r@rArBrCrDrE�clwpos.object_cache.redis_utilsrF�clwposrGr�rH�clwpos.parserIrJ�clwpos.logsetuprKrLrM�clcommon.cpapi.cpapiexceptionsrN�clwpos.report_generatorrOrP�clwpos.utilsrQrRrSrTrUrVrWrXrYrZr[r\r]r^r_r`rarbrcrd�clwpos.whmcs_utilsrerfrgrh�clwpos.wpos_hooksrirjrk�clcommon.clcagefsrlrm�clwpos.statsro�clwpos.data_collector_utilsrp�secureiorq�clcommon.clwpos_librrrsrtr.r;r>r~r��objectrxr�r�r5r�rLr�rYr�rmr�r�r��<module>rs���'�&�&�&�&�&���������������������	�	�	�	�
�
�
�
�����
�
�
�
�����������������=�=�=�=�=�=�=�=�=�=�=�=�=�=�=�=�������������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���������������������������������������������,����������������������
F�E�E�E�E�E�E�E�5�5�5�5�5�5�/�/�/�/�/�/�"�"�"�"�"�"����������� �a�!P�Q�Q��"#�!�%S�#T�#T��
���9�#��	
�
�
���-��
!�
!��U-�U-�U-�U-�U-�&�U-�U-�U-�p&S�#�S�C�S�37��]�8J�3K�S�37��]�8J�3K�S�S�S�S�""�"�"�-!�3�-!�S�-!�3�s�8�-!�gj�kn�go�-!�-!�-!�-!�`;�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�