From: Jo-Philipp Wich Date: Mon, 30 Mar 2009 19:29:37 +0000 (+0000) Subject: applications/luci-asterisk: add meetme support, data integrity improvements X-Git-Tag: 0.9.0~542 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d0c6e88b95782d8c50cd8c6caec1302bb9ab1a9d;p=oweals%2Fluci.git applications/luci-asterisk: add meetme support, data integrity improvements --- diff --git a/applications/luci-asterisk/luasrc/asterisk.lua b/applications/luci-asterisk/luasrc/asterisk.lua index 23193e720..15081cc9a 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 diff --git a/applications/luci-asterisk/luasrc/controller/asterisk.lua b/applications/luci-asterisk/luasrc/controller/asterisk.lua index c258f2db3..ab053397d 100644 --- a/applications/luci-asterisk/luasrc/controller/asterisk.lua +++ b/applications/luci-asterisk/luasrc/controller/asterisk.lua @@ -53,7 +53,11 @@ function index() entry({"admin", "asterisk", "voicemail", "mailboxes"}, cbi("asterisk/voicemail"), "Mailboxes", 1) entry({"admin", "asterisk", "voicemail", "settings"}, cbi("asterisk/voicemail_settings"), "Settings", 2) - entry({"admin", "asterisk", "dialplans"}, call("handle_dialplan"), "Call Routing", 4) + entry({"admin", "asterisk", "meetme"}, cbi("asterisk/meetme"), "MeetMe", 4) + entry({"admin", "asterisk", "meetme", "rooms"}, cbi("asterisk/meetme"), "Rooms", 1) + entry({"admin", "asterisk", "meetme", "settings"}, cbi("asterisk/meetme_settings"), "Settings", 2) + + entry({"admin", "asterisk", "dialplans"}, call("handle_dialplan"), "Call Routing", 5) entry({"admin", "asterisk", "dialplans", "out"}, cbi("asterisk/dialplan_out"), nil, 1).leaf = true entry({"admin", "asterisk", "dialplans", "zones"}, call("handle_dialzones"), "Dial Zones", 2).leaf = true @@ -125,6 +129,28 @@ function handle_dialplan() end end + for k, v in pairs(luci.http.formvaluetable("delmeetme")) do + local plan = ast.dialplan.plan(k) + if #v > 0 and plan then + uci:delete_all("asterisk", "dialplanmeetme", + { extension=v, dialplan=plan.name }) + end + end + + for k, v in pairs(luci.http.formvaluetable("addmeetme")) do + local plan = ast.dialplan.plan(k) + local meetme = ast.meetme.room(v) + if plan and meetme then + local mext = luci.http.formvalue("addmeetmeext.%s" % plan.name) + mext = ( mext and #mext > 0 ) and mext or meetme.room + uci:section("asterisk", "dialplanmeetme", nil, { + dialplan = plan.name, + extension = mext, + room = meetme.room + }) + end + end + local aname = luci.http.formvalue("addplan") if aname and #aname > 0 then if aname:match("^[a-zA-Z0-9_]+$") then diff --git a/applications/luci-asterisk/luasrc/model/cbi/asterisk/meetme.lua b/applications/luci-asterisk/luasrc/model/cbi/asterisk/meetme.lua new file mode 100644 index 000000000..b02a8f612 --- /dev/null +++ b/applications/luci-asterisk/luasrc/model/cbi/asterisk/meetme.lua @@ -0,0 +1,49 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2009 Jo-Philipp Wich + +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", "MeetMe - Rooms") + +meetme = cbimap:section(TypedSection, "meetme", "MeetMe Rooms") +meetme.addremove = true +meetme.anonymous = true +meetme.template = "cbi/tblsection" +meetme:option(Value, "_description", "Description", "Short room description") + +room = meetme:option(Value, "room", "Room Number", "Unique room identifier") + +function room.write(self, s, val) + if val and #val > 0 then + local old = self:cfgvalue(s) + self.map.uci:foreach("asterisk", "dialplanmeetme", + function(v) + if v.room == old then + self.map:set(v['.name'], "room", val) + end + end) + Value.write(self, s, val) + end +end + + +meetme:option(Value, "pin", "PIN", "PIN required to access") +meetme:option(Value, "adminpin", "Admin PIN", "PIN required for administration") + +function meetme.remove(self, s) + return ast.meetme.remove(self.map:get(s, "room"), self.map.uci) +end + + +return cbimap diff --git a/applications/luci-asterisk/luasrc/model/cbi/asterisk/meetme_settings.lua b/applications/luci-asterisk/luasrc/model/cbi/asterisk/meetme_settings.lua new file mode 100644 index 000000000..511d7a71a --- /dev/null +++ b/applications/luci-asterisk/luasrc/model/cbi/asterisk/meetme_settings.lua @@ -0,0 +1,28 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2009 Jo-Philipp Wich + +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$ +]]-- + +cbimap = Map("asterisk", "MeetMe - Common Settings", + "Common settings for MeetMe phone conferences.") + +meetme = cbimap:section(TypedSection, "meetmegeneral", "General MeetMe Options") +meetme.addremove = false +meetme.anonymous = true + +audiobuffers = meetme:option(ListValue, "audiobuffers", + "Number of 20ms audio buffers to use for conferences") + +for i = 2, 32 do audiobuffers:value(i) end + + +return cbimap diff --git a/applications/luci-asterisk/luasrc/model/cbi/asterisk/voicemail.lua b/applications/luci-asterisk/luasrc/model/cbi/asterisk/voicemail.lua index 1c92d0dbf..5d0de756b 100644 --- a/applications/luci-asterisk/luasrc/model/cbi/asterisk/voicemail.lua +++ b/applications/luci-asterisk/luasrc/model/cbi/asterisk/voicemail.lua @@ -12,6 +12,8 @@ You may obtain a copy of the License at $Id$ ]]-- +local ast = require "luci.asterisk" + cbimap = Map("asterisk", "Voicemail - Mailboxes") voicemail = cbimap:section(TypedSection, "voicemail", "Voicemail Boxes") @@ -22,7 +24,23 @@ voicemail.template = "cbi/tblsection" context = voicemail:option(ListValue, "context", "Context") context:value("default") -voicemail:option(Value, "number", "Mailbox Number", "Unique mailbox identifier") +number = voicemail:option(Value, "number", + "Mailbox Number", "Unique mailbox identifier") + +function number.write(self, s, val) + if val and #val > 0 then + local old = self:cfgvalue(s) + self.map.uci:foreach("asterisk", "dialplanvoice", + function(v) + if v.voicebox == old then + self.map:set(v['.name'], "voicebox", val) + end + end) + Value.write(self, s, val) + end +end + + voicemail:option(Value, "name", "Ownername", "Human readable display name") voicemail:option(Value, "password", "Password", "Access protection") voicemail:option(Value, "email", "eMail", "Where to send voice messages") @@ -33,5 +51,9 @@ zone.titleref = luci.dispatcher.build_url("admin/asterisk/voicemail/settings") cbimap.uci:foreach("asterisk", "voicezone", function(s) zone:value(s['.name']) end) +function voicemail.remove(self, s) + return ast.voicemail.remove(self.map:get(s, "number"), self.map.uci) +end + return cbimap diff --git a/applications/luci-asterisk/luasrc/view/asterisk/dialplans.htm b/applications/luci-asterisk/luasrc/view/asterisk/dialplans.htm index 79b81bd9d..a36016241 100644 --- a/applications/luci-asterisk/luasrc/view/asterisk/dialplans.htm +++ b/applications/luci-asterisk/luasrc/view/asterisk/dialplans.htm @@ -78,7 +78,8 @@ $Id$ Here you can manage your dial plans which are used to route outgoing calls from your local extensions.

Related tasks:
Manage dialzones | - Manage voicemail boxes + Manage voicemail boxes | + Manage meetme rooms
@@ -117,10 +118,10 @@ $Id$

- + Edit dialzone - + Remove from this dialplan @@ -142,10 +143,10 @@ $Id$

- + Edit dialzone - + Remove from this dialplan @@ -153,6 +154,28 @@ $Id$ <% row = row + 1; end %> + + <% local rooms_used = { } %> + <% for ext, room in luci.util.kspairs(plan.meetmerooms) do rooms_used[room.room] = true %> + + + └ MeetMe Room <%=room.room%> (<%=room.description%>) +

+ Matches: <%=format_matches(ext)%> +

+ + + + Edit dialzone + + + Remove from this dialplan + + + + <% row = row + 1; end %> + +
@@ -181,6 +204,19 @@ $Id$

+ Add MeetMe Conference:
+ + as extension + +

+