zhOdZddlZddlZddlZddlmZddlZddlZddlZddlm 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+ej,e-Z.ej/eej0eej1eej2eiZ3Gd d Z4e-d kre4Z5e6e57e6e58de6e59e6e5:e6e5;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 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.40-1.el9.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/vendors_api/parser.py_scriptszPublicApi._scriptsCs#$$$cbtj}dD]}||dd|d< t j|tjtjd|5} |d\}}nS#tj $rA}| |td|d |d}~wwxYw dddn #1swxYwYn&#t$r} td | d | d} ~ wwxYw| ||S) N) PYTHONPATH PYTHONHOME PYTHONSTARTUP PYTHONINSPECT LD_PRELOADLD_LIBRARY_PATH1PYTHONNOUSERSITET)stdoutstderrtextenv)timeoutzIntegration script timed out: ``z-Something is wrong with integration script: `)osenvironcopypop subprocessPopenPIPEDEVNULL communicateTimeoutExpiredkillr OSError _validate) r!command schema_filer1varpoutput_exces r"_executezPublicApi._executeMsjooF  C GGC    "%  !')3)3);'+&) +++ /0 ! b 9 9IFAA!0FFHHHMMOOO(D'DDD                   DDDD   ~~fk222s`-C5-C)/B C) C> <// <<#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) openr5pathjoinBASE_DIRyamlloadread SafeLoader)r!filenamef data_schemas r"r`zPublicApi._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.yamlrCzFeature zX is not available, please check your panel_info integration script. Available keys are: z, cg|] }|j S)value).0rus r" z(PublicApi.panel_info..s1S1S1Sa!'1S1S1Sr$)rJr# panel_inforsupported_cl_featuresr rrn)r! valid_datarLfeatures r"r~zPublicApi.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.yamlrx)rJr#db_infor)r!rs r"rzPublicApi.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.yamlrxc,g|]}t|Srz)rr|xs r"r}z&PublicApi.packages..s///q ///r$)r#packagesrJ)r!ownerargsrs 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|Srz)all)r|is r"r}z#PublicApi.users..s4V4V4VSVV4V4V4Vr$z.You cannot use all these args in one request: rz--package-namez--package-ownerz --usernamez --unix-idz--fields,z users.yamlrxc,g|]}t|Srz)rrs r"r}z#PublicApi.users..#s...a$q''...r$c&g|] }|jv |Srz)rr|u filter_namess r"r}z#PublicApi.users..'s%FFFA1:+E+Ea+E+E+Er$)boolrZ isinstancelisttupletypesetrr^r#usersrcrnrJ)r!r package_name package_ownerrunix_idfieldsallowed_fieldsnot_allowed_fieldsexclusive_groups used_argsrBrrLs ` 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.yamlrx)rZr#domainsrJitemsr) r!rnamewith_phprBrhrrLkvs 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.yamlrxc,g|]}t|Srz)rrs r"r}z'PublicApi.resellers.._s222!(1++222r$c&g|] }|jv |Srzrrs r"r}z'PublicApi.resellers..a%BBBA16\+A+Aa+A+A+Ar$)rZr# resellersrcrrJrr)r!id_rrBrrLs ` r"rzPublicApi.resellersGs  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.yamlrxc,g|]}t|Srz)rrs r"r}z$PublicApi.admins..~s///q%((///r$c&g|] }|jv |Srzrrs r"r}z$PublicApi.admins..rr$) rZr#adminsrrclowerrJrr)r!ris_mainrBrrLs ` r"rzPublicApi.adminsds$  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.yamlrxc,g|]}t|Srz)rrs r"r}z!PublicApi.php..s444A Q444r$)r#phprJ)r!rrs r"rz PublicApi.phps7} ]]4Z]@@ 444444r$)N)NNNNNN)NNF)NN)__name__ __module__ __qualname____doc__propertyr#rJrRrAr`r~rrrrrrrrrrzr$r"rr>s4%%X%333< ! ! !%N%N%NN   0 % % %0000"  AAAAF::> 5d<( 5 5 5 5 5 5r$r__main__{)r)rs    &&&&&&,,,,,,,,,,,,------222222                       7??27??844 5 5  8 $ $"$4jH Q5Q5Q5Q5Q5Q5Q5Q5h  z )++C E#..   E#))C) !!! E#**,, E#--// E#++--r$