Add. Use parameters in cidlookup.lua and call_block app (#2096)

This commit is contained in:
Alexey Melnichuk
2016-11-18 20:16:22 +03:00
committed by FusionPBX
parent 46cbac7b37
commit 6c3dce77d9
2 changed files with 17 additions and 12 deletions

View File

@@ -93,8 +93,8 @@ This method causes the script to get its manadatory arguments directly from the
--if not cached then get the information from the database
if (cache == "-ERR NOT FOUND") then
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
Database = require "resources.functions.database";
dbh = Database.new('system');
--log if not connect
if dbh:connected() == false then
@@ -104,8 +104,8 @@ This method causes the script to get its manadatory arguments directly from the
--check if the the call block is blocked
sql = "SELECT * FROM v_call_block as c "
sql = sql .. "JOIN v_domains as d ON c.domain_uuid=d.domain_uuid "
sql = sql .. "WHERE c.call_block_number = '" .. params["cid_num"] .. "' AND d.domain_name = '" .. params["domain_name"] .."'"
status = dbh:query(sql, function(rows)
sql = sql .. "WHERE c.call_block_number = :cid_num AND d.domain_name = :domain_name"
dbh:query(sql, params, function(rows)
found_cid_num = rows["call_block_number"];
found_uuid = rows["call_block_uuid"];
found_enabled = rows["call_block_enabled"];

View File

@@ -26,9 +26,6 @@
-- add this in Inbound Routes before transfer to use it:
-- action set caller_id_name=${luarun cidlookup.lua ${uuid}}
--debug
debug["sql"] = true;
--define the trim function
require "resources.functions.trim"
@@ -71,9 +68,15 @@
--include config.lua
require "resources.functions.config";
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
dbh = Database.new('system');
if (database["type"] == "mysql") then
sql = "SELECT CONCAT(v_contacts.contact_name_given, ' ', v_contacts.contact_name_family,' (',v_contact_phones.phone_type,')') AS name FROM v_contacts ";
elseif (database["type"] == "pgsql") then
@@ -83,12 +86,14 @@
end
sql = sql .. "INNER JOIN v_contact_phones ON v_contact_phones.contact_uuid = v_contacts.contact_uuid ";
sql = sql .. "INNER JOIN v_destinations ON v_destinations.domain_uuid = v_contacts.domain_uuid ";
sql = sql .. "WHERE v_contact_phones.phone_number = '"..caller.."'
sql = sql .. "WHERE v_contact_phones.phone_number = :caller"
local params = {caller = caller}
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[cidlookup] "..sql.."\n");
freeswitch.consoleLog("notice", "[cidlookup] SQL: "..sql.."; params:" .. json.encode(params) .. "\n");
end
status = dbh:query(sql, function(row)
dbh:query(sql, params, function(row)
name = row.name;
end);