diff --git a/modem/api_validations.py b/modem/api_validations.py index b8257d9c..a5cbc70e 100644 --- a/modem/api_validations.py +++ b/modem/api_validations.py @@ -1,5 +1,16 @@ import re + +def validate_remote_config(config): + if not config: + return + + mygrid = config["STATION"]["mygrid"] + if len(mygrid) != 6: + raise ValueError(f"Gridsquare must be 6 characters!") + + return True + def validate_freedata_callsign(callsign): #regexp = "^[a-zA-Z]+\d+\w+-\d{1,2}$" regexp = "^[A-Za-z0-9]{1,7}-[0-9]{1,3}$" # still broken - we need to allow all ssids form 0 - 255 diff --git a/modem/server.py b/modem/server.py index f425b37f..8b7acd3e 100644 --- a/modem/server.py +++ b/modem/server.py @@ -96,6 +96,9 @@ def index(): @app.route('/config', methods=['GET', 'POST']) def config(): if request.method in ['POST']: + + if not validations.validate_remote_config(request.json): + return api_abort("wrong config", 500) # check if config already exists if app.config_manager.read() == request.json: return api_response(request.json)