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'] }
33 local function find_incoming_contexts(uci)
37 uci:foreach("asterisk", "sip",
39 if s.context and not h[s.context] and
40 uci:get_bool("asterisk", s['.name'], "provider")
42 c[#c+1] = { s.context, "Incoming: %s" % s['.name'] or s.context }
54 if arg[2] == "info" then
55 form = SimpleForm("asterisk", "SIP Phone Information")
57 form.submit = "Back to overview"
59 local info, keys = ast.sip.peer(arg[1])
62 for _, key in ipairs(keys) do
65 val = type(info[key]) == "boolean"
66 and ( info[key] and "yes" or "no" )
67 or ( info[key] == nil or #info[key] == 0 )
69 or tostring(info[key])
73 itbl = form:section(Table, data, "SIP Phone %q" % arg[1])
74 itbl:option(DummyValue, "key", "Key")
75 itbl:option(DummyValue, "val", "Value")
77 function itbl.parse(...)
79 luci.dispatcher.build_url("admin", "asterisk", "phones")
86 -- SIP phone configuration
89 cbimap = Map("asterisk", "Edit SIP Client")
91 peer = cbimap:section(NamedSection, arg[1])
100 back = peer:option(DummyValue, "_overview", "Back to phone overview")
102 back.titleref = luci.dispatcher.build_url("admin", "asterisk", "phones")
104 active = peer:option(Flag, "disable", "Account enabled")
105 active.enabled = "yes"
106 active.disabled = "no"
107 function active.cfgvalue(...)
108 return AbstractValue.cfgvalue(...) or "yes"
111 exten = peer:option(Value, "extension", "Extension Number")
112 cbimap.uci:foreach("asterisk", "dialplanexten",
116 "%s (via %s/%s)" %{ s.extension, s.type:upper(), s.target }
120 display = peer:option(Value, "callerid", "Display Name")
122 username = peer:option(Value, "username", "Authorization ID")
123 password = peer:option(Value, "secret", "Authorization Password")
124 password.password = true
126 regtimeout = peer:option(Value, "registertimeout", "Registration Time Value")
127 function regtimeout.cfgvalue(...)
128 return AbstractValue.cfgvalue(...) or "60"
131 sipport = peer:option(Value, "port", "SIP Port")
132 function sipport.cfgvalue(...)
133 return AbstractValue.cfgvalue(...) or "5060"
136 linekey = peer:option(ListValue, "_linekey", "Linekey Mode (broken)")
137 linekey:value("", "Off")
138 linekey:value("trunk", "Trunk Appearance")
139 linekey:value("call", "Call Appearance")
141 dialplan = peer:option(ListValue, "context", "Assign Dialplan")
142 dialplan.titleref = luci.dispatcher.build_url("admin", "asterisk", "dialplans")
143 for _, v in ipairs(find_outgoing_contexts(cbimap.uci)) do
144 dialplan:value(unpack(v))
147 incoming = peer:option(StaticList, "incoming", "Receive incoming calls from")
148 for _, v in ipairs(find_incoming_contexts(cbimap.uci)) do
149 incoming:value(unpack(v))
152 --function incoming.cfgvalue(...)
153 --error(table.concat(MultiValue.cfgvalue(...),"."))