%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/clcommon/lib/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib/python3.7/site-packages/clcommon/lib/__pycache__/cledition.cpython-37.pyc

B

`�1b�*�@sxddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
ddlmZmZddlmZmZmZddlmZdd	lmZd
ZdZdZd
ZGdd�de�ZGdd�de�Zeejj eej!j eej"j iZ#Gdd�d�Z$d-dd�Z%d.dd�Z&d/dd�Z'ed�dd�Z(dd �Z)d!d"�Z*d#d$�Z+d%d&�Z,ee
e-e
e-fd�d'd(�Z.e/d�d)d*�Z0e/d�d+d,�Z1dS)0�N)�Enum)�wraps)�
exceptions)�AnyStr�Tuple�Optional)�CLN_JWT_TOKEN_PATH�CL_EDITION_FILE_FOR_USERS)�read_jwt�
decode_jwt�jwt_token_check)�FormattedException)�	in_cagefsz/etc/cloudlinux-edition-solozCloudLinux OS Shared ProzCloudLinux OS SharedzCloudLinux OS Soloc@seZdZdZdZdZdZdS)�SupportedEditionsz-
    Keeps supported CloudLinux editions
    ZsoloZsharedZ
shared_proN)�__name__�
__module__�__qualname__�__doc__�SOLO�SHARED�
SHARED_PRO�rr�G/opt/alt/python37/lib/python3.7/site-packages/clcommon/lib/cledition.pyr src@seZdZdd�ZdS)�CLEditionDetectionErrorcKst�|||d��dS)N)�message�context)r
�__init__)�selfrrrrrr+sz CLEditionDetectionError.__init__N)rrrrrrrrr*src@s4eZdZed
dd��Zedd��Zeddd	��ZdS)�
CLEditionsNTc
Cs�|dkrtt�}yt||d�}Wn8tjk
rX}ztdt�d|����Wdd}~XYnXy|dStk
r�|�d�}|dkr�tdt�d���|r�tj	j
Stjj
SXdS)z�
        Note: be careful when modifying this method.
        Passing token in is used in X-Ray,
        ask @dkavchuk or someone else from C-Projects team for details
        :param token:
        :param verify_exp:
        :return:
        N)�
verify_expz)Unable to detect edition from jwt token: z-. Please, make sure it is not broken, error: �edition�cl_pluszL. Please, make sure it is not broken, error: not enough fields for detection)r
rrrZ
PyJWTErrorr�KeyError�getrr�valuer)�tokenr�jwt�er!rrr�get_from_jwt;s
&
zCLEditions.get_from_jwtcCsftjdd|gtjtjdd�}|��\}}|jdkr>d|kr>dS|jdkrbtd|�d	|�d
|����dS)NZrpmz-qT)�stdout�stderr�textrzis not installedFzUnable to check is package z is installed, reason: z, )�
subprocess�Popen�PIPEZcommunicate�
returncoder)Zpackage_nameZprocess�out�errrrr�is_package_installedWs
zCLEditions.is_package_installedFcCs�|r|rtd��|sVtj�t�rVy|j||d�}Wntk
rLt�}YnX|rV|St�rbt�S|s�tj�t	�rzt
jjSt
j
jSdS)a
        1. Try to detect edition from jwt token
           if edition field is in token -> return edition
           if edition field is not present -> recheck via cl_plus flag
           if token is broken -> raise error about it
        2. Try to detect from file
           if edition is in file -> return edition
           if file is broken -> raise about it
           if file is missed -> check if meta package is present
           Detection from file may be switched off using skip_marker_check
        In case there is no token with correct edition,
        no file we consider edition as regular CL.
        Note: be careful when modifying this method.
        It is used in X-Ray, ask @dkavchuk or someone else from C-Projects team
        for details
        zOUnable to detect edition: neither jwt token check, no file marker check enabled)r%rN)r�os�path�isfilerr(�PermissionError�user_cl_editionr�CL_EDITION_FILE_MARKERrrr$r)�cls�skip_jwt_check�skip_marker_checkZraw_jwtrr rrr�get_cl_editiones zCLEditions.get_cl_edition)NT)FFNT)rrr�staticmethodr(r2�classmethodr<rrrrr9srTFcCs$tj|||d�}|dk	o"|tjjkS)aU
    Allow skip_jwt_check ONLY if it not critical when license is not valid
    Use skip_marker_check=True when validity of license is critical
     and fallback to file is not applicable
    Note: be careful when modifying this method.
    It is used in X-Ray and SSA,
    ask @dkavchuk or someone else from C-Projects team for details
    )r:r;rN)rr<rrr$)r:r;rr rrr�is_cl_solo_edition�s

r?cCs$tj|||d�}|dk	o"|tjjkS)z�
    Allow skip_jwt_check ONLY if it not critical when license is not valid
    Use skip_marker_check=True when validity of license is critical
     and fallback to file is not applicable
    )r:r;rN)rr<rrr$)r:r;rr rrr�is_cl_shared_edition�s
r@cCs$tj|||d�}|dk	o"|tjjkS)z�
    Allow skip_jwt_check ONLY if it not critical when license is not valid
    Use skip_marker_check=True when validity of license is critical
     and fallback to file is not applicable
    )r:r;rN)rr<rrr$)r:r;rr rrr�is_cl_shared_pro_edition�s
	rA)�returnc	Cs|ytdd�rtSWntk
r&tSXt�\}}}d|krltj�t�sNt	�rlt
td��}|���
�SQRX|rttStSdS)z�
    Function returns current edition of CL:
    - CloudLinux OS Shared
    - CloudLinux OS Shared Pro
    - CloudLinux OS Solo
    - Error string
    T)r:z
read error�rN)r?�SOLO_EDITION_HUMAN_READABLEr�SHARED_EDITION_HUMAN_READABLErr3r4r5rr�openr	�read�strip�!SHARED_PRO_EDITION_HUMAN_READABLE)Zsuccess_flagZ
error_message�_�frrr�get_cl_edition_readable�s	
rLcCstd�dS)zJust print skip messagezpCloudLinux Solo edition detected! 
Command is skipped, because it is unsupported and unneeded on current editionN)�printrrrr�print_skip_message_on_solo�srNc
Cs^ytdd�rt�t�d�Wn:tk
rX}ztd|���t�d�Wdd}~XYnXdS)NT)r:rzError: �)r?rN�sys�exitrrM)r'rrr�skip_on_cl_solo�s
rRcst���fdd��}|S)Ncs"tdd�rt�dS�||�SdS)NT)r:)r?rN)�args�kwargs)rKrr�inner�s
z$lve_supported_or_exit.<locals>.inner)r)rKrUr)rKr�lve_supported_or_exit�srVc	Cs<tj�t�r8ttd��}|����}WdQRXt�|�SdS)z�This function is used as workaround for users to be able to get CL Edition.
    Crontab will write to CL_EDITION_FILE_FOR_USERS, output of cldetect --detect-edition command with 0644 permission.
    rCN)	r3r4�existsr	rFrGrH�"HUMAN_READABLE_TOKEN_EDITION_PAIRSr#)rKr rrrr7�s

r7c
Cs�yjd}d}t��}t|�� }|�d|�d�|���WdQRX|�|d��d�}|�|d��d�}||fStttj	fk
r�YnXd	S)
zM
    Detect system name and version
    :return: tuple (os_name, os_ver)
    z/etc/os-release�top�[z]
N�NAME�"Z
VERSION_ID)NN)
�configparserZConfigParserrFZread_stringrGr#rH�OSError�IOError�Error)Zos_release_filenameZsection_nameZconfig�stream�os_nameZos_verrrr�get_os_version
s
$rccCst�\}}|dkS)zL
    Detertmines is this system Ubuntu
    :return: bool flag is_ubuntu
    ZUbuntu)rc)rbrJrrr�	is_ubuntu$s
rdcCs0d}tj�d�r,tjdddtjtjd�dk}|S)z]
    Determines if secure boot is turned on
    :return: bool flag is_secureboot_enabled
    Fz/sys/firmware/efiz!mokutil --sb-state | grep enabledTz	/bin/bash)�shell�
executabler)r*r)r3r4rWr,ZcallZDEVNULL)Zenabledrrr�is_secureboot_enabled-srg)TFT)FFT)FFT)2r]r3rPr,�enumr�	functoolsrr&r�typingrrrZclcommon.lib.constsrr	Zclcommon.lib.jwt_tokenr
rrZclcommon.clexceptionr
Zclcommon.clcagefsrr8rIrErDrrrr$rrrXrr?r@rArLrNrRrVr7�strrc�boolrdrgrrrr�<module>
sD
	Y


	

Zerion Mini Shell 1.0