Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, urllib2, urllib
- from xml.etree.cElementTree import tostring, ElementTree
- def updateFirewall(url):
- # Getting the username and password from the user
- username = sys.argv[1]
- password = sys.argv[2]
- # Auth and getting key
- values = {"type":"keygen", "user":username, "password":password}
- data = urllib.urlencode(values)
- req = urllib2.Request(url, data)
- response = urllib2.urlopen(req)
- response_body = response.read()
- key = ElementTree(response_body).find('//key/text()')
- # reading the elements we need to add to the existing config
- with open('policy.xml', 'rt') as f:
- tree = ElementTree.parse(f)
- services = tree.find("/config/devices/entry/vsys/entry/service")
- security_rules = tree.find("/config/devices/entry/vsys/entry/rulebase/security")
- default_security_rules = tree.find("/config/devices/entry/vsys/entry/rulebase/default-security-rules")
- # adding services
- values1 = {"type":"config", "key":key, "action":"edit", "xpath":"/config/devices/entry/vsys/entry/service", "element":services}
- data1 = urllib.urlencode(values1)
- serviceResponse = urllib2.Request(url, data1)
- # adding the security rules
- values2 = {"type":"config", "key":key, "action":"edit", "xpath":"/config/devices/entry/vsys/entry/rulebase/security", "element":security_rules}
- data2 = urllib.urlencode(values2)
- secRulesResonse = urllib2.Request(url, data2)
- # adding the default security rules
- values3 = {"type":"config", "key":key, "action":"edit", "xpath":"/config/devices/entry/vsys/entry/rulebase/default-security-rules", "element":default_security_rules}
- data3 = urllib.urlencode(values3)
- secRulesResonse = urllib2.Request(url, data3)
- url = "https://192.168.10.1/api/"
- updateFirewall(url)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement