Add form for editing ipsets
This commit is contained in:
parent
a5df435931
commit
5add39a8a7
7 changed files with 88 additions and 4 deletions
32
web/ipsets.py
Normal file
32
web/ipsets.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
import json
|
||||
|
||||
import flask
|
||||
import flask_login
|
||||
|
||||
from . import db
|
||||
from . import system
|
||||
|
||||
blueprint = flask.Blueprint('ipsets', __name__, url_prefix='/ipsets')
|
||||
|
||||
@blueprint.route('/', methods=('GET', 'POST'))
|
||||
@flask_login.login_required
|
||||
def index():
|
||||
if not flask_login.current_user.is_admin:
|
||||
return flask.Response('forbidden', status=403, mimetype='text/plain')
|
||||
|
||||
with db.locked():
|
||||
ipsets = db.read('ipsets')
|
||||
networks = db.read('networks')
|
||||
if flask.request.method == 'POST':
|
||||
form = flask.request.form
|
||||
ipsets = {}
|
||||
for name, ip, ip6 in zip(form.getlist('name'), form.getlist('ip'), form.getlist('ip6')):
|
||||
if name and name not in networks:
|
||||
ipsets[name] = {
|
||||
'ip': ip.split(),
|
||||
'ip6': ip6.split()
|
||||
}
|
||||
db.write('ipsets', ipsets)
|
||||
system.run(system.save_config)
|
||||
return flask.redirect(flask.url_for('ipsets.index'))
|
||||
return flask.render_template('ipsets/index.html', ipsets=ipsets)
|
Loading…
Add table
Add a link
Reference in a new issue