HEX
Server: Apache
System: Linux insrv.serversdaddy.com 5.14.0-362.24.2.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Mar 30 14:11:54 EDT 2024 x86_64
User: jsaha (1066)
PHP: 8.3.6
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/clcommon/lib/__pycache__/whmapi_lib.cpython-37.pyc
B

A]#�W���@s�dZddlmZddlmZddlmZddlZddlmZddlm	Z	ddl
mZd	ZGd
d�de�Z
Gdd
�d
e
�ZGdd�de
�ZGdd�d�ZdS)z,
Everything that is related to whmapi calls
�)�print_function)�absolute_import)�divisionN)�FormattedException)�run_command)�	urlencode)�
WhmApiRequest�WhmApiErrorc@seZdZdZdd�ZdS)r	zW
    An error that is raised in case of an error
    in communication with whmapi.
    cKst�|||d��dS)N)�message�context)r�__init__)�selfr
r�r��/builddir/build/BUILDROOT/alt-python27-cllib-3.4.1-1.el9.cloudlinux.x86_64/opt/alt/python37/lib/python3.7/site-packages/clcommon/lib/whmapi_lib.pyrszWhmApiError.__init__N)�__name__�
__module__�__qualname__�__doc__rrrrrr	sr	c@seZdZdZdS)�WhmLicenseErrorz)A license-related error raised by whmapi.N)rrrrrrrrr%src@seZdZdZdS)�WhmNoPhpBinariesErrorz;
    An error when there are no installed php binaries
    N)rrrrrrrrr*src@s\eZdZdZdZdZdd�Zdd�Zedd	��Z	e
d
d��Ze
dd
��Zdd�Z
dd�ZdS)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/whmapi1�cCs ||_i|_i|_ddg|_dS)Nz--output�json)�_command�_filters�_args�_extra_args)r
�commandrrrr=szWhmApiRequest.__init__c	Cs�t|dd�\}}}|dkr&td|d��y>t�|�}d|krbd|dkrb|dddkrbd|dd<Wn$ttfk
r�td	|d
��YnX|�|�|S)NT)Zreturn_full_outputrz whmapi exited with code %(code)i)�code�metadata�reason�zTwhmapi returned invalid response that cannot be parsed with json, output: %(output)s)�output)rr	r�loads�	TypeError�
ValueError�	_validate)r
rZexitcoder!�_�responserrr�_run_whmapiCs$

zWhmApiRequest._run_whmapicCs�|�|�rtd|dd��|�|�r8td|ddd��y|dd|dd}}Wn tk
rvtd|d��YnX|tjkr�td	|d
��dS)z)
        Check response metadata
        z"whmapi license error: %(response)s�	statusmsg)r'z Php binaries error: %(response)srr�resultz7whmapi metadata section is broken, output: %(response)sz4whmapi failed to execute request, reason: %(reason)s)rN)�_is_license_errorr�_is_no_php_binaries_errorr�KeyErrorr	r�
API_RESULT_OK)�clsr'r*rrrrr%_s 


zWhmApiRequest._validatecCs$d|ko"|ddko"d|d��kS)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'
        r)Zstatusr�license)�lower)r'rrrr+|szWhmApiRequest._is_license_errorcCs$d|ko"d|dko"d|ddkS)u�
        No binaries error can be detected by  checking special message
        '“PHP” is not installed on the system' whmapi output
        rru(“PHP” is not installed on the systemr)r'rrrr,�sz'WhmApiRequest._is_no_php_binaries_errorcKs|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
�kwargsrrr�with_arguments�szWhmApiRequest.with_argumentscCs�|j|jg}xBt|j���D]0\}}t|t�r6t|�}t||i�}|�	|�qW|�
|j�|�|�}d|krv|dSd|kr�|dS|SdS)zp
        Run subprocess, run output validation and
        return json-loaded response
        :return:
        �datar!N)
�WHMAPIr�listr�items�
isinstance�bool�intr�append�extendrr()r
�cmd�k�vZargumentr*rrr�call�s

zWhmApiRequest.callN)rrrrr6r.rr(�classmethodr%�staticmethodr+r,r4rArrrrr1s
r)rZ
__future__rrrrZclcommonrZclcommon.utilsrZurllib.parser�__all__r	rrrrrrr�<module>s