This repository has been archived by the owner on Aug 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pf-gui.py
75 lines (54 loc) · 1.71 KB
/
pf-gui.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import pf
import time
from flask import *
app = Flask(__name__)
filter = pf.PacketFilter()
@app.route("/")
def index():
status = filter.get_status()
tables = filter.get_tables()
rules = filter.get_ruleset()
return render_template("index.html", tables=tables,
rules=rules, status=status)
@app.route("/disable")
def disable():
filter.disable()
flash("pf disabled")
return redirect(url_for('index'))
@app.route("/enable")
def enable():
filter.enable()
flash("pf enabled")
return redirect(url_for('index'))
@app.route("/rules/delete/<id>")
def delete_rule(id):
new_rs = filter.get_ruleset()
new_rs.remove(int(id))
filter.load_ruleset(new_rs, '')
flash("rule deleted")
return redirect(url_for('index'))
@app.route("/tables/<name>")
def tables(name):
addrs = filter.get_addrs(pf.PFTable(name))
stats = filter.get_tstats(pf.PFTable(name))
return render_template("tables.html", addrs=addrs, name=name, stats=stats)
@app.route('/tables/add/<name>', methods=['POST'])
def add_address_to_table(name):
filter.add_addrs(name, request.form['address'])
flash("Addres " + request.form['address'] + " added ")
return redirect(url_for('tables', name=name))
@app.route('/tables/clear_stats/<name>')
def clear_stats(name):
filter.clear_tstats(pf.PFTable(name))
flash("Stats cleared")
return redirect(url_for('tables', name=name))
@app.template_filter('format_time')
def format_time(timestamp):
return time.ctime(timestamp)
@app.template_filter('mbyte')
def mbyte(bytes):
return round(bytes / 1024.0 / 1024.0, 2)
if __name__ == "__main__":
app.debug = True
app.secret_key = 'some_secret'
app.run(host='0.0.0.0')