IQg\-ddlZddlZddlZddlmZddlmZddlmZddl 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_PROADMINv/builddir/build/BUILD/imunify360-venv-2.5.0/opt/imunify360/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"cXeZdZeddZedZe ddZdS) 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"BFc<|r|rtd|s_tjtr; |||}n#t $rt}YnwxYw|r|StrtS|stjtrtj j Stjtrtjj Stptjj 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)r2r+N)r"rApathisfilerr5PermissionErroruser_cl_editionr CL_SOLO_EDITION_FILE_MARKERrrr1CL_ADMIN_EDITION_FILE_MARKERrr)clsskip_jwt_checkskip_marker_checkraw_jwtr+r,s r get_cl_editionzCLEditions.get_cl_editionrs5(  c/ c)acc c "'..1C"D"D  ,**Z*PP" , , ,)++ ,  ;; %"$$ $! Gw~~9:: 5(-33 <== 5(.44"$$F(9(@(F F  G GsAA.-A.)NT)FFNT)rrr staticmethodr5rI classmethodrUrrr r)r)=s}eee\e<\&DI04+G+G+G[+G+G+Grr)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 rRrSr+N)r)rUrrr1rRrSr+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 rYN)r)rUrrr1rZs r is_cl_shared_editionr^sE''%+(G $  L7.?.F.L#LLrcnt|||}|duo|tjjkSr])r)rUrrr1rZs r is_cl_shared_pro_editionr`sE''%+(G $  P7.?.J.P#PPrc > tdi|S#t$rYdSwxYw)z: Supress edition checking error and returns False FNr)r`r")kwargss r is_cl_shared_pro_edition_safelyrcs='11&111 "uus  cnt|||}|duo|tjjkSr])r)rUrrr1rZs r is_cl_admin_editionresE''%+(G $  K7.?.E.K#KKrreturnc 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)rRz read errorrutf-8encodingN)r[SOLO_EDITION_HUMAN_READABLEreADMIN_EDITION_HUMAN_READABLEr"SHARED_EDITION_HUMAN_READABLEr rArKrLrr openrreadstrip!SHARED_PRO_EDITION_HUMAN_READABLE) success_flag error_message_fs r get_cl_edition_readablerws>- 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)ryrzr{clcommon.cpapi.utilsrrs r rrs? MJ655555    rcXtjdtddlm}||S)NzEsince v3.4.1 use "clcommon.cpapi.utils:lve_supported_or_exit" insteadr)lve_supported_or_exit)ryrzr{rr)rvrs r rr&sA MO;:::::  # ##rc,tjtrot tdd5}|}dddn #1swxYwYt|SdS)zThis 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. rhrirjN) rArKexistsrrorprq"HUMAN_READABLE_TOKEN_EDITION_PAIRSr0)rvr,s r rNrN/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)rArKrrrr is_containerr;s 7>>5 6 66r)TFT)FFT)3rAr>ryenumrtypingrr3rclcommon.lib.constsrrclcommon.lib.jwt_tokenrr r clcommon.clexceptionr clcommon.clcagefsr clcommon.utilsr rrrOrPrrrnrlrmrr"rr1rrrrr)r[r^r`rcrerwr}rrrNboolrrrr rs MMMMMMMMHHHHHHHHHH333333''''''LKKKKKKKKK<>$>! 624     0    !2!7!=%'8'C'I!#4#;#A "3"9"? &"aGaGaGaGaGaGaGaGHKKKK$ M M M M-2/4(,QQQQ (-*/#'LLLL"----->[[[ $$$   7d777777r