X-Git-Url: http://git.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=applications%2Fluci-asterisk%2Fluasrc%2Fasterisk.lua;fp=applications%2Fluci-asterisk%2Fluasrc%2Fasterisk.lua;h=15081cc9a4a7f469f1f74ca66de91f09eb0b3507;hp=23193e72063479504d716d32639e094b740b0298;hb=d0c6e88b95782d8c50cd8c6caec1302bb9ab1a9d;hpb=7385d0b070e2aa4a367b8864fcaad00e65fabb18 diff --git a/applications/luci-asterisk/luasrc/asterisk.lua b/applications/luci-asterisk/luasrc/asterisk.lua index 23193e7206..15081cc9a4 100644 --- a/applications/luci-asterisk/luasrc/asterisk.lua +++ b/applications/luci-asterisk/luasrc/asterisk.lua @@ -598,11 +598,102 @@ end --- Remove voicemailbox and associated extensions from config -- @param box Voicemailbox number or table +-- @param ctx UCI context to use (optional) -- @return Boolean indicating success -function voicemail.remove(v) +function voicemail.remove(v, ctx) + ctx = ctx or uci local box = type(v) == "string" and v or v.number - local ok1 = uci:delete_all("asterisk", "voicemail", {number=box}) - local ok2 = uci:delete_all("asterisk", "dialplanvoice", {voicebox=box}) + local ok1 = ctx:delete_all("asterisk", "voicemail", {number=box}) + local ok2 = ctx:delete_all("asterisk", "dialplanvoice", {voicebox=box}) + return ( ok1 or ok2 ) and true or false +end + + +--- LuCI Asterisk - MeetMe Conferences +-- @type module +meetme = luci.util.class() + +--- Parse a meetme section +-- @param room Table containing the room info +-- @return Table with parsed information +function meetme.parse(r) + if r.room and #r.room > 0 then + local v = { + room = r.room, + pin = r.pin or '', + adminpin = r.adminpin or '', + description = r._description or '', + dialplans = { } + } + + uci:foreach("asterisk", "dialplanmeetme", + function(s) + if s.dialplan and #s.dialplan > 0 and s.room == v.room then + v.dialplans[#v.dialplans+1] = s.dialplan + end + end) + + return v + end +end + +--- Get a list of known meetme rooms +-- @return Associative table of rooms and table of room numbers +function meetme.rooms() + local mrooms = { } + local mnames = { } + uci:foreach("asterisk", "meetme", + function(r) + local v = meetme.parse(r) + if v then + mrooms[v.room] = v + mnames[#mnames+1] = v.room + end + end) + return mrooms, mnames +end + +--- Get a specific meetme room +-- @param number Number of the room +-- @return Table containing room information +function meetme.room(n) + local room + uci:foreach("asterisk", "meetme", + function(r) + if r.room == tostring(n) then + room = meetme.parse(r) + end + end) + return room +end + +--- Find all meetme rooms within the given dialplan +-- @param plan Dialplan name or table +-- @return Associative table containing extensions mapped to room info +function meetme.in_dialplan(p) + local plan = type(p) == "string" and p or p.name + local rooms = { } + uci:foreach("asterisk", "dialplanmeetme", + function(s) + if s.extension and #s.extension > 0 and s.dialplan == plan then + local room = meetme.room(s.room) + if room then + rooms[s.extension] = room + end + end + end) + return rooms +end + +--- Remove meetme room and associated extensions from config +-- @param room Voicemailbox number or table +-- @param ctx UCI context to use (optional) +-- @return Boolean indicating success +function meetme.remove(v, ctx) + ctx = ctx or uci + local room = type(v) == "string" and v or v.number + local ok1 = ctx:delete_all("asterisk", "meetme", {room=room}) + local ok2 = ctx:delete_all("asterisk", "dialplanmeetme", {room=room}) return ( ok1 or ok2 ) and true or false end @@ -633,6 +724,9 @@ function dialplan.parse(z) -- voicemailboxes plan.voicemailboxes = voicemail.in_dialplan(plan) + -- meetme conferences + plan.meetmerooms = meetme.in_dialplan(plan) + return plan end end