From 0046578697ca3323852bcd87af7e19905e82f91a Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 28 Jun 2023 15:08:06 +0000 Subject: [PATCH] voip: Show outbound registrations Signed-off-by: Michael Tremer --- Makefile.am | 1 + src/backend/asterisk.py | 43 +++++++++++++++++++ src/templates/voip/index.html | 13 ++++++ .../voip/modules/outbound-registrations.html | 30 +++++++++++++ src/web/__init__.py | 2 + src/web/voip.py | 12 +++++- 6 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 src/templates/voip/modules/outbound-registrations.html diff --git a/Makefile.am b/Makefile.am index 9fab4394..36b0d641 100644 --- a/Makefile.am +++ b/Makefile.am @@ -335,6 +335,7 @@ templates_voip_DATA = \ templates_voipdir = $(templatesdir)/voip templates_voip_modules_DATA = \ + src/templates/voip/modules/outbound-registrations.html \ src/templates/voip/modules/registrations.html templates_voip_modulesdir = $(templates_voipdir)/modules diff --git a/src/backend/asterisk.py b/src/backend/asterisk.py index f5f91e06..8b5fa04d 100644 --- a/src/backend/asterisk.py +++ b/src/backend/asterisk.py @@ -96,6 +96,18 @@ class Asterisk(misc.Object): return registrations + async def get_outbound_registrations(self): + registrations = [] + + for data in await self.manager.send_action({"Action" : "PJSIPShowRegistrationsOutbound"}): + if not data.Event == "OutboundRegistrationDetail": + continue + + registration = OutboundRegistration(self.backend, data) + registrations.append(registration) + + return registrations + class Channel(misc.Object): def init(self, data): @@ -200,3 +212,34 @@ class Registration(misc.Object): @property def roundtrip(self): return int(self.data.RoundtripUsec) / 1000 + + +class OutboundRegistration(misc.Object): + def init(self, data): + self.data = data + + def __lt__(self, other): + if isinstance(other, self.__class__): + return self.server < other.server or self.username < other.username + + return NotImplemented + + @lazy_property + def uri(self): + return urllib.parse.urlparse(self.data.ClientUri) + + @property + def server(self): + username, _, server = self.uri.path.partition("@") + + return server + + @property + def username(self): + username, _, server = self.uri.path.partition("@") + + return username + + @property + def status(self): + return self.data.Status diff --git a/src/templates/voip/index.html b/src/templates/voip/index.html index e607ed4a..c8abf825 100644 --- a/src/templates/voip/index.html +++ b/src/templates/voip/index.html @@ -36,4 +36,17 @@ {% end %} + + {% if outbound_registrations %} +
+
+

+ {{ _("Outbound Registrations") }} + {{ len(outbound_registrations) }} +

+ + {% module VoIPOutboundRegistrations(outbound_registrations) %} +
+
+ {% end %} {% end block %} diff --git a/src/templates/voip/modules/outbound-registrations.html b/src/templates/voip/modules/outbound-registrations.html new file mode 100644 index 00000000..96d8a846 --- /dev/null +++ b/src/templates/voip/modules/outbound-registrations.html @@ -0,0 +1,30 @@ + + + + + + + + + + + {% for r in sorted(registrations) %} + + {# Server #} + + + {# Username #} + + + {# Status #} + + + {% end %} + +
{{ _("Server") }}{{ _("Username") }}{{ _("Status") }}
+ {{ r.server }} + + {{ r.username }} + + {{ r.status }} +
diff --git a/src/web/__init__.py b/src/web/__init__.py index 27d05035..e509f2af 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -94,6 +94,8 @@ class Application(tornado.web.Application): "UsersList" : users.ListModule, # VoIP + "VoIPOutboundRegistrations" : + voip.OutboundRegistrationsModule, "VoIPRegistrations" : voip.RegistrationsModule, # Wiki diff --git a/src/web/voip.py b/src/web/voip.py index be07f646..b002b448 100644 --- a/src/web/voip.py +++ b/src/web/voip.py @@ -9,11 +9,19 @@ from . import ui_modules class IndexHandler(base.BaseHandler): @tornado.web.authenticated async def get(self): - registrations, = await asyncio.gather( + registrations, outbound_registrations, = await asyncio.gather( self.backend.asterisk.get_registrations(), + self.backend.asterisk.get_outbound_registrations(), ) - self.render("voip/index.html", registrations=registrations) + self.render("voip/index.html", registrations=registrations, + outbound_registrations=outbound_registrations) + + +class OutboundRegistrationsModule(ui_modules.UIModule): + def render(self, registrations): + return self.render_string("voip/modules/outbound-registrations.html", + registrations=registrations) class RegistrationsModule(ui_modules.UIModule): -- 2.47.3