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/fortianalyzer.pyo

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

N(tHttpApiBase(tto_text(tBASE_HEADERS(tFAZBaseException(t	FAZCommon(t
FAZMethodstHttpApicB`s�eZd�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�Zd#d �Z d!�Z!d"�Z"RS($cC`s�tt|�j|�d|_d|_d|_d|_t|_	t
|_d|_d|_
d|_d|_d|_d|_t�|_t�|_t
|_t
|_t�|_d|_dS(Nis/jsonrpc(tsuperR	t__init__t_req_idtNonet_sidt_urlt_hostRt_toolstFalset_debugt_connected_fazt_last_response_msgt_last_response_codet_last_data_payloadt	_last_urlt_last_response_rawtlistt_locked_adom_listt_locked_adoms_by_usert_uses_workspacet_uses_adomst
_adom_listt_logged_in_user(tselft
connection((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR.s&														cC`sdS(s�
        ELEVATION IS NOT REQUIRED ON FORTINET DEVICES - SKIPPED
        :param become_context: Unused input.
        :return: None
        N(R
(R!tbecome_context((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyt
set_becomeCscC`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
(R!tresponset
response_data((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pytupdate_authKsc	C`sm||_|jtj|jjtjdd|d|��d|j�krZ|j�dStdd��dS(s
        This function will log the plugin into FortiAnalyzer, and return the results.
        :param username: Username of FortiAnalyzer Admin
        :param password: Password of FortiAnalyzer Admin

        :return: Dictionary of status, if it logged in or not.
        ssys/login/usertpasswdtusers/FortiAnalyzer object connected to FortiAnalyzerNtmsgsWUnknown error while logging in...connection was lost during login operation.... Exiting(	R tsend_requestRtEXECRtformat_requestt__str__tinspect_fazR(R!tusernametpassword((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pytloginTs		!
cC`s�|j�}|ddkr8|j�tdd��n~|ddkr�yW|j�|jrk|j�n|jr�|j�n|d|_|jd|_	Wq�t
k
r�q�XndS(Nii����R*sRError -11 -- the Session ID was likely malformed somehow. Contact authors. ExitingitHostname(tget_system_statustlogoutRt
check_modeRt
get_adom_listRtget_locked_adom_listRRt
BaseException(R!tstatus((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR/is 

	
	


cC`ss|jdk	ro|jr/|j�|j�n|jtj|jj	tjd��\}}d|_||fSdS(sA
        This function will logout of the FortiAnalyzer.
        s
sys/logoutN(
tsidR
tuses_workspacet
get_lock_infot
run_unlockR+RR,RR-(R!tret_codeR%((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR5~s	

!	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 FAZ with no valid session and an incorrectly formatted request.smAn attempt was made at communicating with a FAZ with no valid session and an unexpected error was discovered.tmethodtparamstsessiontiditverbosetensure_asciis\\s\tpathtdatatheadersN(R;R
Rt
IndexErrort	Exceptiont_update_request_idtreq_idtjsontdumpsRtreplaceR"tsendRRRtloadstgetvaluet_update_self_from_responset_handle_response(	R!RARBtjson_requestRHR%R&tresultterr((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR+�s.#





!'cC`ss|j|�t|dt�r1|dd}n
|d}d|kr]|dd|dfS|dd|fSdS(NRWiRHR:tcode(t_set_sidt
isinstanceR(R!R%RW((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyRU�s

cC`s~||_t|dt�r-|dd}n
|d}d|krz|dd|_|dd|_||_||_ndS(NRWiR:RYtmessage(RR[RRRRR(R!R%R@RHRW((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyRT�s	
	cC`s/|jdkr+d|kr+|d|_ndS(NRC(R;R
(R!R%((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyRZ�scC`s8y|jr|jSWntk
r3td��nXdS(sZ
        Returns the data stored under self._connected_faz

        :return: dict
        s%Couldn't Retrieve Connected FAZ StatsN(RR9R(R!((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pytreturn_connected_faz�s
	
cC`s+|jtj|jjtjd��}|S(s{
        Returns the system status page from the FortiAnalyzer, for logging and other uses.
        return: status
        s
sys/status(R+RtGETRR-(R!R:((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR4�s'cC`s|jS(N(R(R!((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pytdebug�scC`s
||_dS(N(R(R!tval((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR_�scC`s|jS(N(R(R!((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyRM�scC`s
||_dS(N(R(R!R`((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyRM�sicC`s&|dkr|n
|jd|_dS(Nii(RM(R!treqid((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyRL�scC`s|jS(N(R(R!((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR;�scC`s
||_dS(N(R(R!R`((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR;�scC`s9|jdk	r5|jjdk	r5dt|jj�SdS(Ns1FortiAnalyzer object connected to FortiAnalyzer: sKFortiAnalyzer object with no valid connection to a FortiAnalyzer appliance.(R;R
R"Rtstr(R!((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR.�s!cC`s|jS(N(R(R!((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR<scC`s
||_dS(N(R(R!R`((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR<scC`s|jS(N(R(R!((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyt
uses_adomsscC`s
||_dS(N(R(R!R`((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyRcscC`s&||jkr"|jj|�ndS(N(Rtappend(R!tadom((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pytadd_adom_to_lock_listscC`s&||jkr"|jj|�ndS(N(Rtremove(R!Re((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pytremove_adom_from_lock_listscC`s d}|jtj|jjtj|dddg��\}}y<|ddkr^t|_n|ddkrzt|_nWn9tk
r�t|_n t	k
r�t
dd��nXy)|dd
kr�t|_n	t|_Wn9tk
r�t|_n t	k
rt
dd��nXdS(sD
        Checks FortiAnalyzer for the use of Workspace mode
        s/cli/global/system/globaltfieldssworkspace-modesadom-statustworkflowtdisabledR*s/Couldn't determine workspace-mode in the pluginitenables,Couldn't determine adom-status in the pluginN(iRl(R+RR^RR-tTrueR<RtKeyErrorR9RRc(R!R@RYtresp_obj((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR6 s,




cC`s/x(|jD]}|d}|j|�q
WdS(sC
        Checks for ADOM status, if locked, it will unlock
        ReN(Rtunlock_adom(R!tadom_lockedRe((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR><s
cO`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/Res/dvmdb/adom/root/workspace/lockiR:R\tok(tlowertformatR+RR,RR-Rf(R!RetargstkwargsR@RYtrespobj((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyt	lock_adomDs	-&cO`s�|r6|j�dkr!d}q<djd|�}nd}|jtj|jjtj|��\}}|dkr�|ddj�d	kr�|j|�n||fS(
s/
        Unlocks an ADOM after changes
        Rrs/dvmdb/global/workspace/unlock/s$/dvmdb/adom/{adom}/workspace/unlock/Res!/dvmdb/adom/root/workspace/unlockiR:R\Rs(RtRuR+RR,RR-Rh(R!ReRvRwR@RYRx((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyRpTs	-&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/commitReRrs/dvmdb/global/workspace/commit/s#/dvmdb/adom/{adom}/workspace/commits!/dvmdb/adom/root/workspace/commit(RuRtR+RR,RR-(R!RetauxRvRwR@((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pytcommit_changesds	cC`s|s|dkrd}n-|j�dkr7d}ndjd|�}i}|jjtj||�}|jtj|�}|d}|dkr�|jjdd	t	|��nX|dkr
y(|d
ddd
kr�d|_nWq
tk
r	|d
|_q
Xn|S(s�
        Gets ADOM lock info so it can be displayed with the error messages. Or if determined to be locked by ansible
        for some reason, then unlock it.
        troots#/dvmdb/adom/root/workspace/lockinfoRrs!/dvmdb/global/workspace/lockinfo/s&/dvmdb/adom/{adom}/workspace/lockinfo/ReiR*s;An error occurred trying to get the ADOM Lock Info. Error: iR:R\tOKN(
RtRuRR-RR^R+t_modulet	fail_jsonRbR
t
_lock_infoR9(R!ReR@tdatagramRHRoRY((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR=ts$		
 
c	C`s�|jr�d}i}|jjtj||�}|jtj|�}|d}|dkr{|jjddt|��np|dkr�t	|d�}dg}x<|dD]0}|ddkr�|j
t|d	��q�q�W||_n|Sd
S(s>
        Gets the list of ADOMs for the FortiAnalyzer
        s/dvmdb/adomiR*s6An error occurred trying to get the ADOM Info. Error: iR|t
tab_statusttnameN(RcRR-RR^R+R~RRbtlenRdR(	R!R@R�RHRoRYtnum_of_adomstappend_listRe((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR7�s 	
 	cC`sVy#t�}t�}x�|jD]�}|jd|�}y"|ddddkrXwnWntk
rlnXy}|dddr�|jt|��n|ddd|jkr�|jit|�d6t|ddd�d6�nWqtk
r}t|��qXqW||_||_	Wn,tk
rQ}td	d
t|���nXdS(s/
        Gets the list of locked adoms
        ReiR:R\R}it	lock_userR)R*sCAn error occurred while trying to get the locked adom list. Error: N(
RRR=R9RdRbR RRR(R!tlocked_listtlocked_by_user_listRetadom_lock_infoRX((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR8�s,		

:	
	N(#t__name__t
__module__RR$R'R2R/R5R+RURTRZR]R4tpropertyR_tsetterRMRLR;R.R<RcRfRhR6R>R
RyRpRR{R=R7R8(((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyR	-sD								)												(t
__future__RRRttypet
__metaclass__t
DOCUMENTATIONRNtansible.plugins.httpapiRtansible.module_utils.basicRt1ansible.module_utils.network.fortianalyzer.commonRRRRR	(((sI/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/fortianalyzer.pyt<module>s

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