diff --git a/app/dialplan/resources/switch/conf/dialplan/070_toll_type_assignment.xml b/app/dialplan/resources/switch/conf/dialplan/070_toll_type_assignment.xml deleted file mode 100644 index 467bb3d554..0000000000 --- a/app/dialplan/resources/switch/conf/dialplan/070_toll_type_assignment.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/app/dialplan_outbound/app_languages.php b/app/dialplan_outbound/app_languages.php index b0232bced6..48523a7163 100644 --- a/app/dialplan_outbound/app_languages.php +++ b/app/dialplan_outbound/app_languages.php @@ -302,6 +302,16 @@ $text['description-accountcode']['pt-pt'] = "Introduza a conta."; $text['description-accountcode']['fr-fr'] = ""; + $text['label-toll_allow']['en-us'] = "Toll allow"; + $text['label-toll_allow']['es-cl'] = "Permitir Tarifas Especiales"; + $text['label-toll_allow']['pt-pt'] = "Permissões"; + $text['label-toll_allow']['fr-fr'] = "Droits"; + + $text['description-enable-toll_allow']['en-us'] = "Set to true to enable toll allow"; + $text['description-enable-toll_allow']['es-cl'] = "Seleccione verdadero para activar permitir Tarifas Especiales"; + $text['description-enable-toll_allow']['pt-pt'] = "scolha 'sim' para activar permissões"; + $text['description-enable-toll_allow']['fr-fr'] = "Choisir Oui pour activer droits"; + $text['label-order']['en-us'] = "Order"; $text['label-order']['es-cl'] = "Orden"; $text['label-order']['pt-pt'] = "Ordem"; diff --git a/app/dialplan_outbound/dialplan_outbound_add.php b/app/dialplan_outbound/dialplan_outbound_add.php index 27b71757ab..d538313a14 100644 --- a/app/dialplan_outbound/dialplan_outbound_add.php +++ b/app/dialplan_outbound/dialplan_outbound_add.php @@ -62,7 +62,11 @@ else { $gateway = check_str($_POST["gateway"]); $limit = check_str($_POST["limit"]); $accountcode = check_str($_POST["accountcode"]); - + + $toll_allow_enable = check_str($_POST["toll_allow_enabled"]); + //set default to enabled + if (strlen($toll_allow_enable) == 0) { $toll_allow_enable = "false"; } + //set the default type $gateway_type = 'gateway'; $gateway_2_type = 'gateway'; @@ -267,7 +271,7 @@ else { $tmp_prefix == $dialplan_expression ? $outbound_prefix = "" : $outbound_prefix = $tmp_prefix; - + if ($gateway_type == "gateway") { $dialplan_name = $gateway_name.".".$abbrv; $action_data = "sofia/gateway/".$gateway_uuid."/".$prefix_number."\$1"; @@ -482,10 +486,21 @@ else { dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data, $dialplan_detail_break, $dialplan_detail_inline); } + if ($toll_allow_enable == "true") { + $dialplan_detail_tag = 'action'; //condition, action, antiaction + $dialplan_detail_type = 'lua'; + $dialplan_detail_data = 'app.lua toll_allow ${uuid}'; + $dialplan_detail_order = '065'; + $dialplan_detail_group = ''; + $dialplan_detail_break = ''; + $dialplan_detail_inline = 'true'; + dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data, $dialplan_detail_break, $dialplan_detail_inline); + } + $dialplan_detail_tag = 'action'; //condition, action, antiaction $dialplan_detail_type = 'bridge'; $dialplan_detail_data = $action_data; - $dialplan_detail_order = '065'; + $dialplan_detail_order = '070'; $dialplan_detail_group = ''; dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); @@ -493,7 +508,7 @@ else { $dialplan_detail_tag = 'action'; //condition, action, antiaction $dialplan_detail_type = 'bridge'; $dialplan_detail_data = $bridge_2_data; - $dialplan_detail_order = '070'; + $dialplan_detail_order = '075'; $dialplan_detail_group = ''; dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); } @@ -502,7 +517,7 @@ else { $dialplan_detail_tag = 'action'; //condition, action, antiaction $dialplan_detail_type = 'bridge'; $dialplan_detail_data = $bridge_3_data; - $dialplan_detail_order = '075'; + $dialplan_detail_order = '080'; $dialplan_detail_group = ''; dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); } @@ -913,6 +928,20 @@ function type_onchange(dialplan_detail_type) { echo "\n"; echo "\n"; + echo "\n"; + echo "\n"; + echo " ".$text['label-toll_allow'].":\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-enable-toll_allow']."\n"; + echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; echo " ".$text['label-order'].":\n"; diff --git a/resources/install/scripts/toll_type_assignment.lua b/resources/install/scripts/app/toll_allow/index.lua similarity index 62% rename from resources/install/scripts/toll_type_assignment.lua rename to resources/install/scripts/app/toll_allow/index.lua index fff46a925b..fe039accac 100644 --- a/resources/install/scripts/toll_type_assignment.lua +++ b/resources/install/scripts/app/toll_allow/index.lua @@ -23,19 +23,20 @@ -- Riccardo Granchi --debug - debug["toll_type"] = false + debug["toll_type"] = true - 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/explode.lua") + dofile(scripts_dir.."/resources/functions/explode.lua"); --create the api object and get variables api = freeswitch.API() - uuid = argv[1] + 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 @@ -63,8 +64,17 @@ 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") - template_indexes = { "mobile", "landline", "international", "tollfree", "sharedcharge", "premium", "unknown"} + if (debug["toll_type"]) then + freeswitch.consoleLog("NOTICE", "[toll_type_assignment] called: " .. called .. "\n") + freeswitch.consoleLog("NOTICE", "[toll_type_assignment] prefix: " .. prefix .. "\n") + freeswitch.consoleLog("NOTICE", "[toll_type_assignment] country: " .. country .. "\n") + freeswitch.consoleLog("NOTICE", "[toll_type_assignment] tollAllow: " .. toll_allow .. "\n") + end + templates = {} local toll_type = "unknown" @@ -78,11 +88,13 @@ if country == "IT" then get_toll_types_it() elseif country == "US" then get_toll_types_us() else - freeswitch.consoleLog("NOTICE", "[toll_type_assignment] toll type: " .. toll_type .. "\n") + if (debug["toll_type"]) then + freeswitch.consoleLog("NOTICE", "[toll_type_assignment] toll type: " .. toll_type .. "\n") + end return toll_type end - --test templates matching to set correct toll_type + --set toll_type local found = false for i,label in pairs(template_indexes) do template = templates[label] @@ -113,7 +125,41 @@ break end end + + freeswitch.consoleLog("NOTICE", "[toll_type_assignment] 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_type_assignment] checking toll allow part " .. part .. "\n") + end + + if ( part == toll_type ) then + allow = true + break + end + end + else + freeswitch.consoleLog("WARNING", domain_name .. " - 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", domain_name .. " - " .. toll_type .. " call not authorized from " .. caller .. " to " .. called .. " : REJECTING!\n") + session:hangup("OUTGOING_CALL_BARRED") + else + freeswitch.consoleLog("NOTICE", domain_name .. " - " .. toll_type .. " call authorized from " .. caller .. " to " .. called .. "\n") + end end - freeswitch.consoleLog("NOTICE", "[toll_type_assignment] toll type: " .. toll_type .. "\n") - return toll_type