Enhance Call Blocking [master] (#2988)

* Added support for regular expressions in the numbers to be blocked.
Reduced the caching timeout, as the counter is only incremented when a call is blocked and the number is not cached.

* Added default sort order.

* Added option to switch on/off use of regular expression matching for pgsql and mysql.

* Added support for sqlite and updated default number match to "LIKE" as suggested by MafooUK on IRC.

* Selection of behavior (default [=], regex or like matching) is now done via the variable call_block_matching = regex|like|EMPTY - type text - in the Call Block section of Default Settings.

* Updated comment to match new matching.
This commit is contained in:
The-Operator
2018-05-08 16:50:57 +02:00
committed by FusionPBX
parent 490803114b
commit 593f8ac9a9
3 changed files with 33 additions and 8 deletions

View File

@@ -37,11 +37,12 @@ This method causes the script to get its manadatory arguments directly from the
12 Jun, 2013: update the database connection, change table name from v_callblock to v_call_block
14 Jun, 2013: Change Voicemail option to use Transfer, avoids mod_voicemail dependency
27 Sep, 2013: Changed the name of the fields to conform with the table name
12 Feb, 2018: Added support for regular expressions and SQL "like" matching on the phone number
]]
--set defaults
expire = {}
expire["call_block"] = "3600";
expire["call_block"] = "60";
source = "";
-- Command line parameters
@@ -62,6 +63,8 @@ This method causes the script to get its manadatory arguments directly from the
local sql = nil
--define the functions
local Settings = require "resources.functions.lazy_settings"
local Database = require "resources.functions.database"
require "resources.functions.trim";
--define the logger function
@@ -78,6 +81,12 @@ This method causes the script to get its manadatory arguments directly from the
-- ensure that we have a fresh status on exit
session:setVariable("call_block", "")
-- get the configuration variables from the DB
local db = dbh or Database.new('system')
local settings = Settings.new(db, domain_name, domain_uuid)
local call_block_matching = settings:get('call block', 'call_block_matching', 'text');
--send to the log
logger("D", "NOTICE", "params are: " .. string.format("'%s', '%s', '%s', '%s'", params["cid_num"],
params["cid_name"], params["userid"], params["domain_name"]));
@@ -104,7 +113,19 @@ 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 = :cid_num AND d.domain_name = :domain_name "
if ((database["type"] == "pgsql") and (call_block_matching == "regex")) then
logger("W", "NOTICE", "call_block using regex match on cid_num")
sql = sql .. "WHERE :cid_num ~ c.call_block_number AND d.domain_name = :domain_name "
elseif (((database["type"] == "mysql") or (database["type"] == "sqlite")) and (call_block_matching == "regex")) then
logger("W", "NOTICE", "call_block using regex match on cid_num")
sql = sql .. "WHERE :cid_num REGEXP c.call_block_number AND d.domain_name = :domain_name "
elseif call_block_matching == "like" then
logger("W", "NOTICE", "call_block using like match on cid_num")
sql = sql .. "WHERE :cid_num LIKE c.call_block_number AND d.domain_name = :domain_name "
else
logger("W", "NOTICE", "call_block using exact match on cid_num")
sql = sql .. "WHERE :cid_num = c.call_block_number AND d.domain_name = :domain_name "
end
dbh:query(sql, params, function(rows)
found_cid_num = rows["call_block_number"];
found_uuid = rows["call_block_uuid"];