2 LuCI - Lua Configuration Interface
4 Copyright 2008 Jo-Philipp Wich <xm@subsignal.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
16 local ast = require("luci.asterisk")
18 cbimap = Map("asterisk", "Registered Trunks")
19 cbimap.pageaction = false
22 cbimap.uci:foreach("asterisk", "sip",
24 if s.type == "peer" then
26 s.info = ast.sip.peer(s.name)
32 sip_table = cbimap:section(TypedSection, "sip", "SIP Trunks")
33 sip_table.template = "cbi/tblsection"
34 sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s")
35 sip_table.addremove = true
42 function sip_table.filter(self, s)
44 cbimap.uci:get("asterisk", s, "type") == "peer" or
45 cbimap.uci:get("asterisk", s, "type") == nil
49 function sip_table.create(self, section)
50 if TypedSection.create(self, section) then
53 self.invalid_cts = true
57 function sip_table.parse(self, ...)
58 TypedSection.parse(self, ...)
60 cbimap.uci:save("asterisk")
61 luci.http.redirect(luci.dispatcher.build_url(
62 "admin", "asterisk", "trunks", "sip", created
68 user = sip_table:option(DummyValue, "username")
70 host = sip_table:option(DummyValue, "host")
71 function host.cfgvalue(self, s)
72 if sip_peers[s] and sip_peers[s].info.address then
73 return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port }
79 context = sip_table:option(DummyValue, "context")
80 context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")
81 function context.cfgvalue(...)
82 return AbstractValue.cfgvalue(...) or "(default)"
85 nat = sip_table:option(DummyValue, "nat")
86 function nat.cfgvalue(self, s)
87 return sip_peers[s] and sip_peers[s].info.Nat or "none"
90 online = sip_table:option(DummyValue, "online")
91 function online.cfgvalue(self, s)
92 if sip_peers[s] and sip_peers[s].info.online == nil then
95 return sip_peers[s] and sip_peers[s].info.online
96 and "yes" or "no (%s)" %{
97 sip_peers[s] and sip_peers[s].info.Status:lower() or "unknown"
102 delay = sip_table:option(DummyValue, "delay")
103 function delay.cfgvalue(self, s)
104 if sip_peers[s] and sip_peers[s].info.online then
105 return "%i ms" % sip_peers[s].info.delay
111 info = sip_table:option(Button, "_info", "Info")
112 function info.write(self, s)
113 luci.http.redirect(luci.dispatcher.build_url(
114 "admin", "asterisk", "trunks", "sip", s, "info"