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/scripts/common') 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/scripts/common') 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 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/scripts/common') 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 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/scripts/common') 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/scripts/common') 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 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/scripts/common') 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 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/scripts/common') 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 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/scripts/common') 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 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/scripts/common') 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 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/scripts/common') 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 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/scripts/common') 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 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/scripts/common') 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 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/scripts/common') 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 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/scripts/common') 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 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/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 +- 12 files changed, 12 insertions(+), 12 deletions(-) (limited to 'misc/freeswitch/scripts/common') 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) -- 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 ----------------------- 1 file changed, 66 deletions(-) delete mode 100644 misc/freeswitch/scripts/common/routing_tables.lua (limited to 'misc/freeswitch/scripts/common') 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 -- cgit v1.2.3