diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-02-24 01:09:51 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-02-24 01:09:51 +0000 |
commit | cebe6f031bc475e8e21102c4b5e378e1fa7bcf54 (patch) | |
tree | db68b297c46e0dd85279486eb1a24b4096429aae /applications/luci-asterisk/luasrc/model/cbi | |
parent | 1eec55dd47a6a54c18f6de655279ad75c1d3a01b (diff) |
applications/luci-asterisk:
- initial dialplan management
- disabled uci scheme
- improved context handling in sip and trunk settings
Diffstat (limited to 'applications/luci-asterisk/luasrc/model/cbi')
6 files changed, 347 insertions, 55 deletions
diff --git a/applications/luci-asterisk/luasrc/model/cbi/asterisk/dialplan_out.lua b/applications/luci-asterisk/luasrc/model/cbi/asterisk/dialplan_out.lua new file mode 100644 index 0000000000..c8538426cf --- /dev/null +++ b/applications/luci-asterisk/luasrc/model/cbi/asterisk/dialplan_out.lua @@ -0,0 +1,134 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ + +]]-- + +local ast = require("luci.asterisk") + +local function find_outgoing_contexts(uci) + local c = { } + local h = { } + +-- uci:foreach("asterisk", "dialplan", +-- function(s) +-- if not h[s['.name']] then +-- c[#c+1] = { s['.name'], "Dialplan: %s" % s['.name'] } +-- h[s['.name']] = true +-- end +-- end) + + uci:foreach("asterisk", "dialzone", + function(s) + if not h[s['.name']] then + c[#c+1] = { s['.name'], "Dialzone: %s" % s['.name'] } + h[s['.name']] = true + end + end) + + return c +end + +local function find_incoming_contexts(uci) + local c = { } + local h = { } + + uci:foreach("asterisk", "sip", + function(s) + if s.context and not h[s.context] and + uci:get_bool("asterisk", s['.name'], "provider") + then + c[#c+1] = { s.context, "Incoming: %s" % s['.name'] or s.context } + h[s.context] = true + end + end) + + return c +end + +local function find_trunks(uci) + local t = { } + + uci:foreach("asterisk", "sip", + function(s) + if uci:get_bool("asterisk", s['.name'], "provider") then + t[#t+1] = { + "SIP/%s" % s['.name'], + "SIP: %s" % s['.name'] + } + end + end) + + uci:foreach("asterisk", "iax", + function(s) + t[#t+1] = { + "IAX/%s" % s['.name'], + "IAX: %s" % s.extension or s['.name'] + } + end) + + return t +end + +--[[ + +dialzone {name} - Outgoing zone. + uses - Outgoing line to use: TYPE/Name + match (list) - Number to match + countrycode - The effective country code of this dialzone + international (list) - International prefix to match + localzone - dialzone for local numbers + addprefix - Prexix required to dial out. + localprefix - Prefix for a local call + +]] + + +-- +-- SIP dialzone configuration +-- +if arg[1] then + cbimap = Map("asterisk", "Edit Dialplan Entry") + + entry = cbimap:section(NamedSection, arg[1]) + + back = entry:option(DummyValue, "_overview", "Back to dialplan overview") + back.value = "" + back.titleref = luci.dispatcher.build_url("admin", "asterisk", "dialplans") + + desc = entry:option(Value, "description", "Description") + function desc.cfgvalue(self, s, ...) + return Value.cfgvalue(self, s, ...) or s + end + + match = entry:option(DynamicList, "match", "Number matches") + + intl = entry:option(DynamicList, "international", "Intl. prefix matches (optional)") + + trunk = entry:option(ListValue, "uses", "Used trunk") + for _, v in ipairs(find_trunks(cbimap.uci)) do + trunk:value(unpack(v)) + end + + aprefix = entry:option(Value, "addprefix", "Add prefix to dial out (optional)") + ccode = entry:option(Value, "countrycode", "Effective countrycode (optional)") + + lzone = entry:option(ListValue, "localzone", "Dialzone for local numbers") + lzone:value("", "no special treatment of local numbers") + for _, v in ipairs(find_outgoing_contexts(cbimap.uci)) do + lzone:value(unpack(v)) + end + + lprefix = entry:option(Value, "localprefix", "Prefix for local calls (optional)") + + return cbimap +end diff --git a/applications/luci-asterisk/luasrc/model/cbi/asterisk/dialplans.lua b/applications/luci-asterisk/luasrc/model/cbi/asterisk/dialplans.lua new file mode 100644 index 0000000000..3a993da456 --- /dev/null +++ b/applications/luci-asterisk/luasrc/model/cbi/asterisk/dialplans.lua @@ -0,0 +1,115 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ + +]]-- + +local ast = require("luci.asterisk") + +cbimap = Map("asterisk", "Registered Trunks") +cbimap.pageaction = false + +local sip_peers = { } +cbimap.uci:foreach("asterisk", "sip", + function(s) + if s.type == "peer" then + s.name = s['.name'] + s.info = ast.sip.peer(s.name) + sip_peers[s.name] = s + end + end) + + +sip_table = cbimap:section(TypedSection, "sip", "SIP Trunks") +sip_table.template = "cbi/tblsection" +sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s") +sip_table.addremove = true +sip_table.sectionhead = "Extension" + +function sip_table.filter(self, s) + return s and ( + cbimap.uci:get("asterisk", s, "type") == nil or + cbimap.uci:get_bool("asterisk", s, "provider") + ) +end + +function sip_table.create(self, section) + if TypedSection.create(self, section) then + created = section + else + self.invalid_cts = true + end +end + +function sip_table.parse(self, ...) + TypedSection.parse(self, ...) + if created then + cbimap.uci:tset("asterisk", created, { + type = "friend", + qualify = "yes", + provider = "yes" + }) + + cbimap.uci:save("asterisk") + luci.http.redirect(luci.dispatcher.build_url( + "admin", "asterisk", "trunks", "sip", created + )) + end +end + + +user = sip_table:option(DummyValue, "username", "Username") + +host = sip_table:option(DummyValue, "host", "Hostname") +function host.cfgvalue(self, s) + if sip_peers[s] and sip_peers[s].info.address then + return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port } + else + return "n/a" + end +end + +context = sip_table:option(DummyValue, "context", "Dialplan") +context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan") +function context.cfgvalue(...) + return AbstractValue.cfgvalue(...) or "(default)" +end + +online = sip_table:option(DummyValue, "online", "Registered") +function online.cfgvalue(self, s) + if sip_peers[s] and sip_peers[s].info.online == nil then + return "n/a" + else + return sip_peers[s] and sip_peers[s].info.online + and "yes" or "no (%s)" %{ + sip_peers[s] and sip_peers[s].info.Status:lower() or "unknown" + } + end +end + +delay = sip_table:option(DummyValue, "delay", "Delay") +function delay.cfgvalue(self, s) + if sip_peers[s] and sip_peers[s].info.online then + return "%i ms" % sip_peers[s].info.delay + else + return "n/a" + end +end + +info = sip_table:option(Button, "_info", "Info") +function info.write(self, s) + luci.http.redirect(luci.dispatcher.build_url( + "admin", "asterisk", "trunks", "sip", s, "info" + )) +end + +return cbimap diff --git a/applications/luci-asterisk/luasrc/model/cbi/asterisk/phone_sip.lua b/applications/luci-asterisk/luasrc/model/cbi/asterisk/phone_sip.lua index 29286c1f7b..10afe3bef9 100644 --- a/applications/luci-asterisk/luasrc/model/cbi/asterisk/phone_sip.lua +++ b/applications/luci-asterisk/luasrc/model/cbi/asterisk/phone_sip.lua @@ -15,6 +15,47 @@ $Id$ local ast = require("luci.asterisk") +local function find_outgoing_contexts(uci) + local c = { } + local h = { } + + uci:foreach("asterisk", "dialplan", + function(s) + if not h[s['.name']] then + c[#c+1] = { s['.name'], "Dialplan: %s" % s['.name'] } + h[s['.name']] = true + end + end) + + uci:foreach("asterisk", "dialzone", + function(s) + if not h[s['.name']] then + c[#c+1] = { s['.name'], "Dialzone: %s" % s['.name'] } + h[s['.name']] = true + end + end) + + return c +end + +local function find_incoming_contexts(uci) + local c = { } + local h = { } + + uci:foreach("asterisk", "sip", + function(s) + if s.context and not h[s.context] and + uci:get_bool("asterisk", s['.name'], "provider") + then + c[#c+1] = { s.context, "Incoming: %s" % s['.name'] or s.context } + h[s.context] = true + end + end) + + return c +end + + -- -- SIP phone info -- @@ -68,6 +109,13 @@ elseif arg[1] then back.value = "" back.titleref = luci.dispatcher.build_url("admin", "asterisk", "phones") + active = peer:option(Flag, "disable", "Account enabled") + active.enabled = "yes" + active.disabled = "no" + function active.cfgvalue(...) + return AbstractValue.cfgvalue(...) or "yes" + end + exten = peer:option(Value, "extension", "Extension Number") cbimap.uci:foreach("asterisk", "dialplanexten", function(s) @@ -83,13 +131,6 @@ elseif arg[1] then password = peer:option(Value, "secret", "Authorization Password") password.password = true - active = peer:option(Flag, "disable", "Active") - active.enabled = "yes" - active.disabled = "no" - function active.cfgvalue(...) - return AbstractValue.cfgvalue(...) or "yes" - end - regtimeout = peer:option(Value, "registertimeout", "Registration Time Value") function regtimeout.cfgvalue(...) return AbstractValue.cfgvalue(...) or "60" @@ -106,8 +147,18 @@ elseif arg[1] then linekey:value("call", "Call Appearance") dialplan = peer:option(ListValue, "context", "Dialplan Context") - cbimap.uci:foreach("asterisk", "dialplan", - function(s) dialplan:value(s['.name']) end) + for _, v in ipairs(find_outgoing_contexts(cbimap.uci)) do + dialplan:value(unpack(v)) + end + + incoming = peer:option(StaticList, "incoming", "Receive incoming calls from") + for _, v in ipairs(find_incoming_contexts(cbimap.uci)) do + incoming:value(unpack(v)) + end + + --function incoming.cfgvalue(...) + --error(table.concat(MultiValue.cfgvalue(...),".")) + --end return cbimap end diff --git a/applications/luci-asterisk/luasrc/model/cbi/asterisk/phones.lua b/applications/luci-asterisk/luasrc/model/cbi/asterisk/phones.lua index 7831824905..7c8f03f000 100644 --- a/applications/luci-asterisk/luasrc/model/cbi/asterisk/phones.lua +++ b/applications/luci-asterisk/luasrc/model/cbi/asterisk/phones.lua @@ -34,21 +34,23 @@ sip_table.template = "cbi/tblsection" sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "phones", "sip", "%s") sip_table.addremove = true -sip_table.hidden = { - type = "friend", - qualify = "yes", - host = "dynamic", - nat = "no", - canreinvite = "no" -} - function sip_table.filter(self, s) - return s and cbimap.uci:get("asterisk", s, "type") ~= "peer" + return s and not cbimap.uci:get_bool("asterisk", s, "provider") end function sip_table.create(self, section) if TypedSection.create(self, section) then created = section + cbimap.uci:tset("asterisk", section, { + type = "friend", + qualify = "yes", + provider = "no", + host = "dynamic", + nat = "no", + canreinvite = "no", + extension = section:match("^%d+$") and section or "", + username = section:match("^%d+$") and section or "" + }) else self.invalid_cts = true end @@ -65,13 +67,13 @@ function sip_table.parse(self, ...) end -user = sip_table:option(DummyValue, "username") +user = sip_table:option(DummyValue, "username", "Username") function user.cfgvalue(self, s) return sip_peers[s] and sip_peers[s].callerid or AbstractValue.cfgvalue(self, s) end -host = sip_table:option(DummyValue, "host") +host = sip_table:option(DummyValue, "host", "Hostname") function host.cfgvalue(self, s) if sip_peers[s] and sip_peers[s].info.address then return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port } @@ -80,15 +82,10 @@ function host.cfgvalue(self, s) end end -context = sip_table:option(DummyValue, "context") +context = sip_table:option(DummyValue, "context", "Dialplan") context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan") -nat = sip_table:option(DummyValue, "nat") -function nat.cfgvalue(self, s) - return sip_peers[s] and sip_peers[s].info.Nat or "none" -end - -online = sip_table:option(DummyValue, "online") +online = sip_table:option(DummyValue, "online", "Registered") function online.cfgvalue(self, s) if sip_peers[s] and sip_peers[s].info.online == nil then return "n/a" @@ -100,7 +97,7 @@ function online.cfgvalue(self, s) end end -delay = sip_table:option(DummyValue, "delay") +delay = sip_table:option(DummyValue, "delay", "Delay") function delay.cfgvalue(self, s) if sip_peers[s] and sip_peers[s].info.online then return "%i ms" % sip_peers[s].info.delay diff --git a/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunk_sip.lua b/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunk_sip.lua index 900ff516a4..e2e73eefbe 100644 --- a/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunk_sip.lua +++ b/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunk_sip.lua @@ -67,11 +67,9 @@ elseif arg[1] then sipdomain = peer:option(Value, "host", "SIP Domain") sipport = peer:option(Value, "port", "SIP Port") - sipport.default = 5060 - - sipnat = peer:option(Flag, "nat", "NAT between this device and provider") - sipnat.enabled = "yes" - sipnat.disabled = "no" + function sipport.cfgvalue(...) + return AbstractValue.cfgvalue(...) or "5060" + end username = peer:option(Value, "username", "Authorization ID") password = peer:option(Value, "secret", "Authorization Password") @@ -85,14 +83,14 @@ elseif arg[1] then register.disabled = "no" regext = peer:option(Value, "registerextension", "Extension to register (optional)") - regext:depends({register="yes"}) + regext:depends({register="1"}) didval = peer:option(ListValue, "_did", "Number of assigned DID numbers") didval:value("", "(none)") for i=1,24 do didval:value(i) end dialplan = peer:option(ListValue, "context", "Dialplan Context") - dialplan:value("", "(default)") + dialplan:value(arg[1] .. "_inbound", "(default)") cbimap.uci:foreach("asterisk", "dialplan", function(s) dialplan:value(s['.name']) end) diff --git a/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunks.lua b/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunks.lua index 02576b5593..3a993da456 100644 --- a/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunks.lua +++ b/applications/luci-asterisk/luasrc/model/cbi/asterisk/trunks.lua @@ -30,19 +30,15 @@ cbimap.uci:foreach("asterisk", "sip", sip_table = cbimap:section(TypedSection, "sip", "SIP Trunks") -sip_table.template = "cbi/tblsection" -sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s") -sip_table.addremove = true - -sip_table.hidden = { - type = "peer", - qualify = "yes" -} +sip_table.template = "cbi/tblsection" +sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s") +sip_table.addremove = true +sip_table.sectionhead = "Extension" function sip_table.filter(self, s) return s and ( - cbimap.uci:get("asterisk", s, "type") == "peer" or - cbimap.uci:get("asterisk", s, "type") == nil + cbimap.uci:get("asterisk", s, "type") == nil or + cbimap.uci:get_bool("asterisk", s, "provider") ) end @@ -57,6 +53,12 @@ end function sip_table.parse(self, ...) TypedSection.parse(self, ...) if created then + cbimap.uci:tset("asterisk", created, { + type = "friend", + qualify = "yes", + provider = "yes" + }) + cbimap.uci:save("asterisk") luci.http.redirect(luci.dispatcher.build_url( "admin", "asterisk", "trunks", "sip", created @@ -65,9 +67,9 @@ function sip_table.parse(self, ...) end -user = sip_table:option(DummyValue, "username") +user = sip_table:option(DummyValue, "username", "Username") -host = sip_table:option(DummyValue, "host") +host = sip_table:option(DummyValue, "host", "Hostname") function host.cfgvalue(self, s) if sip_peers[s] and sip_peers[s].info.address then return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port } @@ -76,18 +78,13 @@ function host.cfgvalue(self, s) end end -context = sip_table:option(DummyValue, "context") +context = sip_table:option(DummyValue, "context", "Dialplan") context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan") function context.cfgvalue(...) return AbstractValue.cfgvalue(...) or "(default)" end -nat = sip_table:option(DummyValue, "nat") -function nat.cfgvalue(self, s) - return sip_peers[s] and sip_peers[s].info.Nat or "none" -end - -online = sip_table:option(DummyValue, "online") +online = sip_table:option(DummyValue, "online", "Registered") function online.cfgvalue(self, s) if sip_peers[s] and sip_peers[s].info.online == nil then return "n/a" @@ -99,7 +96,7 @@ function online.cfgvalue(self, s) end end -delay = sip_table:option(DummyValue, "delay") +delay = sip_table:option(DummyValue, "delay", "Delay") function delay.cfgvalue(self, s) if sip_peers[s] and sip_peers[s].info.online then return "%i ms" % sip_peers[s].info.delay |