summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/dialplan
diff options
context:
space:
mode:
Diffstat (limited to 'misc/freeswitch/scripts/dialplan')
-rw-r--r--misc/freeswitch/scripts/dialplan/dialplan.lua3
-rw-r--r--misc/freeswitch/scripts/dialplan/fax.lua7
-rw-r--r--misc/freeswitch/scripts/dialplan/router.lua26
-rw-r--r--misc/freeswitch/scripts/dialplan/sip_call.lua47
-rw-r--r--misc/freeswitch/scripts/dialplan/voicemail.lua12
5 files changed, 58 insertions, 37 deletions
diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua
index b92dc70..ff4adc6 100644
--- a/misc/freeswitch/scripts/dialplan/dialplan.lua
+++ b/misc/freeswitch/scripts/dialplan/dialplan.lua
@@ -135,7 +135,7 @@ 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);
+ local gateway = gateway_class:authenticate(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);
@@ -565,6 +565,7 @@ function Dialplan.faxaccount(self, destination)
if not fax_account:insert_document(fax_document) then
self.log:error('FAX_RECEIVE - error inserting fax document to database - fax_account=', fax_account.id, '/', fax_account.uuid, ', file: ', fax_document.filename);
end
+ fax_account:trigger_notification(fax_account.id, self.caller.uuid);
end
return { continue = false, code = 200, phrase = 'OK' }
diff --git a/misc/freeswitch/scripts/dialplan/fax.lua b/misc/freeswitch/scripts/dialplan/fax.lua
index aa29ff6..49a45d9 100644
--- a/misc/freeswitch/scripts/dialplan/fax.lua
+++ b/misc/freeswitch/scripts/dialplan/fax.lua
@@ -230,3 +230,10 @@ function Fax.insert_document(self, record)
return self.database:query(sql_query);
end
+
+function Fax.trigger_notification(self, fax_document_id, uuid)
+ local command = 'http_request.lua ' .. uuid .. ' http://127.0.0.1/trigger/fax?fax_account_id=' .. tostring(fax_document_id);
+
+ require 'common.fapi'
+ return common.fapi.FApi:new():execute('luarun', command);
+end
diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua
index 7e64d7b..cdcb58b 100644
--- a/misc/freeswitch/scripts/dialplan/router.lua
+++ b/misc/freeswitch/scripts/dialplan/router.lua
@@ -52,27 +52,27 @@ function Router.read_table(self, table_name)
end
-function Router.expand_variables(self, line, variables)
+function Router.expand_variables(self, line, variables, variables2)
return (line:gsub('{([%a%d%._]+)}', function(captured)
- return common.str.try(variables, captured) or '';
+ return common.str.try(variables, captured) or common.str.try(variables2, captured) or '';
end))
end
-function Router.element_match(self, pattern, search_string, replacement)
+function Router.element_match(self, pattern, search_string, replacement, route_variables)
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, self.variables));
+ return true, search_string:gsub(pattern, self:expand_variables(replacement, route_variables, self.variables));
end
return false;
end
-function Router.element_match_group(self, pattern, groups, replacement, use_key)
+function Router.element_match_group(self, pattern, groups, replacement, use_key, route_variables)
if type(groups) ~= 'table' then
return false;
end
@@ -81,7 +81,7 @@ function Router.element_match_group(self, pattern, groups, replacement, use_key)
if use_key then
value = key;
end
- result, replaced_value = self:element_match(pattern, tostring(value), replacement);
+ result, replaced_value = self:element_match(pattern, tostring(value), replacement, route_variables);
if result then
return true, replaced_value;
end
@@ -94,7 +94,8 @@ function Router.route_match(self, route)
gateway = 'gateway' .. route.endpoint_id,
['type'] = route.endpoint_type,
id = route.endpoint_id,
- channel_variables = {}
+ destination_number = common.str.try(self, 'caller.destination_number'),
+ channel_variables = {},
};
local route_matches = false;
@@ -108,13 +109,16 @@ 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 = self:expand_variables(element.replacement, self.variables);
+ replacement = self:expand_variables(element.replacement, destination, self.variables);
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));
+ if not command or not variable_name then
+ local search_string = tostring(common.str.try(destination, element.var_in) or common.str.try(self.caller, element.var_in));
+ result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement), destination);
+ elseif command == 'var' then
+ local search_string = tostring(common.str.try(self.caller, element.var_in));
+ result, replacement = self:element_match(tostring(element.pattern), 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');
diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua
index 3f56753..d1557e9 100644
--- a/misc/freeswitch/scripts/dialplan/sip_call.lua
+++ b/misc/freeswitch/scripts/dialplan/sip_call.lua
@@ -89,20 +89,21 @@ 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, ', caller_id: "', destination.caller_id_name, '" <', destination.caller_id_number, '>');
+ self.log:info('FORK ', index, '/', #destinations, ' - ', destination.type, '=', destination.id, '/', destination.uuid, '@', destination.node_id, ', number: ', destination.number, ', 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');
end
- if not destination.node_local or destination.type == 'node' then
+ if not destination.node_local then
require 'common.node'
- local node = nil;
- if tonumber(destination.gateway) then
- node = common.node.Node:new{ log = self.log, database = self.database }:find_by_id(tonumber(destination.gateway));
- else
- node = common.node.Node:new{ log = self.log, database = self.database }:find_by_id(destination.node_id);
+ local node = common.node.Node:new{ log = self.log, database = self.database }:find_by_id(destination.node_id);
+ if node then
+ table.insert(origination_variables, 'sip_h_X-GS_node_id=' .. self.caller.local_node_id);
+ table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/gateway/' .. node.record.name .. '/' .. destination.number);
end
+ elseif destination.type == 'node' then
+ local node = common.node.Node:new{ log = self.log, database = self.database }:find_by_id(destination.id);
if node then
table.insert(origination_variables, 'sip_h_X-GS_node_id=' .. self.caller.local_node_id);
table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/gateway/' .. node.record.name .. '/' .. destination.number);
@@ -129,18 +130,26 @@ function SipCall.fork(self, destinations, arg )
call_result = { code = 486, phrase = 'User busy', disposition = 'USER_BUSY' };
end
elseif destination.type == 'gateway' then
- if destination.caller_id_number then
- table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'");
- end
- if destination.caller_id_name then
- table.insert(origination_variables, "origination_caller_id_name='" .. destination.caller_id_name .. "'");
- end
- if destination.channel_variables then
- for key, value in pairs(destination.channel_variables) do
- table.insert(origination_variables, tostring(key) .. "='" .. tostring(value) .. "'");
+ require 'common.gateway'
+ local gateway = common.gateway.Gateway:new{ log = self.log, database = self.database}:find_by_id(destination.id);
+
+ if gateway and gateway.outbound then
+ if destination.caller_id_number then
+ table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'");
+ end
+ if destination.caller_id_name then
+ table.insert(origination_variables, "origination_caller_id_name='" .. destination.caller_id_name .. "'");
end
+ if destination.channel_variables then
+ for key, value in pairs(destination.channel_variables) do
+ table.insert(origination_variables, tostring(key) .. "='" .. tostring(value) .. "'");
+ end
+ end
+
+ table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']' .. gateway:call_url(destination.number));
+ else
+ self.log:notice('FORK - gateway not found - gateway=', destination.id);
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
table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'");
@@ -173,8 +182,10 @@ function SipCall.fork(self, destinations, arg )
self.caller:execute('ring_ready');
end
+ local session_dialstring = '{local_var_clobber=true}' .. table.concat(dial_strings, ',');
+ self.log:debug('FORK SESSION_START - call_url: ', session_dialstring);
local start_time = os.time();
- local session_callee = freeswitch.Session('{local_var_clobber=true}' .. table.concat(dial_strings, ','), self.caller.session);
+ local session_callee = freeswitch.Session(session_dialstring, self.caller.session);
self.log:debug('FORK SESSION_INIT - dial_time: ', os.time() - start_time);
local answer_result = self:wait_answer(self.caller.session, session_callee, arg.timeout, start_time);
local fork_index = nil;
diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua
index 5d79ba3..4c96fbe 100644
--- a/misc/freeswitch/scripts/dialplan/voicemail.lua
+++ b/misc/freeswitch/scripts/dialplan/voicemail.lua
@@ -117,6 +117,7 @@ function Voicemail.leave(self, caller, phone_number)
caller.uuid .. "'"
);
caller:set_variable('voicemail_message_len', duration);
+ self:trigger_notification(caller);
else
caller:set_variable('voicemail_message_len');
end
@@ -125,14 +126,11 @@ function Voicemail.leave(self, caller, phone_number)
end
-function Voicemail.send_notify(self, caller)
- self.log:debug('VOICEMAIL_NOTIFY - account: ' .. self.record.auth_name .. ", id: " .. tostring(caller.uuid));
+function Voicemail.trigger_notification(self, caller)
+ local command = 'http_request.lua ' .. caller.uuid .. ' http://127.0.0.1/trigger/voicemail?sip_account_id=' .. tostring(self.id);
- local 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();
-
- return true;
+ require 'common.fapi'
+ return common.fapi.FApi:new():execute('luarun', command);
end