diff --git a/app/call_block/app_config.php b/app/call_block/app_config.php new file mode 100644 index 0000000000..ce6c125e43 --- /dev/null +++ b/app/call_block/app_config.php @@ -0,0 +1,102 @@ + \ No newline at end of file diff --git a/app/call_block/app_languages.php b/app/call_block/app_languages.php new file mode 100644 index 0000000000..1548136a1f --- /dev/null +++ b/app/call_block/app_languages.php @@ -0,0 +1,105 @@ + \ No newline at end of file diff --git a/app/call_block/call_block.php b/app/call_block/call_block.php new file mode 100644 index 0000000000..de984dc510 --- /dev/null +++ b/app/call_block/call_block.php @@ -0,0 +1,182 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane + + Call Block is written by Gerrit Visser +*/ +require_once "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; + +if (permission_exists('call_block_view')) { + //access granted +} +else { + echo "access denied"; + exit; +} + +//add multi-lingual support + require_once "app_languages.php"; + foreach($text as $key => $value) { + $text[$key] = $value[$_SESSION['domain']['language']['code']]; + } + +//additional includes + require_once "resources/header.php"; + require_once "resources/paging.php"; + +//get variables used to control the order + $order_by = $_GET["order_by"]; + $order = $_GET["order"]; + +//show the content + echo "
"; + echo "\n"; + echo "\n"; + echo " "; + echo ""; + echo "
\n"; + echo "
"; + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
".$text['title-call-block']." 
\n"; + echo " ".$text['description-call-block']."

\n"; + echo "
\n"; + + //prepare to page the results + $sql = "select count(*) as num_rows from v_call_block "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' and direction <> 'outbound' "; + if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } + $prep_statement = $db->prepare($sql); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['num_rows'] > 0) { + $num_rows = $row['num_rows']; + } + else { + $num_rows = '0'; + } + } + + //prepare to page the results + $rows_per_page = 10; + $param = ""; + $page = $_GET['page']; + if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } + list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page); + $offset = $rows_per_page * $page; + + //get the list + $sql = " select * from v_call_block "; + $sql .= " where domain_uuid = '".$_SESSION['domain_uuid']."' "; + if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } + $sql .= " limit $rows_per_page offset $offset "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(); + $result_count = count($result); + unset ($prep_statement, $sql); + + $c = 0; + $row_style["0"] = "row_style0"; + $row_style["1"] = "row_style1"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo th_order_by('blocked_caller_number', $text['label-number'], $order_by, $order); + echo th_order_by('blocked_caller_name', $text['label-name'], $order_by, $order); + echo th_order_by('blocked_call_count', $text['label-count'], $order_by, $order); + echo th_order_by('date_added', $text['label-date-added'], $order_by, $order); + echo th_order_by('blocked_call_action', $text['label-action'], $order_by, $order); + echo th_order_by('block_call_enabled', $text['label-enabled'], $order_by, $order); + echo "\n"; + echo "\n"; + + if ($result_count > 0) { + foreach($result as $row) { + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + if (defined('TIME_24HR') && TIME_24HR == 1) { + $tmp_date_added = date("j M Y H:i:s", $row['date_added']); + } else { + $tmp_date_added = date("j M Y h:i:sa", $row['date_added']); + } + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + if ($c==0) { $c=1; } else { $c=0; } + } //end foreach + unset($sql, $result, $row_count); + } //end if results + + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + if (permission_exists('call_block_add')) { + echo " $v_link_label_add\n"; + } + echo "
".$row['blocked_caller_number']." ".$row['blocked_caller_name']." ".$row['blocked_call_count']." ".$tmp_date_added." ".$row['blocked_call_action']." ".$row['block_call_enabled']." \n"; + if (permission_exists('call_block_edit')) { + echo " $v_link_label_edit\n"; + } + if (permission_exists('call_block_delete')) { + echo " $v_link_label_delete\n"; + }; + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
 $paging_controls\n"; + if (permission_exists('call_block_add')) { + echo " $v_link_label_add\n"; + } + echo "
\n"; + echo "
"; + echo "
"; + echo "

"; + echo "

"; + + echo "
"; + echo "
"; + echo "

"; + +//include the footer + require_once "resources/footer.php"; +?> \ No newline at end of file diff --git a/app/call_block/call_block_cdr_add.php b/app/call_block/call_block_cdr_add.php new file mode 100644 index 0000000000..d918d8d57d --- /dev/null +++ b/app/call_block/call_block_cdr_add.php @@ -0,0 +1,98 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane + + Call Block is written by Gerrit Visser +*/ +require_once "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; + +if (permission_exists('call_block_edit') || permission_exists('call_block_add')) { + //access granted +} +else { + echo "access denied"; + exit; +} + +//add multi-lingual support + require_once "app_languages.php"; + foreach($text as $key => $value) { + $text[$key] = $value[$_SESSION['domain']['language']['code']]; + } + +//action add from cdr + if (isset($_REQUEST["cdr_id"])) { + $action = "cdr_add"; + $cdr_uuid = check_str($_REQUEST["cdr_id"]); + } + + // get the caller id info from cdr that user chose + $sql = "select caller_id_name, caller_id_number from v_xml_cdr "; + $sql .= "where uuid = '$cdr_uuid' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetch(); + unset ($prep_statement); + + $blocked_caller_name = $result["caller_id_name"]; + $blocked_caller_number = $result["caller_id_number"]; + $block_call_enabled = "true"; + $block_call_action = "Reject"; + + $sql = "insert into v_call_block "; + $sql .= "("; + $sql .= "domain_uuid, "; + $sql .= "blocked_caller_uuid, "; + $sql .= "blocked_caller_name, "; + $sql .= "blocked_caller_number, "; + $sql .= "blocked_call_count, "; + $sql .= "blocked_call_action, "; + $sql .= "block_call_enabled, "; + $sql .= "date_added "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".$_SESSION['domain_uuid']."', "; + $sql .= "'".uuid()."', "; + $sql .= "'$blocked_caller_name', "; + $sql .= "'$blocked_caller_number', "; + $sql .= "0, "; + $sql .= "'$block_call_action', "; + $sql .= "'$block_call_enabled', "; + $sql .= "'".time()."' "; + $sql .= ")"; + $db->exec(check_sql($sql)); + unset($sql); + + require_once "resources/header.php"; + echo "\n"; + echo "
\n"; + echo $text['label-add-complete']."\n"; + echo "
\n"; + require_once "resources/footer.php"; + return; + +?> \ No newline at end of file diff --git a/app/call_block/call_block_delete.php b/app/call_block/call_block_delete.php new file mode 100644 index 0000000000..8a0a82e4aa --- /dev/null +++ b/app/call_block/call_block_delete.php @@ -0,0 +1,78 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane + + Call Block is written by Gerrit Visser +*/ +include "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; +if (permission_exists('call_block_delete')) { + //access granted +} +else { + echo "access denied"; + exit; +} + +//add multi-lingual support + require_once "app_languages.php"; + foreach($text as $key => $value) { + $text[$key] = $value[$_SESSION['domain']['language']['code']]; + } + +//set the variable + if (count($_GET)>0) { + $id = $_GET["id"]; + } + +//delete the extension + if (strlen($id)>0) { + $sql = "delete from v_call_block "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + $sql .= "and blocked_caller_uuid = '$id' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + unset($prep_statement, $sql); + } + +//redirect the user + require_once "resources/header.php"; + echo "\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
".$text['label-message']."
".$text['label-delete-complete']."
\n"; + echo "
\n"; + echo "
\n"; + require_once "resources/footer.php"; + return; + +?> \ No newline at end of file diff --git a/app/call_block/call_block_edit.php b/app/call_block/call_block_edit.php new file mode 100644 index 0000000000..61fcd18961 --- /dev/null +++ b/app/call_block/call_block_edit.php @@ -0,0 +1,385 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane + + Call Block is written by Gerrit Visser +*/ +require_once "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; + +if (permission_exists('call_block_edit') || permission_exists('call_block_add')) { + //access granted +} +else { + echo "access denied"; + exit; +} + +//add multi-lingual support + require_once "app_languages.php"; + foreach($text as $key => $value) { + $text[$key] = $value[$_SESSION['domain']['language']['code']]; + } + +//define the call_block_get_extensions function + function call_block_get_extensions($select_extension) { + global $db; + + //list voicemail + $sql = "select extension, user_context, description from v_extensions "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + $sql .= "and enabled = 'true' "; + $sql .= "order by extension asc "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); + + echo "\n"; + foreach ($result as &$row) { + $extension = $row["extension"]; + $context = $row["user_context"]; + $description = $row["description"]; + if ($extension == $select_extension) $selected = "SELECTED"; + echo " \n"; + $selected = ""; + } + echo "\n"; + } + +//action add or update + if (isset($_REQUEST["id"])) { + $action = "update"; + $blocked_caller_uuid = check_str($_REQUEST["id"]); + } + else { + $action = "add"; + } + +//get http post variables and set them to php variables + if (count($_POST)>0) { + $blocked_caller_name = check_str($_POST["blocked_caller_name"]); + $blocked_caller_number = check_str($_POST["blocked_caller_number"]); + $blocked_call_action = check_str($_POST["blocked_call_action"]); + $block_call_enabled = check_str($_POST["block_call_enabled"]); + } + +if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { + + $msg = ''; + if ($action == "update") { + //$blocked_caller_uuid = check_str($_POST["blocked_caller_uuid"]); + } + + //check for all required data + if (strlen($blocked_caller_name) == 0) { $msg .= $text['label-provide-name']."
\n"; } + if ($action == "add") { + if (strlen($blocked_caller_number) == 0) { $msg .= $text['label-provide-number']."
\n"; } + } + if (strlen($block_call_enabled) == 0) { $msg .= $text['label-provide-enabled']."
\n"; } + if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { + require_once "resources/header.php"; + require_once "resources/persist_form_var.php"; + echo "
\n"; + echo "
\n"; + echo $msg."
"; + echo "
\n"; + persistformvar($_POST); + echo "
\n"; + require_once "resources/footer.php"; + return; + } + + //add or update the database + if (($_POST["persistformvar"] != "true")>0) { + if ($action == "add") { + $sql = "insert into v_call_block "; + $sql .= "("; + $sql .= "domain_uuid, "; + $sql .= "blocked_caller_uuid, "; + $sql .= "blocked_caller_name, "; + $sql .= "blocked_caller_number, "; + $sql .= "blocked_call_count, "; + $sql .= "blocked_call_action, "; + $sql .= "block_call_enabled, "; + $sql .= "date_added "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".$_SESSION['domain_uuid']."', "; + $sql .= "'".uuid()."', "; + $sql .= "'$blocked_caller_name', "; + $sql .= "'$blocked_caller_number', "; + $sql .= "0, "; + $sql .= "'$blocked_call_action', "; + $sql .= "'$block_call_enabled', "; + $sql .= "'".time()."' "; + $sql .= ")"; + $db->exec(check_sql($sql)); + unset($sql); + + require_once "resources/header.php"; + echo "\n"; + echo "
\n"; + echo $text['label-add-complete']."\n"; + echo "
\n"; + require_once "resources/footer.php"; + return; + } //if ($action == "add") + + if ($action == "update") { + $sql = "update v_call_block set "; + $sql .= "blocked_caller_name = '$blocked_caller_name', "; + //$sql .= "blocked_caller_number = '$blocked_caller_number', "; + $sql .= "blocked_call_action = '$blocked_call_action', "; + $sql .= "block_call_enabled = '$block_call_enabled' "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + $sql .= "and blocked_caller_uuid = '$blocked_caller_uuid'"; + $db->exec(check_sql($sql)); + unset($sql); + + require_once "resources/header.php"; + echo "\n"; + echo "
\n"; + echo $text['label-update-complete']."\n"; + echo "
\n"; + require_once "resources/footer.php"; + return; + } //if ($action == "update") + } //if ($_POST["persistformvar"] != "true") +} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) + +//pre-populate the form + if (count($_GET)>0 && $_POST["persistformvar"] != "true") { + $blocked_caller_uuid = $_GET["id"]; + $sql = "select * from v_call_block "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + $sql .= "and blocked_caller_uuid = '$blocked_caller_uuid' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(); + foreach ($result as &$row) { + $blocked_caller_name = $row["blocked_caller_name"]; + $blocked_caller_number = $row["blocked_caller_number"]; + $blocked_call_action = $row["blocked_call_action"]; + $blocked_call_destination = $row["blocked_call_destination"]; + $block_call_enabled = $row["block_call_enabled"]; + break; //limit to 1 row + } + unset ($prep_statement, $sql); + } + +//show the header + require_once "resources/header.php"; + +//show the content + echo "
"; + // Show last 5-10 calls first, with add button + +//get the results from the db + $sql = "select caller_id_number, caller_id_name, start_epoch, uuid from v_xml_cdr "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + $sql .= "and direction != 'outbound' "; + $sql .= "order by start_stamp DESC "; + $sql .= "limit 20 "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(); + $result_count = count($result); + unset ($prep_statement); + + echo "\n"; + echo "\n"; + echo th_order_by('caller_id_name', $text['label-name'], $order_by, $order); + echo th_order_by('caller_id_number', $text['label-number'], $order_by, $order); + echo th_order_by('start_stamp', $text['label-called-on'], $order_by, $order); + + $c = 0; + $row_style["0"] = "row_style0"; + $row_style["1"] = "row_style1"; + + if ($result_count > 0) { + foreach($result as $row) { + if (strlen($row['caller_id_number']) >= 7) { + if (defined('TIME_24HR') && TIME_24HR == 1) { + $tmp_start_epoch = date("j M Y H:i:s", $row['start_epoch']); + } else { + $tmp_start_epoch = date("j M Y h:i:sa", $row['start_epoch']); + } + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + if ($c==0) { $c=1; } else { $c=0; } + } + } //end foreach + unset($sql, $result, $row_count); + } //end if results + + echo "\n"; + echo "\n"; + echo "
"; + echo $row['caller_id_name'].' '; + echo " "; + if (is_numeric($row['caller_id_number'])) { + echo format_phone($row['caller_id_number']).' '; + } + else { + echo $row['caller_id_number'].' '; + } + echo " ".$tmp_start_epoch."\n"; + echo " $v_link_label_add\n"; + echo "
"; + // end of Display Last 5-10 Calls + + echo "\n"; + echo "\n"; + echo " "; + echo " "; + echo "
\n"; + echo "
"; + + echo "
\n"; + echo "
\n"; + echo "\n"; + echo "\n"; + if ($action == "add") { + echo "\n"; + } + if ($action == "update") { + echo "\n"; + } + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo " \n"; + echo " \n"; + echo " "; + echo "
".$text['label-edit-add']."".$text['label-edit-edit']."
\n"; + if ($action == "add") { + echo $text['label-add-note']."

\n"; + } + if ($action == "update") { + echo $text['label-edit-note']."

\n"; + } + echo "
\n"; + echo " Number:\n"; + echo "\n"; + if ($action == "add") { + echo " \n"; + echo "
\n"; + echo $text['label-exact-number']."\n"; + } + else { + echo $blocked_caller_number; + } + echo "
\n"; + echo "
\n"; + echo " Name:\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo "Enter the name.\n"; + echo "
\n"; + echo " Action:\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['label-action-message']."\n"; + echo "\n"; + echo "
\n"; + echo " Enabled:\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['label-enable-message']."\n"; + echo "\n"; + echo "
\n"; + if ($action == "update") { + echo " \n"; + } + echo " \n"; + echo "
"; + echo ""; + + echo "
"; + echo "
"; + +//include the footer + require_once "resources/footer.php"; +?> \ No newline at end of file diff --git a/app/call_block/root.php b/app/call_block/root.php new file mode 100644 index 0000000000..e791876a14 --- /dev/null +++ b/app/call_block/root.php @@ -0,0 +1,52 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane + + Callblock is written by Gerrit Visser +*/ + +// make sure the PATH_SEPARATOR is defined + if (!defined("PATH_SEPARATOR")) { + if ( strpos( $_ENV[ "OS" ], "Win" ) !== false ) { define("PATH_SEPARATOR", ";"); } else { define("PATH_SEPARATOR", ":"); } + } + +// make sure the document_root is set + $_SERVER["SCRIPT_FILENAME"] = str_replace("\\", "/", $_SERVER["SCRIPT_FILENAME"]); + $_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]); + $_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]); + //echo "DOCUMENT_ROOT: ".$_SERVER["DOCUMENT_ROOT"]."
\n"; + //echo "PHP_SELF: ".$_SERVER["PHP_SELF"]."
\n"; + //echo "SCRIPT_FILENAME: ".$_SERVER["SCRIPT_FILENAME"]."
\n"; + +// if the project directory exists then add it to the include path otherwise add the document root to the include path + if (is_dir($_SERVER["DOCUMENT_ROOT"].'/fusionpbx')){ + if(!defined('PROJECT_PATH')) { define('PROJECT_PATH', '/fusionpbx'); } + set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER["DOCUMENT_ROOT"].'/fusionpbx' ); + } + else { + if(!defined('PROJECT_PATH')) { define('PROJECT_PATH', ''); } + set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] ); + } + +?> \ No newline at end of file diff --git a/app/call_block/scripts/call_block.lua b/app/call_block/scripts/call_block.lua new file mode 100644 index 0000000000..3c85b59d39 --- /dev/null +++ b/app/call_block/scripts/call_block.lua @@ -0,0 +1,125 @@ +-- +-- call_block-FS +-- Version: MPL 1.1 +-- +-- The contents of this file are subject to the Mozilla Public License Version +-- 1.1 (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- http://www.mozilla.org/MPL/ +-- +-- Software distributed under the License is distributed on an "AS IS" basis, +-- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +-- for the specific language governing rights and limitations under the +-- License. +-- +-- The Original Code is call_block-FS +-- +-- The Initial Developer of the Original Code is +-- Gerrit Visser +-- Copyright (C) 2011 +-- the Initial Developer. All Rights Reserved. +-- +-- Contributor(s): +-- Gerrit Visser +-- Mark J Crane +--[[ +This module provides for Blacklisting of phone numbers. Essentially these are numbers that you do not want to hear from again! + +To call this script and pass it arguments: +1. On the command line, e.g. in a FS incoming dialplan: +This method causes the script to get its manadatory arguments directly from the Session +]] +--[[ Change Log: + 15 Jun, 2011: initial release > FusionPBX + 15 Jun, 2011: Added loglevel parameter and logger function to simplify control of debug output + 4 May, 2012: tested with FusionPBX V3 + 4 May, 2012: added per_tenant capability (domain based) + 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 +]] + +-- Command line parameters + local params = { cmd="", + cid_num = string.gsub(tostring(session:getVariable("caller_id_number")), "+", ""), + cid_name = session:getVariable("caller_id_name"), + domain = session:getVariable("domain"), + userid= "", -- session:getVariable("id") + loglevel = "W" -- Warning, Debug, Info + } + +-- local storage + local sql = nil + +--define the logger function + local function logger(level, log, data) + -- output data to console 'log' if debug level is on + if string.find(params["loglevel"], level) then + freeswitch.consoleLog(log, "[Call Block]: " .. data .. "\n") + end + end + +--include config.lua + scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); + dofile(scripts_dir.."/resources/functions/config.lua"); + dofile(config()); + +--connect to the database + dofile(scripts_dir.."/resources/functions/database_handle.lua"); + dbh = database_handle('system'); + +--log if not connect + if dbh:connected() == false then + logger("W", "NOTICE", "db was not connected") + end + +-- We have a single command letter +-- Use session variables + logger("D", "NOTICE", "params default from session, count " .. string.format("%d", #argv[1]) .. " \n") + params["cmd"] = argv[1] + +-- ensure that we have a fresh status on exit + session:setVariable("call_block", "") + +--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"])); + +--Check if number is in call_block list + -- If it is, then increment the counter and block the call + if (params["cmd"] == "C") then + 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.blocked_caller_number = '" .. params["cid_num"] .. "' AND d.domain_name = '" .. params["domain"] .."'" + status = dbh:query(sql, function(rows) + found_cid_num = rows["blocked_caller_number"] + found_uuid = rows["blocked_caller_uuid"] + found_enabled = rows["block_call_enabled"] + found_action = rows["blocked_call_action"] + found_count = rows["blocked_call_count"] + end) + -- dbh:affected_rows() doesn't do anything if using core:db so this is the workaround: + if found_cid_num then -- caller id exists + if (found_enabled == "true") then + details = {} + k = 0 + for v in string.gmatch(found_action, "[%w%.]+") do + details[k] = v + --logger("W", "INFO", "Details: " .. details[k]) + k = k + 1 + end + dbh:query("UPDATE v_call_block SET blocked_call_count = " .. found_count + 1 .. " WHERE blocked_caller_uuid = '" .. found_uuid .. "'") + session:setVariable("call_block", "block") + logger("W", "NOTICE", "number " .. params["cid_num"] .. " blocked with " .. found_count .. " previous hits, domain: " .. params["domain"]) + if (found_action == "Reject") then + session:hangup("CALL_REJECTED") + end + if (found_action == "Busy") then + session:hangup("USER_BUSY") + end + if (details[0] =="Voicemail") then + session:setAutoHangup(false) + session:execute("transfer", "*99" .. details[2] .. " XML " .. details[1]) + end + end + end + end