Exemple #1
0
    def cut_call(self, channel, reason=""):
	    self._callID = 0
	    if reason:
		    self.log("CUTTING CALL (%s)" % (reason, ))
	    else:
		    self.log("CUTTING CALL")
            print cli.run_command("channel request hangup %s" % (channel))
Exemple #2
0
	def find_hosts(self):
		if self.hosts:
			return self.hosts
		hosts = {}
		for a in range(256):
			exten = "+00%s00@pln" % (a,)
			res = run_command("dundi lookup " + exten)
			if "EXISTS" in res:
				node_id = res[res.find('from')+5:res.find(", expires")]
				addr = res[res.find('SIP'):res.find(" (EX")]
				ip = addr.split("/")[1].split(":")[0]
				try:
					url = urlopen("http://%s" % (ip,), timeout=1)
				except:
					continue
				if url:
					data = url.read()
					url.close()
				else:
					data = False
				hosts[node_id] = {'host': ip, 'nongeo': a, 'id': node_id, 'web': data}
		for name, node in self.config.iteritems():
			if name == 'general':
				continue
			if name in hosts:
				hosts[name].update(node)
			else:
				hosts[name] = node
		self.hosts = hosts
		return hosts
Exemple #3
0
 def find_hosts(self):
     if self.hosts:
         return self.hosts
     hosts = {}
     for a in range(256):
         exten = "+00%s00@pln" % (a, )
         res = run_command("dundi lookup " + exten)
         if "EXISTS" in res:
             node_id = res[res.find('from') + 5:res.find(", expires")]
             addr = res[res.find('SIP'):res.find(" (EX")]
             ip = addr.split("/")[1].split(":")[0]
             try:
                 url = urlopen("http://%s" % (ip, ), timeout=1)
             except:
                 continue
             if url:
                 data = url.read()
                 url.close()
             else:
                 data = False
             hosts[node_id] = {
                 'host': ip,
                 'nongeo': a,
                 'id': node_id,
                 'web': data
             }
     for name, node in self.config.iteritems():
         if name == 'general':
             continue
         if name in hosts:
             hosts[name].update(node)
         else:
             hosts[name] = node
     self.hosts = hosts
     return hosts
Exemple #4
0
 def parse_connections(self):
     connections = {}
     data = run_command('dundi show peers')
     lines = data.split("\n")[1:-1]
     for line in lines:
         eid = line[0:21].strip()
         host = line[21:31].strip()
         port = line[41:48].strip()
         status = line[68:].strip()
         if 'OK' in status:
             ping = float(
                 status[status.find('(') + 1:status.find(' ms')]) / 1000.0
             status = 'OK'
         elif 'LAGGED' in status:
             ping = float(
                 status[status.find('(') + 1:status.find(' ms')]) / 1000.0
             status = 'LAGGED'
         else:
             ping = False
         connections[host] = {
             'host': host,
             'status': status,
             'ping': ping,
             'eid': eid
         }
     self.connections = connections
     return connections
    def get_channels(self):
	raw_data = cli.run_command("sip show channels")
	raw_data = raw_data.split("\n")[1:-2]
	#print raw_data
	data = {}
	for line in raw_data:
		peer = line[:18].strip()
		user = line[18:35].strip()
		call_id = line[35:52].strip()[:10]
		format = line[52:69].strip()
		hold = line[69:78].strip()
		last_message = line[78:94].strip()
		expiry = line[94:105].strip()
		peer_name = line[105:].strip()
		if not 'nothing' in format:
			#print "%s/"*8 % (peer, user, call_id, format, hold, last_message, expiry, peer_name)
			data[call_id] = [peer, user, call_id, format, hold, last_message, expiry, peer_name]
	return data
Exemple #6
0
	def parse_connections(self):
		connections = {}
		data = run_command('dundi show peers')
		lines = data.split("\n")[1:-1]
		for line in lines:
			eid = line[0:21].strip()
			host = line[21:31].strip()
			port = line[41:48].strip()
			status = line[68:].strip()
			if 'OK' in status:
				ping = float(status[status.find('(')+1:status.find(' ms')])/1000.0
				status = 'OK'
			elif 'LAGGED' in status:
				ping = float(status[status.find('(')+1:status.find(' ms')])/1000.0
				status = 'LAGGED'
			else:
				ping = False
			connections[host] = {'host': host, 'status': status, 'ping': ping, 'eid': eid}
		self.connections = connections
		return connections
    def get_channelstats(self):
	raw_data = cli.run_command("sip show channelstats")
	raw_data = raw_data.split("\n")[1:-2]
	#print raw_data
	data = {}
	for line in raw_data:
		peer = line[:18].strip()
		call_id = line[18:31].strip()[:10]
		duration = line[31:40].strip()
		rx_pack = line[40:52].strip()
		rx_lost = line[52:63].strip()
		rx_per = line[63:72].strip(" )(")
		rx_jitter = line[72:79].strip()
		tx_pack = line[79:91].strip()
		tx_lost = line[91:102].strip()
		tx_per = line[102:111].strip(" )(")
		tx_jitter = line[111:].strip()
		#print peer, call_id, rx_per, tx_per
		data[call_id] = [call_id, duration, rx_pack, rx_lost, rx_per, rx_jitter, tx_pack, tx_lost, tx_per, tx_jitter]
	return data
Exemple #8
0
 def get_channels(self):
     raw_data = cli.run_command("sip show channels")
     raw_data = raw_data.split("\n")[1:-2]
     #print raw_data
     data = {}
     for line in raw_data:
         peer = line[:18].strip()
         user = line[18:35].strip()
         call_id = line[35:52].strip()[:10]
         format = line[52:69].strip()
         hold = line[69:78].strip()
         last_message = line[78:94].strip()
         expiry = line[94:105].strip()
         peer_name = line[105:].strip()
         if not 'nothing' in format:
             #print "%s/"*8 % (peer, user, call_id, format, hold, last_message, expiry, peer_name)
             data[call_id] = [
                 peer, user, call_id, format, hold, last_message, expiry,
                 peer_name
             ]
     return data
Exemple #9
0
 def get_channelstats(self):
     raw_data = cli.run_command("sip show channelstats")
     raw_data = raw_data.split("\n")[1:-2]
     #print raw_data
     data = {}
     for line in raw_data:
         peer = line[:18].strip()
         call_id = line[18:31].strip()[:10]
         duration = line[31:40].strip()
         rx_pack = line[40:52].strip()
         rx_lost = line[52:63].strip()
         rx_per = line[63:72].strip(" )(")
         rx_jitter = line[72:79].strip()
         tx_pack = line[79:91].strip()
         tx_lost = line[91:102].strip()
         tx_per = line[102:111].strip(" )(")
         tx_jitter = line[111:].strip()
         #print peer, call_id, rx_per, tx_per
         data[call_id] = [
             call_id, duration, rx_pack, rx_lost, rx_per, rx_jitter,
             tx_pack, tx_lost, tx_per, tx_jitter
         ]
     return data
Exemple #10
0
def reload_peer(peer_name):
    cli.run_command('sip prune realtime peer ' + peer_name)
    cli.run_command('sip show peer ' + peer_name + ' load')
Exemple #11
0
    def render_GET(self, request):
	user = session.get_user(request)
	if not user:
		return redirectTo("/", request)
	model = Model()
	output = cli.run_command('sip show peers')
	lines = output.split("\n")
	res = ""
	formatted = {"local": "<tr><th>Nombre</th><th>Ext</th><th>Estado</th><th>Latencia</th><tr>\n",
		     "channels": "<tr><th>Nombre</th><th>Estado</th><th>Latencia</th><tr>\n",
		     "end": "<tr><th>Nombre</th><th>Ext</th><th>Estado</th><th>Latencia</th><tr>\n"}
	for line in lines[1:]:
		line = line.replace(" D ", "")
		line = line.replace(" N ", "")
		line = line.replace(" a ", "")
		line = line.replace(" A ", "")
		line = line.replace("Cached RT", "")
		parts = line.split()
		parts = map(lambda s: s.strip("()"), parts)
		if len(parts) > 8 or len(parts) <= 3 :
			continue
		peer_name = parts[0].split("/")[0]
		ext = None
		peer = model.query(SipPeer).filter_by(name=peer_name).first()
		if peer:
			ext = peer.regexten

		if (" OK" in line or "LAGGED" in line) and ext: # and "192.168." in line:
			# line = self.add_ip_href(line)
			dest = 'local'
		elif ext:
			dest = 'end'
		else:
			dest = 'channels'
		if len(parts) > 4:
			# connected
			if dest == 'channels':
				output = "<tr><td>%s</td><td>%s</td><td>%sms</td><tr>" % (peer_name, parts[3], parts[4])
			else:
				output = "<tr><td>%s</td><td>%s</td><td>%s</td><td>%sms</td><tr>" % (peer_name, ext, parts[3], parts[4])
		elif len(parts) > 3:
			if dest == 'channels':
				output = "<tr><td>%s</td><td>%s</td><td></td>" % (peer_name, parts[3])
			else:
				output = "<tr><td>%s</td><td>%s</td><td>%s</td><td></td>" % (peer_name, ext, parts[3])
		else:
			print "not enough parts", parts
			continue
		formatted[dest] += output+"\n"
	res += "<h2>Local</h2>"
	res += "<table>"
	res += formatted['local']
	res += "</table>"
	if user.admin:
		res += "<h2>Channels</h2><table>"
		res += formatted['channels']
		res += "</table>"
	res += "<h2>Other</h2><table>"
	res += formatted['end']
	res += "</table><pre>"
	res += "<h2>Calls</h2>"
	res += cli.run_command('core show calls')
	res += "</pre><pre>"
	res += cli.run_command('core show uptime')
	res += "</pre>"
	return print_template('content-pbx-lorea', {'content': res})
Exemple #12
0
    def get_peers(self):
	model = Model()
	output = cli.run_command('sip show peers')
	lines = output.split("\n")
	res = ""
	pln_nodes = []
	formatted = {"local": [],
		     "channels": [],
		     "pln": [],
		     "end": []}
	for line in lines[1:]:
		line = line.replace(" D ", "")
		line = line.replace(" N ", "")
		line = line.replace(" a ", "")
		line = line.replace(" A ", "")
		line = line.replace("Cached RT", "")
		parts = line.split()
		parts = map(lambda s: s.strip("()"), parts)
		if len(parts) > 8 or len(parts) <= 3 :
			continue
		peer_name = parts[0].split("/")[0]
		ext = None
		ip = parts[1].strip()
		port = parts[2].strip()
		peer = model.query(SipPeer).filter_by(name=peer_name).first()
		output = {'name': peer_name, 'status': parts[3]}
		if peer:
			ext = peer.regexten
		if ext: # and "192.168." in line:
			# line = self.add_ip_href(line)
			dest = 'local'
			output['useragent'] = peer.useragent
			if peer.encryption == 'yes':
				output['srtp'] = True
			else:
				output['srtp'] = False
			if peer.fullcontact and 'transport=tls' in peer.fullcontact.lower():
				output['tls'] = True
			else:
				output['tls'] = False
		elif ip.startswith('1.'):
			dest = 'pln'
			if peer_name in pln_nodes:
				continue
			pln_nodes.append(peer_name)
		else:
			dest = 'channels'
		if len(parts) > 4 and not port == '0':
			# connected
			if dest == 'channels':
				output['ping'] = parts[4]
			else:
				output['exten'] = ext
				output['ping'] = parts[4]
		elif len(parts) > 3:
			if ext:
				output['exten'] = ext
		formatted[dest].append(output)
	dundi_output = cli.run_command('dundi show peers')
	lines = dundi_output.split("\n")
	res = ""
	for line in lines[1:-2]:
		line = line.replace("(S)", "")
		parts = line.split()
		if not len(parts) > 5:
			continue
		pln_id = parts[0]
		if pln_id == '00:50:bf:5a:71:6b':
			# ourselves
			continue
		pln_ip = parts[1]
		pln_port = parts[2]
		pln_model = parts[3]
		avg_time = parts[4]
		status = parts[5]
		dundi_peer = self.get_dundi_peer_name(pln_id)
		if dundi_peer in pln_nodes:
			continue
		if len(parts) > 6:
			latency = parts[6].strip("(")
		else:
			latency = ''
		output = {'name': dundi_peer, 'status': status, 'ping': latency}
		formatted['pln'].append(output)
		
	return formatted
Exemple #13
0
def reload_peer(peer_name):
    cli.run_command("sip prune realtime peer " + peer_name)
    cli.run_command("sip show peer " + peer_name + " load")
Exemple #14
0
    def get_dundi_peer(self, dundi_id):
	if not dundi_id in self._dundi_peers:
		self._dundi_peers[dundi_id] = cli.run_command('dundi show peer ' + dundi_id)
	return self._dundi_peers[dundi_id]
Exemple #15
0
    def get_peers(self):
        model = Model()
        output = cli.run_command('sip show peers')
        lines = output.split("\n")
        res = ""
        pln_nodes = []
        formatted = {"local": [], "channels": [], "pln": [], "end": []}
        for line in lines[1:]:
            line = line.replace(" D ", "")
            line = line.replace(" N ", "")
            line = line.replace(" a ", "")
            line = line.replace(" A ", "")
            line = line.replace("Cached RT", "")
            parts = line.split()
            parts = map(lambda s: s.strip("()"), parts)
            if len(parts) > 8 or len(parts) <= 3:
                continue
            peer_name = parts[0].split("/")[0]
            ext = None
            ip = parts[1].strip()
            port = parts[2].strip()
            peer = model.query(SipPeer).filter_by(name=peer_name).first()
            output = {'name': peer_name, 'status': parts[3]}
            if peer:
                ext = peer.regexten
            if ext:  # and "192.168." in line:
                # line = self.add_ip_href(line)
                dest = 'local'
                output['useragent'] = peer.useragent
                if peer.encryption == 'yes':
                    output['srtp'] = True
                else:
                    output['srtp'] = False
                if peer.fullcontact and 'transport=tls' in peer.fullcontact.lower(
                ):
                    output['tls'] = True
                else:
                    output['tls'] = False
            elif ip.startswith('1.'):
                dest = 'pln'
                if peer_name in pln_nodes:
                    continue
                pln_nodes.append(peer_name)
            else:
                dest = 'channels'
            if len(parts) > 4 and not port == '0':
                # connected
                if dest == 'channels':
                    output['ping'] = parts[4]
                else:
                    output['exten'] = ext
                    output['ping'] = parts[4]
            elif len(parts) > 3:
                if ext:
                    output['exten'] = ext
            formatted[dest].append(output)
        dundi_output = cli.run_command('dundi show peers')
        lines = dundi_output.split("\n")
        res = ""
        for line in lines[1:-2]:
            line = line.replace("(S)", "")
            parts = line.split()
            if not len(parts) > 5:
                continue
            pln_id = parts[0]
            if pln_id == '00:50:bf:5a:71:6b':
                # ourselves
                continue
            pln_ip = parts[1]
            pln_port = parts[2]
            pln_model = parts[3]
            avg_time = parts[4]
            status = parts[5]
            dundi_peer = self.get_dundi_peer_name(pln_id)
            if dundi_peer in pln_nodes:
                continue
            if len(parts) > 6:
                latency = parts[6].strip("(")
            else:
                latency = ''
            output = {'name': dundi_peer, 'status': status, 'ping': latency}
            formatted['pln'].append(output)

        return formatted
Exemple #16
0
    def render_GET(self, request):
        user = session.get_user(request)
        if not user:
            return redirectTo("/", request)
        model = Model()
        output = cli.run_command('sip show peers')
        lines = output.split("\n")
        res = ""
        formatted = {
            "local":
            "<tr><th>Nombre</th><th>Ext</th><th>Estado</th><th>Latencia</th><tr>\n",
            "channels":
            "<tr><th>Nombre</th><th>Estado</th><th>Latencia</th><tr>\n",
            "end":
            "<tr><th>Nombre</th><th>Ext</th><th>Estado</th><th>Latencia</th><tr>\n"
        }
        for line in lines[1:]:
            line = line.replace(" D ", "")
            line = line.replace(" N ", "")
            line = line.replace(" a ", "")
            line = line.replace(" A ", "")
            line = line.replace("Cached RT", "")
            parts = line.split()
            parts = map(lambda s: s.strip("()"), parts)
            if len(parts) > 8 or len(parts) <= 3:
                continue
            peer_name = parts[0].split("/")[0]
            ext = None
            peer = model.query(SipPeer).filter_by(name=peer_name).first()
            if peer:
                ext = peer.regexten

            if ("OK" in line
                    or "LAGGED" in line) and ext:  # and "192.168." in line:
                # line = self.add_ip_href(line)
                dest = 'local'
            elif ext:
                dest = 'end'
            else:
                dest = 'channels'
            if len(parts) > 4:
                # connected
                if dest == 'channels':
                    output = "<tr><td>%s</td><td>%s</td><td>%sms</td><tr>" % (
                        peer_name, parts[3], parts[4])
                else:
                    output = "<tr><td>%s</td><td>%s</td><td>%s</td><td>%sms</td><tr>" % (
                        peer_name, ext, parts[3], parts[4])
            elif len(parts) > 3:
                if dest == 'channels':
                    output = "<tr><td>%s</td><td>%s</td><td></td>" % (
                        peer_name, parts[3])
                else:
                    output = "<tr><td>%s</td><td>%s</td><td>%s</td><td></td>" % (
                        peer_name, ext, parts[3])
            else:
                print "not enough parts", parts
                continue
            formatted[dest] += output + "\n"
        res += "<h2>Local</h2>"
        res += "<table>"
        res += formatted['local']
        res += "</table>"
        if user.admin:
            res += "<h2>Channels</h2><table>"
            res += formatted['channels']
            res += "</table>"
        res += "<h2>Other</h2><table>"
        res += formatted['end']
        res += "</table><pre>"
        res += "<h2>Calls</h2>"
        res += cli.run_command('core show calls')
        res += "</pre><pre>"
        res += cli.run_command('core show uptime')
        res += "</pre>"
        return print_template('content-pbx-lorea', {'content': res})
Exemple #17
0
 def get_dundi_peer(self, dundi_id):
     if not dundi_id in self._dundi_peers:
         self._dundi_peers[dundi_id] = cli.run_command('dundi show peer ' +
                                                       dundi_id)
     return self._dundi_peers[dundi_id]