Development
This commit is contained in:
parent
113328c566
commit
01a636e842
16 changed files with 388 additions and 502 deletions
|
|
@ -3,7 +3,7 @@ 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
|
||||
from config_utils import load_config, record_group, diff_fields, verify_config_hash
|
||||
import sanitize
|
||||
import validation as validate
|
||||
|
||||
|
|
@ -73,10 +73,6 @@ def _parse_entry():
|
|||
}, None
|
||||
|
||||
|
||||
def _entry_key(entry):
|
||||
port = f':{entry["dst_port"]}' if entry.get('dst_port') else ''
|
||||
return f'{entry["protocol"]}:{entry["src_ip_or_subnet"]}→{entry["dst_ip_or_subnet"]}{port}'
|
||||
|
||||
|
||||
@bp.route('/action/intervlan/addexception_add', methods=['POST'])
|
||||
@require_level('administrator')
|
||||
|
|
@ -95,13 +91,9 @@ def addexception_add():
|
|||
flash(msg, 'error')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
key = _entry_key(entry)
|
||||
flash(save_config_with_snapshot(
|
||||
cfg,
|
||||
path='inter_vlan_exceptions', key=key, operation='add',
|
||||
before=None, after=entry,
|
||||
description=f'Added inter-VLAN rule: {key}',
|
||||
), 'success')
|
||||
src = entry.get('src_ip_or_subnet', '')
|
||||
changes = diff_fields(None, entry)
|
||||
flash(record_group(cfg, 'inter_vlan_exceptions', 'src_ip_or_subnet', src, changes, 'core apply'), 'success')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
|
||||
|
|
@ -122,6 +114,7 @@ def table_toggle():
|
|||
return redirect(f'/{_PAGE}')
|
||||
|
||||
old_enabled = items[idx].get('enabled', True)
|
||||
before = copy.deepcopy(items[idx])
|
||||
items[idx]['enabled'] = not old_enabled
|
||||
errors = validate.validate_config(cfg)
|
||||
if errors:
|
||||
|
|
@ -129,14 +122,9 @@ def table_toggle():
|
|||
flash(msg, 'error')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
key = _entry_key(items[idx])
|
||||
action = 'Enabled' if not old_enabled else 'Disabled'
|
||||
flash(save_config_with_snapshot(
|
||||
cfg,
|
||||
path='inter_vlan_exceptions', key=key, operation='toggle',
|
||||
before={'enabled': old_enabled}, after={'enabled': not old_enabled},
|
||||
description=f'{action} inter-VLAN rule: {key}',
|
||||
), 'success')
|
||||
src = items[idx].get('src_ip_or_subnet', '')
|
||||
changes = diff_fields(before, items[idx])
|
||||
flash(record_group(cfg, 'inter_vlan_exceptions', 'src_ip_or_subnet', src, changes, 'core apply'), 'success')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
|
||||
|
|
@ -169,13 +157,9 @@ def table_edit():
|
|||
flash(msg, 'error')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
key = _entry_key(entry)
|
||||
flash(save_config_with_snapshot(
|
||||
cfg,
|
||||
path='inter_vlan_exceptions', key=key, operation='edit',
|
||||
before=before, after=copy.deepcopy(items[idx]),
|
||||
description=f'Edited inter-VLAN rule: {key}',
|
||||
), 'success')
|
||||
src = items[idx].get('src_ip_or_subnet', '')
|
||||
changes = diff_fields(before, items[idx])
|
||||
flash(record_group(cfg, 'inter_vlan_exceptions', 'src_ip_or_subnet', src, changes, 'core apply'), 'success')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
|
||||
|
|
@ -202,11 +186,7 @@ def table_delete():
|
|||
flash(msg, 'error')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
key = _entry_key(removed)
|
||||
flash(save_config_with_snapshot(
|
||||
cfg,
|
||||
path='inter_vlan_exceptions', key=key, operation='delete',
|
||||
before=removed, after=None,
|
||||
description=f'Deleted inter-VLAN rule: {key}',
|
||||
), 'success')
|
||||
src = removed.get('src_ip_or_subnet', '')
|
||||
changes = diff_fields(removed, None)
|
||||
flash(record_group(cfg, 'inter_vlan_exceptions', 'src_ip_or_subnet', src, changes, 'core apply'), 'success')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue