From 79a1a0013c9dfb8701c06221ab99c604eb2fd211 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 2 Jan 2013 08:28:30 +0100 Subject: Changed defaults and added some basic docu. --- misc/freeswitch/scripts/ini/dialplan.ini | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/ini/dialplan.ini b/misc/freeswitch/scripts/ini/dialplan.ini index aab8353..2e8914a 100644 --- a/misc/freeswitch/scripts/ini/dialplan.ini +++ b/misc/freeswitch/scripts/ini/dialplan.ini @@ -10,5 +10,11 @@ ringtone_url = http://192.168.0.150 ringback = %(2000,4000,440.0,480.0) tone_busy = %(500,500,480,620);loops=4 +; This one activates the lookup of phone numbers in +; the stored phone books. For incoming calls. phonebook_number_lookup = true -geo_number_lookup = true \ No newline at end of file + +; This one activates adding the Cityname for incoming +; phone calls from Germany which are not in any +; phone book. +geo_number_lookup = false \ No newline at end of file -- cgit v1.2.3 From 16e326c0b62cd319b48c6a6201127857de019585 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 3 Jan 2013 12:29:00 +0100 Subject: comment --- misc/freeswitch/scripts/ini/dialplan.ini | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/ini/dialplan.ini b/misc/freeswitch/scripts/ini/dialplan.ini index 2e8914a..e081055 100644 --- a/misc/freeswitch/scripts/ini/dialplan.ini +++ b/misc/freeswitch/scripts/ini/dialplan.ini @@ -11,10 +11,9 @@ ringback = %(2000,4000,440.0,480.0) tone_busy = %(500,500,480,620);loops=4 ; This one activates the lookup of phone numbers in -; the stored phone books. For incoming calls. +; the stored phone books. phonebook_number_lookup = true -; This one activates adding the Cityname for incoming -; phone calls from Germany which are not in any -; phone book. -geo_number_lookup = false \ No newline at end of file +; This option controls city, country or operator number lookup for +; all numbers not resolved by "phonebook_number_lookup" +geo_number_lookup = false -- cgit v1.2.3 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') 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 04bb4f1ae86bfa0cc495b38e45bb017662cedd37 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 4 Jan 2013 11:46:21 +0100 Subject: persistent clir --- misc/freeswitch/scripts/ini/routes.ini | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/ini/routes.ini b/misc/freeswitch/scripts/ini/routes.ini index 1334e7b..6f9c44c 100644 --- a/misc/freeswitch/scripts/ini/routes.ini +++ b/misc/freeswitch/scripts/ini/routes.ini @@ -12,7 +12,9 @@ ^#0#$ , f-lo ^%*30#$ , f-clipon ^#30#$ , f-clipoff -^%*31#(%d+)$ , f-dclirof, f-%1 +^%*31#$ , f-cliroff +^#31#$ , f-cliron +^%*31#(%d+)$ , f-dcliroff-%1 ^#31#(%d+)$ , f-dcliron-%1 ^%*43#$ , f-cwaon ^#43#$ , f-cwaoff @@ -52,7 +54,6 @@ [outbound] ^%+(%d+)$ , class=gateway, endpoint=gateway1, group=users, %1 -^([1-9]%d+)$ , class=gateway, endpoint=gateway1, group=users, %1 [failover] -- 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') 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 380a4cdfe5cfa573fb916ca7c2145a6062ef8198 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 4 Jan 2013 12:28:53 +0100 Subject: redial star code added --- misc/freeswitch/scripts/ini/routes.ini | 1 + 1 file changed, 1 insertion(+) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/ini/routes.ini b/misc/freeswitch/scripts/ini/routes.ini index 6f9c44c..46c7cd8 100644 --- a/misc/freeswitch/scripts/ini/routes.ini +++ b/misc/freeswitch/scripts/ini/routes.ini @@ -42,6 +42,7 @@ ^%*%*67%*(%d+)#$ , f-cfb-%1 ^#67#$ , f-cfboff ^##67#$ , f-cfbdel +^%*66#$ , f-redial ^%*98$ , f-vmcheck ^%*98#$ , f-vmcheck ^%*98%*(%d+)#$ , f-vmcheck-%1 -- cgit v1.2.3 From 27c1304450fc5ab4b25c92cfea7878d45eb93989 Mon Sep 17 00:00:00 2001 From: spag Date: Sat, 5 Jan 2013 10:51:28 +0100 Subject: acd membership toggling start code added --- misc/freeswitch/scripts/ini/routes.ini | 1 + 1 file changed, 1 insertion(+) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/ini/routes.ini b/misc/freeswitch/scripts/ini/routes.ini index 46c7cd8..33d2f38 100644 --- a/misc/freeswitch/scripts/ini/routes.ini +++ b/misc/freeswitch/scripts/ini/routes.ini @@ -10,6 +10,7 @@ ^%*0%*(%d+)#*$ , f-li-%1 ^%*0%*(%d+)%*(%d+)#*$ , f-li-%1-%2 ^#0#$ , f-lo +^%*5%*(%d+)#$ , f-acdmtg-0-%1 ^%*30#$ , f-clipon ^#30#$ , f-clipoff ^%*31#$ , f-cliroff -- 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') 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') 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') 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/conf/freeswitch.xml | 2 +- misc/freeswitch/scripts/dialplan/voicemail.lua | 2 +- misc/freeswitch/scripts/send_fax.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml index 04369a7..ca452fc 100644 --- a/misc/freeswitch/conf/freeswitch.xml +++ b/misc/freeswitch/conf/freeswitch.xml @@ -636,7 +636,7 @@ - + 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(); diff --git a/misc/freeswitch/scripts/send_fax.lua b/misc/freeswitch/scripts/send_fax.lua index 321a5b1..ec9a8be 100644 --- a/misc/freeswitch/scripts/send_fax.lua +++ b/misc/freeswitch/scripts/send_fax.lua @@ -2,7 +2,7 @@ -- (c) AMOOMA GmbH 2012 -- -local FAX_FILE_PATH = "/opt/GS5/public/uploads/fax_document/tiff/"; +local FAX_FILE_PATH = "/opt/gemeinschaft/public/uploads/fax_document/tiff/"; local FAX_ANSWERING_TIMEOUT = 20; -- Set logger -- cgit v1.2.3 From 4de1d1591f5d25d35fe5192808be832676f3d7a4 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Tue, 8 Jan 2013 05:01:44 +0100 Subject: Change fax spool-dir to /var/spool/freeswitch and correct header name --- misc/freeswitch/conf/freeswitch.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml index ca452fc..13c2954 100644 --- a/misc/freeswitch/conf/freeswitch.xml +++ b/misc/freeswitch/conf/freeswitch.xml @@ -635,8 +635,8 @@ - - + + -- 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') 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') 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 +- misc/freeswitch/scripts/send_fax.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'misc/freeswitch') 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(); diff --git a/misc/freeswitch/scripts/send_fax.lua b/misc/freeswitch/scripts/send_fax.lua index ec9a8be..321a5b1 100644 --- a/misc/freeswitch/scripts/send_fax.lua +++ b/misc/freeswitch/scripts/send_fax.lua @@ -2,7 +2,7 @@ -- (c) AMOOMA GmbH 2012 -- -local FAX_FILE_PATH = "/opt/gemeinschaft/public/uploads/fax_document/tiff/"; +local FAX_FILE_PATH = "/opt/GS5/public/uploads/fax_document/tiff/"; local FAX_ANSWERING_TIMEOUT = 20; -- Set logger -- cgit v1.2.3 From 7b749f8b5f4e01852a25a7cd0a65a9c00476b60d Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 9 Jan 2013 11:06:49 +0100 Subject: read database configuration from odbc.ini --- misc/freeswitch/scripts/common/database.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/database.lua b/misc/freeswitch/scripts/common/database.lua index 3692f84..22a68fb 100644 --- a/misc/freeswitch/scripts/common/database.lua +++ b/misc/freeswitch/scripts/common/database.lua @@ -24,13 +24,13 @@ function Database.connect(self, database_name, user_name, password, host_name) local database_driver = nil; if not (database_name and user_name and password) then require 'common.configuration_file' - local config = common.configuration_file.get('/opt/freeswitch/scripts/ini/database.ini'); + local config = common.configuration_file.get('/var/lib/freeswitch/.odbc.ini'); if config then - database_driver = config[true].driver - database_name = config[database_driver].database - user_name = config[database_driver].user - password = config[database_driver].password - host_name = config[database_driver].host + database_driver = config.gemeinschaft.driver + database_name = config.gemeinschaft.DATABASE + user_name = config.gemeinschaft.USER + password = config.gemeinschaft.PASSWORD + host_name = config.gemeinschaft.HOST end end -- cgit v1.2.3 From d968c1f9a6933c3e5d2b2f16d38d656edb6fe152 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 9 Jan 2013 11:08:00 +0100 Subject: configuration_table added --- .../scripts/common/configuration_table.lua | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 misc/freeswitch/scripts/common/configuration_table.lua (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/configuration_table.lua b/misc/freeswitch/scripts/common/configuration_table.lua new file mode 100644 index 0000000..afb5b0e --- /dev/null +++ b/misc/freeswitch/scripts/common/configuration_table.lua @@ -0,0 +1,39 @@ +-- Gemeinschaft 5 module: configuration table +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +-- retrieve configuration from database +function get(database, entity, section) + if not database or not entity then + return {}; + end + + require 'common.str' + + local sql_query = 'SELECT * FROM `gs_parameters` WHERE `entity` = "' .. entity .. '"'; + if section then + sql_query = sql_query .. ' AND `section` = "' .. section .. '"'; + end + + local root = {} + local parameter_class = ''; + + database:query(sql_query, function(parameters) + if not root[parameters.section] then + root[parameters.section] = {}; + end + parameter_class = tostring(parameters.class_type):lower(); + + if parameter_class == 'boolean' then + root[parameters.section][parameters.name] = common.str.to_b(parameters.value); + elseif parameter_class == 'integer' then + root[parameters.section][parameters.name] = common.str.to_i(parameters.value); + else + root[parameters.section][parameters.name] = tostring(parameters.value); + end + end) + + return root; +end -- 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 ++++++------ misc/freeswitch/scripts/dialplan_default.lua | 20 +++++++++----------- 2 files changed, 15 insertions(+), 17 deletions(-) (limited to 'misc/freeswitch') 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'; diff --git a/misc/freeswitch/scripts/dialplan_default.lua b/misc/freeswitch/scripts/dialplan_default.lua index ee4a88f..91ad4e4 100644 --- a/misc/freeswitch/scripts/dialplan_default.lua +++ b/misc/freeswitch/scripts/dialplan_default.lua @@ -23,10 +23,18 @@ log = common.log.Log:new{ prefix = '### [' .. session:get_uuid() .. '] ' }; require 'dialplan.session' start_caller = dialplan.session.Session:new{ log = log, session = session }; +-- connect to database +require 'common.database' +local database = common.database.Database:new{ log = log }:connect(); +if not database:connected() then + log:critical('DIALPLAN_DEFAULT - database connect failed'); + return; +end + -- dialplan object require 'dialplan.dialplan' -start_dialplan = dialplan.dialplan.Dialplan:new{ log = log, caller = start_caller }; +start_dialplan = dialplan.dialplan.Dialplan:new{ log = log, caller = start_caller, database = database }; start_dialplan:configuration_read(); start_caller.local_node_id = start_dialplan.node_id; start_caller:init_channel_variables(); @@ -39,16 +47,6 @@ if not start_dialplan:check_auth() then return false; end --- connect to database -require 'common.database' -local database = common.database.Database:new{ log = log }:connect(); -if not database:connected() then - log:critical('DIALPLAN_DEFAULT - database connect failed'); - return; -end - -start_dialplan.database = database; - if start_caller.from_node and not start_dialplan:check_auth_node() then log:debug('AUTHENTICATION_REQUIRED_NODE - node_id: ', start_caller.node_id, ', domain: ', start_dialplan.domain); start_dialplan:hangup(407, start_dialplan.domain); -- cgit v1.2.3 From a93f71d0c74c51ef744ed9a0b7152ca20160420e Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 9 Jan 2013 12:40:36 +0100 Subject: db based configuration --- misc/freeswitch/scripts/configuration.lua | 29 +++++++++++++--------- .../scripts/configuration/freeswitch_xml.lua | 9 +++---- 2 files changed, 21 insertions(+), 17 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index 906d3f8..d7fd105 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -22,6 +22,7 @@ function nodes(database, local_node_id) end function gateways(profile_name) + require 'common.configuration_file' local gateways_xml = ''; local gateways = common.configuration_file.get('/opt/freeswitch/scripts/ini/gateways.ini', false); @@ -69,31 +70,32 @@ end -- generate sofia.conf function conf_sofia(database) + require 'common.configuration_table' local sofia_profile = "gemeinschaft"; - require 'common.configuration_file' - local sofia_ini = common.configuration_file.get('/opt/freeswitch/scripts/ini/sofia.ini'); - local dialplan_parameters = common.configuration_file.get('/opt/freeswitch/scripts/ini/dialplan.ini', 'parameters'); + local sofia_ini = common.configuration_table.get(database, 'sofia'); + local dialplan_parameters = common.configuration_table.get(database, 'dialplan', 'parameters'); - local local_node_id = tonumber(dialplan_parameters['node_id']) or 1; + local local_node_id = tonumber(dialplan_parameters.node_id) or 1; require 'configuration.sip' local domains = configuration.sip.Sip:new{ log = log, database = database}:domains(); sofia_profiles_xml = ''; - for index, profile_name in ipairs(sofia_ini.profiles) do - sofia_profiles_xml = sofia_profiles_xml .. profile(database, sofia_ini, profile_name, index, domains, local_node_id); + for profile_name, index in pairs(sofia_ini.profiles) do + if tonumber(index) and tonumber(index) > 0 then + sofia_profiles_xml = sofia_profiles_xml .. profile(database, sofia_ini, profile_name, tonumber(index), domains, local_node_id); + end end XML_STRING = xml:document(xml:sofia(sofia_ini.parameters, sofia_profiles_xml)) end function conf_conference(database) + require 'common.configuration_table' XML_STRING = xml:document(xml:conference()); - require 'common.configuration_file' - local conference_ini = common.configuration_file.get('/opt/freeswitch/scripts/ini/conferences.ini'); - local conference_parameters = conference_ini.parameters; + local conference_parameters = common.configuration_table.get(database, 'conferences', 'parameters'); local event_name = params:getHeader("Event-Name") if event_name == 'COMMAND' then @@ -140,15 +142,18 @@ function directory_sip_account(database) log:debug('DIRECTORY_GATEWAY - gateway not found - name: ', gateway_name, ', auth_name: ', auth_name); end else + require 'common.configuration_table' + local user_params = common.configuration_table.get(database, 'sip_accounts', 'parameters'); + require 'common.sip_account' local sip_account = common.sip_account.SipAccount:new{ log = log, database = database}:find_by_auth_name(auth_name, domain); if sip_account ~= nil then if tostring(purpose) == 'publish-vm' then log:debug('DIRECTORY_SIP_ACCOUNT - purpose: VoiceMail, auth_name: ', sip_account.record.auth_name, ', caller_name: ', sip_account.record.caller_name, ', domain: ', domain); - XML_STRING = xml:document(xml:directory(xml:group_default(xml:user(sip_account.record)), domain)); + XML_STRING = xml:document(xml:directory(xml:group_default(xml:user(sip_account.record, user_params)), domain)); else log:debug('DIRECTORY_SIP_ACCOUNT - auth_name: ', sip_account.record.auth_name, ', caller_name: ', sip_account.record.caller_name, ', domain: ', domain); - XML_STRING = xml:document(xml:directory(xml:user(sip_account.record), domain)); + XML_STRING = xml:document(xml:directory(xml:user(sip_account.record, user_params), domain)); end else log:debug('DIRECTORY_SIP_ACCOUNT - sip account not found - auth_name: ', auth_name, ', domain: ', domain); @@ -164,7 +169,7 @@ function directory_sip_account(database) sip_accountable_type = 'none', sip_accountable_id = 0, } - XML_STRING = xml:document(xml:directory(xml:user(sip_account), domain)) + XML_STRING = xml:document(xml:directory(xml:user(sip_account, user_params), domain)) end end elseif tostring(XML_REQUEST.key_name) == 'name' and tostring(XML_REQUEST.key_value) ~= '' then diff --git a/misc/freeswitch/scripts/configuration/freeswitch_xml.lua b/misc/freeswitch/scripts/configuration/freeswitch_xml.lua index c81bf50..5f4602c 100644 --- a/misc/freeswitch/scripts/configuration/freeswitch_xml.lua +++ b/misc/freeswitch/scripts/configuration/freeswitch_xml.lua @@ -13,11 +13,11 @@ function FreeSwitchXml.new(self, object) end function FreeSwitchXml.param(self, name, value) - return '' + return '' end function FreeSwitchXml.variable(self, name, value) - return '' + return '' end function FreeSwitchXml.document(self, sections_xml) @@ -78,9 +78,8 @@ function FreeSwitchXml.group_default(self, entries_xml) return xml_string end -function FreeSwitchXml.user(self, user) - require 'common.configuration_file' - local params = common.configuration_file.get('/opt/freeswitch/scripts/ini/sip_accounts.ini', 'parameters'); +function FreeSwitchXml.user(self, user, params) + params = params or {}; params['password'] = user.password; params['vm-password'] = user.voicemail_pin; -- cgit v1.2.3 From a1e1ad4fc578042613df891ea25971b8fc045edc Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 9 Jan 2013 13:37:13 +0100 Subject: remove parent --- misc/freeswitch/scripts/common/configuration_table.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/configuration_table.lua b/misc/freeswitch/scripts/common/configuration_table.lua index afb5b0e..731bf2f 100644 --- a/misc/freeswitch/scripts/common/configuration_table.lua +++ b/misc/freeswitch/scripts/common/configuration_table.lua @@ -35,5 +35,9 @@ function get(database, entity, section) end end) + if section then + return root[section]; + end + return root; end -- cgit v1.2.3 From 706d34820b236d28e7dd12ba90dfc1dd585d698f Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 9 Jan 2013 13:54:03 +0100 Subject: read event_manager configuration from database --- misc/freeswitch/scripts/event/event.lua | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/event/event.lua b/misc/freeswitch/scripts/event/event.lua index 8e67bc9..c57b32a 100644 --- a/misc/freeswitch/scripts/event/event.lua +++ b/misc/freeswitch/scripts/event/event.lua @@ -28,10 +28,8 @@ end function EventManager.load_event_modules(self) - local CONFIG_FILE_NAME = '/opt/freeswitch/scripts/ini/events.ini'; - - require 'common.configuration_file' - self.config = common.configuration_file.get(CONFIG_FILE_NAME); + require 'common.configuration_table' + self.config = common.configuration_table.get(self.database, 'events'); return self.config.modules; end @@ -40,7 +38,7 @@ end function EventManager.load_event_handlers(self, event_modules) event_handlers = {} - for index, event_module_name in ipairs(event_modules) do + for event_module_name, index in pairs(event_modules) do event_module = require('event.' .. event_module_name); if event_module then self.log:info('[event] EVENT_MANAGER - loading handler module: ', event_module_name); -- cgit v1.2.3 From fb686a23421652f938c1ac5b6368d6f5918a15f5 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 9 Jan 2013 13:54:33 +0100 Subject: read perimeter configuration from database --- misc/freeswitch/scripts/event/perimeter.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/event/perimeter.lua b/misc/freeswitch/scripts/event/perimeter.lua index 3babba6..86c50d4 100644 --- a/misc/freeswitch/scripts/event/perimeter.lua +++ b/misc/freeswitch/scripts/event/perimeter.lua @@ -40,7 +40,8 @@ end function Perimeter.init(self) - local config = common.configuration_file.get('/opt/freeswitch/scripts/ini/perimeter.ini'); + require 'common.configuration_table'; + local config = common.configuration_table.get(self.database, 'perimeter'); if config and config.general then self.malicious_contact_count = tonumber(config.general.malicious_contact_count) or MALICIOUS_CONTACT_COUNT; self.malicious_contact_time_span = tonumber(config.general.malicious_contact_time_span) or MALICIOUS_CONTACT_TIME_SPAN; -- cgit v1.2.3 From c317b518e0431db624f5e8e66aa00e7d0ff1a291 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 9 Jan 2013 19:26:53 +0100 Subject: set default odbc dsn --- misc/freeswitch/scripts/configuration.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index d7fd105..d0e2268 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -47,6 +47,11 @@ function profile(database, sofia_ini, profile_name, index, domains, node_id) log:error('SOFIA_PROFILE ', index,' - name: ', profile_name, ' - no parameters'); return ''; end + + if tostring(profile_parameters['odbc-dsn']) == 'default' then + profile_parameters['odbc-dsn'] = 'gemeinschaft:' .. tostring(database.user_name) .. ':' .. tostring(database.password); + end + -- set local bind address if domains[index] then profile_parameters['sip-ip'] = domains[index]['host']; -- cgit v1.2.3 From edd484c7936db3995e0e8e2bd93b6115aa7554fa Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 10 Jan 2013 10:03:08 +0100 Subject: method generic added --- .../scripts/configuration/freeswitch_xml.lua | 50 +++++++++++++++------- 1 file changed, 35 insertions(+), 15 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration/freeswitch_xml.lua b/misc/freeswitch/scripts/configuration/freeswitch_xml.lua index 5f4602c..3da76df 100644 --- a/misc/freeswitch/scripts/configuration/freeswitch_xml.lua +++ b/misc/freeswitch/scripts/configuration/freeswitch_xml.lua @@ -12,12 +12,8 @@ function FreeSwitchXml.new(self, object) return object end -function FreeSwitchXml.param(self, name, value) - return '' -end - -function FreeSwitchXml.variable(self, name, value) - return '' +function FreeSwitchXml.nv_tag(self, name, value, tag) + return '<' .. tostring(tag) .. ' name="' .. tostring(name) .. '" value="' .. tostring(value) .. '"/>' end function FreeSwitchXml.document(self, sections_xml) @@ -98,12 +94,12 @@ function FreeSwitchXml.user(self, user, params) local params_xml = {} for name, value in pairs(params) do - params_xml[#params_xml+1] = self:param(name, value) + params_xml[#params_xml+1] = self:nv_tag(name, value, 'param') end local variables_xml = {} for name, value in pairs(variables) do - variables_xml[#variables_xml+1] = self:variable(name, value) + variables_xml[#variables_xml+1] = self:nv_tag(name, value, 'variable') end local xml_string = @@ -137,12 +133,12 @@ function FreeSwitchXml.gateway_user(self, user, gateway_name, auth_name) local params_xml = {} for name, value in pairs(params) do - params_xml[#params_xml+1] = self:param(name, value) + params_xml[#params_xml+1] = self:nv_tag(name, value, 'param') end local variables_xml = {} for name, value in pairs(variables) do - variables_xml[#variables_xml+1] = self:variable(name, value) + variables_xml[#variables_xml+1] = self:nv_tag(name, value, 'variable') end local xml_string = @@ -169,7 +165,7 @@ function FreeSwitchXml.sofia(self, parameters, profiles_xml) local params_xml = {} for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:param(name, value) + params_xml[#params_xml+1] = self:nv_tag(name, value, 'param') end local xml_string = @@ -192,7 +188,7 @@ end function FreeSwitchXml.sofia_profile(self, profile_name, parameters, gateways_xml) params_xml = {} for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:param(name, value) + params_xml[#params_xml+1] = self:nv_tag(name, value, 'param') end if type(gateways_xml) == "string" then @@ -225,7 +221,7 @@ function FreeSwitchXml.gateway(self, gateway_name, parameters) local params_xml = {} if parameters then for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:param(name, value) + params_xml[#params_xml+1] = self:nv_tag(name, value, 'param') end end @@ -291,9 +287,9 @@ function FreeSwitchXml.conference(self, profiles_xml) end function FreeSwitchXml.conference_profile(self, profile_name, parameters) - params_xml = {} + local params_xml = {} for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:param(name, value) + params_xml[#params_xml+1] = self:nv_tag(name, value, 'param') end local xml_string = @@ -304,3 +300,27 @@ function FreeSwitchXml.conference_profile(self, profile_name, parameters) ]] return xml_string end + +function FreeSwitchXml.generic(self, arg) + local params_xml = arg.params_xml or {}; + local params_tag = arg.params_tag or 'settings'; + local parameter_tag = arg.parameter_tag or 'param'; + + if arg.parameters then + for name, value in pairs(arg.parameters) do + params_xml[#params_xml+1] = self:nv_tag(name, value, parameter_tag) + end + end + + local xml_string = +[[ +
+ +<]] .. tostring(params_tag) .. [[> +]] .. table.concat(params_xml, "\n") .. [[ + + + +
]] + return xml_string +end -- cgit v1.2.3 From 957e0b70fc7500ca7eac9eb385d29e8c395198f7 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 10 Jan 2013 10:04:18 +0100 Subject: post_load_switch.conf added --- misc/freeswitch/scripts/configuration.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index d0e2268..41c1523 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -125,6 +125,13 @@ function conf_conference(database) end end +function conf_post_switch(database) + require 'common.configuration_table'; + local parameters = common.configuration_table.get(database, 'post_load_switch', 'settings'); + + XML_STRING = xml:document(xml:generic{name = 'post_load_switch.conf', parameters = parameters}); +end + function directory_sip_account(database) local key = params:getHeader('key'); @@ -213,6 +220,8 @@ if XML_REQUEST.section == 'configuration' and XML_REQUEST.tag_name == 'configura conf_sofia(database); elseif XML_REQUEST.key_value == "conference.conf" then conf_conference(database); + elseif XML_REQUEST.key_value == "post_load_switch.conf" then + conf_post_switch(database); end elseif XML_REQUEST.section == 'directory' and XML_REQUEST.tag_name == '' then log:debug('SIP_ACCOUNT_DIRECTORY - initialization phase'); -- cgit v1.2.3 From 171a2317964f54a9b743eaa77b02d1119bee070c Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 10 Jan 2013 12:27:17 +0100 Subject: old database class removed --- misc/freeswitch/scripts/common/database.lua | 151 ---------------------------- 1 file changed, 151 deletions(-) delete mode 100644 misc/freeswitch/scripts/common/database.lua (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/database.lua b/misc/freeswitch/scripts/common/database.lua deleted file mode 100644 index 22a68fb..0000000 --- a/misc/freeswitch/scripts/common/database.lua +++ /dev/null @@ -1,151 +0,0 @@ --- Gemeinschaft 5 module: database class --- (c) AMOOMA GmbH 2012 --- - -module(...,package.seeall) - -Database = {} - -DATABASE_DRIVER = 'mysql' - -function Database.new(self, arg) - arg = arg or {} - object = arg.object or {} - setmetatable(object, self); - self.__index = self; - self.class = 'database'; - self.log = arg.log; - self.conn = nil; - return object; -end - - -function Database.connect(self, database_name, user_name, password, host_name) - local database_driver = nil; - if not (database_name and user_name and password) then - require 'common.configuration_file' - local config = common.configuration_file.get('/var/lib/freeswitch/.odbc.ini'); - if config then - database_driver = config.gemeinschaft.driver - database_name = config.gemeinschaft.DATABASE - user_name = config.gemeinschaft.USER - password = config.gemeinschaft.PASSWORD - host_name = config.gemeinschaft.HOST - end - end - - host_name = host_name or 'localhost'; - database_driver = database_driver or DATABASE_DRIVER; - - if database_driver == 'mysql' then - require "luasql.mysql" - self.env = luasql.mysql(); - elseif database_driver == 'odbc' then - require "luasql.odbc" - self.env = luasql.odbc(); - end - - self.conn = self.env:connect(database_name, user_name, password, host_name); - self.conn_id = tostring(self.conn); - self.database_name = database_name; - self.user_name = user_name; - self.password = password; - self.host_name = host_name; - - -- self.log:debug('DATABASE_CONNECT - connection: ', self.conn_id, ', environment: ', self.env); - - return self; -end - - -function Database.reconnect(self) - self.conn = self.env:connect(self.database_name, self.user_name, self.password, self.host_name); - self.conn_id = tostring(self.conn); - - if self.log then - self.log:info('DATABASE_RECONNECT - connection: ', self.conn_id, ', environment: ', self.env); - end - - return self; -end - - -function Database.connected(self) - return self.conn; -end - - -function Database.query(self, sql_query, call_function) - local cursor = self.conn:execute(sql_query); - - if cursor == nil and not self.conn:execute('SELECT @@VERSION') then - if self.log then - self.log:error('DATABASE_QUERY - lost connection: ', self.conn_id, ', environment: ', self.env, ', query: ', sql_query); - end - self:reconnect(); - - if call_function then - cursor = self.conn:execute(sql_query); - self.log:notice('DATABASE_QUERY - retry: ', sql_query); - end - end - - if cursor and call_function then - repeat - row = cursor:fetch({}, 'a'); - if row then - call_function(row); - end - until not row; - end - - if type(cursor) == 'userdata' then - cursor:close(); - end - - return cursor; -end - - -function Database.query_return_value(self, sql_query) - local cursor = self.conn:execute(sql_query); - - if cursor == nil and not self.conn:execute('SELECT @@VERSION') then - if self.log then - self.log:error('DATABASE_QUERY - lost connection: ', self.conn_id, ', environment: ', self.env, ', query: ', sql_query); - end - self:reconnect(); - cursor = self.conn:execute(sql_query); - self.log:notice('DATABASE_QUERY - retry: ', sql_query); - end - - if type(cursor) == 'userdata' then - local row = cursor:fetch({}, 'n'); - cursor:close(); - - if not row then - return row; - else - return row[1]; - end - end - - return cursor; -end - - -function Database.last_insert_id(self) - return self:query_return_value('SELECT LAST_INSERT_ID()'); -end - - -function Database.release(self, sql_query, call_function) - if self.conn then - self.conn:close(); - end - if self.env then - self.env:close(); - end - - -- self.log:debug('DATABASE_RELEASE - connection: ', self.conn_id, ', status: ', self.env, ', ', self.conn); -end -- cgit v1.2.3 From 7268fbc3b37ae35993a7379cc66221c5e24c2016 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 10 Jan 2013 12:28:06 +0100 Subject: freeswitch odbc database class added --- misc/freeswitch/scripts/common/database.lua | 78 +++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 misc/freeswitch/scripts/common/database.lua (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/database.lua b/misc/freeswitch/scripts/common/database.lua new file mode 100644 index 0000000..1f39135 --- /dev/null +++ b/misc/freeswitch/scripts/common/database.lua @@ -0,0 +1,78 @@ +-- Gemeinschaft 5 module: database class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +Database = {} + +DATABASE_DSN = 'gemeinschaft'; + +function Database.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.class = 'database'; + self.log = arg.log; + self.conn = nil; + return object; +end + + +function Database.connect(self) + self.dsn = DATABASE_DSN; + + require 'common.configuration_file' + local dsn = common.configuration_file.get('/var/lib/freeswitch/.odbc.ini', self.dsn); + + self.database_name = dsn.DATABASE; + self.user_name = dsn.USER; + self.password = dsn.PASSWORD; + self.host_name = dsn.HOST; + + self.conn = freeswitch.Dbh(self.dsn, self.user_name, self.password); + self.conn_id = tostring(self.conn); + + return self; +end + + +function Database.connected(self) + return self.conn:connected(); +end + + +function Database.query(self, sql_query, call_function) + if call_function then + return self.conn:query(sql_query, call_function); + else + return self.conn:query(sql_query); + end +end + + +function Database.query_return_value(self, sql_query) + local result = nil; + + self.conn:query(sql_query, function(row) + for key, value in pairs(row) do + result = value; + return result; + end + end) + + return result; +end + + +function Database.last_insert_id(self) + return self:query_return_value('SELECT LAST_INSERT_ID()'); +end + + +function Database.release(self) + if self.conn then + self.conn:release(); + end +end -- cgit v1.2.3 From 64011eee947e3719dfce524b5c2bae2f8bed4e88 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 10 Jan 2013 13:09:53 +0100 Subject: generic tag method added --- .../scripts/configuration/freeswitch_xml.lua | 35 ++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration/freeswitch_xml.lua b/misc/freeswitch/scripts/configuration/freeswitch_xml.lua index 3da76df..65e7998 100644 --- a/misc/freeswitch/scripts/configuration/freeswitch_xml.lua +++ b/misc/freeswitch/scripts/configuration/freeswitch_xml.lua @@ -12,8 +12,19 @@ function FreeSwitchXml.new(self, object) return object end -function FreeSwitchXml.nv_tag(self, name, value, tag) - return '<' .. tostring(tag) .. ' name="' .. tostring(name) .. '" value="' .. tostring(value) .. '"/>' +function FreeSwitchXml.to_tag(self, arg) + if not arg.tag_name then + return ''; + end + + local xml_tag = '<' .. tostring(arg.tag_name); + for key, value in pairs(arg) do + if tostring(key) ~= 'tag_name' then + xml_tag = xml_tag .. ' ' .. tostring(key) .. '="' .. tostring(value) .. '"'; + end + end + + return xml_tag .. '/>'; end function FreeSwitchXml.document(self, sections_xml) @@ -94,12 +105,12 @@ function FreeSwitchXml.user(self, user, params) local params_xml = {} for name, value in pairs(params) do - params_xml[#params_xml+1] = self:nv_tag(name, value, 'param') + params_xml[#params_xml+1] = self:to_tag{ tag_name = 'param', name = name, value = value }; end local variables_xml = {} for name, value in pairs(variables) do - variables_xml[#variables_xml+1] = self:nv_tag(name, value, 'variable') + variables_xml[#variables_xml+1] = self:to_tag{ tag_name = 'variable', name = name, value = value }; end local xml_string = @@ -133,12 +144,12 @@ function FreeSwitchXml.gateway_user(self, user, gateway_name, auth_name) local params_xml = {} for name, value in pairs(params) do - params_xml[#params_xml+1] = self:nv_tag(name, value, 'param') + params_xml[#params_xml+1] = self:to_tag{ tag_name = 'param', name = name, value = value }; end local variables_xml = {} for name, value in pairs(variables) do - variables_xml[#variables_xml+1] = self:nv_tag(name, value, 'variable') + variables_xml[#variables_xml+1] = self:to_tag{ tag_name = 'variable', name = name, value = value }; end local xml_string = @@ -165,7 +176,7 @@ function FreeSwitchXml.sofia(self, parameters, profiles_xml) local params_xml = {} for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:nv_tag(name, value, 'param') + params_xml[#params_xml+1] = self:to_tag{ tag_name = 'param', name = name, value = value }; end local xml_string = @@ -188,7 +199,7 @@ end function FreeSwitchXml.sofia_profile(self, profile_name, parameters, gateways_xml) params_xml = {} for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:nv_tag(name, value, 'param') + params_xml[#params_xml+1] = self:to_tag{ tag_name = 'param', name = name, value = value }; end if type(gateways_xml) == "string" then @@ -221,7 +232,7 @@ function FreeSwitchXml.gateway(self, gateway_name, parameters) local params_xml = {} if parameters then for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:nv_tag(name, value, 'param') + params_xml[#params_xml+1] = self:to_tag{ tag_name = 'param', name = name, value = value }; end end @@ -234,7 +245,7 @@ function FreeSwitchXml.gateway(self, gateway_name, parameters) return xml_string end -function FreeSwitchXml.conference(self, profiles_xml) +function FreeSwitchXml.conference(self, profiles_xml, speaker, moderator) if type(profiles_xml) == "string" then profiles_xml = { profiles_xml } elseif type(profiles_xml) == "nil" then @@ -289,7 +300,7 @@ end function FreeSwitchXml.conference_profile(self, profile_name, parameters) local params_xml = {} for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:nv_tag(name, value, 'param') + params_xml[#params_xml+1] = self:to_tag{ tag_name = 'param', name = name, value = value }; end local xml_string = @@ -308,7 +319,7 @@ function FreeSwitchXml.generic(self, arg) if arg.parameters then for name, value in pairs(arg.parameters) do - params_xml[#params_xml+1] = self:nv_tag(name, value, parameter_tag) + params_xml[#params_xml+1] = self:to_tag{ tag_name = parameter_tag, name = name, value = value }; end end -- cgit v1.2.3 From 6ce81a29e0918b3494a08fa47190b2cea59d1a84 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 10 Jan 2013 13:37:42 +0100 Subject: nil vs. empty_string --- misc/freeswitch/scripts/common/conference.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/conference.lua b/misc/freeswitch/scripts/common/conference.lua index d2bf829..a7b21c3 100644 --- a/misc/freeswitch/scripts/common/conference.lua +++ b/misc/freeswitch/scripts/common/conference.lua @@ -103,8 +103,9 @@ function Conference.enter(self, caller, domain) end; end + require 'common.str' -- Check if conference is within time frame - if self.record.start and self.record['end'] then + if not common.str.blank(self.record.start) and not common.str.blank(self.record['end']) then local d = {} _,_,d.year,d.month,d.day,d.hour,d.min,d.sec=string.find(self.record.start, "(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)"); @@ -122,7 +123,6 @@ function Conference.enter(self, caller, domain) end end - require 'common.str' -- Owner ist always moderator if (tonumber(self.record.conferenceable_id) == caller.account_owner_id) and (self.record.conferenceable_type == caller.account_owner_type) then table.insert(flags, 'moderator'); -- cgit v1.2.3 From 44059b1cb8348c2ee24e056f81c3380abd55096d Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 10 Jan 2013 14:22:49 +0100 Subject: read conference controls from database --- misc/freeswitch/scripts/configuration.lua | 6 ++-- .../scripts/configuration/freeswitch_xml.lua | 42 ++++++++++------------ 2 files changed, 21 insertions(+), 27 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index 41c1523..0cd3752 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -100,7 +100,7 @@ function conf_conference(database) require 'common.configuration_table' XML_STRING = xml:document(xml:conference()); - local conference_parameters = common.configuration_table.get(database, 'conferences', 'parameters'); + local config = common.configuration_table.get(database, 'conferences'); local event_name = params:getHeader("Event-Name") if event_name == 'COMMAND' then @@ -112,8 +112,8 @@ function conf_conference(database) conference = common.conference.Conference:new{log=log, database=database}:find_by_id(conf_name); if conference then log:debug('CONFIG_CONFERENCE ', conf_name, ' name: ', conference.record.name, ', profile: ', profile_name); - conference_parameters['caller-id-name'] = conference.record.name or ''; - XML_STRING = xml:document(xml:conference(xml:conference_profile(profile_name, conference_parameters))); + config.parameters['caller-id-name'] = conference.record.name or ''; + XML_STRING = xml:document(xml:conference(xml:conference_profile(profile_name, config.parameters), config.controls_speaker, config.controls_moderator)); else log:error('CONFIG_CONFERENCE ', conf_name, ' - conference not found'); end diff --git a/misc/freeswitch/scripts/configuration/freeswitch_xml.lua b/misc/freeswitch/scripts/configuration/freeswitch_xml.lua index 65e7998..09472bf 100644 --- a/misc/freeswitch/scripts/configuration/freeswitch_xml.lua +++ b/misc/freeswitch/scripts/configuration/freeswitch_xml.lua @@ -252,6 +252,20 @@ function FreeSwitchXml.conference(self, profiles_xml, speaker, moderator) profiles_xml = { "" } end + local speaker_xml = {} + if speaker then + for name, value in pairs(speaker) do + speaker_xml[#speaker_xml+1] = self:to_tag{ tag_name = 'control', action = name, digits = value }; + end + end + + local moderator_xml = {} + if moderator then + for name, value in pairs(speaker) do + moderator_xml[#moderator_xml+1] = self:to_tag{ tag_name = 'control', action = name, digits = value }; + end + end + local xml_string = [[
@@ -260,32 +274,12 @@ function FreeSwitchXml.conference(self, profiles_xml, speaker, moderator) - - - - - - - - - - - - +]] .. table.concat(speaker_xml, "\n") .. [[ + - - - - - - - - - - - - +]] .. table.concat(moderator_xml, "\n") .. [[ + -- cgit v1.2.3 From 7326afdd65ae58c7158249c9ea73eaf0db16bbd3 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 10 Jan 2013 16:34:19 +0100 Subject: strip whitespace --- .../freeswitch/scripts/common/configuration_table.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/configuration_table.lua b/misc/freeswitch/scripts/common/configuration_table.lua index 731bf2f..85bc014 100644 --- a/misc/freeswitch/scripts/common/configuration_table.lua +++ b/misc/freeswitch/scripts/common/configuration_table.lua @@ -21,17 +21,20 @@ function get(database, entity, section) local parameter_class = ''; database:query(sql_query, function(parameters) - if not root[parameters.section] then - root[parameters.section] = {}; + local p_section = common.str.strip(parameters.section):lower(); + local p_class_type = common.str.strip(parameters.class_type):lower(); + local p_name = common.str.strip(parameters.name); + + if not root[p_section] then + root[p_section] = {}; end - parameter_class = tostring(parameters.class_type):lower(); - if parameter_class == 'boolean' then - root[parameters.section][parameters.name] = common.str.to_b(parameters.value); - elseif parameter_class == 'integer' then - root[parameters.section][parameters.name] = common.str.to_i(parameters.value); + if p_class_type == 'boolean' then + root[p_section][p_name] = common.str.to_b(parameters.value); + elseif p_class_type == 'integer' then + root[p_section][p_name] = common.str.to_i(parameters.value); else - root[parameters.section][parameters.name] = tostring(parameters.value); + root[p_section][p_name] = tostring(parameters.value); end end) -- cgit v1.2.3 From e8f75901658a648f2cc4e95f49d76f89afceeb33 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 10 Jan 2013 16:41:05 +0100 Subject: generic tags added --- .../scripts/configuration/freeswitch_xml.lua | 38 ++++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration/freeswitch_xml.lua b/misc/freeswitch/scripts/configuration/freeswitch_xml.lua index 09472bf..53ecccf 100644 --- a/misc/freeswitch/scripts/configuration/freeswitch_xml.lua +++ b/misc/freeswitch/scripts/configuration/freeswitch_xml.lua @@ -12,19 +12,21 @@ function FreeSwitchXml.new(self, object) return object end -function FreeSwitchXml.to_tag(self, arg) - if not arg.tag_name then - return ''; - end - local xml_tag = '<' .. tostring(arg.tag_name); +function FreeSwitchXml.tag(self, arg) + local xml_tag = '<' .. tostring(arg._name); for key, value in pairs(arg) do - if tostring(key) ~= 'tag_name' then + if tostring(key) ~= '_name' and tostring(key) ~= '_data' then xml_tag = xml_tag .. ' ' .. tostring(key) .. '="' .. tostring(value) .. '"'; end end + xml_tag = xml_tag .. '>'; + + if arg._data then + xml_tag = xml_tag .. '\n' .. tostring(arg._data) .. '\n'; + end - return xml_tag .. '/>'; + return xml_tag .. ''; end function FreeSwitchXml.document(self, sections_xml) @@ -105,12 +107,12 @@ function FreeSwitchXml.user(self, user, params) local params_xml = {} for name, value in pairs(params) do - params_xml[#params_xml+1] = self:to_tag{ tag_name = 'param', name = name, value = value }; + params_xml[#params_xml+1] = self:tag{ _name = 'param', name = name, value = value }; end local variables_xml = {} for name, value in pairs(variables) do - variables_xml[#variables_xml+1] = self:to_tag{ tag_name = 'variable', name = name, value = value }; + variables_xml[#variables_xml+1] = self:tag{ _name = 'variable', name = name, value = value }; end local xml_string = @@ -144,12 +146,12 @@ function FreeSwitchXml.gateway_user(self, user, gateway_name, auth_name) local params_xml = {} for name, value in pairs(params) do - params_xml[#params_xml+1] = self:to_tag{ tag_name = 'param', name = name, value = value }; + params_xml[#params_xml+1] = self:tag{ _name = 'param', name = name, value = value }; end local variables_xml = {} for name, value in pairs(variables) do - variables_xml[#variables_xml+1] = self:to_tag{ tag_name = 'variable', name = name, value = value }; + variables_xml[#variables_xml+1] = self:tag{ _name = 'variable', name = name, value = value }; end local xml_string = @@ -176,7 +178,7 @@ function FreeSwitchXml.sofia(self, parameters, profiles_xml) local params_xml = {} for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:to_tag{ tag_name = 'param', name = name, value = value }; + params_xml[#params_xml+1] = self:tag{ _name = 'param', name = name, value = value }; end local xml_string = @@ -199,7 +201,7 @@ end function FreeSwitchXml.sofia_profile(self, profile_name, parameters, gateways_xml) params_xml = {} for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:to_tag{ tag_name = 'param', name = name, value = value }; + params_xml[#params_xml+1] = self:tag{ _name = 'param', name = name, value = value }; end if type(gateways_xml) == "string" then @@ -232,7 +234,7 @@ function FreeSwitchXml.gateway(self, gateway_name, parameters) local params_xml = {} if parameters then for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:to_tag{ tag_name = 'param', name = name, value = value }; + params_xml[#params_xml+1] = self:tag{ _name = 'param', name = name, value = value }; end end @@ -255,14 +257,14 @@ function FreeSwitchXml.conference(self, profiles_xml, speaker, moderator) local speaker_xml = {} if speaker then for name, value in pairs(speaker) do - speaker_xml[#speaker_xml+1] = self:to_tag{ tag_name = 'control', action = name, digits = value }; + speaker_xml[#speaker_xml+1] = self:tag{ _name = 'control', action = name, digits = value }; end end local moderator_xml = {} if moderator then for name, value in pairs(speaker) do - moderator_xml[#moderator_xml+1] = self:to_tag{ tag_name = 'control', action = name, digits = value }; + moderator_xml[#moderator_xml+1] = self:tag{ _name = 'control', action = name, digits = value }; end end @@ -294,7 +296,7 @@ end function FreeSwitchXml.conference_profile(self, profile_name, parameters) local params_xml = {} for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:to_tag{ tag_name = 'param', name = name, value = value }; + params_xml[#params_xml+1] = self:tag{ _name = 'param', name = name, value = value }; end local xml_string = @@ -313,7 +315,7 @@ function FreeSwitchXml.generic(self, arg) if arg.parameters then for name, value in pairs(arg.parameters) do - params_xml[#params_xml+1] = self:to_tag{ tag_name = parameter_tag, name = name, value = value }; + params_xml[#params_xml+1] = self:tag{ _name = parameter_tag, name = name, value = value }; end end -- cgit v1.2.3 From bf0976bf84a8a25c69ce9a36b28e1f74ccc42030 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 10 Jan 2013 16:41:32 +0100 Subject: voicemail configuration --- misc/freeswitch/scripts/configuration.lua | 41 +++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index 0cd3752..ec5099e 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -98,9 +98,9 @@ end function conf_conference(database) require 'common.configuration_table' - XML_STRING = xml:document(xml:conference()); - + local config = common.configuration_table.get(database, 'conferences'); + XML_STRING = xml:document(xml:conference(nil, config.controls_speaker, config.controls_moderator)); local event_name = params:getHeader("Event-Name") if event_name == 'COMMAND' then @@ -125,6 +125,41 @@ function conf_conference(database) end end +function conf_voicemail(database) + require 'common.configuration_table'; + local parameters = common.configuration_table.get(database, 'voicemail', 'parameters'); + + if tostring(parameters['odbc-dsn']) == 'default' then + parameters['odbc-dsn'] = 'gemeinschaft:' .. tostring(database.user_name) .. ':' .. tostring(database.password); + end + + local params_xml = {}; + for name, value in pairs(parameters) do + params_xml[#params_xml+1] = xml:tag{ _name = 'param', name = name, value = value }; + end + + XML_STRING = xml:document( + xml:tag{ + _name = 'section', + name = 'configuration', + description = 'Gemeinschaft 5 FreeSWITCH configuration', + _data = xml:tag{ + _name = 'configuration', + name = 'voicemail.conf', + description = 'Voicemail configuration', + _data = xml:tag{ + _name = 'profiles', + _data = xml:tag{ + _name = 'profile', + name = 'default', + _data = table.concat(params_xml, '\n'), + }, + }, + }, + } + ); +end + function conf_post_switch(database) require 'common.configuration_table'; local parameters = common.configuration_table.get(database, 'post_load_switch', 'settings'); @@ -220,6 +255,8 @@ if XML_REQUEST.section == 'configuration' and XML_REQUEST.tag_name == 'configura conf_sofia(database); elseif XML_REQUEST.key_value == "conference.conf" then conf_conference(database); + elseif XML_REQUEST.key_value == "voicemail.conf" then + conf_voicemail(database); elseif XML_REQUEST.key_value == "post_load_switch.conf" then conf_post_switch(database); end -- cgit v1.2.3 From 69bd05e343fd5341d6b86517e5fad6d135436425 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Fri, 11 Jan 2013 13:04:10 +0100 Subject: remove odbc-dsn parameter from static file freeswitch.xml --- misc/freeswitch/conf/freeswitch.xml | 1 - 1 file changed, 1 deletion(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml index 13c2954..6241986 100644 --- a/misc/freeswitch/conf/freeswitch.xml +++ b/misc/freeswitch/conf/freeswitch.xml @@ -715,7 +715,6 @@ - -- cgit v1.2.3 From 55c1fccd239563be02013509f793685726d8bc6e Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 11 Jan 2013 15:57:34 +0100 Subject: simple xml builder class added --- .../scripts/configuration/simple_xml.lua | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 misc/freeswitch/scripts/configuration/simple_xml.lua (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration/simple_xml.lua b/misc/freeswitch/scripts/configuration/simple_xml.lua new file mode 100644 index 0000000..f04dd1e --- /dev/null +++ b/misc/freeswitch/scripts/configuration/simple_xml.lua @@ -0,0 +1,50 @@ +-- Gemeinschaft 5 simple xml gererator class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +SimpleXml = {} + +-- Create SimpleXml object +function SimpleXml.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.class = 'simplexml'; + return object; +end + +function SimpleXml.element(self, arg) + local xml_tag = '<' .. tostring(arg[1]); + for key, value in pairs(arg) do + if type(key) == 'string' then + xml_tag = xml_tag .. ' ' .. tostring(key) .. '="' .. tostring(value) .. '"'; + end + end + xml_tag = xml_tag .. '>'; + + for key=2, #arg do + xml_tag = xml_tag .. '\n' .. tostring(arg[key]) .. '\n'; + end + + return xml_tag .. ''; +end + + +function SimpleXml.from_hash(self, element_name, parameter_hash, key_name, value_name) + local params_xml = ''; + for key, value in pairs(parameter_hash) do + local arguments = { [1] = element_name }; + if key_name and value_name then + arguments[key_name] = key; + arguments[value_name] = value; + else + arguments[key] = value; + end + params_xml = params_xml .. tostring(self:element(arguments)) .. '\n'; + end + + return params_xml; +end -- cgit v1.2.3 From 7c1bc1abf9fc0d628a308bb69e4e21926a6b41ef Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 11 Jan 2013 15:58:19 +0100 Subject: xml engine change --- misc/freeswitch/scripts/configuration.lua | 339 +++++++++++++++++++++++++----- 1 file changed, 281 insertions(+), 58 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index ec5099e..5db80c0 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -3,6 +3,9 @@ -- function nodes(database, local_node_id) + require 'configuration.simple_xml' + local xml = configuration.simple_xml.SimpleXml:new(); + local gateways_xml = ''; require 'common.node' @@ -14,7 +17,11 @@ function nodes(database, local_node_id) node_parameters['proxy'] = node_record.ip_address; node_parameters['register'] = 'false'; log:debug('NODE_GATEWAY ', node_record.id, ' - name: ', node_record.name, ', address: ', node_record.ip_address); - gateways_xml = gateways_xml .. xml:gateway(node_record.name, node_parameters); + gateways_xml = gateways_xml .. xml:element{ + 'gateway', + name = node_record.name, + xml:from_hash('param', node_parameters, 'name', 'value'), + }; end end @@ -22,6 +29,9 @@ function nodes(database, local_node_id) end function gateways(profile_name) + require 'configuration.simple_xml' + local xml = configuration.simple_xml.SimpleXml:new(); + require 'common.configuration_file' local gateways_xml = ''; local gateways = common.configuration_file.get('/opt/freeswitch/scripts/ini/gateways.ini', false); @@ -30,10 +40,14 @@ function gateways(profile_name) return ''; end - for sofia_gateway, gateway_parameters in pairs(gateways) do + for gateway_name, gateway_parameters in pairs(gateways) do if tostring(gateway_parameters.profile) == profile_name then - log:debug('GATEWAY - name: ', sofia_gateway, ', address: ', gateway_parameters.proxy); - gateways_xml = gateways_xml .. xml:gateway(sofia_gateway, gateway_parameters); + log:debug('GATEWAY - name: ', gateway_name, ', address: ', gateway_parameters.proxy); + gateways_xml = gateways_xml .. xml:element{ + 'gateway', + name = gateway_name, + xml:from_hash('param', gateway_parameters, 'name', 'value'), + }; end end @@ -41,25 +55,28 @@ function gateways(profile_name) end function profile(database, sofia_ini, profile_name, index, domains, node_id) - local profile_parameters = sofia_ini['profile:' .. profile_name]; + require 'configuration.simple_xml' + local xml = configuration.simple_xml.SimpleXml:new(); - if not profile_parameters then + local parameters = sofia_ini['profile:' .. profile_name]; + + if not parameters then log:error('SOFIA_PROFILE ', index,' - name: ', profile_name, ' - no parameters'); return ''; end - if tostring(profile_parameters['odbc-dsn']) == 'default' then - profile_parameters['odbc-dsn'] = 'gemeinschaft:' .. tostring(database.user_name) .. ':' .. tostring(database.password); + if tostring(parameters['odbc-dsn']) == 'default' then + parameters['odbc-dsn'] = 'gemeinschaft:' .. tostring(database.user_name) .. ':' .. tostring(database.password); end -- set local bind address if domains[index] then - profile_parameters['sip-ip'] = domains[index]['host']; - profile_parameters['rtp-ip'] = domains[index]['host']; - profile_parameters['force-register-domain'] = domains[index]['host']; - profile_parameters['force-subscription-domain'] = domains[index]['host']; - profile_parameters['force-register-db-domain'] = domains[index]['host']; - log:debug('SOFIA_PROFILE ', index,' - name: ', profile_name, ', domain: ', domains[index]['host'], ', sip_bind: ', profile_parameters['sip-ip'], ':', profile_parameters['sip-port']); + parameters['sip-ip'] = domains[index]['host']; + parameters['rtp-ip'] = domains[index]['host']; + parameters['force-register-domain'] = domains[index]['host']; + parameters['force-subscription-domain'] = domains[index]['host']; + parameters['force-register-db-domain'] = domains[index]['host']; + log:debug('SOFIA_PROFILE ', index,' - name: ', profile_name, ', domain: ', domains[index]['host'], ', sip_bind: ', parameters['sip-ip'], ':', parameters['sip-port']); else log:error('SOFIA_PROFILE ', index,' - name: ', profile_name, ' - no domains'); end @@ -70,11 +87,37 @@ function profile(database, sofia_ini, profile_name, index, domains, node_id) gateways_xml = gateways_xml .. nodes(database, node_id); end - return xml:sofia_profile(profile_name, profile_parameters, gateways_xml); + local profile_xml = xml:element{ + 'profile', + name = profile_name, + xml:element{ + 'gateways', + gateways_xml, + }, + xml:element{ + 'domains', + xml:element{ + 'domain', + name = 'all', + alias = 'true', + parse = 'false', + }, + }, + xml:element{ + 'settings', + xml:from_hash('param', parameters, 'name', 'value'), + }, + }; + + return profile_xml; end + -- generate sofia.conf function conf_sofia(database) + require 'configuration.simple_xml' + local xml = configuration.simple_xml.SimpleXml:new(); + require 'common.configuration_table' local sofia_profile = "gemeinschaft"; @@ -93,14 +136,38 @@ function conf_sofia(database) end end - XML_STRING = xml:document(xml:sofia(sofia_ini.parameters, sofia_profiles_xml)) + XML_STRING = xml:element{ + 'document', + ['type'] = 'freeswitch/xml', + xml:element{ + 'section', + name = 'configuration', + description = 'Gemeinschaft 5 FreeSWITCH configuration', + xml:element{ + 'configuration', + name = 'sofia.conf', + description = 'Sofia configuration', + xml:element{ + 'global_settings', + xml:from_hash('param', sofia_ini.parameters, 'name', 'value'), + }, + xml:element{ + 'profiles', + sofia_profiles_xml, + }, + }, + }, + }; + end function conf_conference(database) + require 'configuration.simple_xml' + local xml = configuration.simple_xml.SimpleXml:new(); + require 'common.configuration_table' - local config = common.configuration_table.get(database, 'conferences'); - XML_STRING = xml:document(xml:conference(nil, config.controls_speaker, config.controls_moderator)); + local profiles = nil; local event_name = params:getHeader("Event-Name") if event_name == 'COMMAND' then @@ -113,7 +180,14 @@ function conf_conference(database) if conference then log:debug('CONFIG_CONFERENCE ', conf_name, ' name: ', conference.record.name, ', profile: ', profile_name); config.parameters['caller-id-name'] = conference.record.name or ''; - XML_STRING = xml:document(xml:conference(xml:conference_profile(profile_name, config.parameters), config.controls_speaker, config.controls_moderator)); + profiles = xml:element{ + 'profiles', + xml:element{ + 'profile', + name = profile_name, + xml:from_hash('param', config.parameters, 'name', 'value'), + }, + }; else log:error('CONFIG_CONFERENCE ', conf_name, ' - conference not found'); end @@ -123,9 +197,41 @@ function conf_conference(database) else log:debug('CONFIG_CONFERENCE ', conf_name, ' - event: ', event_name); end + + XML_STRING = xml:element{ + 'document', + ['type'] = 'freeswitch/xml', + xml:element{ + 'section', + name = 'configuration', + description = 'Gemeinschaft 5 FreeSWITCH configuration', + xml:element{ + 'configuration', + name = 'conference.conf', + description = 'Conference configuration', + xml:element{ + 'caller-controls', + xml:element{ + 'group', + name = 'speaker', + xml:from_hash('control', config.controls_speaker, 'action', 'digits'), + }, + xml:element{ + 'group', + name = 'moderator', + xml:from_hash('control', config.controls_moderator, 'action', 'digits'), + }, + }, + profiles, + }, + }, + }; end function conf_voicemail(database) + require 'configuration.simple_xml' + local xml = configuration.simple_xml.SimpleXml:new(); + require 'common.configuration_table'; local parameters = common.configuration_table.get(database, 'voicemail', 'parameters'); @@ -133,47 +239,69 @@ function conf_voicemail(database) parameters['odbc-dsn'] = 'gemeinschaft:' .. tostring(database.user_name) .. ':' .. tostring(database.password); end - local params_xml = {}; - for name, value in pairs(parameters) do - params_xml[#params_xml+1] = xml:tag{ _name = 'param', name = name, value = value }; - end - - XML_STRING = xml:document( - xml:tag{ - _name = 'section', + XML_STRING = xml:element{ + 'document', + ['type'] = 'freeswitch/xml', + xml:element{ + 'section', name = 'configuration', description = 'Gemeinschaft 5 FreeSWITCH configuration', - _data = xml:tag{ - _name = 'configuration', + xml:element{ + 'configuration', name = 'voicemail.conf', description = 'Voicemail configuration', - _data = xml:tag{ - _name = 'profiles', - _data = xml:tag{ - _name = 'profile', + xml:element{ + 'profiles', + xml:element{ + 'profile', name = 'default', - _data = table.concat(params_xml, '\n'), + xml:from_hash('param', parameters, 'name', 'value'), }, }, }, - } - ); + }, + }; end function conf_post_switch(database) + require 'configuration.simple_xml' + local xml = configuration.simple_xml.SimpleXml:new(); + require 'common.configuration_table'; local parameters = common.configuration_table.get(database, 'post_load_switch', 'settings'); - XML_STRING = xml:document(xml:generic{name = 'post_load_switch.conf', parameters = parameters}); + XML_STRING = xml:element{ + 'document', + ['type'] = 'freeswitch/xml', + xml:element{ + 'section', + name = 'configuration', + description = 'Gemeinschaft 5 FreeSWITCH configuration', + xml:element{ + 'configuration', + name = 'post_load_switch.conf', + description = 'Switch configuration', + xml:element{ + 'settings', + xml:from_hash('param', parameters, 'name', 'value'), + }, + }, + }, + }; end function directory_sip_account(database) + require 'configuration.simple_xml' + local xml = configuration.simple_xml.SimpleXml:new(); + local key = params:getHeader('key'); local auth_name = params:getHeader('user'); local domain = params:getHeader('domain'); local purpose = params:getHeader('purpose'); + local user_xml = nil; + if auth_name and auth_name ~= '' then -- sip account or gateway if string.len(auth_name) > 3 and auth_name:sub(1, 3) == 'gw+' then @@ -184,45 +312,137 @@ function directory_sip_account(database) local sip_gateway = configuration.sip.Sip:new{ log = log, database = database}:find_gateway_by_name(gateway_name); if sip_gateway ~= nil and next(sip_gateway) ~= nil then log:debug('DIRECTORY_GATEWAY - name: ', gateway_name, ', auth_name: ', auth_name); - XML_STRING = xml:document(xml:directory(xml:gateway_user(sip_gateway, gateway_name, auth_name), domain)); + + local user_variables = { + user_context = "default", + gs_from_gateway = "true", + gs_gateway_name = gateway_name, + gs_gateway_id = sip_gateway.id, + } + + user_xml = xml:element{ + 'user', + id = auth_name, + xml:element{ + 'params', + xml:element{ + 'param', + password = sip_gateway.password, + } + }, + xml:element{ + 'variables', + xml:from_hash('variable', user_variables, 'name', 'value'), + }, + }; else log:debug('DIRECTORY_GATEWAY - gateway not found - name: ', gateway_name, ', auth_name: ', auth_name); end else - require 'common.configuration_table' - local user_params = common.configuration_table.get(database, 'sip_accounts', 'parameters'); - require 'common.sip_account' local sip_account = common.sip_account.SipAccount:new{ log = log, database = database}:find_by_auth_name(auth_name, domain); + + require 'common.configuration_table' + local user_parameters = common.configuration_table.get(database, 'sip_accounts', 'parameters'); + if sip_account ~= nil then + user_parameters['password'] = sip_account.record.password; + user_parameters['vm-password'] = sip_account.record.voicemail_pin; + + local user_variables = { + user_context = "default", + gs_from_gateway = "false", + gs_account_id = sip_account.record.id, + gs_account_uuid = sip_account.record.uuid, + gs_account_type = "SipAccount", + gs_account_state = sip_account.record.state, + gs_account_caller_name = sip_account.record.caller_name, + gs_account_owner_type = sip_account.record.sip_accountable_type, + gs_account_owner_id = sip_account.record.sip_accountable_id + } + if tostring(purpose) == 'publish-vm' then log:debug('DIRECTORY_SIP_ACCOUNT - purpose: VoiceMail, auth_name: ', sip_account.record.auth_name, ', caller_name: ', sip_account.record.caller_name, ', domain: ', domain); - XML_STRING = xml:document(xml:directory(xml:group_default(xml:user(sip_account.record, user_params)), domain)); + user_xml = xml:element{ + 'groups', + xml:element{ + 'group', + name = 'default', + xml:element{ + 'users', + xml:element{ + 'user', + id = sip_account.record.auth_name, + xml:element{ + 'params', + xml:from_hash('param', user_parameters, 'name', 'value'), + }, + xml:element{ + 'variables', + xml:from_hash('variable', user_variables, 'name', 'value'), + }, + }, + }, + }, + }; else log:debug('DIRECTORY_SIP_ACCOUNT - auth_name: ', sip_account.record.auth_name, ', caller_name: ', sip_account.record.caller_name, ', domain: ', domain); - XML_STRING = xml:document(xml:directory(xml:user(sip_account.record, user_params), domain)); + + user_xml = xml:element{ + 'user', + id = sip_account.record.auth_name, + xml:element{ + 'params', + xml:from_hash('param', user_parameters, 'name', 'value'), + }, + xml:element{ + 'variables', + xml:from_hash('variable', user_variables, 'name', 'value'), + }, + }; end else log:debug('DIRECTORY_SIP_ACCOUNT - sip account not found - auth_name: ', auth_name, ', domain: ', domain); -- fake sip_account configuration - sip_account = { - auth_name = auth_name, - id = 0, - uuid = '', - password = tostring(math.random(0, 65534)), - voicemail_pin = '', - state = 'inactive', - caller_name = '', - sip_accountable_type = 'none', - sip_accountable_id = 0, - } - XML_STRING = xml:document(xml:directory(xml:user(sip_account, user_params), domain)) + user_parameters['password'] = tostring(math.random(0, 65534)); + user_parameters['vm-password'] = ''; + + user_xml = xml:element{ + 'user', + id = auth_name, + xml:element{ + 'params', + xml:from_hash('param', user_parameters, 'name', 'value'), + }, + }; end end elseif tostring(XML_REQUEST.key_name) == 'name' and tostring(XML_REQUEST.key_value) ~= '' then log:debug('DOMAIN_DIRECTORY - domain: ', XML_REQUEST.key_value); XML_STRING = xml:document(xml:directory(nil, XML_REQUEST.key_value)); end + + XML_STRING = xml:element{ + 'document', + ['type'] = 'freeswitch/xml', + xml:element{ + 'section', + name = 'directory', + xml:element{ + 'domain', + name = domain, + xml:element{ + 'params', + xml:element{ + 'param', + name = 'dial-string', + value = '${sofia_contact(${dialed_user}@${dialed_domain})}', + }, + }, + user_xml, + }, + }, + }; end @@ -234,9 +454,12 @@ log = common.log.Log:new(); log.prefix = '#C# [' .. log_identifier .. '] '; -- return a valid xml document -require 'configuration.freeswitch_xml' -xml = configuration.freeswitch_xml.FreeSwitchXml:new(); -XML_STRING = xml:document(); +require 'configuration.simple_xml' +local xml = configuration.simple_xml.SimpleXml:new(); +XML_STRING = xml:element{ + 'document', + ['type'] = 'freeswitch/xml', +}; local database = nil; -- cgit v1.2.3 From 697477cca48c8402c6d8e1df73d5c8c902c582ee Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 11 Jan 2013 16:00:10 +0100 Subject: obsolete xml generator removed --- .../scripts/configuration/freeswitch_xml.lua | 333 --------------------- 1 file changed, 333 deletions(-) delete mode 100644 misc/freeswitch/scripts/configuration/freeswitch_xml.lua (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration/freeswitch_xml.lua b/misc/freeswitch/scripts/configuration/freeswitch_xml.lua deleted file mode 100644 index 53ecccf..0000000 --- a/misc/freeswitch/scripts/configuration/freeswitch_xml.lua +++ /dev/null @@ -1,333 +0,0 @@ --- ConfigurationModule: FreeSwitchXml --- -module(...,package.seeall) - -FreeSwitchXml = {} - --- Create FreeSwitchXml object -function FreeSwitchXml.new(self, object) - object = object or {} - setmetatable(object, self) - self.__index = self - return object -end - - -function FreeSwitchXml.tag(self, arg) - local xml_tag = '<' .. tostring(arg._name); - for key, value in pairs(arg) do - if tostring(key) ~= '_name' and tostring(key) ~= '_data' then - xml_tag = xml_tag .. ' ' .. tostring(key) .. '="' .. tostring(value) .. '"'; - end - end - xml_tag = xml_tag .. '>'; - - if arg._data then - xml_tag = xml_tag .. '\n' .. tostring(arg._data) .. '\n'; - end - - return xml_tag .. ''; -end - -function FreeSwitchXml.document(self, sections_xml) - if type(sections_xml) == "string" then - sections_xml = { sections_xml } - elseif type(sections_xml) == "nil" then - sections_xml = { "" } - end - - local xml_string= -[[ - -]] .. table.concat(sections_xml, "\n") .. [[ - -]] - - return xml_string -end - -function FreeSwitchXml.directory(self, entries_xml, domain) - if type(entries_xml) == "string" then - entries_xml = { entries_xml } - elseif type(entries_xml) == "nil" then - entries_xml = { "" } - end - - local xml_string = -[[ -
- - - - -]] .. table.concat(entries_xml, "\n") .. [[ - - -
]] - return xml_string -end - -function FreeSwitchXml.group_default(self, entries_xml) - if type(entries_xml) == "string" then - entries_xml = { entries_xml } - elseif type(entries_xml) == "nil" then - entries_xml = { "" } - end - - local xml_string = -[[ - - - -]] .. table.concat(entries_xml, "\n") .. [[ - - - -]] - return xml_string -end - -function FreeSwitchXml.user(self, user, params) - params = params or {}; - - params['password'] = user.password; - params['vm-password'] = user.voicemail_pin; - - local variables = { - user_context = "default", - gs_from_gateway = "false", - gs_account_id = user.id, - gs_account_uuid = user.uuid, - gs_account_type = "SipAccount", - gs_account_state = user.state, - gs_account_caller_name = user.caller_name, - gs_account_owner_type = user.sip_accountable_type, - gs_account_owner_id = user.sip_accountable_id - } - - local params_xml = {} - for name, value in pairs(params) do - params_xml[#params_xml+1] = self:tag{ _name = 'param', name = name, value = value }; - end - - local variables_xml = {} - for name, value in pairs(variables) do - variables_xml[#variables_xml+1] = self:tag{ _name = 'variable', name = name, value = value }; - end - - local xml_string = -[[ - - -]] .. table.concat(params_xml, "\n") .. [[ - - - -]] .. table.concat(variables_xml, "\n") .. [[ - - -]] - return xml_string -end - -function FreeSwitchXml.gateway_user(self, user, gateway_name, auth_name) - user.id = user.id or 0 - - local params = { - ['password'] = user.password, - } - - local variables = { - user_context = "default", - gs_from_gateway = "true", - gs_gateway_name = gateway_name, - gs_gateway_id = user.id - } - - local params_xml = {} - for name, value in pairs(params) do - params_xml[#params_xml+1] = self:tag{ _name = 'param', name = name, value = value }; - end - - local variables_xml = {} - for name, value in pairs(variables) do - variables_xml[#variables_xml+1] = self:tag{ _name = 'variable', name = name, value = value }; - end - - local xml_string = -[[ - - -]] .. table.concat(params_xml, "\n") .. [[ - - - -]] .. table.concat(variables_xml, "\n") .. [[ - - -]] - return xml_string -end - -function FreeSwitchXml.sofia(self, parameters, profiles_xml) - if type(profiles_xml) == "string" then - profiles_xml = { profiles_xml } - elseif type(profiles_xml) == "nil" then - profiles_xml = { "" } - end - - local params_xml = {} - for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:tag{ _name = 'param', name = name, value = value }; - end - - local xml_string = -[[ -
- - -]] .. table.concat(params_xml, "\n") .. [[ - - - -]] .. table.concat(profiles_xml, "\n") .. [[ - - - -
]] - return xml_string -end - -function FreeSwitchXml.sofia_profile(self, profile_name, parameters, gateways_xml) - params_xml = {} - for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:tag{ _name = 'param', name = name, value = value }; - end - - if type(gateways_xml) == "string" then - gateways_xml = { gateways_xml } - elseif type(gateways_xml) == "nil" then - gateways_xml = { "" } - end - - local xml_string = -[[ - - - - -]] .. table.concat(gateways_xml, "\n") .. [[ - - - - - - -]] .. table.concat(params_xml, "\n") .. [[ - - -]] - return xml_string -end - -function FreeSwitchXml.gateway(self, gateway_name, parameters) - local params_xml = {} - if parameters then - for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:tag{ _name = 'param', name = name, value = value }; - end - end - - local xml_string = -[[ - -]] .. table.concat(params_xml, "\n") .. [[ - -]] - return xml_string -end - -function FreeSwitchXml.conference(self, profiles_xml, speaker, moderator) - if type(profiles_xml) == "string" then - profiles_xml = { profiles_xml } - elseif type(profiles_xml) == "nil" then - profiles_xml = { "" } - end - - local speaker_xml = {} - if speaker then - for name, value in pairs(speaker) do - speaker_xml[#speaker_xml+1] = self:tag{ _name = 'control', action = name, digits = value }; - end - end - - local moderator_xml = {} - if moderator then - for name, value in pairs(speaker) do - moderator_xml[#moderator_xml+1] = self:tag{ _name = 'control', action = name, digits = value }; - end - end - - local xml_string = -[[ -
- - - - - -]] .. table.concat(speaker_xml, "\n") .. [[ - - - -]] .. table.concat(moderator_xml, "\n") .. [[ - - - - -]] .. table.concat(profiles_xml, "\n") .. [[ - - - -
]] - return xml_string -end - -function FreeSwitchXml.conference_profile(self, profile_name, parameters) - local params_xml = {} - for name, value in pairs(parameters) do - params_xml[#params_xml+1] = self:tag{ _name = 'param', name = name, value = value }; - end - - local xml_string = -[[ - -]] .. table.concat(params_xml, "\n") .. [[ - -]] - return xml_string -end - -function FreeSwitchXml.generic(self, arg) - local params_xml = arg.params_xml or {}; - local params_tag = arg.params_tag or 'settings'; - local parameter_tag = arg.parameter_tag or 'param'; - - if arg.parameters then - for name, value in pairs(arg.parameters) do - params_xml[#params_xml+1] = self:tag{ _name = parameter_tag, name = name, value = value }; - end - end - - local xml_string = -[[ -
- -<]] .. tostring(params_tag) .. [[> -]] .. table.concat(params_xml, "\n") .. [[ - - - -
]] - return xml_string -end -- cgit v1.2.3 From 16a46466a2c2f74abd74bf2baff3ef8db5ae9602 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Fri, 11 Jan 2013 20:50:19 +0100 Subject: remove deprecated static ini files --- misc/freeswitch/scripts/ini/conferences.ini | 27 -------------- misc/freeswitch/scripts/ini/database.ini | 11 ------ misc/freeswitch/scripts/ini/dialplan.ini | 19 ---------- misc/freeswitch/scripts/ini/events.ini | 8 ---- misc/freeswitch/scripts/ini/perimeter.ini | 9 ----- misc/freeswitch/scripts/ini/sip_accounts.ini | 10 ----- misc/freeswitch/scripts/ini/sofia.ini | 55 ---------------------------- 7 files changed, 139 deletions(-) delete mode 100644 misc/freeswitch/scripts/ini/conferences.ini delete mode 100644 misc/freeswitch/scripts/ini/database.ini delete mode 100644 misc/freeswitch/scripts/ini/dialplan.ini delete mode 100644 misc/freeswitch/scripts/ini/events.ini delete mode 100644 misc/freeswitch/scripts/ini/perimeter.ini delete mode 100644 misc/freeswitch/scripts/ini/sip_accounts.ini delete mode 100644 misc/freeswitch/scripts/ini/sofia.ini (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/ini/conferences.ini b/misc/freeswitch/scripts/ini/conferences.ini deleted file mode 100644 index d8d0817..0000000 --- a/misc/freeswitch/scripts/ini/conferences.ini +++ /dev/null @@ -1,27 +0,0 @@ -; Gemeinschaft 5 conferences configuration file -; (c) AMOOMA GmbH 2012 -; - -[parameters] -caller-controls = speaker -moderator-controls = moderator -max-members = 100 -rate = 16000 -interval = 20 -energy-level = 300 -sound-prefix = /opt/freeswitch/sounds/en/us/callie -muted-sound = conference/conf-muted.wav -unmuted-sound = conference/conf-unmuted.wav -alone-sound = conference/conf-alone.wav -moh-sound = local_stream://moh -enter-sound = tone_stream://%(200,0,500,600,700) -exit-sound = tone_stream://%(500,0,300,200,100,50,25) -kicked-sound = conference/conf-kicked.wav -locked-sound = conference/conf-locked.wav -is-locked-sound = conference/conf-is-locked.wav -is-unlocked-sound = conference/conf-is-unlocked.wav -pin-sound = conference/conf-pin.wav -bad-pin-sound = conference/conf-bad-pin.wav -caller-id-name = Conference -caller-id-number = -comfort-noise = true diff --git a/misc/freeswitch/scripts/ini/database.ini b/misc/freeswitch/scripts/ini/database.ini deleted file mode 100644 index 1652118..0000000 --- a/misc/freeswitch/scripts/ini/database.ini +++ /dev/null @@ -1,11 +0,0 @@ -; Gemeinschaft 5 database configuration -; (c) AMOOMA GmbH 2012 -; - -driver = mysql - -[mysql] -host = localhost -database = gemeinschaft -user = gemeinschaft -password = gemeinschaft diff --git a/misc/freeswitch/scripts/ini/dialplan.ini b/misc/freeswitch/scripts/ini/dialplan.ini deleted file mode 100644 index e081055..0000000 --- a/misc/freeswitch/scripts/ini/dialplan.ini +++ /dev/null @@ -1,19 +0,0 @@ -; Gemeinschaft 5 dialplan configuration file -; (c) AMOOMA GmbH 2012 -; - -[parameters] -node_id = 1 -phone_book_entry_image_url = http://192.168.0.150/uploads/phone_book_entry/image -user_image_url = http://192.168.0.150/uploads/user/image -ringtone_url = http://192.168.0.150 -ringback = %(2000,4000,440.0,480.0) -tone_busy = %(500,500,480,620);loops=4 - -; This one activates the lookup of phone numbers in -; the stored phone books. -phonebook_number_lookup = true - -; This option controls city, country or operator number lookup for -; all numbers not resolved by "phonebook_number_lookup" -geo_number_lookup = false diff --git a/misc/freeswitch/scripts/ini/events.ini b/misc/freeswitch/scripts/ini/events.ini deleted file mode 100644 index e63eb73..0000000 --- a/misc/freeswitch/scripts/ini/events.ini +++ /dev/null @@ -1,8 +0,0 @@ -; Gemeinschaft 5 routing configuration file -; (c) AMOOMA GmbH 2012 -; - -[modules] -cdr_save -call_history_save -presence_update diff --git a/misc/freeswitch/scripts/ini/perimeter.ini b/misc/freeswitch/scripts/ini/perimeter.ini deleted file mode 100644 index ecbb032..0000000 --- a/misc/freeswitch/scripts/ini/perimeter.ini +++ /dev/null @@ -1,9 +0,0 @@ -; Gemeinschaft 5 perimeter defense configuration file -; (c) AMOOMA GmbH 2012 -; - -[general] -malicious_contact_count = 20 -malicious_contact_time_span = 2 -ban_futile = 5 -execute = sudo /usr/local/bin/ban_ip.sh {ip_address} diff --git a/misc/freeswitch/scripts/ini/sip_accounts.ini b/misc/freeswitch/scripts/ini/sip_accounts.ini deleted file mode 100644 index 73a5fae..0000000 --- a/misc/freeswitch/scripts/ini/sip_accounts.ini +++ /dev/null @@ -1,10 +0,0 @@ -; Gemeinschaft 5 sip accounts default parameters -; (c) AMOOMA GmbH 2012 -; - -[parameters] -vm-enabled = true -vm-email-all-messages = false -vm-attach-file = false -vm-mailto = - diff --git a/misc/freeswitch/scripts/ini/sofia.ini b/misc/freeswitch/scripts/ini/sofia.ini deleted file mode 100644 index 5c99dbd..0000000 --- a/misc/freeswitch/scripts/ini/sofia.ini +++ /dev/null @@ -1,55 +0,0 @@ -; Gemeinschaft 5 sofia configuration file -; (c) AMOOMA GmbH 2012 -; - -[profiles] -gemeinschaft - -[parameters] -log-level = 3 -debug-presence = 0 - -[profile:gemeinschaft] -user-agent-string = Gemeinschaft5 -debug = 0 -sip-trace = no -log-auth-failures = false -context = default -rfc2833-pt = 101 -pass-rfc2833 = true -sip-port = 5060 -dialplan = XML -dtmf-duration = 2000 -rtp-timer-name = soft -inbound-codec-prefs = PCMA,G7221@32000h,G7221@16000h,G722,PCMU,GSM -outbound-codec-prefs = PCMA,G7221@32000h,G7221@16000h,G722,PCMU,GSM -inbound-codec-negotiation = greedy -ext-rtp-ip = auto-nat -ext-sip-ip = auto-nat -hold-music = local_stream://moh -manage-presence = true -tls = false -tls-sip-port = 5061 -tls-cert-dir = /opt/freeswitch/conf/ssl -accept-blind-reg = false -accept-blind-auth = false -nonce-ttl = 60 -disable-transcoding = false -manual-redirect = true -disable-transfer = false -disable-register = false -auth-calls = false -inbound-reg-force-matching-username = true -auth-all-packets = false -rtp-timeout-sec = 300 -rtp-hold-timeout-sec = 1800 -force-subscription-expires = 3600 -sip-force-expires = 3000 -sip-expires-max-deviation = 600; -challenge-realm = auto_from -rtp-rewrite-timestamps = true -inbound-use-callid-as-uuid = false -outbound-use-callid-as-uuid = false -context = default -record-template = ${user_name}_${uuid}_${strftime(%Y-%m-%d-%H-%M-%S)}.wav -odbc-dsn = gemeinschaft:gemeinschaft:gemeinschaft -- cgit v1.2.3 From 393428c8551f9c8180bb31e6f7c3101c62c8828e Mon Sep 17 00:00:00 2001 From: spag Date: Sat, 12 Jan 2013 09:02:24 +0100 Subject: debug level --- misc/freeswitch/scripts/configuration.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index 5db80c0..3ef1a9c 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -78,7 +78,7 @@ function profile(database, sofia_ini, profile_name, index, domains, node_id) parameters['force-register-db-domain'] = domains[index]['host']; log:debug('SOFIA_PROFILE ', index,' - name: ', profile_name, ', domain: ', domains[index]['host'], ', sip_bind: ', parameters['sip-ip'], ':', parameters['sip-port']); else - log:error('SOFIA_PROFILE ', index,' - name: ', profile_name, ' - no domains'); + log:debug('SOFIA_PROFILE ', index,' - name: ', profile_name, ' - no domains'); end local gateways_xml = gateways(profile_name); -- 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') 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 81dfa5ac9a7c6b25526109d11309706260a739f5 Mon Sep 17 00:00:00 2001 From: spag Date: Sat, 12 Jan 2013 09:07:26 +0100 Subject: freeswitch configuration cleanup --- misc/freeswitch/conf/freeswitch.xml | 93 +------------------------------------ 1 file changed, 2 insertions(+), 91 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml index 6241986..c5dd3f1 100644 --- a/misc/freeswitch/conf/freeswitch.xml +++ b/misc/freeswitch/conf/freeswitch.xml @@ -1,10 +1,6 @@ - - - -
@@ -495,13 +491,6 @@ - - - - - - - @@ -541,30 +530,13 @@ - - - - - - - - - - - - - - - - - - + @@ -645,8 +617,6 @@ - - @@ -654,12 +624,8 @@ - - - - @@ -668,62 +634,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + -- cgit v1.2.3 From 9012171763a7f1155e39bfb7f39fea34d437feef Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 13 Jan 2013 17:22:00 +0100 Subject: gateway class added --- misc/freeswitch/scripts/common/gateway.lua | 122 +++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 misc/freeswitch/scripts/common/gateway.lua (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/gateway.lua b/misc/freeswitch/scripts/common/gateway.lua new file mode 100644 index 0000000..2c50c0f --- /dev/null +++ b/misc/freeswitch/scripts/common/gateway.lua @@ -0,0 +1,122 @@ +-- Gemeinschaft 5 module: gateway class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +Gateway = {} + +-- Create Gateway object +function Gateway.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.class = 'gateway'; + self.log = arg.log; + self.database = arg.database; + self.record = arg.record; + return object; +end + + +function Gateway.list(self, technology) + technology = technology or 'sip'; + local sql_query = 'SELECT * FROM `gateways` WHERE (`outbound` IS TRUE OR `inbound` IS TRUE) AND `technology` = "' .. technology .. '"'; + local gateways = {}; + self.database:query(sql_query, function(entry) + table.insert(gateways, entry); + end) + + return gateways; +end + + +function Gateway.find_by_sql(self, where) + local sql_query = 'SELECT * FROM `gateways` WHERE ' .. where .. ' LIMIT 1'; + + local gateway = nil; + self.database:query(sql_query, function(entry) + gateway = Gateway:new(self); + gateway.record = entry; + gateway.id = tonumber(entry.id); + gateway.uuid = entry.uuid; + end) + + return gateway; +end + + +-- find gateway by id +function Gateway.find_by_id(self, id) + local sql_query = '`id`= ' .. tonumber(id); + return self:find_by_sql(sql_query); +end + +-- find gateway name +function Gateway.find_by_name(self, name) + local sql_query = '`name`= "' .. name .. '"'; + + return self:find_by_sql(sql_query); +end + + +function Gateway.profile_get(self, gateway_id) + local sql_query = 'SELECT `value` FROM `gateway_settings` WHERE `gateway_id` = ' .. tonumber(gateway_id) .. ' AND `name` = "profile" LIMIT 1'; + + return self.database:query_return_value(sql_query); +end + + +function Gateway.config_table_get(self, config_table, gateway_id) + require 'common.str' + + local sql_query = 'SELECT * FROM `'.. config_table ..'` WHERE `gateway_id` = ' .. tonumber(gateway_id); + + local settings = {}; + self.database:query(sql_query, function(entry) + local p_class_type = common.str.strip(entry.class_type):lower(); + local p_name = common.str.strip(entry.name):lower(); + + if p_class_type == 'boolean' then + settings[p_name] = common.str.to_b(entry.value); + elseif p_class_type == 'integer' then + settings[p_name] = common.str.to_i(entry.value); + else + settings[p_name] = tostring(entry.value); + end + end) + + return settings +end + + +function Gateway.parameters_build(self, gateway_id) + local settings = self:config_table_get('gateway_settings', gateway_id); + local parameters = { + realm = settings.domain, + extension = 'auto_to_user', + }; + + require 'common.str' + + if common.str.blank(settings.username) then + parameters.username = 'gateway' .. gateway_id; + parameters.register = false; + else + parameters.username = settings.username; + parameters.register = true; + end + + if common.str.blank(settings.password) then + parameters.password = 'gateway' .. gateway_id; + else + parameters.password = settings.password; + end + + for key, value in pairs(self:config_table_get('gateway_parameters', gateway_id)) do + parameters[key] = value; + end + + return parameters; +end -- cgit v1.2.3 From 0d5114566e73c44799eac83d46f159cd979f4fcc Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 13 Jan 2013 17:23:37 +0100 Subject: read gateway configuration from database --- misc/freeswitch/scripts/configuration.lua | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index 3ef1a9c..b4dc0f6 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -28,25 +28,29 @@ function nodes(database, local_node_id) return gateways_xml; end -function gateways(profile_name) + +function gateways(database, profile_name) require 'configuration.simple_xml' local xml = configuration.simple_xml.SimpleXml:new(); - require 'common.configuration_file' - local gateways_xml = ''; - local gateways = common.configuration_file.get('/opt/freeswitch/scripts/ini/gateways.ini', false); + require 'common.str' - if not gateways then - return ''; - end + require 'common.gateway' + local gateway_class = common.gateway.Gateway:new{ log = log, database = database}; + local gateways = gateway_class:list('sip'); + + local gateways_xml = ''; + for index=1, #gateways do + local gateway = gateways[index]; + local gateway_profile = gateway_class:profile_get(gateway.id); + if tostring(gateway_profile) == profile_name or (profile_name == 'gemeinschaft' and common.str.blank(gateway_profile)) then + log:debug('GATEWAY - name: ', gateway.name); + local parameters = gateway_class:parameters_build(gateway.id); - for gateway_name, gateway_parameters in pairs(gateways) do - if tostring(gateway_parameters.profile) == profile_name then - log:debug('GATEWAY - name: ', gateway_name, ', address: ', gateway_parameters.proxy); gateways_xml = gateways_xml .. xml:element{ 'gateway', - name = gateway_name, - xml:from_hash('param', gateway_parameters, 'name', 'value'), + name = gateway.name, + xml:from_hash('param', parameters, 'name', 'value'), }; end end @@ -54,6 +58,7 @@ function gateways(profile_name) return gateways_xml; end + function profile(database, sofia_ini, profile_name, index, domains, node_id) require 'configuration.simple_xml' local xml = configuration.simple_xml.SimpleXml:new(); @@ -81,7 +86,7 @@ function profile(database, sofia_ini, profile_name, index, domains, node_id) log:debug('SOFIA_PROFILE ', index,' - name: ', profile_name, ' - no domains'); end - local gateways_xml = gateways(profile_name); + local gateways_xml = gateways(database, profile_name); if index == 1 then gateways_xml = gateways_xml .. nodes(database, node_id); -- cgit v1.2.3 From 24a60c41586dbfa64da30acea1749376bebbef46 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 14 Jan 2013 09:47:22 +0100 Subject: register setting --- misc/freeswitch/scripts/common/gateway.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/gateway.lua b/misc/freeswitch/scripts/common/gateway.lua index 2c50c0f..9c09a22 100644 --- a/misc/freeswitch/scripts/common/gateway.lua +++ b/misc/freeswitch/scripts/common/gateway.lua @@ -108,6 +108,10 @@ function Gateway.parameters_build(self, gateway_id) parameters.register = true; end + if not common.str.blank(settings.register) then + parameters.register = common.str.to_b(settings.register); + end + if common.str.blank(settings.password) then parameters.password = 'gateway' .. gateway_id; else -- cgit v1.2.3 From 64c8b78bbf5880c2b8948cf7588ffe7d0a843357 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 14 Jan 2013 17:15:02 +0100 Subject: display contacht host --- misc/freeswitch/scripts/dialplan_default.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/dialplan_default.lua b/misc/freeswitch/scripts/dialplan_default.lua index 91ad4e4..1c0a52e 100644 --- a/misc/freeswitch/scripts/dialplan_default.lua +++ b/misc/freeswitch/scripts/dialplan_default.lua @@ -42,7 +42,7 @@ start_caller:init_channel_variables(); -- session:execute('info','notice'); if not start_dialplan:check_auth() then - log:debug('AUTHENTICATION_REQUIRED - domain: ', start_dialplan.domain); + log:debug('AUTHENTICATION_REQUIRED - host: ' , start_caller.sip_contact_host, ', domain: ', start_dialplan.domain); start_dialplan:hangup(407, start_dialplan.domain); return false; end -- cgit v1.2.3 From e0064941bc73303e83f1fbd9374c3a731b1d3c0b Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 14 Jan 2013 17:15:51 +0100 Subject: allow header based authentication --- misc/freeswitch/scripts/common/gateway.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/gateway.lua b/misc/freeswitch/scripts/common/gateway.lua index 9c09a22..9cddd7c 100644 --- a/misc/freeswitch/scripts/common/gateway.lua +++ b/misc/freeswitch/scripts/common/gateway.lua @@ -61,6 +61,28 @@ function Gateway.find_by_name(self, name) end +function Gateway.authenticate(self, technology, caller) + local sql_query = 'SELECT `c`.`name`, `c`.`id`, `a`.`value` `auth_source`, `b`.`value` `auth_pattern` \ + FROM `gateway_settings` `a` \ + INNER JOIN `gateway_settings` `b` \ + ON (`a`.`gateway_id` = `b`.`gateway_id` AND `a`.`name` = "auth_source" AND `b`.`name` = "auth_pattern" ) \ + LEFT JOIN `gateways` `c` \ + ON (`a`.`gateway_id` = `c`.`id`) \ + WHERE `c`.`inbound` IS TRUE AND `c`.`technology` = "' .. tostring(technology) .. '"'; + + local gateway = false; + + self.database:query(sql_query, function(entry) + if caller:to_s(entry.auth_source):match(entry.auth_pattern) then + gateway = entry; + return; + end + end) + + return gateway; +end + + function Gateway.profile_get(self, gateway_id) local sql_query = 'SELECT `value` FROM `gateway_settings` WHERE `gateway_id` = ' .. tonumber(gateway_id) .. ' AND `name` = "profile" LIMIT 1'; -- 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') 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') 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') 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 82ab2c07fbc494bad3ffdde30dbb3ce0d98c4e19 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 15 Jan 2013 12:29:12 +0100 Subject: gateway settings --- misc/freeswitch/scripts/common/gateway.lua | 32 ++++++++++++++---------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/gateway.lua b/misc/freeswitch/scripts/common/gateway.lua index 9cddd7c..6e9fbfb 100644 --- a/misc/freeswitch/scripts/common/gateway.lua +++ b/misc/freeswitch/scripts/common/gateway.lua @@ -32,32 +32,22 @@ function Gateway.list(self, technology) end -function Gateway.find_by_sql(self, where) - local sql_query = 'SELECT * FROM `gateways` WHERE ' .. where .. ' LIMIT 1'; +function Gateway.find_by_id(self, id) + local sql_query = 'SELECT * FROM `gateways` WHERE `id`= ' .. tonumber(id) .. ' LIMIT 1'; local gateway = nil; self.database:query(sql_query, function(entry) gateway = Gateway:new(self); gateway.record = entry; gateway.id = tonumber(entry.id); - gateway.uuid = entry.uuid; + gateway.name = entry.name; end) - return gateway; -end - - --- find gateway by id -function Gateway.find_by_id(self, id) - local sql_query = '`id`= ' .. tonumber(id); - return self:find_by_sql(sql_query); -end - --- find gateway name -function Gateway.find_by_name(self, name) - local sql_query = '`name`= "' .. name .. '"'; + if gateway then + gateway.settings = self:config_table_get('gateway_settings', gateway.id); + end - return self:find_by_sql(sql_query); + return gateway; end @@ -140,6 +130,14 @@ function Gateway.parameters_build(self, gateway_id) parameters.password = settings.password; end + parameters['extension-in-contact'] = true; + + if common.str.blank(settings.contact) then + parameters['extension'] = 'gateway' .. gateway_id; + else + parameters['extension'] = settings.contact; + end + for key, value in pairs(self:config_table_get('gateway_parameters', gateway_id)) do parameters[key] = value; 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') 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 +++++++++++---------------- misc/freeswitch/scripts/dialplan_default.lua | 29 ++++++++--- 2 files changed, 51 insertions(+), 48 deletions(-) (limited to 'misc/freeswitch') 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'); diff --git a/misc/freeswitch/scripts/dialplan_default.lua b/misc/freeswitch/scripts/dialplan_default.lua index 1c0a52e..42271b9 100644 --- a/misc/freeswitch/scripts/dialplan_default.lua +++ b/misc/freeswitch/scripts/dialplan_default.lua @@ -34,20 +34,37 @@ end -- dialplan object require 'dialplan.dialplan' -start_dialplan = dialplan.dialplan.Dialplan:new{ log = log, caller = start_caller, database = database }; +local start_dialplan = dialplan.dialplan.Dialplan:new{ log = log, caller = start_caller, database = database }; start_dialplan:configuration_read(); start_caller.local_node_id = start_dialplan.node_id; start_caller:init_channel_variables(); -- session:execute('info','notice'); -if not start_dialplan:check_auth() then - log:debug('AUTHENTICATION_REQUIRED - host: ' , start_caller.sip_contact_host, ', domain: ', start_dialplan.domain); - start_dialplan:hangup(407, start_dialplan.domain); - return false; +if start_caller.from_node and not start_dialplan:auth_node() then + log:debug('DIALPLAN_DEFAULT - node unauthorized - node_id: ', start_caller.node_id, ', domain: ', start_dialplan.domain); + start_dialplan:hangup(401, start_dialplan.domain); +else + if not start_dialplan:auth_sip_account() then + local gateway = start_dialplan:auth_gateway() + + if gateway then + start_caller.gateway_name = gateway.name; + start_caller.gateway_id = gateway.id; + start_caller.from_gateway = true; + start_caller.gateway = gateway; + else + log:debug('AUTHENTICATION_REQUIRED_SIP_ACCOUNT - contact host: ' , start_caller.sip_contact_host, ', ip: ', start_caller.sip_network_ip, ', domain: ', start_dialplan.domain); + start_dialplan:hangup(407, start_dialplan.domain); + if database then + database:release(); + end + return; + end + end end -if start_caller.from_node and not start_dialplan:check_auth_node() then +if start_caller.from_node then log:debug('AUTHENTICATION_REQUIRED_NODE - node_id: ', start_caller.node_id, ', domain: ', start_dialplan.domain); start_dialplan:hangup(407, start_dialplan.domain); else -- cgit v1.2.3 From 1debae060b1c4a816f4565ad55490fee61c6472b Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 16 Jan 2013 09:28:38 +0100 Subject: dump_variables dialplan option added --- misc/freeswitch/scripts/dialplan_default.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/dialplan_default.lua b/misc/freeswitch/scripts/dialplan_default.lua index 42271b9..eb80ae4 100644 --- a/misc/freeswitch/scripts/dialplan_default.lua +++ b/misc/freeswitch/scripts/dialplan_default.lua @@ -39,7 +39,9 @@ start_dialplan:configuration_read(); start_caller.local_node_id = start_dialplan.node_id; start_caller:init_channel_variables(); --- session:execute('info','notice'); +if start_dialplan.config.parameters.dump_variables then + start_caller:execute('info', 'notice'); +end if start_caller.from_node and not start_dialplan:auth_node() then log:debug('DIALPLAN_DEFAULT - node unauthorized - node_id: ', start_caller.node_id, ', domain: ', start_dialplan.domain); -- cgit v1.2.3 From 473e6c52eff0576829138b59b99f83917ff6b0e9 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 16 Jan 2013 10:31:01 +0100 Subject: faster try function --- misc/freeswitch/scripts/common/str.lua | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/str.lua b/misc/freeswitch/scripts/common/str.lua index ca6dcd9..c366fda 100644 --- a/misc/freeswitch/scripts/common/str.lua +++ b/misc/freeswitch/scripts/common/str.lua @@ -5,23 +5,13 @@ module(...,package.seeall) function try(array, arguments) - local argument = arguments:match('^(.-)%.') or arguments; - local remaining_arguments = arguments:match('%.(.-)$'); - argument = tonumber(argument) or argument; + local result = array; - if argument and type(array) == 'table' then - if remaining_arguments then - if type(array[argument]) == 'table' then - return try(array[argument], remaining_arguments); - else - return nil; - end - else - return array[argument]; - end - end - - return nil; + arguments:gsub('([^%.]+)', function(entry) + local success, result = pcall(function() result = (result[tonumber(entry) or entry]); end); + end); + + return result; end -- to number -- 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') 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') 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 d95917ecbc5d0efbc1b4b67c1974d7f0421eebf9 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 16 Jan 2013 16:07:40 +0100 Subject: set gateway prefix --- misc/freeswitch/scripts/common/gateway.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/gateway.lua b/misc/freeswitch/scripts/common/gateway.lua index 6e9fbfb..5c76aba 100644 --- a/misc/freeswitch/scripts/common/gateway.lua +++ b/misc/freeswitch/scripts/common/gateway.lua @@ -16,6 +16,7 @@ function Gateway.new(self, arg) self.log = arg.log; self.database = arg.database; self.record = arg.record; + self.GATEWAY_PREFIX = 'gateway'; return object; end -- cgit v1.2.3 From 7b3582a93d939ae131a608f500654065e8bd18cd Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 16 Jan 2013 16:08:11 +0100 Subject: set gateway name --- misc/freeswitch/scripts/configuration.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index b4dc0f6..1162e97 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -49,7 +49,7 @@ function gateways(database, profile_name) gateways_xml = gateways_xml .. xml:element{ 'gateway', - name = gateway.name, + name = gateway_class.GATEWAY_PREFIX .. gateway.id, xml:from_hash('param', parameters, 'name', 'value'), }; 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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 a76f384bef7deed913af1e2ee54eb1c295b62edd Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 11:55:18 +0100 Subject: gateways ini rexample removed --- misc/freeswitch/scripts/ini/gateways.ini.example | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 misc/freeswitch/scripts/ini/gateways.ini.example (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/ini/gateways.ini.example b/misc/freeswitch/scripts/ini/gateways.ini.example deleted file mode 100644 index b6ae018..0000000 --- a/misc/freeswitch/scripts/ini/gateways.ini.example +++ /dev/null @@ -1,23 +0,0 @@ -; Gemeinschaft 5 gateways configuration file -; (c) AMOOMA GmbH 2012 -; - -[gateway1] -profile = gemeinschaft -name = gateway1 -username = gateway1 -realm = gemeinschaft -password = freeswitch -extension = default -proxy = 192.168.0.1 -expire-seconds = 600 -register = true - -[gateway2] -profile = gemeinschaft -name = sipgate -username = 1234567e0 -password = ABCdeF -proxy = sipgate.com -register = true -extension = {sip_to_user} -- 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') 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 3a91509c6c668cc634d667a2e1c7144873a39861 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 12:10:48 +0100 Subject: gateway find_by_name method added --- misc/freeswitch/scripts/common/gateway.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/gateway.lua b/misc/freeswitch/scripts/common/gateway.lua index 5c76aba..e50c763 100644 --- a/misc/freeswitch/scripts/common/gateway.lua +++ b/misc/freeswitch/scripts/common/gateway.lua @@ -52,6 +52,27 @@ function Gateway.find_by_id(self, id) end +function Gateway.find_by_name(self, name) + local gateway_name = name:gsub('([^%a%d%._%+])', ''); + + local sql_query = 'SELECT * FROM `gateways` WHERE `name`= "' .. gateway_name .. '" LIMIT 1'; + + local gateway = nil; + self.database:query(sql_query, function(entry) + gateway = Gateway:new(self); + gateway.record = entry; + gateway.id = tonumber(entry.id); + gateway.name = entry.name; + end) + + if gateway then + gateway.settings = self:config_table_get('gateway_settings', gateway.id); + end + + return gateway; +end + + function Gateway.authenticate(self, technology, caller) local sql_query = 'SELECT `c`.`name`, `c`.`id`, `a`.`value` `auth_source`, `b`.`value` `auth_pattern` \ FROM `gateway_settings` `a` \ -- cgit v1.2.3 From c7d5128985e4f4480068f467ad8efafdc7f7b7ed Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 12:13:11 +0100 Subject: configuration.sip removed --- misc/freeswitch/scripts/configuration.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index 1162e97..92ae7d8 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -312,10 +312,9 @@ function directory_sip_account(database) if string.len(auth_name) > 3 and auth_name:sub(1, 3) == 'gw+' then local gateway_name = auth_name:sub(4); domain = domain or freeswitch.API():execute('global_getvar', 'domain'); - require 'configuration.sip' - log:notice('DATABASE: ', database); - local sip_gateway = configuration.sip.Sip:new{ log = log, database = database}:find_gateway_by_name(gateway_name); - if sip_gateway ~= nil and next(sip_gateway) ~= nil then + require 'common.gateway' + local sip_gateway = common.gateway.Gateway:new{ log = self.log, database = self.database }:find_by_name(gateway_name); + if sip_gateway then log:debug('DIRECTORY_GATEWAY - name: ', gateway_name, ', auth_name: ', auth_name); local user_variables = { @@ -332,7 +331,7 @@ function directory_sip_account(database) 'params', xml:element{ 'param', - password = sip_gateway.password, + password = sip_gateway.record.password, } }, xml:element{ -- cgit v1.2.3 From 5e46709cadac227cbe5a2459a48d284ad657db36 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 12:17:03 +0100 Subject: find_gateway_by_name method removed --- misc/freeswitch/scripts/configuration/sip.lua | 6 ------ 1 file changed, 6 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/configuration/sip.lua b/misc/freeswitch/scripts/configuration/sip.lua index 78143bc..4679aae 100644 --- a/misc/freeswitch/scripts/configuration/sip.lua +++ b/misc/freeswitch/scripts/configuration/sip.lua @@ -18,12 +18,6 @@ function Sip.new(self, arg) return object; end --- find gateway by name -function Sip.find_gateway_by_name(self, name) - require 'common.configuration_file' - return common.configuration_file.get('/opt/freeswitch/scripts/ini/gateways.ini', name); -end - -- list sip domains function Sip.domains(self) local sql_query = 'SELECT * FROM `sip_domains`'; -- cgit v1.2.3 From b5b1a19dd00eb8455ea21072bdd8249c82172619 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 12:18:39 +0100 Subject: save code lines --- misc/freeswitch/scripts/event_manager.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/event_manager.lua b/misc/freeswitch/scripts/event_manager.lua index 0e3c0e0..707b8a2 100644 --- a/misc/freeswitch/scripts/event_manager.lua +++ b/misc/freeswitch/scripts/event_manager.lua @@ -17,10 +17,9 @@ if not database:connected() then end require "configuration.sip" -local sip = configuration.sip.Sip:new{ log = log, database = database } +local domains = configuration.sip.Sip:new{ log = log, database = database }:domains(); local domain = '127.0.0.1'; -local domains = sip:domains(); if domains[1] then domain = domains[1]['host']; else -- 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/acd_wait.lua | 2 +- misc/freeswitch/scripts/common/call_forwarding.lua | 2 +- misc/freeswitch/scripts/common/call_history.lua | 2 +- misc/freeswitch/scripts/common/conference.lua | 2 +- misc/freeswitch/scripts/common/configuration_file.lua | 2 +- misc/freeswitch/scripts/common/fapi.lua | 2 +- misc/freeswitch/scripts/common/ipcalc.lua | 2 +- misc/freeswitch/scripts/common/log.lua | 2 +- misc/freeswitch/scripts/common/phone_number.lua | 2 +- misc/freeswitch/scripts/common/routing_tables.lua | 2 +- misc/freeswitch/scripts/common/sip_account.lua | 2 +- misc/freeswitch/scripts/common/str.lua | 2 +- misc/freeswitch/scripts/common/sync_log.lua | 2 +- misc/freeswitch/scripts/configuration.lua | 2 +- misc/freeswitch/scripts/configuration/sip.lua | 2 +- 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 +- misc/freeswitch/scripts/dialplan_default.lua | 2 +- misc/freeswitch/scripts/event/call_history_save.lua | 2 +- misc/freeswitch/scripts/event/cdr_save.lua | 2 +- misc/freeswitch/scripts/event/event.lua | 2 +- misc/freeswitch/scripts/event/perimeter.lua | 2 +- misc/freeswitch/scripts/event_manager.lua | 2 +- misc/freeswitch/scripts/fax_daemon.lua | 2 +- misc/freeswitch/scripts/ini/routes.ini | 2 +- misc/freeswitch/scripts/phones/phone.lua | 2 +- misc/freeswitch/scripts/phones/siemens.lua | 2 +- misc/freeswitch/scripts/phones/snom.lua | 2 +- misc/freeswitch/scripts/send_fax.lua | 2 +- 41 files changed, 41 insertions(+), 41 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/acd_wait.lua b/misc/freeswitch/scripts/acd_wait.lua index fd16bea..c05cc24 100644 --- a/misc/freeswitch/scripts/acd_wait.lua +++ b/misc/freeswitch/scripts/acd_wait.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5: acd call handler --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- local caller_uuid = argv[1]; diff --git a/misc/freeswitch/scripts/common/call_forwarding.lua b/misc/freeswitch/scripts/common/call_forwarding.lua index 3942d05..400fcde 100644 --- a/misc/freeswitch/scripts/common/call_forwarding.lua +++ b/misc/freeswitch/scripts/common/call_forwarding.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: call forwarding class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/common/call_history.lua b/misc/freeswitch/scripts/common/call_history.lua index 7a9ac07..7e1e22b 100644 --- a/misc/freeswitch/scripts/common/call_history.lua +++ b/misc/freeswitch/scripts/common/call_history.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: call_history class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/common/conference.lua b/misc/freeswitch/scripts/common/conference.lua index a7b21c3..ca5fa62 100644 --- a/misc/freeswitch/scripts/common/conference.lua +++ b/misc/freeswitch/scripts/common/conference.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: conference class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/common/configuration_file.lua b/misc/freeswitch/scripts/common/configuration_file.lua index 67e1f3b..3b3efbc 100644 --- a/misc/freeswitch/scripts/common/configuration_file.lua +++ b/misc/freeswitch/scripts/common/configuration_file.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: configuration file --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/common/fapi.lua b/misc/freeswitch/scripts/common/fapi.lua index 0a05155..5b96633 100644 --- a/misc/freeswitch/scripts/common/fapi.lua +++ b/misc/freeswitch/scripts/common/fapi.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: FS api class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/common/ipcalc.lua b/misc/freeswitch/scripts/common/ipcalc.lua index 5c19d20..49cb56c 100644 --- a/misc/freeswitch/scripts/common/ipcalc.lua +++ b/misc/freeswitch/scripts/common/ipcalc.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: ip calculation functions --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/common/log.lua b/misc/freeswitch/scripts/common/log.lua index d0d13dc..5aff2b8 100644 --- a/misc/freeswitch/scripts/common/log.lua +++ b/misc/freeswitch/scripts/common/log.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: log --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/common/phone_number.lua b/misc/freeswitch/scripts/common/phone_number.lua index 4df0d57..6635296 100644 --- a/misc/freeswitch/scripts/common/phone_number.lua +++ b/misc/freeswitch/scripts/common/phone_number.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: phone number class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/common/routing_tables.lua b/misc/freeswitch/scripts/common/routing_tables.lua index 34d0143..f28b5c5 100644 --- a/misc/freeswitch/scripts/common/routing_tables.lua +++ b/misc/freeswitch/scripts/common/routing_tables.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: routing table functions --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/common/sip_account.lua b/misc/freeswitch/scripts/common/sip_account.lua index 28a00df..8dd432b 100644 --- a/misc/freeswitch/scripts/common/sip_account.lua +++ b/misc/freeswitch/scripts/common/sip_account.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: sip account class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/common/str.lua b/misc/freeswitch/scripts/common/str.lua index c366fda..32f054e 100644 --- a/misc/freeswitch/scripts/common/str.lua +++ b/misc/freeswitch/scripts/common/str.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: string functions --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/common/sync_log.lua b/misc/freeswitch/scripts/common/sync_log.lua index 05b0dcf..3fdb646 100644 --- a/misc/freeswitch/scripts/common/sync_log.lua +++ b/misc/freeswitch/scripts/common/sync_log.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: sync log class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index 92ae7d8..9e62bb6 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 dynamic freeswitch configuration --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- function nodes(database, local_node_id) diff --git a/misc/freeswitch/scripts/configuration/sip.lua b/misc/freeswitch/scripts/configuration/sip.lua index 4679aae..6f5b204 100644 --- a/misc/freeswitch/scripts/configuration/sip.lua +++ b/misc/freeswitch/scripts/configuration/sip.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: sip configuration class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) 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) diff --git a/misc/freeswitch/scripts/dialplan_default.lua b/misc/freeswitch/scripts/dialplan_default.lua index eb80ae4..7caff57 100644 --- a/misc/freeswitch/scripts/dialplan_default.lua +++ b/misc/freeswitch/scripts/dialplan_default.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 default dialplan --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- diff --git a/misc/freeswitch/scripts/event/call_history_save.lua b/misc/freeswitch/scripts/event/call_history_save.lua index 057ca16..ba7a8f6 100644 --- a/misc/freeswitch/scripts/event/call_history_save.lua +++ b/misc/freeswitch/scripts/event/call_history_save.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: call_history event handler class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/event/cdr_save.lua b/misc/freeswitch/scripts/event/cdr_save.lua index ed53aa3..e7ac64a 100644 --- a/misc/freeswitch/scripts/event/cdr_save.lua +++ b/misc/freeswitch/scripts/event/cdr_save.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: cdr event handler class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/event/event.lua b/misc/freeswitch/scripts/event/event.lua index c57b32a..08d8bfe 100644 --- a/misc/freeswitch/scripts/event/event.lua +++ b/misc/freeswitch/scripts/event/event.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: event manager class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/event/perimeter.lua b/misc/freeswitch/scripts/event/perimeter.lua index 86c50d4..5bbb032 100644 --- a/misc/freeswitch/scripts/event/perimeter.lua +++ b/misc/freeswitch/scripts/event/perimeter.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: cdr event handler class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/event_manager.lua b/misc/freeswitch/scripts/event_manager.lua index 707b8a2..4e78ccf 100644 --- a/misc/freeswitch/scripts/event_manager.lua +++ b/misc/freeswitch/scripts/event_manager.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5.0 event handler --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- -- Set logger diff --git a/misc/freeswitch/scripts/fax_daemon.lua b/misc/freeswitch/scripts/fax_daemon.lua index cfe7c4e..6609fe6 100644 --- a/misc/freeswitch/scripts/fax_daemon.lua +++ b/misc/freeswitch/scripts/fax_daemon.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5.0 fax daemon --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- local MAIN_LOOP_SLEEP_TIME = 30; diff --git a/misc/freeswitch/scripts/ini/routes.ini b/misc/freeswitch/scripts/ini/routes.ini index 33d2f38..535ba63 100644 --- a/misc/freeswitch/scripts/ini/routes.ini +++ b/misc/freeswitch/scripts/ini/routes.ini @@ -1,5 +1,5 @@ ; Gemeinschaft 5 routing configuration file -; (c) AMOOMA GmbH 2012 +; (c) AMOOMA GmbH 2012-2013 ; [general] diff --git a/misc/freeswitch/scripts/phones/phone.lua b/misc/freeswitch/scripts/phones/phone.lua index bc2aa3d..856398b 100644 --- a/misc/freeswitch/scripts/phones/phone.lua +++ b/misc/freeswitch/scripts/phones/phone.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: phone class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/phones/siemens.lua b/misc/freeswitch/scripts/phones/siemens.lua index 71bb40a..ad2447a 100644 --- a/misc/freeswitch/scripts/phones/siemens.lua +++ b/misc/freeswitch/scripts/phones/siemens.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: general siemens model class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/phones/snom.lua b/misc/freeswitch/scripts/phones/snom.lua index 80d1fce..096ccb7 100644 --- a/misc/freeswitch/scripts/phones/snom.lua +++ b/misc/freeswitch/scripts/phones/snom.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5 module: general snom model class --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- module(...,package.seeall) diff --git a/misc/freeswitch/scripts/send_fax.lua b/misc/freeswitch/scripts/send_fax.lua index 321a5b1..a3de5f6 100644 --- a/misc/freeswitch/scripts/send_fax.lua +++ b/misc/freeswitch/scripts/send_fax.lua @@ -1,5 +1,5 @@ -- Gemeinschaft 5.0 --- (c) AMOOMA GmbH 2012 +-- (c) AMOOMA GmbH 2012-2013 -- local FAX_FILE_PATH = "/opt/GS5/public/uploads/fax_document/tiff/"; -- 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') 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') 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 1de349a41e84981171a197546e01eab2f1d2c09e Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 14:21:03 +0100 Subject: ini dependance removed --- misc/freeswitch/scripts/send_fax.lua | 52 +++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 25 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/send_fax.lua b/misc/freeswitch/scripts/send_fax.lua index 321a5b1..7099223 100644 --- a/misc/freeswitch/scripts/send_fax.lua +++ b/misc/freeswitch/scripts/send_fax.lua @@ -80,36 +80,38 @@ local session = nil if phone_number then session = freeswitch.Session("[" .. table.concat(origination_variables, ",") .. "]loopback/" .. destination_number .. "/default"); else - local owner_class = common.str.downcase(fax_account.record.fax_accountable_type); - - local caller = {} - caller.caller_phone_numbers = phone_number_class:list_by_owner(fax_account.record.id, 'FaxAccount'); - caller.account = fax_account; - caller.auth_account = fax_account; - caller.caller_id_name = fax_account.record.station_id; - - if owner_class == 'user' then - require 'dialplan.user' - caller.auth_account.owner = dialplan.user.User:new{ log = log, database = database }:find_by_id(fax_account.record.fax_accountable_id); - if caller.auth_account.owner then - caller.auth_account.owner.groups = caller.auth_account.owner:list_groups(); - end - elseif owner_class == 'tenant' then - require 'dialplan.tenant' - caller.auth_account.owner = dialplan.tenant.Tenant:new{ log = log, database = database }:find_by_id(fax_account.record.fax_accountable_id); + -- local owner_class = common.str.downcase(fax_account.record.fax_accountable_type); + + local caller = { + destination_number = destination_number, + caller_id_name = fax_account.record.station_id, + account_type = 'faxaccount', + account_uuid = fax_account.uuid, + auth_account_type = 'faxaccount', + auth_account_uuid = fax_account.uuid, + } + + -- caller.caller_phone_numbers = phone_number_class:list_by_owner(fax_account.record.id, 'FaxAccount'); + + require 'dialplan.dialplan' + local dialplan = dialplan.dialplan.Dialplan:new{ log = log, caller = caller, database = database }; + local result = dialplan:retrieve_caller_data(); + + local dialplan_router = require('dialplan.router'); + local routes = dialplan_router.Router:new{ log = log, database = database, caller = caller, variables = caller }:route_run('outbound', destination_number); + + if not routes or #routes == 0 then + log:notice('SWITCH - no route - number: ', destination_number); + return { continue = false, code = 404, phrase = 'No route' } end - require 'common.configuration_file' - local routing_table = common.configuration_file.get('/opt/freeswitch/scripts/ini/routes.ini'); - require 'dialplan.route' - local routes = dialplan.route.Route:new{ log = log, database = database, routing_table = routing_table }:outbound(caller, destination_number); - for index, route in ipairs(routes) do - log:info('FAX_SEND - ', route.class, '=', route.endpoint, ', number: ', route.value); - if route.class == 'gateway' then + log:info('FAX_SEND - ', route.type, '=', route.id, '/', route.gateway,', number: ', route.destination_number); + if route.type == 'gateway' then table.insert(origination_variables, "origination_caller_id_number='" .. (route.caller_id_number or caller.caller_phone_numbers[1]) .. "'"); table.insert(origination_variables, "origination_caller_id_name='" .. (route.caller_id_name or fax_account.record.station_id) .. "'"); - session = freeswitch.Session('[' .. table.concat(origination_variables, ',') .. ']sofia/gateway/' .. route.endpoint .. '/' .. route.value); + session = freeswitch.Session('[' .. table.concat(origination_variables, ',') .. ']sofia/gateway/' .. route.gateway .. '/' .. route.destination_number); + log:notice('SESSION: ', session); break; end end -- cgit v1.2.3 From 13f3c5274a025c6cc02200ea56488770d4a23984 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 14:21:41 +0100 Subject: comments removed --- misc/freeswitch/scripts/send_fax.lua | 4 ---- 1 file changed, 4 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/send_fax.lua b/misc/freeswitch/scripts/send_fax.lua index 7099223..ffb81e2 100644 --- a/misc/freeswitch/scripts/send_fax.lua +++ b/misc/freeswitch/scripts/send_fax.lua @@ -80,8 +80,6 @@ local session = nil if phone_number then session = freeswitch.Session("[" .. table.concat(origination_variables, ",") .. "]loopback/" .. destination_number .. "/default"); else - -- local owner_class = common.str.downcase(fax_account.record.fax_accountable_type); - local caller = { destination_number = destination_number, caller_id_name = fax_account.record.station_id, @@ -90,8 +88,6 @@ else auth_account_type = 'faxaccount', auth_account_uuid = fax_account.uuid, } - - -- caller.caller_phone_numbers = phone_number_class:list_by_owner(fax_account.record.id, 'FaxAccount'); require 'dialplan.dialplan' local dialplan = dialplan.dialplan.Dialplan:new{ log = log, caller = caller, database = database }; -- cgit v1.2.3 From 6994ba4b5fecc2d532770f922d76227a175e3d71 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 14:22:24 +0100 Subject: ini removed --- misc/freeswitch/scripts/ini/routes.ini | 80 ---------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 misc/freeswitch/scripts/ini/routes.ini (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/ini/routes.ini b/misc/freeswitch/scripts/ini/routes.ini deleted file mode 100644 index 33d2f38..0000000 --- a/misc/freeswitch/scripts/ini/routes.ini +++ /dev/null @@ -1,80 +0,0 @@ -; Gemeinschaft 5 routing configuration file -; (c) AMOOMA GmbH 2012 -; - -[general] - - -[prerouting] -^%*0%*$ , f-li -^%*0%*(%d+)#*$ , f-li-%1 -^%*0%*(%d+)%*(%d+)#*$ , f-li-%1-%2 -^#0#$ , f-lo -^%*5%*(%d+)#$ , f-acdmtg-0-%1 -^%*30#$ , f-clipon -^#30#$ , f-clipoff -^%*31#$ , f-cliroff -^#31#$ , f-cliron -^%*31#(%d+)$ , f-dcliroff-%1 -^#31#(%d+)$ , f-dcliron-%1 -^%*43#$ , f-cwaon -^#43#$ , f-cwaoff -^#002#$ , f-cfoff -^##002#$ , f-cfdel -^%*21#$ , f-cfu -^%*21%*(%d+)#$ , f-cfu-%1 -^%*%*21%*(%d+)#$ , f-cfu-%1 -^#21#$ , f-cfuoff -^##21#$ , f-cfudel -^%*61#$ , f-cfn -^%*61%*(%d+)#$ , f-cfn-%1 -^%*%*61%*(%d+)#$ , f-cfn-%1 -^%*61%*(%d+)%*(%d+)#$ , f-cfn-%1-%2 -^%*%*61%*(%d+)%*(%d+)#$ , f-cfn-%1-%2 -^#61#$ , f-cfnoff -^##61#$ , f-cfndel -^%*62#$ , f-cfo -^%*62%*(%d+)#$ , f-cfo-%1 -^%*%*62%*(%d+)#$ , f-cfo-%1 -^#62#$ , f-cfooff -^##62#$ , f-cfodel -^%*67#$ , f-cfb -^%*67%*(%d+)#$ , f-cfb-%1 -^%*%*67%*(%d+)#$ , f-cfb-%1 -^#67#$ , f-cfboff -^##67#$ , f-cfbdel -^%*66#$ , f-redial -^%*98$ , f-vmcheck -^%*98#$ , f-vmcheck -^%*98%*(%d+)#$ , f-vmcheck-%1 -^%*1337%*1%*1#$ , f-loaon -^%*1337%*1%*0#$ , f-loaoff - -^00(%d+)$ , +%1 -^0(%d+)$ , +49%1 - - -[outbound] -^%+(%d+)$ , class=gateway, endpoint=gateway1, group=users, %1 - - -[failover] -UNALLOCATED_NUMBER = true -NORMAL_TEMPORARY_FAILURE = true - - -[outbound_cid_number] - - -[outbound_cid_name] - - -[inbound] -^00(%d+)$ , +%1 -^0(%d+)$ , +49%1 - -[inbound_cid_number] -^00(%d+)$ , +%1 -^0(%d+)$ , +49%1 - -[inbound_cid_name] -- 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') 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 4f0e8420bd829abef8b04b51d9df800dfd1ce977 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 15:13:16 +0100 Subject: fixed music on hold configuration --- misc/freeswitch/conf/freeswitch.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml index c5dd3f1..3c098fc 100644 --- a/misc/freeswitch/conf/freeswitch.xml +++ b/misc/freeswitch/conf/freeswitch.xml @@ -492,21 +492,21 @@ - - + + - + - + -- 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') 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') 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 cc16ae7cc59189468854c455bde43a2609350964 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 20 Jan 2013 16:18:19 +0100 Subject: unused variable removed --- misc/freeswitch/scripts/send_fax.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/send_fax.lua b/misc/freeswitch/scripts/send_fax.lua index 35460a3..11cd1d7 100644 --- a/misc/freeswitch/scripts/send_fax.lua +++ b/misc/freeswitch/scripts/send_fax.lua @@ -94,7 +94,7 @@ else local result = dialplan:retrieve_caller_data(); local dialplan_router = require('dialplan.router'); - local routes = dialplan_router.Router:new{ log = log, database = database, caller = caller, variables = caller }:route_run('outbound', destination_number); + local routes = dialplan_router.Router:new{ log = log, database = database, caller = caller, variables = caller }:route_run('outbound'); if not routes or #routes == 0 then log:notice('SWITCH - no route - number: ', destination_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/common/routing_tables.lua | 66 ------ misc/freeswitch/scripts/dialplan/route.lua | 265 ---------------------- 2 files changed, 331 deletions(-) delete mode 100644 misc/freeswitch/scripts/common/routing_tables.lua delete mode 100644 misc/freeswitch/scripts/dialplan/route.lua (limited to 'misc/freeswitch') diff --git a/misc/freeswitch/scripts/common/routing_tables.lua b/misc/freeswitch/scripts/common/routing_tables.lua deleted file mode 100644 index f28b5c5..0000000 --- a/misc/freeswitch/scripts/common/routing_tables.lua +++ /dev/null @@ -1,66 +0,0 @@ --- Gemeinschaft 5 module: routing table functions --- (c) AMOOMA GmbH 2012-2013 --- - -module(...,package.seeall) - -function expand_variables(line, variables_list) - variables_list = variables_list or {}; - - return (line:gsub('{([%a%d_]+)}', function(captured) - return variables_list[captured] or ''; - end)) -end - - -function match_route(entry, search_str, variables_list) - if not entry or not search_str then - return { error = 'No input values' }; - end - - local result = nil; - local success = nil; - success, result = pcall(string.find, search_str, entry[1]); - - if not success then - return { error = result, line = line } - elseif result then - local route = { - pattern = entry[1], - value = search_str:gsub(entry[1], expand_variables(entry[#entry], variables_list)), - } - - for index = 2, #entry-1 do - local attribute = entry[index]:match('^(.-)%s*='); - if attribute then - route[attribute] = entry[index]:match('=%s*(.-)$'); - end - end - - return route; - end - - return {}; -end - - -function match_caller_id(entry, search_str, variables_list) - if not entry or not search_str then - return { error = 'No input values' }; - end - local result = nil; - local success = nil; - success, result = pcall(string.find, search_str, entry[1]); - if not success then - return { error = result, line = line } - elseif result then - return { - value = search_str:gsub(entry[1], expand_variables(entry[4], variables_list)), - class = entry[2], - endpoint = entry[3], - pattern = entry[1], - } - end - - return {}; -end 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') 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') 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') 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