-
Notifications
You must be signed in to change notification settings - Fork 7
/
dhcp.cgi
80 lines (68 loc) · 1.98 KB
/
dhcp.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
79
80
#!/usr/bin/env python
import cgi
import cgitb; cgitb.enable(format='text') # for troubleshooting
import sys
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
import xml.etree.ElementTree as ET
sys.path.insert(0, '/var/dug/')
import fw_creds
fwhost = fw_creds.fwhost
fwkey = fw_creds.fwkey
print "Content-type: text/html"
print
print """
<html>
<head>
<title>DHCP Leases</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">
DHCP Leases
</div>
</div>
"""
#Print the menu
menu = open("menu.html", "r")
for line in menu:
print line
print '<div class="response">'
values = {'type': 'op', 'cmd': '<show><dhcp><server><lease><interface>all</interface></lease></server></dhcp></show>', 'key': fwkey}
palocall = 'https://%s/api/' % (fwhost)
r = requests.post(palocall, data=values, verify=False)
dhcptree = ET.fromstring(r.text)
print "<table cellpadding=5 cellspacing=0 border=1>"
print "<tr><td>IP</td><td>MAC</td><td>Hostname</td><td>State</td><td>Duration</td><td>Lease Time</td></tr>"
for lease in dhcptree.findall('./result/interface/entry'):
print "<tr>"
print "<td>%s</td>" % (lease.find('ip').text, )
print "<td>%s</td>" % (lease.find('mac').text, )
if lease.find('hostname') is not None:
print "<td>%s</td>" % (lease.find('hostname').text, )
else:
print "<td></td>"
if lease.find('state') is not None:
print "<td>%s</td>" % (lease.find('state').text, )
else:
print "<td></td>"
if lease.find('duration') is not None:
print "<td>%s</td>" % (lease.find('duration').text, )
else:
print "<td></td>"
if lease.find('leasetime') is not None:
print "<td>%s</td>" % (lease.find('leasetime').text, )
else:
print "<td></td>"
print "</tr>"
print "</table>"
print "</div>"
print """
</body>
</html>
"""