From 251e15fc292deed58d1d2b4fec2ce1172c2d8f75 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Mon, 18 Feb 2013 13:14:44 +0100 Subject: use /var/spool/freeswitch as spooldir for conferences --- misc/freeswitch/scripts/common/conference.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/common') diff --git a/misc/freeswitch/scripts/common/conference.lua b/misc/freeswitch/scripts/common/conference.lua index f6a4d87..7143f1c 100644 --- a/misc/freeswitch/scripts/common/conference.lua +++ b/misc/freeswitch/scripts/common/conference.lua @@ -191,7 +191,7 @@ function Conference.enter(self, caller, domain) -- Record caller's name if common.str.to_b(self.record.announce_new_member_by_name) or common.str.to_b(self.record.announce_left_member_by_name) then local uid = session:get_uuid(); - name_file = "/tmp/conference_caller_name_" .. uid .. ".wav"; + name_file = "/var/spool/freeswitch/conference_caller_name_" .. uid .. ".wav"; caller.session:sayPhrase('conference_record_name'); session:recordFile(name_file, ANNOUNCEMENT_MAX_LEN, ANNOUNCEMENT_SILENCE_THRESHOLD, ANNOUNCEMENT_SILENCE_LEN); caller.session:streamFile(name_file); -- cgit v1.2.3 From ec85421d570b64f3d3ddc6f638d9401b49621224 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 19 Feb 2013 14:59:21 +0100 Subject: phrase fixed --- misc/freeswitch/scripts/common/conference.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'misc/freeswitch/scripts/common') diff --git a/misc/freeswitch/scripts/common/conference.lua b/misc/freeswitch/scripts/common/conference.lua index 7143f1c..b56cba9 100644 --- a/misc/freeswitch/scripts/common/conference.lua +++ b/misc/freeswitch/scripts/common/conference.lua @@ -159,7 +159,7 @@ function Conference.enter(self, caller, domain) caller:sleep(1000); caller.session:sayPhrase('conference_welcome'); - if pin and pin ~= "" then + if not common.str.blank(pin) then local digits = ""; for i = 1, 3, 1 do if digits == pin then @@ -167,7 +167,7 @@ function Conference.enter(self, caller, domain) elseif digits ~= "" then caller.session:sayPhrase('conference_bad_pin'); end - digits = caller.session:read(PIN_LENGTH_MIN, PIN_LENGTH_MAX, 'conference/conf-enter_conf_pin.wav', PIN_TIMEOUT, '#'); + digits = caller.session:read(PIN_LENGTH_MIN, PIN_LENGTH_MAX, 'conference/conf-pin.wav', PIN_TIMEOUT, '#'); end if digits ~= pin then caller.session:sayPhrase('conference_goodbye'); -- cgit v1.2.3 From dfce431ca5c07aa53ce55eb0cdb5ecaff2cfc58a Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Sat, 23 Feb 2013 12:26:01 -0500 Subject: pickup groups added to dialplan --- misc/freeswitch/scripts/common/group.lua | 99 ++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 misc/freeswitch/scripts/common/group.lua (limited to 'misc/freeswitch/scripts/common') diff --git a/misc/freeswitch/scripts/common/group.lua b/misc/freeswitch/scripts/common/group.lua new file mode 100644 index 0000000..b89585a --- /dev/null +++ b/misc/freeswitch/scripts/common/group.lua @@ -0,0 +1,99 @@ +-- Gemeinschaft 5 module: group class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +Group = {} + +MAX_GROUP_MEMBERSHIPS = 256; + +-- create group object +function Group.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.class = 'group'; + self.log = arg.log; + self.database = arg.database; + return object; +end + +-- find group by id +function Group.find_by_id(self, id) + local sql_query = 'SELECT * FROM `groups` WHERE `id`= ' .. tonumber(id) .. ' LIMIT 1'; + local group = nil; + + self.database:query(sql_query, function(account_entry) + group = Group:new(self); + group.record = account_entry; + group.id = tonumber(account_entry.id); + group.name = account_entry.name; + end); + + return group; +end + +-- list groups by member permissions +function Group.name_id_by_member_permissions(self, member_id, member_type, permissions, targets) + if not tonumber(member_id) then + return {}; + end + + local sql_query = nil; + + if targets then + sql_query = 'SELECT DISTINCT `c`.`id`, `c`.`name` \ + FROM `group_permissions` `a` \ + JOIN `group_memberships` `b` ON `a`.`target_group_id` = `b`.`group_id` \ + JOIN `groups` `c` ON `c`.`id` = `b`.`group_id` \ + WHERE `b`.`item_type` = ' .. self.database:escape(member_type, '"') .. ' \ + AND `b`.`item_id` = ' .. member_id .. ' \ + AND `a`.`permission` IN ("' .. table.concat(permissions, ',') .. '") \ + GROUP BY `b`.`group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS; + else + sql_query = 'SELECT DISTINCT `c`.`id`, `c`.`name` \ + FROM `group_permissions` `a` \ + JOIN `group_memberships` `b` ON `a`.`group_id` = `b`.`group_id` \ + JOIN `groups` `c` ON `c`.`id` = `a`.`group_id` \ + WHERE `b`.`item_type` = ' .. self.database:escape(member_type, '"') .. ' \ + AND `b`.`item_id` = ' .. member_id .. ' \ + AND `a`.`permission` IN ("' .. table.concat(permissions, ',') .. '") \ + GROUP BY `b`.`group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS; + end + + local group_names = {}; + local group_ids = {}; + + self.database:query(sql_query, function(account_entry) + table.insert(group_names, account_entry.name); + table.insert(group_ids, tonumber(account_entry.id)); + end); + + return group_names, group_ids; +end + +-- list groups by member +function Group.name_id_by_member(self, member_id, member_type) + if not tonumber(member_id) then + return {}; + end + + local sql_query = 'SELECT DISTINCT `c`.`id`, `c`.`name` \ + FROM `group_memberships` `b` \ + JOIN `groups` `c` ON `c`.`id` = `b`.`group_id` \ + WHERE `b`.`item_type` = ' .. self.database:escape(member_type, '"') .. ' \ + AND `b`.`item_id` = ' .. member_id .. ' \ + GROUP BY `b`.`group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS; + + local group_names = {}; + local group_ids = {}; + + self.database:query(sql_query, function(account_entry) + table.insert(group_names, account_entry.name); + table.insert(group_ids, tonumber(account_entry.id)); + end); + + return group_names, group_ids; +end -- cgit v1.2.3 From 757fbb9de88c1b6d8ec1eff6519bd057c74892a5 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Sat, 23 Feb 2013 12:34:45 -0500 Subject: method streamlined --- misc/freeswitch/scripts/common/group.lua | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'misc/freeswitch/scripts/common') diff --git a/misc/freeswitch/scripts/common/group.lua b/misc/freeswitch/scripts/common/group.lua index b89585a..1a2d315 100644 --- a/misc/freeswitch/scripts/common/group.lua +++ b/misc/freeswitch/scripts/common/group.lua @@ -36,32 +36,19 @@ function Group.find_by_id(self, id) end -- list groups by member permissions -function Group.name_id_by_member_permissions(self, member_id, member_type, permissions, targets) +function Group.name_id_by_permission(self, member_id, member_type, permission) if not tonumber(member_id) then return {}; end - local sql_query = nil; - - if targets then - sql_query = 'SELECT DISTINCT `c`.`id`, `c`.`name` \ - FROM `group_permissions` `a` \ - JOIN `group_memberships` `b` ON `a`.`target_group_id` = `b`.`group_id` \ - JOIN `groups` `c` ON `c`.`id` = `b`.`group_id` \ - WHERE `b`.`item_type` = ' .. self.database:escape(member_type, '"') .. ' \ - AND `b`.`item_id` = ' .. member_id .. ' \ - AND `a`.`permission` IN ("' .. table.concat(permissions, ',') .. '") \ - GROUP BY `b`.`group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS; - else - sql_query = 'SELECT DISTINCT `c`.`id`, `c`.`name` \ - FROM `group_permissions` `a` \ - JOIN `group_memberships` `b` ON `a`.`group_id` = `b`.`group_id` \ - JOIN `groups` `c` ON `c`.`id` = `a`.`group_id` \ - WHERE `b`.`item_type` = ' .. self.database:escape(member_type, '"') .. ' \ - AND `b`.`item_id` = ' .. member_id .. ' \ - AND `a`.`permission` IN ("' .. table.concat(permissions, ',') .. '") \ - GROUP BY `b`.`group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS; - end + local sql_query = 'SELECT DISTINCT `c`.`id`, `c`.`name` \ + FROM `group_permissions` `a` \ + JOIN `group_memberships` `b` ON `a`.`target_group_id` = `b`.`group_id` \ + JOIN `groups` `c` ON `c`.`id` = `b`.`group_id` \ + WHERE `b`.`item_type` = ' .. self.database:escape(member_type, '"') .. ' \ + AND `b`.`item_id` = ' .. member_id .. ' \ + AND `a`.`permission` = ' .. self.database:escape(permission, '"') .. ' \ + GROUP BY `b`.`group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS; local group_names = {}; local group_ids = {}; -- cgit v1.2.3 From ab22563c3206fc3d986495214a57f29f26761b36 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 24 Feb 2013 09:33:49 +0100 Subject: table functions --- misc/freeswitch/scripts/common/str.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'misc/freeswitch/scripts/common') diff --git a/misc/freeswitch/scripts/common/str.lua b/misc/freeswitch/scripts/common/str.lua index 72ff388..541199f 100644 --- a/misc/freeswitch/scripts/common/str.lua +++ b/misc/freeswitch/scripts/common/str.lua @@ -146,3 +146,37 @@ end function blank(value) return (value == nil or to_s(value) == ''); end + +-- concatenate string to buffer +function append(buffer, value, separator, prefix, suffix) + separator = separator or ''; + prefix = prefix or ''; + suffix = suffix or ''; + if buffer ~= '' then + buffer = buffer .. separator .. prefix .. value .. suffix; + else + buffer = prefix .. value .. suffix; + end + + return buffer; +end + +-- concatenate array values to string +function concat(array, separator, prefix, suffix) + local buffer = ''; + for key, value in pairs(array) do + buffer = append(buffer, value, separator, prefix, suffix); + end + + return buffer; +end + +-- concatenate array keys to string +function concat_keys(array, separator, prefix, suffix) + local buffer = ''; + for key, value in pairs(array) do + buffer = append(buffer, key, separator, prefix, suffix); + end + + return buffer; +end -- cgit v1.2.3 From 0442cd19bc9383669b506185356227361a16e442 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 09:29:40 -0500 Subject: call_forwards - polymorphism added --- misc/freeswitch/scripts/common/call_forwarding.lua | 55 ++++++++++++++++++++++ misc/freeswitch/scripts/common/phone_number.lua | 55 ++-------------------- 2 files changed, 59 insertions(+), 51 deletions(-) (limited to 'misc/freeswitch/scripts/common') diff --git a/misc/freeswitch/scripts/common/call_forwarding.lua b/misc/freeswitch/scripts/common/call_forwarding.lua index 400fcde..192c694 100644 --- a/misc/freeswitch/scripts/common/call_forwarding.lua +++ b/misc/freeswitch/scripts/common/call_forwarding.lua @@ -37,6 +37,61 @@ function CallForwarding.find_by_id(self, id) return nil end + +function CallForwarding.list_by_owner(self, call_forwardable_id, call_forwardable_type, caller_ids) + require 'common.str'; + + if not tonumber(call_forwardable_id) or common.str.blank(call_forwardable_type) then + return {}; + end + + local sql_query = 'SELECT \ + `a`.`destination` AS `number`, \ + `a`.`destinationable_id` AS `id`, \ + `a`.`destinationable_type` AS `type`, \ + `a`.`call_forwardable_id`, \ + `a`.`call_forwardable_type`, \ + `a`.`timeout`, `a`.`depth`, \ + `a`.`source`, \ + `b`.`value` AS `service` \ + FROM `call_forwards` `a` JOIN `call_forward_cases` `b` ON `a`.`call_forward_case_id` = `b`.`id` \ + WHERE `a`.`call_forwardable_id`= ' .. tonumber(call_forwardable_id) .. ' \ + AND `a`.`call_forwardable_type`= ' .. self.database:escape(call_forwardable_type, '"') .. ' \ + AND `a`.`active` IS TRUE'; + + local call_forwarding_entries = {}; + + self.database:query(sql_query, function(forwarding_entry) + local entry_match = false; + + if common.str.blank(forwarding_entry.source) then + entry_match = true; + else + local sources = common.str.strip_to_a(forwarding_entry.source, ',') + for source_index=1, #sources do + for caller_id_index=1, #caller_ids do + if caller_ids[caller_id_index]:match(sources[source_index]) then + entry_match = true; + self.log:debug('CALL_FORWARDING - source match: ', sources[source_index], ' ~ ', caller_ids[caller_id_index] ); + break; + end + end + end + end + + if entry_match then + call_forwarding_entries[forwarding_entry.service] = forwarding_entry; + self.log:debug('CALL_FORWARDING - ', call_forwardable_type, '=', call_forwardable_id, + ', service: ', forwarding_entry.service, + ', destination: ',forwarding_entry.type, '=', forwarding_entry.id, + ', number: ', forwarding_entry.number); + end + end) + + return call_forwarding_entries; +end + + function CallForwarding.presence_set(self, presence_state) require 'dialplan.presence' local presence = dialplan.presence.Presence:new(); diff --git a/misc/freeswitch/scripts/common/phone_number.lua b/misc/freeswitch/scripts/common/phone_number.lua index 6635296..d6ee42a 100644 --- a/misc/freeswitch/scripts/common/phone_number.lua +++ b/misc/freeswitch/scripts/common/phone_number.lua @@ -55,6 +55,8 @@ function PhoneNumber.find_by_number(self, number, phone_numberable_types) self.database:query(sql_query, function(number_entry) phone_number = PhoneNumber:new(self); phone_number.record = number_entry; + phone_number.id = tonumber(number_entry.id); + phone_number.uuid = number_entry.uuid; end) return phone_number; @@ -68,6 +70,8 @@ function PhoneNumber.find_all_by_owner(self, owner_id, owner_type) self.database:query(sql_query, function(number_entry) phone_numbers[tonumber(number_entry.id)] = PhoneNumber:new(self); phone_numbers[tonumber(number_entry.id)].record = number_entry; + phone_numbers[tonumber(number_entry.id)].id = tonumber(number_entry.id); + phone_numbers[tonumber(number_entry.id)].uuid = number_entry.uuid; end) return phone_numbers; @@ -94,57 +98,6 @@ function PhoneNumber.list_by_same_owner(self, number, owner_types) end end --- Retrieve call forwarding -function PhoneNumber.call_forwarding(self, caller_ids) - require 'common.str' - - sources = sources or {}; - table.insert(sources, ''); - - local sql_query = 'SELECT \ - `a`.`destination` AS `number`, \ - `a`.`call_forwardable_id` AS `id`, \ - `a`.`call_forwardable_type` AS `type`, \ - `a`.`timeout`, `a`.`depth`, \ - `a`.`source`, \ - `b`.`value` AS `service` \ - FROM `call_forwards` `a` JOIN `call_forward_cases` `b` ON `a`.`call_forward_case_id` = `b`.`id` \ - WHERE `a`.`phone_number_id`= ' .. tonumber(self.record.id) .. ' \ - AND `a`.`active` IS TRUE'; - - local call_forwarding = {} - - self.database:query(sql_query, function(forwarding_entry) - local entry_match = false; - - if common.str.blank(forwarding_entry.source) then - entry_match = true; - else - local sources = common.str.strip_to_a(forwarding_entry.source, ',') - for index, source in ipairs(sources) do - for index, caller_id in ipairs(caller_ids) do - if caller_id:match(source) then - entry_match = true; - self.log:debug('CALL_FORWARDING_GET - source match: ', source, ' ~ ', caller_id ); - break; - end - end - end - end - - if entry_match then - call_forwarding[forwarding_entry.service] = forwarding_entry; - self.log:debug('CALL_FORWARDING_GET - PhoneNumber=', self.record.id, '/', self.record.uuid, '@', self.record.gs_node_id, - ', number: ', self.record.number, - ', service: ', forwarding_entry.service, - ', destination: ',forwarding_entry.type, '=', forwarding_entry.id, - ', number: ', forwarding_entry.number); - end - end) - - return call_forwarding; -end - function PhoneNumber.call_forwarding_effective(self, service, source) local conditions = {} -- cgit v1.2.3 From 08285c5324b03c307d34313d5030a6e95ed09068 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 17:11:00 -0500 Subject: return active groups only --- misc/freeswitch/scripts/common/group.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'misc/freeswitch/scripts/common') diff --git a/misc/freeswitch/scripts/common/group.lua b/misc/freeswitch/scripts/common/group.lua index 1a2d315..c4125bc 100644 --- a/misc/freeswitch/scripts/common/group.lua +++ b/misc/freeswitch/scripts/common/group.lua @@ -48,6 +48,7 @@ function Group.name_id_by_permission(self, member_id, member_type, permission) WHERE `b`.`item_type` = ' .. self.database:escape(member_type, '"') .. ' \ AND `b`.`item_id` = ' .. member_id .. ' \ AND `a`.`permission` = ' .. self.database:escape(permission, '"') .. ' \ + AND `c`.`active` IS TRUE \ GROUP BY `b`.`group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS; local group_names = {}; @@ -72,6 +73,7 @@ function Group.name_id_by_member(self, member_id, member_type) JOIN `groups` `c` ON `c`.`id` = `b`.`group_id` \ WHERE `b`.`item_type` = ' .. self.database:escape(member_type, '"') .. ' \ AND `b`.`item_id` = ' .. member_id .. ' \ + AND `c`.`active` IS TRUE \ GROUP BY `b`.`group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS; local group_names = {}; -- cgit v1.2.3