-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsearch1.cgi.save
executable file
·76 lines (68 loc) · 2.2 KB
/
fsearch1.cgi.save
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
#!/usr/bin/env python
#import sqlite3 as sq
import mysql.connector as mx
import sys
import cgi
import cgitb
cgitb.enable()
def htmltop():
print("""Content-type: text/html\r\n\r\n
<!DOCTYPE html><html><body>
<table border='1'><tr><th>STOVEPIPE</th><th>DATACENTER</th><th>VIRTUALSERVERNAME</th><th>FQDN</th><th>IPADDRESS</th><th>SERVICE PORT</th>
<th>SECURITY POLICY</th><th>DEVICE NAME</th></tr>""")
def htmltail():
print("""</body></html>""")
def connectdb():
mydb=mx.connect(host='localhost',user='root',passwd='Tulsi@991',database='searchdb')
cur=mydb.cursor()
return mydb,cur
def Blacklist(mydb,cur):
form = cgi.FieldStorage()
print ("form = ", form)
# print (form['valuetosearch'])
# if form.getvalue('valuetosearch'):
if form("search"):
valuetosearch = form.getvalue["valuetosearch"]
search = ['%UTC-A%']
query = "SELECT * from test WHERE (STOVEPIPE || DATACENTER || VSN || FQDN || IP || PORT || POLICY || DEVICE LIKE ?)";
result = cur.execute(query,search).fetchall()
#form.getvalue['valuetosearch'])
#result=cur.fetchall()
print(result)
print("here")
return result
print("connection established")
else:
print("Enter to search based on the below table:<br><br>")
#cur.execute(query)
#result=cur.fetchall()
#return result
def displaytest(result):
print("<table>")
for x in result:
print("<tr>")
print("<td> {0} </td>".format(x[0]))
print("<td> {0} </td>".format(x[1]))
print("<td> {0} </td>".format(x[2]))
print("<td> {0} </td>".format(x[3]))
print("<td> {0} </td>".format(x[4]))
print("<td> {0} </td>".format(x[5]))
print("<td> {0} </td>".format(x[6]))
print("<td> {0} </td>".format(x[7]))
print("</tr>")
print("</table>")
if __name__ == '__main__':
try:
htmltop()
print("<form action = '/cgi-bin/fsearch1.cgi' method = 'POST'>")
#print('<form action="" method="POST" enctype="multipart/form-data">')
print('<input type="text" name="valuetosearch" placeholder="Search">')
print('<input type="submit" name="search" value="Search"><br><br>')
print('</form>')
mydb,cur=connectdb()
result=Blacklist(mydb,cur)
displaytest(result)
cur.close()
htmltail()
except:
cgi.print_exception()