Merge branch 'master' of https://github.com/fusionpbx/fusionpbx
This commit is contained in:
+59
-31
@@ -62,6 +62,12 @@
|
|||||||
--all other directory actions: sip_auth, user_call
|
--all other directory actions: sip_auth, user_call
|
||||||
--except for the action: group_call
|
--except for the action: group_call
|
||||||
|
|
||||||
|
-- Make sance only for extensions with number_alias
|
||||||
|
-- true - you should register with AuthID=Extension and UserID=Number Alias
|
||||||
|
-- false - you should register with AuthID=UserID=Extension
|
||||||
|
-- also in this case you need 2 records in memcache for one extension
|
||||||
|
local DIAL_STRING_BASED_ON_USERID = false
|
||||||
|
|
||||||
local sip_auth_method = params:getHeader("sip_auth_method")
|
local sip_auth_method = params:getHeader("sip_auth_method")
|
||||||
if sip_auth_method then
|
if sip_auth_method then
|
||||||
sip_auth_method = sip_auth_method:upper();
|
sip_auth_method = sip_auth_method:upper();
|
||||||
@@ -80,30 +86,50 @@
|
|||||||
user = "";
|
user = "";
|
||||||
end
|
end
|
||||||
|
|
||||||
--get the cache
|
if (from_user == "") or (from_user == nil) then
|
||||||
if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
|
from_user = user
|
||||||
if (domain_name) then
|
|
||||||
XML_STRING = trim(api:execute("memcache", "get directory:" .. user .. "@" .. domain_name));
|
|
||||||
end
|
|
||||||
if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then
|
|
||||||
source = "database";
|
|
||||||
continue = true;
|
|
||||||
else
|
|
||||||
source = "cache";
|
|
||||||
continue = true;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
XML_STRING = "";
|
|
||||||
source = "database";
|
|
||||||
continue = true;
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--prevent processing for invalid user
|
--prevent processing for invalid user
|
||||||
if (user == "*97") then
|
if (user == "*97") or (user == "") then
|
||||||
source = "";
|
source = "";
|
||||||
continue = false;
|
continue = false;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- cleanup
|
||||||
|
XML_STRING = nil;
|
||||||
|
|
||||||
|
--get the cache
|
||||||
|
if (continue) then
|
||||||
|
if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
|
||||||
|
if (domain_name) then
|
||||||
|
local key = "directory:" .. (from_user or user) .. "@" .. domain_name
|
||||||
|
XML_STRING = trim(api:execute("memcache", "get " .. key));
|
||||||
|
|
||||||
|
if debug['cache'] then
|
||||||
|
if XML_STRING:sub(1, 4) == '-ERR' then
|
||||||
|
freeswitch.consoleLog("notice", "[xml_handler-directory][memcache] get key: " .. key .. " fail: " .. XML_STRING .. "\n")
|
||||||
|
else
|
||||||
|
freeswitch.consoleLog("notice", "[xml_handler-directory][memcache] get key: " .. key .. " pass!" .. "\n")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
XML_STRING = "-ERR NOT FOUND"
|
||||||
|
end
|
||||||
|
if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then
|
||||||
|
source = "database";
|
||||||
|
continue = true;
|
||||||
|
else
|
||||||
|
source = "cache";
|
||||||
|
continue = true;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
XML_STRING = "";
|
||||||
|
source = "database";
|
||||||
|
continue = true;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--show the params in the console
|
--show the params in the console
|
||||||
--if (params:serialize() ~= nil) then
|
--if (params:serialize() ~= nil) then
|
||||||
-- freeswitch.consoleLog("notice", "[xml_handler-directory.lua] Params:\n" .. params:serialize() .. "\n");
|
-- freeswitch.consoleLog("notice", "[xml_handler-directory.lua] Params:\n" .. params:serialize() .. "\n");
|
||||||
@@ -118,8 +144,10 @@
|
|||||||
--freeswitch.consoleLog("notice", "[xml_handler-directory.lua] dialed_extension is " .. dialed_extension .. "\n");
|
--freeswitch.consoleLog("notice", "[xml_handler-directory.lua] dialed_extension is " .. dialed_extension .. "\n");
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local loaded_from_db = false
|
||||||
--build the XML string from the database
|
--build the XML string from the database
|
||||||
if (source == "database") or (load_balancing) then
|
if (source == "database") or (load_balancing) then
|
||||||
|
loaded_from_db = true
|
||||||
--database connection
|
--database connection
|
||||||
if (continue) then
|
if (continue) then
|
||||||
--connect to the database
|
--connect to the database
|
||||||
@@ -211,8 +239,10 @@
|
|||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
|
continue = false
|
||||||
dbh:query(sql, function(row)
|
dbh:query(sql, function(row)
|
||||||
--general
|
--general
|
||||||
|
continue = true
|
||||||
domain_uuid = row.domain_uuid;
|
domain_uuid = row.domain_uuid;
|
||||||
extension_uuid = row.extension_uuid;
|
extension_uuid = row.extension_uuid;
|
||||||
extension = row.extension;
|
extension = row.extension;
|
||||||
@@ -266,7 +296,7 @@
|
|||||||
|
|
||||||
-- check matching UserID and AuthName
|
-- check matching UserID and AuthName
|
||||||
if sip_auth_method and (METHODS[sip_auth_method] or METHODS._ANY_) then
|
if sip_auth_method and (METHODS[sip_auth_method] or METHODS._ANY_) then
|
||||||
continue = (sip_from_user == user) and ((sip_from_number == user) or (sip_from_number == from_user))
|
continue = (sip_from_user == user) and ((sip_from_number == from_user) or (from_user == user))
|
||||||
if not continue then
|
if not continue then
|
||||||
XML_STRING = nil;
|
XML_STRING = nil;
|
||||||
return 1;
|
return 1;
|
||||||
@@ -279,8 +309,7 @@
|
|||||||
else
|
else
|
||||||
--set a default dial string
|
--set a default dial string
|
||||||
if (dial_string == null) then
|
if (dial_string == null) then
|
||||||
local username = (#number_alias > 0) and number_alias or extension
|
dial_string = "{sip_invite_domain=" .. domain_name .. ",presence_id=" .. user .. "@" .. domain_name .. "}${sofia_contact(" .. (DIAL_STRING_BASED_ON_USERID and sip_from_number or sip_from_user) .. "@" .. domain_name .. ")}";
|
||||||
dial_string = "{sip_invite_domain=" .. domain_name .. ",presence_id=" .. user .. "@" .. domain_name .. "}${sofia_contact(" .. username .. "@" .. domain_name .. ")}";
|
|
||||||
end
|
end
|
||||||
--set the an alternative dial string if the hostnames don't match
|
--set the an alternative dial string if the hostnames don't match
|
||||||
if (load_balancing) then
|
if (load_balancing) then
|
||||||
@@ -514,9 +543,11 @@
|
|||||||
dbh:release();
|
dbh:release();
|
||||||
|
|
||||||
--set the cache
|
--set the cache
|
||||||
if (user and domain_name) then
|
local key = "directory:" .. (DIAL_STRING_BASED_ON_USERID and sip_from_number or sip_from_user) .. "@" .. domain_name
|
||||||
result = trim(api:execute("memcache", "set directory:" .. user .. "@" .. domain_name .. " '"..XML_STRING:gsub("'", "'").."' "..expire["directory"]));
|
if debug['cache'] then
|
||||||
|
freeswitch.consoleLog("notice", "[xml_handler-directory][memcache] set key: " .. key .. "\n")
|
||||||
end
|
end
|
||||||
|
result = trim(api:execute("memcache", "set " .. key .. " '"..XML_STRING:gsub("'", "'").."' "..expire["directory"]));
|
||||||
|
|
||||||
--send the xml to the console
|
--send the xml to the console
|
||||||
if (debug["xml_string"]) then
|
if (debug["xml_string"]) then
|
||||||
@@ -532,17 +563,14 @@
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if XML_STRING and sip_auth_method and (METHODS[sip_auth_method] or METHODS._ANY_) then
|
if XML_STRING and (not loaded_from_db)
|
||||||
--disable registration for number-alias
|
and sip_auth_method and (METHODS[sip_auth_method] or METHODS._ANY_)
|
||||||
if (api:execute("user_data", user .. "@" .. domain_name .." attr id") ~= user) then
|
then
|
||||||
|
local user_id = api:execute("user_data", from_user .. "@" .. domain_name .." attr id")
|
||||||
|
--disable registration for number-alias and foreign number_alias
|
||||||
|
if user_id ~= user then
|
||||||
XML_STRING = nil;
|
XML_STRING = nil;
|
||||||
end
|
end
|
||||||
--disable registration for foreign number_alias
|
|
||||||
if from_user ~= user then
|
|
||||||
if (api:execute("user_data", from_user .. "@" .. domain_name .." attr id") ~= user) then
|
|
||||||
XML_STRING = nil;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--get the XML string from the cache
|
--get the XML string from the cache
|
||||||
|
|||||||
Reference in New Issue
Block a user