HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //lib/python2.7/site-packages/lap/FgSNMP.py
import subprocess

class SimpleSNMP():
    '''Minimal SNMP call from python'''

    def walk(self, options):
        command = "snmpwalk {0}".format(options)
        walk = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        output, err = walk.communicate()
        return(output)


class FortiGet:
    '''Simple class to fetch snmp infos from fortigate'''

    def __init__(self):
        self.lastfield = lambda output: output.split()[-1]


    def get_data(self, snmpclient, user, password, host, oid):
        walk = snmpclient.walk("-v3 -u {0} -a MD5 -A {1} -l authPriv -X {2} {3} {4}".format(user, password, password, host, oid))
        return(walk)


    def get_all_vpn_ids(self, snmpclient, user, password, host):
        walk = self.get_data(snmpclient, user, password, host, "FORTINET-FORTIGATE-MIB::fgVpnTunEntIndex")
        ids = [x.split()[-1] for x in walk.split("\n") if x != ""]
        return(ids)


    def get_quantity_vdom(self, snmpclient, user, password, host):
        quantity = self.get_data(snmpclient, user, password, host, "FORTINET-FORTIGATE-MIB::fgVdNumber")
        return(self.lastfield(quantity))


    def get_max_vdoms(self, snmpclient, user, password, host):
        maxvdoms = self.get_data(snmpclient, user, password, host, "FORTINET-FORTIGATE-MIB::fgVdMaxVdoms")
        return(self.lastfield(maxvdoms))


    def get_vpn_status(self, vpnid, snmpclient, user, password, host):
        oid = "FORTINET-FORTIGATE-MIB::fgVpnTunEntStatus.{0}".format(vpnid) 
        status = self.get_data(snmpclient, user, password, host, oid)
        return(self.lastfield(status))


    def get_vpn_phase_name(self, vpnid, phase, snmpclient, user, password, host):
        oid = "FORTINET-FORTIGATE-MIB::fgVpnTunEntPhase{0}Name.{1}".format(phase, vpnid)
        vpnname = self.get_data(snmpclient, user, password, host, oid)
        return(self.lastfield(vpnname))


    def get_vdomid(self, vpnid, snmpclient, user, password, host):
        oid = "FORTINET-FORTIGATE-MIB::fgVpnTunEntVdom.{0}".format(vpnid)
        vdom = self.get_data(snmpclient, user, password, host, oid)
        return(self.lastfield(vdom))


    def get_vdom_name(self, vdomid, snmpclient, user, password, host):
        oid = "FORTINET-FORTIGATE-MIB::fgVdEntName.{0}".format(vdomid)
        vdomname = self.get_data(snmpclient, user, password, host, oid)
        return(self.lastfield(vdomname))