Development

This commit is contained in:
Matthew Grotke 2026-05-27 22:04:04 -04:00
parent eed1d295dc
commit d9f3bd8289
45 changed files with 635 additions and 666 deletions

View file

@ -1,3 +1,4 @@
from pathlib import Path
import copy
from flask import Blueprint, request, redirect, flash
@ -6,9 +7,9 @@ from config_utils import load_config, save_config_with_snapshot, verify_config_h
import sanitize
import validation as validate
bp = Blueprint('intervlan', __name__)
_PAGE = Path(__file__).parent.name
VIEW = '/view/view_intervlan'
bp = Blueprint(_PAGE, __name__)
_VALID_PROTOS_STR = ', '.join(sorted(validate.VALID_PROTOCOLS))
@ -77,14 +78,14 @@ def _entry_key(entry):
return f'{entry["protocol"]}:{entry["src_ip_or_subnet"]}{entry["dst_ip_or_subnet"]}{port}'
@bp.route('/action/add_inter_vlan', methods=['POST'])
@bp.route('/action/intervlan/addexception_add', methods=['POST'])
@require_level('administrator')
def add_inter_vlan():
def addexception_add():
entry, err = _parse_entry()
if err:
return redirect(VIEW)
return redirect(f'/{_PAGE}')
if not _hash_ok():
return redirect(VIEW)
return redirect(f'/{_PAGE}')
cfg = load_config()
cfg.setdefault('inter_vlan_exceptions', []).append(entry)
@ -92,7 +93,7 @@ def add_inter_vlan():
if errors:
for msg in errors:
flash(msg, 'error')
return redirect(VIEW)
return redirect(f'/{_PAGE}')
key = _entry_key(entry)
flash(save_config_with_snapshot(
@ -101,24 +102,24 @@ def add_inter_vlan():
before=None, after=entry,
description=f'Added inter-VLAN rule: {key}',
), 'success')
return redirect(VIEW)
return redirect(f'/{_PAGE}')
@bp.route('/action/toggle_inter_vlan', methods=['POST'])
@bp.route('/action/intervlan/table_toggle', methods=['POST'])
@require_level('administrator')
def toggle_inter_vlan():
def table_toggle():
idx = _row_index()
if idx is None:
flash('Invalid request.', 'error')
return redirect(VIEW)
return redirect(f'/{_PAGE}')
if not _hash_ok():
return redirect(VIEW)
return redirect(f'/{_PAGE}')
cfg = load_config()
items = cfg.get('inter_vlan_exceptions', [])
if idx < 0 or idx >= len(items):
flash('Entry not found.', 'error')
return redirect(VIEW)
return redirect(f'/{_PAGE}')
old_enabled = items[idx].get('enabled', True)
items[idx]['enabled'] = not old_enabled
@ -126,7 +127,7 @@ def toggle_inter_vlan():
if errors:
for msg in errors:
flash(msg, 'error')
return redirect(VIEW)
return redirect(f'/{_PAGE}')
key = _entry_key(items[idx])
action = 'Enabled' if not old_enabled else 'Disabled'
@ -136,28 +137,28 @@ def toggle_inter_vlan():
before={'enabled': old_enabled}, after={'enabled': not old_enabled},
description=f'{action} inter-VLAN rule: {key}',
), 'success')
return redirect(VIEW)
return redirect(f'/{_PAGE}')
@bp.route('/action/edit_inter_vlan', methods=['POST'])
@bp.route('/action/intervlan/table_edit', methods=['POST'])
@require_level('administrator')
def edit_inter_vlan():
def table_edit():
idx = _row_index()
if idx is None:
flash('Invalid request.', 'error')
return redirect(VIEW)
return redirect(f'/{_PAGE}')
entry, err = _parse_entry()
if err:
return redirect(VIEW)
return redirect(f'/{_PAGE}')
if not _hash_ok():
return redirect(VIEW)
return redirect(f'/{_PAGE}')
cfg = load_config()
items = cfg.get('inter_vlan_exceptions', [])
if idx < 0 or idx >= len(items):
flash('Entry not found.', 'error')
return redirect(VIEW)
return redirect(f'/{_PAGE}')
before = copy.deepcopy(items[idx])
items[idx] = entry
@ -166,7 +167,7 @@ def edit_inter_vlan():
if errors:
for msg in errors:
flash(msg, 'error')
return redirect(VIEW)
return redirect(f'/{_PAGE}')
key = _entry_key(entry)
flash(save_config_with_snapshot(
@ -175,31 +176,31 @@ def edit_inter_vlan():
before=before, after=copy.deepcopy(items[idx]),
description=f'Edited inter-VLAN rule: {key}',
), 'success')
return redirect(VIEW)
return redirect(f'/{_PAGE}')
@bp.route('/action/delete_inter_vlan', methods=['POST'])
@bp.route('/action/intervlan/table_delete', methods=['POST'])
@require_level('administrator')
def delete_inter_vlan():
def table_delete():
idx = _row_index()
if idx is None:
flash('Invalid request.', 'error')
return redirect(VIEW)
return redirect(f'/{_PAGE}')
if not _hash_ok():
return redirect(VIEW)
return redirect(f'/{_PAGE}')
cfg = load_config()
items = cfg.get('inter_vlan_exceptions', [])
if idx < 0 or idx >= len(items):
flash('Entry not found.', 'error')
return redirect(VIEW)
return redirect(f'/{_PAGE}')
removed = items.pop(idx)
errors = validate.validate_config(cfg)
if errors:
for msg in errors:
flash(msg, 'error')
return redirect(VIEW)
return redirect(f'/{_PAGE}')
key = _entry_key(removed)
flash(save_config_with_snapshot(
@ -208,4 +209,4 @@ def delete_inter_vlan():
before=removed, after=None,
description=f'Deleted inter-VLAN rule: {key}',
), 'success')
return redirect(VIEW)
return redirect(f'/{_PAGE}')