diff --git a/app.py b/app.py index 649fe99..22cc29b 100644 --- a/app.py +++ b/app.py @@ -137,7 +137,7 @@ def delete(image_id): return jsonify(message="409") filename = db.get_conf_image_id(image_id) squashfs = os.path.join(app.config['UPLOAD_FOLDER'], filename) - pubkey = os.path.join(app.config['UPLOAD_FOLDER'], filename.split(".")[0]) + pubkey = os.path.join(app.config['UPLOAD_FOLDER'], filename.split(".")[0]+".pub") if os.path.exists(squashfs): os.remove(squashfs) if os.path.exists(pubkey): @@ -238,6 +238,8 @@ def add_ip(): try: token = request.headers['token'] ip = request.form['ip'] + if utils.is_valid_ip_address(ip) is False: + return jsonify(message="400") except: return jsonify(message="400") if db.update_image_allocation_ip_vpn(token, ip) is not None: diff --git a/templates/index.html b/templates/index.html index e94d891..fe9d736 100644 --- a/templates/index.html +++ b/templates/index.html @@ -78,7 +78,7 @@ {{ machine.start_time }} {{ machine.ipvpn }} {{ machine.iplocal }} - + {% endfor %} @@ -86,9 +86,10 @@ diff --git a/utils.py b/utils.py index b8c753d..5926e1a 100644 --- a/utils.py +++ b/utils.py @@ -9,7 +9,7 @@ import threading from time import sleep import db import config - +import ipaddress def generate_random_string(length): letters = string.ascii_letters @@ -76,3 +76,10 @@ def init_threads(): allocation_thread = threading.Thread( target=check_allocation_thread_function) allocation_thread.start() + +def is_valid_ip_address(ip: str) -> bool: + try: + ipaddress.IPv4Address(ip) + return True + except ipaddress.AddressValueError: + return False