From 1c4543b7bf12e227075a11db1b0b01a3ee192149 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Fri, 10 May 2019 23:00:18 +0200 Subject: [PATCH] re-implement the status page --- owrx/controllers.py | 17 ++++++++++++++++- owrx/source.py | 5 ++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/owrx/controllers.py b/owrx/controllers.py index 3f974dc..adc29a2 100644 --- a/owrx/controllers.py +++ b/owrx/controllers.py @@ -34,7 +34,22 @@ class Controller(object): class StatusController(Controller): def handle_request(self): - self.send_response("you have reached the status page!") + pm = PropertyManager.getSharedInstance() + # TODO keys that have been left out since they are no longer simple strings: sdr_hw, bands, antenna + vars = { + "status": "active", + "name": pm["receiver_name"], + "op_email": pm["receiver_admin"], + "users": ClientReporterThread.getSharedInstance().clientCount(), + "users_max": pm["max_clients"], + "gps": pm["receiver_gps"], + "asl": pm["receiver_asl"], + "loc": pm["receiver_location"], + # TODO get some version in there + "sw_version": "TODO", + "avatar_ctime": os.path.getctime("htdocs/gfx/openwebrx-avatar.png") + } + self.send_response("\n".join(["{key}={value}".format(key = key, value = value) for key, value in vars.items()])) class AssetsController(Controller): def serve_file(self, file, content_type = None): diff --git a/owrx/source.py b/owrx/source.py index 5ed0918..64637b2 100644 --- a/owrx/source.py +++ b/owrx/source.py @@ -521,7 +521,7 @@ class ClientReporterThread(threading.Thread): def run(self): while (self.doRun): - n = len(self.clients) + n = self.clientCount() for c in self.clients: c.write_clients(n) time.sleep(3) @@ -533,6 +533,9 @@ class ClientReporterThread(threading.Thread): raise TooManyClientsException() self.clients.append(client) + def clientCount(self): + return len(self.clients) + def removeClient(self, client): try: self.clients.remove(client)