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 local function find_outgoing_contexts(uci)
10 uci:foreach("asterisk", "dialplan",
12 if not h[s['.name']] then
13 c[#c+1] = { s['.name'], "Dialplan: %s" % s['.name'] }
21 local function find_incoming_contexts(uci)
25 uci:foreach("asterisk", "sip",
27 if s.context and not h[s.context] and
28 uci:get_bool("asterisk", s['.name'], "provider")
30 c[#c+1] = { s.context, "Incoming: %s" % s['.name'] or s.context }
42 if arg[2] == "info" then
43 form = SimpleForm("asterisk", "SIP Phone Information")
45 form.submit = "Back to overview"
47 local info, keys = ast.sip.peer(arg[1])
50 for _, key in ipairs(keys) do
53 val = type(info[key]) == "boolean"
54 and ( info[key] and "yes" or "no" )
55 or ( info[key] == nil or #info[key] == 0 )
57 or tostring(info[key])
61 itbl = form:section(Table, data, "SIP Phone %q" % arg[1])
62 itbl:option(DummyValue, "key", "Key")
63 itbl:option(DummyValue, "val", "Value")
65 function itbl.parse(...)
67 luci.dispatcher.build_url("admin", "asterisk", "phones")
74 -- SIP phone configuration
77 cbimap = Map("asterisk", "Edit SIP Client")
79 peer = cbimap:section(NamedSection, arg[1])
88 back = peer:option(DummyValue, "_overview", "Back to phone overview")
90 back.titleref = luci.dispatcher.build_url("admin", "asterisk", "phones")
92 active = peer:option(Flag, "disable", "Account enabled")
93 active.enabled = "yes"
94 active.disabled = "no"
95 function active.cfgvalue(...)
96 return AbstractValue.cfgvalue(...) or "yes"
99 exten = peer:option(Value, "extension", "Extension Number")
100 cbimap.uci:foreach("asterisk", "dialplanexten",
104 "%s (via %s/%s)" %{ s.extension, s.type:upper(), s.target }
108 display = peer:option(Value, "callerid", "Display Name")
110 username = peer:option(Value, "username", "Authorization ID")
111 password = peer:option(Value, "secret", "Authorization Password")
112 password.password = true
114 regtimeout = peer:option(Value, "registertimeout", "Registration Time Value")
115 function regtimeout.cfgvalue(...)
116 return AbstractValue.cfgvalue(...) or "60"
119 sipport = peer:option(Value, "port", "SIP Port")
120 function sipport.cfgvalue(...)
121 return AbstractValue.cfgvalue(...) or "5060"
124 linekey = peer:option(ListValue, "_linekey", "Linekey Mode (broken)")
125 linekey:value("", "Off")
126 linekey:value("trunk", "Trunk Appearance")
127 linekey:value("call", "Call Appearance")
129 dialplan = peer:option(ListValue, "context", "Assign Dialplan")
130 dialplan.titleref = luci.dispatcher.build_url("admin", "asterisk", "dialplans")
131 for _, v in ipairs(find_outgoing_contexts(cbimap.uci)) do
132 dialplan:value(unpack(v))
135 incoming = peer:option(StaticList, "incoming", "Receive incoming calls from")
136 for _, v in ipairs(find_incoming_contexts(cbimap.uci)) do
137 incoming:value(unpack(v))
140 --function incoming.cfgvalue(...)
141 --error(table.concat(MultiValue.cfgvalue(...),"."))