-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.py
49 lines (43 loc) · 1.49 KB
/
backend.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
from flask import Flask, request, jsonify, render_template, abort
import subprocess
import re
import db as database
from iptables import IPTables
from helper import Helper
app = Flask(__name__)
# create objects needed here
ipt = IPTables()
helper = Helper()
db = database.DB()
@app.route('/', methods=['GET', 'POST'], defaults={'path': ''})
@app.route('/<path:path>', methods=['GET', 'POST'])
def main_site(path):
# set signal tokens for the webinterface
token = False
iptoken = False
dbtoken = False
# try to get MAC (doesn't work on localhost connection)
mac = helper.getMAC(request.remote_addr)
# and send an 400 error if there is no client mac in arp table (like for localhost)
if not mac:
abort(400)
# this is the code which runs if the client accepts the tos
if request.method == 'POST':
token = True
try:
if not db.checkRecordExists(mac):
db.addMAC(mac, longterm=('longterm' in request.form))
if not ipt.unlockMAC(mac):
iptoken = True
token = False
# else:
# helper.rmtrack(request.remote_addr)
else:
token = False
dbtoken = True
except:
print("An unexpected error occurred!!! Please handle with it!")
raise
return render_template('toc.html', token = token, iptoken = iptoken, dbtoken = dbtoken, url = request.url)
if __name__ == "__main__":
pass