Development
This commit is contained in:
parent
d8d1d46fd2
commit
eed1d295dc
69 changed files with 3355 additions and 3230 deletions
|
|
@ -1,93 +0,0 @@
|
|||
import copy
|
||||
from flask import Blueprint, request, redirect, flash
|
||||
from auth import require_level
|
||||
from config_utils import load_config, save_config_with_snapshot, verify_config_hash
|
||||
import sanitize
|
||||
import validation as validate
|
||||
|
||||
bp = Blueprint('action_dnsserver', __name__)
|
||||
|
||||
_VIEW = '/view/view_dns_server'
|
||||
|
||||
|
||||
@bp.route('/action/dnsserver_cardupstreamdns_save', methods=['POST'])
|
||||
@require_level('administrator')
|
||||
def dnsserver_cardupstreamdns_save():
|
||||
strict_order = 'strict_order' in request.form
|
||||
submitted = request.form.getlist('upstream_servers')
|
||||
|
||||
for s in submitted:
|
||||
if not s.strip():
|
||||
flash('Remove blank server entries before saving.', 'error')
|
||||
return redirect(_VIEW)
|
||||
|
||||
upstream_servers = []
|
||||
for s in submitted:
|
||||
clean = sanitize.ip(s.strip())
|
||||
if not clean:
|
||||
flash(f"'{s.strip()}' is not a valid IP address.", 'error')
|
||||
return redirect(_VIEW)
|
||||
upstream_servers.append(clean)
|
||||
|
||||
if not verify_config_hash(request.form.get('config_hash', '')):
|
||||
flash('Configuration was modified by another session. Please refresh and try again.', 'error')
|
||||
return redirect(_VIEW)
|
||||
|
||||
cfg = load_config()
|
||||
before = copy.deepcopy(cfg.get('upstream_dns', {}))
|
||||
current = cfg.get('upstream_dns', {})
|
||||
if (strict_order == bool(current.get('strict_order', False)) and
|
||||
upstream_servers == current.get('upstream_servers', [])):
|
||||
flash('No changes detected.', 'info')
|
||||
return redirect(_VIEW)
|
||||
|
||||
cfg.setdefault('upstream_dns', {}).update({
|
||||
'strict_order': strict_order,
|
||||
'upstream_servers': upstream_servers,
|
||||
})
|
||||
errors = validate.validate_config(cfg)
|
||||
if errors:
|
||||
for msg in errors:
|
||||
flash(msg, 'error')
|
||||
return redirect(_VIEW)
|
||||
flash(save_config_with_snapshot(
|
||||
cfg, path='upstream_dns', key='global', operation='edit',
|
||||
before=before, after=copy.deepcopy(cfg['upstream_dns']),
|
||||
description='Updated upstream DNS servers',
|
||||
cmd='core apply',
|
||||
), 'success')
|
||||
return redirect(_VIEW)
|
||||
|
||||
|
||||
@bp.route('/action/dnsserver_carddnsforwarding_save', methods=['POST'])
|
||||
@require_level('administrator')
|
||||
def dnsserver_carddnsforwarding_save():
|
||||
cache_size = validate.int_range(request.form.get('cache_size', '').strip(), 0, None)
|
||||
if cache_size is None:
|
||||
flash('Cache Size must be a non-negative integer.', 'error')
|
||||
return redirect(_VIEW)
|
||||
|
||||
if not verify_config_hash(request.form.get('config_hash', '')):
|
||||
flash('Configuration was modified by another session. Please refresh and try again.', 'error')
|
||||
return redirect(_VIEW)
|
||||
|
||||
cfg = load_config()
|
||||
before = copy.deepcopy(cfg.get('upstream_dns', {}))
|
||||
current = cfg.get('upstream_dns', {})
|
||||
if cache_size == int(current.get('cache_size', 0)):
|
||||
flash('No changes detected.', 'info')
|
||||
return redirect(_VIEW)
|
||||
|
||||
cfg.setdefault('upstream_dns', {})['cache_size'] = cache_size
|
||||
errors = validate.validate_config(cfg)
|
||||
if errors:
|
||||
for msg in errors:
|
||||
flash(msg, 'error')
|
||||
return redirect(_VIEW)
|
||||
flash(save_config_with_snapshot(
|
||||
cfg, path='upstream_dns', key='global', operation='edit',
|
||||
before=before, after=copy.deepcopy(cfg['upstream_dns']),
|
||||
description='Updated DNS cache size',
|
||||
cmd='core apply',
|
||||
), 'success')
|
||||
return redirect(_VIEW)
|
||||
Loading…
Add table
Add a link
Reference in a new issue