HEX
Server: Apache
System: Linux www3.pit.tblive.com 5.14.0-687.38.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Aug 12 17:19:12 EDT 2026 x86_64
User: awaldron (1020)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/cloudlinux/venv/lib64/python3.11/site-packages/cllicense/__pycache__/license.cpython-311.pyc
�

�T�+�U�	�@�ddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
mZddlm
Z
mZmZddlZddlmZmZddlmZdd	lmZejd
��ZdZdZd
efd�Z			ddeedeedeed
dfd�Z ded
efd�Z!Gd�d��Z"dS)�N)�JSONDecodeError)�Path)�PIPE�STDOUT�run)�Dict�Optional�Union)�print_dictionary�replace_params)�CloudlinuxLicenseLib�)�parse_cloudlinux_packages_optszcloudlinux-licensez/usr/sbin/clnreg_ksz--activationkey=-�returnc���	ttdgttd���}n#tt
f$rYdSwxYwt���|jpdvS)a�Return True if the installed clnreg_ks advertises the --activationkey=- sentinel.

    Probed via `clnreg_ks --help` (which forwards to `rhnreg_ks --help`); the literal
    `--activationkey=-` is a locale-stable option token (translators preserve option
    syntax), so the check is robust. stderr is merged into stdout in case the help text
    is emitted there. Best-effort: any failure to probe is treated as "unsupported" and
    the caller falls back to the legacy argv form.
    z--helpF)�stdout�stderr�check�)	r�	CLNREG_KSrr�OSError�
ValueError�ACTIVATIONKEY_STDIN�encoder)�results �py/cllicense/license.py�_clnreg_supports_stdin_keyr#si����i��*�4��e�T�T�T�����Z� �����u�u������%�%�'�'�F�M�,@�S�A�As�$'�<�<�error�details�contextc���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.
    �	timestampNrr�successrrr )�time�json�dump�sysr�exit)rrr �output�	exit_codes     r�_print_as_json_and_exitr+3s����4�9�;�;�
'�F��� ��x���	�	�$��x���	���#��y����#��y���I�f�c�j�!�!�!��H�Y�����r�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�	_beautifyr2RsM���F�)�/�/�1�1�*�*���u��)�u�)�)��)�)�)�)����Mrc�|�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_stager6r5)�_is_json�_optsr
�_license_lib�CONFIG_PATH�exists�configparser�ConfigParser�read�bool�
cln_subdomain�ALLOWED_CLN_SUBDOMAINS)�self�configs  r�__init__zCloudlinuxLicense.__init__is�����
���
�0�2�2�����"�"�$�$�	'�!�.�0�0�F��K�K��(�)�)�)�26�v�i�7H��7T�2U�2U�!`���[`�D���!&�D����T�%@�@�@�!&�D����A�@rc�$�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)rE�argvs  rrzCloudlinuxLicense.runxs���!�D�(��
��%�%�d�+�+��
��:�e��	��M�M�O�O�O��M�M�O�O�O�O�
�Z��
$�	��O�O������M�M�O�O�O��qrc��|j���rd}nd}dtj��|d�}t|d��dS)z#
        Run 'get' command
        �valid�invalidr#)rr"�licenseTN)r<�get_license_statusr$r)rE�license_status�result_datas   rrMzCloudlinuxLicense._get_run�sU����/�/�1�1�	'�$�N�N�'�N�!*�����Q_�`�`����d�+�+�+�+�+rc��|jdr|j���|jd}|r|j�|��dSdS)z#
        Run 'set' command
        z--ipz--keyN)r;r<�!register_and_update_license_by_ip�"register_and_update_license_by_key)rE�keys  rrLzCloudlinuxLicense._set_run�sg���:�f��	B���?�?�A�A�A��j��!���	F���@�@��E�E�E�E�E�	F�	Frc�~�t||j��\}}|s"|�t|����|S)z%
        Parse CLI arguments
        )rr:�_error_and_exitr)rErO�status�datas    rrKzCloudlinuxLicense._parse_args�sB��6�d�D�M�J�J�����	7�� � ���!5�!5�6�6�6��rrc�~�|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
        r"Trr zError: z [�]N)
r:�updater$r�print�str�get�KeyErrorr'r()rE�message�
error_code�es    rr\z!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 �)rZ�type�
validationzVInput data validation failed: 
 %(error_text)sPlease fix form errors and submit again.�
error_text�errors)r rfzsWe 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�postrC�RequestExceptionrc�loggerr�status_code�textrdr2�RuntimeError)rErFrj�responserh�
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�`�|���}d|j�d�}t��r8ttdt
d|g|dz���dd���}n8td	tj	�
��ttdd|d|gdd���}|j
d
kr+tdd�|j
���d���tddgdd���}|j
d
kr-tdd�|j
���d���dSt��dS)Nzhttps://xmlrpc.z.cloudlinux.com/XMLRPCz--forcez--serverUrlr/TF)�input�capture_outputrz�Warning: installed clnreg_ks lacks the --activationkey=- stdin channel; passing the activation key on the command line, which is less secure. Upgrade rhn-client-tools to pass the key via stdin.)�filez--activationkey)r�rrzfWe 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)r}rCrrrrrrbr'r�
returncoder+�join�args)rErZ�
server_urlrs    rrNzCloudlinuxLicense._get_trial�s����m�m�o�o��Q�t�'9�Q�Q�Q�
�%�'�'�	�
��I�':�M�:�V��T�z�)�)�+�+�#��	���F�F�
�F��Z�	
�
�
�
���I�'8�#�}�j�Y�#�����F�
���!�!�#�_��H�H�V�[�)�)�_�_�_�
�
�
��)�+=�>�t�[`�a�a�a�����!�!�#�_��H�H�V�[�)�)�_�_�_�
�
�
�
�
�

$�%�%�%�%�%r)r)rN)�__name__�
__module__�__qualname__�__doc__rr=�	frozensetrDrGrrMrLrKr\rcr}rN�rrr4r4as����������$�>�?�?�K�&�Y��}�'=�>�>��
'�
'�
'���� ,�,�,�
F�
F�
F����
�
�
�
�59�#�59�59�59�59�n/&�/&�/&�/&�/&�/&rr4)NNN)#r?r%�loggingr'r$r�pathlibr�
subprocessrrr�typingrr	r
rt�	cli_utilsrr�	cllicenser
�cl_license_arg_parser�	getLoggerrwrrrBrrc�dictr+r2r4r�rr�<module>r�s���������������
�
�
�
����� � � � � � �������(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�����6�6�6�6�6�6�6�6�*�*�*�*�*�*�@�@�@�@�@�@�	��	�/�	0�	0��!�	�*��
B�D�
B�
B�
B�
B�" �!�"����C�=��
�c�]���d�^��
�	����>���#�����&�&�&�&�&�&�&�&�&�&r