44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
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('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_config_hash(request.form.get('config_hash', '')):
|
|
flash('Configuration was modified by another session. Please refresh and try again.', 'error')
|
|
return redirect('/view/view_mdns')
|
|
|
|
cfg = load_config()
|
|
mdns_reflect_vlans = sanitize.filterlist(
|
|
request.form.getlist('mdns_reflect_vlans'),
|
|
{v.get('name') for v in cfg.get('vlans', [])},
|
|
)
|
|
|
|
before = copy.deepcopy(cfg.get('mdns_reflection', {}))
|
|
cfg.setdefault('mdns_reflection', {}).update({
|
|
'enabled': mdns_enabled,
|
|
'reflect_vlans': mdns_reflect_vlans,
|
|
})
|
|
errors = validate.validate_config(cfg)
|
|
if errors:
|
|
for msg in errors:
|
|
flash(msg, 'error')
|
|
return redirect('/view/view_mdns')
|
|
|
|
flash(save_config_with_snapshot(
|
|
cfg,
|
|
path='mdns_reflection', key='global', operation='edit',
|
|
before=before or None, after=copy.deepcopy(cfg['mdns_reflection']),
|
|
description='Updated mDNS reflection settings',
|
|
), 'success')
|
|
return redirect('/view/view_mdns')
|