Ѡg0ddlZddlZddlZddlmZddlmZddlmZddl m Z m Z ddl m Z mZmZddlmZddlmZdd lmZmZmZd Zd Zd Zd ZdZdZGddeZGddeZeej j!eej"j!eej#j!eej$j!iZ%GddZ&d$dZ'd%dZ( d%dZ)dZ* d%dZ+defdZ,dZ-d Z.d!Z/d"Z0de1fd#Z2dS)&N)Enum)AnyStr) exceptions)CLN_JWT_TOKEN_PATHCL_EDITION_FILE_FOR_USERS)read_jwt decode_jwtjwt_token_check)FormattedException) in_cagefs)get_os_version is_ubuntuis_secureboot_enabledz/etc/cloudlinux-edition-soloz/etc/cloudlinux-edition-adminzCloudLinux OS Shared ProzCloudLinux OS SharedzCloudLinux OS SolozCloudLinux OS Adminc"eZdZdZdZdZdZdZdS)SupportedEditionsz- Keeps supported CloudLinux editions soloshared shared_proadminN)__name__ __module__ __qualname____doc__SOLOSHARED SHARED_PROADMIN/builddir/build/BUILDROOT/alt-python27-cllib-3.4.22-1.el8.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/lib/cledition.pyrr"s. D FJ EEErrceZdZdZdS)CLEditionDetectionErrorc 6tj|||ddS)N)messagecontext)r __init__)selfr$r%s r r&z CLEditionDetectionError.__init__.s3#D+ +      rN)rrrr&rrr r"r"-s#     rr"cheZdZeddZedZe d dedzfdZdS) CLEditionsNTc|tt} t||}n2#tj$r }t dtd||d}~wwxYw |dS#t $r^}|d}|t dtd||rtj j ntj j cYd}~Sd}~wwxYw)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: editioncl_pluszL. Please, make sure it is not broken, error: not enough fields for detection) rrr r PyJWTErrorr"KeyErrorgetrrvaluer)tokenr+jwter-s r get_from_jwtzCLEditions.get_from_jwt?s8 =/00E Uz:::CC$   )B?BB   ey> ! e e eggi((G-b@Rbbb:Ad$/55FWF^Fd d d d d d d es3*AAAA%% C /ACC C c Ptjdd|gtjtjditjddi5}|\}}|jdkr*d|vr dddd Std |d |d | dddn #1swxYwYdS) Nrpmz-qTLC_ALLC)stdoutstderrtextenvrzis not installedFzUnable to check if package z is installed, reason: z, ) subprocessPopenPIPEosenviron communicate returncoder") package_nameprocouterrs r is_package_installedzCLEditions.is_package_installed^s<   D, '??12:1(C1      ''))HC!##%,,         .,,,,",,&),, $                ts(B6BB"BFreturnc|r|rtd|s_tjtr; |||}n#t $rt}YnwxYw|r|StrtS|sxtjtrtj j Stjtrtjj StSdS)a 1. Try to detect CL edition from JWT token; If edition field is in token -> return edition If edition field is not present -> recheck via cl_plus flag (see get_from_jwt) If token is broken -> raise an error about it 2. Try to detect edition from files. If JWT edition retreival was attempted and failed, or if we're in cagefs -> get edition from CL_EDITION_FILE_FOR_USERS If a edition marker file for Solo or Admin edition is present -> return corresponding edition Otherwise, fall back to CL_EDITION_FILE_FOR_USERS again Detection from marker files may be switched off using the `skip_marker_check` parameter. @param skip_jwt_check: if True, skip checking JWT token for edition. @param skip_marker_check: if True, skip checking marker files for edition. @param raw_jwt: raw JWT token to use for edition detection. If None, token will be read from file. @param verify_exp: if True, verify JWT token expiration time. @return: Edition of CloudLinux OS or None if edition could not be determined. 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)r2r+N)r"rApathisfilerr5PermissionErroruser_cl_editionr CL_SOLO_EDITION_FILE_MARKERrrr1CL_ADMIN_EDITION_FILE_MARKERr)clsskip_jwt_checkskip_marker_checkraw_jwtr+r,s r get_cl_editionzCLEditions.get_cl_editionrs<  / )a   "'..1C"D"D  ,**Z*PP" , , ,)++ ,  ;; %"$$ $! %w~~9:: 5(-33 <== 5(.44"$$ $tsAA.-A.)NT)FFNT) rrr staticmethodr5rI classmethodstrrVrrr r)r)=seee\e<\& :: t :::[:::rr)TFcnt|||}|duo|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 rSrTr+N)r)rVrrr1rSrTr+r,s r is_cl_solo_editionr]sE''%+(G $  J7.?.D.J#JJrcnt|||}|duo|tjjkSz 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[N)r)rVrrr1r\s r is_cl_shared_editionr`sE''%+(G $  L7.?.F.L#LLrcnt|||}|duo|tjjkSr_)r)rVrrr1r\s r is_cl_shared_pro_editionrbsE''%+(G $  P7.?.J.P#PPrc > tdi|S#t$rYdSwxYw)z: Supress edition checking error and returns False FNr)rbr")kwargss r is_cl_shared_pro_edition_safelyres='11&111 "uus  cnt|||}|duo|tjjkSr_)r)rVrrr1r\s r is_cl_admin_editionrgsE''%+(G $  K7.?.E.K#KKrrJc tdrtStdrtSn#t$r t cYSwxYwt \}}}d|vrtj tstrUttdd5}|cdddS#1swxYwY|rt St S)z Function returns current edition of CL: - CloudLinux OS Shared - CloudLinux OS Shared Pro - CloudLinux OS Solo - Error string T)rSz read errorrutf-8encodingN)r]SOLO_EDITION_HUMAN_READABLErgADMIN_EDITION_HUMAN_READABLEr"SHARED_EDITION_HUMAN_READABLEr rArLrMrr openrreadstrip!SHARED_PRO_EDITION_HUMAN_READABLE) success_flag error_message_fs r get_cl_edition_readablerxs>- T 2 2 2 0. .  5 5 5 0/ / 0 "---,,,,-&5%6%6"L-}$$"'..9K*L*L$PYP[P[$ +S7 C C C $q6688>>## $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $-00,,s%11AA'&CC!CcXtjdttddS)zJust print skip messagezJas part of unification effort, features might not map directly to editionszpCloudLinux Solo edition detected! Command is skipped, because it is unsupported and unneeded on current editionN)warningswarnDeprecationWarningprintrrr print_skip_message_on_solor~sG MT  Z[[[[[rcVtjdtddlm}|S)Nz@since v3.4.1 use "clcommon.cpapi.utils:skip_without_lve" insteadrskip_without_lve)rzr{r|clcommon.cpapi.utilsrrs r rr,s? MJ655555    rcXtjdtddlm}||S)NzEsince v3.4.1 use "clcommon.cpapi.utils:lve_supported_or_exit" insteadr)lve_supported_or_exit)rzr{r|rr)rwrs r rr5sA MO;:::::  # ##rc,tjtrot tdd5}|}dddn #1swxYwYt|SdS)z This function is used as a workaround for users to be able to get the CL Edition. Crontab will write output of `cldetect --detect-edition` command to CL_EDITION_FILE_FOR_USERS, with 0644 permission. rirjrkN) rArLexistsrrprqrr"HUMAN_READABLE_TOKEN_EDITION_PAIRSr0)rwr,s r rOrO>s  w~~/00? +S7 C C C 'qffhhnn&&G ' ' ' ' ' ' ' ' ' ' ' ' ' ' '255g>>> 4s'A//A36A3c@tjdS)z< Determines is this system running inside container z/etc/cloudlinux-container)rArLrrrr is_containerrKs 7>>5 6 66r)TFT)FFT)3rAr>rzenumrtypingrr3rclcommon.lib.constsrrclcommon.lib.jwt_tokenrr r clcommon.clexceptionr clcommon.clcagefsr clcommon.utilsr rrrPrQrsrormrnrr"rr1rrrrr)r]r`rbrergrxr~rrrOboolrrrr rs MMMMMMMMHHHHHHHHHH333333''''''LKKKKKKKKK<>$>! 624     0    !2!7!=%'8'C'I!#4#;#A "3"9"? &"ppppppppfKKKK$ M M M M-2/4(,QQQQ"(-*/#'LLLL"----->[[[ $$$   7d777777r