VULN_CHECK_I913V6 Is}dZddlZddlZddlZddlmZddlZddlZddlZddlm Z ddl m Z m Z m Z mZddlmZddlmZddlmZmZmZmZmZmZmZmZmZdd lmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%ej&'ej&(e)Z*d Z+d Z,ej-e.Z/ej0eej1eej2eej3eiZ4Gd d Z5e.dkre5Z6e7e68e7e69de7e6:e7e6;e7e6<dSdS)zt Main API module that provides class uses as proxy to public vendors methods and converts data to internal objects. N)compress)ValidationError)OptionalListDictAny)ALL_CL_FEATURESintegration_scripts) BadScriptErrorMalformedError ErrorMessage InternalErrorPermissionDenied BadRequestNotFoundUnexpectedResultVendorApiMalformedData) PanelInfo DatabasesPackageUser DomainDataResellerAdmin InstalledPHPz Proxy to the public universal api for control panels ctS)zU Re-read this each time we call api due to lve-stats daemon. r )selfs /builddir/build/BUILDROOT/alt-python27-cllib-3.4.41-1.el10.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/vendors_api/parser.py_scriptszPublicApi._scriptsDs#$$$ctdd}dD](}tj|}||||<) t j|tjtjd|5}|\}}dddn #1swxYwYn&#t$r} td| d| d} ~ wwxYw| ||S)N1)PATHPYTHONNOUSERSITE)LANGLC_ALLLC_CTYPETZT)stdoutstderrtextenvz-Something is wrong with integration script: ``) SAFE_PATHosenvironget subprocessPopenPIPEDEVNULL communicateOSErrorr _validate) r!command schema_filer0varvalpoutput_es r"_executezPublicApi._executeNs5!c::7  C*..%%CC !')3)3);'+&) +++ ,/0MMOO  , , , , , , , , , , , , , , ,    DDDD   ~~fk222s;-B$B< BB  BB B B7B22B7ctt|}|td||||)z Convert documented api error constants into python exceptions. :param result: error constant :param message: custom message that vendor returned Nz8Unexpected result key: `%(result)s`; message=`%(error)s`)resulterror)_ERROR_MESSAGE_TO_ERRORr5r)r!rGmessage error_clss r"_error_key_to_errorzPublicApi._error_key_to_errorlsN,//77  "JW... .i   r$cB tj|pi}ni#ttf$rU}|r|dtn|}t d|rt|nd|t||d}~wwxYw |dpi}|d}nc#t$rV}|r|dtn|}t d|rt|nd|t||d}~wwxYw|dkrv | |}tj |d |n<#tttf$r"}tt||d}~wwxYw|d S|||d  dS) zs Checks input for valid json structure :param raw_data: json :return: dict or list Nz;Failed to parse vendor script output (len=%d, truncated=%r)rmetadatarGz?Missing metadata in vendor script output (len=%d, truncated=%r))rBokdatarJ)rJ)jsonloads TypeError ValueError_MAX_OUTPUT_LENGTHloggerdebuglenr KeyError_read_data_schema jsonschemavalidaterrstrrLr5) r!raw_data schema_path deserializedrD truncatedrNrGschemas r"r<zPublicApi._validate{s 3:h//52LL:& 3 3 39AO!4"4!455xI LLM!)0H q) = = =!++ 2  3 :#J/52Hh'FF : : :9AO!4"4!455xI LLQ!)0H q) = = =! 222 9  : T>> <// <<#L$8&AAAA#Xy9 < < <-SVV44!; < ' '  $ $VX\\)5L5L $ M M M M MsFA?AA::A?B C6 AC11C60D11E*E%%E*cttjtd|d5}t j|t j}dddn #1swxYwY|S)a- Knowing the fact that we store all data schemas in one folder we can easily find their absolute path. We do not handle errors here as normally package contains all it's files. :param filename: schema filename to load :return: dict, jsonschema schemaszutf-8)encodingN) openr3pathjoinBASE_DIRyamlloadread SafeLoader)r!filenamef data_schemas r"rZzPublicApi._read_data_schemas"',,xH== P P P ?TU)AFFHHdo>>K ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?s2A44A8;A8c  ||jjd}t|}|js|S|jD]B}|t vr t d|dddt D|S)z Returns the information about the control panel. Necessity: Always Accessed by: All UNIX users Must work inside CageFS also: Yes zpanel_info.yamlr>zFeature zX is not available, please check your panel_info integration script. Available keys are: z, cg|] }|j S)value).0ros r" z(PublicApi.panel_info..s1S1S1Sa!'1S1S1Sr$)rEr# panel_inforsupported_cl_featuresr rrh)r! valid_datarGfeatures r"rxzPublicApi.panel_infos]]4=#;IZ][[ :&&+ M3  G/))!W7WW'+yy1S1S?1S1S1S'T'TWW   r$cb||jjd}t|S)a Returns the information about databases that are available to the control panel users and are managed by the control panel. Necessity: Only for LVE-Stats Accessed by: admins (UNIX users) Must work inside CageFS also: No z db_info.yamlrr)rEr#db_infor)r!rzs r"r}zPublicApi.db_infos,]]4=#8n]UU $$$r$Ncr|jj}||d|fz }||d}d|DS)a Returns list of abstractions called "package" that represents a group of users that have the same default limits. Necessity: For limits functionality Accessed by: admins (UNIX users) Must work inside CageFS also: No N--ownerz packages.yamlrrc,g|]}t|Srt)rrvxs r"rwz&PublicApi.packages..s///q ///r$)r#packagesrE)r!ownerargsrzs r"rzPublicApi.packagessL}%   Y& &D]]4_]EE //J////r$cZhd}t|t|z rtdt|ttt dfstd|&t ||z }|rt|d|g||gg|gg} tt| d| D} t| dkrtd| |j j } || d |fz } |r |r | d |d |fz } rttr| d fz } |r| d t|fz } |r| dd |fz } | | d} d| D} tttfrfd| D} | S)z Returns information about UNIX users, created and managed by the control panel. Necessity: Always Accessed by: admins (UNIX users) Must work inside CageFS also: No >idemailrdomainpackageusername locale_codez7You can only use package_name and package_owner in pairNz"fields accept only list of stringsz are not allowed fieldsc,g|]}t|Srt)all)rvis r"rwz#PublicApi.users..s4V4V4VSVV4V4V4Vr$z.You cannot use all these args in one request: rz--package-namez--package-ownerz --usernamez --unix-idz--fields,z users.yamlrrc,g|]}t|Srt)rrs r"rwz#PublicApi.users..$s...a$q''...r$c&g|] }|jv |Srt)rrvu filter_namess r"rwz#PublicApi.users..(s%FFFA1:+E+Ea+E+E+Er$)boolrT isinstancelisttupletypesetrrXr#usersr]rhrE)r!r package_name package_ownerrunix_idfieldsallowed_fieldsnot_allowed_fieldsexclusive_groups used_argsr=rzrGs ` r"rzPublicApi.userss? GGG   ] 3 3 3 :9:: :&4T ";<< CABB B  !$V~!= ! Q $6!O!O!OPPPG = ) N I  "24V4VEU4V4V4VWWXX y>>A  LLL -%    5) )G  :M : (,)=: :G  4J|S99 4  l3 3G  3  S\\2 2G  6  CHHV$4$45 5G]]7 ]EE ..:... lT5M 2 2 GFFFFFFFF r$Fc|r|rtd|jj}d}|r|d|fz }|r|d|fz }|r|dz }d}|||}i}|D]\}} t | ||<|S)z Returns key-value object, where a key is a domain (or subdomain) and a value is DomainData object Necessity: Selectors, some UI features Accessed by: All UNIX users Must work inside CageFS also: Yes z"you cannot use both owner and namez domains.yamlr--name)z --with-phpzdomains_with_php.yamlrr)rTr#domainsrEitemsr) r!rnamewith_phpr=rbrzrGkvs r"rzPublicApi.domains+s  CT CABB B-'  *  5) )G  ( $' 'G  - ' 'G,F]]7]?? $$&& & &DAq"1 F1II r$cD|rrtd|jj}||dt|fz }t tr|dfz }||d}d|D}t t tfrfd|D}|S) a Gives information about resellers who can be users owners in the control panel. Resellers do not obligatory have their own same-name UNIX accounts in the system and could exist only as an account in the control panel. Necessity: Always Accessed by: admins (UNIX users) Must work inside CageFS also: no :param int id_: int, reseller id :param filter_names: name or list of reseller names to return z&You cannot use id and name at one callNz--idrzresellers.yamlrrc,g|]}t|Srt)rrs r"rwz'PublicApi.resellers..`s222!(1++222r$c&g|] }|jv |Srtrrs r"rwz'PublicApi.resellers..b%BBBA16\+A+Aa+A+A+Ar$)rTr# resellersr]rrErr)r!id_rr=rzrGs ` r"rzPublicApi.resellersHs  G< GEFF F-) ? C) )G lC ( ( 0 ,/ /G]]78H]II 22z222 lT5M 2 2 CBBBBBBBF r$chr|td|jj}ttr|dfz }|&|dt |fz }||d}d|D}tttfrfd|D}|S) u Gives information about panel’s administrators, output information about all panel’s administrators who: - could be (or actually are) the owners of the users, listed in users() - could be (or actually are) the owners of the packages, listed in packages() - has UNIX users with the rights to run LVE Manager UI Necessity: Always Accessed by: admins (UNIX users) Must work inside CageFS also: no :param filter_names: name or list of names to return :param is_main: filter output by type of admins: None means no filtering, return all False means only additional admins True means only main admin Nz&unable to use name and is_main at oncerz --is-mainz admins.yamlrrc,g|]}t|Srt)rrs r"rwz$PublicApi.admins..s///q%((///r$c&g|] }|jv |Srtrrs r"rwz$PublicApi.admins..rr$) rTr#adminsrr]lowerrErr)r!ris_mainr=rzrGs ` r"rzPublicApi.adminses$  GG/EFF F-& lC ( ( 0 ,/ /G    S\\%7%7%9%9: :G]]7 ]FF //J/// lT5M 2 2 CBBBBBBBF r$returnc`|jj}||d}d|DS)a% Returns list of abstractions called "php" that represents an installed php with it's binary, ini file, modules directory, etc Necessity: For accelerate wp functionality Accessed by: admins (UNIX users) Must work inside CageFS also: No zphp.yamlrrc,g|]}t|Srt)rrs r"rwz!PublicApi.php..s444A Q444r$)r#phprE)r!rrzs r"rz PublicApi.phps7} ]]4Z]@@ 444444r$)N)NNNNNN)NNF)NN)__name__ __module__ __qualname____doc__propertyr#rErLr<rZrxr}rrrrrrrrrtr$r"rr?s4%%X%333< ! ! !%N%N%NN   0 % % %0000"  AAAAF::> 5d<( 5 5 5 5 5 5r$r__main__{)r)=rloggingr3r6 itertoolsrrQr[rjrtypingrrrrclcommon.featuresr vendors_api.configr vendors_api.exceptionsr r rrrrrrrvendors_api.modelsrrrrrrrrrgabspathdirname__file__rirUr2 getLoggerrrVINTERNAL_ERRORPERMISSION_DENIED BAD_REQUEST NOT_FOUNDrIrapiprintrxrrrrrtr$r"rs    &&&&&&,,,,,,,,,,,,------222222                       7??27??844 5 5 J  8 $ $"$4jH Q5Q5Q5Q5Q5Q5Q5Q5h  z )++C E#..   E#))C) !!! E#**,, E#--// E#++--r$