|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from flask import Flask, render_template, request, url_for
|
|
|
|
import logic
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
@app.route('/remove', methods=['GET'])
|
|
|
|
def remove():
|
|
|
|
macs = logic.get_known_macs()
|
|
|
|
return render_template('remove.html', macs=macs)
|
|
|
|
|
|
|
|
@app.route('/removed', methods=['POST'])
|
|
|
|
def removed():
|
|
|
|
macs = request.form.getlist('mac')
|
|
|
|
print('Macs: {}'.format(macs))
|
|
|
|
for mac in macs:
|
|
|
|
logic.remove_mac_address(mac)
|
|
|
|
print('Removed {}'.format(mac))
|
|
|
|
return 'Success!'
|
|
|
|
|
|
|
|
@app.route('/', methods=['GET'])
|
|
|
|
def form():
|
|
|
|
macs = logic.get_unknown_macs()
|
|
|
|
return render_template('portal.html', macs=macs)
|
|
|
|
|
|
|
|
@app.route('/submit', methods=['POST'])
|
|
|
|
def submit():
|
|
|
|
macs = request.form.getlist('mac')
|
|
|
|
print('Macs: {}'.format(macs))
|
|
|
|
duration_type = request.form['duration_type']
|
|
|
|
print('Duration Type: {}'.format(duration_type))
|
|
|
|
comments = request.form.getlist('comment')
|
|
|
|
comments = [ c for c in comments if c ]
|
|
|
|
|
|
|
|
if len(macs) != len(comments):
|
|
|
|
return 'Some macs doesn\'t have their owners written!'
|
|
|
|
if duration_type == 'permanent':
|
|
|
|
expire = 'never'
|
|
|
|
else:
|
|
|
|
h = request.form['duration_h']
|
|
|
|
if not h:
|
|
|
|
h = 0
|
|
|
|
m = request.form['duration_m']
|
|
|
|
if not m:
|
|
|
|
m = 0
|
|
|
|
expire = 3600 * int(h) + 60 * int(m)
|
|
|
|
print('Duration: {}'.format(expire))
|
|
|
|
|
|
|
|
mac_comm = list(zip(macs, comments))
|
|
|
|
for mac in mac_comm:
|
|
|
|
logic.allow_mac_address(mac[0], expire, mac[1])
|
|
|
|
if expire == 'never':
|
|
|
|
print('Allowed {0} forever'.format(mac[0], expire))
|
|
|
|
else:
|
|
|
|
print('Allowed {0} for {1}h {2}m'.format(mac[0], h, m))
|
|
|
|
return 'Success!'
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(host="172.16.88.25", port="81")
|