A simple web portal for Linux iptables
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

#!/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:
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'
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))
print('Allowed {0} for {1}h {2}m'.format(mac[0], h, m))
return 'Success!'
if __name__ == '__main__':
app.run(host="", port="81")