Example #1
0
#!/usr/bin/python3.6

from ftntlib import FortiManagerJSON

ip = '10.20.30.31'
login = '******'
password = '******'

url = 'sys/proxy/json'
resource = "/api/v2/monitor/user/detected-device/select?&vdom=root&expand_child_macs=true&with_fortilink=true&with_fortiap=true&with_endpoint=true&with_dhcp=true&width_user=true"

data = {
    'target': ["adom/root/device/OT60FR"],
    'action': 'get',
    'resource': resource
}

api = FortiManagerJSON()
api.login(ip, login, password)
api.debug('on')
status, mydata = api.execute(url, data)
print(mydata[0]['response']['results'])
api.debug('off')
api.logout()
Example #2
0
                        '--version',
                        action='version',
                        version='%(prog)s {}'.format(__version__))
    args = parser.parse_args()

    ip = args.ip
    login = args.login
    password = args.password
    adom = args.adom
    what_to_replace = args.source
    replace_with = args.destination

    if password == None:
        password = getpass.getpass()

    api = FortiManagerJSON()
    api.verbose('on')

    response = api.login(ip, login, password)
    if response[0]['code'] != 0:
        my_print("Login", "Wrong credentials", newline=False)
        check_response(response)
        my_print("Login", "Exiting...")
        quit()

    category_urls = {
        140: {
            'name': 'firewall address',
            'url': '/pm/config/adom/{}/obj/firewall/address/{}',
        },
        142: {
Example #3
0
def main(argv):
    me, objip = argv
    addrgrp = 'Block_SSH'
    package = 'Edge/edge-fw_ITS_Link'
    adom = '54Devices'
    urlpf = 'pm/config/adom/' + adom
    api = FortiManagerJSON()
    api.debug('on')
    api.login(ip, user, pwd)

    objname = 'h_' + objip

    code, d = api.get(urlpf + '/obj/firewall/addrgrp/' + addrgrp)

    if type(d['member']) is list:
        member = d['member']
    if objname not in member:
        print('Host is not in block group!')
        return
    else:
        member.remove(objname)
    data = {'member': member}
    api.update(urlpf + '/obj/firewall/addrgrp/' + addrgrp, data)

    scope = [{'name': 'All_FortiGate'}]
    flags = ['install_chg', 'generate_rev']
    ret_code, response = api.install_package(adom, package, scope, flags)
    api.logout()
    api.debug('off')
    return
def _ban(argv):
    me, objip, push = argv
    addrgrp = 'Block_SSH'
    package = 'Edge/edge-fw_ITS_Link'
    adom = '54Devices'
    urlpf = 'pm/config/adom/' + adom
    api = FortiManagerJSON()
    api.debug('on')
    api.login(ip, user, pwd)

    objname = 'h_' + objip
    obj = {
        'name': objname,
        'type': 'ipmask',
        'color': 13,
        'subnet': [objip, '255.255.255.255']
    }
    api.add(urlpf + '/obj/firewall/address', obj)

    code, d = api.get(urlpf + '/obj/firewall/addrgrp/' + addrgrp)

    if type(d['member']) is list:
        member = d['member']
    if objname not in member:
        member.append(objname)
    else:
        member = [d['member'], objname]
    data = {'member': member}
    api.update(urlpf + '/obj/firewall/addrgrp/' + addrgrp, data)

    if push == "push":
        scope = [{'name': 'All_FortiGate'}]
        flags = ['install_chg', 'generate_rev']
        ret_code, response = api.install_package(adom, package, scope, flags)
    api.logout()
    api.debug('off')
    return
Example #5
0
        print('=' * (l_result + r_result + 7))
        for key in self._adomdb:
            print(string.format(key, self._adomdb[key]))
            total = total + self._adomdb[key]

        print('=' * (l_result + r_result + 7))
        print(string.format('TOTAL', total))


if __name__ == '__main__':
    #ip = '10.210.35.200'
    ip = '10.210.34.241'
    login = '******'
    password = '******'

    api = FortiManagerJSON()
    api.login(ip, login, password)

    adom = "LDL-FR"
    au = AdomUsage(adom, api)

    au.count('/firewall/address')
    au.count('/firewall/address6')
    au.count('/firewall/addrgrp')
    au.count('/firewall/addrgrp6')
    au.count('/firewall/vip')
    au.count('/firewall/vipgrp')
    au.count('/firewall/service/custom')
    au.count('/firewall/schedule/onetime')
    au.count('/webfilter/profile')
    au.count('/ips/sensor')
Example #6
0
File: main.py Project: SelR4c/ztp
def main():
    log = logging.getLogger()
    logging.basicConfig(stream=sys.stdout, level=log_level)
    log.info(
        "\n\n<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Fortinet SD-WAN Zero Touch Provisionning Tool <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"
    )

    parser = argparse.ArgumentParser(description='ZTP FMG fortinet')
    parser.add_argument('-f',
                        '--file',
                        help='excel file to import data from',
                        required=True)
    parser.add_argument('-i', '--ip', help='Fortimanager IP', required=True)
    parser.add_argument('-u',
                        '--user',
                        help='Fortimanager Username',
                        default="admin")
    parser.add_argument('-p', '--password', help='Fortimanager password')

    args = parser.parse_args()

    if args.password is None:
        try:
            args.password = getpass.getpass()
        except Exception as error:
            log.error(str(error.args))

    device_list = []
    api = FortiManagerJSON()
    api.login(args.ip, args.user, args.password)
    log.info("Logging to Fortimanager at {ip}".format(ip=args.ip))
    api.verbose('off')
    api.debug('on')

    fmg_gui = FortiManagerGUI(args.ip)
    fmg_gui.login(args.user, args.password)

    # read values from CSV
    load_value(args.file, device_list)

    log.info("Starting import...\n")

    # loop to wait for new unauthorized device
    if len(device_list) > 0:
        log.debug(len(device_list))
        wait_and_registered_new_devices(api, fmg_gui, device_list)

    # first loop for model device
    for device in device_list:
        success = True  # TODO
        if str(device.model_device).lower() == "yes":
            if device.type == "FGT":
                success = device.add_model_device(api)
            elif device.type == "FAP":
                success = device.add_fap_to_fmg(api)
            elif device.type == "FSW":
                success = device.add_fsw_to_fmg(api)

            if success:
                device_list.remove(device)

    api.logout()
Example #7
0
        l = l.split(',')
        self.data = {
            "url": l[0],
            "type": l[1],
            "action": l[2],
            "status": l[3],
            "referrer-host": l[4]
        }


if __name__ == '__main__':
    ip = '192.168.244.200'
    login = '******'
    password = '******'

    fmg = FortiManagerJSON()
    fmg.verbose('on')
    fmg.skip('off')

    f = open('data.csv')

    for line in f:
        line = line.strip()
        if re.match('^#.*$', line):
            next
        else:
            entry = Entry(line)
            print entry

    adom = 'CM-LAB-003'
    fmg.login(ip, login, password)
Example #8
0
from ftntlib import FortiManagerJSON


class FmgObject:
    def __init__(self):
        pass


if __name__ == '__main__':

    ip = '192.168.244.200'
    login = '******'
    password = '******'

    fmg = FortiManagerJSON()
    fmg.verbose('on')
    fmg.login(ip, login, password)

    adom = 'CM-LAB-001'

    path = 'pm/config/adom/{0}/obj/firewall/address'.format(adom)
    payload = {}

    response = fmg.get(path, payload)

    data = response[1]

    if type(data) is list:
        print "coucou"
        for item in data: