import ipaddress
import logging
import re
+import time
from . import database
for row in res:
yield SIPRegistration(self, data=row)
+ def get_sip_channels(self, account):
+ res = self.db.query("SELECT * FROM channels \
+ WHERE (direction = %s AND cid_num = %s) OR \
+ (direction = %s AND callee_num = %s) ORDER BY created_epoch",
+ "inbound", account.sip_id, "outbound", account.sip_id)
+
+ for row in res:
+ yield Channel(self, data=row)
+
class SIPRegistration(object):
def __init__(self, freeswitch, data):
return self.data.ping_time / 1000.0
+class Channel(object):
+ def __init__(self, freeswitch, data):
+ self.freeswitch = freeswitch
+ self.data = data
-class Talk(Object):
- def init(self):
- # Connect to FreeSWITCH
- self.freeswitch = Freeswitch(self.backend)
+ @property
+ def backend(self):
+ return self.freeswitch.backend
- def get_phonebook(self, account=None):
- accounts = []
- for a in self.accounts.list():
- if account and a == account:
- continue
+ @property
+ def uuid(self):
+ return self.data.uuid
- if not a.is_talk_enabled():
- continue
+ @property
+ def direction(self):
+ return self.data.direction
+
+ @lazy_property
+ def caller(self):
+ return self.backend.accounts.get_by_sip_id(self.caller_number)
+
+ @property
+ def caller_name(self):
+ return self.data.cid_name
+
+ @property
+ def caller_number(self):
+ return self.data.cid_num
+
+ @lazy_property
+ def callee(self):
+ return self.backend.accounts.get_by_sip_id(self.callee_number)
- accounts.append(a)
+ @property
+ def callee_name(self):
+ return self.data.callee_name
+
+ @property
+ def callee_number(self):
+ return self.data.callee_num
+
+ @property
+ def called_number(self):
+ return self.data.dest
+
+ @property
+ def application(self):
+ return self.data.application
- return accounts
+ @property
+ def application_data(self):
+ return self.data.application_data
- def user_is_online(self, sip_id):
- res = self.db.get("SELECT 1 FROM location WHERE username = %s \
- AND expires >= NOW() LIMIT 1", sip_id)
+ @property
+ def duration(self):
+ return time.time() - self.data.created_epoch
- if res:
- return True
+ @property
+ def codec(self):
+ # We always assume a symmetric codec
+ s = [
+ "%s @ %s kHz" % (self.data.write_codec, int(self.data.write_rate) / 1000.0),
+ ]
+
+ if self.data.write_bit_rate == "0":
+ s.append("VBR")
+ else:
+ s.append("%.0f kBit/s" % (int(self.data.write_bit_rate) / 1000.0))
- return False
+ return " ".join(s)
+
+ @property
+ def secure(self):
+ return self.data.secure
+
+
+class Talk(Object):
+ def init(self):
+ # Connect to FreeSWITCH
+ self.freeswitch = Freeswitch(self.backend)
def get_lines(self, account=None):
accounts_cache = {}
return self._process_cdr(res, replace_sip_uris=True)
- # Favourites
-
- def get_favourite_contacts(self, account, limit=6):
- res = self.db.query("SELECT src_user AS caller, dst_ouser AS called, \
- COUNT(*) AS count FROM acc WHERE method = %s AND src_user = %s AND \
- dst_ouser BETWEEN %s AND %s AND time >= NOW() - INTERVAL '1 year' \
- GROUP BY caller, called ORDER BY count DESC LIMIT %s",
- "INVITE", account.sip_id, "1000", "1999", limit)
-
- return self._process_cdr(res)
-
# Conferences
@property
--- /dev/null
+{% if channels %}
+ <div class="card">
+ <div class="card-body">
+ <table class="table mb-0">
+ <tbody>
+ {% for chan in channels %}
+ <tr>
+ <td>
+ {{ chan.direction }}
+
+ {% if chan.direction == "inbound" %}
+ {% if chan.application == "conference" %}
+ CONFERENCE
+
+ {% else %}
+ {% if chan.callee %}
+ <a href="/users/{{ chan.callee.uid }}">{{ chan.callee }}</a>
+ {% else %}
+ {{ chan.callee_name }}
+ {% end %}
+
+ <span class="text-muted">({{ chan.callee_number }})</span>
+ {% end %}
+ {% elif chan.direction == "outbound" %}
+ {% if chan.caller %}
+ <a href="/users/{{ chan.caller.uid }}">{{ chan.caller }}</a>
+ {% else %}
+ {{ chan.caller_name }}
+ {% end %}
+
+ <span class="text-muted">({{ chan.caller_number }})</span>
+ {% end %}
+
+ <br>
+
+ <span class="text-muted">{{ chan.codec }}</span>
+
+ {% if chan.secure %}
+ <span class="text-muted">{{ chan.secure }}</span>
+ {% end %}
+ </td>
+
+ <td class="text-right">
+ {{ format_time(chan.duration) }}
+ </td>
+ </tr>
+ {% end %}
+ </tbody>
+ </table>
+ </div>
+ </div>
+{% end %}