Development
This commit is contained in:
parent
d0cfffac52
commit
adcfe55c7c
24 changed files with 405 additions and 359 deletions
|
|
@ -2,7 +2,7 @@ import copy
|
|||
|
||||
from flask import Blueprint, request, redirect, flash
|
||||
from auth import require_level
|
||||
from config_utils import load_core, save_core_with_snapshot, verify_core_hash
|
||||
from config_utils import load_config, save_config_with_snapshot, verify_config_hash
|
||||
import sanitize
|
||||
import validation as validate
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ def _row_index():
|
|||
|
||||
|
||||
def _hash_ok():
|
||||
if not verify_core_hash(request.form.get('config_hash', '')):
|
||||
if not verify_config_hash(request.form.get('config_hash', '')):
|
||||
flash('Configuration was modified by another session. Please refresh and try again.', 'error')
|
||||
return False
|
||||
return True
|
||||
|
|
@ -47,17 +47,17 @@ def add_banned_ip():
|
|||
if not _hash_ok():
|
||||
return redirect(VIEW)
|
||||
|
||||
core = load_core()
|
||||
cfg = load_config()
|
||||
entry = {'description': description, 'ip': ip, 'enabled': True}
|
||||
core.setdefault('banned_ips', []).append(entry)
|
||||
errors = validate.validate_config(core)
|
||||
cfg.setdefault('banned_ips', []).append(entry)
|
||||
errors = validate.validate_config(cfg)
|
||||
if errors:
|
||||
for msg in errors:
|
||||
flash(msg, 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
flash(save_core_with_snapshot(
|
||||
core,
|
||||
flash(save_config_with_snapshot(
|
||||
cfg,
|
||||
path='banned_ips', key=ip, operation='add',
|
||||
before=None, after=entry,
|
||||
description=f'Added banned IP: {ip}',
|
||||
|
|
@ -75,23 +75,23 @@ def toggle_banned_ip():
|
|||
if not _hash_ok():
|
||||
return redirect(VIEW)
|
||||
|
||||
core = load_core()
|
||||
items = core.get('banned_ips', [])
|
||||
cfg = load_config()
|
||||
items = cfg.get('banned_ips', [])
|
||||
if idx < 0 or idx >= len(items):
|
||||
flash('Entry not found.', 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
old_enabled = items[idx].get('enabled', True)
|
||||
items[idx]['enabled'] = not old_enabled
|
||||
errors = validate.validate_config(core)
|
||||
errors = validate.validate_config(cfg)
|
||||
if errors:
|
||||
for msg in errors:
|
||||
flash(msg, 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
action = 'Enabled' if not old_enabled else 'Disabled'
|
||||
flash(save_core_with_snapshot(
|
||||
core,
|
||||
flash(save_config_with_snapshot(
|
||||
cfg,
|
||||
path='banned_ips', key=items[idx]['ip'], operation='toggle',
|
||||
before={'enabled': old_enabled}, after={'enabled': not old_enabled},
|
||||
description=f'{action} banned IP: {items[idx]["ip"]}',
|
||||
|
|
@ -116,22 +116,22 @@ def edit_banned_ip():
|
|||
if not _hash_ok():
|
||||
return redirect(VIEW)
|
||||
|
||||
core = load_core()
|
||||
items = core.get('banned_ips', [])
|
||||
cfg = load_config()
|
||||
items = cfg.get('banned_ips', [])
|
||||
if idx < 0 or idx >= len(items):
|
||||
flash('Entry not found.', 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
before = copy.deepcopy(items[idx])
|
||||
items[idx].update({'description': description, 'ip': ip, 'enabled': enabled})
|
||||
errors = validate.validate_config(core)
|
||||
errors = validate.validate_config(cfg)
|
||||
if errors:
|
||||
for msg in errors:
|
||||
flash(msg, 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
flash(save_core_with_snapshot(
|
||||
core,
|
||||
flash(save_config_with_snapshot(
|
||||
cfg,
|
||||
path='banned_ips', key=ip, operation='edit',
|
||||
before=before, after=copy.deepcopy(items[idx]),
|
||||
description=f'Edited banned IP: {ip}',
|
||||
|
|
@ -149,21 +149,21 @@ def delete_banned_ip():
|
|||
if not _hash_ok():
|
||||
return redirect(VIEW)
|
||||
|
||||
core = load_core()
|
||||
items = core.get('banned_ips', [])
|
||||
cfg = load_config()
|
||||
items = cfg.get('banned_ips', [])
|
||||
if idx < 0 or idx >= len(items):
|
||||
flash('Entry not found.', 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
removed = items.pop(idx)
|
||||
errors = validate.validate_config(core)
|
||||
errors = validate.validate_config(cfg)
|
||||
if errors:
|
||||
for msg in errors:
|
||||
flash(msg, 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
flash(save_core_with_snapshot(
|
||||
core,
|
||||
flash(save_config_with_snapshot(
|
||||
cfg,
|
||||
path='banned_ips', key=removed['ip'], operation='delete',
|
||||
before=removed, after=None,
|
||||
description=f'Deleted banned IP: {removed["ip"]}',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue