From ac63ced87d2fa66e5348d92b0427165e0a386f01 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 4 Jan 2013 11:44:39 +0100 Subject: clir function added --- misc/freeswitch/scripts/dialplan/functions.lua | 48 +++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index 9a89857..d208d12 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -55,6 +55,10 @@ function Functions.dialplan_function(self, caller, dialed_number) result = self:dial_clir_off(caller, parameters[3]); elseif fid == "dcliron" then result = self:dial_clir_on(caller, parameters[3]); + elseif fid == "cliron" then + result = self:clir_on(caller); + elseif fid == "cliroff" then + result = self:clir_off(caller); elseif fid == "clipon" then result = self:clip_on(caller); elseif fid == "clipoff" then @@ -565,6 +569,48 @@ function Functions.callwaiting_off(self, caller) return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end +function Functions.clir_on(self, caller) + -- Find caller's SipAccount + local caller_sip_account = self:ensure_caller_sip_account(caller); + if not caller_sip_account then + return { continue = false, code = 403, phrase = 'Incompatible caller', no_cdr = true } + end + + local sql_query = 'UPDATE `sip_accounts` SET `clir` = TRUE WHERE `id` = ' .. caller_sip_account.record.id; + + if not self.database:query(sql_query) then + self.log:notice("CLIR could not be set"); + return { continue = false, code = 500, phrase = 'CLIR could not be set', no_cdr = true } + + end + + caller:answer(); + caller:send_display('CLIR on'); + caller:sleep(1000); + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } +end + +function Functions.clir_off(self, caller) + -- Find caller's SipAccount + local caller_sip_account = self:ensure_caller_sip_account(caller); + if not caller_sip_account then + return { continue = false, code = 403, phrase = 'Incompatible caller', no_cdr = true } + end + + local sql_query = 'UPDATE `sip_accounts` SET `clir` = FALSE WHERE `id` = ' .. caller_sip_account.record.id; + + if not self.database:query(sql_query) then + self.log:notice("CLIR could not be set"); + return { continue = false, code = 500, phrase = 'CLIR could not be set', no_cdr = true } + + end + + caller:answer(); + caller:send_display('CLIR off'); + caller:sleep(1000); + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } +end + function Functions.clip_on(self, caller) -- Find caller's SipAccount local caller_sip_account = self:ensure_caller_sip_account(caller); @@ -586,6 +632,7 @@ function Functions.clip_on(self, caller) return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end + function Functions.clip_off(self, caller) -- Find caller's SipAccount local caller_sip_account = self:ensure_caller_sip_account(caller); @@ -607,7 +654,6 @@ function Functions.clip_off(self, caller) return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end - function Functions.call_forwarding_off(self, caller, call_forwarding_service, delete) local defaults = {log = self.log, database = self.database, domain = caller.domain} -- cgit v1.2.3 From 24613b79d5f81e1490fd4ae32956171a87782fae Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 4 Jan 2013 12:28:28 +0100 Subject: redial function added --- misc/freeswitch/scripts/dialplan/functions.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index d208d12..3fa1589 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -51,6 +51,8 @@ function Functions.dialplan_function(self, caller, dialed_number) result = self:user_auto_logout(caller, true); elseif fid == "loaoff" then result = self:user_auto_logout(caller, false); + elseif fid == "redial" then + result = self:redial(caller); elseif fid == "dcliroff" then result = self:dial_clir_off(caller, parameters[3]); elseif fid == "dcliron" then @@ -507,6 +509,24 @@ function Functions.user_auto_logout(self, caller, auto_logout) caller:sleep(1000); end +function Functions.redial(self, caller) + -- Ensure a valid sip account + local caller_sip_account = self:ensure_caller_sip_account(caller); + if not caller_sip_account then + return { continue = false, code = 403, phrase = 'Incompatible caller', no_cdr = true } + end + + local sql_query = 'SELECT `destination_number` FROM `call_histories` WHERE `entry_type` = "dialed" AND `call_historyable_type` = "SipAccount" AND `call_historyable_id` = ' .. caller_sip_account.record.id; + local phone_number = self.database:query_return_value(sql_query); + + common_str = require 'common.str'; + if common_str.blank(phone_number) then + return { continue = false, code = 404, phrase = 'No phone number saved', no_cdr = true } + end + + return { continue = true, number = phone_number } +end + function Functions.dial_clir_off(self, caller, phone_number) -- Ensure a valid sip account local caller_sip_account = self:ensure_caller_sip_account(caller); -- cgit v1.2.3 From cd41d91906334f0c87aeaf6698baefb3e8c64190 Mon Sep 17 00:00:00 2001 From: spag Date: Sat, 5 Jan 2013 10:52:33 +0100 Subject: force-convert gateway and number to strings --- misc/freeswitch/scripts/dialplan/sip_call.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 57f92c6..ab6a471 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -128,7 +128,7 @@ 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 - table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/gateway/' .. destination.gateway .. '/' .. destination.number); + table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/gateway/' .. tostring(destination.gateway) .. '/' .. tostring(destination.number)); elseif destination.type == 'dial' then if destination.caller_id_number then table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'"); -- cgit v1.2.3 From ddb3dfa92ec0878240211cb2b7a8e125961b1360 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sat, 5 Jan 2013 23:01:16 +0100 Subject: Moved to GsParemeter.get and set defaults for a couple of validations. --- misc/freeswitch/scripts/dialplan/sip_call.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 57f92c6..ad7188f 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -65,11 +65,11 @@ end function SipCall.call_waiting_busy(self, sip_account) require 'common.str' if common.str.to_b(sip_account.record.call_waiting) then - self.log:info('CALL_WAITING - status: enabled'); + self.log:info('GsParameter.get('CALL_WAITING') - status: enabled'); return false; else local state = sip_account:call_state(); - self.log:info('CALL_WAITING - status: disabled, sip_account state: ', state); + self.log:info('GsParameter.get('CALL_WAITING') - status: disabled, sip_account state: ', state); return state; end end -- cgit v1.2.3 From b1fb25f0d6ee481cca54f69ed50e6196595ce777 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 7 Jan 2013 12:57:49 +0100 Subject: fixed single quotes --- misc/freeswitch/scripts/dialplan/sip_call.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 0071075..ab6a471 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -65,11 +65,11 @@ end function SipCall.call_waiting_busy(self, sip_account) require 'common.str' if common.str.to_b(sip_account.record.call_waiting) then - self.log:info('GsParameter.get('CALL_WAITING') - status: enabled'); + self.log:info('CALL_WAITING - status: enabled'); return false; else local state = sip_account:call_state(); - self.log:info('GsParameter.get('CALL_WAITING') - status: disabled, sip_account state: ', state); + self.log:info('CALL_WAITING - status: disabled, sip_account state: ', state); return state; end end -- cgit v1.2.3 From 42ec3e041e3bbf55c6e2c37bc6d62569228c5ee2 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Tue, 8 Jan 2013 04:58:27 +0100 Subject: Change path from /opt/GS5 to /opt/gemeinschaft --- misc/freeswitch/scripts/dialplan/voicemail.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index b9dab79..801e0d0 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -128,7 +128,7 @@ end function Voicemail.send_notify(self, caller) self.log:debug('VOICEMAIL_NOTIFY - account: ' .. self.record.auth_name .. ", id: " .. tostring(caller.uuid)); - local file = io.popen("/opt/GS5/script/voicemail_new.sh '" .. tostring(self.record.auth_name) .. "' '" .. tostring(caller.uuid) .. "' 2>&1"); + local file = io.popen("/opt/gemeinschaft/script/voicemail_new.sh '" .. tostring(self.record.auth_name) .. "' '" .. tostring(caller.uuid) .. "' 2>&1"); self.log:debug('VOICEMAIL_NOTIFY - result: ' .. tostring(file:read("*a"))); file:close(); -- cgit v1.2.3 From 11f2b585d700f0be7e80f3e41a65f75785244125 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Tue, 8 Jan 2013 05:40:20 +0100 Subject: usage of shell wrapper script is obsolete --- misc/freeswitch/scripts/dialplan/voicemail.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index 801e0d0..9d823d9 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -128,7 +128,7 @@ end function Voicemail.send_notify(self, caller) self.log:debug('VOICEMAIL_NOTIFY - account: ' .. self.record.auth_name .. ", id: " .. tostring(caller.uuid)); - local file = io.popen("/opt/gemeinschaft/script/voicemail_new.sh '" .. tostring(self.record.auth_name) .. "' '" .. tostring(caller.uuid) .. "' 2>&1"); + local file = io.popen("/opt/gemeinschaft/script/voicemail_new '" .. tostring(self.record.auth_name) .. "' '" .. tostring(caller.uuid) .. "' 2>&1"); self.log:debug('VOICEMAIL_NOTIFY - result: ' .. tostring(file:read("*a"))); file:close(); -- cgit v1.2.3 From 70ef0ee8e668b0f620ec74afc8347e43bcfebb87 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 8 Jan 2013 11:15:31 +0100 Subject: update_callee_display option added --- misc/freeswitch/scripts/dialplan/dialplan.lua | 1 + misc/freeswitch/scripts/dialplan/sip_call.lua | 7 +++++++ 2 files changed, 8 insertions(+) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 391f5bf..69cccf1 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -476,6 +476,7 @@ function Dialplan.dial(self, destination) { timeout = self.dial_timeout_active, send_ringing = ( self.send_ringing_to_gateways and self.caller.from_gateway ), bypass_media_network = self.config.parameters.bypass_media_network, + update_callee_display = self.config.parameters.update_callee_display, } ); end diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index ab6a471..95ab0f3 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -79,6 +79,8 @@ function SipCall.fork(self, destinations, arg ) local dial_strings = {} require 'common.sip_account' + require 'common.str' + local sip_account_class = common.sip_account.SipAccount:new{ log = self.log, database = self.database }; local call_result = { code = 404, phrase = 'No destination' }; @@ -88,6 +90,11 @@ function SipCall.fork(self, destinations, arg ) local origination_variables = { 'gs_fork_index=' .. index } self.log:info('FORK ', index, '/', #destinations, ' - ', destination.type, '=', destination.id, '/', destination.gateway or 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'); + end + if not destination.node_local or destination.type == 'node' then require 'common.node' local node = nil; -- cgit v1.2.3 From faabc3e5db9310727e5d8cb9cd509adeb900d6c0 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Tue, 8 Jan 2013 19:07:24 +0100 Subject: change GS5 default directory back to /opt/GS5 --- misc/freeswitch/scripts/dialplan/voicemail.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index 9d823d9..fe20128 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -128,7 +128,7 @@ end function Voicemail.send_notify(self, caller) self.log:debug('VOICEMAIL_NOTIFY - account: ' .. self.record.auth_name .. ", id: " .. tostring(caller.uuid)); - local file = io.popen("/opt/gemeinschaft/script/voicemail_new '" .. tostring(self.record.auth_name) .. "' '" .. tostring(caller.uuid) .. "' 2>&1"); + local file = io.popen("/opt/GS5/script/voicemail_new '" .. tostring(self.record.auth_name) .. "' '" .. tostring(caller.uuid) .. "' 2>&1"); self.log:debug('VOICEMAIL_NOTIFY - result: ' .. tostring(file:read("*a"))); file:close(); -- cgit v1.2.3 From c8db7371bc31c6ef6ab27026d5f839c2095b924f Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 9 Jan 2013 11:10:04 +0100 Subject: read dialplan configuration from database --- misc/freeswitch/scripts/dialplan/dialplan.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 69cccf1..0f3f59f 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -74,22 +74,22 @@ function Dialplan.domain_get(self, domain) end -function Dialplan.configuration_read(self, file_name) +function Dialplan.configuration_read(self) require 'common.str' - require 'common.configuration_file' + require 'common.configuration_table' -- dialplan configuration - self.config = common.configuration_file.get(file_name or CONFIG_FILE_NAME); + self.config = common.configuration_table.get(self.database, 'dialplan'); self.node_id = common.str.to_i(self.config.parameters.node_id); self.domain = self:domain_get(self.config.parameters.domain); self.dial_timeout = tonumber(self.config.parameters.dial_timeout) or DIAL_TIMEOUT; self.max_loops = tonumber(self.config.parameters.max_loops) or MAX_LOOPS; self.user_image_url = common.str.to_s(self.config.parameters.user_image_url); self.phone_book_entry_image_url = common.str.to_s(self.config.parameters.phone_book_entry_image_url); - self.phonebook_number_lookup = common.str.to_b(self.config.parameters.phonebook_number_lookup); - self.geo_number_lookup = common.str.to_b(self.config.parameters.geo_number_lookup); + self.phonebook_number_lookup = self.config.parameters.phonebook_number_lookup; + self.geo_number_lookup = self.config.parameters.geo_number_lookup; self.default_language = self.config.parameters.default_language or 'en'; - self.send_ringing_to_gateways = common.str.to_b(self.config.parameters.send_ringing_to_gateways); + self.send_ringing_to_gateways = self.config.parameters.send_ringing_to_gateways; if tonumber(self.config.parameters.default_ringtone) then self.default_ringtone = 'http://amooma.de;info=Ringer' .. self.config.parameters.default_ringtone .. ';x-line-id=0'; -- cgit v1.2.3 From ce5a4c9dc44a3793f336e454f63994fb4990a618 Mon Sep 17 00:00:00 2001 From: spag Date: Sat, 12 Jan 2013 09:02:59 +0100 Subject: set dialplan variables --- misc/freeswitch/scripts/dialplan/dialplan.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 0f3f59f..07b8f4f 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -466,10 +466,6 @@ function Dialplan.dial(self, destination) end end - if common.str.to_b(self.config.parameters.bypass_media) then - self.caller:set_variable('bypass_media', true); - end - require 'dialplan.sip_call' return dialplan.sip_call.SipCall:new{ log = self.log, database = self.database, caller = self.caller }:fork( destinations, @@ -866,9 +862,7 @@ end function Dialplan.run(self, destination) self.caller:set_variable('hangup_after_bridge', false); - self.caller:set_variable('ringback', self.config.parameters.ringback); self.caller:set_variable('bridge_early_media', 'true'); - self.caller:set_variable('send_silence_when_idle', 0); self.caller:set_variable('default_language', self.default_language); self.caller:set_variable('gs_save_cdr', true); self.caller:set_variable('gs_call_service', 'dial'); @@ -876,6 +870,12 @@ function Dialplan.run(self, destination) self.caller.date = os.date('%y%m%d%w'); self.caller.time = os.date('%H%M%S'); + if type(self.config.variables) == 'table' then + for key, value in pairs(self.config.variables) do + self.caller:set_variable(key, value); + end + end + self.routes = common.configuration_file.get('/opt/freeswitch/scripts/ini/routes.ini'); self.caller.domain_local = self.domain; self:retrieve_caller_data(); -- cgit v1.2.3 From 9292aa909881b7f21192f9278b8ce5eb8fe442de Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 14 Jan 2013 17:16:38 +0100 Subject: allow header based authentication --- misc/freeswitch/scripts/dialplan/dialplan.lua | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 07b8f4f..aa6b8c8 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -127,17 +127,15 @@ function Dialplan.check_auth(self) self.log:info('AUTH_FIRST_STAGE - gateway autheticated by name/password: gateway=', self.caller.gateway_id, ', name: ', self.caller.gateway_name); authenticated = true; else - local gateways = common.configuration_file.get('/opt/freeswitch/scripts/ini/gateways.ini', false); - if not gateways then - return false; - end - for gateway, gateway_parameters in pairs(gateways) do - if common.str.to_s(gateway_parameters.proxy) == self.caller.sip_contact_host then - self.caller.gateway_name = gateway; - self.caller.from_gateway = true; - self.log:info('AUTH_FIRST_STAGE - gateway autheticated by ip: gateway=', self.caller.gateway_id, ', name: ', self.caller.gateway_name, ', ip: ', self.caller.sip_contact_host); - authenticated = true; - end + require 'common.gateway' + local gateway = common.gateway.Gateway:new{ log = self.log, database = self.database}:authenticate('sip', self.caller); + + if gateway then + self.caller.gateway_name = gateway.name; + self.caller.gateway_id = gateway.id; + self.caller.from_gateway = true; + self.log:info('AUTH_FIRST_STAGE - gateway autheticated by ip: gateway=', self.caller.gateway_id, ', name: ', self.caller.gateway_name, ', ip: ', self.caller.sip_contact_host); + authenticated = true; end end @@ -876,6 +874,10 @@ function Dialplan.run(self, destination) end end + require 'dialplan.router' + local router = dialplan.router.Router:new{ log = self.log, database = self.database }; + router:table_load(); + self.routes = common.configuration_file.get('/opt/freeswitch/scripts/ini/routes.ini'); self.caller.domain_local = self.domain; self:retrieve_caller_data(); -- cgit v1.2.3 From 5ad2029e3e9beb4d581940a440d5a2ac455a163e Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 14 Jan 2013 17:19:51 +0100 Subject: premature inclusion removed --- misc/freeswitch/scripts/dialplan/dialplan.lua | 4 ---- 1 file changed, 4 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index aa6b8c8..2c6f4e0 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -874,10 +874,6 @@ function Dialplan.run(self, destination) end end - require 'dialplan.router' - local router = dialplan.router.Router:new{ log = self.log, database = self.database }; - router:table_load(); - self.routes = common.configuration_file.get('/opt/freeswitch/scripts/ini/routes.ini'); self.caller.domain_local = self.domain; self:retrieve_caller_data(); -- cgit v1.2.3 From 160a510a6638b1e58f6460ae9c03ab64ef6ced75 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 14 Jan 2013 17:31:31 +0100 Subject: log line --- misc/freeswitch/scripts/dialplan/dialplan.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 2c6f4e0..3073aca 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -134,7 +134,7 @@ function Dialplan.check_auth(self) self.caller.gateway_name = gateway.name; self.caller.gateway_id = gateway.id; self.caller.from_gateway = true; - self.log:info('AUTH_FIRST_STAGE - gateway autheticated by ip: gateway=', self.caller.gateway_id, ', name: ', self.caller.gateway_name, ', ip: ', self.caller.sip_contact_host); + self.log:info('AUTH_FIRST_STAGE - gateway autheticated by: ', gateway.auth_source, ' ~ ', gateway.auth_pattern, ', gateway=', self.caller.gateway_id, ', name: ', self.caller.gateway_name, ', ip: ', self.caller.sip_contact_host); authenticated = true; end end -- cgit v1.2.3 From 4ce6146b0883fd9f7557d6ccf118a4dac7adbbe9 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 15 Jan 2013 12:29:38 +0100 Subject: retrieve sip_network_ip --- misc/freeswitch/scripts/dialplan/session.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/session.lua b/misc/freeswitch/scripts/dialplan/session.lua index 7174b24..20fef88 100644 --- a/misc/freeswitch/scripts/dialplan/session.lua +++ b/misc/freeswitch/scripts/dialplan/session.lua @@ -46,6 +46,7 @@ function Session.init_channel_variables(self) self.account_uuid = self:to_s('gs_account_uuid'); self.account_type = self:to_s('gs_account_type'); self.sip_contact_host = self:to_s('sip_contact_host'); + self.sip_network_ip = self:to_s('sip_network_ip'); self.clir = self:to_b('gs_clir'); self.call_timeout = self:to_i('gs_call_timeout'); self.auth_account_type = self:to_s('gs_auth_account_type'); -- cgit v1.2.3 From b713c19f0a7727a14b5ea4d72f8ddaaf01736027 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 15 Jan 2013 12:30:29 +0100 Subject: tweaking authentication --- misc/freeswitch/scripts/dialplan/dialplan.lua | 70 +++++++++++---------------- 1 file changed, 28 insertions(+), 42 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 3073aca..88670ca 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -113,55 +113,34 @@ function Dialplan.hangup(self, code, phrase, cause) end -function Dialplan.check_auth(self) - local authenticated = false; - - require 'common.str' - if self.caller.from_node then - self.log:info('AUTH_FIRST_STAGE - node authenticated - node_id: ', self.caller.node_id); - authenticated = true; - elseif not common.str.blank(self.caller.auth_account_type) then - self.log:info('AUTH_FIRST_STAGE - sipaccount autheticated by name/password: ', self.caller.auth_account_type, '=', self.caller.account_id, '/', self.caller.account_uuid); - authenticated = true; - elseif self.caller.from_gateway then - self.log:info('AUTH_FIRST_STAGE - gateway autheticated by name/password: gateway=', self.caller.gateway_id, ', name: ', self.caller.gateway_name); - authenticated = true; - else - require 'common.gateway' - local gateway = common.gateway.Gateway:new{ log = self.log, database = self.database}:authenticate('sip', self.caller); - - if gateway then - self.caller.gateway_name = gateway.name; - self.caller.gateway_id = gateway.id; - self.caller.from_gateway = true; - self.log:info('AUTH_FIRST_STAGE - gateway autheticated by: ', gateway.auth_source, ' ~ ', gateway.auth_pattern, ', gateway=', self.caller.gateway_id, ', name: ', self.caller.gateway_name, ', ip: ', self.caller.sip_contact_host); - authenticated = true; - end - end - - return authenticated; -end - - -function Dialplan.check_auth_node(self) +function Dialplan.auth_node(self) require 'common.node' local node = common.node.Node:new{ log = self.log, database = self.database }:find_by_address(self.caller.sip_contact_host); - return (node ~= nil); + if node then + self.log:info('AUTH_NODE - node_id: ', self.caller.node_id, ', contact address:', self.caller.sip_contact_host); + return true; + end end -function Dialplan.check_auth_ip(self) - self.log:info('AUTH - node: ', self.caller.from_node, ', auth_account: ', self.caller.auth_account_type, ', gateway: ', self.caller.from_gateway); +function Dialplan.auth_sip_account(self) require 'common.str' - if self.caller.from_node then + if not common.str.blank(self.caller.auth_account_type) then + self.log:info('AUTH_SIP_ACCOUNT - ', self.caller.auth_account_type, '=', self.caller.account_id, '/', self.caller.account_uuid); return true; - elseif not common.str.blank(self.caller.auth_account_type) then - return true; - elseif self.caller.from_gateway then - return true; - else - return nil; + end +end + + +function Dialplan.auth_gateway(self) + require 'common.gateway' + local gateway_class = common.gateway.Gateway:new{ log = self.log, database = self.database}; + local gateway = gateway_class:authenticate('sip', self.caller); + + if gateway then + log:info('AUTH_GATEWAY - ', gateway.auth_source, ' ~ ', gateway.auth_pattern, ', gateway=', gateway.id, ', name: ', gateway.name, ', ip: ', self.caller.sip_contact_host); + return gateway_class:find_by_id(gateway.id); end end @@ -859,6 +838,8 @@ end function Dialplan.run(self, destination) + require 'common.str'; + self.caller:set_variable('hangup_after_bridge', false); self.caller:set_variable('bridge_early_media', 'true'); self.caller:set_variable('default_language', self.default_language); @@ -882,7 +863,12 @@ function Dialplan.run(self, destination) require 'dialplan.route' local route = nil; - if self.caller.from_gateway then + if self.caller.gateway then + if not common.str.blank(self.caller.gateway.settings.number_source) then + self.log:debug('INBOUND_NUMBER: number_source: ', self.caller.gateway.settings.number_source, ', number: ', self.caller:to_s(self.caller.gateway.settings.number_source)); + self.caller.destination_number = self.caller:to_s(self.caller.gateway.settings.number_source); + end + local route_object = dialplan.route.Route:new{ log = self.log, database = self.database, routing_table = self.routes }; route = route_object:inbound(self.caller, self.caller.destination_number); local inbound_caller_id_number = route_object:inbound_cid_number(self.caller, self.caller.gateway_name, 'gateway'); -- cgit v1.2.3 From 113e3c6c6117fbeca7b9bf1f0e6dc26b0db9c407 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 16 Jan 2013 08:33:45 -0500 Subject: call_routes added --- misc/freeswitch/scripts/dialplan/router.lua | 203 ++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 misc/freeswitch/scripts/dialplan/router.lua (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua new file mode 100644 index 0000000..76d7ada --- /dev/null +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -0,0 +1,203 @@ +-- Gemeinschaft 5 module: call router class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +Router = {} + +-- create route object +function Router.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.class = 'router'; + self.log = arg.log; + self.database = arg.database; + self.routes = arg.routes or {}; + self.caller = arg.caller; + self.variables = arg.variables or {}; + return object; +end + +function Router.build_tables(self) + local elements = { + { var_in = 'group', var_out = '', pattern = '^users$', replacement = '', action = 'not_match', mandatory = true }, + { var_in = 'destination_number', var_out = 'destination_number', pattern = '^1$', replacement = '+123456', action = 'not_match', mandatory = true }, + { var_in = 'caller_id_number', var_out = 'caller_id_number', pattern = '^100$', replacement = '+4930100', action = 'set_route_var', mandatory = false }, + } + + local elements2 = { + { var_in = 'group', var_out = '', pattern = '^users$', replacement = '', action = 'match', mandatory = true }, + { var_in = 'destination_number', var_out = 'destination_number', pattern = '^1$', replacement = '+123456', action = 'not_match', mandatory = true }, + { var_in = 'caller_id_number', var_out = 'caller_id_number', pattern = '^100$', replacement = '+4930100', action = 'set_route_var', mandatory = false }, + } + + local elements3 = { + { var_in = 'destination_number', var_out = 'destination_number', pattern = '^#31#(%d+)$', replacement = 'f-dcliron-%1', action = 'set_route_var', mandatory = false }, + } + + local elements4 = { + { var_in = 'destination_number', var_out = 'destination_number', pattern = '^(%d+)$', replacement = '%1', action = 'set_route_var', mandatory = true }, + { var_in = 'caller_id_number', var_out = 'caller_id_number', pattern = '^(.+)$', replacement = '+49%1', action = 'set_route_var', mandatory = false }, + } + + local routes = { + prerouting = { + { id = 10, name = 'feature codes', elements = elements3, endpoint_type = 'dialplanfunction', endpoint_id = 0 }, + }, + outbound = { + { id = 1, name = 'no users', elements = elements, endpoint_type = 'gateway', endpoint_id = 1, }, + { id = 2, name = 'all users', elements = elements2, endpoint_type = 'gateway', endpoint_id = 1, }, + { id = 3, name = 'all users', elements = elements2, endpoint_type = 'gateway', endpoint_id = 1, }, + }, + inbound = { + { id = 20, name = 'haeron', elements = elements4, endpoint_type = 'phonenumber', endpoint_id = 1, }, + }, + + }; + + return routes; +end + + +function Router.failover_table(self) + return { + ['603'] = true, + ['480'] = true, + UNALLOCATED_NUMBER = true, + NORMAL_TEMPORARY_FAILURE = true, + } +end + + +function Router.expand_variables(self, line) + return (line:gsub('{([%a%d_]+)}', function(captured) + return variables[captured] or ''; + end)) +end + + +function Router.set_parameter(self, action, name, value) + if action == 'set_session_var' then + self.log:debug('ROUTER_SET_SESSION_VARIABLE - ', name, ' = ', value); + self.caller[name] = value; + elseif action == 'set_channel_var' then + self.log:debug('ROUTER_SET_VARIABLE - ', name, ' = ', value); + self.caller:set_variable(name, value); + elseif action == 'export_channel_var' then + self.log:debug('ROUTER_EXPORT_VARIABLE - ', name, ' = ', value); + self.caller:export_variable(name, value); + elseif action == 'set_header' then + self.log:debug('ROUTER_SIP_HEADER - ', name, ': ', value); + self.caller:export_variable('sip_h_' .. name, value); + else + self.log:error('ROUTER_SET_PARAMERER - unknown action: ', action, ', ', name, ' = ', value); + end +end + + +function Router.element_match(self, pattern, search_string, replacement) + local variables_list = {}; + local success, result = pcall(string.find, search_string, pattern); + + if not success then + self.log:error('ELEMENT_MATCH - table error - pattern: ', pattern, ', search_string: ', search_string); + elseif result then + return true, search_string:gsub(pattern, self:expand_variables(replacement, variables_list)); + end + + return false; +end + + +function Router.route_match(self, route) + local destination = { + gateway = 'gateway' .. route.endpoint_id, + ['type'] = route.endpoint_type, + id = route.endpoint_id, + actions = {} + }; + + local route_matches = false; + + for index=1, #route.elements do + local result = false; + local replacement = nil; + + local element = route.elements[index]; + if element.var_in == 'group' then + local groups = common.str.try(self.caller, 'auth_account.owner.groups'); + if not groups or type(groups) ~= 'table' then + if element.mandatory then + return false; + end + end + + for group_name, value in pairs(groups) do + result, replacement = self:element_match(tostring(element.pattern), tostring(group_name), tostring(element.replacement)); + if result then + break; + end + end + + else + local search_string = tostring(common.str.try(self.caller, element.var_in)) + result, replacement = self:element_match(tostring(element.pattern), tostring(search_string), tostring(element.replacement)); + end + + if element.action == 'not_match' then + result = not result; + end + + if not result then + if element.mandatory then + return false; + end + elseif element.action ~= 'match' and element.action ~= 'not_match' then + if element.action == 'set_route_var' then + destination[element.var_out] = replacement; + else + table.insert(destination.actions, {action = element.action, name = element.var_out, value = replacement}); + end + end + + if result then + route_matches = true; + end + end + + if route_matches then + return destination; + end; + + return nil; +end + + +function Router.route_run(self, table_name, phone_number, find_first) + local routing_tables = self:build_tables(); + local routing_table = routing_tables[table_name]; + + local routes = {}; + + if type(routing_table) == 'table' then + for index=1, #routing_table do + local route = self:route_match(routing_table[index], phone_number); + if route then + table.insert(routes, route); + self.log:info('ROUTE ', #routes,' - ', table_name,'=', routing_table[index].id, '/', routing_table[index].name, ', destination: ', route.type, '=', route.id); + if find_first then + return route; + end + else + self.log:debug('ROUTE_NO_MATCH - ', table_name, '=', routing_table[index].id, '/', routing_table[index].name); + end + end + end + + if not find_first then + return routes; + end +end -- cgit v1.2.3 From ac7ebc61a99cd638d7f23c9c99dcd1329e6040b6 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 16 Jan 2013 16:06:52 +0100 Subject: call router added --- misc/freeswitch/scripts/dialplan/router.lua | 181 ++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 misc/freeswitch/scripts/dialplan/router.lua (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua new file mode 100644 index 0000000..2071288 --- /dev/null +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -0,0 +1,181 @@ +-- Gemeinschaft 5 module: call router class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +Router = {} + +-- create route object +function Router.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.class = 'router'; + self.log = arg.log; + self.database = arg.database; + self.routes = arg.routes or {}; + self.caller = arg.caller; + self.variables = arg.variables or {}; + return object; +end + + +function Router.read_table(self, table_name) + local routing_table = {}; + + local sql_query = 'SELECT * \ + FROM `call_routes` `a` \ + JOIN `route_elements` `b` ON `a`.`id` = `b`.`call_route_id`\ + WHERE `a`.`table` = "' .. table_name .. '" \ + ORDER BY `a`.`position`, `b`.`position`'; + + local last_id = 0; + 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 = {} }); + end + + table.insert(routing_table[#routing_table].elements, { + var_in = route.var_in, + var_out = route.var_out, + pattern = route.pattern, + replacement = route.replacement, + action = route.action, + mandatory = common.str.to_b(route.mandatory), + }); + end); + + return routing_table; +end + + +function Router.expand_variables(self, line) + return (line:gsub('{([%a%d_]+)}', function(captured) + return variables[captured] or ''; + end)) +end + + +function Router.set_parameter(self, action, name, value) + if action == 'set_session_var' then + self.log:debug('ROUTER_SET_SESSION_VARIABLE - ', name, ' = ', value); + self.caller[name] = value; + elseif action == 'set_channel_var' then + self.log:debug('ROUTER_SET_VARIABLE - ', name, ' = ', value); + self.caller:set_variable(name, value); + elseif action == 'export_channel_var' then + self.log:debug('ROUTER_EXPORT_VARIABLE - ', name, ' = ', value); + self.caller:export_variable(name, value); + elseif action == 'set_header' then + self.log:debug('ROUTER_SIP_HEADER - ', name, ': ', value); + self.caller:export_variable('sip_h_' .. name, value); + else + self.log:error('ROUTER_SET_PARAMERER - unknown action: ', action, ', ', name, ' = ', value); + end +end + + +function Router.element_match(self, pattern, search_string, replacement) + local variables_list = {}; + local success, result = pcall(string.find, search_string, pattern); + + if not success then + self.log:error('ELEMENT_MATCH - table error - pattern: ', pattern, ', search_string: ', search_string); + elseif result then + return true, search_string:gsub(pattern, self:expand_variables(replacement, variables_list)); + end + + return false; +end + + +function Router.route_match(self, route) + local destination = { + gateway = 'gateway' .. route.endpoint_id, + ['type'] = route.endpoint_type, + id = route.endpoint_id, + actions = {} + }; + + local route_matches = false; + + for index=1, #route.elements do + local result = false; + local replacement = nil; + + local element = route.elements[index]; + if element.var_in == 'group' then + local groups = common.str.try(self.caller, 'auth_account.owner.groups'); + if not groups or type(groups) ~= 'table' then + if element.mandatory then + return false; + end + end + + for group_name, value in pairs(groups) do + result, replacement = self:element_match(tostring(element.pattern), tostring(group_name), tostring(element.replacement)); + if result then + break; + end + end + + else + local search_string = tostring(common.str.try(self.caller, element.var_in)) + result, replacement = self:element_match(tostring(element.pattern), tostring(search_string), tostring(element.replacement)); + end + + if element.action == 'not_match' then + result = not result; + end + + if not result then + if element.mandatory then + return false; + end + elseif element.action ~= 'match' and element.action ~= 'not_match' then + if element.action == 'set_route_var' then + destination[element.var_out] = replacement; + else + table.insert(destination.actions, {action = element.action, name = element.var_out, value = replacement}); + end + end + + if result then + route_matches = true; + end + end + + if route_matches then + return destination; + end; + + return nil; +end + + +function Router.route_run(self, table_name, phone_number, find_first) + local routing_table = self:read_table(table_name); + local routes = {}; + + if type(routing_table) == 'table' then + for index=1, #routing_table do + local route = self:route_match(routing_table[index], phone_number); + if route then + table.insert(routes, route); + self.log:info('ROUTE ', #routes,' - ', table_name,'=', routing_table[index].id, '/', routing_table[index].name, ', destination: ', route.type, '=', route.id); + if find_first then + return route; + end + else + self.log:debug('ROUTE_NO_MATCH - ', table_name, '=', routing_table[index].id, '/', routing_table[index].name); + end + end + end + + if not find_first then + return routes; + end +end -- cgit v1.2.3 From dc68dbecc380e94322aa2777fcbb5be1f4b0af99 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 16 Jan 2013 16:08:50 +0100 Subject: database driven routing tables --- misc/freeswitch/scripts/dialplan/dialplan.lua | 87 ++++++++++++++++----------- 1 file changed, 53 insertions(+), 34 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 88670ca..32f59c2 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -343,12 +343,6 @@ function Dialplan.destination_new(self, arg) end -function Dialplan.routes_get(self, destination) - require 'dialplan.route' - return dialplan.route.Route:new{ log = self.log, database = self.database, routing_table = self.routes }:outbound(self.caller, destination.number); -end - - function Dialplan.set_caller_picture(self, entry_id, entry_type, image) entry_type = entry_type:lower(); if entry_type == 'user' then @@ -629,9 +623,11 @@ function Dialplan.callthrough(self, destination) return { continue = false, code = 404, phrase = 'No destination' } end - local route = dialplan.route.Route:new{ log = self.log, database = self.database, routing_table = self.routes }:prerouting(self.caller, destination_number); - if route and route.value then - destination_number = route.value; + require 'dialplan.router' + local route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller }:route_run('prerouting', destination_number, true); + + if route and route.destination_number then + destination_number = route.destination_number; end if not callthrough:whitelist(destination_number) then @@ -760,7 +756,9 @@ function Dialplan.switch(self, destination) return self:dialplanfunction(destination); elseif not common.str.blank(destination.number) then local result = { continue = false, code = 404, phrase = 'No route' } - local routes = self:routes_get(destination); + + require 'dialplan.router' + local routes = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller }:route_run('outbound', destination.number); if not routes or #routes == 0 then self.log:notice('SWITCH - no route - number: ', destination.number); @@ -802,26 +800,26 @@ function Dialplan.switch(self, destination) self.caller:set_callee_id(destination.callee_id_number, destination.callee_id_name); for index, route in ipairs(routes) do - if route.class == 'hangup' then + if route.endpoint_type == 'hangup' then return { continue = false, code = route.endpoint, phrase = route.phrase, cause = route.value } end - if route.class == 'forward' then + if route.endpoint_type == 'forward' then return { continue = true, call_forwarding = { number = route.value, service = 'route', type = 'phonenumber' }} end - destination.gateway = route.endpoint; - destination.type = route.class; - destination.number = route.value; - destination.caller_id_number = route.caller_id_number; - destination.caller_id_name = route.caller_id_name; + + for key, value in pairs(route) do + destination[key] = value; + end + result = self:dial(destination); if result.continue == false then break; end - if common.str.to_b(self.routes.failover[tostring(result.code)]) == true then + if common.str.to_b(self.route_failover[tostring(result.code)]) == true then self.log:info('SWITCH - failover - code: ', result.code); - elseif common.str.to_b(self.routes.failover[tostring(result.cause)]) == true then + elseif common.str.to_b(self.route_failover[tostring(result.cause)]) == true then self.log:info('SWITCH - failover - cause: ', result.cause); else self.log:info('SWITCH - no failover - cause: ', result.cause, ', code: ', result.code); @@ -839,7 +837,8 @@ end function Dialplan.run(self, destination) require 'common.str'; - + require 'dialplan.router'; + self.caller:set_variable('hangup_after_bridge', false); self.caller:set_variable('bridge_early_media', 'true'); self.caller:set_variable('default_language', self.default_language); @@ -855,35 +854,55 @@ function Dialplan.run(self, destination) end end - self.routes = common.configuration_file.get('/opt/freeswitch/scripts/ini/routes.ini'); self.caller.domain_local = self.domain; self:retrieve_caller_data(); + self.route_failover = common.configuration_table.get(self.database, 'call_route', 'failover'); if not destination or destination.type == 'unknown' then - require 'dialplan.route' local route = nil; - if self.caller.gateway then if not common.str.blank(self.caller.gateway.settings.number_source) then self.log:debug('INBOUND_NUMBER: number_source: ', self.caller.gateway.settings.number_source, ', number: ', self.caller:to_s(self.caller.gateway.settings.number_source)); self.caller.destination_number = self.caller:to_s(self.caller.gateway.settings.number_source); end - local route_object = dialplan.route.Route:new{ log = self.log, database = self.database, routing_table = self.routes }; - route = route_object:inbound(self.caller, self.caller.destination_number); - local inbound_caller_id_number = route_object:inbound_cid_number(self.caller, self.caller.gateway_name, 'gateway'); - route_object.expandable.caller_id_number = inbound_caller_id_number; - local inbound_caller_id_name = route_object:inbound_cid_name(self.caller, self.caller.gateway_name, 'gateway'); - self.log:info('INBOUND_CALLER_ID_REWRITE - number: ', inbound_caller_id_number, ', name: ', inbound_caller_id_name); - self.caller.caller_id_number = inbound_caller_id_number or self.caller.caller_id_number; - self.caller.caller_id_name = inbound_caller_id_name or self.caller.caller_id_name; - self.caller.caller_phone_numbers[1] = self.caller.caller_id_number; + route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller }:route_run('inbound', self.caller.destination_number, true); + if route then + + local ignore_keys = { + gateway = true, + ['type'] = true, + actions = true, + }; + + for key, value in pairs(route) do + if not ignore_keys[key] then + self.caller[key] = value; + end + end + + self.caller.caller_phone_numbers[1] = self.caller.caller_id_number; + else + self.log:notice('INBOUND - no route'); + end + + if false then + local route_object = dialplan.route.Route:new{ log = self.log, database = self.database, routing_table = self.routes }; + route = route_object:inbound(self.caller, self.caller.destination_number); + local inbound_caller_id_number = route_object:inbound_cid_number(self.caller, self.caller.gateway_name, 'gateway'); + route_object.expandable.caller_id_number = inbound_caller_id_number; + local inbound_caller_id_name = route_object:inbound_cid_name(self.caller, self.caller.gateway_name, 'gateway'); + self.log:info('INBOUND_CALLER_ID_REWRITE - number: ', inbound_caller_id_number, ', name: ', inbound_caller_id_name); + self.caller.caller_id_number = inbound_caller_id_number or self.caller.caller_id_number; + self.caller.caller_id_name = inbound_caller_id_name or self.caller.caller_id_name; + self.caller.caller_phone_numbers[1] = self.caller.caller_id_number; + end else - route = dialplan.route.Route:new{ log = self.log, database = self.database, routing_table = self.routes }:prerouting(self.caller, self.caller.destination_number); + route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller }:route_run('prerouting', self.caller.destination_number, true); end if route then - destination = self:destination_new{ number = route.value } + destination = self:destination_new{ ['type'] = route.type, id = route.id, number = route.destination_number } self.caller.destination_number = destination.number; self.caller.destination = destination; elseif not destination or destination.type == 'unknown' then -- cgit v1.2.3 From 87aa843f920c2961496da669df4bba035c08aa1c Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 16 Jan 2013 16:12:48 +0100 Subject: call router added --- misc/freeswitch/scripts/dialplan/router.lua | 181 ++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 misc/freeswitch/scripts/dialplan/router.lua (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua new file mode 100644 index 0000000..2071288 --- /dev/null +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -0,0 +1,181 @@ +-- Gemeinschaft 5 module: call router class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +Router = {} + +-- create route object +function Router.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.class = 'router'; + self.log = arg.log; + self.database = arg.database; + self.routes = arg.routes or {}; + self.caller = arg.caller; + self.variables = arg.variables or {}; + return object; +end + + +function Router.read_table(self, table_name) + local routing_table = {}; + + local sql_query = 'SELECT * \ + FROM `call_routes` `a` \ + JOIN `route_elements` `b` ON `a`.`id` = `b`.`call_route_id`\ + WHERE `a`.`table` = "' .. table_name .. '" \ + ORDER BY `a`.`position`, `b`.`position`'; + + local last_id = 0; + 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 = {} }); + end + + table.insert(routing_table[#routing_table].elements, { + var_in = route.var_in, + var_out = route.var_out, + pattern = route.pattern, + replacement = route.replacement, + action = route.action, + mandatory = common.str.to_b(route.mandatory), + }); + end); + + return routing_table; +end + + +function Router.expand_variables(self, line) + return (line:gsub('{([%a%d_]+)}', function(captured) + return variables[captured] or ''; + end)) +end + + +function Router.set_parameter(self, action, name, value) + if action == 'set_session_var' then + self.log:debug('ROUTER_SET_SESSION_VARIABLE - ', name, ' = ', value); + self.caller[name] = value; + elseif action == 'set_channel_var' then + self.log:debug('ROUTER_SET_VARIABLE - ', name, ' = ', value); + self.caller:set_variable(name, value); + elseif action == 'export_channel_var' then + self.log:debug('ROUTER_EXPORT_VARIABLE - ', name, ' = ', value); + self.caller:export_variable(name, value); + elseif action == 'set_header' then + self.log:debug('ROUTER_SIP_HEADER - ', name, ': ', value); + self.caller:export_variable('sip_h_' .. name, value); + else + self.log:error('ROUTER_SET_PARAMERER - unknown action: ', action, ', ', name, ' = ', value); + end +end + + +function Router.element_match(self, pattern, search_string, replacement) + local variables_list = {}; + local success, result = pcall(string.find, search_string, pattern); + + if not success then + self.log:error('ELEMENT_MATCH - table error - pattern: ', pattern, ', search_string: ', search_string); + elseif result then + return true, search_string:gsub(pattern, self:expand_variables(replacement, variables_list)); + end + + return false; +end + + +function Router.route_match(self, route) + local destination = { + gateway = 'gateway' .. route.endpoint_id, + ['type'] = route.endpoint_type, + id = route.endpoint_id, + actions = {} + }; + + local route_matches = false; + + for index=1, #route.elements do + local result = false; + local replacement = nil; + + local element = route.elements[index]; + if element.var_in == 'group' then + local groups = common.str.try(self.caller, 'auth_account.owner.groups'); + if not groups or type(groups) ~= 'table' then + if element.mandatory then + return false; + end + end + + for group_name, value in pairs(groups) do + result, replacement = self:element_match(tostring(element.pattern), tostring(group_name), tostring(element.replacement)); + if result then + break; + end + end + + else + local search_string = tostring(common.str.try(self.caller, element.var_in)) + result, replacement = self:element_match(tostring(element.pattern), tostring(search_string), tostring(element.replacement)); + end + + if element.action == 'not_match' then + result = not result; + end + + if not result then + if element.mandatory then + return false; + end + elseif element.action ~= 'match' and element.action ~= 'not_match' then + if element.action == 'set_route_var' then + destination[element.var_out] = replacement; + else + table.insert(destination.actions, {action = element.action, name = element.var_out, value = replacement}); + end + end + + if result then + route_matches = true; + end + end + + if route_matches then + return destination; + end; + + return nil; +end + + +function Router.route_run(self, table_name, phone_number, find_first) + local routing_table = self:read_table(table_name); + local routes = {}; + + if type(routing_table) == 'table' then + for index=1, #routing_table do + local route = self:route_match(routing_table[index], phone_number); + if route then + table.insert(routes, route); + self.log:info('ROUTE ', #routes,' - ', table_name,'=', routing_table[index].id, '/', routing_table[index].name, ', destination: ', route.type, '=', route.id); + if find_first then + return route; + end + else + self.log:debug('ROUTE_NO_MATCH - ', table_name, '=', routing_table[index].id, '/', routing_table[index].name); + end + end + end + + if not find_first then + return routes; + end +end -- cgit v1.2.3 From bc530494cca59845b5896ae4b0900ca1b9691827 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 17 Jan 2013 10:05:49 +0100 Subject: set caller id numbers array --- misc/freeswitch/scripts/dialplan/dialplan.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 32f59c2..704728a 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -757,6 +757,21 @@ function Dialplan.switch(self, destination) elseif not common.str.blank(destination.number) then local result = { continue = false, code = 404, phrase = 'No route' } + local clip_no_screening = common.str.try(caller, 'account.record.clip_no_screening'); + self.caller.caller_id_numbers = {} + if not common.str.blank(clip_no_screening) then + for index, number in ipairs(common.str.strip_to_a(clip_no_screening, ',')) do + table.insert(self.caller.caller_id_numbers, number); + end + end + for index, number in ipairs(self.caller.caller_phone_numbers) do + table.insert(self.caller.caller_id_numbers, number); + end + self.log:info('CALLER_ID_NUMBERS - clir: ', self.caller.clir, ', numbers: ', table.concat(self.caller.caller_id_numbers, ',')); + + destination.callee_id_number = destination.number; + destination.callee_id_name = nil; + require 'dialplan.router' local routes = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller }:route_run('outbound', destination.number); @@ -765,9 +780,6 @@ function Dialplan.switch(self, destination) return { continue = false, code = 404, phrase = 'No route' } end - destination.callee_id_number = destination.number; - destination.callee_id_name = nil; - if self.phonebook_number_lookup then require 'common.str' local user_id = common.str.try(self.caller, 'account.owner.id'); -- cgit v1.2.3 From 0a3a4c78badb80e7f0f7b5d372421f1e75fd5f02 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 17 Jan 2013 11:12:02 +0100 Subject: access arrays from within routing elements --- misc/freeswitch/scripts/dialplan/router.lua | 40 ++++++++++++++++++----------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 2071288..de543f3 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -92,6 +92,23 @@ function Router.element_match(self, pattern, search_string, replacement) end +function Router.element_match_group(self, pattern, groups, replacement, use_key) + if type(groups) ~= 'table' then + return false; + end + + for key, value in pairs(groups) do + if use_key then + value = key; + end + result, replaced_value = self:element_match(pattern, tostring(value), replacement); + if result then + return true, replaced_value; + end + end +end + + function Router.route_match(self, route) local destination = { gateway = 'gateway' .. route.endpoint_id, @@ -107,24 +124,17 @@ function Router.route_match(self, route) local replacement = nil; local element = route.elements[index]; - if element.var_in == 'group' then - local groups = common.str.try(self.caller, 'auth_account.owner.groups'); - if not groups or type(groups) ~= 'table' then - if element.mandatory then - return false; - end - end + local command, variable_name = common.str.partition(element.var_in, ':'); - for group_name, value in pairs(groups) do - result, replacement = self:element_match(tostring(element.pattern), tostring(group_name), tostring(element.replacement)); - if result then - break; - end - end - - else + if not command or not variable_name or command == 'var' then local search_string = tostring(common.str.try(self.caller, element.var_in)) result, replacement = self:element_match(tostring(element.pattern), tostring(search_string), tostring(element.replacement)); + elseif command == 'key' or command == 'val' then + local groups = common.str.try(self.caller, variable_name); + result, replacement = self:element_match_group(tostring(element.pattern), groups, tostring(element.replacement), command == 'key'); + elseif command == 'chv' then + local search_string = self.caller:to_s(variable_name); + result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement)); end if element.action == 'not_match' then -- cgit v1.2.3 From 4bf20d36ed26746e0a7b2fc551e57337c8788c86 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 17 Jan 2013 12:03:09 +0100 Subject: array vs. hash --- misc/freeswitch/scripts/dialplan/user.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/user.lua b/misc/freeswitch/scripts/dialplan/user.lua index 3b483c8..0a2e0dd 100644 --- a/misc/freeswitch/scripts/dialplan/user.lua +++ b/misc/freeswitch/scripts/dialplan/user.lua @@ -62,7 +62,7 @@ function User.list_groups(self, id) local groups = {}; self.database:query(sql_query, function(entry) - groups[common.str.downcase(entry.name)] = true; + table.insert(groups, common.str.downcase(entry.name)); end); return groups; -- cgit v1.2.3 From a4c63280de43e820bfcf9f02d61f90a50fffff92 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 17 Jan 2013 12:03:57 +0100 Subject: debugging output --- misc/freeswitch/scripts/dialplan/router.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index de543f3..e82d224 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -175,7 +175,7 @@ function Router.route_run(self, table_name, phone_number, find_first) local route = self:route_match(routing_table[index], phone_number); if route then table.insert(routes, route); - self.log:info('ROUTE ', #routes,' - ', table_name,'=', routing_table[index].id, '/', routing_table[index].name, ', destination: ', route.type, '=', route.id); + self.log:info('ROUTE ', #routes,' - ', table_name,'=', routing_table[index].id, '/', routing_table[index].name, ', destination: ', route.type, '=', route.id, ', destination_number: ', route.destination_number); if find_first then return route; end -- cgit v1.2.3 From d66a90d64f6c99070c8dde1d12d4de90d7032b49 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 17 Jan 2013 15:10:34 +0100 Subject: display caller id in fork --- misc/freeswitch/scripts/dialplan/sip_call.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 95ab0f3..1513459 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -89,7 +89,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.gateway or destination.uuid, '@', destination.node_id, ', number: ', destination.number); + self.log:info('FORK ', index, '/', #destinations, ' - ', destination.type, '=', destination.id, '/', destination.gateway or destination.uuid, '@', destination.node_id, ', number: ', destination.number, ', caller_id: "', destination.caller_id_name, '" <', destination.caller_id_number, '>'); if not common.str.to_b(arg.update_callee_display) then table.insert(origination_variables, 'ignore_display_updates=true'); -- cgit v1.2.3 From 25a311e5dd538a190a1b3cf94477d2aad2cc89c9 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 17 Jan 2013 15:11:27 +0100 Subject: action handling improvements --- misc/freeswitch/scripts/dialplan/router.lua | 63 ++++++++++++++++------------- 1 file changed, 36 insertions(+), 27 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index e82d224..4a756ea 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -114,7 +114,7 @@ function Router.route_match(self, route) gateway = 'gateway' .. route.endpoint_id, ['type'] = route.endpoint_type, id = route.endpoint_id, - actions = {} + channel_variables = {} }; local route_matches = false; @@ -124,37 +124,46 @@ function Router.route_match(self, route) local replacement = nil; local element = route.elements[index]; - local command, variable_name = common.str.partition(element.var_in, ':'); - - if not command or not variable_name or command == 'var' then - local search_string = tostring(common.str.try(self.caller, element.var_in)) - result, replacement = self:element_match(tostring(element.pattern), tostring(search_string), tostring(element.replacement)); - elseif command == 'key' or command == 'val' then - local groups = common.str.try(self.caller, variable_name); - result, replacement = self:element_match_group(tostring(element.pattern), groups, tostring(element.replacement), command == 'key'); - elseif command == 'chv' then - local search_string = self.caller:to_s(variable_name); - result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement)); - end - if element.action == 'not_match' then - result = not result; - end + if element.action ~= 'none' then + local command, variable_name = common.str.partition(element.var_in, ':'); + + if not command or not variable_name or command == 'var' then + local search_string = tostring(common.str.try(self.caller, element.var_in)) + result, replacement = self:element_match(tostring(element.pattern), tostring(search_string), tostring(element.replacement)); + elseif command == 'key' or command == 'val' then + local groups = common.str.try(self.caller, variable_name); + result, replacement = self:element_match_group(tostring(element.pattern), groups, tostring(element.replacement), command == 'key'); + elseif command == 'chv' then + local search_string = self.caller:to_s(variable_name); + result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement)); + 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)); + end - if not result then - if element.mandatory then - return false; + if element.action == 'not_match' then + result = not result; end - elseif element.action ~= 'match' and element.action ~= 'not_match' then - if element.action == 'set_route_var' then - destination[element.var_out] = replacement; + + if not result then + if element.mandatory then + return false; + end else - table.insert(destination.actions, {action = element.action, name = element.var_out, value = replacement}); - end - end + local command, variable_name = common.str.partition(element.var_out, ':'); + if not command or not variable_name or command == 'var' then + destination[element.var_out] = replacement; + elseif command == 'chv' then + table.insert(destination.channel_variables, { name = element.var_out, value = replacement }); + elseif command == 'hdr' then + table.insert(destination.channel_variables, { name = 'sip_h_' .. tostring(element.var_out), value = replacement }); + end - if result then - route_matches = true; + if element.action == 'match' or element.action == 'not_match' then + route_matches = true; + end + end end end -- cgit v1.2.3 From 48d569baeda24663b3adcb6532c9678f5b6ddbcb Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 17 Jan 2013 15:18:52 +0100 Subject: do not set variable when name blank --- misc/freeswitch/scripts/dialplan/router.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 4a756ea..f207276 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -151,13 +151,15 @@ function Router.route_match(self, route) return false; end else - local command, variable_name = common.str.partition(element.var_out, ':'); - if not command or not variable_name or command == 'var' then - destination[element.var_out] = replacement; - elseif command == 'chv' then - table.insert(destination.channel_variables, { name = element.var_out, value = replacement }); - elseif command == 'hdr' then - table.insert(destination.channel_variables, { name = 'sip_h_' .. tostring(element.var_out), value = replacement }); + if not common.str.blank(element.var_out) then + local command, variable_name = common.str.partition(element.var_out, ':'); + if not command or not variable_name or command == 'var' then + destination[element.var_out] = replacement; + elseif command == 'chv' then + table.insert(destination.channel_variables, { name = element.var_out, value = replacement }); + elseif command == 'hdr' then + table.insert(destination.channel_variables, { name = 'sip_h_' .. tostring(element.var_out), value = replacement }); + end end if element.action == 'match' or element.action == 'not_match' then -- cgit v1.2.3 From 17206a20e5bcb44fa4d90f0e176f7aa0fe43bca3 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 17 Jan 2013 21:51:58 +0100 Subject: rename_column table to routing_table --- misc/freeswitch/scripts/dialplan/router.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index f207276..33434ee 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -28,7 +28,7 @@ function Router.read_table(self, table_name) local sql_query = 'SELECT * \ FROM `call_routes` `a` \ JOIN `route_elements` `b` ON `a`.`id` = `b`.`call_route_id`\ - WHERE `a`.`table` = "' .. table_name .. '" \ + WHERE `a`.`routing_table` = "' .. table_name .. '" \ ORDER BY `a`.`position`, `b`.`position`'; local last_id = 0; -- cgit v1.2.3 From 59b51b24e78a58ecd76baee530531df64ff3f668 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 09:47:04 +0100 Subject: set channel variables/headers --- misc/freeswitch/scripts/dialplan/sip_call.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 1513459..06132ab 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -135,6 +135,12 @@ 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 destination.channel_variables then + for key, value in pairs(destination.channel_variables) do + self.log:notice('FORK_CHANNEL_VARIABLES: ', tostring(key) .. "='" .. tostring(value) .. "'"); + table.insert(origination_variables, tostring(key) .. "='" .. tostring(value) .. "'"); + end + end table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/gateway/' .. tostring(destination.gateway) .. '/' .. tostring(destination.number)); elseif destination.type == 'dial' then if destination.caller_id_number then -- cgit v1.2.3 From 983a3e274ab46609d0563d8e941ac4a8d90400c9 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 09:47:58 +0100 Subject: set channel variables/headers --- misc/freeswitch/scripts/dialplan/router.lua | 56 +++++++++++------------------ 1 file changed, 21 insertions(+), 35 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 33434ee..6c5b9f1 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -59,25 +59,6 @@ function Router.expand_variables(self, line) end -function Router.set_parameter(self, action, name, value) - if action == 'set_session_var' then - self.log:debug('ROUTER_SET_SESSION_VARIABLE - ', name, ' = ', value); - self.caller[name] = value; - elseif action == 'set_channel_var' then - self.log:debug('ROUTER_SET_VARIABLE - ', name, ' = ', value); - self.caller:set_variable(name, value); - elseif action == 'export_channel_var' then - self.log:debug('ROUTER_EXPORT_VARIABLE - ', name, ' = ', value); - self.caller:export_variable(name, value); - elseif action == 'set_header' then - self.log:debug('ROUTER_SIP_HEADER - ', name, ': ', value); - self.caller:export_variable('sip_h_' .. name, value); - else - self.log:error('ROUTER_SET_PARAMERER - unknown action: ', action, ', ', name, ' = ', value); - end -end - - function Router.element_match(self, pattern, search_string, replacement) local variables_list = {}; local success, result = pcall(string.find, search_string, pattern); @@ -126,20 +107,25 @@ function Router.route_match(self, route) local element = route.elements[index]; if element.action ~= 'none' then - local command, variable_name = common.str.partition(element.var_in, ':'); - - if not command or not variable_name or command == 'var' then - local search_string = tostring(common.str.try(self.caller, element.var_in)) - result, replacement = self:element_match(tostring(element.pattern), tostring(search_string), tostring(element.replacement)); - elseif command == 'key' or command == 'val' then - local groups = common.str.try(self.caller, variable_name); - result, replacement = self:element_match_group(tostring(element.pattern), groups, tostring(element.replacement), command == 'key'); - elseif command == 'chv' then - local search_string = self.caller:to_s(variable_name); - result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement)); - 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)); + if common.str.blank(element.var_in) or common.str.blank(element.pattern) and element.action == 'set' then + result = true; + replacement = element.replacement; + else + local command, variable_name = common.str.partition(element.var_in, ':'); + + if not command or not variable_name or command == 'var' then + local search_string = tostring(common.str.try(self.caller, element.var_in)) + result, replacement = self:element_match(tostring(element.pattern), tostring(search_string), tostring(element.replacement)); + elseif command == 'key' or command == 'val' then + local groups = common.str.try(self.caller, variable_name); + result, replacement = self:element_match_group(tostring(element.pattern), groups, tostring(element.replacement), command == 'key'); + elseif command == 'chv' then + local search_string = self.caller:to_s(variable_name); + result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement)); + 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)); + end end if element.action == 'not_match' then @@ -156,9 +142,9 @@ function Router.route_match(self, route) if not command or not variable_name or command == 'var' then destination[element.var_out] = replacement; elseif command == 'chv' then - table.insert(destination.channel_variables, { name = element.var_out, value = replacement }); + destination.channel_variables[variable_name] = replacement; elseif command == 'hdr' then - table.insert(destination.channel_variables, { name = 'sip_h_' .. tostring(element.var_out), value = replacement }); + destination.channel_variables['sip_h_' .. variable_name] = replacement; end end -- cgit v1.2.3 From 01078d50412183ff4fbeb213643093e6d2cf8714 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 10:08:47 +0100 Subject: log line removed --- misc/freeswitch/scripts/dialplan/sip_call.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 06132ab..0b799e5 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -137,7 +137,6 @@ function SipCall.fork(self, destinations, arg ) end if destination.channel_variables then for key, value in pairs(destination.channel_variables) do - self.log:notice('FORK_CHANNEL_VARIABLES: ', tostring(key) .. "='" .. tostring(value) .. "'"); table.insert(origination_variables, tostring(key) .. "='" .. tostring(value) .. "'"); end end -- cgit v1.2.3 From b79543b0881a75c97a3710f4dadba6bf19ce6895 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 10:32:05 +0100 Subject: set inbound variables --- misc/freeswitch/scripts/dialplan/dialplan.lua | 36 ++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 704728a..e90354c 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -880,11 +880,11 @@ function Dialplan.run(self, destination) route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller }:route_run('inbound', self.caller.destination_number, true); if route then - local ignore_keys = { + id = true, gateway = true, ['type'] = true, - actions = true, + channel_variables = true, }; for key, value in pairs(route) do @@ -897,23 +897,31 @@ function Dialplan.run(self, destination) else self.log:notice('INBOUND - no route'); end - - if false then - local route_object = dialplan.route.Route:new{ log = self.log, database = self.database, routing_table = self.routes }; - route = route_object:inbound(self.caller, self.caller.destination_number); - local inbound_caller_id_number = route_object:inbound_cid_number(self.caller, self.caller.gateway_name, 'gateway'); - route_object.expandable.caller_id_number = inbound_caller_id_number; - local inbound_caller_id_name = route_object:inbound_cid_name(self.caller, self.caller.gateway_name, 'gateway'); - self.log:info('INBOUND_CALLER_ID_REWRITE - number: ', inbound_caller_id_number, ', name: ', inbound_caller_id_name); - self.caller.caller_id_number = inbound_caller_id_number or self.caller.caller_id_number; - self.caller.caller_id_name = inbound_caller_id_name or self.caller.caller_id_name; - self.caller.caller_phone_numbers[1] = self.caller.caller_id_number; - end else route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller }:route_run('prerouting', self.caller.destination_number, true); + if route then + local ignore_keys = { + id = true, + gateway = true, + ['type'] = true, + channel_variables = true, + }; + + for key, value in pairs(route) do + if not ignore_keys[key] then + self.caller[key] = value; + end + end + end end if route then + if type(route.channel_variables) == 'table' then + for key, value in pairs(route.channel_variables) do + self.caller:set_variable(key, value); + end + end + destination = self:destination_new{ ['type'] = route.type, id = route.id, number = route.destination_number } self.caller.destination_number = destination.number; self.caller.destination = destination; -- cgit v1.2.3 From 78cfbba5f201d2468c628abdfd457b1f14495541 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 11:18:30 +0100 Subject: set variables --- misc/freeswitch/scripts/dialplan/dialplan.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index e90354c..0407485 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -624,7 +624,7 @@ function Dialplan.callthrough(self, destination) end require 'dialplan.router' - local route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller }:route_run('prerouting', destination_number, true); + local route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('prerouting', destination_number, true); if route and route.destination_number then destination_number = route.destination_number; @@ -773,7 +773,7 @@ function Dialplan.switch(self, destination) destination.callee_id_name = nil; require 'dialplan.router' - local routes = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller }:route_run('outbound', destination.number); + local routes = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('outbound', destination.number); if not routes or #routes == 0 then self.log:notice('SWITCH - no route - number: ', destination.number); @@ -878,7 +878,7 @@ function Dialplan.run(self, destination) self.caller.destination_number = self.caller:to_s(self.caller.gateway.settings.number_source); end - route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller }:route_run('inbound', self.caller.destination_number, true); + route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('inbound', self.caller.destination_number, true); if route then local ignore_keys = { id = true, @@ -898,7 +898,7 @@ function Dialplan.run(self, destination) self.log:notice('INBOUND - no route'); end else - route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller }:route_run('prerouting', self.caller.destination_number, true); + route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('prerouting', self.caller.destination_number, true); if route then local ignore_keys = { id = true, -- cgit v1.2.3 From 1e465e49670f6c0fccc1cd920992a14942d3cfba Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 11:19:09 +0100 Subject: expand variables --- misc/freeswitch/scripts/dialplan/router.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 6c5b9f1..5f427ac 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -52,21 +52,20 @@ function Router.read_table(self, table_name) end -function Router.expand_variables(self, line) - return (line:gsub('{([%a%d_]+)}', function(captured) - return variables[captured] or ''; +function Router.expand_variables(self, line, variables) + return (line:gsub('{([%a%d%._]+)}', function(captured) + return common.str.try(variables, captured) or ''; end)) end function Router.element_match(self, pattern, search_string, replacement) - local variables_list = {}; local success, result = pcall(string.find, search_string, pattern); if not success then self.log:error('ELEMENT_MATCH - table error - pattern: ', pattern, ', search_string: ', search_string); elseif result then - return true, search_string:gsub(pattern, self:expand_variables(replacement, variables_list)); + return true, search_string:gsub(pattern, self:expand_variables(replacement, self.variables)); end return false; @@ -109,7 +108,7 @@ function Router.route_match(self, route) 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 = element.replacement; + replacement = self:expand_variables(element.replacement, self.variables); else local command, variable_name = common.str.partition(element.var_in, ':'); -- cgit v1.2.3 From 045a4cfb6374cde4c664e91a9f8d1fede844b610 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 11:57:19 +0100 Subject: unused constant removed --- misc/freeswitch/scripts/dialplan/dialplan.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 0407485..87652d5 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -7,7 +7,6 @@ module(...,package.seeall) Dialplan = {} -- local constants -local CONFIG_FILE_NAME = '/opt/freeswitch/scripts/ini/dialplan.ini'; local DIAL_TIMEOUT = 120; local MAX_LOOPS = 20; local DIALPLAN_FUNCTION_PATTERN = '^f[_%-].*'; -- cgit v1.2.3 From 8744de13516c3fc2fbf2843e85aff08707f50de1 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Fri, 18 Jan 2013 12:54:45 +0100 Subject: adjust copyright date for 2013 --- misc/freeswitch/scripts/dialplan/acd.lua | 2 +- misc/freeswitch/scripts/dialplan/cdr.lua | 2 +- misc/freeswitch/scripts/dialplan/dialplan.lua | 2 +- misc/freeswitch/scripts/dialplan/fax.lua | 2 +- misc/freeswitch/scripts/dialplan/geo_number.lua | 2 +- misc/freeswitch/scripts/dialplan/hunt_group.lua | 2 +- misc/freeswitch/scripts/dialplan/phone_book.lua | 2 +- misc/freeswitch/scripts/dialplan/presence.lua | 2 +- misc/freeswitch/scripts/dialplan/route.lua | 2 +- misc/freeswitch/scripts/dialplan/session.lua | 2 +- misc/freeswitch/scripts/dialplan/sip_call.lua | 2 +- misc/freeswitch/scripts/dialplan/tenant.lua | 2 +- misc/freeswitch/scripts/dialplan/user.lua | 2 +- misc/freeswitch/scripts/dialplan/voicemail.lua | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/acd.lua b/misc/freeswitch/scripts/dialplan/acd.lua index 563d836..f4b298e 100644 --- a/misc/freeswitch/scripts/dialplan/acd.lua +++ b/misc/freeswitch/scripts/dialplan/acd.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: acd class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/dialplan/cdr.lua b/misc/freeswitch/scripts/dialplan/cdr.lua index 55a7889..d0fdede 100644 --- a/misc/freeswitch/scripts/dialplan/cdr.lua +++ b/misc/freeswitch/scripts/dialplan/cdr.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: cdr class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 87652d5..405a664 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: dialplan class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/dialplan/fax.lua b/misc/freeswitch/scripts/dialplan/fax.lua index 2a40620..aa29ff6 100644 --- a/misc/freeswitch/scripts/dialplan/fax.lua +++ b/misc/freeswitch/scripts/dialplan/fax.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: fax class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/dialplan/geo_number.lua b/misc/freeswitch/scripts/dialplan/geo_number.lua index 06bfd62..76cc01b 100644 --- a/misc/freeswitch/scripts/dialplan/geo_number.lua +++ b/misc/freeswitch/scripts/dialplan/geo_number.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: geonumber class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/dialplan/hunt_group.lua b/misc/freeswitch/scripts/dialplan/hunt_group.lua index 87f86f1..44c2bb8 100644 --- a/misc/freeswitch/scripts/dialplan/hunt_group.lua +++ b/misc/freeswitch/scripts/dialplan/hunt_group.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: hunt group class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/dialplan/phone_book.lua b/misc/freeswitch/scripts/dialplan/phone_book.lua index 089f115..6653789 100644 --- a/misc/freeswitch/scripts/dialplan/phone_book.lua +++ b/misc/freeswitch/scripts/dialplan/phone_book.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: phone book class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/dialplan/presence.lua b/misc/freeswitch/scripts/dialplan/presence.lua index 234b908..0f63ce9 100644 --- a/misc/freeswitch/scripts/dialplan/presence.lua +++ b/misc/freeswitch/scripts/dialplan/presence.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: presence class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/dialplan/route.lua b/misc/freeswitch/scripts/dialplan/route.lua index 2243cbe..a12b5f9 100644 --- a/misc/freeswitch/scripts/dialplan/route.lua +++ b/misc/freeswitch/scripts/dialplan/route.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: routing class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/dialplan/session.lua b/misc/freeswitch/scripts/dialplan/session.lua index 20fef88..4029f9e 100644 --- a/misc/freeswitch/scripts/dialplan/session.lua +++ b/misc/freeswitch/scripts/dialplan/session.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: caller session class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 0b799e5..3f56753 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: sip call class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall); diff --git a/misc/freeswitch/scripts/dialplan/tenant.lua b/misc/freeswitch/scripts/dialplan/tenant.lua index 8d6436c..904609e 100644 --- a/misc/freeswitch/scripts/dialplan/tenant.lua +++ b/misc/freeswitch/scripts/dialplan/tenant.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: user class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/dialplan/user.lua b/misc/freeswitch/scripts/dialplan/user.lua index 0a2e0dd..b536600 100644 --- a/misc/freeswitch/scripts/dialplan/user.lua +++ b/misc/freeswitch/scripts/dialplan/user.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: user class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index fe20128..5d79ba3 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: voicemail class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) -- cgit v1.2.3 From baafa28ebe7046a987083f853cfe5a1a55b7adb3 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 14:19:01 +0100 Subject: dialed_sip_user and dialed_domain added --- misc/freeswitch/scripts/dialplan/session.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/session.lua b/misc/freeswitch/scripts/dialplan/session.lua index 20fef88..dc53f7a 100644 --- a/misc/freeswitch/scripts/dialplan/session.lua +++ b/misc/freeswitch/scripts/dialplan/session.lua @@ -43,6 +43,9 @@ function Session.init_channel_variables(self) self.from_gateway = true; end + self.dialed_sip_user = self.caller:to_s('dialed_user'); + self.dialed_domain = self.caller:to_s('dialed_domain'); + self.account_uuid = self:to_s('gs_account_uuid'); self.account_type = self:to_s('gs_account_type'); self.sip_contact_host = self:to_s('sip_contact_host'); -- cgit v1.2.3 From 8e58b80f2da3eb341e1be2ad5847606030910963 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 14:20:32 +0100 Subject: retrieve_caller_data method not dependent on session --- misc/freeswitch/scripts/dialplan/dialplan.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 87652d5..1c31968 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -234,19 +234,21 @@ end function Dialplan.retrieve_caller_data(self) - self.caller.caller_phone_numbers_hash = {} - require 'common.str' - local dialed_sip_user = self.caller:to_s('dialed_user'); + self.caller.caller_phone_numbers_hash = {} -- TODO: Set auth_account on transfer initiated by calling party - if not common.str.blank(dialed_sip_user) then - self.caller.auth_account = self:object_find('sipaccount', self.caller:to_s('dialed_domain'), dialed_sip_user); - self.caller:set_auth_account(self.caller.auth_account); + if not common.str.blank(self.caller.dialed_sip_user) then + self.caller.auth_account = self:object_find('sipaccount', self.caller.dialed_domain, dialed_sip_user); + if self.caller.set_auth_account then + self.caller:set_auth_account(self.caller.auth_account); + end elseif not common.str.blank(self.caller.auth_account_type) and not common.str.blank(self.caller.auth_account_uuid) then self.caller.auth_account = self:object_find(self.caller.auth_account_type, self.caller.auth_account_uuid); - self.caller:set_auth_account(self.caller.auth_account); + if self.caller.set_auth_account then + self.caller:set_auth_account(self.caller.auth_account); + end end if self.caller.auth_account then @@ -275,7 +277,7 @@ function Dialplan.retrieve_caller_data(self) self.log:error('CALLER_DATA - caller owner not found'); end - if not self.caller.clir then + if not self.caller.clir and self.caller.set_caller_id then self.caller:set_caller_id(self.caller.caller_phone_numbers[1], self.caller.account.record.caller_name or self.caller.account.record.name); end else -- cgit v1.2.3 From c4c3ce49a9f1a229df30c88f0f8a24f06acc4d0f Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 14:27:43 +0100 Subject: dialed_sip_user and dialed_domain fixed --- misc/freeswitch/scripts/dialplan/session.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/session.lua b/misc/freeswitch/scripts/dialplan/session.lua index 6cb670c..7de85ca 100644 --- a/misc/freeswitch/scripts/dialplan/session.lua +++ b/misc/freeswitch/scripts/dialplan/session.lua @@ -43,8 +43,8 @@ function Session.init_channel_variables(self) self.from_gateway = true; end - self.dialed_sip_user = self.caller:to_s('dialed_user'); - self.dialed_domain = self.caller:to_s('dialed_domain'); + self.dialed_sip_user = self:to_s('dialed_user'); + self.dialed_domain = self:to_s('dialed_domain'); self.account_uuid = self:to_s('gs_account_uuid'); self.account_type = self:to_s('gs_account_type'); -- cgit v1.2.3 From 79e4b0b95336d568b5f65bcd793995a7d0d4ee50 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 20 Jan 2013 16:16:36 +0100 Subject: unused variable removed --- misc/freeswitch/scripts/dialplan/dialplan.lua | 8 ++++---- misc/freeswitch/scripts/dialplan/router.lua | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 3fcb2bd..cc222fc 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -625,7 +625,7 @@ function Dialplan.callthrough(self, destination) end require 'dialplan.router' - local route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('prerouting', destination_number, true); + local route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('prerouting', true); if route and route.destination_number then destination_number = route.destination_number; @@ -774,7 +774,7 @@ function Dialplan.switch(self, destination) destination.callee_id_name = nil; require 'dialplan.router' - local routes = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('outbound', destination.number); + local routes = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('outbound'); if not routes or #routes == 0 then self.log:notice('SWITCH - no route - number: ', destination.number); @@ -879,7 +879,7 @@ function Dialplan.run(self, destination) self.caller.destination_number = self.caller:to_s(self.caller.gateway.settings.number_source); end - route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('inbound', self.caller.destination_number, true); + route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('inbound', true); if route then local ignore_keys = { id = true, @@ -899,7 +899,7 @@ function Dialplan.run(self, destination) self.log:notice('INBOUND - no route'); end else - route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('prerouting', self.caller.destination_number, true); + route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('prerouting', true); if route then local ignore_keys = { id = true, diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 5f427ac..7e64d7b 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -162,13 +162,13 @@ function Router.route_match(self, route) end -function Router.route_run(self, table_name, phone_number, find_first) +function Router.route_run(self, table_name, find_first) local routing_table = self:read_table(table_name); local routes = {}; if type(routing_table) == 'table' then for index=1, #routing_table do - local route = self:route_match(routing_table[index], phone_number); + local route = self:route_match(routing_table[index]); if route then table.insert(routes, route); self.log:info('ROUTE ', #routes,' - ', table_name,'=', routing_table[index].id, '/', routing_table[index].name, ', destination: ', route.type, '=', route.id, ', destination_number: ', route.destination_number); -- cgit v1.2.3 From e840f0b4d7bab10b53174b607ed60e1bce450321 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 20 Jan 2013 16:17:09 +0100 Subject: routing in hunt group class --- misc/freeswitch/scripts/dialplan/hunt_group.lua | 39 ++++++++++++++++++------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/hunt_group.lua b/misc/freeswitch/scripts/dialplan/hunt_group.lua index 44c2bb8..07f403e 100644 --- a/misc/freeswitch/scripts/dialplan/hunt_group.lua +++ b/misc/freeswitch/scripts/dialplan/hunt_group.lua @@ -98,21 +98,35 @@ function HuntGroup.run(self, dialplan_object, caller, destination) self.log:info('HUNTGROUP ', self.record.id, ' - name: ', self.record.name, ', strategy: ', self.record.strategy,', members: ', #hunt_group_members); + local save_destination = caller.destination; + local destinations = {} for index, hunt_group_member in ipairs(hunt_group_members) do local destination = dialplan_object:destination_new{ number = hunt_group_member.number }; if destination.type == 'unknown' then - require 'dialplan.route' - local routes = dialplan.route.Route:new{ log = self.log, database = self.database, routing_table = dialplan_object.routes }:outbound(caller, destination.number); - if routes and #routes > 0 then - destination.callee_id_number = destination.number; - destination.callee_id_name = nil; - local route = routes[1]; - destination.gateway = route.endpoint; - destination.type = route.class; - destination.number = route.value; - destination.caller_id_number = route.caller_id_number; - destination.caller_id_name = route.caller_id_name; + self.log:notice('HG_DESTINATION - number: ', destination.number, ', hunt_group_member.number: ', hunt_group_member.number); + + + caller.destination_number = destination.number; + + require 'dialplan.router' + local route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = caller, variables = caller }:route_run('outbound', true); + + if route then + destination = dialplan_object:destination_new{ ['type'] = route.type, id = route.id, number = route.destination_number } + + local ignore_keys = { + id = true, + ['type'] = true, + channel_variables = true, + }; + + for key, value in pairs(route) do + if not ignore_keys[key] then + destination[key] = value; + end + end + table.insert(destinations, destination); end else @@ -120,6 +134,9 @@ function HuntGroup.run(self, dialplan_object, caller, destination) end end + caller.destination = save_destination; + caller.destination_number = save_destination.number; + local forwarding_destination = nil; if caller.forwarding_service == 'assistant' and caller.auth_account then forwarding_destination = dialplan_object:destination_new{ type = caller.auth_account.class, id = caller.auth_account.id, number = forwarding_number } -- cgit v1.2.3 From 6e269043f470b597dcc256170c9167e164e74fec Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 20 Jan 2013 16:21:41 +0100 Subject: deep-sixed old call routing engine --- misc/freeswitch/scripts/dialplan/route.lua | 265 ----------------------------- 1 file changed, 265 deletions(-) delete mode 100644 misc/freeswitch/scripts/dialplan/route.lua (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/route.lua b/misc/freeswitch/scripts/dialplan/route.lua deleted file mode 100644 index a12b5f9..0000000 --- a/misc/freeswitch/scripts/dialplan/route.lua +++ /dev/null @@ -1,265 +0,0 @@ --- Gemeinschaft 5 module: routing class --- (c) AMOOMA GmbH 2012-2013 --- - -module(...,package.seeall) - -Route = {} - --- create route object -function Route.new(self, arg) - arg = arg or {} - object = arg.object or {} - setmetatable(object, self); - self.__index = self; - self.log = arg.log; - self.database = arg.database; - self.routing_table = arg.routing_table; - self.expandable = arg.expandable or {}; - return object; -end - --- find matching routes -function Route.prerouting(self, caller, number) - require 'common.routing_tables' - - for index, routing_entry in pairs(self.routing_table.prerouting) do - local route = common.routing_tables.match_route(routing_entry, number); - if route.error then - self.log:error('PREROUTE - error: ', route.error); - elseif route.value then - self.log:info('ROUTE_PREROUTING - called number: ', number, ', value: ', route.value, ', pattern: ', route.pattern); - return route; - end - end -end - --- find matching routes -function Route.outbound(self, caller, number) - local routes = {}; - require 'common.routing_tables' - require 'common.str' - - local ignore_arguments = { - class=true, - endpoint=true, - pattern=true, - value=true, - group=true, - phrase=true, - } - - local clip_no_screening = common.str.try(caller, 'account.record.clip_no_screening'); - local caller_id_numbers = {} - if not common.str.blank(clip_no_screening) then - for index, number in ipairs(common.str.strip_to_a(clip_no_screening, ',')) do - table.insert(caller_id_numbers, number); - end - end - for index, number in ipairs(caller.caller_phone_numbers) do - table.insert(caller_id_numbers, number); - end - self.log:info('CALLER_ID_NUMBER - caller_id_numbers: ', table.concat(caller_id_numbers, ',')); - - for index, routing_entry in pairs(self.routing_table.outbound) do - local route = common.routing_tables.match_route(routing_entry, number); - if route.error then - self.log:error('ROUTE_OUTBOUND - error: ', route.error); - elseif route.value then - local valid_route = true; - - for argument, value in pairs(route) do - if not ignore_arguments[argument] then - local table_value = common.str.downcase(tostring(common.str.try(caller, argument))); - value = common.str.downcase(tostring(value)); - if table_value:match(value) then - self.log:info('ROUTE_OUTBOUND_POSITIVE - ', argument, '=', value, ' ~ ', table_value, ', pattern: ', route.pattern); - else - self.log:info('ROUTE_OUTBOUND_NEGATIVE - ', argument, '=', value, ' !~ ', table_value, ', pattern: ', route.pattern); - valid_route = false; - end - end - end - - if route.group then - if common.str.try(caller.auth_account, 'owner.groups.' .. tostring(route.group)) then - self.log:info('ROUTE_OUTBOUND_POSITIVE - group=', route.group, ', pattern: ', route.pattern); - else - self.log:info('ROUTE_OUTBOUND_NEGATIVE - group=', route.group, ', pattern: ', route.pattern); - valid_route = false; - end - end - - if route.cidn then - if caller.caller_id_number:match(route.cidn) then - self.log:info('ROUTE_OUTBOUND_POSITIVE - cidn=', route.cidn, ' ~ ', caller.caller_id_number,', pattern: ', route.pattern); - else - self.log:info('ROUTE_OUTBOUND_NEGATIVE - cidn=', route.cidn, ' !~ ', caller.caller_id_number, ', pattern: ', route.pattern); - valid_route = false; - end - end - - if valid_route then - if route.class ~= 'hangup' then - route.caller_id_number = self:outbound_cid_number(caller, caller_id_numbers, route.endpoint, route.class); - self.expandable.caller_id_number = route.caller_id_number; - route.caller_id_name = self:outbound_cid_name(caller, route.endpoint, route.class); - end - table.insert(routes, route); - self.log:info('ROUTE_OUTBOUND ', #routes,' - ', route.class, '=', route.endpoint, ', value: ', route.value, ', caller_id_number: ', route.caller_id_number, ', caller_id_name: ', route.caller_id_name); - end - end - end - - return routes; -end - - -function Route.inbound(self, caller, number) - require 'common.routing_tables' - - local ignore_arguments = { - class=true, - endpoint=true, - pattern=true, - value=true, - group=true, - phrase=true, - } - - for index, routing_entry in pairs(self.routing_table.inbound) do - local route = common.routing_tables.match_route(routing_entry, number); - if route.error then - self.log:error('ROUTE_INBOUND - error: ', route.error); - elseif route.value then - local valid_route = true; - - for argument, value in pairs(route) do - if not ignore_arguments[argument] then - local table_value = common.str.downcase(tostring(common.str.try(caller, argument))); - value = common.str.downcase(tostring(value)); - if table_value:match(value) then - self.log:info('ROUTE_INBOUND_POSITIVE - ', argument, '=', value, ' ~ ', table_value, ', pattern: ', route.pattern); - else - self.log:info('ROUTE_INBOUND_NEGATIVE - ', argument, '=', value, ' !~ ', table_value, ', pattern: ', route.pattern); - valid_route = false; - end - end - end - - if route.class and route.endpoint then - if route.class == 'gateway' and caller.gateway_name:match(route.endpoint) then - self.log:info('ROUTE_INBOUND_POSITIVE - ', route.class, '=', route.endpoint, ' ~ ', caller.gateway_name, ', pattern: ', route.pattern); - else - self.log:info('ROUTE_INBOUND_NEGATIVE - ', route.class, '=', route.endpoint, ' !~ ', caller.gateway_name, ', pattern: ', route.pattern); - valid_route = false; - end - end - - if valid_route then - self.log:info('ROUTE_INBOUND - called number: ', number, ', value: ', route.value, ', pattern: ', route.pattern); - return route; - end - end - end -end - --- find caller id -function Route.caller_id(self, caller, cid_entry, search_str, endpoint, class) - local ignore_arguments = { - class=true, - endpoint=true, - pattern=true, - value=true, - group=true, - phrase=true, - } - - local route = common.routing_tables.match_route(cid_entry, search_str, self.expandable); - if route.error then - self.log:error('CALLER_ID - error: ', route.error); - elseif route.value then - local valid_route = true; - - for argument, value in pairs(route) do - if not ignore_arguments[argument] then - local table_value = common.str.downcase(tostring(common.str.try(caller, argument))); - value = common.str.downcase(tostring(value)); - if table_value:match(value) then - self.log:debug('CALLER_ID_POSITIVE - ', argument, '=', value, ' ~ ', table_value, ', pattern: ', route.pattern); - else - self.log:debug('CALLER_ID_NEGATIVE - ', argument, '=', value, ' !~ ', table_value, ', pattern: ', route.pattern); - valid_route = false; - end - end - end - - if route.group then - if common.str.try(caller.auth_account, 'owner.groups.' .. tostring(route.group)) then - self.log:debug('CALLER_ID_POSITIVE - group=', route.group, ', pattern: ', route.pattern); - else - self.log:debug('CALLER_ID_NEGATIVE - group=', route.group, ', pattern: ', route.pattern); - valid_route = false; - end - end - - endpoint = tostring(endpoint); - if route.class and route.endpoint then - if route.class == 'gateway' and endpoint:match(route.endpoint) then - self.log:debug('CALLER_ID_POSITIVE - ', route.class, '=', route.endpoint, ' ~ ', endpoint, ', pattern: ', route.pattern); - else - self.log:debug('CALLER_ID_NEGATIVE - ', route.class, '=', route.endpoint, ' !~ ', endpoint, ', pattern: ', route.pattern); - valid_route = false; - end - end - - if valid_route then - self.log:debug('CALLER_ID ', route.class, '=', route.endpoint, ', value: ', route.value); - return route.value; - end - end - - return nil; -end - --- find matching caller id number -function Route.outbound_cid_number(self, caller, caller_id_numbers, endpoint, class) - for route_index, cid_entry in pairs(self.routing_table.outbound_cid_number) do - for index, number in ipairs(caller_id_numbers) do - local route = self:caller_id(caller, cid_entry, number, endpoint, class); - if route then - return route; - end - end - end -end - --- find matching caller id name -function Route.outbound_cid_name(self, caller, endpoint, class) - for route_index, cid_entry in pairs(self.routing_table.outbound_cid_name) do - local route = self:caller_id(caller, cid_entry, caller.caller_id_name, endpoint, class); - if route then - return route; - end - end -end - --- find matching caller id number -function Route.inbound_cid_number(self, caller, endpoint, class) - for route_index, cid_entry in pairs(self.routing_table.inbound_cid_number) do - local route = self:caller_id(caller, cid_entry, caller.caller_id_number, endpoint, class); - if route then - return route; - end - end -end - --- find matching caller id name -function Route.inbound_cid_name(self, caller, endpoint, class) - for route_index, cid_entry in pairs(self.routing_table.inbound_cid_name) do - local route = self:caller_id(caller, cid_entry, caller.caller_id_name, endpoint, class); - if route then - return route; - end - end -end -- cgit v1.2.3 From 23886159814997bff0afd4ac493657ff9f451500 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 20 Jan 2013 16:24:18 +0100 Subject: log line --- misc/freeswitch/scripts/dialplan/hunt_group.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/hunt_group.lua b/misc/freeswitch/scripts/dialplan/hunt_group.lua index 07f403e..2c73bf8 100644 --- a/misc/freeswitch/scripts/dialplan/hunt_group.lua +++ b/misc/freeswitch/scripts/dialplan/hunt_group.lua @@ -104,8 +104,6 @@ function HuntGroup.run(self, dialplan_object, caller, destination) for index, hunt_group_member in ipairs(hunt_group_members) do local destination = dialplan_object:destination_new{ number = hunt_group_member.number }; if destination.type == 'unknown' then - self.log:notice('HG_DESTINATION - number: ', destination.number, ', hunt_group_member.number: ', hunt_group_member.number); - caller.destination_number = destination.number; -- cgit v1.2.3 From f916b83b562edf5a3961fbbba107840c343a53a1 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 21 Jan 2013 13:01:35 +0100 Subject: set caller.destination_number from destination.number --- misc/freeswitch/scripts/dialplan/dialplan.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index cc222fc..b92dc70 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -1004,6 +1004,7 @@ function Dialplan.run(self, destination) self.log:info('LOOP ', loop, ' NEW_DESTINATION_NUMBER - number: ', result.number ); destination = self:destination_new{ number = result.number } self.caller.destination = destination; + self.caller.destination_number = destination.number; end end -- cgit v1.2.3 From 495bbfdf78206c8adaec057e83900dda6754092c Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 21 Jan 2013 23:21:48 +0100 Subject: order and limit added to redial query --- misc/freeswitch/scripts/dialplan/functions.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index 3fa1589..2ca51c8 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -516,7 +516,13 @@ function Functions.redial(self, caller) return { continue = false, code = 403, phrase = 'Incompatible caller', no_cdr = true } end - local sql_query = 'SELECT `destination_number` FROM `call_histories` WHERE `entry_type` = "dialed" AND `call_historyable_type` = "SipAccount" AND `call_historyable_id` = ' .. caller_sip_account.record.id; + local sql_query = 'SELECT `destination_number` \ + FROM `call_histories` \ + WHERE `entry_type` = "dialed" \ + AND `call_historyable_type` = "SipAccount" \ + AND `call_historyable_id` = ' .. caller_sip_account.record.id .. ' \ + ORDER BY `start_stamp` DESC LIMIT 1'; + local phone_number = self.database:query_return_value(sql_query); common_str = require 'common.str'; -- cgit v1.2.3