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

�m_e�)���ddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
mZmZmZmZmZddlmZdd	lmZdd
lmZe	d��Zded
eedefd�Zded
eedefd�Zded
eedefd�Zdedeedefd�Z				d$deededeefd�Zd�Z defd�Z!d�Z"d�Z#de$d e%d!ed"efd#�Z&dS)%�N)�List)�cpapi)�drop_privileges)�
setup_logging)�ALL_OPTIMIZATION_FEATURES)�get_allowed_modules�get_visible_modules�get_allowed_suites�PremiumSuite�
ALL_SUITES�AWPSuite)�get_server_wide_options)�
UserConfig)�CDNSuitePro�clwpos_statistics�user�checked_modules�returnc�&�d}	t|��5t|��}|�|��}ddd��n#1swxYwYnA#t$r4}t�dt
|����|cYd}~Sd}~wwxYw|S)zW
    Calculates total count of sites with at least one enabled
    module per user
    rNz3Error while getting info from clwpos user config %s)rr�"get_enabled_sites_count_by_modules�	Exception�_logger�warning�str)rr�count�uc�es     �C/opt/cloudlinux/venv/lib64/python3.11/site-packages/clwpos/stats.py�,get_sites_count_with_enabled_wpos_statisticsrs���

�E��
�T�
"�
"�	K�	K��D�!�!�B��9�9�/�J�J�E�	K�	K�	K�	K�	K�	K�	K�	K�	K�	K�	K����	K�	K�	K�	K����������M�s�ST�v�v�V�V�V�����������������Ls?�A�%A�A�A�A�A�A�
B�)B	�B�	Bc����	tj|��j}n,#t$rt�d|��YdSwxYwt
|���t�fd�|D����S)z:
    Checks if there are any allowed modules for user
    �Unable to get uid for %sFc3� �K�|]}|�vV��	dS�N�)�.0�checked_module�allowed_moduless  �r�	<genexpr>z-is_module_allowed_for_user.<locals>.<genexpr>6�(�����W�W�^�~��0�W�W�W�W�W�W�)�pwd�getpwnam�pw_uid�KeyErrorr�debugr�any)rr�uidr's   @r�is_module_allowed_for_userr2,������l�4� � �'���������
�
�0�$�7�7�7��u�u�����*�#�.�.�O��W�W�W�W��W�W�W�W�W�W���%A�Ac����	tj|��j}n,#t$rt�d|��YdSwxYwt
|���t�fd�|D����S)z:
    Checks if there are any visible modules for user
    r!Fc3� �K�|]}|�vV��	dSr#r$)r%r&�visible_moduless  �rr(z-is_module_visible_for_user.<locals>.<genexpr>Cr)r*)r+r,r-r.rr/r	r0)rrr1r7s   @r�is_module_visible_for_userr89r3r4�suitesc����	tj|��j}n,#t$rt�d|��YdSwxYwt
|���t�fd�|D����S)Nr!Fc3� �K�|]}|�vV��	dSr#r$)r%�
checked_suite�allowed_suitess  �rr(z,is_suite_allowed_for_user.<locals>.<genexpr>Ms(�����K�K�=�}��.�K�K�K�K�K�Kr*)r+r,r-r.rr/r
r0)rr9r1r=s   @r�is_suite_allowed_for_userr>Fs������l�4� � �'���������
�
�0�$�7�7�7��u�u�����(��,�,�N��K�K�K�K�F�K�K�K�K�K�Kr4�allowedF�modules�kind�allowed_by_suitesc�B�d}tj��}|D]�}|rt||��s�|�t||��s�(|dkr|dz
}�4|dkrt	||��r|dz
}�P|r!|tt
||����z
}�s|t
||��z
}��|S)z�
    Returns total count of users with allowed wpos module
    or total count of sites with enabled wpos module
    for all panel users on server
    rNr?��visible)r�cpusersr2r>r8�boolr)r@rA�allowed_by_modulesrB�per_user�total_count�panel_usersrs        r� _get_wpos_statistics_total_countrLPs����K��-�/�/�K��[�[���	�&@��w�&O�&O�	���(�1J�4�Qb�1c�1c�(���9����1��K�K�
�Y�
�
�)�$��8�8�
!��q� ����
[��t�$P�QU�W^�$_�$_�`�`�`����K�D�RY�Z�Z�Z����r*c��tj��}d}d}|D]]}t|tj��s�t|tj��r!t|tj��r�R|dz
}�X|dz
}�^||fS)z

    rrD)rrFrr
�feature_setr8r)rK�visible_premium�disallowed_premiumrs    r�*_get_premium_potential_upgrades_statisticsrQss����-�/�/�K��O����$�$��;�D�(�BV�W�W�	��%�d�L�,D�E�E�	$�;�D�,�BZ�[�[�
���q� �O�O��!�#����.�.�.r*�suitec���d}tj��}|D]F}t||g��s�t|t	t
|j����r|dz
}�G|S)z?
    Returns total count of users with active wpos module.
    rrD)rrFr>r�listr�primary_features)rRrJrKrs    r�!_get_wpos_statistics_active_countrV�st���K��-�/�/�K�����(���w�7�7�	��7��d�:�e�,�=�>�>�@�@�	��1��K���r*c��	t��}n@#t$r3}t�dt	|����Yd}~dSd}~wwxYw|jS)z0
    Obtains admin`s options, e.g show_icon
    z$Error when getting admin options: %sNi���)rrr�errorr�	show_icon)�optionsrs  r�is_accelerate_wp_icon_enabledr[�sf���)�+�+���������
�
�<�c�!�f�f�E�E�E��s�s�s�s�s�����������s��
A�(A	�	Ac��tj�d��}t��}dddd�}t	��}t��\}}idt
���dt
���dt
���d	t
���d
t
���dt
���d|�d
|�d|�d|�dtt|j	�����dtt|j
�����dtj|j
tj|ji�d|�|j���d|�|j���d|�|j���}t)t*dd���|dd<t)t*dd���|d
d<t)t*d��|d	d<t*D]|}|dkrd}n|}t)|gdd���|d|<t)|gdd���|d
|<t)|gd��|d	|<t)|gddd���|d|<�}t)dgdtjg���|dd<t)dgdtjgd� ��|d
d<t)dgdtjg���|d	d<t)dgdtjgdd�!��|dd<t,D]A}	|	d"krd#}n|	}t)gd|	g���|d|<t/|	��|d|<�Bt1|gd$�dd��|S)%zj
    Returns current statistics with enabled sites/allowed users counters
    per module and in total
    z/var/lve/enable-wpos.flag�disabled�enabled�none)TFN�
allowed_usersr=�enabled_suites�
visible_users�
enabled_sites�
enabled_users�is_accelerate_wp_flag_enabledr[�1accelerate_wp_suite_enabled_premium_suite_visible�4accelerate_wp_suite_enabled_premium_suite_disallowed�features_visible_by_default�features_allowed_by_default�upgrade_urls�%is_smart_advice_notifications_enabled�!is_smart_advice_reminders_enabled�is_object_cache_banners_enabledr?T)rH�totalrE�cdn�cdn_free)rHrI)rB�cdn_pro)rBrH)rBrHrI�accelerate_wp_cdn�accelerate_wp_cdn_free)rarcrd)�os�path�isfiler[rrQ�dict�sortedrT�visible_features�allowed_featuresr�name�upgrade_urlr�upgrade_url_cdn�get�"disable_smart_advice_notifications�disable_smart_advice_reminders�disable_object_cache_bannersrLrrrV�#_mutually_exclusive_wpos_statistics)
�is_feature_flag�is_feature_icon_enabled�disabled_status�server_wide_options�awp_enabled_visible_premium�awp_enabled_disallowed_premium�result�module�stats_suiterRs
          r�fill_current_wpos_statisticsr��sS���g�n�n�%@�A�A�O�;�=�=��'�	��H�H�O�1�3�3��Bl�Bn�Bn�?��!?�(�����(�
	�$�&�&�(�	�$�&�&�(�	����(�&	����'(�.	����/(�6	(��7(�8	(�)@�9(�:	<�=X�;(�<	?�@^�=(�>	&�v�d�3F�3W�.X�.X�'Y�'Y�?(�@	&�v�d�3F�3W�.X�.X�'Y�'Y�A(�B	���2�>���1�A�
�C(�J	0��1D�1D�EX�E{�1|�1|�K(�L	,�_�-@�-@�AT�As�-t�-t�M(�N	*�?�+>�+>�?R�?o�+p�+p�O(�F�T(H�!�9��(G�(G�(G�F�?��G�$�'G�!�9��(G�(G�(G�F�?��G�$�'G�!�9�(.�(.�F�?��G�$�,�I�I���U�?�?�$�K�K� �K�/O�
�H�i�D�0:�0:�0:�����,�/O�
�H�i�D�0:�0:�0:�����,�/O�
�H�i�0!�0!�����,�/O�
�H�i�D�4�0I�0I�0I�����,�,�*J�	���{�/?�.@�*B�*B�*B�F�?��I�&�)I�	���{�/?�.@�UY�*[�*[�*[�F�?��I�&�)I�	���{�/?�.@�*B�*B�*B�F�?��I�&�)I�	���{�/?�.@�UY�dh�*j�*j�*j�F�?��I�&��5�5���'�'�'�2�K�K��K�
-�R��u�g�V�V�V�	�� ��-�
.�e�4�4�	�� ��-�-�(��<�<�<���	����Mr*�wpos_statistics�statistic_keys�	from_stat�
subtract_statc��d|��}d|��}|���D][\}}||vrRt|��tur<||vr||vr||xx||zcc<||vr||vr||xx||zcc<�\dS)z/
    Returns mutually exclusive statistics
    �accelerate_wp_N)�items�typerw)r�r�r�r��
from_stat_awp�subtract_awp�key�stats        rr�r�s���
1�Y�0�0�M�3�M�3�3�L�$�*�*�,�,�:�:�	��T��.� � �T�$�Z�Z�4�%7�%7��D� � �]�d�%:�%:��Y����4�
�#6�6������$�$���)=�)=��]�#�#�#�t�L�'9�9�#�#�#��
:�:r*)r?FNF)'rtr+�typingr�clcommonr�clcommon.clpwdr�clwpos.logsetupr�clwpos.optimization_featuresr�clwpos.feature_suitesrr	r
rrr
�clwpos.utilsr�clwpos.user.configrrrr�intrr2r8r>rLrQrVr[r�rwrTr�r$r*r�<module>r�s���
�	�	�	�
�
�
�
�������������*�*�*�*�*�*�)�)�)�)�)�)�B�B�B�B�B�B�����������������
1�0�0�0�0�0�)�)�)�)�)�)�-�-�-�-�-�-�
�-�+�
,�
,��
�s�
�T�RU�Y�
�[^�
�
�
�
� 
X�S�
X�4��9�
X��
X�
X�
X�
X�
X�S�
X�4��9�
X��
X�
X�
X�
X�L�C�L��c��L�s�L�L�L�L�� �'+�� � ��c�� �� � ��9�	 � � � �F/�/�/�0�S�����	�	�	�n�n�n�b:��:�t�:�`c�:�tw�:�:�:�:�:�:r*