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 local function find_outgoing_contexts(uci)
22 uci:foreach("asterisk", "dialplan",
24 if not h[s['.name']] then
25 c[#c+1] = { s['.name'], "Dialplan: %s" % s['.name'] }
30 uci:foreach("asterisk", "dialzone",
32 if not h[s['.name']] then
33 c[#c+1] = { s['.name'], "Dialzone: %s" % s['.name'] }
41 local function find_incoming_contexts(uci)
45 uci:foreach("asterisk", "sip",
47 if s.context and not h[s.context] and
48 uci:get_bool("asterisk", s['.name'], "provider")
50 c[#c+1] = { s.context, "Incoming: %s" % s['.name'] or s.context }
62 if arg[2] == "info" then
63 form = SimpleForm("asterisk", "SIP Phone Information")
65 form.submit = "Back to overview"
67 local info, keys = ast.sip.peer(arg[1])
70 for _, key in ipairs(keys) do
73 val = type(info[key]) == "boolean"
74 and ( info[key] and "yes" or "no" )
75 or ( info[key] == nil or #info[key] == 0 )
77 or tostring(info[key])
81 itbl = form:section(Table, data, "SIP Phone %q" % arg[1])
82 itbl:option(DummyValue, "key", "Key")
83 itbl:option(DummyValue, "val", "Value")
85 function itbl.parse(...)
87 luci.dispatcher.build_url("admin", "asterisk", "phones")
94 -- SIP phone configuration
97 cbimap = Map("asterisk", "Edit SIP Client")
99 peer = cbimap:section(NamedSection, arg[1])
108 back = peer:option(DummyValue, "_overview", "Back to phone overview")
110 back.titleref = luci.dispatcher.build_url("admin", "asterisk", "phones")
112 active = peer:option(Flag, "disable", "Account enabled")
113 active.enabled = "yes"
114 active.disabled = "no"
115 function active.cfgvalue(...)
116 return AbstractValue.cfgvalue(...) or "yes"
119 exten = peer:option(Value, "extension", "Extension Number")
120 cbimap.uci:foreach("asterisk", "dialplanexten",
124 "%s (via %s/%s)" %{ s.extension, s.type:upper(), s.target }
128 display = peer:option(Value, "callerid", "Display Name")
130 username = peer:option(Value, "username", "Authorization ID")
131 password = peer:option(Value, "secret", "Authorization Password")
132 password.password = true
134 regtimeout = peer:option(Value, "registertimeout", "Registration Time Value")
135 function regtimeout.cfgvalue(...)
136 return AbstractValue.cfgvalue(...) or "60"
139 sipport = peer:option(Value, "port", "SIP Port")
140 function sipport.cfgvalue(...)
141 return AbstractValue.cfgvalue(...) or "5060"
144 linekey = peer:option(ListValue, "_linekey", "Linekey Mode (broken)")
145 linekey:value("", "Off")
146 linekey:value("trunk", "Trunk Appearance")
147 linekey:value("call", "Call Appearance")
149 dialplan = peer:option(ListValue, "context", "Dialplan Context")
150 for _, v in ipairs(find_outgoing_contexts(cbimap.uci)) do
151 dialplan:value(unpack(v))
154 incoming = peer:option(StaticList, "incoming", "Receive incoming calls from")
155 for _, v in ipairs(find_incoming_contexts(cbimap.uci)) do
156 incoming:value(unpack(v))
159 --function incoming.cfgvalue(...)
160 --error(table.concat(MultiValue.cfgvalue(...),"."))