add aprs symbols to http server

This commit is contained in:
Jakob Ketterl 2019-09-18 17:22:35 +02:00
parent 30512e347a
commit c6c4012a36
3 changed files with 28 additions and 6 deletions

View File

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

View File

@ -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")

View File

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