F6 $ddlZddlZddlZddlZddlZddlmZddlmZddlm Z ddl m Z m Z m Z ddlZddlmZmZddlmZdd lmZejd Z dd e ed e ed e eddfdZdedefdZGddZdS)N)JSONDecodeError)Path)run)DictOptionalUnion)print_dictionaryreplace_params)CloudlinuxLicenseLib)parse_cloudlinux_packages_optszcloudlinux-licenseerrordetailscontextreturncdtji}|||d<d}nd|d<d}|||d<|||d<tj|tjtj|dS) a This function makes UI-specific JSON, prints it and exits from the program. It sets "timestamp". And if @param error is specified, then field "result" will be filled with this parameter and exit code will be 1. Otherwise "result" will be filled with "success" and exit code will be 0. @param details: if it's specified, then field "details" will be will be filled with this parameter. @param context: if it's specified, then field "context" will be filled with this parameter. timestampNresultr successrrr)timejsondumpsysstdoutexit)rrroutput exit_codes py/cllicense/license.py_print_as_json_and_exitrs49;; 'F  x $x #y#yIfcj!!!HYvalidation_errorscVd}|D]\}}|d|d|dz }|S)z This function converts dict of validation errors in a more human-readable presentation as str. Ends each line with ' '. @param validation_errors: dict of validation errors @return: str z- z:  )items)r!rfieldrs r _beautifyr'<sMF)//11** u)u)))))) Mr c|eZdZdZedZeddhZdZdZ dZ dZ d Z dd Z d efd ZddZdS)CloudlinuxLicensez+ Class to check Cloudlinux license z%/etc/lve-utils/cloudlinux-license.inicln cln-stagingcZd|_i|_t|_|jrRt j}||jt|ddrdnd|_ nd|_ |j |j vr d|_ dSdS)NFDEFAULTis_stager+r*) _is_json_optsr _license_lib CONFIG_PATHexists configparser ConfigParserreadbool cln_subdomainALLOWED_CLN_SUBDOMAINS)selfconfigs r__init__zCloudlinuxLicense.__init__Ss  022   " " $ $ '!.00F KK( ) ) )26vi7H7T2U2U!`[`D  !&D   T%@ @ @!&D    A @r c$d|v|_|||_|jdr)||n6|jdr|n|dS)z$ Run command action z--jsonset get_trialr)r/ _parse_argsr0_set_run_get_run _get_trial)r:argvs rrzCloudlinuxLicense.runbs!D( %%d++ :e   MMOOO MMOOOO Z $  OO     MMOOOqr c|jrd}nd}dtj|d}t|ddS)z# Run 'get' command validinvalidr)rrlicenseTN)r1get_license_statusrr )r:license_status result_datas rrBzCloudlinuxLicense._get_runrsU   / / 1 1 '$NN'N!*Q_`` d+++++r c|jdr|j|jd}|r|j|dSdS)z# Run 'set' command z--ipz--keyN)r0r1!register_and_update_license_by_ip"register_and_update_license_by_key)r:keys rrAzCloudlinuxLicense._set_runsg :f  B   ? ? A A Aj!  F   @ @ E E E E E F Fr c~t||j\}}|s"|t||S)z% Parse CLI arguments )r r/_error_and_exitr )r:rDstatusdatas rr@zCloudlinuxLicense._parse_argssB6dDMJJ  7  !5!5 6 6 6 r r c~|jr9|dtjit|dnh t t |d|dizn-#t$r }t d|d|dYd}~nd}~wwxYwtj |dS) z Print error and exit :param message dict: Dictionary with keys "result" as string and optional "context" as dict rTrrzError: z []N) r/updaterr printstrgetKeyErrorrr)r:message error_codees rrQz!CloudlinuxLicense._error_and_exits = 1 NNK5 6 6 6 Wd + + + + 1c'(+,,w{{9b/I/IIJJJJ 1 1 1///W///00000000 1 s9A<< B&B!!B&rcx tj|jd}|dd}n,#t$rt d|jdYnwxYw t jd|jd|d|d }n:#t j $r(}t d t|Yd}~nd}~wwxYw |}nP#t$rCt d |j |jt d d|j dYnwxYwd|vr|dS|ddkr&t ddt!|di|dt |dt dt#d)Nz--configeditionzCL-SolozInput config is not valid JSON.)rzhttps://z.cloudlinux.com/wapi/z/trial)rtimeoutzWe tried to get a trial license, but were unable to connect to the server application. Please, try again later or contact our support for help.z:Trial license API returned non-JSON response (HTTP %s): %szWe tried to get a trial license, but something went wrong on the server side. Please, try again later or contact our support for help.z(Server returned non-JSON response (HTTP )rOtype validationzVInput data validation failed: %(error_text)sPlease fix form errors and submit again. error_texterrors)rr[zsWe tried to get a trial license, but something went wrong. Please, try again later or contact our support for help.zlicense key request failed)rloadsr0poprrrequestspostr8RequestExceptionrXloggerr status_codetextrYr' RuntimeError)r:r;r_responser] response_jsons r_get_keyzCloudlinuxLicense._get_keysW gZ : 677FjjI66GG g g g #$EtzZdOe f f f f f f g }S4-SSGSSSHH (    #KA           $MMOOMM    LLL$hm    $KZ8CWZZZ        M ! ! ' '   V $ $ 4 4 #;%yx1H'I'IJ       V $ $ , #M)$< = = =  G   7888s:58&A! A!%#B CB;;CCA D&%D&Nc |}tddd|dd|jdgdd }|jd kr+t d d |jd tddgdd }|jd kr-t d d |jd dSt dS)N clnreg_ksz--forcez--activationkeyz --serverUrlzhttps://xmlrpc.z.cloudlinux.com/XMLRPCTF)capture_outputcheckrzfWe created a trial license, but were unable to register the server. Please, try to run this command: ` z3` a little bit later. Contact our support for help.z/usr/bin/cldetectz--update-license)rrrr8 returncoderjoinargs)r:rOrs rrCzCloudlinuxLicense._get_trials mmoo!PD$6PPP          ! ! #_HHV[))___    )+=>t[`aaa   ! ! #_HHV[))___      $ % % % % %r )r )rN)__name__ __module__ __qualname____doc__rr2 frozensetr9r<rrBrAr@rQrXrrrCr rr)r)Ks$>??K&Y}'=>> ' ' ' , , , F F F    59#59595959n&&&&&&r r))NNN)r4rloggingrrrpathlibr subprocessrtypingrrrri cli_utilsr r cllicenser cl_license_arg_parser getLoggerrlrXdictrr'r)rr rrs  ((((((((((66666666******@@@@@@  / 0 0 !" C= c]d^ >  #    m&m&m&m&m&m&m&m&m&m&r