summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ogcp/views.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 2dba569..097041f 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -116,6 +116,13 @@ def prettify_mac(mac):
return mac
return (':'.join(normalized_mac[i:i+2] for i in range(0, 12, 2))).lower()
+def is_valid_ip(ip):
+ try:
+ ipaddress.ip_address(ip)
+ except:
+ return False
+ return True
+
def ogserver_down(view):
flash(_('Cannot talk to ogserver. Is ogserver down?'), category='error')
return redirect(url_for(view))
@@ -1310,9 +1317,7 @@ def action_client_update():
form = ClientDetailsForm(request.form)
if request.method == 'POST':
- try:
- ipaddress.ip_address(form.ip.data)
- except ValueError as e:
+ if not is_valid_ip(form.ip.data):
flash(_('Invalid IP address'), category='error')
return redirect(url_for("scopes"))
@@ -1573,9 +1578,7 @@ def action_client_add():
flash(_('Invalid empty client name'), category='error')
return redirect(url_for("scopes"))
- try:
- ipaddress.ip_address(form.ip.data)
- except ValueError as e:
+ if not is_valid_ip(form.ip.data):
flash(_('Invalid IP address'), category='error')
return redirect(url_for("scopes"))
@@ -1791,9 +1794,7 @@ def action_clients_import_post():
client_ip = client_values[2]
- try:
- ipaddress.ip_address(client_ip)
- except ValueError as e:
+ if not is_valid_ip(client_ip):
flash(_(f'Invalid IP address {client_ip}'), category='error')
return redirect(url_for("scopes"))