diff --git a/app/calls/resources/classes/call_forward.php b/app/calls/resources/classes/call_forward.php index ab99f9ddcb..9b7fe294f7 100644 --- a/app/calls/resources/classes/call_forward.php +++ b/app/calls/resources/classes/call_forward.php @@ -38,6 +38,7 @@ include "root.php"; public $forward_all_destination; public $forward_all_enabled; private $dial_string; + private $toll_allow; public $accountcode; public $forward_caller_id_uuid; public $outbound_caller_id_name; @@ -58,6 +59,7 @@ include "root.php"; foreach ($result as &$row) { $this->extension = $row["extension"]; $this->accountcode = $row["accountcode"]; + $this->toll_allow = $row["toll_allow"]; $this->outbound_caller_id_name = $row["outbound_caller_id_name"]; $this->outbound_caller_id_number = $row["outbound_caller_id_number"]; } @@ -73,6 +75,7 @@ include "root.php"; $dial_string .= ",domain_name=".$_SESSION['domain_name']; $dial_string .= ",domain=".$_SESSION['domain_name']; $dial_string .= ",extension_uuid=".$this->extension_uuid; + $dial_string .= ",toll_allow='".$this->toll_allow."'"; if (strlen($this->accountcode) > 0) { $dial_string .= ",sip_h_X-accountcode=".$this->accountcode; $dial_string .= ",accountcode=".$this->accountcode; @@ -140,7 +143,7 @@ include "root.php"; } else { $sql .= "forward_all_destination = '$this->forward_all_destination', "; - $sql .= "dial_string = '".$this->dial_string."', "; + $sql .= "dial_string = '".check_str($this->dial_string)."', "; $sql .= "forward_all_enabled = 'true' "; } $sql .= "where domain_uuid = '$this->domain_uuid' "; diff --git a/app/calls/resources/classes/follow_me.php b/app/calls/resources/classes/follow_me.php index 18c18325fa..8aeb0f80cc 100644 --- a/app/calls/resources/classes/follow_me.php +++ b/app/calls/resources/classes/follow_me.php @@ -43,6 +43,7 @@ include "root.php"; public $outbound_caller_id_name; public $outbound_caller_id_number; private $extension; + private $toll_allow; public $destination_data_1; public $destination_type_1; @@ -247,6 +248,7 @@ include "root.php"; foreach ($result as &$row) { $this->extension = $row["extension"]; $this->accountcode = $row["accountcode"]; + $this->toll_allow = $row["toll_allow"]; $this->outbound_caller_id_name = $row["outbound_caller_id_name"]; $this->outbound_caller_id_number = $row["outbound_caller_id_number"]; } @@ -330,6 +332,7 @@ include "root.php"; $dial_string .= ",sip_h_X-accountcode=".$this->accountcode; $dial_string .= ",accountcode=".$this->accountcode; } + $dial_string .= ",toll_allow='".$this->toll_allow."'"; $dial_string .= "}"; $x = 0; foreach ($result as &$row) { @@ -419,7 +422,7 @@ include "root.php"; } $sql = "update v_extensions set "; - $sql .= "dial_string = '".$dial_string."', "; + $sql .= "dial_string = '".check_str($dial_string)."', "; $sql .= "dial_domain = '".$_SESSION['domain_name']."' "; $sql .= "where domain_uuid = '".$this->domain_uuid."' "; $sql .= "and follow_me_uuid = '".$this->follow_me_uuid."' "; diff --git a/app/operator_panel/index.php b/app/operator_panel/index.php index e50a546646..daa77ee8bd 100644 --- a/app/operator_panel/index.php +++ b/app/operator_panel/index.php @@ -204,6 +204,7 @@ require_once "resources/header.php"; function refresh_start() { if (document.getElementById('refresh_state')) { document.getElementById('refresh_state').innerHTML = "\"<?php\" title=\"\">"; } + refresh_stop(); interval_timer_id = setInterval( function() { url = source_url; url += '&vd_ext_from=' + document.getElementById('vd_ext_from').value; diff --git a/app/operator_panel/resources/functions/get_call_activity.php b/app/operator_panel/resources/functions/get_call_activity.php index 64ccdd63a0..3490a159dd 100644 --- a/app/operator_panel/resources/functions/get_call_activity.php +++ b/app/operator_panel/resources/functions/get_call_activity.php @@ -45,6 +45,11 @@ function get_call_activity() { //build the response $x = 0; foreach($extensions as &$row) { + $user = $row['extension']; + if (strlen($row['number_alias']) >0 ) { + $user = $row['number_alias']; + } + //add the extension details $array[$x] = $row; @@ -88,7 +93,7 @@ function get_call_activity() { $presence = explode("@", $presence_id); $presence_id = $presence[0]; $presence_domain = $presence[1]; - if ($row['extension'] == $presence_id) { + if ($user == $presence_id) { if ($presence_domain == $_SESSION['domain_name']) { $found = true; break; diff --git a/resources/install/scripts/app/toll_allow/index.lua b/resources/install/scripts/app/toll_allow/index.lua index 31844e4e69..46a0f27f39 100644 --- a/resources/install/scripts/app/toll_allow/index.lua +++ b/resources/install/scripts/app/toll_allow/index.lua @@ -22,159 +22,184 @@ -- Contributor(s): -- Riccardo Granchi -- Philippe Rioual +-- Alexey Melnichuck + +--Configuration + -- Define known template names + local known_templates = { + ["mobile" ] = true, + ["landline" ] = true, + ["international"] = true, + ["tollfree" ] = true, + ["sharedcharge" ] = true, + ["premium" ] = true, + ["unknown" ] = true, + } + + --Define templates for every toll type for your country + local templates = { + IT = { + {"mobile", "[35]%d%d%d%d%d%d+" }, + {"landline", "0[123456789]%d+" }, + {"international", "00%d+" }, + {"tollfree", "119|1[3456789]%d|19[24]%d|192[01]%d%d|800%d%d%d%d%d+|803%d%d%d+|456%d%d%d%d%d%d+|11[2345678]|15%d%d|116%d%d%d|196%d%d" }, + {"sharedcharge", "84[0178]%d%d%d%d+|199%d%d%d%d%d+|178%d%d%d%d%d+|12%d%d|10%d%d%d+|1482|149%d+|4[012]%d+|70%d%d%d%d%d+" }, + {"premium", "89[2459]%d%d%d+|16[456]%d%d%d+|144%d%d%d+|4[346789]%d%d+" }, + {"unknown", "%d%d+" }, + }; + FR = { + {"mobile", "0[67]%d%d%d%d%d%d%d%d" }, + {"landline", "0[1234589]%d%d%d%d%d%d%d%d" }, + {"international", "00%d+" }, + {"tollfree", "15|17|18|112|114|115|116%d%d%d|118%d%d%d|119|19[16]|1[06]%d%d|080%d+" }, + {"sharedcharge", "081%d+|082[0156]%d+|0884%d+|089[0123789]%d+" }, + {"premium", "%d%d+" }, + {"unknown", "%d%d+" }, + }; + US = { + {"unknown", "%d+"}, + }; + RU = { + {"international", "810%d+|8[89]40%d+|87%d%d%d%d%d%d%d%d%d"}; + {"mobile", "89%d%d%d%d%d%d%d%d%d" }; + {"tollfree", "8800%d%d%d%d%d%d%d|10[1-9]" }; + {"landline", "8[3-68]%d%d%d%d%d%d%d%d%d%d" }; + {"unknown", "" }; + }; + } + + --Set to true to allow all calls for extensions without toll_allow + local ACCEPT_EMPTY_TOLL_ALLOW = false + + --debug + debug["toll_type"] = false ---debug - debug["toll_type"] = false - require "resources.functions.explode"; --create the api object and get variables - api = freeswitch.API() - uuid = argv[2] - + local api = freeswitch.API() + local uuid = argv[2] + if not uuid or uuid == "" then return end - - template_indexes = { "mobile", "landline", "international", "tollfree", "sharedcharge", "premium", "unknown"} ---Define templates for every toll type for your country - function get_toll_types_it() - if (debug["toll_type"]) then - freeswitch.consoleLog("NOTICE", "[toll_allow] using IT toll types\n") + local function hungup() + session:hangup("OUTGOING_CALL_BARRED") + end + + local function log(level, msg) + freeswitch.consoleLog(level, "[toll_allow] " .. msg .. "\n") + end + + local function logf(level, ...) + return log(level, string.format(...)) + end + + local function trace(type, ...) + if debug[type] then log(...) end + end + + local function tracef(type, ...) + if debug[type] then logf(...) end + end + + local function channel_variable(uuid, name) + local result = api:executeString("uuid_getvar " .. uuid .. " " .. name) + + tracef("toll_type", "NOTICE", "channel_variable %s - %s", name, result) + + if result:sub(1, 4) == '-ERR' then return nil end + return result + end + + local function template_match(prefix, template, called) + local parts = explode("|", template) + + for index,part in ipairs(parts) do + local pattern = "^" .. prefix .. part .. "$" + if ( string.match(called, pattern) ~= nil ) then + return pattern + end end - - templates["mobile"] = "[35]%d%d%d%d%d%d+" - templates["landline"] = "0[123456789]%d+" - templates["international"] = "00%d+" - templates["tollfree"] = "119|1[3456789]%d|19[24]%d|192[01]%d%d|800%d%d%d%d%d+|803%d%d%d+|456%d%d%d%d%d%d+|11[2345678]|15%d%d|116%d%d%d|196%d%d" - templates["sharedcharge"] = "84[0178]%d%d%d%d+|199%d%d%d%d%d+|178%d%d%d%d%d+|12%d%d|10%d%d%d+|1482|149%d+|4[012]%d+|70%d%d%d%d%d+" - templates["premium"] = "89[2459]%d%d%d+|16[456]%d%d%d+|144%d%d%d+|4[346789]%d%d+" - templates["unknown"] = "%d%d+" end - function get_toll_types_us() - if (debug["toll_type"]) then - freeswitch.consoleLog("NOTICE", "[toll_allow] using US toll types\n") + local function get_toll_type(prefix, templates, called) + for _,params in ipairs(templates) do + local label, template = params[1], params[2] + if not known_templates[label] then + logf("WARNING", "unknown template name: %s in country template array", label) + end + + trace("toll_type", "NOTICE", "checking toll type " .. label .. " template: " .. template) + + local pattern = template_match(prefix, template, called) + if pattern then + trace("toll_type", "NOTICE", "destination number " .. called .. " matches " .. label .. " pattern: " .. pattern) + return label + end end - - templates["unknown"] = "%d+" end - function get_toll_types_fr() - if (debug["toll_type"]) then - freeswitch.consoleLog("NOTICE", "[toll_allow] using FR toll types\n") - end - - templates["mobile"] = "0[67]%d%d%d%d%d%d%d%d" - templates["landline"] = "0[1234589]%d%d%d%d%d%d%d%d" - templates["international"] = "00%d+" - templates["tollfree"] = "15|17|18|112|114|115|116%d%d%d|118%d%d%d|119|19[16]|1[06]%d%d|080%d+" - templates["sharedcharge"] = "081%d+|082[0156]%d+|0884%d+|089[0123789]%d+" - templates["premium"] = "%d%d+" - templates["unknown"] = "%d%d+" + local function is_undef(str) + return (not str) or (#str == 0) or (str == "_undef_") end - - called = api:executeString("uuid_getvar " .. uuid .. " destination_number") - prefix = api:executeString("uuid_getvar " .. uuid .. " outbound_prefix") - country = api:executeString("uuid_getvar " .. uuid .. " default_country") - toll_allow = api:executeString("uuid_getvar " .. uuid .. " toll_allow") - domain_name = api:executeString("uuid_getvar " .. uuid .. " domain_name") - caller = api:executeString("uuid_getvar " .. uuid .. " caller_id_number") - + + local called = channel_variable(uuid, "destination_number") or "" + local caller = channel_variable(uuid, "caller_id_number") or "" + local prefix = channel_variable(uuid, "outbound_prefix") or "" + local country = channel_variable(uuid, "default_country") or "" + local toll_allow = channel_variable(uuid, "toll_allow") or "" + if (debug["toll_type"]) then - freeswitch.consoleLog("NOTICE", "[toll_allow] called: " .. called .. "\n") - freeswitch.consoleLog("NOTICE", "[toll_allow] prefix: " .. prefix .. "\n") - freeswitch.consoleLog("NOTICE", "[toll_allow] country: " .. country .. "\n") - freeswitch.consoleLog("NOTICE", "[toll_allow] tollAllow: " .. toll_allow .. "\n") + logf("NOTICE", "called: %s", called) + logf("NOTICE", "prefix: %s", prefix) + logf("NOTICE", "country: %s", country) + logf("NOTICE", "tollAllow: %s", toll_allow) end - - templates = {} - local toll_type = "unknown" - - if ((prefix == nil) or (string.len(prefix) == 0) or (prefix == "_undef_") ) then + + if is_undef(toll_allow) then + if ACCEPT_EMPTY_TOLL_ALLOW then + logf("NOTICE", "unknown call authorized from %s to %s", caller, called) + return + end + logf("WARNING", "unknown call not authorized from %s to %s : OUTGOING_CALL_BARRED", caller, called) + return hungup() + end + + if is_undef(prefix) then prefix = "" end - - if ((country ~= nil) and (string.len(country) > 0)) then - --set templates for default country - if country == "IT" then get_toll_types_it() - elseif country == "US" then get_toll_types_us() - elseif country == "FR" then get_toll_types_fr() - else - if (debug["toll_type"]) then - freeswitch.consoleLog("NOTICE", "[toll_allow] toll type: " .. toll_type .. "\n") - end - return toll_type - end - - --set toll_type - local found = false - for i,label in pairs(template_indexes) do - template = templates[label] - if (debug["toll_type"]) then - freeswitch.consoleLog("NOTICE", "[toll_allow] checking toll type " .. label .. " template: " .. template .. "\n") - end - - --Doing split on | character - parts = explode("|", template) + if is_undef(country) then + log("WARNING", "undefined country") + return + end - for index,part in pairs(parts) do - pattern = "^" .. prefix .. part .. "$" - if (debug["toll_type"]) then - --freeswitch.consoleLog("NOTICE", "[toll_allow] checking toll type " .. label .. " pattern: " .. pattern .. "\n") - end - - if ( string.match(called, pattern) ~= nil ) then - if (debug["toll_type"]) then - freeswitch.consoleLog("NOTICE", "[toll_allow] destination number " .. called .. " matches " .. label .. " pattern: " .. pattern .. "\n") - end - toll_type = label - found = true - break - end - end - - if (found) then - break - end + local templates = templates[country] + if not templates then + log("WARNING", "undefined templates") + return + end + +--set toll_type + local toll_type = get_toll_type(prefix, templates, called) or "unknown" + + log("NOTICE", "toll type: " .. toll_type) + + local parts = explode(",", toll_allow) + + for i,part in ipairs(parts) do + if not known_templates[part] then + logf("WARNING", "unknown toll_allow name: %s in extension", part) end - - freeswitch.consoleLog("NOTICE", "[toll_allow] toll type: " .. toll_type .. "\n") - -- api:executeString("uuid_setvar " .. uuid .. " toll_type " .. toll_type); - -- session:setVariable('toll_type', toll_type); - - - --check toll allow - allow = false - - if ((toll_allow ~= nil) and (string.len(toll_allow) > 0) and (toll_allow ~= "_undef_")) then - parts = explode(",", toll_allow) - - for i,part in pairs(parts) do - if (debug["toll_type"]) then - freeswitch.consoleLog("NOTICE", "[toll_allow] checking toll allow part " .. part .. "\n") - end - - if ( part == toll_type ) then - allow = true - break - end - end - else - freeswitch.consoleLog("WARNING", "[toll_allow] toll_allow not defined for extension " .. caller .. "\n") - - -- Uncomment following line to allow all calls for extensions without toll_allow - -- allow = true - end - - --hangup not allowed calls - if ( not allow ) then - freeswitch.consoleLog("WARNING", "[toll_allow] " .. toll_type .. " call not authorized from " .. caller .. " to " .. called .. " : OUTGOING_CALL_BARRED\n") - session:hangup("OUTGOING_CALL_BARRED") - else - freeswitch.consoleLog("NOTICE", "[toll_allow] " .. toll_type .. " call authorized from " .. caller .. " to " .. called .. "\n") + + tracef("toll_type", "NOTICE", "checking toll allow part " .. part) + if ( part == toll_type ) then + logf("NOTICE", "%s call authorized from %s to %s", toll_type, caller, called) + return end end - + + logf("WARNING", "%s call not authorized from %s to %s : OUTGOING_CALL_BARRED", toll_type, caller, called) + return hungup() diff --git a/resources/install/scripts/call_forward.lua b/resources/install/scripts/call_forward.lua index ceb87a5701..95cbce7c3a 100644 --- a/resources/install/scripts/call_forward.lua +++ b/resources/install/scripts/call_forward.lua @@ -133,6 +133,7 @@ forward_all_enabled = row.forward_all_enabled; forward_all_destination = row.forward_all_destination; follow_me_uuid = row.follow_me_uuid; + toll_allow = row.toll_allow or ''; --freeswitch.consoleLog("NOTICE", "[call forward] extension "..row.extension.."\n"); --freeswitch.consoleLog("NOTICE", "[call forward] accountcode "..row.accountcode.."\n"); end); @@ -148,7 +149,7 @@ end --get the forward destination - if (session:ready() and enabled == "true" or enabled == "toggle") then + if (session:ready() and (enabled == "true" or enabled == "toggle") ) then if (string.len(forward_all_destination) == 0) then forward_all_destination = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-enter_destination_telephone_number.wav", "", "\\d+"); end @@ -171,6 +172,7 @@ dial_string = dial_string .. ",sip_invite_domain="..domain_name; dial_string = dial_string .. ",domain_name="..domain_name; dial_string = dial_string .. ",domain="..domain_name; + dial_string = dial_string .. ",toll_allow='"..toll_allow.."'"; if (accountcode ~= nil) then dial_string = dial_string .. ",accountcode="..accountcode; end @@ -241,7 +243,7 @@ sql = "update v_extensions set "; if (enabled == "true") then sql = sql .. "forward_all_destination = '"..forward_all_destination.."', "; - sql = sql .. "dial_string = '"..dial_string.."', "; + sql = sql .. "dial_string = '"..dial_string:gsub("'", "''").."', "; sql = sql .. "do_not_disturb = 'false', "; else sql = sql .. "forward_all_destination = null, ";