1 -- Copyright 2008 Jo-Philipp Wich <xm@subsignal.org>
2 -- Licensed to the public under the Apache License 2.0.
4 local ast = require("luci.asterisk")
6 cbimap = Map("asterisk", "Registered Phones")
7 cbimap.pageaction = false
10 cbimap.uci:foreach("asterisk", "sip",
12 if s.type ~= "peer" then
14 s.info = ast.sip.peer(s.name)
20 sip_table = cbimap:section(TypedSection, "sip", "SIP Phones")
21 sip_table.template = "cbi/tblsection"
22 sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "phones", "sip", "%s")
23 sip_table.addremove = true
25 function sip_table.filter(self, s)
26 return s and not cbimap.uci:get_bool("asterisk", s, "provider")
29 function sip_table.create(self, section)
30 if TypedSection.create(self, section) then
32 cbimap.uci:tset("asterisk", section, {
39 extension = section:match("^%d+$") and section or "",
40 username = section:match("^%d+$") and section or ""
43 self.invalid_cts = true
47 function sip_table.parse(self, ...)
48 TypedSection.parse(self, ...)
50 cbimap.uci:save("asterisk")
51 luci.http.redirect(luci.dispatcher.build_url(
52 "admin", "asterisk", "phones", "sip", created
58 user = sip_table:option(DummyValue, "username", "Username")
59 function user.cfgvalue(self, s)
60 return sip_peers[s] and sip_peers[s].callerid or
61 AbstractValue.cfgvalue(self, s)
64 host = sip_table:option(DummyValue, "host", "Hostname")
65 function host.cfgvalue(self, s)
66 if sip_peers[s] and sip_peers[s].info.address then
67 return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port }
73 context = sip_table:option(DummyValue, "context", "Dialplan")
74 context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")
76 online = sip_table:option(DummyValue, "online", "Registered")
77 function online.cfgvalue(self, s)
78 if sip_peers[s] and sip_peers[s].info.online == nil then
81 return sip_peers[s] and sip_peers[s].info.online
82 and "yes" or "no (%s)" % {
83 sip_peers[s] and sip_peers[s].info.Status:lower() or "unknown"
88 delay = sip_table:option(DummyValue, "delay", "Delay")
89 function delay.cfgvalue(self, s)
90 if sip_peers[s] and sip_peers[s].info.online then
91 return "%i ms" % sip_peers[s].info.delay
97 info = sip_table:option(Button, "_info", "Info")
98 function info.write(self, s)
99 luci.http.redirect(luci.dispatcher.build_url(
100 "admin", "asterisk", "phones", "sip", s, "info"