Development
This commit is contained in:
parent
e2573fbf12
commit
f0504f802e
8 changed files with 67 additions and 66 deletions
|
|
@ -11,7 +11,7 @@ bp = Blueprint('action_networklayout', __name__)
|
|||
|
||||
VIEW = '/view/view_network_layout'
|
||||
|
||||
_VLAN_FIELDS = ['name', 'is_vpn', 'subnet', 'subnet_mask', 'dnsmasq_log_queries',
|
||||
_VLAN_FIELDS = ['name', 'vlan_id', 'is_vpn', 'subnet', 'subnet_mask', 'dnsmasq_log_queries',
|
||||
'radius_default', 'mdns_reflection', 'use_blocklists']
|
||||
|
||||
|
||||
|
|
@ -33,6 +33,7 @@ def _hash_ok():
|
|||
@require_level('administrator')
|
||||
def networklayout_cardaddvlan_addvlan():
|
||||
name = sanitize.name(request.form.get('name', ''))
|
||||
vlan_id = sanitize.vlan_id(request.form.get('vlan_id', ''))
|
||||
is_vpn = 'is_vpn' in request.form
|
||||
subnet = sanitize.ip(request.form.get('subnet', ''))
|
||||
subnet_mask = sanitize.subnet_mask(request.form.get('subnet_mask', ''))
|
||||
|
|
@ -47,6 +48,9 @@ def networklayout_cardaddvlan_addvlan():
|
|||
if not name:
|
||||
flash('Name is required.', 'error')
|
||||
return redirect(VIEW)
|
||||
if vlan_id is None:
|
||||
flash('VLAN ID must be an integer between 1 and 4094.', 'error')
|
||||
return redirect(VIEW)
|
||||
if not subnet:
|
||||
flash('Subnet IP is required.', 'error')
|
||||
return redirect(VIEW)
|
||||
|
|
@ -54,19 +58,14 @@ def networklayout_cardaddvlan_addvlan():
|
|||
flash('Invalid subnet prefix (must be 1-30).', 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
vlan_id = validate.derive_vlan_id(subnet, subnet_mask)
|
||||
if vlan_id is None:
|
||||
flash('Cannot derive a valid VLAN ID (1-4094) from this subnet/prefix combination.', 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
if not _hash_ok():
|
||||
return redirect(VIEW)
|
||||
|
||||
cfg = load_config()
|
||||
vlans = cfg.setdefault('vlans', [])
|
||||
|
||||
if any(validate.derive_vlan_id(v.get('subnet', ''), v.get('subnet_mask', 24)) == vlan_id for v in vlans):
|
||||
flash(f'VLAN {vlan_id} (derived from subnet) already exists.', 'error')
|
||||
if any(v.get('vlan_id') == vlan_id for v in vlans):
|
||||
flash(f'VLAN ID {vlan_id} is already in use.', 'error')
|
||||
return redirect(VIEW)
|
||||
if radius_default and any(v.get('radius_default') for v in vlans):
|
||||
flash('Only one VLAN can be the RADIUS default.', 'error')
|
||||
|
|
@ -74,6 +73,7 @@ def networklayout_cardaddvlan_addvlan():
|
|||
|
||||
entry = {
|
||||
'name': name,
|
||||
'vlan_id': vlan_id,
|
||||
'is_vpn': is_vpn,
|
||||
'subnet': subnet,
|
||||
'subnet_mask': subnet_mask,
|
||||
|
|
@ -111,6 +111,7 @@ def networklayout_tablevlans_edit():
|
|||
return redirect(VIEW)
|
||||
|
||||
name = sanitize.name(request.form.get('name', ''))
|
||||
vlan_id = sanitize.vlan_id(request.form.get('vlan_id', ''))
|
||||
subnet = sanitize.ip(request.form.get('subnet', ''))
|
||||
radius_default = 'radius_default' in request.form
|
||||
mdns_reflection = 'mdns_reflection' in request.form
|
||||
|
|
@ -142,6 +143,9 @@ def networklayout_tablevlans_edit():
|
|||
if not name:
|
||||
flash('Name is required.', 'error')
|
||||
return redirect(VIEW)
|
||||
if vlan_id is None:
|
||||
flash('VLAN ID must be an integer between 1 and 4094.', 'error')
|
||||
return redirect(VIEW)
|
||||
if not subnet:
|
||||
flash('Subnet IP is required.', 'error')
|
||||
return redirect(VIEW)
|
||||
|
|
@ -165,21 +169,13 @@ def networklayout_tablevlans_edit():
|
|||
flash(f"Server identity IP '{_ip}' is not in the VLAN subnet ({subnet}/{final_mask}).", 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
vlan_id = validate.derive_vlan_id(subnet, final_mask)
|
||||
if vlan_id is None:
|
||||
flash('Cannot derive a valid VLAN ID (1-4094) from this subnet/prefix combination.', 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
current_id = validate.derive_vlan_id(existing.get('subnet', ''), existing.get('subnet_mask', 24))
|
||||
current_id = existing.get('vlan_id')
|
||||
if current_id == 1 and vlan_id != 1:
|
||||
flash('VLAN 1 is the physical interface; change its subnet so the derived ID remains 1.', 'error')
|
||||
flash('VLAN 1 is the physical interface and cannot change its ID.', 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
if vlan_id != current_id and any(
|
||||
validate.derive_vlan_id(v.get('subnet', ''), v.get('subnet_mask', 24)) == vlan_id
|
||||
for i, v in enumerate(vlans) if i != idx
|
||||
):
|
||||
flash(f'VLAN {vlan_id} (derived from subnet) already exists.', 'error')
|
||||
if vlan_id != current_id and any(v.get('vlan_id') == vlan_id for i, v in enumerate(vlans) if i != idx):
|
||||
flash(f'VLAN ID {vlan_id} is already in use.', 'error')
|
||||
return redirect(VIEW)
|
||||
|
||||
if radius_default and any(i != idx and v.get('radius_default') for i, v in enumerate(vlans)):
|
||||
|
|
@ -274,6 +270,7 @@ def networklayout_tablevlans_edit():
|
|||
)
|
||||
)
|
||||
if (name == existing.get('name', '')
|
||||
and vlan_id == existing.get('vlan_id')
|
||||
and subnet == existing.get('subnet', '')
|
||||
and final_mask == existing.get('subnet_mask', 24)
|
||||
and dnsmasq_log_queries == bool(existing.get('dnsmasq_log_queries', False))
|
||||
|
|
@ -290,6 +287,7 @@ def networklayout_tablevlans_edit():
|
|||
before = {k: existing.get(k) for k in _VLAN_FIELDS}
|
||||
existing.update({
|
||||
'name': name,
|
||||
'vlan_id': vlan_id,
|
||||
'is_vpn': is_vpn,
|
||||
'subnet': subnet,
|
||||
'subnet_mask': final_mask,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue