summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/configuration.lua
diff options
context:
space:
mode:
Diffstat (limited to 'misc/freeswitch/scripts/configuration.lua')
-rw-r--r--misc/freeswitch/scripts/configuration.lua152
1 files changed, 74 insertions, 78 deletions
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'] = '';