Anons79 Mini Shell

Directory : /proc/self/root/lib/python2.7/site-packages/ansible/plugins/httpapi/
Upload File :
Current File : //proc/self/root/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyc

�
�Udac@`s�ddlmZmZmZeZdZddlZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZdd	lmZd
e	fd��YZdS(i(tabsolute_importtdivisiontprint_functions^
---
author:
    - Luke Weighall (@lweighall)
    - Andrew Welsh (@Ghilli3)
    - Jim Huber (@p4r4n0y1ng)
httpapi : fortimanager
short_description: HttpApi Plugin for Fortinet FortiManager Appliance or VM
description:
  - This HttpApi plugin provides methods to connect to Fortinet FortiManager Appliance or VM via JSON RPC API
version_added: "2.8"

N(tHttpApiBase(tto_text(tBASE_HEADERS(tFMGBaseException(t
FMGRCommon(tFMGRMethodstHttpApicB`syeZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
ed��Zejd
��Zed��Zejd��Zdd�Zed��Zejd��Zd�Zed��Zejd��Zed��Zejd��Zd�Zd�Zd�Zd�Zd d�Zd d�Zd ed�ZRS(!cC`s�tt|�j|�d|_d|_d|_d|_t|_	t
|_d|_d|_
d|_d|_d|_d|_t�|_t
|_t
|_dS(Nis/jsonrpc(tsuperR	t__init__t_req_idtNonet_sidt_urlt_hostRt_toolstFalset_debugt_connected_fmgrt_last_response_msgt_last_response_codet_last_data_payloadt	_last_urlt_last_response_rawtlistt_locked_adom_listt_uses_workspacet_uses_adoms(tselft
connection((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyR.s 													cC`sdS(s�
        ELEVATION IS NOT REQUIRED ON FORTINET DEVICES - SKIPPED
        :param become_context: Unused input.
        :return: None
        N(R
(Rtbecome_context((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyt
set_become@scC`sdS(s�
        TOKENS ARE NOT USED SO NO NEED TO UPDATE AUTH
        :param response: Unused input.
        :param response_data Unused_input.
        :return: None
        N(R
(Rtresponset
response_data((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pytupdate_authHsc	C`sd|jtj|jjtjdd|d|��d|j�krQ|j�dStdd��dS(s
        This function will log the plugin into FortiManager, and return the results.
        :param username: Username of FortiManager Admin
        :param password: Password of FortiManager Admin

        :return: Dictionary of status, if it logged in or not.
        ssys/login/usertpasswdtusers-FortiManager object connected to FortiManagerNtmsgsWUnknown error while logging in...connection was lost during login operation.... Exiting(tsend_requestRtEXECRtformat_requestt__str__tinspect_fmgrR(Rtusernametpassword((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pytloginQs!
cC`s�|j�|j�}|ddkrB|j�tdd��nH|ddkr�y!|d|_|jd|_Wq�tk
r�q�XndS(Nii����R'sRError -11 -- the Session ID was likely malformed somehow. Contact authors. ExitingitHostname(t
check_modetget_system_statustlogoutRRRt
BaseException(Rtstatus((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyR,ds



cC`si|jdk	re|jr%|j�n|jtj|jjtjd��\}}d|_||fSdS(s@
        This function will logout of the FortiManager.
        s
sys/logoutN(	tsidR
tuses_workspacet
run_unlockR(RR)RR*(Rtret_codeR"((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyR3ws	
!	c	C`sjy6|jdkr5|dddkr5td��nWn9tk
rUtd��ntk
rqtd��nX|j�i|d6|d6|jd	6|jd
6dd6}tj|d
t	�j
dd�}yx|jjdt
|j�dt
|�dt�\}}tjt
|j���}|j||j|�|j|�SWntk
re}t|��nXdS(s�
        Responsible for actual sending of data to the connection httpapi base plugin. Does some formatting as well.
        :param params: A formatted dictionary that was returned by self.common_datagram_params()
        before being called here.
        :param method: The preferred API Request method (GET, ADD, POST, etc....)
        :type method: basestring

        :return: Dictionary of status, if it logged in or not.
        iturlssys/login/usersDAn attempt was made to login with the SID None and URL != login url.skAn attempt was made at communicating with a FMG with no valid session and an incorrectly formatted request.smAn attempt was made at communicating with a FMG with no valid session and an unexpected error was discovered.tmethodtparamstsessiontiditverbosetensure_asciis\\s\tpathtdatatheadersN(R6R
Rt
IndexErrort	Exceptiont_update_request_idtreq_idtjsontdumpsRtreplaceRtsendRRRtloadstgetvaluet_update_self_from_responset_handle_response(	RR;R<tjson_requestRBR"R#tresultterr((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyR(�s.#





!'cC`ss|j|�t|dt�r1|dd}n
|d}d|kr]|dd|dfS|dd|fSdS(NRQiRBR5tcode(t_set_sidt
isinstanceR(RR"RQ((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyRO�s

cC`s~||_t|dt�r-|dd}n
|d}d|krz|dd|_|dd|_||_||_ndS(NRQiR5RStmessage(RRURRRRR(RR"R:RBRQ((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyRN�s	
	cC`s/|jdkr+d|kr+|d|_ndS(NR=(R6R
(RR"((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyRT�scC`s8y|jr|jSWntk
r3td��nXdS(s[
        Returns the data stored under self._connected_fmgr

        :return: dict
        s&Couldn't Retrieve Connected FMGR StatsN(RR4R(R((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pytreturn_connected_fmgr�s
	
cC`s+|jtj|jjtjd��}|S(sz
        Returns the system status page from the FortiManager, for logging and other uses.
        return: status
        s
sys/status(R(RtGETRR*(RR5((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyR2�s'cC`s|jS(N(R(R((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pytdebug�scC`s
||_dS(N(R(Rtval((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyRY�scC`s|jS(N(R(R((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyRG�scC`s
||_dS(N(R(RRZ((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyRG�sicC`s&|dkr|n
|jd|_dS(Nii(RG(Rtreqid((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyRF�scC`s|jS(N(R(R((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyR6�scC`s
||_dS(N(R(RRZ((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyR6�scC`s9|jdk	r5|jjdk	r5dt|jj�SdS(Ns/FortiManager object connected to FortiManager: sIFortiManager object with no valid connection to a FortiManager appliance.(R6R
RRtstr(R((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyR+�s!cC`s|jS(N(R(R((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyR7�scC`s
||_dS(N(R(RRZ((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyR7scC`s|jS(N(R(R((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyt
uses_adomsscC`s
||_dS(N(R(RRZ((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyR]scC`s&||jkr"|jj|�ndS(N(Rtappend(Rtadom((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pytadd_adom_to_lock_listscC`s&||jkr"|jj|�ndS(N(Rtremove(RR_((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pytremove_adom_from_lock_listscC`s�d}|jtj|jjtj|dddg��\}}y |ddkr^t|_nWntk
r{t|_nXy |ddkr�t|_	nWntk
r�t|_	nXdS(sC
        Checks FortiManager for the use of Workspace mode
        s/cli/global/system/globaltfieldssworkspace-modesadom-statusiiN(
R(RRXRR*tTrueR7tKeyErrorRR](RR:RStresp_obj((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyR1s!


cC`s%x|jD]}|j|�q
WdS(sC
        Checks for ADOM status, if locked, it will unlock
        N(Rtunlock_adom(Rtadom_locked((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyR8*scO`s�|r6|j�dkr!d}q<djd|�}nd}|jtj|jjtj|��\}}|dkr�|ddj�d	kr�|j|�n||fS(
s+
        Locks an ADOM for changes
        tglobals/dvmdb/global/workspace/lock/s"/dvmdb/adom/{adom}/workspace/lock/R_s/dvmdb/adom/root/workspace/lockiR5RVtok(tlowertformatR(RR)RR*R`(RR_targstkwargsR:RStrespobj((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyt	lock_adom1s	-&cO`s�|r6|j�dkr!d}q<djd|�}nd}|jtj|jjtj|��\}}|dkr�|ddj�d	kr�|j|�n||fS(
s/
        Unlocks an ADOM after changes
        Ris/dvmdb/global/workspace/unlock/s$/dvmdb/adom/{adom}/workspace/unlock/R_s!/dvmdb/adom/root/workspace/unlockiR5RVRj(RkRlR(RR)RR*Rb(RR_RmRnR:RSRo((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyRgAs	-&cO`s||rQ|r!djd|�}qW|j�dkr<d}qWdjd|�}nd}|jtj|jjtj|��S(s,
        Commits changes to an ADOM
        s'/pm/config/adom/{adom}/workspace/commitR_Ris/dvmdb/global/workspace/commit/s#/dvmdb/adom/{adom}/workspace/commits!/dvmdb/adom/root/workspace/commit(RlRkR(RR)RR*(RR_tauxRmRnR:((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pytcommit_changesQs	N( t__name__t
__module__RR!R$R/R,R3R(RORNRTRWR2tpropertyRYtsetterRGRFR6R+R7R]R`RbR1R8R
RpRgRRr(((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyR	-s>								)											(t
__future__RRRttypet
__metaclass__t
DOCUMENTATIONRHtansible.plugins.httpapiRtansible.module_utils.basicRt0ansible.module_utils.network.fortimanager.commonRRRRR	(((sH/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortimanager.pyt<module>s

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]