wo4hkddlZddlZddlZddlZddlmZddlmZmZddl m Z ej e Z dZgdZGdde ZGd d eZdd Zd ZdZdZdS)N)quote) check_run CheckRunError)PanelExceptionz/usr/sbin/whmapi1)zno certificatezno key with the idzcannot read license filezinvalid license filezlicense file expiredceZdZdZdS)WHMAPIExceptionz5Got broken output or other problem during WHMAPI callN__name__ __module__ __qualname____doc__]/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/subsys/panels/cpanel/whm.pyrrs??DrrceZdZdZdS)WHMAPILicenseErrorz$Raises when cannot Read License FileNr rrrrrs..DrrFcK|rdgng}|td|gd|D} t||zd{V}nS#t $rF}|jtj kr)t |t||d}~wwxYw tj |}n-#tj$r}td|d||d}~wwxYw |ddr|dStd |dd |dd #t $r_}d |vr!t d t"td||d}~wwxYw)Nsudo --output=jsoncZg|](\}}d|t|)S)z{}={})formatr).0kvs r zwhmapi1..'s0 E E EdagnnQa)) E E ErzBroken output from whmapi1: z , reason: metadataresultdatazwhmapi {} command failed: {}commandreason) statusmsgzCannot Read License FilezCannot Read CPanel License Filez/Broken output from whmapi1 (KeyError: {}): {!r})extend WHMAPI1_CMDitemsrdecoder returncodesignalSIGTERMloggerwarningrjsonloadsJSONDecodeErrorrKeyErrorr)functionrkwargscmdparams raw_outputeoutputs rwhmapi1r6$s  "6((CJJ _h7888 E Efllnn E E EF%cFl33333333;;==  !!.55:&y16*3Eh3O      4  F F NN< = = =$ $!AHHv  sP*A11 C;AB<<CCD)C??DE;E G#AF==Gctg|d} td|tj|dtj}n*#tj$r}td|z|d}~wwxYw|rtj |j }g}t|D]l\}} |} |D] } | | } | | +#t$r5}|dkrtd|| dYd}~ed}~wwxYwndSt|dkr|dS|S) Nrzsubprocess.run(%r)T)checkstdoutzFailed to run whmapi1: %srzCould not parse whmapi1 output)r#r)debug subprocessrunPIPECalledProcessErrorrr+r,r9r% enumerateappendr.len) args path_listr1resr4decoded_outputri element_pathitemkeys r run_whmapirKLs  / / /CF )3///nSZ_EEE  (FFF9A=>>AEFCJ$5$5$7$788(33 ( (OA| (%'%%C9DD d#### ( ( (66*8 MM$'''''''' (  ("  6{{aay s/r)F)r+loggingr<r' urllib.parserdefence360agent.utilsrr"defence360agent.subsys.panels.baser getLoggerr r)r#WHMAPI_CERT_ERROR_LISTrrr6rKrNrPrrrrWs4  ::::::::======  8 $ $"      n           %%%%P$$$N444r