ok

Mini Shell

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

B

E!wd�1�@s�ddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
ddlmZmZddlmZmZmZddlmZdd	lmZd
ZdZdZd
ZdZdZGdd�de�ZGdd�de�Z eej!j"eej#j"eej$j"eej%j"iZ&Gdd�d�Z'd5dd�Z(d6dd�Z)d7dd�Z*d8dd�Z+ed �d!d"�Z,d#d$�Z-d%d&�Z.d'd(�Z/e/Z0d)d*�Z1d+d,�Z2ee
e3e
e3fd �d-d.�Z4e5d �d/d0�Z6e5d �d1d2�Z7e5d �d3d4�Z8dS)9�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-soloz/etc/cloudlinux-edition-adminzCloudLinux OS Shared ProzCloudLinux OS SharedzCloudLinux OS SolozCloudLinux OS Adminc@s eZdZdZdZdZdZdZdS)�SupportedEditionsz-
    Keeps supported CloudLinux editions
    ZsoloZsharedZ
shared_proZadminN)�__name__�
__module__�__qualname__�__doc__�SOLO�SHARED�
SHARED_PRO�ADMIN�rr�G/opt/alt/python37/lib/python3.7/site-packages/clcommon/lib/cledition.pyr"s
rc@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_installed[s
zCLEditions.is_package_installedFcCs�|r|rtd��|sVtj�t�rVy|j||d�}Wntk
rLt�}YnX|rV|St�rbt�S|s�tj�t	�rzt
jjStj�t
�r�t
jjSt�p�t
jj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&r N)r�os�path�isfilerr)�PermissionError�user_cl_editionr�CL_SOLO_EDITION_FILE_MARKERrrr%�CL_ADMIN_EDITION_FILE_MARKERrr)�cls�skip_jwt_check�skip_marker_checkZraw_jwtr r!rrr�get_cl_editionis$zCLEditions.get_cl_edition)NT)FFNT)rrr�staticmethodr)r3�classmethodr>rrrrr=s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=r N)rr>rrr%)r<r=r r!rrr�is_cl_solo_edition�s

rAcCs$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=r N)rr>rrr%)r<r=r r!rrr�is_cl_shared_edition�s
rBcCs$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=r N)rr>rrr%)r<r=r r!rrr�is_cl_shared_pro_edition�s
	rCcCs$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=r N)rr>rrr%)r<r=r r!rrr�is_cl_admin_edition�s
	rD)�returnc	Cs�y tdd�rtStdd�rtSWntk
r4tSXt�\}}}d|krztj�	t
�s\t�rztt
d��}|����SQRX|r�tStSdS)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)rA�SOLO_EDITION_HUMAN_READABLErD�ADMIN_EDITION_HUMAN_READABLEr�SHARED_EDITION_HUMAN_READABLErr4r5r6rr�openr	�read�strip�!SHARED_PRO_EDITION_HUMAN_READABLE)Zsuccess_flagZ
error_message�_�frrr�get_cl_edition_readable�s	

rPcCs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�srRcCstd�dS)zJust print skip messageznContainer environment detected! 
Command is skipped, because it is unsupported and unneeded on current editionN)rQrrrr�print_skip_message_in_container�srSc
Csty4tdd�rt�t�d�t�r2t�t�d�Wn:tk
rn}ztd|���t�d�Wdd}~XYnXdS)NT)r<rzError: �)rArR�sys�exit�is_containerrSrrQ)r(rrr�skip_on_cl_solos

rXcst���fdd��}|S)Ncs(tdd�st�rt�dS�||�SdS)NT)r<)rArWrR)�args�kwargs)rOrr�inners

z$lve_supported_or_exit.<locals>.inner)r)rOr[r)rOr�lve_supported_or_exits	r\c	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.
    rFN)	r4r5�existsr	rJrKrL�"HUMAN_READABLE_TOKEN_EDITION_PAIRSr$)rOr!rrrr8)s

r8c
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ConfigParserrJZread_stringrKr$rL�OSError�IOError�Error)Zos_release_filenameZsection_nameZconfig�stream�os_nameZos_verrrr�get_os_version5s
$ricCst�\}}|dkS)zL
    Detertmines is this system Ubuntu
    :return: bool flag is_ubuntu
    ZUbuntu)ri)rhrNrrr�	is_ubuntuOs
rjcCstj�d�S)z<
    Determines is this system running inside container
    z/etc/cloudlinux-container)r4r5r]rrrrrWXsrWcCs0d}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)r4r5r]r-ZcallZDEVNULL)Zenabledrrr�is_secureboot_enabled_srm)TFT)FFT)FFT)FFT)9rcr4rUr-�enumr�	functoolsrr'r�typingrrrZclcommon.lib.constsrr	Zclcommon.lib.jwt_tokenr
rrZclcommon.clexceptionr
Zclcommon.clcagefsrr9r:rMrIrGrHrrrr%rrrr^rrArBrCrDrPrRrSrXZskip_without_lver\r8�strri�boolrjrWrmrrrr�<module>
sV	[




	

Zerion Mini Shell 1.0