summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-asterisk/luasrc/asterisk.lua
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2009-03-21 04:36:08 +0000
committerJo-Philipp Wich <jow@openwrt.org>2009-03-21 04:36:08 +0000
commit1a3d44865f6cbda203b84340684aa539599bb876 (patch)
tree5ce1a7ef3e121a03c4361cc490f3928b7a99dc90 /applications/luci-asterisk/luasrc/asterisk.lua
parent684f695c13d6e415b834b5dbd4d2923cc63468b4 (diff)
applications/luci-asterisk: rework dialplan management
Diffstat (limited to 'applications/luci-asterisk/luasrc/asterisk.lua')
-rw-r--r--applications/luci-asterisk/luasrc/asterisk.lua59
1 files changed, 59 insertions, 0 deletions
diff --git a/applications/luci-asterisk/luasrc/asterisk.lua b/applications/luci-asterisk/luasrc/asterisk.lua
index 908986366..2967b42c0 100644
--- a/applications/luci-asterisk/luasrc/asterisk.lua
+++ b/applications/luci-asterisk/luasrc/asterisk.lua
@@ -25,6 +25,11 @@ AST_BIN = "/usr/sbin/asterisk"
AST_FLAGS = "-r -x"
+--- LuCI Asterisk - Resync uci context
+function uci_resync()
+ uci = luci.model.uci.cursor()
+end
+
--- LuCI Asterisk io interface
-- Handles low level io.
-- @type module
@@ -318,3 +323,57 @@ function dialzone.ucisection(i)
end)
return hash
end
+
+
+--- LuCI Asterisk - Dialplan
+-- @type module
+dialplan = luci.util.class()
+
+--- Parse a dialplan section
+-- @param plan Table containing the plan info
+-- @return Table with parsed information
+function dialplan.parse(z)
+ if z['.name'] then
+ local plan = {
+ zones = { },
+ name = z['.name'],
+ description = z.description or z['.name']
+ }
+
+ for _, name in ipairs(tools.parse_list(z.include)) do
+ local zone = dialzone.zone(name)
+ if zone then
+ plan.zones[#plan.zones+1] = zone
+ end
+ end
+
+ return plan
+ end
+end
+
+--- Get a list of known dial plans
+-- @return Associative table of plans and table of plan names
+function dialplan.plans()
+ local plans = { }
+ local pnames = { }
+ uci:foreach("asterisk", "dialplan",
+ function(p)
+ plans[p['.name']] = dialplan.parse(p)
+ pnames[#pnames+1] = p['.name']
+ end)
+ return plans, pnames
+end
+
+--- Get a specific dial plan
+-- @param name Name of the dial plan
+-- @return Table containing plan information
+function dialplan.plan(n)
+ local plan
+ uci:foreach("asterisk", "dialplan",
+ function(p)
+ if p['.name'] == n then
+ plan = dialplan.parse(p)
+ end
+ end)
+ return plan
+end