????

Your IP : 216.73.217.84


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

�

��F�6
�	�$�ddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
ddlZddlmZmZddlmZdd	lmZejd
��Z			ddeedeed
eeddfd�Zdedefd�ZGd�d��ZdS)�N)�JSONDecodeError)�Path)�run)�Dict�Optional�Union)�print_dictionary�replace_params)�CloudlinuxLicenseLib�)�parse_cloudlinux_packages_optszcloudlinux-license�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'<sM���F�)�/�/�1�1�*�*���u��)�u�)�)��)�)�)�)����Mr c�|�eZdZdZed��Zeddh��Zd�Zd�Z	d�Z
d�Zd	�Zdd�Z
defd
�Zdd�ZdS)�CloudlinuxLicensez+
    Class to check Cloudlinux license
    z%/etc/lve-utils/cloudlinux-license.ini�cln�cln-stagingc�Z�d|_i|_t��|_|j���rRt
j��}|�|j��t|dd��rdnd|_
nd|_
|j
|jvr	d|_
dSdS)NF�DEFAULT�is_stager+r*)�_is_json�_optsr�_license_lib�CONFIG_PATH�exists�configparser�ConfigParser�read�bool�
cln_subdomain�ALLOWED_CLN_SUBDOMAINS)�self�configs  r�__init__zCloudlinuxLicense.__init__Ss�����
���
�0�2�2�����"�"�$�$�	'�!�.�0�0�F��K�K��(�)�)�)�26�v�i�7H��7T�2U�2U�!`���[`�D���!&�D����T�%@�@�@�!&�D����A�@r c�$�d|v|_|�|��|_|jdr)|���|���n6|jdr|���n|���dS)z$
        Run command action
        z--json�set�	get_trialr)r/�_parse_argsr0�_set_run�_get_run�
_get_trial)r:�argvs  rrzCloudlinuxLicense.runbs���!�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)r1�get_license_statusrr	)r:�license_status�result_datas   rrBzCloudlinuxLicense._get_runrsU����/�/�1�1�	'�$�N�N�'�N�!*�����Q_�`�`����d�+�+�+�+�+r c��|jdr|j���|jd}|r|j�|��dSdS)z#
        Run 'set' command
        z--ipz--keyN)r0r1�!register_and_update_license_by_ip�"register_and_update_license_by_key)r:�keys  rrAzCloudlinuxLicense._set_runsg���:�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
)r:rD�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)r:�message�
error_code�es    rrQz!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�x�	tj|jd��}|�dd��}n,#t$rtd|jd���YnwxYw	t
jd|j�d|�d�|d	�
��}n:#tj	$r(}tdt|�����Yd}~nd}~wwxYw	|���}nP#t$rCt�d|j
|j��td
d|j
�d����YnwxYwd|vr|dS|�d��dkr&tddt!|d��i���|�d���t|d��td��t#d���)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:Trial license API returned non-JSON response (HTTP %s): %sz�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.z(Server returned non-JSON response (HTTP �)rO�type�
validationzVInput data validation failed: 
 %(error_text)sPlease fix form errors and submit again.�
error_text�errors)rr[zsWe 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�loadsr0�poprr�requests�postr8�RequestExceptionrX�loggerr�status_code�textrYr'�RuntimeError)r:r;r_�responser]�
response_jsons      r�_get_keyzCloudlinuxLicense._get_key�sW��	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���		�		�		��L�L�L��$�h�m�
�
�
�
$�K�Z�8�CW�Z�Z�Z�
�
�
�
�
�
�		�����M�!�!� ��'�'����V�$�$��4�4�#�;�%�y��x�1H�'I�'I�J�
�
�
�
����V�$�$�,�#�M�)�$<�=�=�=�	 �
G�	
�	
�	
��7�8�8�8s:�58�&A!� A!�%#B	�	C�B;�;C�C�A
D&�%D&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)rrrr8�
returncoder�join�args)r:rOrs   rrCzCloudlinuxLicense._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__rr2�	frozensetr9r<rrBrAr@rQrXrrrC�r rr)r)Ks����������$�>�?�?�K�&�Y��}�'=�>�>��
'�
'�
'���� ,�,�,�
F�
F�
F����
�
�
�
�59�#�59�59�59�59�n&�&�&�&�&�&r r))NNN)r4r�loggingrrr�pathlibr�
subprocessr�typingrrrri�	cli_utilsr	r
�	cllicenser�cl_license_arg_parser
�	getLoggerrlrX�dictrr'r)r�r r�<module>r�s���������������
�
�
�
����� � � � � � �������������(�(�(�(�(�(�(�(�(�(�����6�6�6�6�6�6�6�6�*�*�*�*�*�*�@�@�@�@�@�@�	��	�/�	0�	0�� �!�"����C�=��
�c�]���d�^��
�	����>���#�����m&�m&�m&�m&�m&�m&�m&�m&�m&�m&r