Development
This commit is contained in:
parent
9c22b6f2fd
commit
6e610f888e
10 changed files with 526 additions and 102 deletions
|
|
@ -1,5 +1,6 @@
|
|||
from pathlib import Path
|
||||
import copy
|
||||
import ipaddress
|
||||
|
||||
from flask import Blueprint, request, redirect, flash
|
||||
from auth import require_level
|
||||
|
|
@ -36,6 +37,27 @@ def _parse_ip():
|
|||
return ip
|
||||
|
||||
|
||||
def _check_ip_in_vlan_subnet(ip, vlan):
|
||||
if not ip or ip == 'dynamic':
|
||||
return None
|
||||
subnet = vlan.get('subnet')
|
||||
prefix = vlan.get('subnet_mask')
|
||||
if not subnet or prefix is None:
|
||||
return None
|
||||
try:
|
||||
network = ipaddress.IPv4Network(f'{subnet}/{prefix}', strict=False)
|
||||
addr = ipaddress.IPv4Address(ip)
|
||||
if addr == network.network_address:
|
||||
return f'{ip} is the network address and cannot be assigned.'
|
||||
if addr == network.broadcast_address:
|
||||
return f'{ip} is the broadcast address and cannot be assigned.'
|
||||
if addr not in network:
|
||||
return f'{ip} is not within the {vlan["name"]} subnet ({subnet}/{prefix}).'
|
||||
except ValueError:
|
||||
return f'{ip} is not a valid IP address.'
|
||||
return None
|
||||
|
||||
|
||||
@bp.route('/action/dhcp/addreservation_add', methods=['POST'])
|
||||
@require_level('administrator')
|
||||
def addreservation_add():
|
||||
|
|
@ -64,6 +86,11 @@ def addreservation_add():
|
|||
flash(f'The configuration has not been saved because VLAN "{vlan_name}" was not found.', 'error')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
subnet_err = _check_ip_in_vlan_subnet(ip, vlan)
|
||||
if subnet_err:
|
||||
flash(f'The configuration has not been saved because {subnet_err}', 'error')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
conflict = validate.check_reservation_ip_conflicts(ip, vlan)
|
||||
if conflict:
|
||||
flash(f'The configuration has not been saved because {conflict}', 'error')
|
||||
|
|
@ -153,6 +180,10 @@ def reservations_edit():
|
|||
vlan_name = res.get('vlan', '')
|
||||
vlan = next((v for v in cfg.get('vlans', []) if v.get('name') == vlan_name), None)
|
||||
if vlan:
|
||||
subnet_err = _check_ip_in_vlan_subnet(ip, vlan)
|
||||
if subnet_err:
|
||||
flash(f'The configuration has not been saved because {subnet_err}', 'error')
|
||||
return redirect(f'/{_PAGE}')
|
||||
conflict = validate.check_reservation_ip_conflicts(ip, vlan)
|
||||
if conflict:
|
||||
flash(f'The configuration has not been saved because {conflict}', 'error')
|
||||
|
|
|
|||
|
|
@ -117,7 +117,8 @@
|
|||
},
|
||||
{
|
||||
"col": "ip",
|
||||
"input_type": "text"
|
||||
"input_type": "text",
|
||||
"validate": "VALIDATION_ADDRESS"
|
||||
},
|
||||
{
|
||||
"col": "radius_client",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue