]> git.ipfire.org Git - ipfire.org.git/commitdiff
voip: Show outbound registrations
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 28 Jun 2023 15:08:06 +0000 (15:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 28 Jun 2023 15:08:06 +0000 (15:08 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/backend/asterisk.py
src/templates/voip/index.html
src/templates/voip/modules/outbound-registrations.html [new file with mode: 0644]
src/web/__init__.py
src/web/voip.py

index 9fab4394add3fc5d427fb137dc4b370c81219632..36b0d6418bfca9935872126a5a54ffc9a9751bff 100644 (file)
@@ -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
index f5f91e06534c3f60b060954ed7b70821862996bb..8b5fa04d09d47c7fe762030d43c8a9f4b40ebbd6 100644 (file)
@@ -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
index e607ed4ad71c52673ce6edb5e2fa08e384bcf883..c8abf825269847876d274b30c45002e8fa8395a5 100644 (file)
                        </div>
                </section>
        {% end %}
+
+       {% if outbound_registrations %}
+               <section class="section">
+                       <div class="container">
+                               <h4 class="title is-4">
+                                       {{ _("Outbound Registrations") }}
+                                       <span class="tag">{{ len(outbound_registrations) }}</span>
+                               </h4>
+
+                               {% module VoIPOutboundRegistrations(outbound_registrations) %}
+                       </div>
+               </section>
+       {% 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 (file)
index 0000000..96d8a84
--- /dev/null
@@ -0,0 +1,30 @@
+<table class="table is-striped is-fullwidth">
+       <thead>
+               <tr>
+                       <th>{{ _("Server") }}</th>
+                       <th>{{ _("Username") }}</th>
+                       <th>{{ _("Status") }}</th>
+               </tr>
+       </thead>
+
+       <tbody>
+               {% for r in sorted(registrations) %}
+                       <tr>
+                               {# Server #}
+                               <th scope="row">
+                                       {{ r.server }}
+                               </th>
+
+                               {# Username #}
+                               <td>
+                                       {{ r.username }}
+                               </td>
+
+                               {# Status #}
+                               <td>
+                                       {{ r.status }}
+                               </td>
+                       </tr>
+               {% end %}
+       </tbody>
+</table>
index 27d05035cf4e963e772dfcda8b06373ba3f938f9..e509f2af79b8ca6f5060971699373111c240734c 100644 (file)
@@ -94,6 +94,8 @@ class Application(tornado.web.Application):
                                "UsersList"            : users.ListModule,
 
                                # VoIP
+                               "VoIPOutboundRegistrations" :
+                                       voip.OutboundRegistrationsModule,
                                "VoIPRegistrations"    : voip.RegistrationsModule,
 
                                # Wiki
index be07f6460fd4fa2ebe3a2623fc9cd29f49d4bb85..b002b4481a6510ec7251e1be1dc43d03e1f5198e 100644 (file)
@@ -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):