views: validate ip in client creation and update

Check the provided IP is valid before trying to send the payload
to the server.
master
Alejandro Sirgo Rica 2024-06-05 12:43:36 +02:00
parent 1d8c752901
commit b3c25a827b
1 changed files with 14 additions and 0 deletions

View File

@ -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,