From c203c3efaae924f420862ad8a243dc18d2c9e154 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Mon, 25 Mar 2013 15:29:12 +0100 Subject: add dummy entry for G.729 activation --- misc/freeswitch/conf/freeswitch.xml | 3 +++ 1 file changed, 3 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml index 3405bc9..5792e96 100644 --- a/misc/freeswitch/conf/freeswitch.xml +++ b/misc/freeswitch/conf/freeswitch.xml @@ -1234,6 +1234,9 @@ + + -- cgit v1.2.3 From 3833ac1506fb336cd617ec41d25e35c34e74064e Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Mar 2013 15:51:35 +0100 Subject: voicemail refactored --- misc/freeswitch/conf/freeswitch.xml | 136 ++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml index 97e027d..025641b 100644 --- a/misc/freeswitch/conf/freeswitch.xml +++ b/misc/freeswitch/conf/freeswitch.xml @@ -73,6 +73,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -250,6 +314,14 @@ + + + + + + + + @@ -599,6 +671,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From 2c1136bd6d3a772f13cf4aacdca0d17baeb79ffe Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Mar 2013 15:52:02 +0100 Subject: defaults added --- .../scripts/common/configuration_table.lua | 59 ++++++++++++++++++---- 1 file changed, 48 insertions(+), 11 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/common/configuration_table.lua b/misc/freeswitch/scripts/common/configuration_table.lua index 85bc014..1b8d8b7 100644 --- a/misc/freeswitch/scripts/common/configuration_table.lua +++ b/misc/freeswitch/scripts/common/configuration_table.lua @@ -4,12 +4,43 @@ module(...,package.seeall) + +function cast(variable_type, value, default) + require 'common.str'; + + if variable_type == 'boolean' then + return common.str.to_b(value); + elseif variable_type == 'integer' then + if default and not tonumber(value) then + return default; + end + return common.str.to_i(value); + elseif variable_type == 'float' then + if default and not tonumber(value) then + return default; + end + return common.str.to_n(value); + elseif variable_type == 'string' then + if default and not value then + return default; + end + return common.str.to_s(value); + elseif variable_type == 'array' then + if default and not value then + return default; + end + return common.str.to_a(value, ','); + end +end + -- retrieve configuration from database -function get(database, entity, section) +function get(database, entity, section, defaults) if not database or not entity then return {}; end + defaults = defaults or {}; + require 'common.str' local sql_query = 'SELECT * FROM `gs_parameters` WHERE `entity` = "' .. entity .. '"'; @@ -17,7 +48,7 @@ function get(database, entity, section) sql_query = sql_query .. ' AND `section` = "' .. section .. '"'; end - local root = {} + local root = defaults[1] or {} local parameter_class = ''; database:query(sql_query, function(parameters) @@ -26,21 +57,27 @@ function get(database, entity, section) local p_name = common.str.strip(parameters.name); if not root[p_section] then - root[p_section] = {}; + root[p_section] = defaults[p_section] or {}; end - if p_class_type == 'boolean' then - root[p_section][p_name] = common.str.to_b(parameters.value); - elseif p_class_type == 'integer' then - root[p_section][p_name] = common.str.to_i(parameters.value); - else - root[p_section][p_name] = tostring(parameters.value); - end + root[p_section][p_name] = cast(p_class_type, parameters.value); end) if section then - return root[section]; + return root[section] or defaults[section]; end return root; end + + +function settings(database, table_name, key, value, defaults) + local sql_query = 'SELECT * FROM ' .. database:escape(table_name, '`') .. ' WHERE ' .. database:escape(key, '`') .. ' = ' .. database:escape(value, '"'); + + local settings_entries = defaults or {}; + database:query(sql_query, function(record) + settings_entries[record.name] = cast(record.class_type:lower(), record.value, settings_entries[record.name]); + end); + + return settings_entries; +end -- cgit v1.2.3 From d79da64a619f83e06990c372dd1f2787b3109e7a Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Mar 2013 15:52:40 +0100 Subject: ivr methods --- misc/freeswitch/scripts/dialplan/ivr.lua | 67 ++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 11 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/ivr.lua b/misc/freeswitch/scripts/dialplan/ivr.lua index f8b8a2d..2a16e3b 100644 --- a/misc/freeswitch/scripts/dialplan/ivr.lua +++ b/misc/freeswitch/scripts/dialplan/ivr.lua @@ -21,29 +21,51 @@ function Ivr.new(self, arg) end -function Ivr.ivr_phrase(self, phrase, keys, timeout, ivr_repeat) +function Ivr.ivr_break(self) + return self.exit or not self.caller:ready(); +end + + +function Ivr.ivr_phrase(self, phrase, keys, timeout, ivr_repeat, phrase_data) ivr_repeat = ivr_repeat or 3; timeout = timeout or 30; self.digit = ''; self.exit = false; self.break_keys = {}; + local query_keys = {}; + for index=1, #keys do - self.break_keys[keys[index]] = true; + if type(keys[index]) == 'table' then + if tostring(keys[index].key) ~= '' then + table.insert(query_keys, keys[index].key); + end + self.break_keys[keys[index].key] = keys[index]; + else + if tostring(keys[index]) ~= '' then + table.insert(query_keys, keys[index]); + end + self.break_keys[keys[index]] = true; + end end global_callback:callback('dtmf', 'ivr_ivr_phrase', self.ivr_phrase_dtmf, self); - + local continue = true; for index=0, ivr_repeat do - self.caller.session:sayPhrase(phrase, table.concat(keys, ':')); - self.caller:sleep(timeout * 1000); - if self.exit then + continue = self:ivr_break() or self.caller.session:sayPhrase(phrase, phrase_data or table.concat(query_keys, ':')); + continue = self:ivr_break() or self.caller:sleep(timeout * 1000); + + if self:ivr_break() then break; end end global_callback:callback_unset('dtmf', 'ivr_ivr_phrase'); + if type(self.break_keys[self.digit]) == 'table' then + return self.digit, self.break_keys[self.digit]; + end + return self.digit; end @@ -66,8 +88,8 @@ function Ivr.read_phrase(self, phrase, phrase_data, max_keys, min_keys, timeout, timeout = timeout or 30; global_callback:callback('dtmf', 'ivr_read_phrase', self.read_phrase_dtmf, self); - self.caller.session:sayPhrase(phrase, phrase_data or enter_key or ''); - self.caller:sleep(timeout * 1000); + local continue = self:ivr_break() or self.caller.session:sayPhrase(phrase, phrase_data or enter_key or ''); + continue = self:ivr_break() or self.caller:sleep(timeout * 1000); global_callback:callback_unset('dtmf', 'ivr_read_phrase'); return self.digits; @@ -88,7 +110,7 @@ function Ivr.read_phrase_dtmf(self, dtmf) end -function Ivr.check_pin(self, phrase, pin, pin_timeout, pin_repeat, key_enter) +function Ivr.check_pin(self, phrase_enter, phrase_incorrect, pin, pin_timeout, pin_repeat, key_enter) if not pin then return nil; end @@ -101,19 +123,42 @@ function Ivr.check_pin(self, phrase, pin, pin_timeout, pin_repeat, key_enter) for i = 1, pin_repeat do if digits == pin then self.caller:send_display('PIN: OK'); - break + break; elseif digits ~= "" then self.caller:send_display('PIN: wrong'); + self.caller.session:sayPhrase(phrase_incorrect, ''); + elseif self:ivr_break() then + break; end self.caller:send_display('Enter PIN'); - digits = ivr:read_phrase(phrase, nil, 0, pin:len() + 1, pin_timeout, key_enter); + digits = ivr:read_phrase(phrase_enter, nil, 0, pin:len() + 1, pin_timeout, key_enter); end if digits ~= pin then self.caller:send_display('PIN: wrong'); + self.caller.session:sayPhrase(phrase_incorrect, ''); return false end self.caller:send_display('PIN: OK'); return true; end + + +function Ivr.record(self, file_name, phrase_record, phrase_too_short, record_length_max, record_length_min, record_repeat, silence_level, silence_lenght_abort) + local duration = nil; + for index=1, record_repeat do + if (duration and duration >= record_length_min) or not self.caller:ready() then + break; + elseif duration then + self.caller:send_display('Recording too short'); + self.caller.session:sayPhrase(phrase_too_short); + end + self.caller.session:sayPhrase(phrase_record); + self.caller:send_display('Recording...'); + local result = self.caller.session:recordFile(file_name, record_length_max, silence_level, silence_lenght_abort); + duration = self.caller:to_i('record_seconds'); + end + + return duration or 0; +end -- cgit v1.2.3 From ecfea29b48d9581725bd6d8a8eb25b090f25b55e Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Mar 2013 15:53:56 +0100 Subject: voicemail_check dialplan function --- misc/freeswitch/scripts/dialplan/functions.lua | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index a47d9d3..6399c5e 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -756,31 +756,28 @@ function Functions.voicemail_message_leave(self, caller, phone_number) end -function Functions.voicemail_check(self, caller, phone_number) +function Functions.voicemail_check(self, caller, number) + require 'dialplan.voicemail'; local voicemail_account = nil; local voicemail_authorized = false; - - require 'dialplan.voicemail' - - if phone_number then - voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_number(phone_number); - else - if caller.auth_account_type == 'SipAccount' then - voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_sip_account_id(caller.auth_account.id); - voicemail_authorized = true; - end + + if number then + voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_number(number); + elseif caller.auth_account and tostring(caller.auth_account.class):lower() == 'sipaccount' then + voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_sip_account_id(caller.auth_account.id); + voicemail_authorized = true; end if not voicemail_account then + self.log:notice('FUNCTION_VOICEMAIL_CHECK - mailbox not found'); return { continue = false, code = 404, phrase = 'Mailbox not found', no_cdr = true } end - voicemail_account:menu(caller, voicemail_authorized); - - return { continue = false, code = 200, phrase = 'OK', no_cdr = true } + return voicemail_account:menu_main(caller, voicemail_authorized); end + function Functions.acd_membership_toggle(self, caller, agent_id, phone_number) -- Find caller's SipAccount local caller_sip_account = self:ensure_caller_sip_account(caller); -- cgit v1.2.3 From 479d5b9353a518e456a68d74e81730eeb4230890 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Mar 2013 15:54:41 +0100 Subject: voicemail refactored --- misc/freeswitch/scripts/dialplan/voicemail.lua | 378 ++++++++++++++++++++----- 1 file changed, 301 insertions(+), 77 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index caeeb48..4fd5612 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -1,17 +1,39 @@ -- Gemeinschaft 5 module: voicemail class --- (c) AMOOMA GmbH 2012-2013 +-- (c) AMOOMA GmbH 2013 -- module(...,package.seeall) Voicemail = {} -MESSAGE_LENGTH_MIN = 3; -MESSAGE_LENGTH_MAX = 120; -SILENCE_LENGTH_ABORT = 5; -SILENCE_LEVEL = 500; -BEEP = 'tone_stream://%(1000,0,500)'; -RECORD_FILE_PREFIX = '/var/spool/freeswitch/voicemail_'; +DEFAULT_SETTINGS = { + pin_length_max = 10, + pin_length_min = 2, + pin_timeout = 20, + key_new_messages = '1', + key_saved_messages = '2', + key_config_menu = '0', + key_terminator = '#', + key_previous = '4', + key_next = '6', + key_delete = '7', + key_save = '2', + key_main_menu = '#', + record_length_max = 300, + record_length_min = 4, + records_max = 100, + silence_lenght_abort = 3, + silence_level = 500, + beep = 'tone_stream://%(1000,0,500)', + record_file_prefix = 'voicemail_', + record_file_suffix = '.wav', + record_file_path = '/var/spool/freeswitch/', + record_repeat = 3, + notify = true, + attachment = true, + mark_read = true, + purge = false, +} -- create voicemail object function Voicemail.new(self, arg) @@ -23,93 +45,313 @@ function Voicemail.new(self, arg) self.log = arg.log; self.database = arg.database; self.record = arg.record; + self.domain = arg.domain; return object end --- find voicemail account by sip account id -function Voicemail.find_by_sip_account_id(self, id) - local sql_query = 'SELECT `a`.`id`, `a`.`uuid`, `a`.`auth_name`, `a`.`caller_name`, `b`.`name_path`, `b`.`greeting_path`, `a`.`voicemail_pin`, `b`.`password`, `c`.`host` AS `domain` \ - FROM `sip_accounts` `a` LEFT JOIN `voicemail_prefs` `b` ON `a`.`auth_name` = `b`.`username` \ - JOIN `sip_domains` `c` ON `a`.`sip_domain_id` = `c`.`id` \ - WHERE `a`.`id` = ' .. tonumber(id); +function Voicemail.find_by_sql(self, sql_query) local voicemail_account = nil; self.database:query(sql_query, function(entry) voicemail_account = Voicemail:new(self); voicemail_account.record = entry; voicemail_account.id = tonumber(entry.id); voicemail_account.uuid = entry.uuid; - end) + voicemail_account.name = entry.name; + voicemail_account.settings = self:settings_get(entry.id); + end); return voicemail_account; end --- Find Voicemail account by name -function Voicemail.find_by_name(self, account_name) - id = tonumber(id) or 0; - local sql_query = string.format('SELECT * FROM `voicemail_prefs` WHERE `username`= "%s" LIMIT 1', account_name) - local record = nil - self.database:query(sql_query, function(voicemail_entry) - record = voicemail_entry - end) +function Voicemail.find_by_name(self, name) + local sql_query = 'SELECT * FROM `voicemail_accounts` \ + WHERE `name` = ' .. self.database:escape(name, '"') .. ' LIMIT 1'; + + return self:find_by_sql(sql_query); +end + + +function Voicemail.find_by_id(self, id) + local sql_query = 'SELECT * FROM `voicemail_accounts` \ + WHERE `id` = ' .. self.database:escape(id, '"') .. ' LIMIT 1'; + + return self:find_by_sql(sql_query); +end + + +function Voicemail.find_by_sip_account_id(self, id) + local sql_query = 'SELECT `a`.* FROM `voicemail_accounts` `a` \ + JOIN `sip_accounts` `b` ON `a`.`id` = `b`.`voicemail_account_id` \ + WHERE `b`.`id` = ' .. self.database:escape(id, '"') .. ' LIMIT 1'; + + return self:find_by_sql(sql_query); +end + + +function Voicemail.find_by_number(self, number) + local sql_query = 'SELECT `a`.* FROM `voicemail_accounts` `a` \ + JOIN `sip_accounts` `b` ON `a`.`id` = `b`.`voicemail_account_id` \ + JOIN `phone_numbers` `c` ON `b`.`id` = `c`.`phone_numberable_id` \ + WHERE `c`.`number` = ' .. self.database:escape(number, '"') .. ' \ + AND `c`.`phone_numberable_type` = "SipAccount" LIMIT 1'; + + return self:find_by_sql(sql_query); +end + + +function Voicemail.settings_get(self, id) + require 'common.configuration_table'; + local parameters = common.configuration_table.get(self.database, 'voicemail', 'settings', { settings = DEFAULT_SETTINGS }); - if voicemail_account then - voicemail_account.account_name = account_name; - if record then - voicemail_account.name_path = record.name_path; - voicemail_account.greeting_path = record.greeting_path; - voicemail_account.password = record.password; + return common.configuration_table.settings(self.database, 'voicemail_settings', 'voicemail_account_id', id or self.id, parameters) +end + + +function Voicemail.messages_get(self, status) + local sql_query = 'SELECT * FROM `voicemail_msgs` WHERE `username` = ' .. self.database:escape(self.name, '"'); + + status = status or 'all'; + + if status == 'read' then + sql_query = sql_query .. ' AND `read_epoch` > 0'; + elseif status == 'unread' then + sql_query = sql_query .. ' AND (`read_epoch` = 0 OR `read_epoch` IS NULL)'; + elseif status == 'new' then + sql_query = sql_query .. ' AND `in_folder` != "save" AND `flags` != "save"'; + elseif status == 'saved' then + sql_query = sql_query .. ' AND (`in_folder` = "save" OR `flags` = "save")'; + end + + return self.database:query_return_all(sql_query); +end + + +function Voicemail.check_pin(self, pin) + self.caller:answer(); + self.caller:sleep(1000); + + require 'dialplan.ivr'; + local ivr = dialplan.ivr.Ivr:new{ caller = self.caller, log = self.log }; + + local digits = ''; + for i = 1, 3 do + if digits == pin then + self.caller:send_display('PIN: OK'); + break + elseif digits ~= "" then + self.caller:send_display('PIN: wrong'); end + self.caller:send_display('Enter PIN'); + digits = ivr:read_phrase('voicemail_enter_pass', nil, self.settings.pin_length_min, self.settings.pin_length_max, self.settings.pin_timeout, self.settings.terminator_key); + end + + if digits ~= pin then + return false + end + + return true; +end + + +function Voicemail.menu_main(self, caller, authorized) + self.caller = caller; + + require 'dialplan.ivr'; + self.ivr = dialplan.ivr.Ivr:new{ caller = self.caller, log = self.log }; + + if not authorized then + if common.str.blank(self.pin) then + self.log:notice('VOICEMAIL_MAIN_MENU - unaunthorized, no PIN, ', self.class, '=', self.id, '/', self.uuid, '|', self.name); + return { continue = false, code = 500, phrase = 'Unauthorized', no_cdr = true } + end + + self.caller:answer(); + self.caller:sleep(1000); + + if not self.ivr:check_pin('voicemail_enter_pass', 'voicemail_fail_auth', self.pin) then + self.log:notice('VOICEMAIL_MAIN_MENU - wrong PIN, ', self.class, '=', self.id, '/', self.uuid, '|', self.name); + caller.session:sayPhrase('voicemail_goodbye'); + return { continue = false, code = 500, phrase = 'Unauthorized', no_cdr = true } + end + end + + local messages_new = self:messages_get('unread'); + local messages_saved = self:messages_get('read'); + + if not caller:answered() then + self.caller:answer(); + self.caller:sleep(1000); end - return voicemail_account + if self.settings.voicemail_hello then + caller.session:sayPhrase('voicemail_hello'); + end + + if self.settings.voicemail_message_count then + caller.session:sayPhrase('voicemail_message_count', #messages_new .. ':new'); + end + + while true do + self.log:info('VOICEMAIL_MAIN_MENU - ', self.class, '=', self.id, '/', self.uuid, '|', self.name, ', messages: ', #messages_new, ':', #messages_saved); + self.caller:send_display(#messages_new .. ' new messages'); + + local main_menu = { + { key = self.settings.key_new_messages, method = self.menu_messages, parameters = { self, 'new', messages_new } }, + { key = self.settings.key_saved_messages, method = self.menu_messages, parameters = { self, 'saved', messages_saved } }, + { key = self.settings.key_config_menu, method = self.menu_options, parameters = { self } }, + { key = self.settings.key_terminator, exit = true }, + { key = '', exit = true }, + }; + + local digits, key = self.ivr:ivr_phrase('voicemail_menu', main_menu); + self.log:debug('VOICEMAIL_MAIN_MENU - digit: ', digits); + if key.exit then + break; + end + + key.method(unpack(key.parameters)); + + messages_new = self:messages_get('unread'); + messages_saved = self:messages_get('read'); + end + self.caller:send_display('Goodbye'); + caller.session:sayPhrase('voicemail_goodbye'); end --- Find Voicemail account by number -function Voicemail.find_by_number(self, phone_number) - local sip_account = nil; - require "common.phone_number" - local destination_number_object = common.phone_number.PhoneNumber:new{ log = self.log, database = self.database }:find_by_number(phone_number); - if destination_number_object and destination_number_object.record.phone_numberable_type:lower() == "sipaccount" then - return self:find_by_sip_account_id(destination_number_object.record.phone_numberable_id); +function Voicemail.menu_messages(self, folder, messages) + self.log:info('VOICEMAIL_MESSAGES_MENU - ', folder,' messages: ', #messages); + + local digits = nil; + local key = nil; + + local message_menu = { + { key = self.settings.key_previous, action = 'previous' }, + { key = self.settings.key_delete, action = 'delete' }, + { key = self.settings.key_save, action = 'save' }, + { key = self.settings.key_next, action = 'next' }, + { key = self.settings.key_main_menu, exit = true }, + }; + + if folder == 'saved' then + message_menu = { + { key = self.settings.key_previous, action = 'previous' }, + { key = self.settings.key_delete, action = 'delete' }, + { key = self.settings.key_next, action = 'next' }, + { key = self.settings.key_main_menu, exit = true }, + }; + end + + if #messages == 0 then + digits, key = self.ivr:ivr_phrase('voicemail_no_messages', message_menu, 0, 0); + return; end - return false; + local index = 1; + while index <= #messages do + local message = messages[index]; + self.caller:send_display(index .. ': ' .. message.cid_name .. ' ' .. message.cid_number); + digits, key = self.ivr:ivr_phrase('voicemail_message_play', message_menu, 0, 0, + index .. ':' .. message.created_epoch .. ':' .. message.file_path + ); + if digits == '' then + if common.str.to_i(message.read_epoch) == 0 then + self:message_mark_read(message); + end + digits, key = self.ivr:ivr_phrase('voicemail_message_menu_' .. folder, message_menu, 15, 0); + end + + if not key or key.exit then + break; + end + + if key.action == 'previous' then + if index > 1 then + index = index - 1; + end + else + index = index + 1; + end + + if index > #messages then + digits, key = self.ivr:ivr_phrase('voicemail_no_messages', message_menu, 0, 0); + return; + end + + if key.action == 'delete' and self:message_delete(message) then + self.caller:send_display('Message deleted'); + digits = self.caller.session:sayPhrase('voicemail_ack', 'deleted'); + elseif key.action == 'save' and self:message_save(message) then + self.caller:send_display('Message saved'); + digits = self.caller.session:sayPhrase('voicemail_ack', 'saved'); + end + end end -function Voicemail.leave(self, caller, phone_number) - require 'common.str' +function Voicemail.menu_options(self) + self.log:info('VOICEMAIL_OPTIONS_MENU'); + self.caller:send_display('Voicemail options'); +end + + +function Voicemail.message_delete(self, message) + self.log:debug('VOICEMAIL_MESSAGE_DELETE - message: ', message.uuid); + require 'common.fapi'; + return common.fapi.FApi:new{ log = self.log }:execute('vm_delete', message.username .. '@' .. message.domain .. ' ' .. message.uuid); +end + +function Voicemail.message_mark_read(self, message) + self.log:debug('VOICEMAIL_MESSAGE_MARK_READ - message: ', message.uuid); + require 'common.fapi'; + return common.fapi.FApi:new{ log = self.log }:execute('vm_read', message.username .. '@' .. message.domain .. ' read ' .. message.uuid); +end - self.log:info('VOICEMAIL_LEAVE - account=', self.record.id, '/', self.record.uuid, ', auth_name: ', self.record.auth_name, ', caller_name: ', self.record.caller_name); - caller:set_callee_id(phone_number, self.record.caller_name); +function Voicemail.message_save(self, message) + self.log:debug('VOICEMAIL_MESSAGE_SAVE - message: ', message.uuid); + require 'common.fapi'; + return common.fapi.FApi:new{ log = self.log }:execute('vm_fsdb_msg_save', 'default ' .. message.domain .. ' ' .. message.username .. ' ' .. message.uuid); +end + + +function Voicemail.leave(self, caller, greeting) + local forwarding_number = caller.forwarding_number; + self.log:info('VOICEMAIL_LEAVE - voicemail_account=', self.record.id, '/', self.record.uuid, '|', self.record.name, ', forwarding_number: ', forwarding_number); + + caller:set_callee_id(forwarding_number, common.array.try(caller, 'auth_account.caller_name') or common.array.try(caller, 'auth_account.name')); caller:answer(); - caller:send_display(common.str.to_s(self.record.caller_name), common.str.to_s(phone_number)); + caller:send_display(common.array.try(caller, 'auth_account.caller_name') or common.array.try(caller, 'auth_account.name')); caller:sleep(1000); - if not common.str.blank(self.record.greeting_path) then - caller.session:sayPhrase('voicemail_play_greeting', 'greeting:' .. tostring(self.record.greeting_path)); - elseif not common.str.blank(self.record.name_path) then - caller.session:sayPhrase('voicemail_play_greeting', 'name:' .. tostring(self.record.name_path)); - elseif not common.str.blank(phone_number) then - caller.session:sayPhrase('voicemail_play_greeting', (tostring(phone_number):gsub('[%D]', ''))); + if not common.str.blank(forwarding_number) then + caller.session:sayPhrase('voicemail_play_greeting', (tostring(forwarding_number):gsub('[%D]', ''))); end - local record_file_name = RECORD_FILE_PREFIX .. caller.uuid .. '.wav'; - caller.session:streamFile(BEEP); + local record_file_name = self.settings.record_file_path ..self.settings.record_file_prefix .. caller.uuid .. self.settings.record_file_suffix; self.log:info('VOICEMAIL_LEAVE - recording to file: ', tostring(record_file_name)); - local result = caller.session:recordFile(record_file_name, MESSAGE_LENGTH_MAX, SILENCE_LEVEL, SILENCE_LENGTH_ABORT); - local duration = caller:to_i('record_seconds'); + + require 'dialplan.ivr'; + local ivr = dialplan.ivr.Ivr:new{ caller = caller, log = self.log }; + + local duration = ivr:record( + record_file_name, + 'voicemail_record_message', + 'voicemail_message_too_short', + self.settings.record_length_max, + self.settings.record_length_min, + self.settings.record_repeat, + self.settings.silence_level, + self.settings.silence_lenght_abort); - if duration >= MESSAGE_LENGTH_MIN then + if duration >= self.settings.record_length_min then self.log:info('VOICEMAIL_LEAVE - saving recorded message to voicemail, duration: ', duration); require 'common.fapi' common.fapi.FApi:new{ log = self.log, uuid = caller.uuid }:execute('vm_inject', - self.record.auth_name .. - '@' .. self.record.domain .. " '" .. + self.record.name .. + '@' .. self.domain .. " '" .. record_file_name .. "' '" .. caller.caller_id_number .. "' '" .. caller.caller_id_name .. "' '" .. @@ -121,32 +363,14 @@ function Voicemail.leave(self, caller, phone_number) caller:set_variable('voicemail_message_len'); end os.remove(record_file_name); - return true; + caller:send_display('Goodbye'); + caller.session:sayPhrase('voicemail_goodbye'); end function Voicemail.trigger_notification(self, caller) - local command = 'http_request.lua ' .. caller.uuid .. ' http://127.0.0.1/trigger/voicemail?sip_account_id=' .. tostring(self.id); + local command = 'http_request.lua ' .. caller.uuid .. ' http://127.0.0.1/trigger/voicemail?voicemail_account_id=' .. tostring(self.id); - require 'common.fapi' + require 'common.fapi'; return common.fapi.FApi:new():execute('luarun', command); end - - -function Voicemail.menu(self, caller, authorized) - self.log:info('VOICEMAIL_MENU - account: ', self.record.auth_name); - - if authorized then - caller:set_variable('voicemail_authorized', true); - end - - caller:set_callee_id(phone_number, self.record.caller_name); - caller:answer(); - caller:send_display(common.str.to_s(self.record.caller_name), common.str.to_s(phone_number)); - - caller:sleep(1000); - caller:set_variable('skip_greeting', true); - caller:set_variable('skip_instructions', true); - - caller:execute('voicemail', 'check default ' .. self.record.domain .. ' ' .. self.record.auth_name); -end -- cgit v1.2.3 From ed7625053860e646824e3213dbff96c312e4c9b7 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Mar 2013 15:55:17 +0100 Subject: voicemail dialplan method --- misc/freeswitch/scripts/dialplan/dialplan.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 5335328..7ed835b 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -590,19 +590,21 @@ end function Dialplan.voicemail(self, destination) - require 'dialplan.voicemail' + require 'dialplan.voicemail'; local voicemail_account = nil; - - local sip_account_id - if not common.str.blank(destination.number) and false then - voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_number(destination.number); + if common.str.to_i(destination.id) > 0 then + voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database, domain = self.domain }:find_by_id(destination.id); + elseif not common.str.blank(destination.number) then + voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database, domain = self.domain }:find_by_number(destination.number); elseif self.caller.auth_account and self.caller.auth_account.class == 'sipaccount' then - voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_sip_account_id(self.caller.auth_account.id); + voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database, domain = self.domain }:find_by_sip_account_id(self.caller.auth_account.id); + elseif self.caller.forwarding_number then + voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database, domain = self.domain }:find_by_number(self.caller.forwarding_number); end if not voicemail_account then - self.log:error('VOICEMAIL - no mailbox'); + self.log:error('VOICEMAIL - mailbox not found, '); return { continue = false, code = 404, phrase = 'Mailbox not found' } end -- cgit v1.2.3 From 6c5141ca90bb25dd358a4b2cb4bf5a7a39c22597 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Mar 2013 15:55:42 +0100 Subject: global callback --- misc/freeswitch/scripts/dialplan_default.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan_default.lua b/misc/freeswitch/scripts/dialplan_default.lua index 2b651c5..ba51ed3 100644 --- a/misc/freeswitch/scripts/dialplan_default.lua +++ b/misc/freeswitch/scripts/dialplan_default.lua @@ -29,6 +29,9 @@ function input_call_back_callee(s, object_type, object_data, arg) end end +function global_callback_handler(...) + return global_callback:run({...}); +end -- initialize logging require 'common.log' @@ -90,6 +93,10 @@ else end end +require 'dialplan.callback'; +global_callback = dialplan.callback.Callback:new{ session = session, log = log }; + + if start_caller.from_node then log:debug('AUTHENTICATION_REQUIRED_NODE - node_id: ', start_caller.node_id, ', domain: ', start_dialplan.domain); start_dialplan:hangup(407, start_dialplan.domain); -- cgit v1.2.3 From b2bfc8a3f6a826c1c0b2bd10213c11439df11aad Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 27 Mar 2013 08:14:22 +0100 Subject: voicemail account configuration directory --- misc/freeswitch/scripts/configuration.lua | 75 ++++++++++++++----------------- 1 file changed, 34 insertions(+), 41 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index 88ef452..c17f8a4 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -412,7 +412,27 @@ function directory_sip_account(database) local user_xml = nil; - if not common.str.blank(auth_name) then + if tostring(purpose) == 'publish-vm' and not common.str.blank(auth_name) then + require 'dialplan.voicemail'; + local voicemail_account = dialplan.voicemail.Voicemail:new{ log = log, database = database }:find_by_name(auth_name); + if voicemail_account then + log:debug('DIRECTORY_VOICEMAIL_ACCOUNT - ', voicemail_account.class, '=',voicemail_account.id, '/', voicemail_account.uuid, '|', voicemail_account.name); + user_xml = xml:element{ + 'groups', + xml:element{ + 'group', + name = 'default', + xml:element{ + 'users', + xml:element{ + 'user', + id = voicemail_account.record.name, + }, + }, + }, + }; + end + elseif not common.str.blank(auth_name) then require 'common.sip_account' local sip_account = common.sip_account.SipAccount:new{ log = log, database = database}:find_by_auth_name(auth_name); @@ -435,46 +455,19 @@ function directory_sip_account(database) gs_account_owner_id = sip_account.record.sip_accountable_id } - if tostring(purpose) == 'publish-vm' then - log:debug('DIRECTORY_SIP_ACCOUNT - purpose: VoiceMail, auth_name: ', sip_account.record.auth_name, ', caller_name: ', sip_account.record.caller_name, ', domain: ', domain); - user_xml = xml:element{ - 'groups', - xml:element{ - 'group', - name = 'default', - xml:element{ - 'users', - xml:element{ - 'user', - id = sip_account.record.auth_name, - xml:element{ - 'params', - xml:from_hash('param', user_parameters, 'name', 'value'), - }, - xml:element{ - 'variables', - xml:from_hash('variable', user_variables, 'name', 'value'), - }, - }, - }, - }, - }; - else - log:debug('DIRECTORY_SIP_ACCOUNT - auth_name: ', sip_account.record.auth_name, ', caller_name: ', sip_account.record.caller_name, ', domain: ', domain); - - user_xml = xml:element{ - 'user', - id = sip_account.record.auth_name, - xml:element{ - 'params', - xml:from_hash('param', user_parameters, 'name', 'value'), - }, - xml:element{ - 'variables', - xml:from_hash('variable', user_variables, 'name', 'value'), - }, - }; - end + log:debug('DIRECTORY_SIP_ACCOUNT - auth_name: ', sip_account.record.auth_name, ', caller_name: ', sip_account.record.caller_name, ', domain: ', domain); + user_xml = xml:element{ + 'user', + id = sip_account.record.auth_name, + xml:element{ + 'params', + xml:from_hash('param', user_parameters, 'name', 'value'), + }, + xml:element{ + 'variables', + xml:from_hash('variable', user_variables, 'name', 'value'), + }, + }; else require 'common.gateway' local sip_gateway = common.gateway.Gateway:new{ log = log, database = database }:find_by_auth_name(auth_name); -- cgit v1.2.3 From 8e9f9fd6f76356c18f43a1a1526e5a5ac40bb1f5 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 27 Mar 2013 08:20:46 +0100 Subject: deletion of last message fixed --- misc/freeswitch/scripts/dialplan/voicemail.lua | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index 4fd5612..522f9c2 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -275,11 +275,6 @@ function Voicemail.menu_messages(self, folder, messages) index = index + 1; end - if index > #messages then - digits, key = self.ivr:ivr_phrase('voicemail_no_messages', message_menu, 0, 0); - return; - end - if key.action == 'delete' and self:message_delete(message) then self.caller:send_display('Message deleted'); digits = self.caller.session:sayPhrase('voicemail_ack', 'deleted'); @@ -287,6 +282,9 @@ function Voicemail.menu_messages(self, folder, messages) self.caller:send_display('Message saved'); digits = self.caller.session:sayPhrase('voicemail_ack', 'saved'); end + if index > #messages then + digits = self.ivr:ivr_phrase('voicemail_no_messages', message_menu, 0, 0); + end end end -- cgit v1.2.3 From 24a63bc91adf2b9c8d3869be80a0654b22de2636 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 27 Mar 2013 08:23:55 +0100 Subject: messages count --- misc/freeswitch/scripts/dialplan/voicemail.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index 522f9c2..eaa8064 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -189,7 +189,7 @@ function Voicemail.menu_main(self, caller, authorized) caller.session:sayPhrase('voicemail_hello'); end - if self.settings.voicemail_message_count then + if #messages_new > 0 then caller.session:sayPhrase('voicemail_message_count', #messages_new .. ':new'); end -- cgit v1.2.3 From c2e5547c22d2021bfa0dbafadd55723485e1c7d1 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 27 Mar 2013 10:37:12 +0100 Subject: handle voicemailaccount destinations --- misc/freeswitch/scripts/dialplan/dialplan.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 7ed835b..31b88fd 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -711,7 +711,7 @@ function Dialplan.switch(self, destination) end end return result; - elseif destination.type == 'voicemail' then + elseif destination.type == 'voicemail' or destination.type == 'voicemailaccount' then return self:voicemail(destination); elseif destination.type == 'dialplanfunction' then return self:dialplanfunction(destination); -- cgit v1.2.3 From 22ba2cab06b81120d8ac3ff99815fab293566932 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 27 Mar 2013 15:58:39 +0100 Subject: log line deleted --- misc/freeswitch/scripts/dialplan/hunt_group.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/hunt_group.lua b/misc/freeswitch/scripts/dialplan/hunt_group.lua index b1728c3..e87c6b2 100644 --- a/misc/freeswitch/scripts/dialplan/hunt_group.lua +++ b/misc/freeswitch/scripts/dialplan/hunt_group.lua @@ -108,7 +108,6 @@ function HuntGroup.run(self, dialplan_object, caller, destination) table.insert(caller.caller_id_numbers, number); end - self.log:debug('HUNTGROUP ', self.record.id, ' - auth: ', caller.auth_account.class, '=', caller.auth_account.id, '/', caller.auth_account.uuid, ', caller: ', caller.account.class, '=', caller.account.id, '/', caller.account.uuid); self.log:info('HUNTGROUP ', self.record.id, ' - clir: ', caller.clir, ', caller_id_numbers: ', table.concat(caller.caller_id_numbers, ',')); local hunt_group_destination = caller.destination; -- cgit v1.2.3 From 6c8f3e9536da2e8364de6696f8e0bb38032d067c Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 28 Mar 2013 09:09:57 +0100 Subject: vmplay dialplan function added --- misc/freeswitch/scripts/dialplan/functions.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index 6399c5e..ce99953 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -102,6 +102,8 @@ function Functions.dialplan_function(self, caller, dialed_number) result = self:voicemail_message_leave(caller, parameters[3]); elseif fid == "vmcheck" then result = self:voicemail_check(caller, parameters[3]); + elseif fid == "vmplay" then + result = self:voicemail_play(caller, tostring(parameters[3]) .. '-' .. tostring(parameters[4]) .. '-' .. tostring(parameters[5]) .. '-' .. tostring(parameters[6]) .. '-' .. tostring(parameters[7])); elseif fid == "vmtg" then result = self:call_forwarding_toggle(caller, nil, parameters[3]); elseif fid == "acdmtg" then @@ -777,6 +779,18 @@ function Functions.voicemail_check(self, caller, number) end +function Functions.voicemail_play(self, caller, uuid) + require 'dialplan.voicemail'; + + local voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_sip_account_id(caller.auth_account.id); + + if voicemail_account then + local message = voicemail_account:message_play(caller, uuid); + end + + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } +end + function Functions.acd_membership_toggle(self, caller, agent_id, phone_number) -- Find caller's SipAccount -- cgit v1.2.3 From 19b259d1bcba979b6af0b494029ed8be547afa45 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 28 Mar 2013 09:12:47 +0100 Subject: options menu added --- misc/freeswitch/scripts/dialplan/voicemail.lua | 72 +++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 6 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index eaa8064..bdbb223 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -109,6 +109,12 @@ function Voicemail.settings_get(self, id) end +function Voicemail.find_message_by_uuid(self, uuid) + local sql_query = 'SELECT * FROM `voicemail_msgs` WHERE `uuid` = ' .. self.database:escape(uuid, '"') .. ' LIMIT 1'; + return self.database:query_return_first(sql_query); +end + + function Voicemail.messages_get(self, status) local sql_query = 'SELECT * FROM `voicemail_msgs` WHERE `username` = ' .. self.database:escape(self.name, '"'); @@ -289,12 +295,6 @@ function Voicemail.menu_messages(self, folder, messages) end -function Voicemail.menu_options(self) - self.log:info('VOICEMAIL_OPTIONS_MENU'); - self.caller:send_display('Voicemail options'); -end - - function Voicemail.message_delete(self, message) self.log:debug('VOICEMAIL_MESSAGE_DELETE - message: ', message.uuid); require 'common.fapi'; @@ -372,3 +372,63 @@ function Voicemail.trigger_notification(self, caller) require 'common.fapi'; return common.fapi.FApi:new():execute('luarun', command); end + + +function Voicemail.message_play(self, caller, uuid) + local message = self:find_message_by_uuid(uuid); + + if message and message.file_path then + if not caller:answered() then + caller:answer(); + caller:sleep(1000); + end + caller:send_display(message.cid_name .. ' ' .. message.cid_number); + caller:playback(message.file_path); + end + + return message; +end + + +function Voicemail.menu_options(self) + self.log:info('VOICEMAIL_OPTIONS_MENU'); + self.caller:send_display('Voicemail options'); + + local menu = { + { key = '1', method = self.greeting_record, parameters = { self } }, + { key = '2', method = self.greeting_choose, parameters = { self } }, + { key = '3', method = self.name_record, parameters = { self } }, + { key = '4', method = self.pin_change, parameters = { self } }, + { key = self.settings.key_terminator, exit = true }, + { key = '', exit = true }, + }; + + while true do + local digits, key = self.ivr:ivr_phrase('voicemail_config_menu', menu); + self.log:debug('VOICEMAIL_MAIN_MENU - digit: ', digits); + if key.exit then + break; + end + + key.method(unpack(key.parameters)); + end +end + +function Voicemail.greeting_record(self) + self.log:info('VOICEMAIL_GREETING_RECORD'); +end + +function Voicemail.greeting_choose(self) + self.log:info('VOICEMAIL_GREETING_CHOSE'); + +end + +function Voicemail.name_record(self) + self.log:info('VOICEMAIL_NAME_RECORD'); +end + +function Voicemail.pin_change(self) + self.log:info('VOICEMAIL_PIN_CHANGE'); + + +end -- cgit v1.2.3 From cd91f754501e2c29348276b975462411fe170ba9 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 28 Mar 2013 10:09:44 +0100 Subject: consistent variable naming --- misc/freeswitch/scripts/dialplan/ivr.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/ivr.lua b/misc/freeswitch/scripts/dialplan/ivr.lua index 2a16e3b..e6ddd58 100644 --- a/misc/freeswitch/scripts/dialplan/ivr.lua +++ b/misc/freeswitch/scripts/dialplan/ivr.lua @@ -79,16 +79,16 @@ function Ivr.ivr_phrase_dtmf(self, dtmf) end -function Ivr.read_phrase(self, phrase, phrase_data, max_keys, min_keys, timeout, enter_key) +function Ivr.read_phrase(self, phrase, phrase_data, max_keys, min_keys, timeout, key_terminator) self.max_keys = max_keys or 64; self.min_keys = min_keys or 1; - self.enter_key = enter_key or '#'; + self.key_terminator = key_terminator or '#'; self.digits = ''; self.exit = false; timeout = timeout or 30; global_callback:callback('dtmf', 'ivr_read_phrase', self.read_phrase_dtmf, self); - local continue = self:ivr_break() or self.caller.session:sayPhrase(phrase, phrase_data or enter_key or ''); + local continue = self:ivr_break() or self.caller.session:sayPhrase(phrase, phrase_data or key_terminator or ''); continue = self:ivr_break() or self.caller:sleep(timeout * 1000); global_callback:callback_unset('dtmf', 'ivr_read_phrase'); @@ -101,7 +101,7 @@ function Ivr.read_phrase_dtmf(self, dtmf) return nil; end - if self.enter_key == dtmf.digit then + if self.key_terminator == dtmf.digit then self.exit = true; return false; end @@ -110,14 +110,15 @@ function Ivr.read_phrase_dtmf(self, dtmf) end -function Ivr.check_pin(self, phrase_enter, phrase_incorrect, pin, pin_timeout, pin_repeat, key_enter) +function Ivr.check_pin(self, phrase_enter, phrase_incorrect, pin, pin_timeout, pin_repeat, key_terminator) if not pin then return nil; end + self.exit = false; pin_timeout = pin_timeout or 30; pin_repeat = pin_repeat or 3; - key_enter = key_enter or '#'; + key_terminator = key_terminator or '#'; local digits = ''; for i = 1, pin_repeat do @@ -131,7 +132,7 @@ function Ivr.check_pin(self, phrase_enter, phrase_incorrect, pin, pin_timeout, p break; end self.caller:send_display('Enter PIN'); - digits = ivr:read_phrase(phrase_enter, nil, 0, pin:len() + 1, pin_timeout, key_enter); + digits = ivr:read_phrase(phrase_enter, nil, 0, pin:len() + 1, pin_timeout, key_terminator); end if digits ~= pin then -- cgit v1.2.3 From 5f403c5ac7f029001cec5f2a533e213865834b3b Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 28 Mar 2013 10:10:13 +0100 Subject: unset callback fixed --- misc/freeswitch/scripts/dialplan/callback.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/callback.lua b/misc/freeswitch/scripts/dialplan/callback.lua index f6fd48e..ce1068c 100644 --- a/misc/freeswitch/scripts/dialplan/callback.lua +++ b/misc/freeswitch/scripts/dialplan/callback.lua @@ -46,7 +46,7 @@ end function Callback.callback_unset(self, class, identifier, callback_session) - local session_record = self.sessions[tostring(callback_session or self.session)]; + local session_record = self.sessions[common.str.to_i(callback_session or self.session)]; if not session_record then return false; end -- cgit v1.2.3 From b1c47ccb599044130cdff3b32bc7bc431815636a Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 28 Mar 2013 14:24:53 +0100 Subject: voicemail menu added --- misc/freeswitch/scripts/dialplan/voicemail.lua | 61 +++++++++++++------------- 1 file changed, 30 insertions(+), 31 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index bdbb223..e955101 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -134,41 +134,17 @@ function Voicemail.messages_get(self, status) end -function Voicemail.check_pin(self, pin) - self.caller:answer(); - self.caller:sleep(1000); - - require 'dialplan.ivr'; - local ivr = dialplan.ivr.Ivr:new{ caller = self.caller, log = self.log }; - - local digits = ''; - for i = 1, 3 do - if digits == pin then - self.caller:send_display('PIN: OK'); - break - elseif digits ~= "" then - self.caller:send_display('PIN: wrong'); - end - self.caller:send_display('Enter PIN'); - digits = ivr:read_phrase('voicemail_enter_pass', nil, self.settings.pin_length_min, self.settings.pin_length_max, self.settings.pin_timeout, self.settings.terminator_key); - end - - if digits ~= pin then - return false - end - - return true; -end - - function Voicemail.menu_main(self, caller, authorized) + -- authorized = false; + self.settings.pin = '1234'; + self.caller = caller; require 'dialplan.ivr'; self.ivr = dialplan.ivr.Ivr:new{ caller = self.caller, log = self.log }; if not authorized then - if common.str.blank(self.pin) then + if common.str.blank(self.settings.pin) then self.log:notice('VOICEMAIL_MAIN_MENU - unaunthorized, no PIN, ', self.class, '=', self.id, '/', self.uuid, '|', self.name); return { continue = false, code = 500, phrase = 'Unauthorized', no_cdr = true } end @@ -176,7 +152,7 @@ function Voicemail.menu_main(self, caller, authorized) self.caller:answer(); self.caller:sleep(1000); - if not self.ivr:check_pin('voicemail_enter_pass', 'voicemail_fail_auth', self.pin) then + if not self.ivr:check_pin('voicemail_enter_pass', 'voicemail_fail_auth', self.settings.pin) then self.log:notice('VOICEMAIL_MAIN_MENU - wrong PIN, ', self.class, '=', self.id, '/', self.uuid, '|', self.name); caller.session:sayPhrase('voicemail_goodbye'); return { continue = false, code = 500, phrase = 'Unauthorized', no_cdr = true } @@ -414,21 +390,44 @@ function Voicemail.menu_options(self) end end + function Voicemail.greeting_record(self) self.log:info('VOICEMAIL_GREETING_RECORD'); end + function Voicemail.greeting_choose(self) self.log:info('VOICEMAIL_GREETING_CHOSE'); end + function Voicemail.name_record(self) self.log:info('VOICEMAIL_NAME_RECORD'); end + function Voicemail.pin_change(self) - self.log:info('VOICEMAIL_PIN_CHANGE'); + self.log:info('VOICEMAIL_PIN_CHANGE - lenght: ', self.settings.pin_length_min, '-', self.settings.pin_length_max); - + if not common.str.blank(self.settings.pin) then + if not self.ivr:check_pin('voicemail_enter_pass', 'voicemail_fail_auth', self.settings.pin) then + self.log:notice('VOICEMAIL_PIN_CHANGE - wrong old PIN, ', self.class, '=', self.id, '/', self.uuid, '|', self.name); + return false; + end + end + + local digits = ''; + for i = 1, 3 do + if digits:len() < self.settings.pin_length_min then + self.caller:send_display('PIN too short'); + elseif digits:len() > self.settings.pin_length_max then + self.caller:send_display('PIN too long'); + else + self.caller:send_display('PIN: OK'); + break + end + self.caller:send_display('Enter new PIN'); + digits = self.ivr:read_phrase('voicemail_enter_pass', nil, self.settings.pin_length_max, self.settings.pin_length_min, self.settings.pin_timeout, self.settings.terminator_key); + end end -- cgit v1.2.3 From edf06bf6f7d4f20d5a9145a5bbf8db409fe6ab1b Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 2 Apr 2013 13:14:07 +0200 Subject: pin changing dialog added --- misc/freeswitch/scripts/dialplan/voicemail.lua | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index e955101..e5579f8 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -135,9 +135,6 @@ end function Voicemail.menu_main(self, caller, authorized) - -- authorized = false; - self.settings.pin = '1234'; - self.caller = caller; require 'dialplan.ivr'; @@ -430,4 +427,25 @@ function Voicemail.pin_change(self) self.caller:send_display('Enter new PIN'); digits = self.ivr:read_phrase('voicemail_enter_pass', nil, self.settings.pin_length_max, self.settings.pin_length_min, self.settings.pin_timeout, self.settings.terminator_key); end + + if digits:len() < self.settings.pin_length_min or digits:len() > self.settings.pin_length_max then + self.caller:send_display('PIN not changed'); + return false; + end + + local sql_query = 'UPDATE `voicemail_settings` \ + SET `value` = ' .. self.database:escape(digits, '"') .. ', `class_type` = "String", `updated_at` = NOW() \ + WHERE `name`="pin" AND `voicemail_account_id` = ' .. self.id; + if not self.settings.pin then + sql_query = 'INSERT INTO `voicemail_settings` \ + (`voicemail_account_id`, `name`, `value`, `class_type`, `description`, `created_at`, `updated_at`) \ + VALUES (' .. self.id .. ', "pin", "' .. digits .. '", "String", "Voicemail PIN", NOW(), NOW())'; + end + + if self.database:query(sql_query) then + self.settings.pin = digits; + self.caller:send_display('PIN changed'); + self.caller.session:sayPhrase('voicemail_change_pass_success'); + return true; + end end -- cgit v1.2.3 From 1b5cd43bcabd516f98117a16d44d2a7f1bf70600 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 8 Apr 2013 15:36:30 +0200 Subject: dtmf test --- misc/freeswitch/scripts/dialplan/functions.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index ce99953..2edc131 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -116,6 +116,8 @@ function Functions.dialplan_function(self, caller, dialed_number) result = self:call_parking_inout(caller, parameters[3], parameters[4]); elseif fid == "cpai" then result = self:call_parking_inout_index(caller, parameters[3]); + elseif fid == "test" then + result = self:test(caller, parameters[3]); end return result or { continue = false, code = 505, phrase = 'Error executing function', no_cdr = true }; @@ -912,3 +914,20 @@ function Functions.call_parking_inout_index(self, caller, stall_index) return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end + + +function Functions.test(self, caller, name) + if tostring(name) == 'dtmf' then + while caller:ready() do + local digits = caller.session:read(1, 1, '', 30000, ''); + if digits == "" then + break; + end + caller:send_display('DTMF: ', digits); + caller.session:say(digits, "en", "number", "pronounced"); + self.log:devel('DTMF: ', digits); + end + end + + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } +end -- cgit v1.2.3 From 8d8bf48aa95f979da8f67d274b66d5c207b8b667 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 8 Apr 2013 16:01:52 +0200 Subject: dtmf test --- misc/freeswitch/scripts/dialplan/functions.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index 2edc131..0c30b86 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -918,14 +918,21 @@ end function Functions.test(self, caller, name) if tostring(name) == 'dtmf' then + local digits = ''; while caller:ready() do - local digits = caller.session:read(1, 1, '', 30000, ''); - if digits == "" then - break; + if digits == '' then + caller:playback('ivr/ivr-love_those_touch_tones.wav'); end - caller:send_display('DTMF: ', digits); - caller.session:say(digits, "en", "number", "pronounced"); + digits = caller.session:read(1, 1, '', 5000, ''); self.log:devel('DTMF: ', digits); + caller:send_display('DTMF: ', digits); + if digits == '*' then + caller:playback('digits/star.wav'); + elseif digits == '#' then + caller:playback('digits/pound.wav'); + elseif digits ~= '' then + caller.session:say(digits, "en", "number", "pronounced"); + end end end -- cgit v1.2.3 From d6adfbba723de9732f24efd71f80c422ae1a40f0 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 8 Apr 2013 16:05:16 +0200 Subject: dtmf test --- misc/freeswitch/scripts/dialplan/functions.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index 0c30b86..7519ff9 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -918,13 +918,15 @@ end function Functions.test(self, caller, name) if tostring(name) == 'dtmf' then + self.log:info('FUNCTION_TEST_DTMF'); local digits = ''; + caller:answer(); while caller:ready() do if digits == '' then caller:playback('ivr/ivr-love_those_touch_tones.wav'); end digits = caller.session:read(1, 1, '', 5000, ''); - self.log:devel('DTMF: ', digits); + self.log:info('DTMF: ', digits); caller:send_display('DTMF: ', digits); if digits == '*' then caller:playback('digits/star.wav'); -- cgit v1.2.3 From 58741154e0147ee878b093fc25051ef9d1b93e4a Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 9 Apr 2013 13:25:52 +0200 Subject: max_depth added --- misc/freeswitch/scripts/common/array.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/common/array.lua b/misc/freeswitch/scripts/common/array.lua index b1b7a71..c3cabec 100644 --- a/misc/freeswitch/scripts/common/array.lua +++ b/misc/freeswitch/scripts/common/array.lua @@ -4,6 +4,8 @@ module(...,package.seeall) +MAX_JSON_DEPTH = 100; + function try(array, arguments) if type(arguments) ~= 'string' or type(array) ~= 'table' then return nil; @@ -79,12 +81,19 @@ function keys_to_s(array, separator, prefix, suffix) end -- convert to JSON -function to_json(array) +function to_json(array, max_depth) + max_depth = tonumber(max_depth) or MAX_JSON_DEPTH; + max_depth = max_depth - 1; + + if max_depth <= 0 then + return 'null'; + end + require 'common.str'; local buffer = '{'; for key, value in pairs(array) do if type(value) == 'table' then - buffer = buffer .. '"' .. key .. '":' .. to_json(value) .. ','; + buffer = buffer .. '"' .. key .. '":' .. to_json(value, max_depth) .. ','; else buffer = buffer .. '"' .. key .. '":' .. common.str.to_json(value) .. ','; end -- cgit v1.2.3 From fb438bf1a0c62e89b5b8a42f8668d3f510533123 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 9 Apr 2013 13:26:18 +0200 Subject: max_depth added --- misc/freeswitch/scripts/common/log.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/common/log.lua b/misc/freeswitch/scripts/common/log.lua index b9893ac..7201d2a 100644 --- a/misc/freeswitch/scripts/common/log.lua +++ b/misc/freeswitch/scripts/common/log.lua @@ -38,7 +38,7 @@ function Log.message(self, log_level, message_arguments ) if type(index) == 'number' then if type(value) == 'table' then require 'common.array'; - message = message .. common.array.to_json(value); + message = message .. common.array.to_json(value, 3); else message = message .. tostring(value); end -- cgit v1.2.3 From 1a56b27c66cb1580313045d87a59ceb4f849038b Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 9 Apr 2013 13:26:42 +0200 Subject: presence_update removed --- misc/freeswitch/scripts/event/presence_update.lua | 9 --------- 1 file changed, 9 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/event/presence_update.lua b/misc/freeswitch/scripts/event/presence_update.lua index f9d8ee7..fd85f03 100644 --- a/misc/freeswitch/scripts/event/presence_update.lua +++ b/misc/freeswitch/scripts/event/presence_update.lua @@ -95,9 +95,6 @@ function PresenceUpdate.sofia_register(self, event) local timestamp = event:getHeader('Event-Date-Timestamp'); local sip_account = self:retrieve_sip_account(account, account); - if sip_account and common.str.to_b(self.config.trigger.sip_account_register) then - self:trigger_rails(sip_account, 'register', timestamp, account) - end self.log:debug('[', account, '] PRESENCE_UPDATE - flushing account cache on register'); self.presence_accounts[account] = nil; @@ -109,9 +106,6 @@ function PresenceUpdate.sofia_ungerister(self, event) local timestamp = event:getHeader('Event-Date-Timestamp'); local sip_account = self:retrieve_sip_account(account, account); - if sip_account and common.str.to_b(self.config.trigger.sip_account_unregister) then - self:trigger_rails(sip_account, 'unregister', timestamp, account) - end self.log:debug('[', account, '] PRESENCE_UPDATE - flushing account cache on unregister'); self.presence_accounts[account] = nil; @@ -242,9 +236,6 @@ function PresenceUpdate.sip_account(self, inbound, account, domain, status, uuid uuid = uuid }:set(status_map[status] or 'terminated', caller_id); - if common.str.to_b(self.config.trigger.sip_account_presence) then - self:trigger_rails(sip_account, status_map[status] or 'terminated', timestamp, uuid); - end end -- cgit v1.2.3 From 4fccfd605fc705f8785568fc393be1207b51ecc5 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 11 Apr 2013 09:33:28 +0200 Subject: defaults added --- misc/freeswitch/scripts/configuration.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index c17f8a4..b23f76a 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -289,8 +289,9 @@ function conf_event_socket(database) require 'configuration.simple_xml' local xml = configuration.simple_xml.SimpleXml:new(); + local settings = { password = 'ClueCon', ['listen-ip'] = '127.0.0.1', ['listen-port'] = '80212' }; require 'common.configuration_table'; - local settings = common.configuration_table.get(database, 'event_socket', 'settings'); + settings = common.configuration_table.get(database, 'event_socket', 'settings', settings) or settings; XML_STRING = xml:element{ 'document', -- cgit v1.2.3 From a1569d8a2c8ea1716aa7ec72954407e422004c90 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 11 Apr 2013 10:46:44 +0200 Subject: message_too_short macro added --- misc/freeswitch/conf/freeswitch.xml | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml index 7283211..3190577 100644 --- a/misc/freeswitch/conf/freeswitch.xml +++ b/misc/freeswitch/conf/freeswitch.xml @@ -915,6 +915,13 @@ + + + + + + + -- cgit v1.2.3 From f89c54f914741e2aaa6d4910cd33eaa2bd7fedf3 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 11 Apr 2013 10:47:24 +0200 Subject: pass number as greeting --- misc/freeswitch/scripts/dialplan/dialplan.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 31b88fd..a8054ff 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -595,8 +595,6 @@ function Dialplan.voicemail(self, destination) local voicemail_account = nil; if common.str.to_i(destination.id) > 0 then voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database, domain = self.domain }:find_by_id(destination.id); - elseif not common.str.blank(destination.number) then - voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database, domain = self.domain }:find_by_number(destination.number); elseif self.caller.auth_account and self.caller.auth_account.class == 'sipaccount' then voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database, domain = self.domain }:find_by_sip_account_id(self.caller.auth_account.id); elseif self.caller.forwarding_number then @@ -608,7 +606,7 @@ function Dialplan.voicemail(self, destination) return { continue = false, code = 404, phrase = 'Mailbox not found' } end - voicemail_account:leave(self.caller, self.caller.forwarding_number); + voicemail_account:leave(self.caller, destination.number, self.caller.forwarding_number); if self.caller:to_s("voicemail_message_len") == '' then self.log:info('VOICEMAIL - no message saved'); -- cgit v1.2.3 From 720a55fd2540e74a84ef2113ad9475bb56f364c0 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 11 Apr 2013 10:49:30 +0200 Subject: beep added --- misc/freeswitch/scripts/dialplan/ivr.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/ivr.lua b/misc/freeswitch/scripts/dialplan/ivr.lua index e6ddd58..6b230dc 100644 --- a/misc/freeswitch/scripts/dialplan/ivr.lua +++ b/misc/freeswitch/scripts/dialplan/ivr.lua @@ -146,16 +146,23 @@ function Ivr.check_pin(self, phrase_enter, phrase_incorrect, pin, pin_timeout, p end -function Ivr.record(self, file_name, phrase_record, phrase_too_short, record_length_max, record_length_min, record_repeat, silence_level, silence_lenght_abort) +function Ivr.record(self, file_name, beep, phrase_record, phrase_too_short, record_length_max, record_length_min, record_repeat, silence_level, silence_lenght_abort) local duration = nil; for index=1, record_repeat do if (duration and duration >= record_length_min) or not self.caller:ready() then break; elseif duration then self.caller:send_display('Recording too short'); - self.caller.session:sayPhrase(phrase_too_short); + if phrase_too_short then + self.caller.session:sayPhrase(phrase_too_short); + end + end + if phrase_record then + self.caller.session:sayPhrase(phrase_record); + end + if beep then + self.caller:playback(beep); end - self.caller.session:sayPhrase(phrase_record); self.caller:send_display('Recording...'); local result = self.caller.session:recordFile(file_name, record_length_max, silence_level, silence_lenght_abort); duration = self.caller:to_i('record_seconds'); -- cgit v1.2.3 From 145d774adece71282020603b699ab684537cc1b3 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 11 Apr 2013 10:50:04 +0200 Subject: greeting added --- misc/freeswitch/scripts/dialplan/voicemail.lua | 50 +++++++++++++++++++++----- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index e5579f8..6418c46 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -288,28 +288,40 @@ function Voicemail.message_save(self, message) end -function Voicemail.leave(self, caller, greeting) - local forwarding_number = caller.forwarding_number; - self.log:info('VOICEMAIL_LEAVE - voicemail_account=', self.record.id, '/', self.record.uuid, '|', self.record.name, ', forwarding_number: ', forwarding_number); +function Voicemail.leave(self, caller, greeting, number) + self.log:info('VOICEMAIL_LEAVE - voicemail_account=', self.record.id, '/', self.record.uuid, '|', self.record.name, ', forwarding_number: ', number, ', greeting: ', greeting); - caller:set_callee_id(forwarding_number, common.array.try(caller, 'auth_account.caller_name') or common.array.try(caller, 'auth_account.name')); + caller:set_callee_id(number, common.array.try(caller, 'auth_account.caller_name') or common.array.try(caller, 'auth_account.name')); caller:answer(); caller:send_display(common.array.try(caller, 'auth_account.caller_name') or common.array.try(caller, 'auth_account.name')); caller:sleep(1000); - if not common.str.blank(forwarding_number) then - caller.session:sayPhrase('voicemail_play_greeting', (tostring(forwarding_number):gsub('[%D]', ''))); + local greeting_file = nil; + if not common.str.blank(greeting) then + greeting_file = self:greeting_get(greeting, caller.auth_account.owner.class, caller.auth_account.owner.id) + end + + if not common.str.blank(greeting_file) then + self.log:debug('VOICEMAIL_LEAVE greeting_file: ', greeting_file); + caller:playback(greeting_file); + elseif not common.str.blank(number) then + caller.session:sayPhrase('voicemail_play_greeting', (tostring(number):gsub('[%D]', ''))); end local record_file_name = self.settings.record_file_path ..self.settings.record_file_prefix .. caller.uuid .. self.settings.record_file_suffix; self.log:info('VOICEMAIL_LEAVE - recording to file: ', tostring(record_file_name)); + local voicemail_record_message = nil; + if common.str.blank(greeting_file) then + voicemail_record_message = 'voicemail_record_message'; + end + require 'dialplan.ivr'; local ivr = dialplan.ivr.Ivr:new{ caller = caller, log = self.log }; - local duration = ivr:record( - record_file_name, - 'voicemail_record_message', + record_file_name, + self.settings.beep, + voicemail_record_message, 'voicemail_message_too_short', self.settings.record_length_max, self.settings.record_length_min, @@ -363,6 +375,26 @@ function Voicemail.message_play(self, caller, uuid) end +function Voicemail.greeting_get(self, name, owner_type, owner_id, file_types) + local store_dir = '/var/opt/gemeinschaft/generic_files/'; + + file_types = file_types or {'audio/x-wav'} + local sql_query = 'SELECT * FROM `generic_files` \ + WHERE `name` = ' .. self.database:escape(name, '"') .. ' \ + AND `owner_type` = ' .. self.database:escape(owner_type, '"') .. ' \ + AND `owner_id` = ' .. self.database:escape(owner_id, '"') .. ' \ + AND `file_type` IN ("' .. table.concat(file_types, '","') .. '") LIMIT 1'; + + local greeting = self.database:query_return_first(sql_query); + + if not greeting or common.str.blank(greeting.file) then + return nil; + end + + return store_dir .. greeting.id .. '/' .. greeting.file; +end + + function Voicemail.menu_options(self) self.log:info('VOICEMAIL_OPTIONS_MENU'); self.caller:send_display('Voicemail options'); -- cgit v1.2.3 From 8d4ad7908c78357845b82ad9fb298cf1f9612093 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 11 Apr 2013 10:57:29 +0200 Subject: port fixed --- misc/freeswitch/scripts/configuration.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index b23f76a..16dbed7 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -289,9 +289,9 @@ function conf_event_socket(database) require 'configuration.simple_xml' local xml = configuration.simple_xml.SimpleXml:new(); - local settings = { password = 'ClueCon', ['listen-ip'] = '127.0.0.1', ['listen-port'] = '80212' }; + local settings = { password = 'ClueCon', ['listen-ip'] = '127.0.0.1', ['listen-port'] = '8021' }; require 'common.configuration_table'; - settings = common.configuration_table.get(database, 'event_socket', 'settings', settings) or settings; + settings = common.configuration_table.get(database, 'event_socket', 'settings', {settings = settings}); XML_STRING = xml:element{ 'document', -- cgit v1.2.3 From 9e571115056c83adf34fcc55089f0c3781d76122 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 12 Apr 2013 11:46:11 +0200 Subject: greeting recording added --- misc/freeswitch/scripts/dialplan/voicemail.lua | 61 ++++++++++++++++++++------ 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index 6418c46..3358d2b 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -32,9 +32,11 @@ DEFAULT_SETTINGS = { notify = true, attachment = true, mark_read = true, - purge = false, + purge = false, + generic_file_path = '/var/opt/gemeinschaft/generic_files/', } + -- create voicemail object function Voicemail.new(self, arg) arg = arg or {} @@ -376,8 +378,6 @@ end function Voicemail.greeting_get(self, name, owner_type, owner_id, file_types) - local store_dir = '/var/opt/gemeinschaft/generic_files/'; - file_types = file_types or {'audio/x-wav'} local sql_query = 'SELECT * FROM `generic_files` \ WHERE `name` = ' .. self.database:escape(name, '"') .. ' \ @@ -391,7 +391,7 @@ function Voicemail.greeting_get(self, name, owner_type, owner_id, file_types) return nil; end - return store_dir .. greeting.id .. '/' .. greeting.file; + return self.settings.generic_file_path .. greeting.id .. '/' .. greeting.file; end @@ -401,9 +401,7 @@ function Voicemail.menu_options(self) local menu = { { key = '1', method = self.greeting_record, parameters = { self } }, - { key = '2', method = self.greeting_choose, parameters = { self } }, - { key = '3', method = self.name_record, parameters = { self } }, - { key = '4', method = self.pin_change, parameters = { self } }, + { key = '3', method = self.pin_change, parameters = { self } }, { key = self.settings.key_terminator, exit = true }, { key = '', exit = true }, }; @@ -422,17 +420,53 @@ end function Voicemail.greeting_record(self) self.log:info('VOICEMAIL_GREETING_RECORD'); -end + local record_file_name = self.settings.record_file_path ..self.settings.record_file_prefix .. self.caller.uuid .. self.settings.record_file_suffix; + + require 'dialplan.ivr'; + local ivr = dialplan.ivr.Ivr:new{ caller = self.caller, log = self.log }; + local duration = ivr:record( + record_file_name, + self.settings.beep, + 'voicemail_record_greeting', + 'voicemail_message_too_short', + self.settings.record_length_max, + 1, + self.settings.record_repeat, + self.settings.silence_level, + self.settings.silence_lenght_abort); -function Voicemail.greeting_choose(self) - self.log:info('VOICEMAIL_GREETING_CHOSE'); + if duration >= 0 then + self.caller:playback(record_file_name); + end -end + if duration >= 1 then + local name = 'greeting_' .. os.time(); + local file_name = name .. self.settings.record_file_suffix + + local generic_file_record = { + name = name, + file = file_name, + file_type = 'audio/x-wav', + category = 'greeting', + owner_id = self.record.voicemail_accountable_id, + owner_type = self.record.voicemail_accountable_type, + updated_at = { 'NOW()', raw = true }, + created_at = { 'NOW()', raw = true }, + }; + if self.database:insert_or_update('generic_files', generic_file_record) then + local file_id = self.database:last_insert_id(); -function Voicemail.name_record(self) - self.log:info('VOICEMAIL_NAME_RECORD'); + local destination_directory = self.settings.generic_file_path .. file_id; + self.log:info('VOICEMAIL_GREETING_RECORD recorded greeting - id: ', file_id, ', file: ', destination_directory .. '/' .. file_name, ', duration: ', duration); + os.execute('mkdir ' .. destination_directory); + local result, error_string = os.rename(record_file_name, destination_directory .. '/' .. file_name); + if not result then + self.log:error('VOICEMAIL_GREETING_RECORD - ', error_string); + end + end + end end @@ -481,3 +515,4 @@ function Voicemail.pin_change(self) return true; end end + -- cgit v1.2.3 From f59241b377665c3b902aeadf70dddc495a708199 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 12 Apr 2013 11:46:36 +0200 Subject: options menu phrases --- misc/freeswitch/conf/freeswitch.xml | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml index 3190577..0a6538e 100644 --- a/misc/freeswitch/conf/freeswitch.xml +++ b/misc/freeswitch/conf/freeswitch.xml @@ -160,27 +160,19 @@ - + - - - - - - - - - + - + @@ -758,27 +750,19 @@ - + - - - - - - - - - + - + -- cgit v1.2.3 From d3747bd38f106669d7b57a9c9b64d99b98c6aa59 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 16 Apr 2013 15:14:33 +0200 Subject: pass caller record to call forwarding class --- misc/freeswitch/scripts/dialplan/dialplan.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index a8054ff..3f84007 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -248,7 +248,7 @@ function Dialplan.destination_new(self, arg) destination.account = self:object_find{ class = destination.type, id = destination.id}; if self.caller then require 'common.call_forwarding'; - local call_forwarding_class = common.call_forwarding.CallForwarding:new{ log = self.log, database = self.database } + local call_forwarding_class = common.call_forwarding.CallForwarding:new{ log = self.log, database = self.database, caller = self.caller } destination.call_forwarding = call_forwarding_class:list_by_owner(destination.id, destination.type, self.caller.caller_phone_numbers); for service, call_forwarding_entry in pairs(call_forwarding_class:list_by_owner(destination.phone_number.id, destination.phone_number.class, self.caller.caller_phone_numbers)) do destination.call_forwarding[service] = call_forwarding_entry; -- cgit v1.2.3 From a1eb4fa1f6460dc2c56a5b8799cc6713f1379878 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 16 Apr 2013 15:15:21 +0200 Subject: call forwarding attributes added --- misc/freeswitch/scripts/common/call_forwarding.lua | 35 +++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/common/call_forwarding.lua b/misc/freeswitch/scripts/common/call_forwarding.lua index 3429dc9..9556de3 100644 --- a/misc/freeswitch/scripts/common/call_forwarding.lua +++ b/misc/freeswitch/scripts/common/call_forwarding.lua @@ -17,6 +17,7 @@ function CallForwarding.new(self, arg, object) self.record = arg.record; self.domain = arg.domain; self.parent = arg.parent; + self.caller = arg.caller; return object; end @@ -70,12 +71,38 @@ function CallForwarding.list_by_owner(self, call_forwardable_id, call_forwardabl 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] ); + local variable_name, pattern = common.str.partition(sources[source_index], '!=') + local invert = variable_name ~= nil; + if not variable_name then + variable_name, pattern = common.str.partition(sources[source_index], '=') + end + if variable_name and self.caller then + local search_string = tostring(common.array.try(self.caller, variable_name)); + local success, result = pcall(string.find, pattern, '^%d+-%d+$'); + + if success and result and tonumber(search_string) then + local min, max = common.str.partition(pattern, '-') + entry_match = tonumber(search_string) >= tonumber(min) and tonumber(search_string) <= tonumber(max); + else + local success, result = pcall(string.find, search_string, pattern); + entry_match = common.str.to_b(result); + end + if invert then + entry_match = not entry_match; + end + + if entry_match == false then break; end + self.log:debug('CALL_FORWARDING ', forwarding_entry.service, ' - element match: ', entry_match, ', variable: ', variable_name, ' = ', pattern, ' ~ ', search_string); + else + 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 ', forwarding_entry.service, ' - source match: ', sources[source_index], ' ~ ', caller_ids[caller_id_index] ); + break; + end + end end end end -- cgit v1.2.3 From 34ac090e79942dd8d9b65eb7f4b7f4873135e221 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 17 Apr 2013 16:50:47 +0200 Subject: numbers method added --- misc/freeswitch/scripts/dialplan/phone_book.lua | 29 +++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/phone_book.lua b/misc/freeswitch/scripts/dialplan/phone_book.lua index 6653789..50972ac 100644 --- a/misc/freeswitch/scripts/dialplan/phone_book.lua +++ b/misc/freeswitch/scripts/dialplan/phone_book.lua @@ -19,7 +19,7 @@ function PhoneBook.new(self, arg) end -function PhoneBook.find_entry_by_number_user_tenant(self, numbers, user_id, tenant_id) +function PhoneBook.find_entry_by_number_user_tenant(self, numbers, user_id, tenant_id, name) user_id = tonumber(user_id) or 0; tenant_id = tonumber(tenant_id) or 0; @@ -37,7 +37,7 @@ function PhoneBook.find_entry_by_number_user_tenant(self, numbers, user_id, tena `c`.`name` AS `phone_book_name`, \ `d`.`bellcore_id` \ FROM `phone_numbers` `a` \ - JOIN `phone_book_entries` `b` ON `a`.`phone_numberable_id` = `b`.`id` AND `a`.`phone_numberable_type` = "PhoneBookENtry" \ + JOIN `phone_book_entries` `b` ON `a`.`phone_numberable_id` = `b`.`id` AND `a`.`phone_numberable_type` = "PhoneBookEntry" \ JOIN `phone_books` `c` ON `b`.`phone_book_id` = `c`.`id` \ LEFT JOIN `ringtones` `d` ON `a`.`id` = `d`.`ringtoneable_id` AND `d`.`ringtoneable_type` = "PhoneNumber" \ WHERE ((`c`.`phone_bookable_type` = "User" AND `c`.`phone_bookable_id` = ' .. user_id .. ') \ @@ -45,8 +45,13 @@ function PhoneBook.find_entry_by_number_user_tenant(self, numbers, user_id, tena AND `a`.`number` IN (' .. numbers_sql .. ') \ AND `a`.`state` = "active" \ AND `b`.`state` = "active" \ - AND `c`.`state` = "active" \ - ORDER BY `c`.`phone_bookable_type` DESC LIMIT 1'; + AND `c`.`state` = "active"'; + + if name then + sql_query = sql_query ..' AND `a`.`name` = ' .. self.database:escape(name, '"'); + end + + sql_query = sql_query ..' ORDER BY `c`.`phone_bookable_type` DESC LIMIT 1'; local phone_book_entry = nil; @@ -61,3 +66,19 @@ function PhoneBook.find_entry_by_number_user_tenant(self, numbers, user_id, tena return phone_book_entry; end + + +function PhoneBook.numbers(self, phone_book_entry_id, name, not_name) + local sql_query = 'SELECT * FROM `phone_numbers` \ + WHERE `phone_numberable_id` = ' .. phone_book_entry_id .. ' AND `phone_numberable_type` = "PhoneBookEntry"'; + + if name then + sql_query = sql_query ..' AND `name` = ' .. self.database:escape(name, '"'); + end + + if not_name then + sql_query = sql_query ..' AND `name` != ' .. self.database:escape(not_name, '"'); + end + + return self.database:query_return_all(sql_query); +end -- cgit v1.2.3 From ccb2ccc255218ec44a1694431cfbccd6308be6d5 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 17 Apr 2013 16:51:30 +0200 Subject: router function speeddial added --- misc/freeswitch/scripts/dialplan/router.lua | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 322c748..d6d00de 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -149,6 +149,14 @@ function Router.route_match(self, route) elseif command == 'hdr' then local search_string = self.caller:to_s('sip_h_' .. variable_name); result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement)); + elseif command == 'fun' then + if self['fun_' .. variable_name] then + local arguments = {}; + for index, argument in ipairs(common.str.to_a(element.replacement, ',')) do + table.insert(arguments, common.array.expand_variables(argument, destination, self.variables)); + end + result, replacement = self['fun_' .. variable_name](self, unpack(arguments)) + end end end @@ -214,3 +222,32 @@ function Router.route_run(self, table_name, find_first) return routes; end end + + +function Router.fun_speeddial(self, number, name) + local owner_class = common.array.try(self, 'caller.auth_account.owner.class'); + local owner_id = common.array.try(self, 'caller.auth_account.owner.id') + + local user_id = nil; + local tenant_id = nil; + + if tostring(owner_class) == 'user' then + user_id = owner_id; + tenant_id = common.array.try(self, 'caller.auth_account.owner.record.current_nenant_id'); + elseif + tostring(owner_class) == 'tenant' then + tenant_id = owner_id; + end + + require 'dialplan.phone_book' + local phone_book_class = dialplan.phone_book.PhoneBook:new{ log = self.log, database = self.database } + local phone_book_entry = phone_book_class:find_entry_by_number_user_tenant({number}, user_id, tenant_id, 'speeddial'); + + if phone_book_entry then + local phone_numbers = phone_book_class:numbers(phone_book_entry.id, name, 'speeddial'); + for index, phone_number in ipairs(phone_numbers) do + self.log:info('SPEEDDIAL: ', number, ' => ', phone_number.number) + return true, phone_number.number; + end + end +end -- cgit v1.2.3 From 75047661f380c62dae7bab4942c9e8a8cf39501a Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 18 Apr 2013 08:30:06 +0200 Subject: logging --- misc/freeswitch/scripts/dialplan/router.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index d6d00de..dde527c 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -156,6 +156,13 @@ function Router.route_match(self, route) table.insert(arguments, common.array.expand_variables(argument, destination, self.variables)); end result, replacement = self['fun_' .. variable_name](self, unpack(arguments)) + if self.log_details or true then + if result then + self.log:debug('ELEMENT_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); + else + self.log:debug('ELEMENT_NO_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', tostring(replacement)); + end + end end end end @@ -233,7 +240,7 @@ function Router.fun_speeddial(self, number, name) if tostring(owner_class) == 'user' then user_id = owner_id; - tenant_id = common.array.try(self, 'caller.auth_account.owner.record.current_nenant_id'); + tenant_id = common.array.try(self, 'caller.auth_account.owner.record.current_tenant_id'); elseif tostring(owner_class) == 'tenant' then tenant_id = owner_id; @@ -243,10 +250,12 @@ function Router.fun_speeddial(self, number, name) local phone_book_class = dialplan.phone_book.PhoneBook:new{ log = self.log, database = self.database } local phone_book_entry = phone_book_class:find_entry_by_number_user_tenant({number}, user_id, tenant_id, 'speeddial'); + self.log:debug('SPEEDDIAL - user=', user_id, ', tenant=', tenant_id, ', entry: "', common.array.try(phone_book_entry, 'phone_book_name'), '" => "', common.array.try(phone_book_entry, 'caller_id_name'), '"'); + if phone_book_entry then local phone_numbers = phone_book_class:numbers(phone_book_entry.id, name, 'speeddial'); for index, phone_number in ipairs(phone_numbers) do - self.log:info('SPEEDDIAL: ', number, ' => ', phone_number.number) + self.log:info('SPEEDDIAL - ', number, ' => ', phone_number.number) return true, phone_number.number; end end -- cgit v1.2.3 From 7804dbb985f25c8bafbcfad1f9345d14a9a6adc3 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 23 Apr 2013 22:04:07 +0200 Subject: elements loading order fixed --- misc/freeswitch/scripts/dialplan/router.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index dde527c..10551f1 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -38,15 +38,19 @@ function Router.read_table(self, table_name, force_reload) JOIN `route_elements` `b` ON `a`.`id` = `b`.`call_route_id`\ WHERE `a`.`routing_table` = "' .. table_name .. '" \ ORDER BY `a`.`position`, `b`.`position`'; - - local last_id = 0; + + local call_routes = {}; + self.database:query(sql_query, function(route) - if last_id ~= tonumber(route.call_route_id) then - last_id = tonumber(route.call_route_id); - table.insert(routing_table, {id = route.call_route_id, name = route.name, endpoint_type = route.endpoint_type , endpoint_id = route.endpoint_id, elements = {} }); + if call_routes[route.call_route_id] then + call_route = call_routes[route.call_route_id]; + else + call_route = {id = route.call_route_id, name = route.name, endpoint_type = route.endpoint_type , endpoint_id = route.endpoint_id, elements = {} }; + call_routes[route.call_route_id] = call_route; + table.insert(routing_table, call_route); end - table.insert(routing_table[#routing_table].elements, { + table.insert(call_route.elements, { var_in = route.var_in, var_out = route.var_out, pattern = route.pattern, -- cgit v1.2.3 From af21d33a75e856e875f170498ea702b7e9d2e19c Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 6 May 2013 14:23:55 +0200 Subject: start_dtmf only if out-of-band DTMF is absend in SDP description --- misc/freeswitch/scripts/dialplan/sip_call.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 0cde601..f401c5c 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -233,11 +233,19 @@ function SipCall.fork(self, destinations, arg ) end if arg.detect_dtmf_after_bridge_caller and self.caller.auth_account then - session:execute('start_dtmf'); + if not string.match(self.caller:to_s('switch_r_sdp'), '101 telephone%-event') then + self.log:notice('FORK A_LEG inband dtmf detection - channel_uuid: ', session:get_uuid()); + session:execute('start_dtmf'); + end end + if arg.detect_dtmf_after_bridge_callee and destination.type == 'sipaccount' then - session_callee:execute('start_dtmf'); + if not string.match(tostring(session_callee:getVariable('switch_r_sdp')), '101 telephone%-event') then + self.log:notice('FORK B_LEG inband dtmf detection - channel_uuid: ', session_callee:get_uuid()); + session_callee:execute('start_dtmf'); + end end + if arg.bypass_media_network then local callee_uuid = session_callee:get_uuid(); -- cgit v1.2.3 From 7ceae357dc8081afc73f74d6790340fdca3fea4f Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 6 May 2013 14:24:46 +0200 Subject: unset input callback --- misc/freeswitch/scripts/dialplan_default.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan_default.lua b/misc/freeswitch/scripts/dialplan_default.lua index ba51ed3..32789cb 100644 --- a/misc/freeswitch/scripts/dialplan_default.lua +++ b/misc/freeswitch/scripts/dialplan_default.lua @@ -117,6 +117,8 @@ else start_dialplan:run(start_destination); end +start_caller.session:unsetInputCallback(); + -- release database handle if database then database:release(); -- cgit v1.2.3 From f5e9590b7ed69ba5d029d5d8724b7690316df9c9 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 13 May 2013 12:17:21 +0200 Subject: mysql library added --- misc/mon_ami/mysqlr.py | 135 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 misc/mon_ami/mysqlr.py (limited to 'misc') diff --git a/misc/mon_ami/mysqlr.py b/misc/mon_ami/mysqlr.py new file mode 100644 index 0000000..7ddf27a --- /dev/null +++ b/misc/mon_ami/mysqlr.py @@ -0,0 +1,135 @@ +# -*- coding: utf-8 -*- +# MySQL library + +import MySQLdb + +class MySQLR(): + + def __init__(self, database=None, user=None, password='', address='127.0.0.1', port=3306): + self.db_name = database + if (self.db_name == None): + self.db_name = ':memory:' + self.db_conn = None + self.db_cursor = None + self.db_port = int(port) + self.db_address = address + self.db_user = user + self.db_password = password + + def record_factory(self, cursor, row): + record = dict() + for index, column in enumerate(cursor.description): + record[column[0]] = row[index] + return record + + def connect(self, isolation_level = None): + try: + self.db_conn = MySQLdb.connect(host=self.db_address, port=self.db_port, user=self.db_user, passwd=self.db_password, db=self.db_name) + self.db_cursor = self.db_conn.cursor() + except: + return False + + return True + + def disconnect(self): + try: + self.db_nonn.close() + except: + return False + return True + + def execute(self, query, parameters = []): + try: + return self.db_cursor.execute(query, parameters) + except: + return False + + def fetch_row(self): + return self.db_cursor.fetchone() + + def fetch_rows(self): + return self.db_cursor.fetchall() + + def execute_get_rows(self, query, parameters = []): + if (self.execute(query, parameters)): + return self.fetch_rows() + else: + return False + + def execute_get_row(self, query, parameters = []): + query = "%s LIMIT 1" % query + if (self.execute(query, parameters)): + return self.fetch_row() + else: + return False + + def execute_get_value(self, query, parameters = []): + row = self.execute_get_row(query, parameters) + if (row): + return row[0] + else: + return row + + def create_table(self, table, structure, primary_key = None): + columns = list() + for row in structure: + key, value = row.items()[0] + sql_type = "VARCHAR(255)" + sql_key = '' + if (key == primary_key): + sql_key = 'PRIMARY KEY' + type_r = value.split(':', 1) + type_n = type_r[0] + if (type_n == 'integer'): + sql_type = 'INTEGER' + elif (type_n == 'string'): + try: + sql_type = "VARCHAR(%s)" % type_r[1] + except IndexError, e: + sql_type = "VARCHAR(255)" + + columns.append('"%s" %s %s' % (key, sql_type, sql_key)) + + query = 'CREATE TABLE "%s" (%s)' % (table, ', '.join(columns)) + return self.execute(query) + + def save(self, table, row): + keys = row.keys() + query = 'INSERT OR REPLACE INTO "%s" (%s) VALUES (:%s)' % (table, ', '.join(keys), ', :'.join(keys)) + + return self.execute(query, row) + + def find_sql(self, table, rows = None): + values = list() + if (rows): + if (type(rows) == type(list())): + rows_list = rows + else: + rows_list = list() + rows_list.append(rows) + + query_parts = list() + + for row in rows_list: + statements = list() + for key, value in row.items(): + if (value == None): + statements.append("`%s` IS %s" % (key, '%s')) + else: + statements.append("`%s` = %s" % (key, '%s')) + values.append(value) + query_parts.append('(%s)' % ' AND '.join(statements)) + + query = 'SELECT * FROM `%s` WHERE %s' % (table, ' OR '.join(query_parts)) + else: + query = 'SELECT * FROM `%s`' % table + return query, values + + def find(self, table, row = None): + query, value = self.find_sql(table, row) + + return self.execute_get_row(query, value) + + def findall(self, table, row = None): + query, values = self.find_sql(table, row) + return self.execute_get_rows(query, values) -- cgit v1.2.3 From 6a1961283914a6b87400bf0b7b492fa9f8692c03 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 13 May 2013 12:17:44 +0200 Subject: use mysql library --- misc/mon_ami/mon_ami_main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'misc') diff --git a/misc/mon_ami/mon_ami_main.py b/misc/mon_ami/mon_ami_main.py index 72220e5..fe43618 100644 --- a/misc/mon_ami/mon_ami_main.py +++ b/misc/mon_ami/mon_ami_main.py @@ -9,7 +9,7 @@ from signal import signal, SIGHUP, SIGTERM, SIGINT from optparse import OptionParser from freeswitch import FreeswitchEventSocket from mon_ami_server import MonAMIServer -from sqliter import SQLiteR +from mysqlr import MySQLR def signal_handler(signal_number, frame): global event_socket @@ -40,7 +40,7 @@ def user_password_authentication(user_name, password): return True return False - db = SQLiteR(configuration_options.user_db_name) + db = MySQLR(configuration_options.user_db_name, configuration_options.user_db_user, configuration_options.user_db_password) if not db.connect(): lerror('cound not connect to user database "%s"' % configuration_options.user_db_name) return False @@ -53,6 +53,7 @@ def user_password_authentication(user_name, password): return True linfo('user-password authentication failed - user: %s, password: %s' % (user_name, '*' * len(str(password)))) + return False def main(): @@ -76,7 +77,9 @@ def main(): option_parser.add_option("-p", "--port", "--ami-port", action="store", type="int", dest="ami_port", default=5038) # User database - option_parser.add_option("--user-db-name", action="store", type="string", dest="user_db_name", default='/opt/GS5/db/development.sqlite3') + option_parser.add_option("--user-db-name", action="store", type="string", dest="user_db_name", default='gemeinschaft') + option_parser.add_option("--user-db-user", action="store", type="string", dest="user_db_user", default='gemeinschaft') + option_parser.add_option("--user-db-password", action="store", type="string", dest="user_db_password", default='gemeinschaft') option_parser.add_option("--user-db-table", action="store", type="string", dest="user_db_table", default='sip_accounts') option_parser.add_option("--user-db-name-row", action="store", type="string", dest="user_db_name_row", default='auth_name') option_parser.add_option("--user-db-password-row", action="store", type="string", dest="user_db_password_row", default='password') -- cgit v1.2.3 From fdab546ae6710e8b870d4b7a46a4283e2f20d86c Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 22 May 2013 00:35:22 +0200 Subject: date/time in routing test fixed --- misc/freeswitch/scripts/test_route.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/scripts/test_route.lua b/misc/freeswitch/scripts/test_route.lua index 98dfda9..4a879d1 100644 --- a/misc/freeswitch/scripts/test_route.lua +++ b/misc/freeswitch/scripts/test_route.lua @@ -41,6 +41,8 @@ local dialplan_object = dialplan.dialplan.Dialplan:new{ log = log, caller = call dialplan_object:configuration_read(); caller.dialplan = dialplan_object; caller.local_node_id = dialplan_object.node_id; +caller.date = os.date('%y%m%d%w'); +caller.time = os.date('%H%M%S'); dialplan_object:retrieve_caller_data(); local destination = arguments.destination or dialplan_object:destination_new{ number = caller.destination_number }; -- cgit v1.2.3 From f1260d478acae4a5fc34d7231530a6c6ba5ce0ba Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 30 May 2013 10:17:43 +0200 Subject: multi-pattern support added --- misc/freeswitch/scripts/common/perimeter.lua | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/common/perimeter.lua b/misc/freeswitch/scripts/common/perimeter.lua index d3b601c..8b06f1d 100644 --- a/misc/freeswitch/scripts/common/perimeter.lua +++ b/misc/freeswitch/scripts/common/perimeter.lua @@ -56,8 +56,14 @@ function Perimeter.setup(self, event) self.checks.register = config.checks_register or {}; self.checks.call = config.checks_call or {}; - self.bad_headers.register = config.bad_headers_register; - self.bad_headers.call = config.bad_headers_call; + + for header, patterns in pairs(config.bad_headers_register) do + self.bad_headers.register[header] = common.str.strip_to_a(patterns, ','); + end + + for header, patterns in pairs(config.bad_headers_call) do + self.bad_headers.call[header] = common.str.strip_to_a(patterns, ','); + end self.log:info('[perimeter] PERIMETER - setup perimeter defense'); end @@ -205,12 +211,14 @@ end function Perimeter.check_bad_headers(self, event) local points = nil; - for name, pattern in pairs(self.bad_headers[event.action]) do - pattern = common.array.expand_variables(pattern, event); - local success, result = pcall(string.find, event[name], pattern); - if success and result then - self.log:debug('[', event.key, '/', event.sequence, '] PERIMETER_BAD_HEADERS - ', name, '=', event[name], ' ~= ', pattern); - points = (points or 0) + 1; + for name, patterns in pairs(self.bad_headers[event.action]) do + for index, pattern in ipairs(patterns) do + pattern = common.array.expand_variables(pattern, event); + local success, result = pcall(string.find, event[name], pattern); + if success and result then + self.log:debug('[', event.key, '/', event.sequence, '] PERIMETER_BAD_HEADERS - ', name, '=', event[name], ' ~= ', pattern); + points = (points or 0) + 1; + end end end -- cgit v1.2.3 From b5df8e80d5b10ae7a71e9945ab9246141c7339af Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 4 Jun 2013 11:21:40 +0200 Subject: pager class added --- misc/freeswitch/scripts/common/pager.lua | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 misc/freeswitch/scripts/common/pager.lua (limited to 'misc') diff --git a/misc/freeswitch/scripts/common/pager.lua b/misc/freeswitch/scripts/common/pager.lua new file mode 100644 index 0000000..2f60d14 --- /dev/null +++ b/misc/freeswitch/scripts/common/pager.lua @@ -0,0 +1,71 @@ +-- Gemeinschaft 5 module: pager class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +Pager = {} + +function Pager.new(self, arg) + arg = arg or {} + pager = arg.pager or {} + setmetatable(pager, self); + self.__index = self; + self.class = 'pager'; + self.log = arg.log; + self.database = arg.database; + self.caller = arg.caller; + + return pager; +end + + +function Pager.find_by_id(self, id) + local sql_query = 'SELECT * FROM `pager_groups` WHERE `id`= '.. tonumber(id) .. ' LIMIT 1'; + local pager = nil; + + self.database:query(sql_query, function(entry) + pager = Pager:new(self); + pager.record = entry; + pager.id = tonumber(entry.id); + pager.uuid = entry.uuid; + pager.identifier = 'pager' .. entry.id; + end) + + return pager; +end + + +function Pager.enter(self, originator) + local flags = 'mute'; + if originator then + flags = 'moderator'; + end + + self:callback(); + + local result = self.caller:execute('conference', self.identifier .. "@profile_" .. self.identifier .. "++flags{" .. flags .. "}"); + + self:callback(); +end + + +function Pager.callback(self) + local destination = { + pager_group_id = self.id, + state = 'terminated', + } + + if self.caller.account and self.caller.account.class:lower() == 'sipaccount' then + destination.sip_account_id = self.caller.account.id; + end + + if self.caller and self.caller:ready() then + destination.state = 'active'; + end + + local command = 'http_request.lua ' .. self.caller.uuid .. ' ' .. common.array.expand_variables(self.record.callback_url, destination, self.caller); + + require 'common.fapi'; + return common.fapi.FApi:new():execute('luarun', command); +end -- cgit v1.2.3 From f89becb96fdfe7a247f04b6f472496972ba5827e Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 4 Jun 2013 11:22:24 +0200 Subject: pager function added --- misc/freeswitch/scripts/dialplan/functions.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index 7519ff9..efd1f05 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -118,6 +118,8 @@ function Functions.dialplan_function(self, caller, dialed_number) result = self:call_parking_inout_index(caller, parameters[3]); elseif fid == "test" then result = self:test(caller, parameters[3]); + elseif fid == "pager" then + result = self:pager(caller, parameters[3]); end return result or { continue = false, code = 505, phrase = 'Error executing function', no_cdr = true }; @@ -940,3 +942,20 @@ function Functions.test(self, caller, name) return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end + + +function Functions.pager(self, caller, pager_group_id) + require 'common.pager'; + local pager = common.pager.Pager:new{ log = self.log, database = self.database, caller = caller }:find_by_id(pager_group_id); + + if not pager then + self.log:notice('FUNCTION_PAGER not found - pager_group=', pager_group_id); + return { continue = false, code = 404, phrase = 'No such pager group', no_cdr = true } + end + + self.log:info('FUNCTION_PAGER pager_group=', pager_group_id); + caller:answer(); + pager:enter(); + + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } +end -- cgit v1.2.3 From eda886ce7ca310beb844d3e56fd1cc7179ae9d9a Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 4 Jun 2013 11:31:01 +0200 Subject: set moderator flag --- misc/freeswitch/scripts/common/pager.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/common/pager.lua b/misc/freeswitch/scripts/common/pager.lua index 2f60d14..bf19ba6 100644 --- a/misc/freeswitch/scripts/common/pager.lua +++ b/misc/freeswitch/scripts/common/pager.lua @@ -36,9 +36,14 @@ function Pager.find_by_id(self, id) end -function Pager.enter(self, originator) +function Pager.enter(self) local flags = 'mute'; - if originator then + + if not self.caller.account or self.caller.account.class ~= 'sipaccount' then + return false; + end + + if tonumber(self.record.sip_account_id) == tonumber(self.caller.account.id) then flags = 'moderator'; end @@ -56,7 +61,7 @@ function Pager.callback(self) state = 'terminated', } - if self.caller.account and self.caller.account.class:lower() == 'sipaccount' then + if self.caller.account and self.caller.account.class == 'sipaccount' then destination.sip_account_id = self.caller.account.id; end -- cgit v1.2.3 From 63f253ee3786fdf2970a64b2bbfea5c2ee89b09f Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 4 Jun 2013 13:08:58 +0200 Subject: hangup added --- misc/freeswitch/scripts/common/pager.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/common/pager.lua b/misc/freeswitch/scripts/common/pager.lua index bf19ba6..6896e4c 100644 --- a/misc/freeswitch/scripts/common/pager.lua +++ b/misc/freeswitch/scripts/common/pager.lua @@ -50,7 +50,7 @@ function Pager.enter(self) self:callback(); local result = self.caller:execute('conference', self.identifier .. "@profile_" .. self.identifier .. "++flags{" .. flags .. "}"); - + self.caller:hangup('NORMAL_CLEARING'); self:callback(); end @@ -70,7 +70,6 @@ function Pager.callback(self) end local command = 'http_request.lua ' .. self.caller.uuid .. ' ' .. common.array.expand_variables(self.record.callback_url, destination, self.caller); - require 'common.fapi'; return common.fapi.FApi:new():execute('luarun', command); end -- cgit v1.2.3 From b3a9f757bf86533c64f6ced8cae5901e2d1aec96 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 7 Jun 2013 10:16:25 +0200 Subject: endconf flag added --- misc/freeswitch/scripts/common/pager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/common/pager.lua b/misc/freeswitch/scripts/common/pager.lua index 6896e4c..d9440f4 100644 --- a/misc/freeswitch/scripts/common/pager.lua +++ b/misc/freeswitch/scripts/common/pager.lua @@ -44,7 +44,7 @@ function Pager.enter(self) end if tonumber(self.record.sip_account_id) == tonumber(self.caller.account.id) then - flags = 'moderator'; + flags = 'moderator|endconf'; end self:callback(); -- cgit v1.2.3 From 313eef1e54b0858ab50a81e7929761744a262c0c Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 7 Jun 2013 10:17:41 +0200 Subject: pager config generator added --- misc/freeswitch/scripts/configuration.lua | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index 16dbed7..2486565 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -194,8 +194,8 @@ function conf_conference(database) local conf_name = params:getHeader('conf_name'); local profile_name = params:getHeader('profile_name'); - if conf_name then - require 'common.conference' + if conf_name:find('^conference%d+') then + require 'common.conference'; conference = common.conference.Conference:new{log=log, database=database}:find_by_id(common.str.to_i(conf_name)); if conference then log:debug('CONFIG_CONFERENCE ', conf_name, ' name: ', conference.record.name, ', profile: ', profile_name); @@ -211,6 +211,27 @@ function conf_conference(database) else log:error('CONFIG_CONFERENCE ', conf_name, ' - conference not found'); end + elseif conf_name:find('^pager%d+') then + local parameters = { + ['moh-sound'] = '', + ['caller-controls'] = "speaker", + ['moderator-controls'] = "moderator", + ['comfort-noise'] = false, + } + + require 'common.pager'; + pager = common.pager.Pager:new{log=log, database=database}:find_by_id(common.str.to_i(conf_name)); + if pager then + log:debug('CONFIG_PAGER ', conf_name, ', profile: ', profile_name); + profiles = xml:element{ + 'profiles', + xml:element{ + 'profile', + name = profile_name, + xml:from_hash('param', parameters, 'name', 'value'), + }, + }; + end else log:notice('CONFIG_CONFERENCE - no conference name'); end -- cgit v1.2.3 From 56ae31b855f0706441fbf69253364361bc743885 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 7 Jun 2013 11:00:44 +0200 Subject: report attacks to URL --- misc/freeswitch/scripts/common/perimeter.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/scripts/common/perimeter.lua b/misc/freeswitch/scripts/common/perimeter.lua index 8b06f1d..fcef97c 100644 --- a/misc/freeswitch/scripts/common/perimeter.lua +++ b/misc/freeswitch/scripts/common/perimeter.lua @@ -47,6 +47,7 @@ function Perimeter.setup(self, event) self.ban_tries = 1; self.checks = { register = {}, call = {} }; self.bad_headers = { register = {}, call = {} }; + self.serial = freeswitch.getGlobalVariable('switch_serial'); if config and config.general then for key, value in pairs(config.general) do @@ -99,6 +100,7 @@ function Perimeter.record_update(self, event) event.record.span_start = event.span_start or event.record.span_start; event.record.span_contact_count = (event.span_contact_count or event.record.span_contact_count) + 1; event.record.users = event.users or event.record.users; + event.record.updated = event.updated or event.record.updated; end @@ -150,6 +152,7 @@ function Perimeter.check(self, event) end self:execute_ban(event); event.ban_time = os.time(); + event.banned = true; end event.record.banned = event.record.banned + 1; @@ -255,6 +258,17 @@ end function Perimeter.update_intruder(self, event) require 'common.intruder'; local result = common.intruder.Intruder:new{ log = self.log, database = self.database }:update_blacklist(event); + + if not common.str.blank(self.report_url) and (not event.record.updated or event.banned) then + event.serial = common.fapi.FApi:new():execute('md5', self.serial); + event.blacklisted = tostring(common.str.to_b(event.banned)); + local command = 'http_request.lua perimeter ' .. common.array.expand_variables(self.report_url, event); + require 'common.fapi' + common.fapi.FApi:new():execute('luarun', command); + self.log:devel(command); + end + + event.updated = common.str.to_i(event.updated) + 1; end -- cgit v1.2.3 From 6fcce9fe8d2630b453e1e45aebb525cf8e6f4e78 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Fri, 7 Jun 2013 12:13:09 +0200 Subject: typo --- misc/freeswitch/scripts/common/intruder.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/common/intruder.lua b/misc/freeswitch/scripts/common/intruder.lua index 7d12155..f5e7a41 100644 --- a/misc/freeswitch/scripts/common/intruder.lua +++ b/misc/freeswitch/scripts/common/intruder.lua @@ -35,7 +35,7 @@ function Intruder.update_blacklist(self, event) contacts_per_second_max = event.contacts_per_second_max, user_agent = event.user_agent, to_user = event.to_user, - comment = 'Permimeter', + comment = 'Perimeter', created_at = {'NOW()', raw = true }, updated_at = {'NOW()', raw = true }, }; -- cgit v1.2.3 From 419b25044950ab06a618eca2f3d2d699c1f3501b Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 10 Jun 2013 10:10:25 +0200 Subject: gateway_id can be nil --- misc/freeswitch/scripts/common/gateway.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/scripts/common/gateway.lua b/misc/freeswitch/scripts/common/gateway.lua index ac38326..0c6ab1c 100644 --- a/misc/freeswitch/scripts/common/gateway.lua +++ b/misc/freeswitch/scripts/common/gateway.lua @@ -34,6 +34,10 @@ end function Gateway.find_by_id(self, id) + if not tonumber(id) then + return nil; + end + local sql_query = 'SELECT `a`.*, `c`.`sip_host` AS `domain`, `c`.`contact` AS `contact_full`, `c`.`network_ip`, `c`.`network_port` \ FROM `gateways` `a` \ LEFT JOIN `gateway_settings` `b` ON `a`.`id` = `b`.`gateway_id` AND `b`.`name` = "inbound_username" \ -- cgit v1.2.3 From 4f2e4d63597904c0f2b71398619ee3d1294f297a Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 11 Jun 2013 14:54:12 +0200 Subject: set_privacy removed --- misc/freeswitch/scripts/dialplan/dialplan.lua | 3 --- 1 file changed, 3 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 3f84007..f96f857 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -372,7 +372,6 @@ function Dialplan.dial(self, destination) self.caller:set_caller_id(destination.caller_id_number, destination.caller_id_name or self.caller.caller_id_name); else self.caller:set_caller_id('anonymous', 'Unknown'); - self.caller:set_privacy(true); end local destinations = { destination }; @@ -418,7 +417,6 @@ function Dialplan.huntgroup(self, destination) end else self.caller:set_caller_id('anonymous', tostring(hunt_group.record.name)); - self.caller:set_privacy(true); end self.caller.auth_account = hunt_group; @@ -449,7 +447,6 @@ function Dialplan.acd(self, destination) end else self.caller:set_caller_id('anonymous', tostring(acd.record.name)); - self.caller:set_privacy(true); end self.caller.auth_account = acd; -- cgit v1.2.3 From c51e4bad9ed2a2e1adaeda94ff1ac983106462f6 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 11 Jun 2013 14:54:31 +0200 Subject: set_privacy method removed --- misc/freeswitch/scripts/dialplan/session.lua | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/session.lua b/misc/freeswitch/scripts/dialplan/session.lua index 9c43e74..1d907c5 100644 --- a/misc/freeswitch/scripts/dialplan/session.lua +++ b/misc/freeswitch/scripts/dialplan/session.lua @@ -211,17 +211,6 @@ function Session.set_callee_id(self, number, name) end end --- Set caller Privacy header -function Session.set_privacy(self, privacy) - if privacy then - self.session:setVariable('cid_type', 'none'); - self.session:setVariable('sip_h_Privacy', 'id'); - else - self.session:setVariable('cid_type', 'none'); - self.session:setVariable('sip_h_Privacy', 'none'); - end -end - function Session.set_auth_account(self, auth_account) if auth_account then -- cgit v1.2.3 From 9a34bfecca1bb3d6da4af4faa4e8f8c3cf13b153 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 11 Jun 2013 14:55:22 +0200 Subject: privacy and cid_type options added --- misc/freeswitch/scripts/dialplan/sip_call.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index f401c5c..66cba0e 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -96,6 +96,18 @@ function SipCall.fork(self, destinations, arg ) table.insert(origination_variables, 'ignore_display_updates=true'); end + local origination_privacy = ''; + + if self.caller.clir then + origination_privacy = 'hide_name:hide_number'; + end + + if self.caller.account then + origination_privacy = origination_privacy .. ':screen'; + end + + table.insert(origination_variables, 'origination_privacy=' .. origination_privacy); + if not destination.node_local or destination.type == 'node' then require 'common.node' local node = nil; @@ -168,6 +180,9 @@ function SipCall.fork(self, destinations, arg ) if destination.caller_id_name then table.insert(origination_variables, "origination_caller_id_name='" .. destination.caller_id_name .. "'"); end + if gateway.settings.sip_cid_type then + table.insert(origination_variables, "sip_cid_type='" .. gateway.settings.sip_cid_type .. "'"); + end if destination.channel_variables then for key, value in pairs(destination.channel_variables) do table.insert(origination_variables, tostring(key) .. "='" .. tostring(value) .. "'"); -- cgit v1.2.3 From 2834eec92f1c92e6a80e5e1e4f5a78f50672c7a8 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 12 Jun 2013 09:15:06 +0200 Subject: retrieve domain --- misc/freeswitch/scripts/common/gateway.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/scripts/common/gateway.lua b/misc/freeswitch/scripts/common/gateway.lua index 0c6ab1c..09e8c4b 100644 --- a/misc/freeswitch/scripts/common/gateway.lua +++ b/misc/freeswitch/scripts/common/gateway.lua @@ -61,6 +61,9 @@ function Gateway.find_by_id(self, id) if gateway then gateway.settings = self:config_table_get('gateway_settings', gateway.id); + if common.str.blank(gateway.domain) then + gateway.domain = gateway.settings.domain; + end end return gateway; -- cgit v1.2.3 From f024d2383255847847de9cba4f1aa454a207de84 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 12 Jun 2013 09:19:38 +0200 Subject: set_caller_id removed --- misc/freeswitch/scripts/dialplan/dialplan.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index f96f857..913d7a5 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -370,8 +370,6 @@ function Dialplan.dial(self, destination) end end self.caller:set_caller_id(destination.caller_id_number, destination.caller_id_name or self.caller.caller_id_name); - else - self.caller:set_caller_id('anonymous', 'Unknown'); end local destinations = { destination }; @@ -416,7 +414,7 @@ function Dialplan.huntgroup(self, destination) self:set_caller_picture(self.caller.account.owner.id, self.caller.account.owner.class); end else - self.caller:set_caller_id('anonymous', tostring(hunt_group.record.name)); + self.caller.anonymous_name = tostring(hunt_group.record.name); end self.caller.auth_account = hunt_group; @@ -446,7 +444,7 @@ function Dialplan.acd(self, destination) self:set_caller_picture(self.caller.account.owner.id, self.caller.account.owner.class); end else - self.caller:set_caller_id('anonymous', tostring(acd.record.name)); + self.caller.anonymous_name = tostring(acd.record.name); end self.caller.auth_account = acd; @@ -814,6 +812,10 @@ function Dialplan.run(self, destination) self.caller.date = os.date('%y%m%d%w'); self.caller.time = os.date('%H%M%S'); + if self.config then + self.caller:export_variable('sip_cid_type=' .. (self.config.sip_cid_type or 'none')); + end + if type(self.config.variables) == 'table' then for key, value in pairs(self.config.variables) do self.caller:set_variable(key, value); -- cgit v1.2.3 From 8f05b452f8d57e87fa8927b0960a17aa386c0864 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 12 Jun 2013 09:20:37 +0200 Subject: caller_id and privacy --- misc/freeswitch/scripts/dialplan/sip_call.lua | 60 ++++++++++++++++++--------- 1 file changed, 40 insertions(+), 20 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 66cba0e..c8e40fc 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -96,18 +96,6 @@ function SipCall.fork(self, destinations, arg ) table.insert(origination_variables, 'ignore_display_updates=true'); end - local origination_privacy = ''; - - if self.caller.clir then - origination_privacy = 'hide_name:hide_number'; - end - - if self.caller.account then - origination_privacy = origination_privacy .. ':screen'; - end - - table.insert(origination_variables, 'origination_privacy=' .. origination_privacy); - if not destination.node_local or destination.type == 'node' then require 'common.node' local node = nil; @@ -124,6 +112,7 @@ function SipCall.fork(self, destinations, arg ) table.insert(origination_variables, 'sip_h_X-GS_auth_account_type=' .. tostring(self.caller.auth_account_type)); table.insert(origination_variables, 'sip_h_X-GS_auth_account_uuid=' .. tostring(self.caller.auth_account_uuid)); table.insert(origination_variables, 'sip_h_X-GS_loop_count=' .. tostring(self.caller.loop_count)); + table.insert(origination_variables, 'sip_h_X-GS_clir=' .. tostring(self.caller.clir)); table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/gateway/' .. node.record.name .. '/' .. destination.number); end elseif destination.type == 'sipaccount' then @@ -158,6 +147,11 @@ function SipCall.fork(self, destinations, arg ) table.insert(origination_variables, "gs_auth_account_uuid='" .. common.str.to_s(self.caller.auth_account.uuid) .. "'"); end + if self.caller.clir then + table.insert(origination_variables, "origination_caller_id_number='anonymous'"); + table.insert(origination_variables, "origination_caller_id_name='" .. ( self.caller.anonymous_name or 'Anonymous') .. "'"); + end + table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/' .. sip_account.record.profile_name .. '/' .. sip_account.record.auth_name .. '%' .. sip_account.record.sip_host); if destination.pickup_groups and #destination.pickup_groups > 0 then for key=1, #destination.pickup_groups do @@ -174,15 +168,41 @@ function SipCall.fork(self, destinations, arg ) local gateway = common.gateway.Gateway:new{ log = self.log, database = self.database}:find_by_id(destination.id); if gateway and gateway.outbound then - if destination.caller_id_number then - table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'"); - end - if destination.caller_id_name then - table.insert(origination_variables, "origination_caller_id_name='" .. destination.caller_id_name .. "'"); - end - if gateway.settings.sip_cid_type then - table.insert(origination_variables, "sip_cid_type='" .. gateway.settings.sip_cid_type .. "'"); + local caller_id_type = tostring(gateway.settings.caller_id_type); + + if caller_id_type == 'pid' or caller_id_type == '' or caller_id_type == 'nil' then + local identity = '"' .. (destination.caller_id_name or self.caller.caller_id_name) .. '" '; + + local account_uuid = common.array.try(self.caller, 'account.uuid'); + local auth_account_uuid = common.array.try(self.caller, 'auth_account.uuid'); + + if account_uuid and auth_account_uuid and account_uuid == auth_account_uuid then + table.insert(origination_variables, "sip_h_P-Asserted-Identity='" .. identity .. "'"); + else + table.insert(origination_variables, "sip_h_P-Preferred-Identity='" .. identity .. "'"); + end + + if self.caller.clir then + table.insert(origination_variables, "origination_caller_id_number='anonymous'"); + table.insert(origination_variables, "origination_caller_id_name='" .. ( self.caller.anonymous_name or 'Anonymous') .. "'"); + table.insert(origination_variables, "sip_h_P-Privacy='id'"); + else + if destination.caller_id_number then + table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'"); + end + if destination.caller_id_name then + table.insert(origination_variables, "origination_caller_id_name='" .. destination.caller_id_name .. "'"); + end + end + else + if destination.caller_id_number then + table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'"); + end + if destination.caller_id_name then + table.insert(origination_variables, "origination_caller_id_name='" .. destination.caller_id_name .. "'"); + end end + if destination.channel_variables then for key, value in pairs(destination.channel_variables) do table.insert(origination_variables, tostring(key) .. "='" .. tostring(value) .. "'"); -- cgit v1.2.3 From bb4ba3747de3f06970dddf4171305d473c11aa7f Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 12 Jun 2013 12:21:33 +0200 Subject: replacement on no_match fixed --- misc/freeswitch/scripts/dialplan/router.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 10551f1..50653d8 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -173,6 +173,9 @@ function Router.route_match(self, route) if element.action == 'not_match' then result = not result; + if result then + replacement = tostring(element.replacement); + end end if not result then -- cgit v1.2.3 From db8867ef5779e40b84da50870ddc6ecf2e52ac10 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 12 Jun 2013 13:57:29 +0200 Subject: gateway dependent caller_id handling --- misc/freeswitch/scripts/dialplan/sip_call.lua | 54 ++++++++++++++++++--------- 1 file changed, 36 insertions(+), 18 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index c8e40fc..7e3cddc 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -90,7 +90,7 @@ function SipCall.fork(self, destinations, arg ) for index, destination in ipairs(destinations) do local origination_variables = { 'gs_fork_index=' .. index } - self.log:info('FORK ', index, '/', #destinations, ' - ', destination.type, '=', destination.id, '/', destination.uuid, '@', destination.node_id, ', number: ', destination.number, ', caller_id: "', destination.caller_id_name, '" <', destination.caller_id_number, '>'); + self.log:info('FORK ', index, '/', #destinations, ' - ', destination.type, '=', destination.id, '/', destination.uuid, '@', destination.node_id, ', number: ', destination.number); if not common.str.to_b(arg.update_callee_display) then table.insert(origination_variables, 'ignore_display_updates=true'); @@ -125,6 +125,8 @@ function SipCall.fork(self, destinations, arg ) else local call_waiting = self:call_waiting_busy(sip_account); if not call_waiting then + local caller_id_number = destination.caller_id_number or self.caller.caller_id_number; + local caller_id_name = destination.caller_id_name or self.caller.caller_id_name; destinations[index].numbers = sip_account:phone_numbers(); if not arg.callee_id_name then @@ -148,10 +150,15 @@ function SipCall.fork(self, destinations, arg ) end if self.caller.clir then - table.insert(origination_variables, "origination_caller_id_number='anonymous'"); - table.insert(origination_variables, "origination_caller_id_name='" .. ( self.caller.anonymous_name or 'Anonymous') .. "'"); + caller_id_number = self.caller.anonymous_number or 'anonymous'; + caller_id_name = self.caller.anonymous_name or 'Anonymous'; + table.insert(origination_variables, "origination_caller_id_number='" .. caller_id_number .. "'"); + table.insert(origination_variables, "origination_caller_id_name='" .. caller_id_name .. "'"); + table.insert(origination_variables, "sip_h_Privacy='id'"); end + self.log:info('FORK ', index, '/', #destinations, ' - caller_id: "', caller_id_name, '" <', caller_id_number, '>, privacy: ', self.caller.clir); + table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/' .. sip_account.record.profile_name .. '/' .. sip_account.record.auth_name .. '%' .. sip_account.record.sip_host); if destination.pickup_groups and #destination.pickup_groups > 0 then for key=1, #destination.pickup_groups do @@ -168,24 +175,25 @@ function SipCall.fork(self, destinations, arg ) local gateway = common.gateway.Gateway:new{ log = self.log, database = self.database}:find_by_id(destination.id); if gateway and gateway.outbound then - local caller_id_type = tostring(gateway.settings.caller_id_type); - - if caller_id_type == 'pid' or caller_id_type == '' or caller_id_type == 'nil' then - local identity = '"' .. (destination.caller_id_name or self.caller.caller_id_name) .. '" '; - - local account_uuid = common.array.try(self.caller, 'account.uuid'); - local auth_account_uuid = common.array.try(self.caller, 'auth_account.uuid'); + local asserted_identity = tostring(gateway.settings.asserted_identity); + local asserted_identity_clir = tostring(gateway.settings.asserted_identity); + local caller_id_number = destination.caller_id_number or self.caller.caller_id_number; + local caller_id_name = destination.caller_id_name or self.caller.caller_id_name; + local from_uri = common.array.expand_variables(gateway.settings.from, destination, self.caller, { gateway = gateway }); - if account_uuid and auth_account_uuid and account_uuid == auth_account_uuid then - table.insert(origination_variables, "sip_h_P-Asserted-Identity='" .. identity .. "'"); - else - table.insert(origination_variables, "sip_h_P-Preferred-Identity='" .. identity .. "'"); - end + self.log:devel('DESTINATION: ', destination); + if gateway.settings.asserted_identity then + local identity = common.array.expand_variables(gateway.settings.asserted_identity, destination, self.caller, { gateway = gateway }) + if self.caller.clir then - table.insert(origination_variables, "origination_caller_id_number='anonymous'"); - table.insert(origination_variables, "origination_caller_id_name='" .. ( self.caller.anonymous_name or 'Anonymous') .. "'"); - table.insert(origination_variables, "sip_h_P-Privacy='id'"); + caller_id_number = self.caller.anonymous_number or 'anonymous'; + caller_id_name = self.caller.anonymous_name or 'Anonymous'; + from_uri = common.array.expand_variables(gateway.settings.from_clir, destination, self.caller, { gateway = gateway }) or from_uri; + identity = common.array.expand_variables(gateway.settings.asserted_identity_clir, destination, self.caller, { gateway = gateway }) or identity; + table.insert(origination_variables, "origination_caller_id_number='" .. caller_id_number .. "'"); + table.insert(origination_variables, "origination_caller_id_name='" .. caller_id_name .. "'"); + table.insert(origination_variables, "sip_h_Privacy='id'"); else if destination.caller_id_number then table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'"); @@ -194,6 +202,16 @@ function SipCall.fork(self, destinations, arg ) table.insert(origination_variables, "origination_caller_id_name='" .. destination.caller_id_name .. "'"); end end + + if from_uri then + table.insert(origination_variables, "sip_from_uri='" .. from_uri .. "'"); + end + + if identity then + table.insert(origination_variables, "sip_h_P-Asserted-Identity='" .. identity .. "'"); + end + + self.log:info('FORK ', index, '/', #destinations, ' - from: ', from_uri, ', identity: ', identity, ', privacy: ', self.caller.clir); else if destination.caller_id_number then table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'"); -- cgit v1.2.3 From d8dce422831675d0aca7b9a640b20bb5a5e947ab Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 12 Jun 2013 13:59:43 +0200 Subject: log line removed --- misc/freeswitch/scripts/dialplan/sip_call.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 7e3cddc..256508a 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -181,8 +181,6 @@ function SipCall.fork(self, destinations, arg ) local caller_id_name = destination.caller_id_name or self.caller.caller_id_name; local from_uri = common.array.expand_variables(gateway.settings.from, destination, self.caller, { gateway = gateway }); - self.log:devel('DESTINATION: ', destination); - if gateway.settings.asserted_identity then local identity = common.array.expand_variables(gateway.settings.asserted_identity, destination, self.caller, { gateway = gateway }) -- cgit v1.2.3 From 29eb5c09076e2966224d7653146ea06f066481b0 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 12 Jun 2013 18:27:14 +0200 Subject: settings can be nil --- misc/freeswitch/scripts/dialplan/sip_call.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 256508a..1966a41 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -179,16 +179,16 @@ function SipCall.fork(self, destinations, arg ) local asserted_identity_clir = tostring(gateway.settings.asserted_identity); local caller_id_number = destination.caller_id_number or self.caller.caller_id_number; local caller_id_name = destination.caller_id_name or self.caller.caller_id_name; - local from_uri = common.array.expand_variables(gateway.settings.from, destination, self.caller, { gateway = gateway }); + local from_uri = common.array.expand_variables(gateway.settings.from or '', destination, self.caller, { gateway = gateway }); if gateway.settings.asserted_identity then - local identity = common.array.expand_variables(gateway.settings.asserted_identity, destination, self.caller, { gateway = gateway }) + local identity = common.array.expand_variables(gateway.settings.asserted_identity or '', destination, self.caller, { gateway = gateway }) if self.caller.clir then caller_id_number = self.caller.anonymous_number or 'anonymous'; caller_id_name = self.caller.anonymous_name or 'Anonymous'; - from_uri = common.array.expand_variables(gateway.settings.from_clir, destination, self.caller, { gateway = gateway }) or from_uri; - identity = common.array.expand_variables(gateway.settings.asserted_identity_clir, destination, self.caller, { gateway = gateway }) or identity; + from_uri = common.array.expand_variables(gateway.settings.from_clir or '', destination, self.caller, { gateway = gateway }) or from_uri; + identity = common.array.expand_variables(gateway.settings.asserted_identity_clir or '', destination, self.caller, { gateway = gateway }) or identity; table.insert(origination_variables, "origination_caller_id_number='" .. caller_id_number .. "'"); table.insert(origination_variables, "origination_caller_id_name='" .. caller_id_name .. "'"); table.insert(origination_variables, "sip_h_Privacy='id'"); -- cgit v1.2.3 From 66ef95959eabf843832eeae4c844cbd05eabd5e3 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 14 Jun 2013 10:55:28 +0200 Subject: expression function added --- misc/freeswitch/scripts/dialplan/router.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 50653d8..c2b229d 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -160,13 +160,21 @@ function Router.route_match(self, route) table.insert(arguments, common.array.expand_variables(argument, destination, self.variables)); end result, replacement = self['fun_' .. variable_name](self, unpack(arguments)) - if self.log_details or true then + if not common.str.blank(element.pattern) then + if self.log_details then + self.log:debug('ELEMENT_FUNCTION - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); + end + result, replacement = self:element_match(tostring(element.pattern), tostring(replacement), tostring(replacement)); + end + if self.log_details then if result then self.log:debug('ELEMENT_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); else self.log:debug('ELEMENT_NO_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', tostring(replacement)); end end + else + self.log:error('ELEMENT_FUNCTION - function not found: ', 'fun_' .. variable_name); end end end @@ -267,3 +275,14 @@ function Router.fun_speeddial(self, number, name) end end end + + +function Router.fun_expression(self, expression_str) + expression_str = expression_str:gsub('[^%d%.%+%(%)%^%%%*%/-<>]', ''); + result = loadstring("return (" .. expression_str .. ")")(); + if result then + return true, result; + else + return false, result; + end +end -- cgit v1.2.3 From e48434bf0e1bac7687d08734578c01367b880562 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 14 Jun 2013 11:14:04 +0200 Subject: expression can be nil, empty or invalid --- misc/freeswitch/scripts/dialplan/router.lua | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index c2b229d..b762010 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -278,8 +278,24 @@ end function Router.fun_expression(self, expression_str) - expression_str = expression_str:gsub('[^%d%.%+%(%)%^%%%*%/-<>]', ''); - result = loadstring("return (" .. expression_str .. ")")(); + if common.str.blank(expression_str) then + self.log:error('EXPRESSION - no expression specified'); + return false; + end + + expression_str = expression_str:gsub('[^%d%.%+%(%)%^%%%*%/-<>=!|&]', ''); + expression_str = expression_str:gsub('&&', ' and '); + expression_str = expression_str:gsub('||', ' or '); + expression_str = expression_str:gsub('!=', '~='); + + local expression = loadstring("return (" .. expression_str .. ")") + + if not expression then + self.log:error('EXPRESSION - invalid expression: ', expression_str); + return false; + end + + result = expression(); if result then return true, result; else -- cgit v1.2.3 From 4f5c5e93fe01dec4eea933ab7cb805d95b0bd647 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 14 Jun 2013 11:59:15 +0200 Subject: action:set added --- misc/freeswitch/scripts/dialplan/router.lua | 72 ++++++++++++++++++----------- 1 file changed, 46 insertions(+), 26 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index b762010..4e6398e 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -109,6 +109,37 @@ function Router.element_match_group(self, pattern, groups, replacement, use_key, end +function Router.element_run_function(self, variable_name, element, destination) + local result = nil; + local replacement = nil; + + if self['fun_' .. variable_name] then + local arguments = {}; + for index, argument in ipairs(common.str.to_a(element.replacement, ',')) do + table.insert(arguments, common.array.expand_variables(argument, destination, self.variables)); + end + result, replacement = self['fun_' .. variable_name](self, unpack(arguments)) + if not common.str.blank(element.pattern) then + if self.log_details then + self.log:debug('ELEMENT_FUNCTION - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); + end + result, replacement = self:element_match(tostring(element.pattern), tostring(replacement), tostring(replacement)); + end + if self.log_details then + if result then + self.log:debug('ELEMENT_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); + else + self.log:debug('ELEMENT_NO_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', tostring(replacement)); + end + end + else + self.log:error('ELEMENT_FUNCTION - function not found: ', 'fun_' .. variable_name); + end + + return result, replacement; +end + + function Router.route_match(self, route) local destination = { gateway = 'gateway' .. route.endpoint_id, @@ -132,9 +163,19 @@ function Router.route_match(self, route) end if element.action ~= 'none' then - if common.str.blank(element.var_in) or common.str.blank(element.pattern) and element.action == 'set' then - result = true; - replacement = common.array.expand_variables(element.replacement, destination, self.variables); + if element.action == 'set' then + if common.str.blank(element.var_in) then + result = true; + replacement = common.array.expand_variables(element.replacement, destination, self.variables); + else + local command, variable_name = common.str.partition(element.var_in, ':'); + if command == 'fun' then + result, replacement = self:element_run_function(variable_name, element, destination); + else + result = true; + replacement = common.array.expand_variables(element.replacement, destination, self.variables); + end + end else local command, variable_name = common.str.partition(element.var_in, ':'); @@ -154,28 +195,7 @@ function Router.route_match(self, route) local search_string = self.caller:to_s('sip_h_' .. variable_name); result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement)); elseif command == 'fun' then - if self['fun_' .. variable_name] then - local arguments = {}; - for index, argument in ipairs(common.str.to_a(element.replacement, ',')) do - table.insert(arguments, common.array.expand_variables(argument, destination, self.variables)); - end - result, replacement = self['fun_' .. variable_name](self, unpack(arguments)) - if not common.str.blank(element.pattern) then - if self.log_details then - self.log:debug('ELEMENT_FUNCTION - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); - end - result, replacement = self:element_match(tostring(element.pattern), tostring(replacement), tostring(replacement)); - end - if self.log_details then - if result then - self.log:debug('ELEMENT_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); - else - self.log:debug('ELEMENT_NO_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', tostring(replacement)); - end - end - else - self.log:error('ELEMENT_FUNCTION - function not found: ', 'fun_' .. variable_name); - end + result, replacement = self:element_run_function(variable_name, element, destination); end end @@ -282,7 +302,7 @@ function Router.fun_expression(self, expression_str) self.log:error('EXPRESSION - no expression specified'); return false; end - + expression_str = expression_str:gsub('[^%d%.%+%(%)%^%%%*%/-<>=!|&]', ''); expression_str = expression_str:gsub('&&', ' and '); expression_str = expression_str:gsub('||', ' or '); -- cgit v1.2.3 From b3a96040433edc2ee2a1d85cf989b6d6adb60ee2 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 20 Jun 2013 11:24:29 +0200 Subject: previous behavior of set action restored --- misc/freeswitch/scripts/dialplan/router.lua | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 4e6398e..24d2462 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -22,6 +22,7 @@ function Router.new(self, arg) self.variables = arg.variables or {}; self.log_details = arg.log_details; self.routing_tables = {}; + return object; end @@ -75,8 +76,9 @@ function Router.element_match(self, pattern, search_string, replacement, route_v local replace_by = common.array.expand_variables(replacement, route_variables, self.variables) result = search_string:gsub(pattern, replace_by); if self.log_details then - self.log:debug('ELEMENT_MATCH - ', search_string, ' ~= ', pattern, ' => ', replacement, ' => ', replace_by); + self.log:debug('ELEMENT_MATCH - ', search_string, ' ~= ', pattern, ' => ', replacement, ' => ', result); end + return true, result; end @@ -163,19 +165,9 @@ function Router.route_match(self, route) end if element.action ~= 'none' then - if element.action == 'set' then - if common.str.blank(element.var_in) then - result = true; - replacement = common.array.expand_variables(element.replacement, destination, self.variables); - else - local command, variable_name = common.str.partition(element.var_in, ':'); - if command == 'fun' then - result, replacement = self:element_run_function(variable_name, element, destination); - else - result = true; - replacement = common.array.expand_variables(element.replacement, destination, self.variables); - end - end + if common.str.blank(element.var_in) and common.str.blank(element.pattern) and element.action == 'set' then + result = true; + replacement = common.array.expand_variables(element.replacement, destination, self.variables); else local command, variable_name = common.str.partition(element.var_in, ':'); -- cgit v1.2.3 From 22c5ce2ab518a548428320ae38818fe1f16ce567 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 20 Jun 2013 11:36:37 +0200 Subject: pattern can be ignored if action=set and var_in is blank --- misc/freeswitch/scripts/dialplan/router.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 24d2462..20b833b 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -165,7 +165,7 @@ function Router.route_match(self, route) end if element.action ~= 'none' then - if common.str.blank(element.var_in) and common.str.blank(element.pattern) and element.action == 'set' then + if common.str.blank(element.var_in) and element.action == 'set' then result = true; replacement = common.array.expand_variables(element.replacement, destination, self.variables); else -- cgit v1.2.3