AlkantarClanX12

Your IP : 3.15.228.162


Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/cllicense/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/cllicense/__pycache__/license.cpython-311.pyc

�

".g)�	��ddlZddlZddlZddlZddlmZddlmZddlmZddl	m
Z
mZmZddl
Z
ddlmZmZddlmZdd	lmZ			dd
eedeedeed
dfd�Zded
efd�ZGd�d��ZdS)�N)�JSONDecodeError)�Path)�run)�Dict�Optional�Union)�print_dictionary�replace_params)�CloudlinuxLicenseLib�)�parse_cloudlinux_packages_opts�error�details�context�returnc���dtj��i}|�||d<d}nd|d<d}|�||d<|�||d<tj|tj��tj|��dS)	a�
    This function makes UI-specific JSON, prints it and exits from the program. It sets "timestamp".
    And if @param error is specified, then field "result" will be filled with this parameter and exit code will be 1.
    Otherwise "result" will be filled with "success" and exit code will be 0.
    @param details: if it's specified, then field "details" will be will be filled with this parameter.
    @param context: if it's specified, then field "context" will be filled with this parameter.
    �	timestampN�resultr�successrrr)�time�json�dump�sys�stdout�exit)rrr�output�	exit_codes     �py/cllicense/license.py�_print_as_json_and_exitrs����4�9�;�;�
'�F��� ��x���	�	�$��x���	���#��y����#��y���I�f�c�j�!�!�!��H�Y�������validation_errorsc�V�d}|���D]\}}|d|�d|�d�z
}�|S)z�
    This function converts dict of validation errors in a more human-readable presentation as str.
    Ends each line with '
'.

    @param validation_errors: dict of validation errors
    @return: str
    �z- z: �
)�items)r!r�fieldrs    r�	_beautifyr'9sM���F�)�/�/�1�1�*�*���u��)�u�)�)��)�)�)�)����Mr c�b�eZdZdZed��Zd�Zd�Zd�Zd�Z	d�Z
dd	�Zd
efd�Z
dd
�ZdS)�CloudlinuxLicensez+
    Class to check Cloudlinux license
    z%/etc/lve-utils/cloudlinux-license.inic�.�d|_i|_t��|_|j���rSt
j��}|�|j��t|dd��rdnd|_
dSd|_
dS)NF�DEFAULT�is_stagezcln-staging�cln)�_is_json�_optsr�_license_lib�CONFIG_PATH�exists�configparser�ConfigParser�read�bool�
cln_subdomain)�self�configs  r�__init__zCloudlinuxLicense.__init__Os�����
���
�0�2�2�����"�"�$�$�	'�!�.�0�0�F��K�K��(�)�)�)�26�v�i�7H��7T�2U�2U�!`���[`�D����!&�D���r c�$�d|v|_|�|��|_|jdr)|���|���n6|jdr|���n|���dS)z$
        Run command action
        z--json�set�	get_trialr)r.�_parse_argsr/�_set_run�_get_run�
_get_trial)r8�argvs  rrzCloudlinuxLicense.run[s���!�D�(��
��%�%�d�+�+��
��:�e��	��M�M�O�O�O��M�M�O�O�O�O�
�Z��
$�	��O�O������M�M�O�O�O��qr c��|j���rd}nd}dtj��|d�}t|d��dS)z#
        Run 'get' command
        �valid�invalidr)rr�licenseTN)r0�get_license_statusrr	)r8�license_status�result_datas   rr@zCloudlinuxLicense._get_runksU����/�/�1�1�	'�$�N�N�'�N�!*�����Q_�`�`����d�+�+�+�+�+r c��|jdr|j���|jd}|r|j�|��dSdS)z#
        Run 'set' command
        z--ipz--keyN)r/r0�!register_and_update_license_by_ip�"register_and_update_license_by_key)r8�keys  rr?zCloudlinuxLicense._set_runxsg���:�f��	B���?�?�A�A�A��j��!���	F���@�@��E�E�E�E�E�	F�	Fr c�~�t||j��\}}|s"|�t|����|S)z%
        Parse CLI arguments
        )r
r.�_error_and_exitr
)r8rB�status�datas    rr>zCloudlinuxLicense._parse_args�sB��6�d�D�M�J�J�����	7�� � ���!5�!5�6�6�6��r rc�~�|jr9|�dtj��i��t|d��nh	t	t|d��|�di��z��n-#t$r }t	d|�d|�d���Yd}~nd}~wwxYwtj	|��dS)	z�
        Print error and exit
        :param message dict: Dictionary with keys "result" as string and optional "context" as dict
        rTrrzError: z [�]N)
r.�updaterr	�print�str�get�KeyErrorrr)r8�message�
error_code�es    rrOz!CloudlinuxLicense._error_and_exit�s���
�=�	1��N�N�K�����5�6�6�6��W�d�+�+�+�+�
1��c�'�(�+�,�,�w�{�{�9�b�/I�/I�I�J�J�J�J���
1�
1�
1��/��/�/�W�/�/�/�0�0�0�0�0�0�0�0�����
1�����������s�9A<�<
B&�B!�!B&rc�$�	tj|jd��}|�dd��}n,#t$rtd|jd���YnwxYw	t
jd|j�d|�d�|d	�
��}n:#tj	$r(}tdt|�����Yd}~nd}~wwxYw	|���}n&#t$rtd|j���YnwxYwd
|vr|d
S|�d��dkr&tddt|d��i���|�d���t|d��td��td���)Nz--config�editionzCL-SolozInput config is not valid JSON.)rzhttps://z.cloudlinux.com/wapi/z/trial�)r�timeoutz�We tried to get a trial license, but were unable to connect to the server application. Please, try again later or contact our support for help.z�We tried to get a trial license, but something went wrong on the server side. Please, try again later or contact our support for help.rM�type�
validationzVInput data validation failed: 
 %(error_text)sPlease fix form errors and submit again.�
error_text�errors)rrYzsWe tried to get a trial license, but something went wrong. Please, try again later or contact our support for help.zlicense key request failed)r�loadsr/�poprr�requests�postr7�RequestExceptionrV�textrWr'�RuntimeError)r8r9r]�responser[�
response_jsons      r�_get_keyzCloudlinuxLicense._get_key�s&��	g��Z��
�:� 6�7�7�F��j�j��I�6�6�G�G���	g�	g�	g�#�$E�t�z�Zd�Oe�f�f�f�f�f�f�	g����	��}�S�4�-�S�S�G�S�S�S������H�H��
�(�	�	�	�#�K��A���
�
�
�
�
�
�
�
�
�����	����	�$�M�M�O�O�M�M���	�	�	�#�K� �
�
�
�
�
�
�
�	�����M�!�!� ��'�'����V�$�$��4�4�#�;�%�y��x�1H�'I�'I�J�
�
�
�
����V�$�$�,�#�M�)�$<�=�=�=�	 �
G�	
�	
�	
��7�8�8�8s9�58�&A!� A!�%#B	�	C�B;�;C�C� C<�;C<Nc
��|���}tddd|dd|j�d�gdd�	��}|jd
kr+t	dd�|j���d
���tddgdd�	��}|jd
kr-t	dd�|j���d
���dSt	��dS)N�	clnreg_ksz--forcez--activationkeyz--serverUrlzhttps://xmlrpc.z.cloudlinux.com/XMLRPCTF)�capture_output�checkrzfWe created a trial license, but were unable to register the server. Please, try to run this command: `� z3` a little bit later. Contact our support for help.z/usr/bin/cldetectz--update-license)rmrr7�
returncoder�join�args)r8rMrs   rrAzCloudlinuxLicense._get_trial�s ���m�m�o�o�����!���P�D�$6�P�P�P�

� ��
�
�
�����!�!�#�_��H�H�V�[�)�)�_�_�_�
�
�
��)�+=�>�t�[`�a�a�a�����!�!�#�_��H�H�V�[�)�)�_�_�_�
�
�
�
�
�

$�%�%�%�%�%r )r)rN)�__name__�
__module__�__qualname__�__doc__rr1r:rr@r?r>rOrVrmrA�r rr)r)Hs����������$�>�?�?�K�
'�
'�
'���� ,�,�,�
F�
F�
F����
�
�
�
�19�#�19�19�19�19�f&�&�&�&�&�&r r))NNN)r3rrrr�pathlibr�
subprocessr�typingrrrrf�	cli_utilsr	r
�	cllicenser�cl_license_arg_parser
rV�dictrr'r)rzr r�<module>r�sy����������
�
�
�
����� � � � � � �������������(�(�(�(�(�(�(�(�(�(�����6�6�6�6�6�6�6�6�*�*�*�*�*�*�@�@�@�@�@�@� �!�"����C�=��
�c�]���d�^��
�	����>���#�����e&�e&�e&�e&�e&�e&�e&�e&�e&�e&r