AlkantarClanX12

Your IP : 18.117.159.65


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

�

".g�����ddlZddlZddlZddlZddlZddlZddlmZmZm	Z	ddl
Zddlm
Z
mZddlmZddlmZddlmZmZmZmZdZGd�d	e��Zd
�ZGd�d��ZGd
�de��ZGd�de��ZGd�de��ZGd�de��Z Gd�de��Z!Gd�de��Z"Gd�de��Z#Gd�de��Z$dS)�N)�Tuple�Optional�List)�ClPwd�	mysql_lib)�ProcLve)�grep)�cpanel�directadmin�
ispmanager�plesk�0c��eZdZdZdS)�ConfigDataErrorz�
    Should be raised when something went wrong during user's config data
    loading/parsing.
    Supposed to be used when we want to skip some user with broken
    configuration files
    N)�__name__�
__module__�__qualname__�__doc__���py/clcontrollib.pyrrs��������	�Drrc��tj��tjdkrt��Stjdkrt	��Stjdkrt��Stjdkrt
��Stjdkrt��Stjdkrt��St��S)N�Plesk�cPanel�	InterWorx�
ISPManager�DirectAdmin�	HostingNG)
�detect�	getCPName�CP_NAMEr�Cpanelrrrr�Unknownrrr�detect_panelclassr$#s���
�����
�~�� � ��w�w��
�~��!�!��x�x��
�~��$�$��{�{��
�~��%�%��|�|��
�~��&�&��}�}��
�~��$�$��{�{���9�9�rc���eZdZd�Zdd�Zd�Zd�Zed���Z		dd	�Z	ed
���Z
edd���Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�GeneralPanelc�4�t��|_|jj|_tj��|_|j���|j���kr td|j�d|j�d����d|_
dS)NzClass "z" not should be used on panel "�")r�
users_data�	__class__r�
class_namerr �current_panel_name�lower�UserWarning�cpapi_plugin)�selfs r�__init__zGeneralPanel.__init__6s����'�'����.�1���"(�"2�"4�"4����?� � �"�"�d�&=�&C�&C�&E�&E�E�E��d�$�/�d�d�$�Ja�d�d�d���
�!����rFc�4�|j���S)z�
        List all admins names in given control panel
        :param bool debug: Do produce debug output or don't
        :return: list of strings
        )r/�admins�r0�debugs  r�list_adminszGeneralPanel.list_adminsAs��� �'�'�)�)�)rc�6�|j�|��S)z|
        Return True if username is in admin names
        :param str username: user to check
        :return: bool
        )r/�is_admin)r0�usernames  rr8zGeneralPanel.is_adminIs��� �)�)�(�3�3�3rc�l�|r1tj�|�d|jj�d���dSdS)Nz is not implemented for �
)�sys�stderr�writer*r�r0r5�method_names   r�_warningzGeneralPanel._warningQsI���	b��J����`�`�T�^�E\�`�`�`�a�a�a�a�a�	b�	brc�J�tjtjd|����dS)NzCL_CONTROLLIB: )�syslog�LOG_WARNING)�msgs r�
_slog_warningzGeneralPanel._slog_warningUs&���
�f�(�*A�C�*A�*A�B�B�B�B�BrNTc�>�|�|�td���|�|�td���|�d	|j�|��S#tj$r7}|rt|��|r|�d|�d���Yd}~dSd}~wwxYw	|j�t|����dS#tj$r7}|rt|��|r|�d|�d���Yd}~dSd}~wt$rtd��YdSwxYw)	aH
        Check that provided user is really exists in system and return it as:
        - uid if username was provided
        - username if uid was provided
        - None if user doesn't exists
        Produce syslog/debug output depending on flags if user isn't exists.

        This helper function is mostly needed because it's possible that
        user is already deleted in system but his entity is still present in
        control panel files (like DA_USERS_DIR) so we should do additional
        checks to skip such users.

        :return: (uid | username) or None
        NzIThis function accepts either uid or username, but not both simultaneouslyz0Incorrect call: uid or username is not specifiedzUser with username="z" is not present in the systemrzUser with uid="�Incorrect user id)	�
ValueErrorr)�get_uidr�NoSuchUserException�printrF�	get_names�int)r0�uidr9r5�syslog_�es      r�_check_and_get_userz GeneralPanel._check_and_get_userYs��� �?�x�3��;�<�<�
<��;�8�+��O�P�P�P���

���.�.�x�8�8�8���,�
�
�
����!�H�H�H����&�&�W�x�W�W�W�����t�t�t�t�t�����
����
	��?�,�,�S��X�X�6�6�q�9�9���(�	�	�	��
��a�����
��"�"�I�c�I�I�I�����4�4�4�4�4������	�	�	��%�&�&�&��4�4�	���s5�A�B
�,B�B
�,B;�;D�
,C<�<D�Dc��t|dd���5}|���}ddd��n#1swxYwY|S)�
        Safely read file content and close it before return the content string.
        No exceptions will have caught!

        :param string file_name: Absolute or relative path to file
        :rtype: string
        :return: Content of given file path
        �r�utf-8��encodingN)�open�	readlines)�	file_name�f�contents   r�get_file_lineszGeneralPanel.get_file_lines�s}���)�S�7�
3�
3�
3�	$�q��k�k�m�m�G�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$����	$�	$�	$�	$��s�4�8�8�wc��t||d���5}|�|��ddd��dS#1swxYwYdS)a=
        Safely write to file and close it before the function end.
        No exceptions will have caught!

        :param string file_name: Absolute or relative path to file
        :param string content: What to write there
        :param string open_method: Either "w" or "a" or "b"
        :return: None
        rVrWN)rY�
writelines)r[r]�open_methodr\s    r�write_file_lineszGeneralPanel.write_file_lines�s����)�[�7�
;�
;�
;�	"�q�
�L�L��!�!�!�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"�	"�	"s�6�:�:c�2�|�|d��dS)a
        Implements /usr/bin/getcontrolpaneluserspackages and
        /usr/bin/getcontrolpaneluserspackages --list-all commands
        Result is stdout output:
            uid package name

        :param bool debug: Do produce debug output or don't
        :return: None
        zList allN�rAr4s  r�list_allzGeneralPanel.list_all�s��	
�
�
�e�Z�(�(�(�(�(rc�2�|�|d��dS)a	
        Implements /usr/bin/getcontrolpaneluserspackages --package=package_name
        Result is stdout output:
            uid

        :param string package: Package name
        :param bool debug: Do produce debug output or don't
        :return: None
        zList users in given packageNre)r0�packager5s   r�list_users_in_packagez"GeneralPanel.list_users_in_package�s��	
�
�
�e�:�;�;�;�;�;rc�2�|�|d��dS)aX
        Implements
        /usr/bin/getcontrolpaneluserspackages --package=package_name --reseller=reseller_name
        Result is stdout output:
            uid

        :param string package: Package name
        :param string reseller: Reseller name
        :param bool debug: Do produce debug output or don't
        :return: None
        z&List users in given reseller's packageNre)r0rh�resellerr5s    r�list_users_in_reseller_packagez+GeneralPanel.list_users_in_reseller_package�s��	
�
�
�e�E�F�F�F�F�Frc�2�|�|d��dS)z�
        Implements /usr/bin/getcontrolpaneluserspackages --userid=id
        Result is stdout output:
            uid package name

        :param int uid: User ID
        :param bool debug: Do produce debug output or don't
        :return: None
        zList given user's packageNre�r0rOr5s   r�list_user_packagezGeneralPanel.list_user_package�s��	
�
�
�e�8�9�9�9�9�9rc�2�|�|d��dS)z�
        Implements /usr/bin/getcontrolpaneluserspackages --list-packages
        Result is stdout output:
            package name

        :param bool debug: Do produce debug output or don't
        :return: None
        zList all packagesNrer4s  r�
list_packageszGeneralPanel.list_packages�s��	
�
�
�e�0�1�1�1�1�1rc�2�|�|d��dS)z�
        Implements /usr/bin/getcontrolpaneluserspackages --list-resellers-packages
        Result is stdout output:
            reseller_name package name

        :param bool debug: Do produce debug output or don't
        :return: None
        z!List packages belong to resellersNrer4s  r�list_resellers_packagesz$GeneralPanel.list_resellers_packages�s��	
�
�
�e�@�A�A�A�A�Arc�2�|�|d��dS)a'
        Implements
        /usr/bin/getcontrolpaneluserspackages --list-reseller-packages=reseller
        Result is stdout output:
            package name

        :param string reseller: Reseller name
        :param bool debug: Do produce debug output or don't
        :return: None
        z&List packages belong to given resellerNre�r0rkr5s   r�list_reseller_packagesz#GeneralPanel.list_reseller_packages�s��	
�
�
�e�E�F�F�F�F�Frc�2�|�|d��dS)z�
        Implements /usr/bin/getcontrolpaneluserspackages --list-users
        Result is stdout output:
            uid,package name,reseller_name

        :param bool debug: Do produce debug output or don't
        :return: None
        z
List usersNrer4s  r�
list_userszGeneralPanel.list_users�s��	
�
�
�e�\�*�*�*�*�*rc#�>K�|�|d��dV�dS)a(
        Generate triple with uid, it's package, it's reseller

        :param bool debug: Do produce debug output or don't
        :param string reseller_name: filter by this reseller
        :rtype: generator of (int, string, string)
        :return: (uid, package name, reseller name)
        zList reseler's users)r�rzNre)r0r5�
reseller_names   r�_get_user_packageszGeneralPanel._get_user_packagess*����	
�
�
�e�3�4�4�4������rc��|jdkrG|�|rtd��dS|�||���D]\}}}t|�d|�����dSdS)z�
        Print uid and package for defined reseller
        :param bool debug: Do produce debug output or don't
        :param reseller: username of reseller
        :return: None
        r&NzReseller is not defined)r5r{�,)r+rLr|)r0r5rkrOrh�_s      r�list_reseller_usersz GeneralPanel.list_reseller_userss����?�n�,�,����5��3�4�4�4���#'�#:�#:��V^�#:�#_�#_�
*�
*���W�a���(�(�w�(�(�)�)�)�)�
-�,�

*�
*rc�2�|�|d��dS)z�
        Determine user's reseller
        :param string uid: uid of user
        :param bool debug: Do produce debug output or don't
        :rtype: string
        :return: reseller name
        zGet user's resellerNrerns   r�get_resellerzGeneralPanel.get_reseller#s��	
�
�
�e�2�3�3�3�3�3r�F)NNFT)r_�FN)rrrr1r6r8rA�staticmethodrFrRr^rcrfrirlrorqrsrvrxr|r�r�rrrr&r&4s�������	!�	!�	!�*�*�*�*�4�4�4�b�b�b��C�C��\�C�BG�$(�1�1�1�1�f����\���"�"�"��\�"�
)�
)�
)�
)�
<�
<�
<�
<�G�G�G�G�
:�
:�
:�
:�	2�	2�	2�	2�	B�	B�	B�	B�G�G�G�G�	+�	+�	+�	+�
�
�
�
�
*�
*�
*�
*�4�4�4�4�4�4rr&c���eZdZdZdZdZdZdZ�fd�Zd�Z	d�Z
d	�Zd
�Zdd�Z
dd
�Zd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z�xZS)r"z/var/cpanel/usersz/var/cpanel/packagesz/var/cpanel/resellersz/etc/trueuserownersNc���t�����|j���|_tj��|_dS�N)�superr1r)�get_sys_min_uid�min_uidr
�PanelPluginr/�r0r*s �rr1zCpanel.__init__6sE���
����������6�6�8�8���"�.�0�0����rc��d}	t|dd���5}|���}ddd��n#1swxYwYn�#t$r~}d|�d|�d�}|�|j��r|d	|��z
}t|tj�
��|�|��t
j	t��Yd}~nd}~wwxYw|S)rTz]http://kb.cloudlinux.com/2017/08/how-to-fix-the-issue-with-non-utf-symbols-in-packages-names/rUrVrWN�Unable to read file 'z
', error is: z-. It looks like you use not an UTF-8 charset.z
Please read the instruction: )�file)rYrZ�UnicodeDecodeError�
startswith�USERDIRrLr<r=rF�exit�BAD_CODING_ERROR_CODE)r0r[�
ENCODING_LINKr\r]rQ�messages       rr^zCpanel.get_file_lines;sI��B�
�
	,��i��w�7�7�7�
(�1��+�+�-�-��
(�
(�
(�
(�
(�
(�
(�
(�
(�
(�
(����
(�
(�
(�
(���!�	,�	,�	,�E�i�E�E�a�E�E�E�G��#�#�D�L�1�1�
M��L�]�L�L�L���'��
�+�+�+�+����w�'�'�'��H�*�+�+�+�+�+�+�+�+�����	,�����s3�A�7�A�;�A�;�A�
C�
A4C�Cc�f�i}tjd��}tj�|j��rv|�|j��}|D]Y}|���}tj||��}|��.|�	d��||�	d��<�Z|S)z~
        Get dict, where keys - user's names, values - reseller's names
        :return: dict {user1: reseller1, ...}
        z!^(?P<name>\w+):\s*(?P<owner>\w+)$N�owner�name)
�re�compile�os�path�isfile�RESELLERS_AND_USERSr^�strip�match�group)r0�result�pattern�file_content�line�strippedr�s       r�_get_users_resellers_dictz Cpanel._get_users_resellers_dictSs���
���*�A�B�B��
�7�>�>�$�2�3�3�	C��.�.�t�/G�H�H�L�$�
C�
C���:�:�<�<�����(�3�3���=��.3�k�k�'�.B�.B��u�{�{�6�*�*�+�+��
rc��g}tj�|j��r&|�|j��}d�|D��}|S)zw
        Get resellers list from RESELLERS_PATH

        :rtype: list
        :return: list of resellers names
        c�j�g|]0}|����dd��d��1S)�:�r)r��split��.0r�s  r�
<listcomp>z)Cpanel._get_resellers.<locals>.<listcomp>xs5��P�P�P�4������+�+�C��3�3�A�6�P�P�Pr)r�r�r��RESELLERS_PATHr^)r0�	resellersr�s   r�_get_resellerszCpanel._get_resellersnsR���	�
�7�>�>�$�-�.�.�	Q��.�.�t�/B�C�C�L�P�P�<�P�P�P�I��rc	��d}tj�|��rk|�|��}t	tdddd|�����}|r3|d����d��d}|S)z�
        Get package name from user's config file

        :param string path: Path to file contains info about cPanel user
        :rtype: string
        :return: Package name
        rzz	PLAN\=.*$F��fixed_string�match_any_position�multiple_search�data_from_filer�=r�)r�r�r�r^�listr	r�r�)r0r�rhr�r�s     r�get_packagezCpanel.get_package{s�����
�7�>�>�$���
	:��.�.�t�4�4�L��$��"�#(� %�+������F��
:� ��)�/�/�+�+�1�1�#�6�6�q�9���rFc	���d}|�||���}|r�tj�|j|��}tj�|��rk|�|��}ttdddd|�����}|r3|d�	���
d��d}|r||���vr|ndS)	��
        Determine user's reseller based on `owner` field from user's config

        :param string uid: uid of user
        :param bool debug: Do produce debug output or don't
        :rtype: string
        :return: reseller name
        rz�rOr5z
OWNER\=.*$Fr�rr�r�)rRr�r��joinr�r�r^r�r	r�r�r�)r0rOr5rkr9r�r�r�s        r�
_get_resellerzCpanel._get_reseller�s������+�+��5�+�A�A���	?��7�<�<���h�7�7�D��w�~�~�d�#�#�

?�#�2�2�4�8�8���d�!�!&�',�$)�#/��������?�%�a�y���0�0�6�6�s�;�;�A�>�H�#�Q��D�4G�4G�4I�4I�(I�(I�x�x�r�Qrc�N�t|�||�����dS)r��r5N)rLr�rns   rr�zCpanel.get_reseller�s+��	�d� � ��E� �2�2�3�3�3�3�3rc#�rK�tj�|j��r�tj|j��D]v}tj�tj�|j|����r|dfV��Ktj�|j|��dfV��udSdS)z�
        Generate list of packages in current panel

        :rtype: generator of (string, bool)
        :return: (name of package, True) for normal files and (/path/to/wrang/file, False) otherwise
        TFN)r�r��isdir�
PACKAGEDIR�listdirr�r�)r0�filenames  r�
_get_packageszCpanel._get_packages�s������7�=�=���)�)�	K��J�t��7�7�
K�
K���7�>�>�"�'�,�,�t���"I�"I�J�J�K�#�T�*�*�*�*�*��7�<�<����B�B�E�J�J�J�J�J�	K�	K�
K�
Krc��|���}|���D]O\}}|r3d|vr|�dd��d|vr�*t|���:|rtd|�d����PdS)Nrr�r�	Warning: � is not a file.�r�r�r�rL)r0r5r�r��is_files     rrqzCpanel.list_packages�s����'�'�)�)�	�!%�!3�!3�!5�!5�	=�	=��H�g��
=��(�?�?�x�~�~�c�1�'=�'=�a�'@�I�'M�'M���h������
=��;�(�;�;�;�<�<�<��
	=�	=rc#�~K�|���}|sdStj�|j��r�tj|j��D]�}	|j�|��}||jkr�)	tj�	|j|��}|�
||�||����}|�|��rdn|}|�||kr��||�
|��|fV���#tj$r}|rt!|��Yd}~��d}~wwxYwdSdS)ao
        Generate triple with uid, it's package and it's reseller for every user in USERDIR
        which uid is greater than MIN_UID

        :param bool debug: Do produce debug output or don't
        :param string reseller_name: filter by this reseller
        :rtype: generator of (int, string, string)
        :return: (uid, package name, reseller name)
        Nrz)r�r�r�r�r�r�r)rJr�r��getr�r8r�rrKrL)	r0r5r{�users_resellers_dictr�rOr�rkrQs	         rr|zCpanel._get_user_packages�st���� $�=�=�?�?��$�	��F�
�7�=�=���&�&�	B��J�t�|�4�4�
B�
B��
B��/�1�1�(�;�;�C��T�\�)�)� �*��7�<�<���h�?�?�D�3�7�7��$�BT�BT�UX�Z_�B`�B`�a�a�H�%)�]�]�8�%<�%<�J�r�r�(�H�$�0�X��5N�5N� ��� 0� 0�� 6� 6��A�A�A�A�A���0�!�!�!��!��a�������������!����
	B�	B�
B�
Bs�%D�D8�D3�3D8c��|�||���D]4\}}}|dkr(|�t||���||krt|���5dS)N�r{rz�r|rL)r0rhr5rkrO�self_package�
self_resellers       rrfzCpanel.list_all�sp��04�0G�0G��]e�0G�0f�0f�	�	�,�C��}��r�!�!��?��#�|�,�,�,�,���,�,��#�J�J�J��	�	rc��	|j�t|����}|D]X}|jdz|z}tj�|��r*|�|��}|dkrt|���YdS#tj
$r|rtd��YdSYdSt$rtd��YdSwxYw)N�/rzz,getcontrolpaneluserspackages: User not foundrH)r)rMrNr�r�r�r�r�rLrrKrI)r0rOr5�users�userr�rhs       rrozCpanel.list_user_package�s��
	'��O�-�-�c�#�h�h�7�7�E��
'�
'���|�c�)�D�0���7�>�>�$�'�'�'�"�.�.�t�4�4�G��"�}�}��g�����
'�
'��
�(�	F�	F�	F��
F��D�E�E�E�E�E�E�
F�
F�
F��	'�	'�	'��%�&�&�&�&�&�&�	'���s�'B� C�,C�Cc��|���}|���D]a\}}|rCd|vr?|�dd��d}||vr�,|�||kr�5t|�d|�����J|s|rtd|�d����bdS)Nrr�r� r�r�r�)r0r5rkr�r�r��res_names       rrszCpanel.list_resellers_packagess����'�'�)�)�	�!%�!3�!3�!5�!5�		=�		=��H�g��
=�3�(�?�?�#�>�>�#�q�1�1�!�4���9�,�,���'�H��,@�,@����.�.�H�.�.�/�/�/�/��
=��
=��;�(�;�;�;�<�<�<��		=�		=rc��|���}||vr|rtd|�d���dS|�||���dS)NzError: z is not reseller�r5rk)r�rLrs)r0rkr5r�s    rrvzCpanel.list_reseller_packagessd���'�'�)�)�	��9�$�$��
<��:��:�:�:�;�;�;��F��$�$�5�8�$�D�D�D�D�Drc	�.���|����d|vrN|�d���t��fd�tdt	�����D����rdS|�|�|��dS|rt
d��dSdS)Nrc3�V�K�|]#}d��d|����vV��$dS)rN)r�)r��i�partsr�s  ��r�	<genexpr>z/Cpanel.list_users_in_package.<locals>.<genexpr>!s<�����R�R��3�8�8�E�"�1�"�I�&�&�)�3�R�R�R�R�R�Rrr�z/getcontrolpaneluserspackages: Undefined package)r�r��any�range�lenrfrL)r0rhr5r�r�s   @@rrizCpanel.list_users_in_packages������'�'�)�)�	��'�>�>��M�M�#�&�&�E��R�R�R�R�R�U�1�c�%�j�j�=Q�=Q�R�R�R�R�R�
������M�M�'�"�"�"�"�"�
�	E��C�D�D�D�D�D�	E�	Erc��|���}||vr|�|||���dS|rtd��dSdS)Nr�z8getcontrolpaneluserspackages: Undefined reseller package)r�rfrL)r0rhrkr5r�s     rrlz%Cpanel.list_users_in_reseller_package(sf���'�'�)�)�	��y� � ��M�M�'���M�B�B�B�B�B�
�	N��L�M�M�M�M�M�	N�	Nrc�l�|�|��D]\}}}t|�d|�d|�����dS�Nr~r�)r0r5rOr�rks     rrxzCpanel.list_users/sW��+/�+B�+B�5�+I�+I�	6�	6�'�C��x��S�4�4�<�4�4�(�4�4�5�5�5�5�	6�	6rr�r�)NFN)rrrr�r�r�r�r)r1r^r�r�r�r�r�r�rqr|rfrorsrvrirlrx�
__classcell__�r*s@rr"r".s��������!�G�'�J�,�N�/���J�1�1�1�1�1�
���0���6������,R�R�R�R�4
4�
4�
4�
4�K�K�K�=�=�=�=�B�B�B�B�B����'�'�'�'� =�=�=�=�E�E�E�E�	E�	E�	E�	E�N�N�N�N�6�6�6�6�6�6�6�6rr"c�$��eZdZdZdZdZdZdZdZdZ	dZ
e��Z�fd�Z
d	�Zd
�Zd�Zd�Zd%d
edeeedefd�Zd&d�Zd&d�Zd'd�Zd�Zd�Zd�Zd'd�Zd'd�Zd�Zd'd�Zd'd�Z d'd�Z!d'd�Z"d'd�Z#d'd �Z$d!�Z%d"�Z&d'd#�Z'd'd$�Z(�xZ)S)(rz"/usr/local/directadmin/data/users/z,/usr/local/directadmin/conf/directadmin.confz,/usr/local/directadmin/data/admin/admin.listz//usr/local/directadmin/data/admin/reseller.listz//usr/local/directadmin/data/admin/packages.listrzNc����t�����tj��|_tj��|_|j���|_	dSr�)
r�r1r�detect_DA_admin�DA_ADMINrr�r/�get_encoding_name�ENCODINGr�s �rr1zDirectAdmin.__init__?sT���
���������.�0�0��
�'�3�5�5����)�;�;�=�=��
�
�
rc�&�	t|d|j���5}|���}ddd��n#1swxYwY|S#t$r?}d|�d|j�d�}|�|d|�d�z��t|��|�d}~wwxYw)NrUrWr�z '. It looks like you use not an z	 charset.z Error is: �.)rYr�rZr�rF�RuntimeError)r0r[r\r]rQr�s      rr^zDirectAdmin.get_file_linesFs��	/��i��t�}�=�=�=�
(���+�+�-�-��
(�
(�
(�
(�
(�
(�
(�
(�
(�
(�
(����
(�
(�
(�
(��N��!�	/�	/�	/�O�i�O�O�6:�m�O�O�O�G����w�);�q�);�);�);�;�<�<�<��w�'�'�Q�.�����		/���s4�A�:�A�>�A�>�A�
B�:B�Bc���	|�|��S#t$r?}d}|�|�||����t	��|�d}~wwxYw)zU
        Just a wrapper around _get_user_info_inner to send errors to syslog
        z;Skipping user '{}' with bad configuration files due to '{}'N)�_get_user_info_inner�	ExceptionrF�formatr)r0r9rQ�tpls    r�_get_user_infozDirectAdmin._get_user_infoQsq��
		+��,�,�X�6�6�6���	+�	+�	+�O�C����s�z�z�(�A�6�6�7�7�7�!�#�#��*�����		+���s��
A �:A�A c	��tj�|j|d��}	|�|��}n#t
$rd}YnwxYw|st
d���ttdddd|�����}ttdddd|�����}	|d�	���
d	��d
}n"#t$r}t
d��|�d}~wwxYw	|d�	���
d	��d
}n"#t$r}t
d��|�d}~wwxYw|�||��}	|d
kr5d}|j
�|��}
|�|
��rd}	|}|j
�|��}||	|fS)zG
        Return uid, package name and owner of user (reseller)
        �	user.confN�&Unable to read any data from user.conf�
usertype\=.*$Fr�zcreator\=.*$rr�r�z#No "usertype" record in user configz"No "creator" record in user configrkrz�DEFAULT)r�r�r��DA_USERS_DIRr^r�rIr�r	r�r��
IndexError�_get_user_packager)rJ�_is_reseller_limits_enabled)r0r9�userprofile�userprofile_content�result_usertype�result_creator�usertyperQrkrh�lvp_idrOs            rr�z DirectAdmin._get_user_info_inneras,��
�g�l�l�4�#4�h��L�L��	'�"&�"5�"5�k�"B�"B�����	'�	'�	'�"&����	'����"�	G��E�F�F�F��t���$�!�.� 
� 
� 
�����d���$�!�.�
�
�
����	K�&�q�)�/�/�1�1�7�7��<�<�Q�?�H�H���	K�	K�	K��B�C�C��J�����	K����	J�%�a�(�.�.�0�0�6�6�s�;�;�A�>�H�H���	J�	J�	J��A�B�B��I�����	J�����(�(��3F�G�G���z�!�!��H��_�,�,�X�6�6�F��/�/��7�7�
$�#��#���o�%�%�h�/�/���G�X�%�%s?�>�A
�A
�$3C�
C7�"C2�2C7�;3D/�/
E�9E	�	Ec�6�|j�|��Sr�)�proc_lve�	exist_lvp)r0rs  rrz'DirectAdmin._is_reseller_limits_enabled�s���}�&�&�v�.�.�.rr9r�returnc	��|s`tj�|j|d��}	|�|��}n#t
$rd}YnwxYw|st
d���ttdddd|�����}ttdddd|�����}	|d�	���
d	��d
}n"#t$r}t
d��|�d}~wwxYw|dkrY|rW	|d�	���
d	��d
}n"#t$r}t
d
��|�d}~wwxYw|S)z�
        Reads user's package just as in the `_get_user_info_inner` function, but without masking to DEFAULT package
        Be aware that it may return different package than the `_get_user_info_inner` function
        r�Nr�zpackage\=.*$Fr�zoriginal_package\=.*$rr�r�z"No "package" record in user config�customz+No "original_package" record in user config)r�r�r�rr^r�rIr�r	r�r�r)r0r9rr�result_package�result_original_packagerhrQs        rrzDirectAdmin._get_user_package�s���
#�	K��'�,�,�t�'8�(�K�P�P�K�
+�&*�&9�&9�+�&F�&F�#�#���
+�
+�
+�&*�#�#�#�
+����&�
K� �!I�J�J�J��d���$�!�.�
�
�
����#'�t�$��$�!�.�(
�(
�(
�#�#��	J�$�Q�'�-�-�/�/�5�5�c�:�:�1�=�G�G���	J�	J�	J��A�B�B��I�����	J�����h���#:��
W�1�!�4�:�:�<�<�B�B�3�G�G��J�����
W�
W�
W� �!N�O�O�UV�V�����
W�����sA�A�A�A�&3C�
C9�$C4�4C9�3D9�9
E�E�EFc#�4K�t|�����}tj|j��D]Z}||vr�|�||�����	|�|��\}}}n#t$rY�FwxYw|�||kr�S|||fV��[dS)a'
        Generate triple with uid, it's package, it's reseller
        :param bool debug: Do produce debug output or don't
        :param string reseller_name: filter by this reseller
        :rtype: generator of (int, string, string)
        :return: (uid, package name, reseller name)
        �r9r5N)�setr6r�r�rrRr�r)r0r5r{r6r9rOrhrks        rr|zDirectAdmin._get_user_packages�s������$�*�*�,�,�-�-���
�4�#4�5�5�	)�	)�H��;�&�&���'�'���'�G�G�O��
�)-�)<�)<�X�)F�)F�&��W�h�h��"�
�
�
���
�����(�X��-F�-F���w��(�(�(�(�(�#	)�	)s�A7�7
B�Bc��tj�|j|d��}tj�|��sdS|�|��}|D]T}	|�|�d����\}}}n#t$rY�<wxYwt|�d|�����U|�
|��sB	|�|��\}}}n#t$rYdSwxYwt|�d|����dSdS)z�
        Print uid and package for users of a specified reseller
        :param debug: whether to produce debug output
        :param reseller: username of a reseller
        :return: None
        z
users.listNr;r~)r�r�r�r�existsr^r��rstriprrLr8)	r0r5rkr��reseller_usersr9rOrhrs	         rr�zDirectAdmin.list_reseller_users�sJ���w�|�|�D�-�x��F�F���w�~�~�d�#�#�	��F��,�,�T�2�2��&�	&�	&�H�
�"&�"5�"5�h�o�o�d�6K�6K�"L�"L���W�a�a��"�
�
�
���
�����S�$�$�7�$�$�%�%�%�%��}�}�X�&�&�	&�
�"&�"5�"5�h�"?�"?���W�a�a��"�
�
�
����
�����S�$�$�7�$�$�%�%�%�%�%�	&�	&s$�",B�
B�B�
C$�$
C2�1C2c��|�||���}|r=	|�|��\}}}n#t$rYdSwxYwt|��dSdS)z�
        Determine user's reseller based on package from user's config
        :param string uid: uid of user
        :param bool debug: Do produce debug output or don't
        :rtype: string
        :return: reseller name
        r�N�rRr�rrL)r0rOr5r9rrks      rr�zDirectAdmin.get_reseller�s���+�+��5�+�A�A���	�
�!%�!4�!4�X�!>�!>���1�h�h��"�
�
�
����
�����(�O�O�O�O�O�	�	��5�
A�Ac�,�|�|��S)z�
        Check login_name is da admin. Backward compatibility wrapper
        :param login_name: Admin name
        :return:
        )r8)r0�
login_names  r�is_da_adminzDirectAdmin.is_da_admins���}�}�Z�(�(�(rc	�z�d}tj�|j|d��}tj�|��rs|�|��}t
tdddd|�����}|r;|d����	d��d}|dkrd	}|S)
z�
        Check login_name is da admin for using in hook

        return True - if login_name is admin
               False - otherwise
        Fr�rr�rr�r��adminT)
r�r�r�rr�r^r�r	r�r�)r0rr�r�r�rr
s       r�is_da_admin_for_hookz DirectAdmin.is_da_admin_for_hooks������w�|�|�D�-�z�;�G�G��
�7�>�>�$���	"��.�.�t�4�4�L�"�4� �"�#(� %�+�$�$�$���O��
"�*�1�-�3�3�5�5�;�;�C�@�@��C���w�&�&�!�F��
rc�(�	ddlm}m}m}m}n3#t
$r&t
d��tjd��YnwxYw|�	��}|D]9}	t|���#|||f$r}t
|�d���Yd}~�2d}~wwxYwdS)z�
        Add all DA admins to sudoers. Now calls only from CageFS plugin installer
        :param s_cmd: String such as "Clsudo.add_cagefs_user(user)"
        :return:
        r)�Clsudo�
NoSuchUser�UnableToReadFile�UnableToWriteFilezDCannot import Clsudo. Check if alt-python27-cllib package installed
r�r;N)�clsudor%r&r'r(�ImportErrorrLr<r�r6�eval)	r0�s_cmdr%r&r'r(�	da_adminsr�rQs	         r�add_all_da_admins_to_sudoersz(DirectAdmin.add_all_da_admins_to_sudoers5s���	�
Y�X�X�X�X�X�X�X�X�X�X�X�X���	�	�	��Y�Z�Z�Z��H�Q�K�K�K�K�K�	�����$�$�&�&�	��	 �	 �D�
 ��U������� 0�2C�D�
 �
 �
 ���h�h�h�������������
 ����	 �	 s$��-?�?�A+�+B�3B
�
Bc�,�|�|��S)z<
           Wrapper for compatibility with old code
        )r6r4s  r�get_all_da_adminszDirectAdmin.get_all_da_adminsIs������&�&�&rc��g}tj�|j��r&|�|j��}d�|D��}|S)zr
        Get all DA admins list

        :rtype: list of strings
        :return: List of DA admins names
        c�8�g|]}|�d����S)r;�rr�s  rr�z+DirectAdmin.list_admins.<locals>.<listcomp>Ys$��D�D�D�t����T�*�*�D�D�Dr)r�r�r��
DA_ADMIN_LISTr^)r0r5r-r�s    rr6zDirectAdmin.list_adminsOsR���	�
�7�>�>�$�,�-�-�	E��.�.�t�/A�B�B�L�D�D�|�D�D�D�I��rc#�vK�|�|j��}|D]}|�d��V��dS�Nr;)r^�DA_ADMINS_PACKAGESr)r0r�r�s   rr�zDirectAdmin._get_packages\sP�����*�*�4�+B�C�C�� �	$�	$�D��+�+�d�#�#�#�#�#�#�	$�	$rc�R�|���D]}t|���dSr�)r�rL)r0r5r�s   rrqzDirectAdmin.list_packagesas4���&�&�(�(�	�	�D��$�K�K�K�K�	�	rc�\�|���D]\}}}t||���dSr�r�)r0r5rOrhrs     rrfzDirectAdmin.list_alles@��#�6�6�8�8�	 �	 �O�C��!��#�w�����	 �	 rc�j�|���D]\}}}t|�d|�d|�����dSr�r�)r0r5rOrhrks     rrxzDirectAdmin.list_usersisU��&*�&=�&=�&?�&?�	1�	1�"�C��(��S�/�/�7�/�/�X�/�/�0�0�0�0�	1�	1rc��|�||���}|r=	|�|��\}}}n#t$rYdSwxYwt|��dSdS)Nr�r)r0rOr5r9rrhs      rrozDirectAdmin.list_user_packagems}���+�+��5�+�A�A���	�
� $� 3� 3�H� =� =�
��7�A�A��"�
�
�
����
�����'�N�N�N�N�N�	�	rc�j�|�d���D]\}}}||krt|���dS)Nrzr�r�)r0rhr5rO�package_rks      rriz!DirectAdmin.list_users_in_packagevsL���'�'�b�'�9�9�	�	�#�C��8��7�"�"��c�
�
�
��	�	rc�j�|�|���D]\}}}||krt|���dS)Nr�r�)r0rhrkr5rOr=rs       rrlz*DirectAdmin.list_users_in_reseller_package}sL���'�'�h�'�?�?�	�	��C��1��7�"�"��c�
�
�
��	�	rc� �g}tj�|j��r&|�|j��}d�|D��}|�|�����tt|����S)z0
        Return list of resellers names
        c�^�g|]*}|����|�����+Srr3r�s  rr�z.DirectAdmin._get_resellers.<locals>.<listcomp>�s-��V�V�V�����
�
�V�d�k�k�m�m�V�V�Vr)	r�r�r��DA_RESELLERS_LISTr^�extendr6r�r)r0�resellers_listr�s   rr�zDirectAdmin._get_resellers�s�����
�7�>�>�$�0�1�1�	W��.�.�t�/E�F�F�L�V�V��V�V�V�N����d�.�.�0�0�1�1�1��C��'�'�(�(�(rc���g}tj�|j|d��}tj�|��r!|�|��}d�|D��}|S)z�
        Get all packages for giver reseller

        :param string reseller: Reseller name
        :rtype: list of strings
        :return: List of packages names that belongs to given reseller
        z
packages.listc�^�g|]*}|����|�����+Srr3r�s  rr�z6DirectAdmin._get_reseller_packages.<locals>.<listcomp>�s-��U�U�U�t�t�{�{�}�}�U�T�[�[�]�]�U�U�Ur)r�r�r�rr�r^)r0rk�
packages_list�package_pathr�s     r�_get_reseller_packagesz"DirectAdmin._get_reseller_packages�sf���
��w�|�|�D�$5�x��Q�Q��
�7�>�>�,�'�'�	V��.�.�|�<�<�L�U�U�|�U�U�U�M��rc��d}|���D]n}	|�|��}n#t$r}|�|}Yd}~�,d}~wwxYwtj|fd�|d�����}t
|���o|�|�dS)Nc��|�|�d|�d�S)Nr�r;r)r��pkg�ress   r�<lambda>z5DirectAdmin.list_resellers_packages.<locals>.<lambda>�s��V�2J�S�2J�2J�3�2J�2J�2J�rrz)r�rHr��	functools�reducer�rL)r0r5�first_exceptionrk�packagesrQ�
out_strings       rrsz#DirectAdmin.list_resellers_packages�s������+�+�-�-�	�	�H�
��6�6�x�@�@�����
�
�
�"�*�&'�O����������
����#�)�(0�J�J�J������e�g�g�	
�

�*������&�!�!�'�&s�0�
A�A�Ac�p�td�|�|������dSr6)rLr�rHrus   rrvz"DirectAdmin.list_reseller_packages�s0��
�d�i�i��3�3�H�=�=�>�>�?�?�?�?�?rr�r�r�)*rrrr�DA_CONFr4rAr7r�r�r)rr
r1r^r�r�r�strrrrr|r�r�r r#r.r0r6r�rqrfrxrorirlr�rHrsrvr�r�s@rrr4sJ�������7�L�<�G�B�M�I��J���H��H��J��w�y�y�H�>�>�>�>�>�	/�	/�	/�+�+�+� 8&�8&�8&�t/�/�/�'�'�#�'�H�T�RU�Y�DW�'�cf�'�'�'�'�R)�)�)�)�8&�&�&�&�8���� )�)�)����< � � �('�'�'�'�����$�$�$�
���� � � � �1�1�1�1�������������	)�	)�	)�
�
�
�"�"�"�"�(@�@�@�@�@�@�@�@rrc��eZdZd�ZdS)�ISPManagerGetPackagesExceptionc�<�t�||��dSr�)r�r1)r0r�s  rr1z'ISPManagerGetPackagesException.__init__�s�����4��)�)�)�)�)rN)rrrr1rrrrWrW�s#������*�*�*�*�*rrWc�p��eZdZdZdZdZ�fd�Zd�Zed
d���Z	d
d�Z
d
d	�Zd
d
�Zd
d�Z
d
d�Z�xZS)rz!/usr/local/ispmgr/etc/ispmgr.confN�	mgrsecurec�@��t�����tj��tj�d��}t
|d��|_tj��|_	tj��|_dS)Nr�r)
r�r1r�getCP�
CP_VERSIONr�rN�
isp_major_ver�ispmanager5_is_master�isp5_is_masterrr�r/)r0�	ver_partsr*s  �rr1zISPManager.__init__�sv���
��������������%�+�+�C�0�0�	� ��1��.�.���$�:�<�<���&�2�4�4����rc	���i}|jdk�r�tj�|j��std|j�����	t
|jdd���5}|���}ddd��n#1swxYwY|�d��}|�	d��|D�]}|���d}t|j�|�
d	d
������}|�d��}|D]�}|����d��rvd
�|������dd���}||vr||d
zt#|��z||<��t#|��||<����n�#t$t&f$r-}td|j�dt#|������|�d}~wwxYw	t)j|j��j}	|	D]7}
	|j�|
��}d||<�##t0j$rY�4wxYwn#t4$rYnwxYw|S)z�
        Retrives list of pairs "uid - package"
        :return: Dictionary: uid -> package_name
            Example: {512: 'custom', 513: 'test1'}
         Case 2: (Error): (1, "error message")
        �zERROR: Can't read rUrVrWN�Accountrr(rzr;�Presetr�r�z - �default)r^r�r�r��	ISP4_CONFrWrY�readr��poprNr)rJ�replacer�r�r�rU�OSError�IOError�grp�getgrnam�ISP5_GRP�gr_memrrK�KeyError)r0�dict_uid_packager\�linesr�rO�line1�pkg_namerQ�panel_usersr�s           r�_get_user_packages_dictz"ISPManager._get_user_packages_dict�s��������"�"��7�>�>�$�.�1�1�
\�4�5Z�$�.�5Z�5Z�[�[�[�
��$�.�#��@�@�@�%�A��F�F�H�H�E�%�%�%�%�%�%�%�%�%�%�%����%�%�%�%����I�.�.���	�	�!����!�
F�
F�D��*�*�,�,�q�/�C��d�o�5�5�c�k�k�$��6K�6K�L�L�M�M�C��:�:�d�+�+�D�!%�F�F�� �;�;�=�=�3�3�H�=�=�F�'*�x�x����
�
�0C�0C�0E�0E�a�b�b�0I�'J�'J�H�"�&6�6�6�8H��8M�PS�8S�VY�Zb�Vc�Vc�8c� 0�� 5� 5�8;�H�
�
� 0�� 5��
F�	
F���W�%�
�
�
�4�D���D�D�C��F�F�D�D���������
����	
�!�l�4�=�9�9�@��'���D��"�o�5�5�d�;�;��09�(��-�-�� �4����������	���
�
�
���
�����ss�G�"B�7G�B�G�
B�EG�H
�(H�H
�"I'�1I�I'�I#� I'�"I#�#I'�'
I4�3I4Fc�(�d}t|��dS)z�
        Get reseller name from user's config file

        :param string uid: uid of user
        :param bool debug: Do produce debug output or don't
        :rtype: string
        :return: reseller name
        r"N)rL)�clsrOr5rks    rr�zISPManager.get_reseller�s����
�h�����rc��	|���}t|�����D]}t|���dS#t$r.}t|��tjd��Yd}~dSd}~wwxYw�Nr�)rwr�valuesrLrWr<r�)r0r5rrrhrQs     rrqzISPManager.list_packagess���	�#�;�;�=�=���/�6�6�8�8�9�9�
�
���g�����
�
��-�	�	�	��!�H�H�H��H�Q�K�K�K�K�K�K�K�K�K�����	���s�AA�
B�#A>�>Bc��	|���}|���D]'\}}tt|��dz|z���(dS#t$r.}t|��tjd��Yd}~dSd}~wwxYw)Nr�r��rw�itemsrLrUrWr<r��r0r5rrrOrhrQs      rrfzISPManager.list_alls���	�#�;�;�=�=�� 0� 6� 6� 8� 8�
0�
0���W��c�#�h�h��n�w�.�/�/�/�/�
0�
0��-�	�	�	��!�H�H�H��H�Q�K�K�K�K�K�K�K�K�K�����	�����AA�
B�#B�Bc�0�	t|��}|���}||vrt||��dSdS#t$r.}t|��t	jd��Yd}~dSd}~wt$rtd��YdSwxYw)Nr�rH)rNrwrLrWr<r�rI)r0rOr5rrrQs     rrozISPManager.list_user_packages���		'��c�(�(�C�#�;�;�=�=���&�&�&��&�s�+�,�,�,�,�,�'�&��-�	�	�	��!�H�H�H��H�Q�K�K�K�K�K�K�K�K�K������	'�	'�	'��%�&�&�&�&�&�&�	'���s�<A�
B�#A5�5B�Bc��	|���}|���D]'\}}||krtt|�����(dS#t$r.}t|��tjd��Yd}~dSd}~wwxYwr{r~)r0rhr5rrrOr=rQs       rriz ISPManager.list_users_in_package&s���	�#�;�;�=�=��!1�!7�!7�!9�!9�
$�
$�
��X��h�&�&��#�c�(�(�O�O�O��
$�
$��.�	�	�	��!�H�H�H��H�Q�K�K�K�K�K�K�K�K�K�����	���r�c��	|���}|���D]\}}t|�d|�d����dS#t$r.}t|��t	jd��Yd}~dSd}~wwxYw)Nr~z,adminr�)rwrrLrWr<r�r�s      rrxzISPManager.list_users0s���	�#�;�;�=�=�� 0� 6� 6� 8� 8�
0�
0���W���.�.�w�.�.�.�/�/�/�/�
0�
0��-�	�	�	��!�H�H�H��H�Q�K�K�K�K�K�K�K�K�K�����	���s�AA�
A?�#A:�:A?r�)rrrrgr)ror1rw�classmethodr�rqrfrorirxr�r�s@rrr�s��������3�I��J��H�5�5�5�5�5�0 �0 �0 �d�
�
�
��[�
���������
'�
'�
'�
'������������rrc����eZdZdZdZdZdZdZ�fd�Zdd�Z	dd	�Z
dd
�Zddede
fd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdeeeeeeffd�Zdedefd�Zdedefd�Zdd�Zdd�Z�xZS)rzz
    See following link for information about database:
    https://github.com/plesk/db-schemas/blob/master/psadb.xml
    z/etc/psa/.psa.shadow�1�NoneNc�x��t�����tj��|_dSr�)r�r1r
r�r/r�s �rr1zPlesk.__init__Ds0���
��������!�-�/�/����rc���tj�|j��sdSt	|jdd���5}|������}ddd��n#1swxYwYtjddt|��ddd	�
��}|�
��5}|�||���cddd��S#1swxYwYdS)NFrUrVrW�	localhostr"�psaT�utf8)�hostr��passwd�db�use_unicode�charset)�args)r�r�r��
PSA_SHADOWrYrhr�r�MySQLConnectorrU�connect�
execute_query)r0�sql�datar\r��	connectorr�s       r�fetch_data_from_dbzPlesk.fetch_data_from_dbHsX���w�~�~�d�o�.�.�	��5�
�$�/�3��
9�
9�
9�	&�Q��V�V�X�X�^�^�%�%�F�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&����	&�	&�	&�	&��,�+�G�47��K�K�E�9=�v�O�O�O�	��
�
�
 �
 �	4�B��#�#�C�d�#�3�3�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4����	4�	4�	4�	4�	4�	4s#�'A1�1A5�8A5�7C�C�"CFc#�0K�d}|�|�d�}|�||g��}n4|�|�d�}|�||g��}n|�|��}|D];\}}}|p|j}|dkrdn|}|�||���}	|r	|	�|	||fV��<dS)a
        Generate triple with uid, it's package, it's reseller

        :param bool debug: Do produce debug output or don't
        :param string reseller_name: filter by this reseller
        :param string username: filter by this username (ignored if reseller_name set)
        :rtype: generator of (int, string, string)
        :return: (uid, package name, reseller name)
        a�
            SELECT
                sys_user.login,
                template.name,
                reseller.login
            FROM
                sys_users AS sys_user
            JOIN
                hosting AS hosting ON hosting.sys_user_id = sys_user.id
            JOIN
                domains AS domain ON hosting.dom_id = domain.id AND domain.webspace_id = 0
            JOIN
                clients AS reseller ON domain.vendor_id = reseller.id
            LEFT JOIN
                Subscriptions AS subscription ON subscription.object_id = domain.id
                AND subscription.object_type = 'domain'
            LEFT JOIN
                PlansSubscriptions AS plan ON plan.subscription_id = subscription.id
            LEFT JOIN
                Templates AS template ON plan.plan_id = template.id
            WHERE
                sys_user.mapped_to IS NULL
                AND (template.type = 'domain' OR template.type IS NULL)
        Nz AND reseller.login = %sz AND sys_user.login = %sr"rzr)r��
NO_PACKAGErR)
r0r5r{r9�queryr��	username_rhrkrOs
          rr|zPlesk._get_user_packagesSs�������0�$��6�6�6�E��,�,�U�]�O�D�D�F�F�
�
!��6�6�6�E��,�,�U�X�J�?�?�F�F��,�,�U�3�3�F�,2�	-�	-�(�I�w���0���G�%��0�0�r�r�h�H��*�*�I�U�*�K�K�C��
-�S�_��7�H�,�,�,�,��	-�	-rc�v�d|j�d�}|�|��D]}t|d���dS)z�
        Print packages (exclude reseller's)

        :param bool debug: Do produce debug output or don't
        :return: packages names

        zI
            SELECT name
            FROM psa.Templates WHERE owner_id = z AND type = 'domain';
        rN��ADMIN_IDr�rL)r0r5r�r�s    rrqzPlesk.list_packages�sW���15������
�+�+�E�2�2�	�	�D��$�q�'�N�N�N�N�	�	rrOr5c�H�d}|j�t|����}|r_d�dgt	|��z��}d|�d�}|�|t
|����}|r|dd}t|dkrdn|��dS)	z�
        Get reseller name from DB
        :param string uid: uid of user
        :param bool debug: Do produce debug output or don't
        :rtype: string
        :return: reseller name
        rzr~z%saGSELECT reseller.login
                FROM sys_users AS sys_user
                JOIN hosting AS hosting ON hosting.sys_user_id = sys_user.id
                JOIN domains AS domain ON hosting.dom_id = domain.id
                JOIN clients AS reseller ON domain.vendor_id = reseller.id
                WHERE sys_user.login IN (�)rr"N)r)rMrNr�r�r��tuplerL)r0rOr5rk�	usernames�format_stringsr�r�s        rr�zPlesk.get_reseller�s������O�-�-�c�#�h�h�7�7�	��
	(� �X�X�t�f�s�9�~�~�&=�>�>�N�>�
+9�>�>�>�E��,�,�U�E�)�4D�4D�E�E�F��
(�!�!�9�Q�<��
�H��'�'�b�b�X�6�6�6�6�6rc�l�|�|���}|D]\}}}t|�d|�����dS)z�
        Print info about user's packages (include resellers)

        :param bool debug: Do produce debug output or don't
        :return: pairs "uid package", where
        uid - unique id of user
        package - name of user's package

        r�r�Nr�)r0r5r�rOrhrs      rrfzPlesk.list_all�sY���'�'�e�'�4�4��!&�	&�	&��S�'�1��S�$�$�7�$�$�%�%�%�%�	&�	&rc�r�|�|���}|D]\}}}t|�d|�d|�����dS)aF
        Print info about user's packages (include resellers) and thouse resellers

        :param bool debug: Do produce debug output or don't
        :return: triples "uid,package,reseller", where
        uid - unique id of user
        package - name of user's package
        reseller - name of package's reseller
        r�r~Nr�)r0r5r�rOrhrks      rrxzPlesk.list_users�sa���'�'�e�'�4�4��(-�	1�	1�$�S�'�8��S�/�/�7�/�/�X�/�/�0�0�0�0�	1�	1rc��g}	|j�t|����}|D]8}|�||���}|�d�|D�����9nG#t
j$r}|rt|��Yd}~n"d}~wt$rtd��YnwxYw|D]}t|���dS)z�
        Print all packages for user's uid

        :param uid: user's unique id
        :param bool debug: Do produce debug output or don't
        :return: package name for user's uid

        )r5r9c��g|]
}|d��S)r�rr�s  rr�z+Plesk.list_user_package.<locals>.<listcomp>�s�� <� <� <�T��a�� <� <� <rNrH)	r)rMrNr|rBrrKrLrI)	r0rOr5rQ�namesr�r�rQrhs	         rrozPlesk.list_user_package�s����
	>��O�-�-�c�#�h�h�7�7�E��
>�
>���0�0�u�t�0�L�L����� <� <�V� <� <� <�=�=�=�=�
>��
�(�	�	�	��
��a��������������	'�	'�	'��%�&�&�&�&�&�	'���� �	�	�G��'�N�N�N�N�	�	s�'A'�'B+�6B�B+�*B+c��d|�d|j�d�}|�|��D]/}t|j�|d�����0dS)z�
        Print all users in package

        :param package: name of package
        :param bool debug: Do produce debug output or don't
        :return: user's uid
        a�
        SELECT t5.login
        FROM psa.Templates AS t1
        JOIN psa.PlansSubscriptions AS t2 ON t2.plan_id = t1.id
        JOIN psa.Subscriptions AS t3 ON t3.id = t2.subscription_id
        JOIN psa.domains AS t4 ON t4.id = t3.object_id
        JOIN psa.hosting AS t6 ON t6.dom_id = t4.id
        RIGHT JOIN psa.sys_users AS t5 ON t6.sys_user_id = t5.id
        WHERE t1.name = 'z' AND t1.owner_id = z! AND t1.type = 'domain';
        rN)r�r�rLr)rJ)r0rhr5r��logins     rrizPlesk.list_users_in_package�s|��	�"�	�	�8<�}�	�	�	���,�,�U�3�3�	5�	5�E��$�/�)�)�%��(�3�3�4�4�4�4�	5�	5rc��d|�d�}|�|��}t|��dkrdSt|dd��}d|�d|�d�}|�|��}|D]l}	|j�|d��}	tt
|	�����@#tj$r}
|rt|
��Yd}
~
�ed}
~
wwxYwdS)	z�
        Print info about users in resellers package

        :param package: package name
        :param reseller: name of package's reseller
        :param bool debug: Do produce debug output or don't
        :return: users uids

        z@SELECT id FROM psa.clients WHERE type = 'reseller' AND login = '�'r�Nra�
            SELECT t5.login
            FROM psa.Templates AS t1
            JOIN psa.PlansSubscriptions AS t2 ON t2.plan_id = t1.id
            JOIN psa.Subscriptions AS t3 ON t3.id = t2.subscription_id
            JOIN psa.domains AS t4 ON t4.id = t3.object_id
            JOIN psa.hosting AS t6 ON t6.dom_id = t4.id
            RIGHT JOIN psa.sys_users AS t5 ON t6.sys_user_id = t5.id
            WHERE t1.type = 'domain' AND t1.name = 'z' AND t1.owner_id = 'z';
        )	r�r�rNr)rJrLrUrrK)r0rhrkr5�reseller_query�reseller_idr�r�r��luidrQs           rrlz$Plesk.list_users_in_reseller_package�s$��l�^f�k�k�k���-�-�n�=�=���{���q� � ��F��+�a�.��+�,�,��	�6=�	�	�T_�	�	�	���(�(��/�/���	!�	!�D�
!���.�.�t�A�w�7�7��
�c�$�i�i� � � � ��	�,�
�
�
����!�H�H�H����������
����	!�	!s�/ B,�,C�;C�Cc��d|j�d�}|�|��D]4}|d}|ddkrdn|d}t|�d|�����5dS)	z�
        Print list of resellers packages

        :param bool debug: Do produce debug output or don't
        :return: pairs "reseller package", where
        package - package name
        reseller - package's reseller

        z�SELECT t2.login, t1.name FROM
        (SELECT name, owner_id, type FROM psa.Templates) AS t1
        JOIN psa.clients AS t2 ON t1.owner_id = t2.id
        WHERE t1.owner_id != z AND t1.type = 'domain';r�rr"�rootr�Nr�)r0r5r�r�rhrks      rrszPlesk.list_resellers_packagess���H�#�m�H�H�H���+�+�E�2�2�	+�	+�D��1�g�G�!%�a��G�!3�!3�v�v��a��H��X�)�)��)�)�*�*�*�*�	+�	+rrc���g}d}|�|��D]M}|d}|ddkrdn|d}|d}|�||t|��f���N|S)z�
        Return list of non-reseller packages with the plesk DB id
            [(reseller, package, plesk_id), (None, package, plesk_id)]
        z�SELECT t2.login, t1.name, t1.id FROM
        (SELECT id, name, owner_id, type FROM psa.Templates) AS t1
        JOIN psa.clients AS t2 ON t1.owner_id = t2.id
        WHERE t1.type = 'domain';r�rr"r��)r��appendrN)r0rLr�r�rhrk�_ids       r�list_domain_packages_with_idz"Plesk.list_domain_packages_with_id2s���
��%���+�+�E�2�2�	6�	6�D��1�g�G�!%�a��G�!3�!3�v�v��a��H��q�'�C��J�J��'�3�s�8�8�4�5�5�5�5��
r�
package_idc�P�d}|�||f��}|ddS)z8
        Return package name by the plesk DB id
        z7SELECT id, name, type FROM psa.Templates WHERE id = %s;rr��r�)r0r�r�r�s    r�$get_package_name_by_id_from_plesk_dbz*Plesk.get_package_name_by_id_from_plesk_dbCs/��J���&�&�u�z�m�<�<���A�w�q�z�r�package_namec�P�d}|�||f��}|ddS)z8
        Return package id by the plesk DB name
        z9SELECT id, name, type FROM psa.Templates WHERE name = %s;rr�)r0r�r�r�s    r�$get_package_id_by_name_from_plesk_dbz*Plesk.get_package_id_by_name_from_plesk_dbKs/��L���&�&�u�|�o�>�>���A�w�q�z�rc��|dkrd}tjd|��sdSd|�d|j�d�}|�|��D]}t	|d���dS)	z�
        Print list reseller's packages

        :param reseller: name of reseller
        :param bool debug: Do produce debug output or don't
        :return: packages names

        r�r"z^[\w_]*$Nz�SELECT t1.name FROM
        (SELECT name, owner_id, type FROM psa.Templates) as t1
        JOIN psa.clients as t2 ON t1.owner_id = t2.id AND t2.login = 'z6'
        WHERE t1.type = 'domain' AND t1.owner_id != �;r)r�r�r�r�rL)r0rkr5r�r�s     rrvzPlesk.list_reseller_packagesSs����v����H��x��X�.�.�	��4�H�GO�H�H�6:�]�H�H�H���+�+�E�2�2�	�	�D��$�q�'�N�N�N�N�	�	rc��dgS)Nr"rr4s  rr6zPlesk.list_adminsgs
���y�rr�)FNNr�)rrrrr�r�r�r)r1r�r|rqrU�boolr�rfrxrorirlrsrrrrNr�r�r�rvr6r�r�s@rrr:s����������(�J��H��J��J�0�0�0�0�0�	4�	4�	4�	4�3-�3-�3-�3-�j����"7�7��7�D�7�7�7�7�.&�&�&�&�1�1�1�1�����25�5�5�5�.!!�!!�!!�!!�F+�+�+�+�&�d�5��#���S�9P�3Q�.R�����"�s��s�����������������(�������rrc��eZdZd�ZdS)rc�p�|rtj�d��tjd��dS)Nz"Doesn't support InterWorx anymore
r)r<r=r>r�r?s   rrAzInterWorx._warningls3���	D��J���B�C�C�C��������rN�rrrrArrrrrks#����������rrc��eZdZd�ZdS)r#c�&�t|�d����)Nz% wasn't implemented for Unknown panel��NotImplementedErrorr?s   rrAzUnknown._warningss��!�[�"W�"W�"W�X�X�XrNr�rrrr#r#rs(������Y�Y�Y�Y�Yrr#c��eZdZd�ZdS)rc�&�t|�d����)Nz' wasn't implemented for HostingNG panelr�r?s   rrAzHostingNG._warningxs��!�[�"Y�"Y�"Y�Z�Z�ZrNr�rrrrrws(������[�[�[�[�[rr)%rmr�r�r<rCrN�typingrrr�cldetectlibr�clcommonrr�clcommon.clprocr�clcommon.utilsr	�clcommon.cpapi.pluginsr
rrr
r�r�rr$r&r"rrWrrrr#rrrr�<module>r�s����
�
�
�	�	�	�	�	�	�	�	�
�
�
�
�
�
�
�
�����(�(�(�(�(�(�(�(�(�(�����%�%�%�%�%�%�%�%�#�#�#�#�#�#�������I�I�I�I�I�I�I�I�I�I�I�I���	�	�	�	�	�i�	�	�	����"w4�w4�w4�w4�w4�w4�w4�w4�tC6�C6�C6�C6�C6�\�C6�C6�C6�L@�@�@�@�@�,�@�@�@�D*�*�*�*�*�Y�*�*�*�
|�|�|�|�|��|�|�|�~n�n�n�n�n�L�n�n�n�b	���������Y�Y�Y�Y�Y�l�Y�Y�Y�
[�[�[�[�[��[�[�[�[�[r