diff options
author | spag <spag@golwen.net> | 2013-01-14 17:15:51 +0100 |
---|---|---|
committer | spag <spag@golwen.net> | 2013-01-14 17:15:51 +0100 |
commit | e0064941bc73303e83f1fbd9374c3a731b1d3c0b (patch) | |
tree | 70bbfed7b3da0a8421302a2c18a0126f3b2e43f2 | |
parent | 64c8b78bbf5880c2b8948cf7588ffe7d0a843357 (diff) |
allow header based authentication
-rw-r--r-- | misc/freeswitch/scripts/common/gateway.lua | 22 |
1 files changed, 22 insertions, 0 deletions
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'; |