-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsid_checker.py
61 lines (52 loc) · 1.74 KB
/
sid_checker.py
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
import sqlite3 as sql
import os.path
from flask import Flask, render_template, request
import waitress
# Variables
db_name = './database.db'
### Flask app
app = Flask(__name__)
def db_check(sid_id):
if os.path.exists(db_name) == False:
print('ERROR: Can\'t find DB file')
else:
conn = sql.connect(db_name)
cur = conn.cursor()
try:
var = cur.execute('''SELECT sid, rule, ref FROM sids WHERE sid=?;''', (sid_id,))
rows = var.fetchall()
cur.close()
conn.close()
return rows
except:
print('ERROR:1a something when wrong')
cur.close()
conn.close()
return render_template('error.html', sid_id=sid_id) #Change this to an error page
@app.route('/')
def index():
return render_template('index.html')
@app.route('/search', methods=['POST', 'GET'])
def search():
if request.method == 'POST':
sid_id = request.form['sid_id']
# print(f'POST: {sid_id}')
rows = db_check(sid_id)
if rows != []:
return render_template('results.html', rows=rows)
else:
return render_template('error.html', sid_id=sid_id)
elif request.method == 'GET':
sid_id = request.args.get('sid_id')
# print(f'GET: {sid_id}')
db_check(sid_id)
rows = db_check(sid_id)
if rows != []:
return render_template('results.html', rows=rows)
else:
return render_template('error.html', sid_id=sid_id)
else:
print('ERROR:1b something when wrong')
# if __name__ == '__main__':
# app.run(host='0.0.0.0')
# waitress.serve(app, host='0.0.0.0' port=5000)