-
Notifications
You must be signed in to change notification settings - Fork 7
/
changes.cgi
78 lines (65 loc) · 2 KB
/
changes.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
import cgi
import cgitb; cgitb.enable(format='text') # for troubleshooting
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
import xml.etree.ElementTree as ET
import sys
sys.path.insert(0, '/var/dug/')
import fw_creds
fwhost = fw_creds.fwhost
fwkey = fw_creds.fwkey
from xmldiff import main, formatting
formatter = formatting.XMLFormatter()
print "Content-type: text/html"
print
print """
<html>
<head>
<title>Pending Changes</title>
<link rel="stylesheet" href="/style.css" type="text/css">
</head>
<body>
<div class="titleblock">
<div class="image">
<img src="/logo.svg" height="75px">
</div>
<div class="text">
Pending Changes
</div>
</div>
"""
#Print the menu
menu = open("menu.html", "r")
for line in menu:
print line
print('<div class="response"><pre>')
#Get running config
values = {'type': 'op', 'cmd': '<show><config><running/></config></show>', 'key': fwkey}
palocall = 'https://%s/api/' % (fwhost, )
try:
response = requests.post(palocall, data=values, verify=False)
tree = ET.fromstring(response.text)
runningconfig = tree.find('./result/config')
except Exception as error:
print(error)
runningconfig = False
#Get candidate config
values = {'type': 'op', 'cmd': '<show><config><candidate/></config></show>', 'key': fwkey}
palocall = 'https://%s/api/' % (fwhost, )
try:
response = requests.post(palocall, data=values, verify=False)
tree = ET.fromstring(response.text)
candidateconfig = tree.find('./result/config')
except Exception as error:
print(error)
candidateconfig = False
if runningconfig and candidateconfig:
diffs = main.diff_texts(ET.tostring(runningconfig), ET.tostring(candidateconfig), formatter=formatter)
for line in diffs.split("\n"):
if "diff:" in line:
print('<font color="red">%s</font>' % (line.replace("<", "<").replace(">", ">"), ))
else:
print(line.replace("<", "<").replace(">", ">"))
print('</pre>')