def render_mailbox(self, user_ext): output = "<h1>Correo de voz</h1>\n" model = Model() model.session.commit() # refresh session all_messages = model.query(VoiceMailMessage).filter_by(mailboxuser=user_ext) folders = set() for message in all_messages: folders.add(message.dir) folders = list(folders) folders.sort() for folder in folders: result = [] messages = model.query(VoiceMailMessage).filter_by(mailboxuser=user_ext, dir=folder) output += "<h2>"+os.path.basename(folder)+"</h2>\n" for message in messages: actions2 = "" if message.msg_id: audio = html.format_audio('/voicemail/message/' + message.msg_id) actions = '<form method="POST" action="/voicemail/delete/%s/%s"><input type="hidden" name="msg_id" value="%s" /><input type="hidden" name="user_ext" value="%s" /><input type="submit" name="submit" value="Borrar" /></form>' % (user_ext, message.msg_id, message.msg_id, user_ext) if folder.endswith('INBOX'): actions2 += '<form method="POST" action="/voicemail/archive/%s/%s"><input type="hidden" name="msg_id" value="%s" /><input type="hidden" name="user_ext" value="%s" /><input type="submit" name="submit" value="Archivar" /></form>' % (user_ext, message.msg_id, message.msg_id, user_ext) else: audio = "" actions = "" result.append([message.callerid, time.ctime(message.origtime), str(message.duration), audio, actions, actions2]) output += html.format_table([['origen', 'fecha', 'duracion', 'audio', 'actions', '']] + result) return output
def render_dundipeers(self, request, peers, connections): res = [['name', 'address', 'nongeo', 'alias', 'signal']] for name, node in peers.iteritems(): address = node.get('host', '') nongeo = str(node.get('nongeo', '')) alias = str(node.get('inkey', '')) online = 'no' if address and address in connections: ping = connections[address]['ping'] online = format_ping(ping) res.append([name, address, nongeo, alias, online]) return html.format_table(res)
def render_dundipeers(self, request, peers, connections): res = [["name", "address", "nongeo", "alias", "signal"]] for name, node in peers.iteritems(): address = node.get("host", "") nongeo = str(node.get("nongeo", "")) alias = str(node.get("inkey", "")) online = "no" if address and address in connections: ping = connections[address]["ping"] online = format_ping(ping) res.append([name, address, nongeo, alias, online]) return html.format_table(res)
def render_tincpeers(self, request, tinc): res = [["name", "address", "subnet", "signal"]] for name, node in tinc.nodes.iteritems(): address = node.get("address", "") subnet = node.get("subnet", "") online = ok_icon(False) if subnet: ping = do_one(subnet, 1) if ping: online = format_ping(ping) else: online = format_ping(False) res.append([name, address, subnet, online]) return html.format_table(res)
def render_tincpeers(self, request, tinc): res = [['name', 'address', 'subnet', 'signal']] for name, node in tinc.nodes.iteritems(): address = node.get('address', '') subnet = node.get('subnet', '') online = ok_icon(False) if subnet: ping = do_one(subnet, 1) if ping: online = format_ping(ping) else: online = format_ping(False) res.append([name, address, subnet, online]) return html.format_table(res)
def render_all_text(self): model = Model() calls = model.query(Call).order_by(desc(Call.timestamp)).limit(1000) origins = set() count_country = defaultdict(int) result = "" call_data = [['Origin', 'Destination', 'Country', 'Duration', 'Date']] for call in calls: country_data = ext2country(str(call.destination)) count_country[country_data[0]+"-"+country_data[1]] += 1 if call.user: origin = str(call.user.voip_id) origins.add(str(call.user.voip_id)) else: origin = "unknown" origins.add('unknown') destination = str(call.destination) country_data = ": ".join(country_data) duration = "%.2f min" % (call.duration/60.0,) date = str(self.format_date(call.timestamp)) call_data.append([origin, destination, country_data, duration, date]) result += html.format_table(call_data) # country stats country_data = [['Country', 'Count']] for key, value in count_country.iteritems(): country_data.append([key, str(value)]) result += html.format_table(country_data) # number of origins origins = list(origins) origins.sort() result += "<p>Origins (%s): %s</p>" % (len(origins), str(origins)) return print_template('content-pbx-lorea', {'content': result})
def render_stats(self, request): output = "<h2>Estadisticas llamadas en el ultimo mes</h2>" model = obelisk.model.Model() ts_start = time.time() - 60 * 60 * 24 * 30 calls = model.query(obelisk.model.Call).filter( obelisk.model.Call.timestamp > datetime.fromtimestamp(ts_start)) all_calls = set() es_mobiles = set() mobiles_min = 0.0 mobiles_min_2 = 0.0 mobiles_min_3 = 0.0 mobiles_min_4 = 0.0 es_fixes = set() users = set() mobile_freq = {} for c in calls: if c.user: users.add(c.user.voip_id) destination = c.destination destination = destination.replace('+', '00') if len(destination) == 3: continue elif destination.startswith('0000'): continue elif len(destination) == 9: destination = '0034' + destination if destination.startswith('00349') or destination.startswith( '00348'): es_fixes.add(destination) elif destination.startswith('0034'): es_mobiles.add(destination) mobiles_min += c.charged / 60.0 if destination in mobile_freq: mobile_freq[destination] += 1 else: mobile_freq[destination] = 1 all_calls.add(destination) # call stats for last month output += 'total calls %d\n' % (len(all_calls), ) output += 'distinct es fix ' + str(len(es_fixes)) + "\n" output += 'distinct es mob %d \n' % (len(es_mobiles), ) output += 'distinct users: %d minutes to mobiles: %d\n' % (len(users), mobiles_min) mobile_freq_2 = filter(lambda s: mobile_freq[s] > 1, mobile_freq) mobile_freq_3 = filter(lambda s: mobile_freq[s] > 2, mobile_freq_2) mobile_freq_4 = filter(lambda s: mobile_freq[s] > 3, mobile_freq_3) for c in calls: destination = c.destination destination = destination.replace('+', '00') if len(destination) == 9: destination = '0034' + destination if destination in mobile_freq_2: mobiles_min_2 += c.charged / 60.0 if destination in mobile_freq_3: mobiles_min_3 += c.charged / 60.0 if destination in mobile_freq_4: mobiles_min_4 += c.charged / 60.0 output += "frequencies: 2/%d/%d 3/%d/%d 4/%d/%d\n" % ( len(mobile_freq_2), mobiles_min_2, len(mobile_freq_3), mobiles_min_3, len(mobile_freq_4), mobiles_min_4) # call stats per provider output += "<h2>Llamadas por proveedor en la ultima semana</h2>" ts_start_week = time.time() - 60 * 60 * 24 * 7 providers = model.query(obelisk.model.Provider) results = [] for provider in providers: if not provider.name: continue calls = provider.calls.filter( obelisk.model.Call.timestamp > datetime.fromtimestamp( ts_start_week)) total_time = 0 total_calls = 0 total_freq_2 = 0 total_freq_3 = 0 total_freq_4 = 0 for call in calls: duration = call.charged if call.rate == 0.0: total_time += duration / 60.0 total_calls += 1 destination = call.destination.replace('+', '00') if len(destination) == 9: destination = '0034' + destination if destination in mobile_freq_2: total_freq_2 += duration / 60.0 if destination in mobile_freq_3: total_freq_3 += duration / 60.0 if destination in mobile_freq_4: total_freq_4 += duration / 60.0 results.append([ provider.name, "%d" % (total_time, ), str(total_calls), str(len(list(calls))), str(total_freq_2), str(total_freq_3), str(total_freq_4) ]) output += html.format_table([[ "Nombre", "Minutos gratis", "Llamadas gratis", "Total llamadas", "Freq 2", "Freq 3", "Freq 4" ]] + results) return output
def render_stats(self, request): output = "<h2>Estadisticas llamadas en el ultimo mes</h2>" model = obelisk.model.Model() ts_start = time.time() - 60*60*24*30 calls = model.query(obelisk.model.Call).filter(obelisk.model.Call.timestamp>datetime.fromtimestamp(ts_start)) all_calls = set() es_mobiles = set() mobiles_min = 0.0 mobiles_min_2 = 0.0 mobiles_min_3 = 0.0 mobiles_min_4 = 0.0 es_fixes = set() users = set() mobile_freq = {} for c in calls: if c.user: users.add(c.user.voip_id) destination = c.destination destination = destination.replace('+', '00') if len(destination) == 3: continue elif destination.startswith('0000'): continue elif len(destination) == 9: destination = '0034' + destination if destination.startswith('00349') or destination.startswith('00348'): es_fixes.add(destination) elif destination.startswith('0034'): es_mobiles.add(destination) mobiles_min += c.charged/60.0 if destination in mobile_freq: mobile_freq[destination] += 1 else: mobile_freq[destination] = 1 all_calls.add(destination) # call stats for last month output += 'total calls %d\n' % (len(all_calls),) output += 'distinct es fix ' + str(len(es_fixes)) + "\n" output += 'distinct es mob %d \n' % (len(es_mobiles),) output += 'distinct users: %d minutes to mobiles: %d\n' % (len(users), mobiles_min) mobile_freq_2 = filter(lambda s: mobile_freq[s] > 1, mobile_freq) mobile_freq_3 = filter(lambda s: mobile_freq[s] > 2, mobile_freq_2) mobile_freq_4 = filter(lambda s: mobile_freq[s] > 3, mobile_freq_3) for c in calls: destination = c.destination destination = destination.replace('+', '00') if len(destination) == 9: destination = '0034' + destination if destination in mobile_freq_2: mobiles_min_2 += c.charged/60.0 if destination in mobile_freq_3: mobiles_min_3 += c.charged/60.0 if destination in mobile_freq_4: mobiles_min_4 += c.charged/60.0 output += "frequencies: 2/%d/%d 3/%d/%d 4/%d/%d\n" % (len(mobile_freq_2), mobiles_min_2, len(mobile_freq_3), mobiles_min_3, len(mobile_freq_4), mobiles_min_4) # call stats per provider output += "<h2>Llamadas por proveedor en la ultima semana</h2>" ts_start_week = time.time() - 60*60*24*7 providers = model.query(obelisk.model.Provider) results = [] for provider in providers: if not provider.name: continue calls = provider.calls.filter(obelisk.model.Call.timestamp>datetime.fromtimestamp(ts_start_week)) total_time = 0 total_calls = 0 total_freq_2 = 0 total_freq_3 = 0 total_freq_4 = 0 for call in calls: duration = call.charged if call.rate == 0.0: total_time += duration/60.0 total_calls += 1 destination = call.destination.replace('+', '00') if len(destination) == 9: destination = '0034' + destination if destination in mobile_freq_2: total_freq_2 += duration / 60.0 if destination in mobile_freq_3: total_freq_3 += duration / 60.0 if destination in mobile_freq_4: total_freq_4 += duration / 60.0 results.append([provider.name, "%d" % (total_time,), str(total_calls), str(len(list(calls))), str(total_freq_2), str(total_freq_3), str(total_freq_4)]) output += html.format_table([["Nombre", "Minutos gratis", "Llamadas gratis", "Total llamadas", "Freq 2", "Freq 3", "Freq 4"]]+results) return output