From: Michael Tremer Date: Wed, 17 Oct 2018 12:22:29 +0000 (+0100) Subject: people: Add page with call information X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=68ece4344986df824d14150c504da24b0df00c8b;p=ipfire.org.git people: Add page with call information Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 1738171d..58a66c3b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -153,6 +153,7 @@ templates_newsletterdir = $(templatesdir)/newsletter templates_people_DATA = \ src/templates/people/base.html \ + src/templates/people/call.html \ src/templates/people/calls.html \ src/templates/people/index.html \ src/templates/people/passwd.html \ @@ -168,6 +169,7 @@ templates_people_modules_DATA = \ src/templates/people/modules/accounts-list.html \ src/templates/people/modules/cdr.html \ src/templates/people/modules/channels.html \ + src/templates/people/modules/mos.html \ src/templates/people/modules/registrations.html templates_people_modulesdir = $(templates_peopledir)/modules diff --git a/src/backend/talk.py b/src/backend/talk.py index 559b83e2..a7392312 100644 --- a/src/backend/talk.py +++ b/src/backend/talk.py @@ -61,6 +61,13 @@ class Freeswitch(Object): for row in res: yield CDR(self, data=row) + def get_call_by_uuid(self, uuid): + res = self.db.get("SELECT * FROM cdr \ + WHERE uuid = %s", uuid) + + if res: + return CDR(self, data=res) + class SIPRegistration(object): def __init__(self, freeswitch, data): @@ -194,6 +201,25 @@ class CDR(object): def backend(self): return self.freeswitch.backend + @property + def db(self): + return self.freeswitch.db + + @property + def uuid(self): + return self.data.uuid + + @lazy_property + def bleg(self): + if self.data.bleg_uuid: + return self.freeswitch.get_call_by_uuid(self.data.bleg_uuid) + + # If we are the bleg, we need to search for one where UUID is the bleg + res = self.db.get("SELECT * FROM cdr WHERE bleg_uuid = %s", self.uuid) + + if res: + return CDR(self.freeswitch, data=res) + @property def direction(self): if self.data.bleg_uuid: @@ -235,7 +261,8 @@ class CDR(object): @property def user_agent(self): - return self.data.user_agent.replace("_", " ") + if self.data.user_agent: + return self.data.user_agent.replace("_", " ") @property def size(self): diff --git a/src/templates/people/call.html b/src/templates/people/call.html new file mode 100644 index 00000000..cd87e746 --- /dev/null +++ b/src/templates/people/call.html @@ -0,0 +1,75 @@ +{% extends "base.html" %} + +{% block title %}{{ _("Call") }}{% end block %} + +{% block main %} +
+
+

+ {% if call.direction == "inbound" %} + {{ _("Call to") }} + + {% if call.callee %} + {{ call.callee }} + {% else %} + {{ format_phone_number(call.callee_number) }} + {% end %} + {% elif call.direction == "outbound" %} + {{ _("Call from") }} + + {% if call.caller %} + {{ call.caller }} + {% else %} + {{ format_phone_number(call.caller_number) }} + {% end %} + {% end %} +

+
{{ locale.format_date(call.time_answered or call.time_start) }}
+ +

+ {% if call.duration %} + {{ format_time(call.duration) }} + {% else %} + {{ _("Not Answered") }} + {% end %} +

+ +
{{ _("Media Information") }}
+ +
+ {% for c in (call, call.bleg) %} + {% if c %} +
+
+

+ + {% if c == call %} + {{ _("Your Leg") }} + {% else %} + {{ _("Other Leg") }} + {% end %} + +

+ +

+ {% module MOS(c) %} +

+ +
+
{{ _("Codec") }}
+
{{ c.codec or _("N/A") }}
+ +
{{ _("Data Transferred") }}
+
{{ format_size(c.size) }}
+ +
{{ _("User Agent") }}
+
{{ c.user_agent or _("N/A") }}
+
+
+
+ {% end %} + {% end %} +
+
+
+{% end %} diff --git a/src/templates/people/modules/cdr.html b/src/templates/people/modules/cdr.html index 80d1ceca..a2ad0a2b 100644 --- a/src/templates/people/modules/cdr.html +++ b/src/templates/people/modules/cdr.html @@ -13,36 +13,28 @@ {% if c.direction == "inbound" %} - {% if c.callee %} - {{ c.callee }} - {% else %} - {{ format_phone_number(c.callee_number) }} - {% end %} + + {% if c.callee %} + {{ c.callee }} + {% else %} + {{ format_phone_number(c.callee_number) }} + {% end %} + {% elif c.direction == "outbound" %} - {% if c.caller %} - {{ c.caller }} - {% else %} - {{ format_phone_number(c.caller_number) }} - {% end %} + + {% if c.caller %} + {{ c.caller }} + {% else %} + {{ format_phone_number(c.caller_number) }} + {% end %} + {% end %}
- {% if c.mos %} - - {% for i in range(1, 6) %} - {% if c.mos > (i + 0.5) %} - - {% elif c.mos > i %} - - {% else %} - - {% end %} - {% end %} - - {% end %} + {% module MOS(c) %} diff --git a/src/templates/people/modules/mos.html b/src/templates/people/modules/mos.html new file mode 100644 index 00000000..524ad747 --- /dev/null +++ b/src/templates/people/modules/mos.html @@ -0,0 +1,13 @@ +{% if call.mos %} + + {% for i in range(1, 6) %} + {% if call.mos > (i + 0.5) %} + + {% elif call.mos > i %} + + {% else %} + + {% end %} + {% end %} + +{% end %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 46c7fe57..b8d46546 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -62,6 +62,7 @@ class Application(tornado.web.Application): "AccountsList" : people.AccountsListModule, "CDR" : people.CDRModule, "Channels" : people.ChannelsModule, + "MOS" : people.MOSModule, "Registrations" : people.RegistrationsModule, # Old modules @@ -254,6 +255,7 @@ class Application(tornado.web.Application): (r"/users", people.UsersHandler), (r"/users/(\w+)", people.UserHandler), (r"/users/(\w+)\.jpg", people.AvatarHandler), + (r"/users/(\w+)/calls/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})", people.CallHandler), (r"/users/(\w+)/calls(?:/(\d{4}-\d{2}-\d{2}))?", people.CallsHandler), (r"/users/(\w+)/edit", people.UserEditHandler), (r"/users/(\w+)/passwd", people.UserPasswdHandler), diff --git a/src/web/people.py b/src/web/people.py index d5fae5aa..6ab25bc2 100644 --- a/src/web/people.py +++ b/src/web/people.py @@ -71,6 +71,18 @@ class CallsHandler(base.BaseHandler): self.render("people/calls.html", account=account, date=date) +class CallHandler(base.BaseHandler): + @tornado.web.authenticated + def get(self, uid, uuid): + call = self.backend.talk.freeswitch.get_call_by_uuid(uuid) + if not call: + raise tornado.web.HTTPError(404, "Could not find call %s" % uuid) + + # XXX limit + + self.render("people/call.html", call=call) + + class RegistrationsHandler(base.BaseHandler): @tornado.web.authenticated def get(self, uid): @@ -245,6 +257,11 @@ class ChannelsModule(ui_modules.UIModule): return self.render_string("people/modules/channels.html", account=account, channels=channels) +class MOSModule(ui_modules.UIModule): + def render(self, call): + return self.render_string("people/modules/mos.html", call=call) + + class RegistrationsModule(ui_modules.UIModule): def render(self, account): return self.render_string("people/modules/registrations.html", account=account)