Ѡg5dZddlZddlZddlmZddlZddlZddlZddlmZddl m Z m Z m Z m Z ddlmZddlmZddlmZmZmZmZmZmZmZmZmZdd lmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ej%&ej%'e(Z)ej*eej+eej,eej-eiZ.Gd d Z/e0d kre/Z1e2e13e2e14d e2e15e2e16e2e17dSdS)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 InstalledPHPceZdZdZedZdZdZdZdZ dZ dZ dd Z dd Z dd ZddZddZdeefdZd S) PublicApiz> 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.22-1.el8.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/vendors_api/parser.py_scriptszPublicApi._scripts@s#$$$ctj}|ddd|d< t j|tjtjd|5}|\}}dddn #1swxYwYn&#t$r}td|d|d}~wwxYw| ||S)N PYTHONPATH1PYTHONNOUSERSITET)stdoutstderrtextenvz-Something is wrong with integration script: ``) osenvironcopypop subprocessPopenPIPEDEVNULL communicateOSErrorr _validate)r command schema_filer+poutput_es r!_executezPublicApi._executeJs%joo  d###"%  !')3)3);'+&) +++ ,/0MMOO   , , , , , , , , , , , , , , ,     DDDD   ~~fk222s;-B(B  B BBBB B;"B66B;ctt|}|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_ERRORgetr)r r@message error_clss r!_error_key_to_errorzPublicApi._error_key_to_error`sN,//77  "JW... .i   r#cB tj|pi}n)#ttf$r}t ||d}~wwxYw |dpi}|d}n##t $r}t ||d}~wwxYw|dkrv ||}tj|d|n<#tt tf$r"}tt||d}~wwxYw|dS| || ddS) zs Checks input for valid json structure :param raw_data: json :return: dict or list Nmetadatar@)r;okdatarD)rD)jsonloads TypeError ValueErrorr KeyError_read_data_schema jsonschemavalidaterrstrrFrC)r raw_data schema_path deserializedr=rHr@schemas r!r7zPublicApi._validateosW 2:h//52LL:& 2 2 2 ** 1 2 9#J/52Hh'FF 9 9 9 111q 8 9 T>> <// <<#L$8&AAAA#Xy9 < < <-SVV44!; < ' '  $ $VX\\)5L5L $ M M M M Ms@?:?A A6 A11A60B11C*C%%C*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) openr-pathjoinBASE_DIRyamlloadread SafeLoader)r filenamef data_schemas r!rPzPublicApi._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.yamlr9zFeature zX is not available, please check your panel_info integration script. Available keys are: z, cg|] }|j S)value).0rds r! z(PublicApi.panel_info..s1S1S1Sa!'1S1S1Sr#)r>r" panel_inforsupported_cl_featuresr rr])r valid_datar@features r!rmzPublicApi.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.yamlrg)r>r"db_infor)r ros r!rrzPublicApi.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.yamlrgc,g|]}t|Sri)rrkxs r!rlz&PublicApi.packages..s///q ///r#)r"packagesr>)r ownerargsros r!rxzPublicApi.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 >idemailrydomainpackageusername locale_codez7You can only use package_name and package_owner in pairNz"fields accept only list of stringsz are not allowed fieldsc,g|]}t|Sri)all)rkis r!rlz#PublicApi.users..s4V4V4VSVV4V4V4Vr#z.You cannot use all these args in one request: rtz--package-namez--package-ownerz --usernamez --unix-idz--fields,z users.yamlrgc,g|]}t|Sri)rrvs r!rlz#PublicApi.users..s...a$q''...r#c&g|] }|jv |Sri)rrku filter_namess r!rlz#PublicApi.users..s%FFFA1:+E+Ea+E+E+Er#)boolrN isinstancelisttupletypesetrlenr"usersrSr]r>)r ry package_name package_ownerrunix_idfieldsallowed_fieldsnot_allowed_fieldsexclusive_groups used_argsr8ror@s ` 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.yamlrt--name)z --with-phpzdomains_with_php.yamlrg)rNr"domainsr>itemsr) r rynamewith_phpr8rWror@kvs r!rzPublicApi.domainss  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.yamlrgc,g|]}t|Sri)rrvs r!rlz'PublicApi.resellers..Ls222!(1++222r#c&g|] }|jv |Srirrs r!rlz'PublicApi.resellers..N%BBBA16\+A+Aa+A+A+Ar#)rNr" resellersrSrr>rr)r id_rr8ror@s ` r!rzPublicApi.resellers4s  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.yamlrgc,g|]}t|Sri)rrvs r!rlz$PublicApi.admins..ks///q%((///r#c&g|] }|jv |Srirrs r!rlz$PublicApi.admins..mrr#) rNr"adminsrrSlowerr>rr)r ris_mainr8ror@s ` r!rzPublicApi.adminsQs$  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.yamlrgc,g|]}t|Sri)rrvs r!rlz!PublicApi.php..|s444A Q444r#)r"phpr>)r rzros r!rz PublicApi.phpps7} ]]4Z]@@ 444444r#)N)NNNNNN)NNF)NN)__name__ __module__ __qualname____doc__propertyr"r>rFr7rPrmrrrxrrrrrrrrir#r!rr;s3%%X%333, ! ! !NNN>   0 % % %0000"  AAAAF::> 5d<( 5 5 5 5 5 5r#r__main__{)r)8rr-r1 itertoolsrrKrQr_rtypingrrrrclcommon.featuresr vendors_api.configr vendors_api.exceptionsr r rrrrrrrvendors_api.modelsrrrrrrrrr\abspathdirname__file__r^INTERNAL_ERRORPERMISSION_DENIED BAD_REQUEST NOT_FOUNDrBrrapiprintrmrrrrrir#r!rs    &&&&&&,,,,,,,,,,,,------222222                       7??27??844 5 5"$4jH A5A5A5A5A5A5A5A5H  z )++C E#..   E#))C) !!! E#**,, E#--// E#++--r#