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') 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