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 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'misc/freeswitch/scripts/configuration.lua') 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 -- 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/scripts/configuration.lua') 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 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/scripts/configuration.lua') 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 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 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'misc/freeswitch/scripts/configuration.lua') 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 -- 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/scripts/configuration.lua') 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 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/scripts/configuration.lua') 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 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/scripts/configuration.lua') 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 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/scripts/configuration.lua') 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 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/scripts/configuration.lua') 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 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/scripts/configuration.lua') 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 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/configuration.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/configuration.lua') 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) -- cgit v1.2.3