1 -- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
4 local ast = require("luci.asterisk")
6 cbimap = Map("asterisk", "Registered Trunks")
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 Trunks")
21 sip_table.template = "cbi/tblsection"
22 sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s")
23 sip_table.addremove = true
24 sip_table.sectionhead = "Extension"
26 function sip_table.filter(self, s)
28 cbimap.uci:get("asterisk", s, "type") == nil or
29 cbimap.uci:get_bool("asterisk", s, "provider")
33 function sip_table.create(self, section)
34 if TypedSection.create(self, section) then
37 self.invalid_cts = true
41 function sip_table.parse(self, ...)
42 TypedSection.parse(self, ...)
44 cbimap.uci:tset("asterisk", created, {
50 cbimap.uci:save("asterisk")
51 luci.http.redirect(luci.dispatcher.build_url(
52 "admin", "asterisk", "trunks", "sip", created
58 user = sip_table:option(DummyValue, "username", "Username")
60 host = sip_table:option(DummyValue, "host", "Hostname")
61 function host.cfgvalue(self, s)
62 if sip_peers[s] and sip_peers[s].info.address then
63 return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port }
69 context = sip_table:option(DummyValue, "context", "Dialplan")
70 context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")
71 function context.cfgvalue(...)
72 return AbstractValue.cfgvalue(...) or "(default)"
75 online = sip_table:option(DummyValue, "online", "Registered")
76 function online.cfgvalue(self, s)
77 if sip_peers[s] and sip_peers[s].info.online == nil then
80 return sip_peers[s] and sip_peers[s].info.online
81 and "yes" or "no (%s)" %{
82 sip_peers[s] and sip_peers[s].info.Status:lower() or "unknown"
87 delay = sip_table:option(DummyValue, "delay", "Delay")
88 function delay.cfgvalue(self, s)
89 if sip_peers[s] and sip_peers[s].info.online then
90 return "%i ms" % sip_peers[s].info.delay
96 info = sip_table:option(Button, "_info", "Info")
97 function info.write(self, s)
98 luci.http.redirect(luci.dispatcher.build_url(
99 "admin", "asterisk", "trunks", "sip", s, "info"