-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.cgi
111 lines (95 loc) · 2.48 KB
/
index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
import cgi
import cgitb; cgitb.enable(format='text') # for troubleshooting
import sqlite3
dbfile = "/var/dug/devices.sql"
print "Content-type: text/html"
print
print """
<html>
<head>
<title>Manage Dynamic Devices</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">
Dynamic User System
</div>
</div>
"""
#Print the menu
menu = open("menu.html", "r")
for line in menu:
print line
form = cgi.FieldStorage()
devicename = form.getvalue("devicename")
devicemac = form.getvalue("devicemac")
devicetag = form.getvalue("devicetag")
devicedelete = form.getvalue("devicedelete")
if (devicedelete):
print devicedelete
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
try:
cursor.execute('DELETE FROM DevicesDynamic WHERE DeviceName = ?', (devicedelete, ))
except sqlite3.Error as e:
print e.args[0]
conn.commit()
conn.close()
if (devicename and devicemac):
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
values = (devicename, devicemac, devicetag)
cursor.execute('INSERT INTO DevicesDynamic ("DeviceName", "DeviceMac", "Groups") VALUES (?,?,?)', values)
conn.commit()
conn.close()
print """
<div class="form1">
<form method="post" action="/cgi-bin/index.cgi">
<label>Name</label><br>
<input type="text" name="devicename"/><br>
<label>MAC Address</label><br>
<input type="text" name="devicemac"/><br>
<label>Group</label><br>
<input type="text" name="devicetag"/><br>
<input type="submit" value="Submit"/>
</form>
</div>
"""
conn = sqlite3.connect(dbfile)
cursor = conn.cursor()
cursor.execute('select DeviceName, DeviceMac, Groups from DevicesDynamic order by Groups')
rows = cursor.fetchall()
print """
<div class="form2">
<form method="post" action="/cgi-bin/index.cgi">
<table>
<col class="radiocolumn" />
<col class="datacolumn" />
<col class="datacolumn" />
<col class="datacolumn" />
<tr>
<th>Delete</th>
<th>Device Name</th>
<th>MAC Address</th>
<th>Group</th>
</tr>
"""
for row in rows:
print ' <tr><td align="center"><input type="radio" name="devicedelete" value="%s"/></td>' % (row[0], )
for field in row:
print " <td>%s</td>" % (field, )
print " </tr>"
conn.close()
print """
</table>
<input type="submit" value="Submit">
</form>
</div>
</body>
</html>
"""