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 Phones")
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 Phones")
33 sip_table.template = "cbi/tblsection"
34 sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "phones", "sip", "%s")
35 sip_table.addremove = true
45 function sip_table.filter(self, s)
46 return s and cbimap.uci:get("asterisk", s, "type") ~= "peer"
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", "phones", "sip", created
68 user = sip_table:option(DummyValue, "username")
69 function user.cfgvalue(self, s)
70 return sip_peers[s] and sip_peers[s].callerid or
71 AbstractValue.cfgvalue(self, s)
74 host = sip_table:option(DummyValue, "host")
75 function host.cfgvalue(self, s)
76 if sip_peers[s] and sip_peers[s].info.address then
77 return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port }
83 context = sip_table:option(DummyValue, "context")
84 context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")
86 nat = sip_table:option(DummyValue, "nat")
87 function nat.cfgvalue(self, s)
88 return sip_peers[s] and sip_peers[s].info.Nat or "none"
91 online = sip_table:option(DummyValue, "online")
92 function online.cfgvalue(self, s)
93 if sip_peers[s] and sip_peers[s].info.online == nil then
96 return sip_peers[s] and sip_peers[s].info.online
97 and "yes" or "no (%s)" % {
98 sip_peers[s] and sip_peers[s].info.Status:lower() or "unknown"
103 delay = sip_table:option(DummyValue, "delay")
104 function delay.cfgvalue(self, s)
105 if sip_peers[s] and sip_peers[s].info.online then
106 return "%i ms" % sip_peers[s].info.delay
112 info = sip_table:option(Button, "_info", "Info")
113 function info.write(self, s)
114 luci.http.redirect(luci.dispatcher.build_url(
115 "admin", "asterisk", "phones", "sip", s, "info"