summaryrefslogtreecommitdiff
path: root/misc/freeswitch
diff options
context:
space:
mode:
Diffstat (limited to 'misc/freeswitch')
-rw-r--r--misc/freeswitch/scripts/common/gateway.lua52
-rw-r--r--misc/freeswitch/scripts/configuration.lua152
-rw-r--r--misc/freeswitch/scripts/dialplan/dialplan.lua16
3 files changed, 137 insertions, 83 deletions
diff --git a/misc/freeswitch/scripts/common/gateway.lua b/misc/freeswitch/scripts/common/gateway.lua
index c1b50a7..14c19fb 100644
--- a/misc/freeswitch/scripts/common/gateway.lua
+++ b/misc/freeswitch/scripts/common/gateway.lua
@@ -34,7 +34,11 @@ end
function Gateway.find_by_id(self, id)
- local sql_query = 'SELECT * FROM `gateways` WHERE `id`= ' .. tonumber(id) .. ' LIMIT 1';
+ local sql_query = 'SELECT `a`.*, `c`.`sip_host` `domain` \
+ FROM `gateways` `a` \
+ LEFT JOIN `gateway_settings` `b` ON `a`.`id` = `b`.`gateway_id` AND `b`.`name` = "inbound_username" \
+ LEFT JOIN `sip_registrations` `c` ON `b`.`value` = `c`.`sip_user` \
+ WHERE `a`.`id`= ' .. tonumber(id) .. ' LIMIT 1';
local gateway = nil;
self.database:query(sql_query, function(entry)
@@ -59,7 +63,42 @@ 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 sql_query = 'SELECT `a`.*, `c`.`sip_host` `domain` \
+ FROM `gateways` `a` \
+ LEFT JOIN `gateway_settings` `b` ON `a`.`id` = `b`.`gateway_id` AND `b`.`name` = "inbound_username" \
+ LEFT JOIN `sip_registrations` `c` ON `b`.`value` = `c`.`sip_user` \
+ WHERE `a`.`name`= ' .. self.database:escape(gateway_name, '"') .. ' LIMIT 1';
+
+ local gateway = nil;
+ self.database:query(sql_query, function(entry)
+ require 'common.str';
+ gateway = Gateway:new(self);
+ gateway.record = entry;
+ gateway.id = tonumber(entry.id);
+ gateway.name = entry.name;
+ gateway.technology = entry.technology;
+ gateway.outbound = common.str.to_b(entry.outbound);
+ gateway.inbound = common.str.to_b(entry.inbound);
+ end)
+
+ if gateway then
+ gateway.settings = self:config_table_get('gateway_settings', gateway.id);
+ end
+
+ return gateway;
+end
+
+
+function Gateway.find_by_auth_name(self, name)
+ local auth_name = name:gsub('([^%a%d%._%+])', '');
+
+ local sql_query = 'SELECT `c`.*, `a`.`value` `password`, `b`.`value` `username` \
+ FROM `gateway_settings` `a` \
+ INNER JOIN `gateway_settings` `b` \
+ ON (`a`.`gateway_id` = `b`.`gateway_id` AND `a`.`name` = "inbound_password" AND `b`.`name` = "inbound_username" AND `b`.`value` = ' .. self.database:escape(auth_name, '"') .. ') \
+ LEFT JOIN `gateways` `c` \
+ ON (`a`.`gateway_id` = `c`.`id`) \
+ WHERE `c`.`inbound` IS TRUE OR `c`.`outbound` IS TRUE LIMIT 1';
local gateway = nil;
self.database:query(sql_query, function(entry)
@@ -82,8 +121,15 @@ end
function Gateway.call_url(self, destination_number)
+ require 'common.str';
+
if self.technology == 'sip' then
- return 'sofia/gateway/' .. self.GATEWAY_PREFIX .. self.id .. '/' .. tostring(destination_number);
+ if self.settings.inbound_username and self.settings.inbound_password and not common.str.blank(self.record.domain) then
+ return 'sofia/' .. (self.settings.profile or 'gemeinschaft') .. '/' .. self.settings.inbound_username .. '%' .. self.record.domain;
+ else
+ return 'sofia/gateway/' .. self.GATEWAY_PREFIX .. self.id .. '/' .. tostring(destination_number);
+ end
+
elseif self.technology == 'xmpp' then
local destination_str = tostring(destination_number);
if self.settings.destination_domain then
diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua
index 6660c3d..be83ef5 100644
--- a/misc/freeswitch/scripts/configuration.lua
+++ b/misc/freeswitch/scripts/configuration.lua
@@ -371,6 +371,7 @@ end
function directory_sip_account(database)
+ require 'common.str';
require 'configuration.simple_xml'
local xml = configuration.simple_xml.SimpleXml:new();
@@ -381,21 +382,82 @@ function directory_sip_account(database)
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
- local gateway_name = auth_name:sub(4);
- domain = domain or freeswitch.API():execute('global_getvar', 'domain');
+ if not common.str.blank(auth_name) then
+ require 'common.sip_account'
+ local sip_account = common.sip_account.SipAccount:new{ log = log, database = database}:find_by_auth_name(auth_name);
+
+ 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);
+ user_xml = xml:element{
+ 'groups',
+ xml:element{
+ 'group',
+ name = 'default',
+ xml:element{
+ 'users',
+ xml:element{
+ 'user',
+ id = sip_account.record.auth_name,
+ xml:element{
+ 'params',
+ xml:from_hash('param', user_parameters, 'name', 'value'),
+ },
+ xml:element{
+ 'variables',
+ xml:from_hash('variable', user_variables, 'name', 'value'),
+ },
+ },
+ },
+ },
+ };
+ else
+ log:debug('DIRECTORY_SIP_ACCOUNT - auth_name: ', sip_account.record.auth_name, ', caller_name: ', sip_account.record.caller_name, ', domain: ', domain);
+
+ user_xml = xml:element{
+ 'user',
+ id = sip_account.record.auth_name,
+ xml:element{
+ 'params',
+ xml:from_hash('param', user_parameters, 'name', 'value'),
+ },
+ xml:element{
+ 'variables',
+ xml:from_hash('variable', user_variables, 'name', 'value'),
+ },
+ };
+ end
+ else
require 'common.gateway'
- local sip_gateway = common.gateway.Gateway:new{ log = self.log, database = self.database }:find_by_name(gateway_name);
+ local sip_gateway = common.gateway.Gateway:new{ log = log, database = database }:find_by_auth_name(auth_name);
+
if sip_gateway then
- log:debug('DIRECTORY_GATEWAY - name: ', gateway_name, ', auth_name: ', auth_name);
+ log:debug('DIRECTORY_GATEWAY - name: ', sip_gateway.name, ', auth_name: ', auth_name);
local user_variables = {
- user_context = "default",
- gs_from_gateway = "true",
- gs_gateway_name = gateway_name,
- gs_gateway_id = sip_gateway.id,
+ user_context = 'default',
+ gs_from_gateway = 'true',
+ gs_gateway_name = sip_gateway.name,
+ gs_gateway_id = sip_gateway.id,
+ gs_gateway_domain = domain,
}
user_xml = xml:element{
@@ -414,73 +476,7 @@ function directory_sip_account(database)
},
};
else
- log:debug('DIRECTORY_GATEWAY - gateway not found - name: ', gateway_name, ', auth_name: ', auth_name);
- end
- else
- require 'common.sip_account'
- local sip_account = common.sip_account.SipAccount:new{ log = log, database = database}:find_by_auth_name(auth_name);
-
- 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);
- user_xml = xml:element{
- 'groups',
- xml:element{
- 'group',
- name = 'default',
- xml:element{
- 'users',
- xml:element{
- 'user',
- id = sip_account.record.auth_name,
- xml:element{
- 'params',
- xml:from_hash('param', user_parameters, 'name', 'value'),
- },
- xml:element{
- 'variables',
- xml:from_hash('variable', user_variables, 'name', 'value'),
- },
- },
- },
- },
- };
- else
- log:debug('DIRECTORY_SIP_ACCOUNT - auth_name: ', sip_account.record.auth_name, ', caller_name: ', sip_account.record.caller_name, ', domain: ', domain);
-
- user_xml = xml:element{
- 'user',
- id = sip_account.record.auth_name,
- xml:element{
- 'params',
- xml:from_hash('param', user_parameters, 'name', 'value'),
- },
- xml:element{
- 'variables',
- xml:from_hash('variable', user_variables, 'name', 'value'),
- },
- };
- end
- else
- log:debug('DIRECTORY_SIP_ACCOUNT - sip account not found - auth_name: ', auth_name, ', domain: ', domain);
+ log:debug('DIRECTORY_SIP_ACCOUNT - neither a sip account nor a gateway found by SIP user name: ', auth_name, ', domain: ', domain);
-- fake sip_account configuration
user_parameters['password'] = tostring(math.random(0, 65534));
user_parameters['vm-password'] = '';
diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua
index 4cc2245..6d75d8d 100644
--- a/misc/freeswitch/scripts/dialplan/dialplan.lua
+++ b/misc/freeswitch/scripts/dialplan/dialplan.lua
@@ -135,10 +135,22 @@ 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(self.caller);
+
+ local gateway = false;
+
+ if self.caller:to_b('gs_from_gateway') then
+ gateway = {
+ name = self.caller:to_s('gs_gateway_name'),
+ id = self.caller:to_i('gs_gateway_id'),
+ }
+ log:info('AUTH_GATEWAY - authenticaded by password and username: ', self.caller:to_s('username'), ', gateway=', gateway.id, '|', gateway.name, ', ip: ', self.caller.sip_contact_host);
+ return gateway_class:find_by_id(gateway.id);
+ else
+ gateway = gateway_class:authenticate(self.caller);
+ end
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);
+ log:info('AUTH_GATEWAY - ', gateway.auth_source, ' ~ ', gateway.auth_pattern, ', gateway=', gateway.id, '|', gateway.name, ', ip: ', self.caller.sip_contact_host);
return gateway_class:find_by_id(gateway.id);
end
end