Add. Use params in hangup_rx.lua (#2149)

This commit is contained in:
Alexey Melnichuk
2016-11-22 11:07:45 -07:00
committed by FusionPBX
parent aeac98c90f
commit 1bcf3a5779
@@ -32,8 +32,14 @@
require "resources.functions.config"; require "resources.functions.config";
--connect to the database --connect to the database
require "resources.functions.database_handle"; local Database = require "resources.functions.database_handle";
dbh = database_handle('system'); dbh = Database.new('system');
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--define the explode function --define the explode function
require "resources.functions.explode"; require "resources.functions.explode";
@@ -58,8 +64,8 @@
--get the domain_uuid using the domain name required for multi-tenant --get the domain_uuid using the domain name required for multi-tenant
if (domain_name ~= nil) then if (domain_name ~= nil) then
sql = "SELECT domain_uuid FROM v_domains "; sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = '" .. domain_name .. "' "; sql = sql .. "WHERE domain_name = :domain_name ";
status = dbh:query(sql, function(rows) dbh:query(sql, {domain_name = domain_name}, function(rows)
domain_uuid = rows["domain_uuid"]; domain_uuid = rows["domain_uuid"];
end); end);
end end
@@ -154,13 +160,14 @@
end end
--get the fax settings from the database --get the fax settings from the database
sql = [[SELECT * FROM v_fax local sql = [[SELECT * FROM v_fax
WHERE fax_uuid = ']] .. fax_uuid ..[[' WHERE fax_uuid = :fax_uuid
AND domain_uuid = ']] .. domain_uuid ..[[']]; AND domain_uuid = :domain_uuid]];
local params = {fax_uuid = fax_uuid, domain_uuid = domain_uuid};
if (debug["sql"]) then if (debug["sql"]) then
freeswitch.consoleLog("notice", "[fax] SQL: " .. sql .. "\n"); freeswitch.consoleLog("notice", "[fax] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end end
status = dbh:query(sql, function(row) dbh:query(sql, params, function(row)
dialplan_uuid = row["dialplan_uuid"]; dialplan_uuid = row["dialplan_uuid"];
fax_extension = row["fax_extension"]; fax_extension = row["fax_extension"];
fax_accountcode = row["accountcode"]; fax_accountcode = row["accountcode"];
@@ -247,57 +254,72 @@
sql = sql .. ") "; sql = sql .. ") ";
sql = sql .. "values "; sql = sql .. "values ";
sql = sql .. "("; sql = sql .. "(";
sql = sql .. "'"..uuid.."', "; sql = sql .. ":uuid, ";
sql = sql .. "'"..domain_uuid.."', "; sql = sql .. ":domain_uuid, ";
if (fax_uuid ~= nil) then if (fax_uuid ~= nil) then
sql = sql .. "'"..fax_uuid.."', "; sql = sql .. ":fax_uuid, ";
end end
sql = sql .. "'"..fax_success.."', "; sql = sql .. ":fax_success, ";
sql = sql .. "'"..fax_result_code .."', "; sql = sql .. ":fax_result_code, ";
sql = sql .. "'"..fax_result_text.."', "; sql = sql .. ":fax_result_text, ";
sql = sql .. "'"..fax_file.."', "; sql = sql .. ":fax_file, ";
if (fax_ecm_used ~= nil) then if (fax_ecm_used ~= nil) then
sql = sql .. "'"..fax_ecm_used.."', "; sql = sql .. ":fax_ecm_used, ";
end end
if (fax_local_station_id ~= nil) then if (fax_local_station_id ~= nil) then
sql = sql .. "'"..fax_local_station_id.."', "; sql = sql .. ":fax_local_station_id, ";
end
if (fax_document_transferred_pages == nil) then
sql = sql .. "'0', ";
else
sql = sql .. "'"..fax_document_transferred_pages.."', ";
end
if (fax_document_total_pages == nil) then
sql = sql .. "'0', ";
else
sql = sql .. "'"..fax_document_total_pages.."', ";
end end
sql = sql .. ":fax_document_transferred_pages, ";
sql = sql .. ":fax_document_total_pages, ";
if (fax_image_resolution ~= nil) then if (fax_image_resolution ~= nil) then
sql = sql .. "'"..fax_image_resolution.."', "; sql = sql .. ":fax_image_resolution, ";
end end
if (fax_image_size ~= nil) then if (fax_image_size ~= nil) then
sql = sql .. "'"..fax_image_size.."', "; sql = sql .. ":fax_image_size, ";
end end
if (fax_bad_rows ~= nil) then if (fax_bad_rows ~= nil) then
sql = sql .. "'"..fax_bad_rows.."', "; sql = sql .. ":fax_bad_rows, ";
end end
if (fax_transfer_rate ~= nil) then if (fax_transfer_rate ~= nil) then
sql = sql .. "'"..fax_transfer_rate.."', "; sql = sql .. ":fax_transfer_rate, ";
end end
if (fax_uri ~= nil) then if (fax_uri ~= nil) then
sql = sql .. "'"..fax_uri.."', "; sql = sql .. ":fax_uri, ";
end end
if (database["type"] == "sqlite") then if (database["type"] == "sqlite") then
sql = sql .. "'"..os.date("%Y-%m-%d %X").."', "; sql = sql .. ":fax_date, ";
else else
sql = sql .. "now(), "; sql = sql .. "now(), ";
end end
sql = sql .. "'"..os.time().."' "; sql = sql .. ":fax_time ";
sql = sql .. ")"; sql = sql .. ")";
local params = {
uuid = uuid;
domain_uuid = domain_uuid;
fax_uuid = fax_uuid;
fax_success = fax_success;
fax_result_code = fax_result_code;
fax_result_text = fax_result_text;
fax_file = fax_file;
fax_ecm_used = fax_ecm_used;
fax_local_station_id = fax_local_station_id;
fax_document_transferred_pages = fax_document_transferred_pages or '0';
fax_document_total_pages = fax_document_total_pages or '0';
fax_image_resolution = fax_image_resolution;
fax_image_size = fax_image_size;
fax_bad_rows = fax_bad_rows;
fax_transfer_rate = fax_transfer_rate;
fax_uri = fax_uri;
fax_date = os.date("%Y-%m-%d %X");
fax_time = os.time();
};
if (debug["sql"]) then if (debug["sql"]) then
freeswitch.consoleLog("notice", "[fax] "..sql.."\n"); freeswitch.consoleLog("notice", "[fax] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end end
dbh:query(sql);
dbh:query(sql, params);
--add the fax files --add the fax files
if (fax_success ~= nil) then if (fax_success ~= nil) then
@@ -333,39 +355,49 @@
table.insert(sql, ") "); table.insert(sql, ") ");
table.insert(sql, "values "); table.insert(sql, "values ");
table.insert(sql, "("); table.insert(sql, "(");
table.insert(sql, "'" .. uuid .. "', "); table.insert(sql, ":uuid, ");
table.insert(sql, "'" .. fax_uuid .. "', "); table.insert(sql, ":fax_uuid, ");
table.insert(sql, "'rx', "); table.insert(sql, "'rx', ");
table.insert(sql, "'tif', "); table.insert(sql, "'tif', ");
table.insert(sql, "'" .. fax_file .. "', "); table.insert(sql, ":fax_file, ");
if (caller_id_name ~= nil) then if (caller_id_name ~= nil) then
table.insert(sql, "'" .. caller_id_name .. "', "); table.insert(sql, ":caller_id_name, ");
end end
if (caller_id_number ~= nil) then if (caller_id_number ~= nil) then
table.insert(sql, "'" .. caller_id_number .. "', "); table.insert(sql, ":caller_id_number, ");
end end
if (database["type"] == "sqlite") then if (database["type"] == "sqlite") then
table.insert(sql, "'"..os.date("%Y-%m-%d %X").."', "); table.insert(sql, ":fax_date, ");
else else
table.insert(sql, "now(), "); table.insert(sql, "now(), ");
end end
table.insert(sql, "'" .. os.time() .. "', "); table.insert(sql, ":fax_time, ");
if (storage_type == "base64") then if (storage_type == "base64") then
table.insert(sql, "'" .. fax_base64 .. "', "); table.insert(sql, ":fax_base64, ");
end end
table.insert(sql, "'" .. domain_uuid .. "'"); table.insert(sql, ":domain_uuid");
table.insert(sql, ")"); table.insert(sql, ")");
sql = table.concat(sql, "\n"); sql = table.concat(sql, "\n");
local params = {
uuid = uuid;
domain_uuid = domain_uuid;
fax_uuid = fax_uuid;
fax_file = fax_file;
caller_id_name = caller_id_name;
caller_id_number = caller_id_number;
fax_base64 = fax_base64;
fax_date = os.date("%Y-%m-%d %X");
fax_time = os.time();
};
if (debug["sql"]) then if (debug["sql"]) then
freeswitch.consoleLog("notice", "[fax] SQL: " .. sql .. "\n"); freeswitch.consoleLog("notice", "[fax] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end end
if (storage_type == "base64") then if (storage_type == "base64") then
local Database = require "resources.functions.database"
local dbh = Database.new('system', 'base64'); local dbh = Database.new('system', 'base64');
dbh:query(sql); dbh:query(sql, params);
dbh:release(); dbh:release();
else else
result = dbh:query(sql); result = dbh:query(sql, params);
end end
end end
end end