From d19ba1d662b42d6aa52a28d585cc1d1c1b40ca66 Mon Sep 17 00:00:00 2001 From: Ian Renton Date: Sat, 4 Oct 2025 16:26:34 +0100 Subject: [PATCH] Spotting tweaks. Closes #2 --- config-example.yml | 5 ++++- core/config.py | 3 ++- server/webserver.py | 12 ++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/config-example.yml b/config-example.yml index d83874d..cf810fb 100644 --- a/config-example.yml +++ b/config-example.yml @@ -70,4 +70,7 @@ max-spot-age-sec: 3600 # Login for QRZ.com to look up information. Optional. qrz-username: "N0CALL" -qrz-password: "" \ No newline at end of file +qrz-password: "" + +# Allow submitting spots to the Spothole API? +allow-spotting: true \ No newline at end of file diff --git a/core/config.py b/core/config.py index 0c2d630..874702e 100644 --- a/core/config.py +++ b/core/config.py @@ -14,4 +14,5 @@ logging.info("Loaded config.") MAX_SPOT_AGE = config["max-spot-age-sec"] SERVER_OWNER_CALLSIGN = config["server-owner-callsign"] -WEB_SERVER_PORT = config["web-server-port"] \ No newline at end of file +WEB_SERVER_PORT = config["web-server-port"] +ALLOW_SPOTTING = config["allow-spotting"] \ No newline at end of file diff --git a/server/webserver.py b/server/webserver.py index 02bddaf..f73bc0e 100644 --- a/server/webserver.py +++ b/server/webserver.py @@ -8,7 +8,7 @@ import bottle import pytz from bottle import run, response, template -from core.config import MAX_SPOT_AGE +from core.config import MAX_SPOT_AGE, ALLOW_SPOTTING from core.constants import BANDS, ALL_MODES, MODE_TYPES, SIGS, CONTINENTS from core.utils import serialize_everything from data.spot import Spot @@ -64,6 +64,12 @@ class WebServer: self.status = "OK" try: + # Reject if not allowed + if not ALLOW_SPOTTING: + response.content_type = 'application/json' + response.status = 401 + return json.dumps("Error - this server does not allow new spots to be added via the API.", default=serialize_everything) + # Reject if no spot if not bottle.request.query.spot: response.content_type = 'application/json' @@ -81,6 +87,8 @@ class WebServer: return json.dumps("Error - 'time' and 'dx_call' must be provided as a minimum.", default=serialize_everything) # infer missing data, and add it to our database. + spot.source = "API" + spot.icon = "desktop" spot.infer_missing() self.spots.add(spot.guid, spot, expire=MAX_SPOT_AGE) @@ -91,7 +99,7 @@ class WebServer: logging.error(e) response.content_type = 'application/json' response.status = 422 - return json.dumps("An error occurred parsing your spot: " + str(e), default=serialize_everything) + return json.dumps("Error - " + str(e), default=serialize_everything) # Serve a templated page def serve_template(self, template_name):