summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-06-05 12:43:36 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-06-05 12:43:36 +0200
commitb3c25a827be0704bf9655fa3dbcf8178870c1eb6 (patch)
treef42aa87697c25c169fceeb9a93248a03aba781d1
parent1d8c7529011448ae7d8cee5b7e9427faaf703e53 (diff)
views: validate ip in client creation and update
Check the provided IP is valid before trying to send the payload to the server.
-rw-r--r--ogcp/views.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index fd4eb01..d4f3506 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -29,6 +29,7 @@ from ogcp.og_server import OGServer, servers
from flask_babel import lazy_gettext as _l
from flask_babel import gettext, _
from ogcp import app, ogcp_cfg_path
+import ipaddress
import requests
import datetime
import hashlib
@@ -1234,6 +1235,13 @@ def action_client_info():
def action_client_update():
form = ClientDetailsForm(request.form)
if request.method == 'POST':
+
+ try:
+ ipaddress.ip_address(form.ip.data)
+ except ValueError as e:
+ flash(_('Invalid IP address'), category='error')
+ return redirect(url_for("scopes"))
+
payload = {"ip": form.ip.data,
"serial_number": form.serial_number.data,
"netdriver": "generic",
@@ -1480,6 +1488,12 @@ def action_client_add():
flash(form.errors, category='error')
return redirect(url_for('servers'))
+ try:
+ ipaddress.ip_address(form.ip.data)
+ except ValueError as e:
+ flash(_('Invalid IP address'), category='error')
+ return redirect(url_for("scopes"))
+
payload = {"boot": form.boot.data,
"ip": form.ip.data,
"livedir": form.livedir.data,