diff --git a/config_webrx.py b/config_webrx.py index b6d4e13..bfd362d 100644 --- a/config_webrx.py +++ b/config_webrx.py @@ -281,3 +281,6 @@ aprs_igate_server = "euro.aprs2.net" aprs_igate_password = "" # beacon uses the receiver_gps setting, so if you enable this, make sure the location is correct there aprs_igate_beacon = False + +# path to the aprs symbols repository (get it here: https://github.com/hessu/aprs-symbols) +aprs_symbols_path = "/opt/aprs-symbols/png" diff --git a/owrx/controllers.py b/owrx/controllers.py index f7ce7e0..a3b232f 100644 --- a/owrx/controllers.py +++ b/owrx/controllers.py @@ -55,9 +55,15 @@ class StatusController(Controller): class AssetsController(Controller): + def __init__(self, handler, request, path): + if not path.endswith("/"): + path += "/" + self.path = path + super().__init__(handler, request) + def serve_file(self, file, content_type=None): try: - modified = datetime.fromtimestamp(os.path.getmtime("htdocs/" + file)) + modified = datetime.fromtimestamp(os.path.getmtime(self.path + file)) if "If-Modified-Since" in self.handler.headers: client_modified = datetime.strptime( @@ -67,7 +73,7 @@ class AssetsController(Controller): self.send_response("", code=304) return - f = open("htdocs/" + file, "rb") + f = open(self.path + file, "rb") data = f.read() f.close() @@ -82,6 +88,17 @@ class AssetsController(Controller): self.serve_file(filename) +class OwrxAssetsController(AssetsController): + def __init__(self, handler, request): + super().__init__(handler, request, "htdocs/") + + +class AprsSymbolsController(AssetsController): + def __init__(self, handler, request): + pm = PropertyManager.getSharedInstance() + super().__init__(handler, request, pm["aprs_symbols_path"]) + + class TemplateController(Controller): def render_template(self, file, **vars): f = open("htdocs/" + file, "r") diff --git a/owrx/http.py b/owrx/http.py index 189dd95..f15b974 100644 --- a/owrx/http.py +++ b/owrx/http.py @@ -1,12 +1,13 @@ from owrx.controllers import ( StatusController, IndexController, - AssetsController, + OwrxAssetsController, WebSocketController, MapController, FeatureController, ApiController, MetricsController, + AprsSymbolsController, ) from http.server import BaseHTTPRequestHandler import re @@ -36,11 +37,12 @@ class Router(object): mappings = [ {"route": "/", "controller": IndexController}, {"route": "/status", "controller": StatusController}, - {"regex": "/static/(.+)", "controller": AssetsController}, + {"regex": "/static/(.+)", "controller": OwrxAssetsController}, + {"regex": "/aprs-symbols/(.+)", "controller": AprsSymbolsController}, {"route": "/ws/", "controller": WebSocketController}, - {"regex": "(/favicon.ico)", "controller": AssetsController}, + {"regex": "(/favicon.ico)", "controller": OwrxAssetsController}, # backwards compatibility for the sdr.hu portal - {"regex": "/(gfx/openwebrx-avatar.png)", "controller": AssetsController}, + {"regex": "/(gfx/openwebrx-avatar.png)", "controller": OwrxAssetsController}, {"route": "/map", "controller": MapController}, {"route": "/features", "controller": FeatureController}, {"route": "/api/features", "controller": ApiController},