44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
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
|
|
import sanitize
|
|
import validation as validate
|
|
|
|
bp = Blueprint('action_apply_mdns', __name__)
|
|
|
|
|
|
@bp.route('/action/apply_mdns', methods=['POST'])
|
|
@require_level('administrator')
|
|
def apply_mdns():
|
|
mdns_enabled = 'mdns_enabled' in request.form
|
|
|
|
if not verify_core_hash(request.form.get('config_hash', '')):
|
|
flash('Configuration was modified by another session. Please refresh and try again.', 'error')
|
|
return redirect('/view/view_mdns')
|
|
|
|
core = load_core()
|
|
mdns_reflect_vlans = sanitize.filterlist(
|
|
request.form.getlist('mdns_reflect_vlans'),
|
|
{v.get('name') for v in core.get('vlans', [])},
|
|
)
|
|
|
|
before = copy.deepcopy(core.get('mdns_reflection', {}))
|
|
core.setdefault('mdns_reflection', {}).update({
|
|
'enabled': mdns_enabled,
|
|
'reflect_vlans': mdns_reflect_vlans,
|
|
})
|
|
errors = validate.validate_config(core)
|
|
if errors:
|
|
for msg in errors:
|
|
flash(msg, 'error')
|
|
return redirect('/view/view_mdns')
|
|
|
|
flash(save_core_with_snapshot(
|
|
core,
|
|
path='mdns_reflection', key='global', operation='edit',
|
|
before=before or None, after=copy.deepcopy(core['mdns_reflection']),
|
|
description='Updated mDNS reflection settings',
|
|
), 'success')
|
|
return redirect('/view/view_mdns')
|