summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-asterisk
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2009-02-24 01:09:51 +0000
committerJo-Philipp Wich <jow@openwrt.org>2009-02-24 01:09:51 +0000
commitcebe6f031bc475e8e21102c4b5e378e1fa7bcf54 (patch)
treedb68b297c46e0dd85279486eb1a24b4096429aae /applications/luci-asterisk
parent1eec55dd47a6a54c18f6de655279ad75c1d3a01b (diff)
applications/luci-asterisk:
- initial dialplan management - disabled uci scheme - improved context handling in sip and trunk settings
Diffstat (limited to 'applications/luci-asterisk')
-rw-r--r--applications/luci-asterisk/luasrc/controller/asterisk.lua73
-rw-r--r--applications/luci-asterisk/luasrc/model/cbi/asterisk/dialplan_out.lua134
-rw-r--r--applications/luci-asterisk/luasrc/model/cbi/asterisk/dialplans.lua115
-rw-r--r--applications/luci-asterisk/luasrc/model/cbi/asterisk/phone_sip.lua69
-rw-r--r--applications/luci-asterisk/luasrc/model/cbi/asterisk/phones.lua35
-rw-r--r--applications/luci-asterisk/luasrc/model/cbi/asterisk/trunk_sip.lua12
-rw-r--r--applications/luci-asterisk/luasrc/model/cbi/asterisk/trunks.lua37
-rw-r--r--applications/luci-asterisk/luasrc/view/asterisk/dialplans.htm171
-rw-r--r--applications/luci-asterisk/root/lib/uci/schema/default/asterisk.hide (renamed from applications/luci-asterisk/root/lib/uci/schema/default/asterisk)0
9 files changed, 585 insertions, 61 deletions
diff --git a/applications/luci-asterisk/luasrc/controller/asterisk.lua b/applications/luci-asterisk/luasrc/controller/asterisk.lua
index bf0b36bef..05d534317 100644
--- a/applications/luci-asterisk/luasrc/controller/asterisk.lua
+++ b/applications/luci-asterisk/luasrc/controller/asterisk.lua
@@ -40,14 +40,75 @@ function index()
cbi("asterisk-mod-res-feature"), "Feature Module Configuration", 9 )
- entry({"admin", "asterisk"}, cbi("asterisk/main"), "Asterisk", 99).i18n = "asterisk"
+ entry({"admin", "asterisk"}, cbi("asterisk/main"), "Asterisk", 99).i18n = "asterisk"
- entry({"admin", "asterisk", "phones"}, cbi("asterisk/phones"), "Phones", 1)
- entry({"admin", "asterisk", "phones", "sip"}, cbi("asterisk/phone_sip"), nil, 1).leaf = true
- entry({"admin", "asterisk", "phones", "exten"}, cbi("asterisk/phone_exten"), "Extensions", 2).leaf = true
+ entry({"admin", "asterisk", "phones"}, cbi("asterisk/phones"), "Phones", 1)
+ entry({"admin", "asterisk", "phones", "sip"}, cbi("asterisk/phone_sip"), nil, 1).leaf = true
+ --entry({"admin", "asterisk", "phones", "exten"}, cbi("asterisk/phone_exten"), "Extensions", 2).leaf = true
- entry({"admin", "asterisk", "trunks"}, cbi("asterisk/trunks"), "Trunks", 2)
- entry({"admin", "asterisk", "trunks", "sip"}, cbi("asterisk/trunk_sip"), nil, 1).leaf = true
+ entry({"admin", "asterisk", "trunks"}, cbi("asterisk/trunks"), "Trunks", 2)
+ entry({"admin", "asterisk", "trunks", "sip"}, cbi("asterisk/trunk_sip"), nil, 1).leaf = true
+ --entry({"admin", "asterisk", "dialplans"}, cbi("asterisk/dialplans"), "Call Routing", 3)
+ entry({"admin", "asterisk", "dialplans"}, call("handle_dialplan"), "Call Routing", 3)
+ entry({"admin", "asterisk", "dialplans", "out"}, cbi("asterisk/dialplan_out"), nil, 1).leaf = true
end
+
+
+function handle_dialplan()
+ local uci = luci.model.uci.cursor()
+
+ if luci.http.formvalue("delete") then
+ local del = luci.http.formvalue("delete")
+ if #del > 0 and not del:match("[^a-zA-Z0-9_]") then
+ uci:delete("asterisk", del)
+ uci:foreach("asterisk", "dialplan",
+ function(s)
+ if s.include then
+ local inc = type(s.include) == "table" and s.include or
+ luci.util.split(s.include, "%s+", nil, true)
+
+ local inc2 = { }
+ for _, v in ipairs(inc) do
+ if v ~= del then
+ inc2[#inc2+1] = v
+ end
+ end
+
+ uci:set("asterisk", s['.name'], "include", inc2)
+ end
+ end)
+
+ uci:save("asterisk")
+ uci:commit("asterisk")
+ end
+ end
+
+ for k, v in pairs(luci.http.formvaluetable("create_entry")) do
+ if #v > 0 and not v:match("[^a-zA-Z0-9_]") then
+ uci:section("asterisk", "dialzone", v, {
+ context = k
+ } )
+
+ local inc = uci:get("asterisk", k, "include")
+ inc = type(inc) == "table" and inc or
+ type(inc) == "string" and #inc > 0 and
+ luci.util.split(inc, "%s+", nil, true) or { }
+
+ inc[#inc+1] = v
+
+ uci:set("asterisk", k, "include", inc)
+ uci:save("asterisk")
+ uci:commit("asterisk")
+
+ luci.http.redirect(luci.dispatcher.build_url(
+ "asterisk", "dialplans", "out", v
+ ))
+
+ return
+ end
+ end
+
+ luci.template.render("asterisk/dialplans")
+end
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 000000000..c8538426c
--- /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 000000000..3a993da45
--- /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 29286c1f7..10afe3bef 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 783182490..7c8f03f00 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 900ff516a..e2e73eefb 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 02576b559..3a993da45 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
diff --git a/applications/luci-asterisk/luasrc/view/asterisk/dialplans.htm b/applications/luci-asterisk/luasrc/view/asterisk/dialplans.htm
new file mode 100644
index 000000000..7432cebf3
--- /dev/null
+++ b/applications/luci-asterisk/luasrc/view/asterisk/dialplans.htm
@@ -0,0 +1,171 @@
+<%#
+LuCI - Lua Configuration Interface
+Copyright 2008 Steven Barth <steven@midlink.org>
+Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+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$
+
+-%>
+
+<%+header%>
+
+<%
+ local uci = luci.model.uci.cursor_state()
+
+ function find_rules(plan)
+ local r = { }
+ if plan and plan.include then
+ local i = luci.util.split(plan.include, "%s+", nil, true)
+ for _, i in ipairs(i) do
+ i = uci:get("asterisk", "dialzone", i)
+ if i then
+ r[#r+1] = i
+ end
+ end
+ end
+ return r
+ end
+
+ dp_lookup_table = { }
+
+ function dialplan_lookup(s)
+ if not dp_lookup_table[s['.name']] then
+ s.childs = { }
+ s.matches = type(s.match) == "table" and s.match or { s.match }
+ s.name, s.type = s['.name'], s['.type']
+ s['.name'], s['.type'] = nil, nil
+ dp_lookup_table[s.name] = s
+ end
+ end
+
+ uci:foreach("asterisk", "dialplan", dialplan_lookup)
+ uci:foreach("asterisk", "dialzone", dialplan_lookup)
+
+ for k, p in pairs(dp_lookup_table) do
+ if p.include then
+ local i = type(p.include) == "string"
+ and luci.util.split(p.include, "%s+", nil, true) or p.include
+
+ for _, i in ipairs(i) do
+ i = dp_lookup_table[i]
+ if i then
+ p.childs[#p.childs+1] = i
+ i.parent = p
+ end
+ end
+ end
+ end
+
+ function digit_pattern(s)
+ return "<code style='padding: 2px; border:1px solid #CCCCCC; background-color: #FFFFFF'>%s</code>" % s
+ end
+
+ function rowstyle(i)
+ return "cbi-rowstyle-%i" %{
+ ( i % 2 ) == 0 and 2 or 1
+ }
+ end
+
+ function link_trunks(s)
+ local l = { }
+ for s in s:gmatch("(%S+)") do
+ if s:match("^[sS][iI][pP]/") then
+ l[#l+1] = '<a href="%s">%s</a>' %{
+ luci.dispatcher.build_url("admin", "asterisk", "trunks",
+ "sip", (s:gsub("^.+/",""))),
+ (s:gsub("^.+/","SIP: "))
+ }
+ end
+ end
+ return '<small>%s</small>' % table.concat(l, ", ")
+ end
+%>
+
+
+<form method="post" action="<%=luci.dispatcher.build_url("admin", "asterisk", "dialplans")%>" enctype="multipart/form-data">
+ <div>
+ <script type="text/javascript" src="/luci-static/resources/cbi.js"></script>
+ <input type="hidden" name="cbi.submit" value="1" />
+ <input type="submit" value="Save" class="hidden" />
+ </div>
+
+<div class="cbi-map" id="cbi-asterisk">
+ <h2><a id="content" name="content">Outgoing Call Routing</a></h2>
+ <div class="cbi-map-descr"></div><!-- tblsection -->
+<fieldset class="cbi-section" id="cbi-asterisk-sip">
+ <!--<legend>Dialplans</legend>-->
+ <div class="cbi-section-descr"></div>
+
+
+
+
+
+ <% for name, plan in luci.util.kspairs(dp_lookup_table) do
+ if plan.type == "dialplan" then %>
+ <div class="cbi-section-node">
+ <table class="cbi-section-table">
+ <tr class="cbi-section-table-titles">
+ <th style="text-align: left; padding: 3px" class="cbi-section-table-cell" colspan="5">
+ <big>&nbsp;Dialplan <em><%=name%></em></big>
+ </th>
+ </tr>
+
+ <tr class="cbi-section-table-descr">
+ <th style="width: 5%; text-align:right" class="cbi-section-table-cell">Prepend</th>
+ <th style="width: 20%; text-align:left" class="cbi-section-table-cell">- Match</th>
+ <th style="text-align:left" class="cbi-section-table-cell">Trunk</th>
+ <th style="width: 40%; text-align:left" class="cbi-section-table-cell">Description</th>
+ <th style="width: 4%; text-align:left" class="cbi-section-table-cell"></th>
+ </tr>
+
+ <% for i, rule in pairs(plan.childs) do
+ if rule.type == "dialzone" then %>
+ <tr class="cbi-section-table-row <%=rowstyle(i)%>">
+ <td style="text-align:right" class="cbi-value-field">
+ <% for _ in ipairs(rule.matches) do %>
+ <%=rule.addprefix and digit_pattern(rule.addprefix)%>&nbsp;<br />
+ <% end %>
+ </td>
+ <td style="text-align:left" class="cbi-value-field">
+ <% for _, m in ipairs(rule.matches) do %>
+ <%=rule.localprefix and "%s " % digit_pattern(rule.localprefix)%>
+ <%=digit_pattern(m)%><br />
+ <% end %>
+ </td>
+ <td style="text-align:left" class="cbi-value-field">
+ <%=rule.uses and link_trunks(rule.uses)%>
+ </td>
+ <td style="text-align:left" class="cbi-value-field">
+ <%=rule.description or rule.name%>
+ </td>
+ <td style="text-align:left" class="cbi-value-field">
+ <a href="<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans', 'out', rule.name)%>">
+ <img style="border:none" alt="Edit entry" title="Edit entry" src="/luci-static/resources/cbi/edit.gif" />
+ </a>
+ <a href="<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans')%>?delete=<%=rule.name%>">
+ <img style="border:none" alt="Delete entry" title="Delete entry" src="/luci-static/resources/cbi/remove.gif" />
+ </a>
+ </td>
+ </tr>
+ <% end end %>
+ </table>
+
+ <div class="cbi-section-create cbi-tblsection-create">
+ <input type="text" class="cbi-section-create-name" name="create_entry.<%=name%>"/>
+ <input type="submit" class="cbi-button cbi-button-add" value="Add entry" title="Add entry"/>
+ </div>
+ </div>
+ <br />
+ <% end end %>
+
+ </fieldset>
+</div>
+</form>
+<div class="clear"></div>
+<%+footer%>
diff --git a/applications/luci-asterisk/root/lib/uci/schema/default/asterisk b/applications/luci-asterisk/root/lib/uci/schema/default/asterisk.hide
index 85d9cb029..85d9cb029 100644
--- a/applications/luci-asterisk/root/lib/uci/schema/default/asterisk
+++ b/applications/luci-asterisk/root/lib/uci/schema/default/asterisk.hide