summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-asterisk/luasrc/controller/asterisk.lua
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/luasrc/controller/asterisk.lua
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/luasrc/controller/asterisk.lua')
-rw-r--r--applications/luci-asterisk/luasrc/controller/asterisk.lua73
1 files changed, 67 insertions, 6 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