-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen.cgi
More file actions
83 lines (69 loc) · 2.19 KB
/
gen.cgi
File metadata and controls
83 lines (69 loc) · 2.19 KB
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
#! /Python/python
import cgi, cgitb
cgitb.enable()
def htmlTop():
print("""Content-type:text/html\r\n\r\n
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title> Object & ACL Generator </title>
</head>
<body><font face="consolas, arial, tahoma" color="black">""")
def htmlTail():
print("""</body>
</font>
</html>""")
if __name__ == "__main__":
try:
htmlTop()
form = cgi.FieldStorage()
dst = form.getvalue('dst')
dst_desc = form.getvalue('dst_desc')
src = form.getvalue('src')
src_desc = form.getvalue('src_desc')
port = form.getvalue('port')
newline = """<br>"""
if form.getvalue('src_mask'):
src_mask = form.getvalue('src_mask')
else:
src_mask = "0.0.0.0"
if form.getvalue('dst_mask'):
dst_mask = form.getvalue('dst_mask')
else:
dst_mask = "0.0.0.0"
src_cidr = sum([bin(int(x)).count("1") for x in src_mask.split(".")])
dst_cidr = sum([bin(int(x)).count("1") for x in dst_mask.split(".")])
if form.getvalue('logging'):
logging_flag = "logging"
else:
logging_flag = ""
if form.getvalue('inactive'):
inactive_flag = "inactive"
else:
inactive_flag = ""
if form.getvalue('protocol'):
protocol = form.getvalue('protocol')
else:
protocol = "--ERROR--"
#print("Logging is: " + (logging_flag))
#print(newline)
#print("ACL is: " + (inactive_flag))
print("<h3> !--Source </h3>")
print("object network " + str(src) + "_" + str(src_cidr))
print(newline)
print("network " + str(src) + " " + str(src_mask))
print(newline)
print("description " + str(src_desc))
print("<h3> !--Destination </h3>")
print("object network " + str(dst) + "_" + str(dst_cidr))
print(newline)
print(" network " + str(dst) + " " + str(dst_mask))
print(newline)
print("description " + str(dst_desc))
print(newline)
print("<h3> !--ACE </h3>")
print("access-list inside_access_in permit " + str(protocol) + " " + str(src) + " " + str(src_mask) + " " + str(dst) + " " + str(dst_mask) + " eq " + str(port) + " " + (logging_flag) + " " + (inactive_flag))
htmlTail()
except:
cgi.print_exception()