IQg2dZddlZddlmZddlmZddlmZdZGddeZ Gd d e Z Gd d e Z Gd dZ dS)z, Everything that is related to whmapi calls N)FormattedException) run_command) urlencode) WhmApiRequest WhmApiErrorceZdZdZdZdS)rzW An error that is raised in case of an error in communication with whmapi. c 6tj|||ddS)N)messagecontext)r__init__)selfr r s w/builddir/build/BUILD/imunify360-venv-2.5.0/opt/imunify360/venv/lib/python3.11/site-packages/clcommon/lib/whmapi_lib.pyr zWhmApiError.__init__s3#D+ +      N)__name__ __module__ __qualname____doc__r rrrrs-      rrceZdZdZdS)WhmLicenseErrorz)A license-related error raised by whmapi.Nrrrrrrrrr"s33DrrceZdZdZdS)WhmNoPhpBinariesErrorz; An error when there are no installed php binaries Nrrrrrr's DrrcteZdZdZdZdZdZdZedZ e dZ e dZ d Z d Zd S) ra Wrapper over cpanel's whm command-line api tool that allows us to easily build complex requests (filter, sorting, etc) See details in the official cpanel docs (link below) https://documentation.cpanel.net/display/DD/Guide+to+WHM+API+1 z/usr/sbin/whmapi1cB||_i|_i|_ddg|_dS)Nz--outputjson)_command_filters_args _extra_args)r commands rr zWhmApiRequest.__init__:s*   &/rcXt|d\}}}|dkrtd| tj|}d|vr#d|dvr|dd d|dd<n+#tt f$r}td | |d}~wwxYw|||S) NT)return_full_outputrz whmapi exited with code %(code)i)codemetadatareasonzTwhmapi returned invalid response that cannot be parsed with json, output: %(output)s)output)rrrloads TypeError ValueError _validate)r r"exitcoder)_responsees r _run_whmapizWhmApiRequest._run_whmapi@s) ...&! q==2   z&))H h&&!Xj%999!*-h7?13$X.:&   A    x   s;A**B;B  Bc||rtd|d||rtd|dd |dd|dd}}n$#t$r}t d||d }~wwxYw|t jkrt d | d S) z) Check response metadata z"whmapi license error: %(response)s statusmsgr0z Php binaries error: %(response)sr&r'resultz7whmapi metadata section is broken, output: %(response)sNz4whmapi failed to execute request, reason: %(reason)s)r')_is_license_errorr_is_no_php_binaries_errorrKeyErrorrr API_RESULT_OK)clsr0r6r'r1s rr-zWhmApiRequest._validate\s   * * !4x ?T   ( ( 2 2 '2Xj=QRZ=[  $X.0DX0NFF   I!   ]0 0 0F  1 0s A== BBBcZd|vo'|ddkod|dvS)a# Distinguish license-related WHM API errors from others. License errors are on the client's side, and should not be logged to sentry. An error is considered license-related if the API returns status 0 and the error message contains the word 'license' r4statusrlicense)lowerr5s rr7zWhmApiRequest._is_license_errorysAx';"a';Xk288::: d|vod|dvod|ddvS)u No binaries error can be detected by checking special message '“PHP” is not installed on the system' whmapi output r&r'u(“PHP” is not installed on the systemrr5s rr8z'WhmApiRequest._is_no_php_binaries_errors> h&]HZ00]:hz>RS[>\\ ^rc :|j||S)z Add some extra arguments to subprocess call Useful for methods like createacct, removeacct :param kwargs: arguments that will be added to cmd :rtype: WhmApiRequest )r update)r kwargss rwith_argumentszWhmApiRequest.with_argumentss &!!! rc|j|jg}t|jD]O\}}t |t rt|}t||i}| |P| |j | |}d|vr|dSd|vr|dS|S)zp Run subprocess, run output validation and return json-loaded response :return: datar)) WHMAPIrlistr items isinstanceboolintrappendextendr!r2)r cmdkvargumentr6s rcallzWhmApiRequest.calls K M ))++,, ! !DAq!T""  FF !Q((H JJx 4#$$$!!#&& V  &> !   (# #MrN)rrrrrGr:r r2 classmethodr- staticmethodr7r8rDrSrrrrr.s!FM000 8[8 < <\ <^^\^($$$$$rr) rrclcommonrclcommon.utilsr urllib.parser__all__rrrrrrrrZs ''''''&&&&&&"""""" *      $         k        K   YYYYYYYYYYr