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
37 function sip_table.filter(self, s)
38 return s and not cbimap.uci:get_bool("asterisk", s, "provider")
41 function sip_table.create(self, section)
42 if TypedSection.create(self, section) then
44 cbimap.uci:tset("asterisk", section, {
51 extension = section:match("^%d+$") and section or "",
52 username = section:match("^%d+$") and section or ""
55 self.invalid_cts = true
59 function sip_table.parse(self, ...)
60 TypedSection.parse(self, ...)
62 cbimap.uci:save("asterisk")
63 luci.http.redirect(luci.dispatcher.build_url(
64 "admin", "asterisk", "phones", "sip", created
70 user = sip_table:option(DummyValue, "username", "Username")
71 function user.cfgvalue(self, s)
72 return sip_peers[s] and sip_peers[s].callerid or
73 AbstractValue.cfgvalue(self, s)
76 host = sip_table:option(DummyValue, "host", "Hostname")
77 function host.cfgvalue(self, s)
78 if sip_peers[s] and sip_peers[s].info.address then
79 return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port }
85 context = sip_table:option(DummyValue, "context", "Dialplan")
86 context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")
88 online = sip_table:option(DummyValue, "online", "Registered")
89 function online.cfgvalue(self, s)
90 if sip_peers[s] and sip_peers[s].info.online == nil then
93 return sip_peers[s] and sip_peers[s].info.online
94 and "yes" or "no (%s)" % {
95 sip_peers[s] and sip_peers[s].info.Status:lower() or "unknown"
100 delay = sip_table:option(DummyValue, "delay", "Delay")
101 function delay.cfgvalue(self, s)
102 if sip_peers[s] and sip_peers[s].info.online then
103 return "%i ms" % sip_peers[s].info.delay
109 info = sip_table:option(Button, "_info", "Info")
110 function info.write(self, s)
111 luci.http.redirect(luci.dispatcher.build_url(
112 "admin", "asterisk", "phones", "sip", s, "info"