diff --git a/app/call_centers/call_center_queue_delete.php b/app/call_centers/call_center_queue_delete.php index 5abb84093f..e00655459a 100644 --- a/app/call_centers/call_center_queue_delete.php +++ b/app/call_centers/call_center_queue_delete.php @@ -43,59 +43,60 @@ else { $id = check_str($_GET["id"]); } -if (strlen($id) > 0) { +//delete the data + if (strlen($id) > 0) { - //get the dialplan uuid - $sql = "select * from v_call_center_queues "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and call_center_queue_uuid = '$id' "; - $prep_statement = $db->prepare($sql); - $prep_statement->execute(); - while($row = $prep_statement->fetch(PDO::FETCH_ASSOC)) { - $queue_name = $row['queue_name']; - $dialplan_uuid = $row['dialplan_uuid']; - } + //get the dialplan uuid + $sql = "select * from v_call_center_queues "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "and call_center_queue_uuid = '$id' "; + $prep_statement = $db->prepare($sql); + $prep_statement->execute(); + while($row = $prep_statement->fetch(PDO::FETCH_ASSOC)) { + $queue_name = $row['queue_name']; + $dialplan_uuid = $row['dialplan_uuid']; + } - //delete the tier from the database - $sql = "delete from v_call_center_tiers "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and queue_name = '$queue_name' "; - $db->query($sql); - unset($sql); + //delete the tier from the database + $sql = "delete from v_call_center_tiers "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "and queue_name = '$queue_name' "; + $db->query($sql); + unset($sql); - //delete the call center queue - $sql = "delete from v_call_center_queues "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and dialplan_uuid = '$dialplan_uuid' "; - $db->query($sql); - unset($sql); + //delete the call center queue + $sql = "delete from v_call_center_queues "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "and call_center_queue_uuid = '$id' "; + $db->query($sql); + unset($sql); - //delete the dialplan entry - $sql = "delete from v_dialplans "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and dialplan_uuid = '$dialplan_uuid' "; - $db->query($sql); - unset($sql); + //delete the dialplan entry + $sql = "delete from v_dialplans "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "and dialplan_uuid = '$dialplan_uuid' "; + $db->query($sql); + unset($sql); - //delete the dialplan details - $sql = "delete from v_dialplan_details "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and dialplan_uuid = '$dialplan_uuid' "; - $db->query($sql); - unset($sql); + //delete the dialplan details + $sql = "delete from v_dialplan_details "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "and dialplan_uuid = '$dialplan_uuid' "; + $db->query($sql); + unset($sql); - //clear the cache - $cache = new cache; - $cache->delete("dialplan:".$_SESSION["context"]); - remove_config_from_cache('configuration:callcenter.conf'); + //clear the cache + $cache = new cache; + $cache->delete("dialplan:".$_SESSION["context"]); + remove_config_from_cache('configuration:callcenter.conf'); - //synchronize configuration - save_dialplan_xml(); - save_call_center_xml(); + //synchronize configuration + save_dialplan_xml(); + save_call_center_xml(); - //apply settings reminder - $_SESSION["reload_xml"] = true; -} + //apply settings reminder + $_SESSION["reload_xml"] = true; + } //redirect the browser $_SESSION["message"] = $text['message-delete']; diff --git a/app/call_centers/call_center_queue_edit.php b/app/call_centers/call_center_queue_edit.php index e37cf5f245..6f9a00809d 100644 --- a/app/call_centers/call_center_queue_edit.php +++ b/app/call_centers/call_center_queue_edit.php @@ -255,7 +255,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $db->exec(check_sql($sql)); unset($sql); - //syncrhonize the configuration + //synchronize the configuration save_call_center_xml(); remove_config_from_cache('configuration:callcenter.conf'); @@ -311,20 +311,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { } unset ($prep_statement); - //dialplan add or update - $c = new call_center; - $c->db = $db; - $c->domain_uuid = $_SESSION['domain_uuid']; - $c->call_center_queue_uuid = $call_center_queue_uuid; - $c->dialplan_uuid = $dialplan_uuid; - $c->queue_name = $queue_name; - $c->queue_name = $queue_name; - $c->queue_cid_prefix = $queue_cid_prefix; - $c->queue_timeout_action = $queue_timeout_action; - $c->queue_description = $queue_description; - $c->destination_number = $queue_extension; - $a = $c->dialplan(); - //synchronize the configuration save_call_center_xml(); remove_config_from_cache('configuration:callcenter.conf'); @@ -337,6 +323,20 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $_SESSION["message"] = $text['message-update']; } //if ($action == "update") + //dialplan add or update + $c = new call_center; + $c->db = $db; + $c->domain_uuid = $_SESSION['domain_uuid']; + $c->call_center_queue_uuid = $call_center_queue_uuid; + $c->dialplan_uuid = $dialplan_uuid; + $c->queue_name = $queue_name; + $c->queue_name = $queue_name; + $c->queue_cid_prefix = $queue_cid_prefix; + $c->queue_timeout_action = $queue_timeout_action; + $c->queue_description = $queue_description; + $c->destination_number = $queue_extension; + $a = $c->dialplan(); + //add agent/tier to queue $agent_name = check_str($_POST["agent_name"]); $tier_level = check_str($_POST["tier_level"]); @@ -399,8 +399,8 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { } //redirect - header("Location: call_center_queue_edit.php?id=".$call_center_queue_uuid); - return; + header("Location: call_center_queue_edit.php?id=".$call_center_queue_uuid); + return; } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) diff --git a/app/destinations/destination_edit.php b/app/destinations/destination_edit.php index f2f446510a..d6051689c1 100644 --- a/app/destinations/destination_edit.php +++ b/app/destinations/destination_edit.php @@ -543,7 +543,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo " if (document.getElementById('tr_caller_id_name')) { document.getElementById('tr_caller_id_name').style.display = 'none'; }\n"; echo " if (document.getElementById('tr_caller_id_number')) { document.getElementById('tr_caller_id_number').style.display = 'none'; }\n"; echo " document.getElementById('tr_actions').style.display = 'none';\n"; - echo " document.getElementById('tr_fax_detection').style.display = 'none';\n"; + echo " if (document.getElementById('tr_fax_detection')) { document.getElementById('tr_fax_detection').style.display = 'none'; }\n"; echo " document.getElementById('tr_cid_name_prefix').style.display = 'none';\n"; echo " if (document.getElementById('tr_sell')) { document.getElementById('tr_sell').style.display = 'none'; }\n"; echo " if (document.getElementById('tr_buy')) { document.getElementById('tr_buy').style.display = 'none'; }\n"; @@ -555,7 +555,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo " if (document.getElementById('tr_caller_id_name')) { document.getElementById('tr_caller_id_name').style.display = ''; }\n"; echo " if (document.getElementById('tr_caller_id_number')) { document.getElementById('tr_caller_id_number').style.display = ''; }\n"; echo " document.getElementById('tr_actions').style.display = '';\n"; - echo " document.getElementById('tr_fax_detection').style.display = '';\n"; + echo " if (document.getElementById('tr_fax_detection')) { document.getElementById('tr_fax_detection').style.display = ''; }\n"; echo " document.getElementById('tr_cid_name_prefix').style.display = '';\n"; echo " if (document.getElementById('tr_sell')) { document.getElementById('tr_sell').style.display = ''; }\n"; echo " if (document.getElementById('tr_buy')) { document.getElementById('tr_buy').style.display = ''; }\n"; diff --git a/app/devices/app_config.php b/app/devices/app_config.php index d8f6591886..6f3f3cfaac 100644 --- a/app/devices/app_config.php +++ b/app/devices/app_config.php @@ -39,6 +39,18 @@ $apps[$x]['permissions'][$y]['groups'][] = "admin"; $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; $y++; + $apps[$x]['permissions'][$y]['name'] = 'device_mac_address'; + $apps[$x]['permissions'][$y]['groups'][] = 'superadmin'; + $apps[$x]['permissions'][$y]['groups'][] = 'admin'; + $y++; + $apps[$x]['permissions'][$y]['name'] = 'device_label'; + $apps[$x]['permissions'][$y]['groups'][] = 'superadmin'; + $apps[$x]['permissions'][$y]['groups'][] = 'admin'; + $y++; + $apps[$x]['permissions'][$y]['name'] = 'device_template'; + $apps[$x]['permissions'][$y]['groups'][] = 'superadmin'; + $apps[$x]['permissions'][$y]['groups'][] = 'admin'; + $y++; $apps[$x]['permissions'][$y]['name'] = "device_extension_view"; $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; $apps[$x]['permissions'][$y]['groups'][] = "admin"; @@ -105,6 +117,15 @@ $y++; $apps[$x]['permissions'][$y]['name'] = 'device_domain'; $apps[$x]['permissions'][$y]['groups'][] = 'superadmin'; + $apps[$x]['permissions'][$y]['groups'][] = 'admin'; + $y++; + $apps[$x]['permissions'][$y]['name'] = 'device_username_password'; + $apps[$x]['permissions'][$y]['groups'][] = 'superadmin'; + $apps[$x]['permissions'][$y]['groups'][] = 'admin'; + $y++; + $apps[$x]['permissions'][$y]['name'] = 'device_alternate'; + $apps[$x]['permissions'][$y]['groups'][] = 'superadmin'; + $apps[$x]['permissions'][$y]['groups'][] = 'admin'; $y++; $apps[$x]['permissions'][$y]['name'] = "device_profile_view"; $apps[$x]['permissions'][$y]['groups'][] = "admin"; @@ -127,6 +148,25 @@ $y++; $apps[$x]['permissions'][$y]['name'] = 'device_all'; $apps[$x]['permissions'][$y]['groups'][] = 'superadmin'; + $y++; + $apps[$x]['permissions'][$y]['name'] = 'device_vendor'; + $apps[$x]['permissions'][$y]['groups'][] = 'superadmin'; + $apps[$x]['permissions'][$y]['groups'][] = 'admin'; + $y++; + $apps[$x]['permissions'][$y]['name'] = 'device_model'; + $apps[$x]['permissions'][$y]['groups'][] = 'superadmin'; + $y++; + $apps[$x]['permissions'][$y]['name'] = 'device_firmware'; + $apps[$x]['permissions'][$y]['groups'][] = 'superadmin'; + $y++; + $apps[$x]['permissions'][$y]['name'] = 'device_enable'; + $apps[$x]['permissions'][$y]['groups'][] = 'superadmin'; + $apps[$x]['permissions'][$y]['groups'][] = 'admin'; + $y++; + $apps[$x]['permissions'][$y]['name'] = 'device_description'; + $apps[$x]['permissions'][$y]['groups'][] = 'superadmin'; + $apps[$x]['permissions'][$y]['groups'][] = 'admin'; + $y++; //schema details $y = 0; //table array index diff --git a/app/devices/app_languages.php b/app/devices/app_languages.php index 577792fd96..c0667a6139 100644 --- a/app/devices/app_languages.php +++ b/app/devices/app_languages.php @@ -789,17 +789,17 @@ $text['label-orbit']['de-at'] = "Park + Orbit"; $text['label-orbit']['ar-eg'] = ""; $text['label-orbit']['he'] = ""; -$text['label-normal']['en-us'] = "normal"; -$text['label-normal']['es-cl'] = "normal"; -$text['label-normal']['pt-pt'] = "normal"; -$text['label-normal']['fr-fr'] = "normal"; +$text['label-normal']['en-us'] = "Normal"; +$text['label-normal']['es-cl'] = "Normal"; +$text['label-normal']['pt-pt'] = "Normal"; +$text['label-normal']['fr-fr'] = "Normal"; $text['label-normal']['pt-br'] = "Normal"; -$text['label-normal']['pl'] = "normalny"; -$text['label-normal']['uk'] = "звичайно"; -$text['label-normal']['sv-se'] = "normal"; -$text['label-normal']['de-at'] = "normal"; -$text['label-normal']['ar-eg'] = ""; -$text['label-normal']['he'] = ""; +$text['label-normal']['pl'] = "Normalny"; +$text['label-normal']['uk'] = "Звичайно"; +$text['label-normal']['sv-se'] = "Normal"; +$text['label-normal']['de-at'] = "Normal"; +$text['label-normal']['ar-eg'] = "Normal"; +$text['label-normal']['he'] = "Normal"; $text['label-none']['en-us'] = "None"; $text['label-none']['es-cl'] = "Ninguno"; @@ -1715,18 +1715,109 @@ $text['label-xfer']['de-at'] = ""; $text['label-xfer']['ar-eg'] = ""; $text['label-xfer']['he'] = ""; -$text['label-automata']['en-us'] = "automata"; -$text['label-automata']['es-cl'] = "automata"; -$text['label-automata']['pt-pt'] = "automata"; -$text['label-automata']['fr-fr'] = "automata"; +$text['label-automata']['en-us'] = "Automata"; +$text['label-automata']['es-cl'] = "Automata"; +$text['label-automata']['pt-pt'] = "Automata"; +$text['label-automata']['fr-fr'] = "Automata"; $text['label-automata']['pt-br'] = "Automata"; -$text['label-automata']['pl'] = "automaty"; -$text['label-automata']['uk'] = ""; +$text['label-automata']['pl'] = "Automaty"; +$text['label-automata']['uk'] = "Automata"; $text['label-automata']['sv-se'] = "Automata"; -$text['label-automata']['ro'] = ""; -$text['label-automata']['de-at'] = "automata"; -$text['label-automata']['ar-eg'] = ""; -$text['label-automata']['he'] = ""; +$text['label-automata']['ro'] = "Automata"; +$text['label-automata']['de-at'] = "Automata"; +$text['label-automata']['ar-eg'] = "Automata"; +$text['label-automata']['he'] = "Automata"; + +$text['label-messages']['en-us'] = "Messages"; +$text['label-messages']['es-cl'] = "Messages"; +$text['label-messages']['pt-pt'] = "Messages"; +$text['label-messages']['fr-fr'] = "Messages"; +$text['label-messages']['pt-br'] = "Messages"; +$text['label-messages']['pl'] = "Messages"; +$text['label-messages']['uk'] = "Messages"; +$text['label-messages']['sv-se'] = "Messages"; +$text['label-messages']['ro'] = "Messages"; +$text['label-messages']['de-at'] = "Messages"; +$text['label-messages']['ar-eg'] = "Messages"; +$text['label-messages']['he'] = "Messages"; + +$text['label-micmute']['en-us'] = "MicMute"; +$text['label-micmute']['es-cl'] = "MicMute"; +$text['label-micmute']['pt-pt'] = "MicMute"; +$text['label-micmute']['fr-fr'] = "MicMute"; +$text['label-micmute']['pt-br'] = "MicMute"; +$text['label-micmute']['pl'] = "MicMute"; +$text['label-micmute']['uk'] = "MicMute"; +$text['label-micmute']['sv-se'] = "MicMute"; +$text['label-micmute']['ro'] = "MicMute"; +$text['label-micmute']['de-at'] = "MicMute"; +$text['label-micmute']['ar-eg'] = "MicMute"; +$text['label-micmute']['he'] = "MicMute"; + +$text['label-redial']['en-us'] = "Redial"; +$text['label-redial']['es-cl'] = "Redial"; +$text['label-redial']['pt-pt'] = "Redial"; +$text['label-redial']['fr-fr'] = "Redial"; +$text['label-redial']['pt-br'] = "Redial"; +$text['label-redial']['pl'] = "Redial"; +$text['label-redial']['uk'] = "Redial"; +$text['label-redial']['sv-se'] = "Redial"; +$text['label-redial']['ro'] = "Redial"; +$text['label-redial']['de-at'] = "Redial"; +$text['label-redial']['ar-eg'] = "Redial"; +$text['label-redial']['he'] = "Redial"; + +$text['label-null']['en-us'] = "Null"; +$text['label-null']['es-cl'] = "Null"; +$text['label-null']['pt-pt'] = "Null"; +$text['label-null']['fr-fr'] = "Null"; +$text['label-null']['pt-br'] = "Null"; +$text['label-null']['pl'] = "Null"; +$text['label-null']['uk'] = "Null"; +$text['label-null']['sv-se'] = "Null"; +$text['label-null']['ro'] = "Null"; +$text['label-null']['de-at'] = "Null"; +$text['label-null']['ar-eg'] = "Null"; +$text['label-null']['he'] = "Null"; + +$text['label-speeddial']['en-us'] = "SpeedDial"; +$text['label-speeddial']['es-cl'] = "SpeedDial"; +$text['label-speeddial']['pt-pt'] = "SpeedDial"; +$text['label-speeddial']['fr-fr'] = "SpeedDial"; +$text['label-speeddial']['pt-br'] = "SpeedDial"; +$text['label-speeddial']['pl'] = "SpeedDial"; +$text['label-speeddial']['uk'] = "SpeedDial"; +$text['label-speeddial']['sv-se'] = "SpeedDial"; +$text['label-speeddial']['ro'] = "SpeedDial"; +$text['label-speeddial']['de-at'] = "SpeedDial"; +$text['label-speeddial']['ar-eg'] = "SpeedDial"; +$text['label-speeddial']['he'] = "SpeedDial"; + +$text['label-speeddialmenu']['en-us'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['es-cl'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['pt-pt'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['fr-fr'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['pt-br'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['pl'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['uk'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['sv-se'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['ro'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['de-at'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['ar-eg'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['he'] = "SpeedDialMenu"; + +$text['label-url']['en-us'] = "URL"; +$text['label-url']['es-cl'] = "URL"; +$text['label-url']['pt-pt'] = "URL"; +$text['label-url']['fr-fr'] = "URL"; +$text['label-url']['pt-br'] = "URL"; +$text['label-url']['pl'] = "URL"; +$text['label-url']['uk'] = "URL"; +$text['label-url']['sv-se'] = "URL"; +$text['label-url']['ro'] = "URL"; +$text['label-url']['de-at'] = "URL"; +$text['label-url']['ar-eg'] = "URL"; +$text['label-url']['he'] = "URL"; $text['label-auto_answer']['en-us'] = "Auto Answer"; $text['label-auto_answer']['es-cl'] = "Respuesta Automática"; diff --git a/app/devices/device_edit.php b/app/devices/device_edit.php index 85885a9467..20fc4e00c1 100644 --- a/app/devices/device_edit.php +++ b/app/devices/device_edit.php @@ -128,10 +128,25 @@ require_once "resources/require.php"; //get http post variables and set them to php variables if (count($_POST) > 0) { + //device mac address + if (permission_exists('device_mac_address')) { + $device_mac_address = check_str($_POST["device_mac_address"]); + $device_mac_address = strtolower(preg_replace('#[^a-fA-F0-9./]#', '', $device_mac_address)); + $_POST["device_mac_address"] = $device_mac_address; + } + else { + $orm = new orm; + $orm->name('devices'); + $orm->uuid($device_uuid); + $result = $orm->find()->get(); + //$message = $orm->message; + foreach ($result as &$row) { + $device_mac_address = $row["device_mac_address"]; + $_POST["device_mac_address"] = $device_mac_address; + } + unset ($prep_statement); + } //devices - $device_mac_address = check_str($_POST["device_mac_address"]); - $device_mac_address = strtolower(preg_replace('#[^a-fA-F0-9./]#', '', $device_mac_address)); - $_POST["device_mac_address"] = $device_mac_address; $device_label = check_str($_POST["device_label"]); $device_vendor = check_str($_POST["device_vendor"]); $device_uuid_alternate = check_str($_POST["device_uuid_alternate"]); @@ -288,7 +303,7 @@ require_once "resources/require.php"; } //write the provision files - if (strlen($_SESSION['switch']['provision']['dir']) > 0) { + if (strlen($_SESSION['provision']['path']['text']) > 0) { require_once "app/provision/provision_write.php"; } @@ -514,7 +529,7 @@ require_once "resources/require.php"; echo "\n"; echo "\n"; echo " \n"; - if ($action != "add") { + if (permission_exists('device_add') && $action != "add") { echo " \n"; } echo " \n"; @@ -526,195 +541,211 @@ require_once "resources/require.php"; echo " ".$text['label-device_mac_address']."\n"; echo "\n"; echo "\n"; - echo " \n"; + if (permission_exists('device_mac_address')) { + echo " \n"; + echo "
\n"; + echo $text['description-device_mac_address']."\n"; + } + else { + echo $device_mac_address; + } echo " \n"; - echo "
\n"; - echo $text['description-device_mac_address']."\n"; echo "\n"; echo "\n"; + echo "\n"; echo "\n"; echo " ".$text['label-device_label']."\n"; echo "\n"; echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-device_label']."\n"; + if (permission_exists('device_label')) { + echo " \n"; + echo "
\n"; + echo $text['description-device_label']."\n"; + } + else { + echo $device_label; + } + echo "\n"; echo "\n"; - echo "\n"; - echo "\n"; - echo " ".$text['label-device_template']."\n"; - echo "\n"; - echo "\n"; - $device = new device; - $template_dir = $device->get_template_dir(); + if (permission_exists('device_template')) { + echo "\n"; + echo "\n"; + echo " ".$text['label-device_template']."\n"; + echo "\n"; + echo "\n"; + $device = new device; + $template_dir = $device->get_template_dir(); - echo "\n"; + echo "\n"; - if (is_dir($template_dir)) { - $templates = scandir($template_dir); - foreach($templates as $dir) { - if($file != "." && $dir != ".." && $dir[0] != '.') { - if(is_dir($template_dir . "/" . $dir)) { - echo ""; - $dh_sub=$template_dir . "/" . $dir; - if(is_dir($dh_sub)) { - $templates_sub = scandir($dh_sub); - foreach($templates_sub as $dir_sub) { - if($file_sub != '.' && $dir_sub != '..' && $dir_sub[0] != '.') { - if(is_dir($template_dir . '/' . $dir .'/'. $dir_sub)) { - if ($device_template == $dir."/".$dir_sub) { - echo "\n"; - } - else { - echo "\n"; + if (is_dir($template_dir)) { + $templates = scandir($template_dir); + foreach($templates as $dir) { + if($file != "." && $dir != ".." && $dir[0] != '.') { + if(is_dir($template_dir . "/" . $dir)) { + echo ""; + $dh_sub=$template_dir . "/" . $dir; + if(is_dir($dh_sub)) { + $templates_sub = scandir($dh_sub); + foreach($templates_sub as $dir_sub) { + if($file_sub != '.' && $dir_sub != '..' && $dir_sub[0] != '.') { + if(is_dir($template_dir . '/' . $dir .'/'. $dir_sub)) { + if ($device_template == $dir."/".$dir_sub) { + echo "\n"; + } + else { + echo "\n"; + } } } } + closedir($dh_sub); } - closedir($dh_sub); + echo ""; } - echo ""; } } + closedir($dh); } - closedir($dh); - } - echo "\n"; - echo "
\n"; - echo $text['description-device_template']."\n"; - echo "\n"; - echo "\n"; - - echo " "; - echo " ".$text['label-lines'].""; - echo " "; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - if (permission_exists('device_line_password')) { - echo " \n"; + echo "\n"; + echo "
\n"; + echo $text['description-device_template']."\n"; + echo "\n"; + echo "\n"; } - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - $x = 0; - foreach($device_lines as $row) { - //determine whether to hide the element - if (strlen($device_line_uuid) == 0) { - $element['hidden'] = false; - $element['visibility'] = "visibility:visible;"; - } - else { - $element['hidden'] = true; - $element['visibility'] = "visibility:hidden;"; - } - //add the primary key uuid - if (strlen($row['device_line_uuid']) > 0) { - echo " \n"; - } - //show each row in the array - echo " \n"; - echo " \n"; - - echo " \n"; - - echo " \n"; - - echo " \n"; - - echo " \n"; - - echo " \n"; - - if (permission_exists('device_line_password')) { - echo " \n"; - } - - echo " \n"; - - echo " \n"; - - echo " \n"; - - echo " \n"; - - echo " "; + echo " "; + echo " "; - echo " "; - if (permission_exists('device_key_add') || permission_exists('device_key_edit')) { + $x = 0; + foreach($device_lines as $row) { + //determine whether to hide the element + if (strlen($device_line_uuid) == 0) { + $element['hidden'] = false; + $element['visibility'] = "visibility:visible;"; + } + else { + $element['hidden'] = true; + $element['visibility'] = "visibility:hidden;"; + } + //add the primary key uuid + if (strlen($row['device_line_uuid']) > 0) { + echo " \n"; + } + //show each row in the array + echo " \n"; + echo " \n"; + + echo " \n"; + + echo " \n"; + + echo " \n"; + + echo " \n"; + + echo " \n"; + + if (permission_exists('device_line_password')) { + echo " \n"; + } + + echo " \n"; + + echo " \n"; + + echo " \n"; + + echo " \n"; + + echo " \n"; + echo " \n"; + $x++; + } + echo "
".$text['label-line']."".$text['label-server_address']."".$text['label-outbound_proxy']."".$text['label-display_name']."".$text['label-user_id']."".$text['label-auth_id']."".$text['label-password']."
".$text['label-sip_port']."".$text['label-sip_transport']."".$text['label-register_expires']."".$text['label-enabled']." 
\n"; - $selected = "selected=\"selected\" "; - 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"; - if (strlen($row['device_line_uuid']) > 0) { - if (permission_exists('device_delete')) { - echo " $v_link_label_delete\n"; - } + if (permission_exists('device_line_view')) { + echo "
".$text['label-lines'].""; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + if (permission_exists('device_line_password')) { + echo " \n"; } - echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; echo " \n"; - $x++; - } - echo "
".$text['label-line']."".$text['label-server_address']."".$text['label-outbound_proxy']."".$text['label-display_name']."".$text['label-user_id']."".$text['label-auth_id']."".$text['label-password']."".$text['label-sip_port']."".$text['label-sip_transport']."".$text['label-register_expires']."".$text['label-enabled']." 
\n"; - if (strlen($text['description-lines']) > 0) { - echo "
".$text['description-lines']."\n"; - } - echo "
\n"; + $selected = "selected=\"selected\" "; + 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"; + if (strlen($row['device_line_uuid']) > 0) { + if (permission_exists('device_delete')) { + echo " $v_link_label_delete\n"; + } + } + echo "
\n"; + if (strlen($text['description-lines']) > 0) { + echo "
".$text['description-lines']."\n"; + } + echo " "; + echo " "; + } + + if (permission_exists('device_profile_edit')) { //device profile $sql = "select * from v_device_profiles "; $sql .= "where (domain_uuid = '".$domain_uuid."' or domain_uuid is null) "; @@ -738,7 +769,9 @@ require_once "resources/require.php"; echo " "; echo " "; } + } + if (permission_exists('device_key_edit')) { $vendor_count = 0; foreach($device_keys as $row) { if ($previous_vendor != $row['device_key_vendor']) { @@ -931,6 +964,13 @@ require_once "resources/require.php"; + + + + + + + "; } } @@ -1065,7 +1105,7 @@ require_once "resources/require.php"; } //device settings - if (permission_exists('device_setting_add')) { + if (permission_exists('device_setting_edit')) { echo " "; echo " ".$text['label-settings'].""; echo " "; @@ -1153,75 +1193,85 @@ require_once "resources/require.php"; echo " \n"; } - echo "\n"; - echo "\n"; - echo " ".$text['label-device']."\n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo $text['description-device']."\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo " ".$text['label-device_uuid_alternate']."\n"; - echo "\n"; - echo "\n"; - if (strlen($device_uuid_alternate) == 0) { - echo " "; + if (permission_exists('device_username_password')) { + echo "\n"; + echo "\n"; + echo " ".$text['label-device']."\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo $text['description-device']."\n"; + echo "\n"; + echo "\n"; } - else { - $label = $device_alternate[0]['device_label']; - if (strlen($label) == 0) { $label = $device_alternate[0]['device_description']; } - if (strlen($label) == 0) { $label = $device_alternate[0]['device_mac_address']; } - echo " \n"; - echo " \n"; - echo " "; - echo " \n"; - echo " \n"; - echo "
$label $v_link_label_delete
\n"; - unset($label); + + if (permission_exists('device_alternate')) { + echo "\n"; + echo "\n"; + echo " ".$text['label-device_uuid_alternate']."\n"; + echo "\n"; + echo "\n"; + if (strlen($device_uuid_alternate) == 0) { + echo " "; + } + else { + $label = $device_alternate[0]['device_label']; + if (strlen($label) == 0) { $label = $device_alternate[0]['device_description']; } + if (strlen($label) == 0) { $label = $device_alternate[0]['device_mac_address']; } + echo " \n"; + echo " \n"; + echo " "; + echo " \n"; + echo " \n"; + echo "
$label $v_link_label_delete
\n"; + unset($label); + } + echo $text['description-device_uuid_alternate']."\n"; + echo "\n"; + echo "\n"; } - echo $text['description-device_uuid_alternate']."\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo " ".$text['label-device_vendor']."\n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-device_vendor']."\n"; - echo "\n"; - echo "\n"; + if (permission_exists('device_vendor')) { + echo "\n"; + echo "\n"; + echo " ".$text['label-device_vendor']."\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-device_vendor']."\n"; + echo "\n"; + echo "\n"; + } - echo "\n"; - echo "\n"; - echo " ".$text['label-device_model']."\n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-device_model']."\n"; - echo "\n"; - echo "\n"; + if (permission_exists('device_model')) { + echo "\n"; + echo "\n"; + echo " ".$text['label-device_model']."\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-device_model']."\n"; + echo "\n"; + echo "\n"; + } - echo "\n"; - echo "\n"; - echo " ".$text['label-device_firmware_version']."\n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-device_firmware_version']."\n"; - echo "\n"; - echo "\n"; + if (permission_exists('device_firmware')) { + echo "\n"; + echo "\n"; + echo " ".$text['label-device_firmware_version']."\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-device_firmware_version']."\n"; + echo "\n"; + echo "\n"; + } if (permission_exists('device_domain')) { echo "\n"; @@ -1253,38 +1303,46 @@ require_once "resources/require.php"; echo " \n"; } - echo "\n"; - echo "\n"; - echo " ".$text['label-device_provision_enable']."\n"; - echo "\n"; - echo "\n"; - echo " \n"; + if ($device_provision_enable == "true" || strlen($device_provision_enable) == 0) { + echo " \n"; + } + else { + echo " \n"; + } + if ($device_provision_enable == "false") { + echo " \n"; + } + else { + echo " \n"; + } + echo " \n"; + echo "
\n"; + echo $text['description-device_provision_enable']."\n"; + echo "\n"; + echo "\n"; } - else { - echo " \n"; - } - if ($device_provision_enable == "false") { - echo " \n"; - } - else { - echo " \n"; - } - echo " \n"; - echo "
\n"; - echo $text['description-device_provision_enable']."\n"; - echo "\n"; - echo "\n"; echo "\n"; echo "\n"; echo " ".$text['label-device_description']."\n"; echo "\n"; echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-device_description']."\n"; + if (permission_exists('device_description')) { + echo " \n"; + echo "
\n"; + echo $text['description-device_description']."\n"; + } + else { + echo $device_description."\n"; + } + echo "\n"; echo "\n"; echo " \n"; diff --git a/app/devices/device_profile_edit.php b/app/devices/device_profile_edit.php index 092fa5e6eb..bfe703b584 100644 --- a/app/devices/device_profile_edit.php +++ b/app/devices/device_profile_edit.php @@ -138,7 +138,7 @@ require_once "resources/require.php"; } //write the provision files - if (strlen($_SESSION['switch']['provision']['dir']) > 0) { + if (strlen($_SESSION['provision']['path']['text']) > 0) { require_once "app/provision/provision_write.php"; } @@ -454,6 +454,13 @@ require_once "resources/require.php"; + + + + + + + "; } } diff --git a/app/fax/fax_emails.php b/app/fax/fax_emails.php index 906a7eb013..3c615a8e75 100644 --- a/app/fax/fax_emails.php +++ b/app/fax/fax_emails.php @@ -29,6 +29,7 @@ include "root.php"; require_once "resources/require.php"; require_once "resources/functions/object_to_array.php"; require_once "resources/functions/parse_attachments.php"; +require_once "resources/classes/text.php"; //get accounts to monitor $sql = "select * from v_fax "; diff --git a/app/fax/fax_send.php b/app/fax/fax_send.php index e134e37bbe..315737f933 100644 --- a/app/fax/fax_send.php +++ b/app/fax/fax_send.php @@ -98,21 +98,28 @@ if (!$included) { $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'.((count($_SESSION["domains"]) > 1) ? '/'.$_SESSION['domain_name'] : null); } - -function correct_path($p) { - global $IS_WINDOWS; - if ($IS_WINDOWS) { - return str_replace('/', '\\', $p); - } - return $p; +else { + require_once "resources/classes/EventSocket.php"; } -function gs_cmd($args) { - global $IS_WINDOWS; - if ($IS_WINDOWS) { - return 'gswin32c '.$args; +if(!function_exists('correct_path')) { + function correct_path($p) { + global $IS_WINDOWS; + if ($IS_WINDOWS) { + return str_replace('/', '\\', $p); + } + return $p; + } +} + +if(!function_exists('gs_cmd')) { + function gs_cmd($args) { + global $IS_WINDOWS; + if ($IS_WINDOWS) { + return 'gswin32c '.$args; + } + return 'gs '.$args; } - return 'gs '.$args; } //get the fax extension diff --git a/app/provision/app_defaults.php b/app/provision/app_defaults.php index 942c228efd..7e80fd2e59 100644 --- a/app/provision/app_defaults.php +++ b/app/provision/app_defaults.php @@ -103,6 +103,13 @@ $array[$x]['default_setting_description'] = ''; $x++; $array[$x]['default_setting_category'] = 'provision'; + $array[$x]['default_setting_subcategory'] = 'path'; + $array[$x]['default_setting_name'] = 'text'; + $array[$x]['default_setting_value'] = ''; + $array[$x]['default_setting_enabled'] = 'false'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'provision'; $array[$x]['default_setting_subcategory'] = 'voicemail_number'; $array[$x]['default_setting_name'] = 'text'; $array[$x]['default_setting_value'] = '*97'; diff --git a/app/provision/resources/classes/provision.php b/app/provision/resources/classes/provision.php index d2a4a6f562..66fa4645cb 100644 --- a/app/provision/resources/classes/provision.php +++ b/app/provision/resources/classes/provision.php @@ -822,8 +822,8 @@ include "root.php"; //$file_size = round(filesize($new_path)/1024, 2); //echo $this->template_dir."/".$device_template."/".$file_name." $file_size\n"; //write the configuration to the directory - if (strlen($_SESSION['switch']['provision']['dir']) > 0) { - $dir_array = explode(";", $_SESSION['switch']['provision']['dir']); + if (strlen($provision["path"]) > 0) { + $dir_array = explode(";", $provision["path"]); foreach($dir_array as $directory) { if (file_exists($this->template_dir."/".$device_template."/".$file_name)) { diff --git a/app/time_conditions/app_defaults.php b/app/time_conditions/app_defaults.php index 249ed0f0f5..2fa4411a74 100644 --- a/app/time_conditions/app_defaults.php +++ b/app/time_conditions/app_defaults.php @@ -3,54 +3,68 @@ if ($domains_processed == 1) { //define holiday presets - $preset[] = json_encode(array("new_years_day" => array("mday" => "1", "mon" => "1"))); - $preset[] = json_encode(array("martin_luther_king_jr_day" => array("wday" => "2", "mon" => "1", "mweek" => "3"))); - $preset[] = json_encode(array("presidents_day" => array("wday" => "2", "mon" => "2", "mweek" => "3"))); - $preset[] = json_encode(array("memorial_day" => array("mday" => "25-31", "wday" => "2", "mon" => "5"))); - $preset[] = json_encode(array("independence_day" => array("mday" => "4", "mon" => "7"))); - $preset[] = json_encode(array("labor_day" => array("wday" => "2", "mon" => "9", "mweek" => "1"))); - $preset[] = json_encode(array("columbus_day" => array("wday" => "2", "mon" => "10", "mweek" => "2"))); - $preset[] = json_encode(array("veterans_day" => array("mday" => "11", "mon" => "11"))); - $preset[] = json_encode(array("thanksgiving_day" => array("wday" => "5-6", "mon" => "11", "mweek" => "4"))); - $preset[] = json_encode(array("christmas_day" => array("mday" => "25", "mon" => "12"))); + $preset['usa'][] = json_encode(array("new_years_day" => array("mday" => "1", "mon" => "1"))); + $preset['usa'][] = json_encode(array("martin_luther_king_jr_day" => array("wday" => "2", "mon" => "1", "mweek" => "3"))); + $preset['usa'][] = json_encode(array("presidents_day" => array("wday" => "2", "mon" => "2", "mweek" => "3"))); + $preset['usa'][] = json_encode(array("memorial_day" => array("mday" => "25-31", "wday" => "2", "mon" => "5"))); + $preset['usa'][] = json_encode(array("independence_day" => array("mday" => "4", "mon" => "7"))); + $preset['usa'][] = json_encode(array("labor_day" => array("wday" => "2", "mon" => "9", "mweek" => "1"))); + $preset['usa'][] = json_encode(array("columbus_day" => array("wday" => "2", "mon" => "10", "mweek" => "2"))); + $preset['usa'][] = json_encode(array("veterans_day" => array("mday" => "11", "mon" => "11"))); + $preset['usa'][] = json_encode(array("thanksgiving_day" => array("wday" => "5-6", "mon" => "11", "mweek" => "4"))); + $preset['usa'][] = json_encode(array("christmas_day" => array("mday" => "25", "mon" => "12"))); - //define array of settings - $x = 0; - foreach ($preset as $json) { - $array[$x]['default_setting_category'] = 'time_conditions'; - $array[$x]['default_setting_subcategory'] = 'preset'; - $array[$x]['default_setting_name'] = 'array'; - $array[$x]['default_setting_value'] = $json; - $array[$x]['default_setting_enabled'] = 'true'; - $array[$x]['default_setting_description'] = 'Holiday'; - $x++; - } + $preset['england'][] = json_encode(array("new_years_day" => array("mday" => "1", "mon" => "1"))); + $preset['england'][] = json_encode(array("christmas_day" => array("mday" => "25", "mon" => "12"))); + $preset['england'][] = json_encode(array("boxing_day" => array("mday" => "26", "mon" => "12"))); + $preset['england'][] = json_encode(array("may_day" => array("mon" => "5", "mweek" => "1", "wday" => "2"))); + $preset['england'][] = json_encode(array("spring_bank_holiday" => array("mon" => "5", "mday" => "25-31", "wday" => "2"))); + $preset['england'][] = json_encode(array("august_bank_holiday" => array("mon" => "8", "mday" => "25-31", "wday" => "2"))); - //get an array of the default settings - $sql = "select * from v_default_settings "; + //iterate and migrate old presets first + $sql = "update v_default_settings "; + $sql .= "set default_setting_subcategory = 'preset_usa' "; + $sql .= ", default_setting_description = 'usa Holiday' "; $sql .= "where default_setting_category = 'time_conditions' "; $sql .= "and default_setting_subcategory = 'preset' "; - $sql .= "and default_setting_name = 'array' "; $prep_statement = $db->prepare($sql); - $prep_statement->execute(); - $default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED); - unset ($prep_statement, $sql); - - //find the missing default settings - $x = 0; - foreach ($array as $setting) { - $found = false; - $missing[$x] = $setting; - foreach ($default_settings as $row) { - if (trim($row['default_setting_value']) == trim($setting['default_setting_value'])) { - $found = true; - //remove items from the array that were found - unset($missing[$x]); - } - } - $x++; + if ($prep_statement) { + $prep_statement->execute(); + unset ($prep_statement, $sql); } + //iterate and add each, if necessary + $x = 0; + foreach ($preset as $region => $data) { + $sql = "select * from v_default_settings "; + $sql .= "where default_setting_category = 'time_conditions' "; + $sql .= "and default_setting_subcategory = 'preset_$region' "; + $sql .= "and default_setting_name = 'array' "; + $prep_statement = $db->prepare($sql); + if ($prep_statement) { + $prep_statement->execute(); + $default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED); + unset ($prep_statement, $sql); + foreach ($data as $json) { + $found = false; + $missing[$x]['default_setting_category'] = 'time_conditions'; + $missing[$x]['default_setting_subcategory'] = "preset_$region"; + $missing[$x]['default_setting_name'] = 'array'; + $missing[$x]['default_setting_value'] = $json; + $missing[$x]['default_setting_enabled'] = 'true'; + $missing[$x]['default_setting_description'] = "$region Holiday"; + foreach ($default_settings as $row) { + if (trim($row['default_setting_value']) == trim($json)) { + $found = true; + //remove items from the array that were found + unset($missing[$x]); + } + } + $x++; + } + } + } + //add the missing default settings foreach ($missing as $row) { //add the default settings @@ -63,6 +77,39 @@ if ($domains_processed == 1) { } unset($missing); + $array[$x]['default_setting_category'] = 'time_conditions'; + $array[$x]['default_setting_subcategory'] = 'region'; + $array[$x]['default_setting_name'] = 'text'; + $array[$x]['default_setting_value'] = 'usa'; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = 'What region to use by default when choosing Time Conditions'; + $x++; + + //iterate and add each, if necessary + foreach ($array as $index => $default_settings) { + + //add the default setting + $sql = "select count(*) as num_rows from v_default_settings "; + $sql .= "where default_setting_category = '".$default_settings['default_setting_category']."' "; + $sql .= "and default_setting_subcategory = '".$default_settings['default_setting_subcategory']."' "; + $sql .= "and default_setting_name = '".$default_settings['default_setting_name']."' "; + $prep_statement = $db->prepare($sql); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + unset($prep_statement); + if ($row['num_rows'] == 0) { + $orm = new orm; + $orm->name('default_settings'); + $orm->save($array[$index]); + $message = $orm->message; + //print_r($message); + } + unset($row); + } + + } + //unset the array variable unset($array); } diff --git a/app/time_conditions/time_condition_edit.php b/app/time_conditions/time_condition_edit.php index 1be14bd414..f3e70b9f77 100644 --- a/app/time_conditions/time_condition_edit.php +++ b/app/time_conditions/time_condition_edit.php @@ -44,10 +44,12 @@ require_once "resources/header.php"; $destination = new destinations; //load available presets - foreach ($_SESSION['time_conditions']['preset'] as $json) { + $preset_region = "preset_".$_SESSION['time_conditions']['region']['text']; + foreach ($_SESSION['time_conditions'][$preset_region] as $json) { $available_presets[] = json_decode($json, true); } - + unset($preset_region); + //set the action as an add or an update if (isset($_REQUEST["id"])) { $action = "update"; diff --git a/core/databases/app_defaults.php b/core/databases/app_defaults.php index dbd68274fe..ea4d04d6c9 100644 --- a/core/databases/app_defaults.php +++ b/core/databases/app_defaults.php @@ -131,6 +131,9 @@ if ($domains_processed == 1) { if (strlen($_SESSION['switch']['sounds']['dir']) > 0) { $tmp .= correct_path(" sounds_dir = [[".$_SESSION['switch']['sounds']['dir']."]];\n"); } + if (strlen($_SESSION['switch']['phrases']['dir']) > 0) { + $tmp .= correct_path(" phrases_dir = [[".$_SESSION['switch']['phrases']['dir']."]];\n"); + } if (strlen($_SESSION['switch']['db']['dir']) > 0) { $tmp .= correct_path(" database_dir = [[".$_SESSION['switch']['db']['dir']."]];\n"); } diff --git a/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua b/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua index 81ac0ffd13..628822955c 100644 --- a/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua +++ b/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua @@ -41,6 +41,16 @@ --array count require "resources.functions.count"; + local IS_WINDOWS = (package.config:sub(1,1) == '\\') + + local function quote(s) + local q = IS_WINDOWS and '"' or "'" + if s:find('%s') or s:find(q, nil, true) then + s = q .. s:gsub(q, q..q) .. q + end + return s + end + -- set channel variables to lua variables domain_uuid = env:getHeader("domain_uuid"); domain_name = env:getHeader("domain_name"); @@ -181,23 +191,17 @@ end --fax to email - cmd = "'"..php_dir.."/"..php_bin.."' '"..document_root.."/secure/fax_to_email.php' "; - cmd = cmd .. "email='"..fax_email.."' "; - cmd = cmd .. "extension="..fax_extension.." "; - cmd = cmd .. "name='"..fax_file.."' "; - cmd = cmd .. "messages='result:"..fax_result_text.." sender:"..fax_remote_station_id.." pages:"..fax_document_total_pages.."' "; - cmd = cmd .. "domain="..domain_name.." "; - cmd = cmd .. "caller_id_name='"; - if (caller_id_name ~= nil) then - cmd = cmd .. caller_id_name; - end - cmd = cmd .. "' "; - cmd = cmd .. "caller_id_number="; - if (caller_id_number ~= nil) then - cmd = cmd .. caller_id_number; - end - cmd = cmd .. " "; - if (string.len(fax_forward_number) > 0) then + + -- cmd = "lua" .. " " .. quote(scripts_dir .. "/fax_to_email.lua") .. " "; + cmd = quote(php_dir.."/"..php_bin).." "..quote(document_root.."/secure/fax_to_email.php").." "; + cmd = cmd .. "email="..quote(fax_email).." "; + cmd = cmd .. "extension="..quote(fax_extension).." "; + cmd = cmd .. "name="..quote(fax_file).." "; + cmd = cmd .. "messages=" .. quote("result:"..fax_result_text.." sender:"..fax_remote_station_id.." pages:"..fax_document_total_pages).." "; + cmd = cmd .. "domain="..quote(domain_name).." "; + cmd = cmd .. "caller_id_name=" .. quote(caller_id_name or '') .. " "; + cmd = cmd .. "caller_id_number=" .. quote(caller_id_number or '') .. " "; + if #fax_forward_number > 0 then cmd = cmd .. "fax_relay=true "; end freeswitch.consoleLog("notice", "[fax] command: " .. cmd .. "\n"); diff --git a/resources/install/scripts/app/ring_groups/index.lua b/resources/install/scripts/app/ring_groups/index.lua index 25e07493f7..9f2d3bcb03 100644 --- a/resources/install/scripts/app/ring_groups/index.lua +++ b/resources/install/scripts/app/ring_groups/index.lua @@ -497,7 +497,7 @@ local log = require "resources.functions.log".ring_group end elseif (r.dialplan_detail_type == "bridge") then if (bridge_match) then - dial_string = dial_string .. "|" .. square .."]"..dialplan_detail_data; + dial_string = dial_string .. delimiter .. square .."]"..dialplan_detail_data; square = "["; else dial_string = square .."]"..dialplan_detail_data; diff --git a/resources/install/scripts/app/voicemail/index.lua b/resources/install/scripts/app/voicemail/index.lua index ee9e79e5cd..2cddb544c1 100644 --- a/resources/install/scripts/app/voicemail/index.lua +++ b/resources/install/scripts/app/voicemail/index.lua @@ -78,6 +78,10 @@ if (not vm_disk_quota) then vm_disk_quota = session:getVariable("vm_disk_quota"); end + record_silence_threshold = session:getVariable("record-silence-threshold"); + if (not record_silence_threshold) then + record_silence_threshold = 300; + end voicemail_authorized = session:getVariable("voicemail_authorized"); if (not vm_message_ext) then vm_message_ext = 'wav'; end diff --git a/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua b/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua index da41ef98fb..efa6da0e36 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua @@ -63,11 +63,10 @@ --prepare to record the greeting if (session:ready()) then max_len_seconds = 30; - silence_threshold = 30; silence_seconds = 5; mkdir(voicemail_dir.."/"..voicemail_id); -- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs) - result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".tmp.wav", max_len_seconds, silence_threshold, silence_seconds); + result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".tmp.wav", max_len_seconds, record_silence_threshold, silence_seconds); --session:execute("record", voicemail_dir.."/"..uuid.." 180 200"); end end diff --git a/resources/install/scripts/app/voicemail/resources/functions/record_message.lua b/resources/install/scripts/app/voicemail/resources/functions/record_message.lua index 4b830f5297..397e52c32e 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_message.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_message.lua @@ -143,10 +143,9 @@ --save the recording -- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs) max_len_seconds = 300; - silence_threshold = 30; silence_seconds = 5; if (storage_path == "http_cache") then - result = session:recordFile(storage_path.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, max_len_seconds, silence_threshold, silence_seconds); + result = session:recordFile(storage_path.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, max_len_seconds, record_silence_threshold, silence_seconds); else mkdir(voicemail_dir.."/"..voicemail_id); if (vm_message_ext == "mp3") then @@ -154,10 +153,10 @@ if (shout_exists == "true") then freeswitch.consoleLog("notice", "using mod_shout for mp3 encoding\n"); --record in mp3 directly - result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".mp3", max_len_seconds, silence_threshold, silence_seconds); + result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".mp3", max_len_seconds, record_silence_threshold, silence_seconds); else --create initial wav recording - result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", max_len_seconds, silence_threshold, silence_seconds); + result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", max_len_seconds, record_silence_threshold, silence_seconds); --use lame to encode, if available if (file_exists("/usr/bin/lame")) then freeswitch.consoleLog("notice", "using lame for mp3 encoding\n"); @@ -176,7 +175,7 @@ end end else - result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, max_len_seconds, silence_threshold, silence_seconds); + result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, max_len_seconds, record_silence_threshold, silence_seconds); end end diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua b/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua index c607d699b3..6254bff9de 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua @@ -142,18 +142,9 @@ table.insert(xml, [[ ]]);; end - require "resources.functions.settings"; - settings = settings(domain_uuid); - lang_path = "/usr/local/freeswitch/conf/lang/"; - if (settings['switch']['phrases'] ~= nil) then - if (settings['switch']['phrases']['dir'] ~= nil) then - lang_path = settings['switch']['phrases']['dir']; - end - end - --read root xml language file, parse included xml files local xml_file_paths = {} - local file_handle = io.open(lang_path.."/"..language.."/"..language..".xml", "r"); + local file_handle = io.open(phrases_dir.."/"..language.."/"..language..".xml", "r"); if (file_handle ~= nil) then for file_line in file_handle:lines() do if (string.find(file_line, 'cmd="include" data="', 0, true) ~= nil) then diff --git a/resources/install/scripts/call_forward.lua b/resources/install/scripts/call_forward.lua index 553a883c20..bd1dd11142 100644 --- a/resources/install/scripts/call_forward.lua +++ b/resources/install/scripts/call_forward.lua @@ -28,250 +28,309 @@ max_tries = "3"; digit_timeout = "3000"; ---debug - debug["sql"] = false; - --define the trim function require "resources.functions.trim" ---define the explode function - require "resources.functions.explode" - --create the api object api = freeswitch.API(); --include config.lua require "resources.functions.config"; +--include config.lua + require "resources.functions.settings"; + + require "resources.functions.channel_utils"; + + local log = require "resources.functions.log".call_forward + local cache = require "resources.functions.cache" + local Database = require "resources.functions.database" + + local function opt(t, ...) + if select('#', ...) == 0 then + return t + end + if type(t) ~= 'table' then + return nil + end + return opt(t[...], select(2, ...)) + end + + local function empty(t) + return (not t) or (#t == 0) + end + --check if the session is ready - if (session:ready()) then - --answer the call - session:answer(); + if not session:ready() then return end - --get the variables - enabled = session:getVariable("enabled"); - pin_number = session:getVariable("pin_number"); - sounds_dir = session:getVariable("sounds_dir"); - domain_uuid = session:getVariable("domain_uuid"); - domain_name = session:getVariable("domain_name"); - extension_uuid = session:getVariable("extension_uuid"); - context = session:getVariable("context"); - if (not context ) then context = 'default'; end - request_id = session:getVariable("request_id"); +--answer the call + session:answer(); - --set the sounds path for the language, dialect and voice - default_language = session:getVariable("default_language"); - default_dialect = session:getVariable("default_dialect"); - default_voice = session:getVariable("default_voice"); - if (not default_language) then default_language = 'en'; end - if (not default_dialect) then default_dialect = 'us'; end - if (not default_voice) then default_voice = 'callie'; end +--get the variables + local enabled = session:getVariable("enabled"); + local pin_number = session:getVariable("pin_number"); + local sounds_dir = session:getVariable("sounds_dir"); + local domain_uuid = session:getVariable("domain_uuid"); + local domain_name = session:getVariable("domain_name"); + local extension_uuid = session:getVariable("extension_uuid"); + local request_id = session:getVariable("request_id"); + local extension, dial_string - --a moment to sleep - session:sleep(1000); +--set the sounds path for the language, dialect and voice + local default_language = session:getVariable("default_language") or 'en'; + local default_dialect = session:getVariable("default_dialect") or 'us'; + local default_voice = session:getVariable("default_voice") or 'callie'; - --connect to the database - require "resources.functions.database_handle"; - dbh = database_handle('system'); +--a moment to sleep + session:sleep(1000); - --request id is true - if (request_id == "true") then - --unset extension uuid - extension_uuid = nil; +--connect to the database + dbh = Database.new('system'); - --get the id - if (session:ready()) then - min_digits = 2; - max_digits = 20; - id = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_id:#", "", "\\d+"); - end +--request id is true + if (request_id == "true") then + --unset extension uuid + extension_uuid = nil; - --get the pin number - if (session:ready()) then - min_digits = 3; - max_digits = 20; - caller_pin_number = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+"); - end + --get the extension + if not session:ready() then return end + local min_digits = 2; + local max_digits = 20; + extension = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_id:#", "", "\\d+"); + if empty(extension) then return end - --check to see if the pin number is correct - if (session:ready()) then - sql = "SELECT * FROM v_voicemails "; - sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .."' "; - sql = sql .. "AND voicemail_id = '" .. id .."' "; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[call_forward] "..sql .."\n"); - end - dbh:query(sql, function(row) - voicemail_password = row.voicemail_password; - --freeswitch.consoleLog("notice", "[call_forward] "..voicemail_password .."\n"); - end); - if (voicemail_password ~= caller_pin_number) then - --access denied - session:streamFile("phrase:voicemail_fail_auth:#"); - session:hangup("NORMAL_CLEARING"); - end - end + --get the pin number + if not session:ready() then return end + min_digits = 3; + max_digits = 20; + local caller_pin_number = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+"); + if empty(caller_pin_number) then return end + + --check to see if the pin number is correct + if not session:ready() then return end + local sql = "SELECT voicemail_password FROM v_voicemails "; + sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .."' "; + sql = sql .. "AND voicemail_id = '" .. extension .."' "; + if (debug["sql"]) then + log.notice(sql); + end + local voicemail_password = dbh:first_value(sql) + if (voicemail_password ~= caller_pin_number) then + --access denied + session:streamFile("phrase:voicemail_fail_auth:#"); + return session:hangup("NORMAL_CLEARING"); + end + end + +--determine whether to update the dial string + if not session:ready() then return end + + local sql = "select * from v_extensions "; + sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; + if (extension_uuid ~= nil) then + sql = sql .. "and extension_uuid = '"..extension_uuid.."' "; + else + sql = sql .. "and (extension = '"..extension.."' or number_alias = '"..extension.."') "; + end + if (debug["sql"]) then + log.notice(sql); + end + local row = dbh:first_row(sql) + if not row then return end + + extension_uuid = row.extension_uuid; + extension = row.extension; + local number_alias = row.number_alias or ''; + local accountcode = row.accountcode; + local forward_all_enabled = row.forward_all_enabled; + local forward_all_destination = row.forward_all_destination; + local follow_me_uuid = row.follow_me_uuid; + local toll_allow = row.toll_allow or ''; + local forward_caller_id_uuid = row.forward_caller_id_uuid; + +--toggle enabled + if enabled == "toggle" then + enabled = (forward_all_enabled == "true") and "false" or "true"; + end + + if not session:ready() then return end + +--get the forward destination + if enabled == "true" and empty(forward_all_destination) 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+"); + if empty(forward_all_destination) then return end + end + +--set call forward + if enabled == "true" then + --set forward_all_enabled + forward_all_enabled = "true"; + channel_display(session:get_uuid(), "Activated") + --say the destination number + session:say(forward_all_destination, default_language, "number", "iterated"); + --notify the caller + session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_set.wav"); + end + +--get the caller_id for outbound call + local forward_caller_id = "" + if enabled == "true" and not empty(forward_caller_id_uuid) then + local sql = "select destination_number, destination_description,".. + "destination_caller_id_number, destination_caller_id_name " .. + "from v_destinations where domain_uuid = '" .. domain_uuid .. "' and " .. + "destination_type = 'inbound' and destination_uuid = '" .. forward_caller_id_uuid .. "'"; + local row = dbh:first_row(sql) + if row then + local caller_id_number = row.destination_caller_id_number + if empty(caller_id_number) then + caller_id_number = row.destination_number end - --determine whether to update the dial string - if (session:ready()) then - sql = "select * from v_extensions "; - sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; - if (extension_uuid ~= nil) then - sql = sql .. "and extension_uuid = '"..extension_uuid.."' "; - else - sql = sql .. "and (extension = '"..id.."' or number_alias = '"..id.."') "; - end - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[call_forward] "..sql.."\n"); - end - status = dbh:query(sql, function(row) - extension_uuid = row.extension_uuid; - extension = row.extension; - number_alias = row.number_alias or ''; - accountcode = row.accountcode; - 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); + local caller_id_name = row.destination_caller_id_name + if empty(caller_id_name) then + caller_id_name = row.destination_description end - --toggle enabled - if (session:ready() and enabled == "toggle") then - if (forward_all_enabled == "true") then - enabled = "false"; - else - enabled = "true"; - end + if not empty(caller_id_number) then + forward_caller_id = forward_caller_id .. + ",outbound_caller_id_number=" .. caller_id_number .. + ",origination_caller_id_number=" .. caller_id_number end - --get the forward destination - 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 + if not empty(caller_id_name) then + forward_caller_id = forward_caller_id .. + ",outbound_caller_id_name=" .. caller_id_name .. + ",origination_caller_id_name=" .. caller_id_name end + end + end - --set the dial string - if (session:ready() and enabled == "true") then - --used for number_alias to get the correct user - sql = "select * from v_extensions "; - sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; - sql = sql .. "and number_alias = '"..forward_all_destination.."' "; - status = dbh:query(sql, function(row) - destination_user = row.extension; - end); +--set the dial string + if enabled == "true" then + local destination_extension, destination_number_alias - --set the dial_string - dial_string = "{presence_id="..forward_all_destination.."@"..domain_name; - dial_string = dial_string .. ",instant_ringback=true"; - dial_string = dial_string .. ",domain_uuid="..domain_uuid; - 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 - dial_string = dial_string .. "}"; + --used for number_alias to get the correct user + local sql = "select extension, number_alias from v_extensions "; + sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; + sql = sql .. "and number_alias = '"..forward_all_destination.."' "; + dbh:query(sql, function(row) + destination_user = row.extension; + destination_extension = row.extension; + destination_number_alias = row.number_alias or ''; + end); - if (destination_user ~= nil) then - cmd = "user_exists id ".. destination_user .." "..domain_name; - else - cmd = "user_exists id ".. forward_all_destination .." "..domain_name; - end - user_exists = trim(api:executeString(cmd)); - if (user_exists == "true") then - if (destination_user ~= nil) then - dial_string = dial_string .. "user/"..destination_user.."@"..domain_name; - else - dial_string = dial_string .. "user/"..forward_all_destination.."@"..domain_name; - end - else - dial_string = dial_string .. "loopback/"..forward_all_destination; - end - end - - --set call forward - if (session:ready() and enabled == "true") then - --set forward_all_enabled - forward_all_enabled = "true"; - --say the destination number - session:say(forward_all_destination, default_language, "number", "iterated"); - --notify the caller - session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_set.wav"); - end - - --unset call forward - if (session:ready() and enabled == "false") then - --set forward_all_enabled - forward_all_enabled = "false"; - --notify the caller - session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_cancelled.wav"); - end - - --disable the follow me - if (session:ready() and enabled == "true" and follow_me_uuid ~= nil) then - if (string.len(follow_me_uuid) > 0) then - sql = "update v_follow_me set "; - sql = sql .. "follow_me_enabled = 'false' "; - sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; - sql = sql .. "and follow_me_uuid = '"..follow_me_uuid.."' "; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[call_forward] "..sql.."\n"); - end - dbh:query(sql); - end - end - - --check the destination - if (forward_all_destination == nil) then - enabled = false; - forward_all_enabled = "false"; + local presence_id + if destination_extension then + if (#destination_number_alias > 0) and (opt(settings(domain_uuid), 'provision', 'number_as_presence_id', 'boolean') == 'true') then + presence_id = destination_number_alias else - if (string.len(forward_all_destination) == 0) then - enabled = false; - forward_all_enabled = "false"; - end + presence_id = destination_extension end - - --update the extension - if (session:ready()) then - sql = "update v_extensions set "; - if (enabled == "true") then - sql = sql .. "forward_all_destination = '"..forward_all_destination.."', "; - sql = sql .. "dial_string = '"..dial_string:gsub("'", "''").."', "; - sql = sql .. "do_not_disturb = 'false', "; - else - sql = sql .. "forward_all_destination = null, "; - sql = sql .. "dial_string = null, "; - end - sql = sql .. "forward_all_enabled = '"..forward_all_enabled.."' "; - sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; - sql = sql .. "and extension_uuid = '"..extension_uuid.."' "; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[call_forward] "..sql.."\n"); - end - dbh:query(sql); - - --clear the cache - if (extension ~= nil) then - api:execute("memcache", "delete directory:"..extension.."@"..domain_name); - if #number_alias > 0 then - api:execute("memcache", "delete directory:"..number_alias.."@"..domain_name); - end - end + elseif extension then + -- setting here presence_id equal extension not dialed number allows work BLF and intercept. + -- $presence_id = extension_presence_id($this->extension, $this->number_alias); + if (#number_alias > 0) and (opt(settings(domain_uuid), 'provision', 'number_as_presence_id', 'boolean') == 'true') then + presence_id = number_alias + else + presence_id = extension end + else + presence_id = forward_all_destination + end - -- hangup - if (session:ready()) then - --wait for the file to be written before proceeding - session:sleep(100); + --set the dial_string + dial_string = "{presence_id="..presence_id.."@"..domain_name; + dial_string = dial_string .. ",instant_ringback=true"; + dial_string = dial_string .. ",domain_uuid="..domain_uuid; + 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 + dial_string = dial_string .. forward_caller_id + dial_string = dial_string .. "}"; - --end the call - session:hangup(); + if (destination_user ~= nil) then + cmd = "user_exists id ".. destination_user .." "..domain_name; + else + cmd = "user_exists id ".. forward_all_destination .." "..domain_name; + end + user_exists = trim(api:executeString(cmd)); + if (user_exists == "true") then + if (destination_user ~= nil) then + dial_string = dial_string .. "user/"..destination_user.."@"..domain_name; + else + dial_string = dial_string .. "user/"..forward_all_destination.."@"..domain_name; end - end \ No newline at end of file + else + dial_string = dial_string .. "loopback/"..forward_all_destination; + end + end + +--unset call forward + if session:ready() and enabled == "false" then + --set forward_all_enabled + forward_all_enabled = "false"; + channel_display(session:get_uuid(), "Cancelled") + --notify the caller + session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_cancelled.wav"); + end + +--disable the follow me + if enabled == "true" and not empty(follow_me_uuid) then + local sql = "update v_follow_me set "; + sql = sql .. "follow_me_enabled = 'false' "; + sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; + sql = sql .. "and follow_me_uuid = '"..follow_me_uuid.."' "; + if (debug["sql"]) then + log.notice(sql); + end + dbh:query(sql); + end + +--check the destination + if empty(forward_all_destination) then + enabled = "false"; + forward_all_enabled = "false"; + end + +--update the extension + do + local sql = "update v_extensions set "; + if (enabled == "true") then + sql = sql .. "forward_all_destination = '"..forward_all_destination.."', "; + sql = sql .. "dial_string = '"..dial_string:gsub("'", "''").."', "; + sql = sql .. "do_not_disturb = 'false', "; + else + sql = sql .. "forward_all_destination = null, "; + sql = sql .. "dial_string = null, "; + end + sql = sql .. "forward_all_enabled = '"..forward_all_enabled.."' "; + sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; + sql = sql .. "and extension_uuid = '"..extension_uuid.."' "; + if (debug["sql"]) then + log.notice(sql); + end + dbh:query(sql); + end + +--disconnect from database + dbh:release() + +--clear the cache + if extension and #extension > 0 and cache.support() then + cache.del("directory:"..extension.."@"..domain_name); + if #number_alias > 0 then + cache.del("directory:"..number_alias.."@"..domain_name); + end + end + +--hangup + if (session:ready()) then + --wait for the file to be written before proceeding + session:sleep(100); + --end the call + session:hangup(); + end diff --git a/resources/install/scripts/follow_me.lua b/resources/install/scripts/follow_me.lua index 5dce059ae0..ee1a267672 100644 --- a/resources/install/scripts/follow_me.lua +++ b/resources/install/scripts/follow_me.lua @@ -22,158 +22,140 @@ -- Contributor(s): -- Mark J Crane ---set default variables - min_digits = "1"; - max_digits = "11"; - max_tries = "3"; - digit_timeout = "3000"; - ---debug - debug["sql"] = true; - ---define the trim function - require "resources.functions.trim"; - ---define the explode function - require "resources.functions.explode"; +--include config.lua + require "resources.functions.config"; --create the api object api = freeswitch.API(); ---include config.lua - require "resources.functions.config"; + require "resources.functions.channel_utils"; + local log = require "resources.functions.log".follow_me + local cache = require "resources.functions.cache" + local Database = require "resources.functions.database" --check if the session is ready - if ( session:ready() ) then - --answer the call - session:answer(); - - --get the variables - pin_number = session:getVariable("pin_number"); - sounds_dir = session:getVariable("sounds_dir"); - domain_uuid = session:getVariable("domain_uuid"); - domain_name = session:getVariable("domain_name"); - extension_uuid = session:getVariable("extension_uuid"); - context = session:getVariable("context"); - if (not context ) then context = 'default'; end - - --set the sounds path for the language, dialect and voice - default_language = session:getVariable("default_language"); - default_dialect = session:getVariable("default_dialect"); - default_voice = session:getVariable("default_voice"); - if (not default_language) then default_language = 'en'; end - if (not default_dialect) then default_dialect = 'us'; end - if (not default_voice) then default_voice = 'callie'; end - - --a moment to sleep - session:sleep(1000); - - --connect to the database - require "resources.functions.database_handle"; - dbh = database_handle('system'); - - --determine whether to update the dial string - sql = "select * from v_extensions "; - sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; - sql = sql .. "and extension_uuid = '"..extension_uuid.."' "; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[follow_me] "..sql.."\n"); - end - status = dbh:query(sql, function(row) - extension = row.extension; - number_alias = row.number_alias or ''; - accountcode = row.accountcode; - follow_me_uuid = row.follow_me_uuid; - --freeswitch.consoleLog("NOTICE", "[call forward] extension "..row.extension.."\n"); - --freeswitch.consoleLog("NOTICE", "[call forward] accountcode "..row.accountcode.."\n"); - end); + if not session:ready() then return end - --determine whether to update the dial string - enabled = "false"; - sql = "select * from v_follow_me "; - sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; - sql = sql .. "and follow_me_uuid = '"..follow_me_uuid.."' "; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[follow_me] "..sql.."\n"); - end - status = dbh:query(sql, function(row) - enabled = row.follow_me_enabled; - call_prompt = row.call_prompt; - cid_name_prefix = row.cid_name_prefix; - cid_number_prefix = row.cid_number_prefix; - dial_string = row.dial_string; - end); - - --set follow me - if (enabled == "false") then - --answer and play a tone - session:answer(); - api = freeswitch.API(); - reply = api:executeString("uuid_display "..session:get_uuid().." Activated "); +--answer the call + session:answer(); - session:execute("sleep", "2000"); - session:execute("playback", "tone_stream://%(200,0,500,600,700)"); - --notify the caller - --session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_set.wav"); - end - - --unset follow me - if (enabled == "true") then - --answer and play a tone - session:answer(); - api = freeswitch.API(); - reply = api:executeString("uuid_display "..session:get_uuid().." Cancelled "); +--get the variables + local domain_uuid = session:getVariable("domain_uuid"); + local domain_name = session:getVariable("domain_name"); + local extension_uuid = session:getVariable("extension_uuid"); - session:execute("sleep", "2000"); - session:execute("playback", "tone_stream://%(500,0,300,200,100,50,25)"); - --notify the caller - --session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_cancelled.wav"); - end +--set the sounds path for the language, dialect and voice + local sounds_dir = session:getVariable("sounds_dir"); + local default_language = session:getVariable("default_language") or 'en'; + local default_dialect = session:getVariable("default_dialect") or 'us'; + local default_voice = session:getVariable("default_voice") or 'callie'; - --enable or disable follow me - if (follow_me_uuid ~= nil) then - sql = "update v_follow_me set "; - if (enabled == "true") then - sql = sql .. "follow_me_enabled = 'false' "; - else - sql = sql .. "follow_me_enabled = 'true' "; - end - sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; - sql = sql .. "and follow_me_uuid = '"..follow_me_uuid.."' "; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[follow_me] "..sql.."\n"); - end - dbh:query(sql); - end - - --update the extension - sql = "update v_extensions set "; - if (enabled == "true") then - sql = sql .. "dial_string = null, "; - else - sql = sql .. "dial_string = '"..dial_string.."', "; - end - sql = sql .. "do_not_disturb = 'false', "; - sql = sql .. "forward_all_enabled= 'false' "; - sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; - sql = sql .. "and extension_uuid = '"..extension_uuid.."' "; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[follow_me] "..sql.."\n"); - end - dbh:query(sql); - - --clear the cache - if (extension ~= nil) then - api:execute("memcache", "delete directory:"..extension.."@"..domain_name); - if #number_alias > 0 then - api:execute("memcache", "delete directory:"..number_alias.."@"..domain_name); - end - end - - --wait for the file to be written before proceeding - session:sleep(1000); - - --end the call - session:hangup(); - +--a moment to sleep + session:sleep(1000); + +--check if the session is ready + if not session:ready() then return end + +--connect to the database + local dbh = Database.new('system'); + +--determine whether to update the dial string + local sql = "select extension, number_alias, accountcode, follow_me_uuid "; + sql = sql .. "from v_extensions "; + sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; + sql = sql .. "and extension_uuid = '"..extension_uuid.."' "; + if (debug["sql"]) then + log.notice(sql); end + + local row = dbh:first_row(sql) + if not row then return end + + local extension = row.extension; + local number_alias = row.number_alias or ''; + local accountcode = row.accountcode; + local follow_me_uuid = row.follow_me_uuid; + +--determine whether to update the dial string + sql = "select follow_me_enabled, call_prompt, cid_name_prefix, cid_number_prefix, dial_string " + sql = sql .. "from v_follow_me "; + sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; + sql = sql .. "and follow_me_uuid = '"..follow_me_uuid.."' "; + if (debug["sql"]) then + log.notice(sql); + end + + row = dbh:first_row(sql) + if not row then return end + + local enabled = row.follow_me_enabled; + local call_prompt = row.call_prompt; + local cid_name_prefix = row.cid_name_prefix; + local cid_number_prefix = row.cid_number_prefix; + local dial_string = row.dial_string; + +--set follow me + if (enabled == "false") then + --play a tone + channel_display(session:get_uuid(), "Activated") + + session:execute("sleep", "2000"); + session:execute("playback", "tone_stream://%(200,0,500,600,700)"); + --notify the caller + --session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_set.wav"); + end + +--unset follow me + if (enabled == "true") then + --play a tone + channel_display(session:get_uuid(), "Cancelled") + + session:execute("sleep", "2000"); + session:execute("playback", "tone_stream://%(500,0,300,200,100,50,25)"); + --notify the caller + --session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_cancelled.wav"); + end + +--enable or disable follow me + sql = "update v_follow_me set "; + if (enabled == "true") then + sql = sql .. "follow_me_enabled = 'false' "; + else + sql = sql .. "follow_me_enabled = 'true' "; + end + sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; + sql = sql .. "and follow_me_uuid = '"..follow_me_uuid.."' "; + if (debug["sql"]) then + log.notice(sql); + end + dbh:query(sql); + +--update the extension + sql = "update v_extensions set "; + if (enabled == "true") then + sql = sql .. "dial_string = null, "; + else + sql = sql .. "dial_string = '"..dial_string:gsub("'", "''").."', "; + end + sql = sql .. "do_not_disturb = 'false', "; + sql = sql .. "forward_all_enabled= 'false' "; + sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; + sql = sql .. "and extension_uuid = '"..extension_uuid.."' "; + if (debug["sql"]) then + log.notice(sql); + end + dbh:query(sql); + +--clear the cache + if (extension ~= nil) and cache.support() then + cache.del("directory:"..extension.."@"..domain_name); + if #number_alias > 0 then + cache.del("directory:"..number_alias.."@"..domain_name); + end + end + +--wait for the file to be written before proceeding + session:sleep(1000); + +--end the call + session:hangup(); diff --git a/resources/install/scripts/intercept.lua b/resources/install/scripts/intercept.lua index a7a6695731..326d93b985 100644 --- a/resources/install/scripts/intercept.lua +++ b/resources/install/scripts/intercept.lua @@ -24,9 +24,10 @@ -- Errol W Samuels --user defined variables - max_tries = "3"; - digit_timeout = "5000"; - extension = argv[1]; + local extension = argv[1]; + +-- we can use any number because other box should check sip_h_X_*** headers first + local pickup_number = '*8' -- extension and '**' or '*8' --set the debug options debug["sql"] = false; @@ -34,139 +35,298 @@ --include config.lua require "resources.functions.config"; ---connect to the database - if (file_exists(database_dir.."/core.db")) then - --dbh = freeswitch.Dbh("core:core"); -- when using sqlite - dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); - else - require "resources.functions.database_handle"; - dbh = database_handle('switch'); - end +--add the function + require "resources.functions.explode"; + require "resources.functions.trim"; + require "resources.functions.channel_utils"; --prepare the api object api = freeswitch.API(); ---add the function - require "resources.functions.trim"; - require "resources.functions.channel_utils"; +--Get intercept logger + local log = require "resources.functions.log".intercept ---exits the script if we didn't connect properly - assert(dbh:connected()); - -if ( session:ready() ) then - --answer the session - session:answer(); - - --get session variables - pin_number = session:getVariable("pin_number"); - sounds_dir = session:getVariable("sounds_dir"); - domain_uuid = session:getVariable("domain_uuid"); - domain_name = session:getVariable("domain_name"); - context = session:getVariable("context"); - sofia_profile_name = session:getVariable("sofia_profile_name"); - - --set the sounds path for the language, dialect and voice - default_language = session:getVariable("default_language"); - default_dialect = session:getVariable("default_dialect"); - default_voice = session:getVariable("default_voice"); - if (not default_language) then default_language = 'en'; end - if (not default_dialect) then default_dialect = 'us'; end - if (not default_voice) then default_voice = 'callie'; end - - --set defaults - if (digit_min_length) then - --do nothing - else - digit_min_length = "2"; - end - - if (digit_max_length) then - --do nothing - else - digit_max_length = "11"; - end - - --if the pin number is provided then require it - if (pin_number) then - --sleep - session:sleep(500); - --get the user pin number - min_digits = 2; - max_digits = 20; - digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+"); - --validate the user pin number - pin_number_table = explode(",",pin_number); - for index,pin_number in pairs(pin_number_table) do - if (digits == pin_number) then - --set the variable to true - auth = true; - --set the authorized pin number that was used - session:setVariable("pin_number", pin_number); - --end the loop - break; - end - end - --if not authorized play a message and then hangup - if (not auth) then - session:streamFile("phrase:voicemail_fail_auth:#"); - session:hangup("NORMAL_CLEARING"); - return; - end - end - - --predefined variables - uuid = ''; - call_hostname = ''; - callee_num = ''; - - --check the database to get the uuid of a ringing call - sql = "select uuid, call_uuid, hostname, callee_num, ip_addr from channels "; - sql = sql .. "where callstate in ('RINGING', 'EARLY') "; - --sql = sql .. "AND direction = 'outbound' "; - if (extension) then - sql = sql .. "and presence_id = '"..extension.."@"..domain_name.."' "; - else - if (domain_count > 1) then - sql = sql .. "and context = '"..context.."' "; - end - end - if (debug["sql"]) then - freeswitch.consoleLog("NOTICE", "sql "..sql.."\n"); - end - dbh:query(sql, function(result) - --for key, val in pairs(result) do - -- freeswitch.consoleLog("NOTICE", "result "..key.." "..val.."\n"); - --end - if result.uuid == result.call_uuid then - uuid = channel_variable(result.uuid, 'ent_originate_aleg_uuid') or - channel_variable(result.uuid, 'cc_member_session_uuid') or - channel_variable(result.uuid, 'fifo_bridge_uuid') or - result.uuid - else - uuid = result.call_uuid; - end - call_hostname = result.hostname; - callee_num = result.callee_num; - end); -end +--include database class + local Database = require "resources.functions.database" --get the hostname - hostname = trim(api:execute("hostname", "")); - freeswitch.consoleLog("NOTICE", "Hostname:"..hostname.." Call Hostname:"..call_hostname.."\n"); + local hostname = trim(api:execute("switchname", "")); + +-- redirect call to another box + local function make_proxy_call(destination, call_hostname) + destination = destination .. "@" .. domain_name + local profile, proxy = "internal", call_hostname; + + local sip_auth_username = session:getVariable("sip_auth_username"); + local sip_auth_password = api:execute("user_data", sip_auth_username .. "@" .. domain_name .." param password"); + local auth = "sip_auth_username="..sip_auth_username..",sip_auth_password='"..sip_auth_password.."'" + dial_string = "{sip_invite_domain=" .. domain_name .. "," .. auth .. "}sofia/" .. profile .. "/" .. destination .. ";fs_path=sip:" .. proxy; + log.notice("Send call to other host...."); + session:execute("bridge", dial_string); + end + +-- check pin number if defined + local function pin(pin_number) + if not pin_number then + return true + end + + --sleep + session:sleep(500); + --get the user pin number + local min_digits = 2; + local max_digits = 20; + local max_tries = "3"; + local digit_timeout = "5000"; + local digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+"); + + --validate the user pin number + local pin_number_table = explode(",",pin_number); + for index,pin_number in pairs(pin_number_table) do + if (digits == pin_number) then + --set the authorized pin number that was used + session:setVariable("pin_number", pin_number); + --done + return true; + end + end + + --if not authorized play a message and then hangup + session:streamFile("phrase:voicemail_fail_auth:#"); + session:hangup("NORMAL_CLEARING"); + return; + end + +-- do intercept if we get redirected request from another box + local function proxy_intercept() + -- Proceed calls from other boxes + + -- Check if this call from other box with setted intercept_uuid + local intercept_uuid = session:getVariable("sip_h_X-intercept_uuid") + + if intercept_uuid and #intercept_uuid > 0 then + log.notice("Get intercept_uuid from sip header. Do intercept....") + session:execute("intercept", intercept_uuid) + return true + end + + -- Check if this call from other box and we need parent uuid for channel + local child_intercept_uuid = session:getVariable("sip_h_X-child_intercept_uuid") + if (not child_intercept_uuid) or (#child_intercept_uuid == 0) then + return + end + + -- search parent uuid + log.notice("Get child_intercept_uuid from sip header.") + local parent_uuid = + channel_variable(child_intercept_uuid, 'ent_originate_aleg_uuid') or + channel_variable(child_intercept_uuid, 'cc_member_session_uuid') or + channel_variable(child_intercept_uuid, 'fifo_bridge_uuid') or + child_intercept_uuid + + if parent_uuid == child_intercept_uuid then + log.notice("Can not found parent call. Try intercept child.") + session:execute("intercept", child_intercept_uuid) + return true + end + + -- search parent hostname + call_hostname = hostname + --[[ parent and child have to be on same box so we do not search it + log.notice("Found parent channel try detect parent hostname") + local dbh = Database.new('switch') + local sql = "SELECT hostname FROM channels WHERE uuid='" .. parent_uuid .. "'" + local call_hostname = dbh:first_value(sql) + dbh:release() + + if not call_hostname then + log.notice("Can not find host name. Channels is dead?") + return true + end + --]] + + if hostname == call_hostname then + log.notice("Found parent call on local machine. Do intercept....") + session:execute("intercept", parent_uuid); + return true + end + + log.noticef("Found parent call on remote machine `%s`.", call_hostname) + session:execute("export", "sip_h_X-intercept_uuid="..parent_uuid); + make_proxy_call(pickup_number, call_hostname) + return true + end + +-- return array of extensions for group + local function select_group_extensions() + -- connect to Fusion database + local dbh = Database.new('system'); + + --get the call groups the extension is a member of + local sql = "SELECT call_group FROM v_extensions "; + sql = sql .. "WHERE domain_uuid = '"..domain_uuid.."' "; + sql = sql .. "AND (extension = '"..caller_id_number.."'"; + sql = sql .. "OR number_alias = '"..caller_id_number.."')"; + sql = sql .. "limit 1"; + local call_group = dbh:first_value(sql) or '' + log.noticef("call_group: `%s`", call_group); + call_groups = explode(",", call_group); + + --get the extensions in the call groups + sql = "SELECT extension, number_alias FROM v_extensions "; + sql = sql .. "WHERE domain_uuid = '"..domain_uuid.."' "; + sql = sql .. "AND ("; + for key,call_group in ipairs(call_groups) do + if (key > 1) then + sql = sql .. "OR "; + end + if (#call_group > 0) then + sql = sql .. "call_group like '%"..call_group.."%' "; + else + sql = sql .. "call_group = '' "; + end + end + sql = sql .. ") "; + if (debug["sql"]) then + log.notice("sql "..sql); + end + local extensions = {} + dbh:query(sql, function(row) + local member = row.extension + if row.number_alias and #row.number_alias > 0 then + member = row.number_alias + end + extensions[#extensions+1] = member + log.noticef("member `%s`", member) + end); + + -- release Fusion database + dbh:release() + + -- return result + return extensions + end + +--check if the session is ready + if ( session:ready() ) then + --answer the session + session:answer(); + --get session variables + domain_uuid = session:getVariable("domain_uuid"); + domain_name = session:getVariable("domain_name"); + pin_number = session:getVariable("pin_number"); + context = session:getVariable("context"); + caller_id_number = session:getVariable("caller_id_number"); + end + +--check if the session is ready + if ( session:ready() ) then + if proxy_intercept() then + return + end + end + +--check if the session is ready + if ( session:ready() ) then + --if the pin number is provided then require it + if not pin(pin_number) then + return + end + end + + if ( session:ready() ) then + -- select intercept mode + if not extension then + log.notice("GROUP INTERCEPT") + extensions = select_group_extensions() + else + log.noticef("INTERCEPT %s", extension) + extensions = {extension} + end + + --connect to FS database + local dbh = Database.new('switch') + + --check the database to get the uuid of a ringing call + call_hostname = ""; + sql = "SELECT uuid, call_uuid, hostname FROM channels "; + sql = sql .. "WHERE callstate in ('RINGING', 'EARLY') "; + -- next check should prevent pickup call from extension + -- e.g. if extension 100 dial some cell phone and some one else dial *8 + -- he can pickup this call. + if not extension then + sql = sql .. "AND direction = 'outbound' "; + end + sql = sql .. "AND (1<>1 "; + for key,extension in pairs(extensions) do + sql = sql .. "OR presence_id = '"..extension.."@"..domain_name.."' "; + end + sql = sql .. ") "; + sql = sql .. "and call_uuid is not null "; + sql = sql .. "limit 1 "; + if (debug["sql"]) then + log.notice("sql "..sql); + end + local is_child + dbh:query(sql, function(row) + -- for key, val in pairs(row) do + -- log.notice("row "..key.." "..val); + -- end + -- log.notice("-----------------------"); + is_child = (row.uuid == row.call_uuid) + uuid = row.call_uuid; + call_hostname = row.hostname; + end); + + if is_child then + -- we need intercept `parent` call e.g. call in FIFO/CallCenter Queue + if (call_hostname == hostname) then + log.notice("Found child call on local machine. Try find parent channel.") + local parent_uuid = + channel_variable(uuid, 'ent_originate_aleg_uuid') or + channel_variable(uuid, 'cc_member_session_uuid') or + channel_variable(uuid, 'fifo_bridge_uuid') or + uuid + + --[[ parent and child have to be on same box so we do not search it + if parent_uuid ~= uuid then + local sql = "SELECT hostname FROM channels WHERE uuid='" .. uuid .. "'" + call_hostname = dbh:first_value(sql) + end + --]] + + if call_hostname then + uuid = parent_uuid + if call_hostname ~= hostname then + log.noticef("Found parent call on remote machine `%s`.", call_hostname) + else + log.notice("Found parent call on local machine.") + end + end + + else + log.noticef("Found child call on remote machine `%s`.", call_hostname) + -- we can not find parent on this box because channel on other box so we have to + -- forward call to this box + session:execute("export", "sip_h_X-child_intercept_uuid="..uuid); + return make_proxy_call(pickup_number, call_hostname) + end + end + + --release FS database + dbh:release() + end + + log.noticef( "Hostname: %s Call Hostname: %s", hostname, call_hostname); --intercept a call that is ringing - if (uuid) then + if (uuid ~= nil) then if (session:getVariable("billmsec") == nil) then if (hostname == call_hostname) then session:execute("intercept", uuid); else session:execute("export", "sip_h_X-intercept_uuid="..uuid); - session:execute("export", "sip_h_X-domain_uuid="..domain_uuid); - session:execute("export", "sip_h_X-domain_name="..domain_name); - session:execute("export", "sip_h_X-callee_num="..callee_num); - port = freeswitch.getGlobalVariable(sofia_profile_name.."_sip_port"); - session:execute("bridge", "sofia/"..sofia_profile_name.."/**@"..call_hostname..":"..port); - freeswitch.consoleLog("NOTICE", "Send call to other host.... \n"); + make_proxy_call(pickup_number, call_hostname) end end end diff --git a/resources/install/scripts/intercept_group.lua b/resources/install/scripts/intercept_group.lua index bfc82f5a18..db4db46d05 100644 --- a/resources/install/scripts/intercept_group.lua +++ b/resources/install/scripts/intercept_group.lua @@ -14,223 +14,5 @@ -- -- The Original Code is FusionPBX -- --- The Initial Developer of the Original Code is --- Mark J Crane --- Copyright (C) 2010 - 2014 --- the Initial Developer. All Rights Reserved. --- --- Contributor(s): --- Mark J Crane ---user defined variables - max_tries = "3"; - digit_timeout = "5000"; - extension = argv[1]; - ---set the debug options - debug["sql"] = false; - ---include config.lua - require "resources.functions.config"; - ---add the function - require "resources.functions.explode"; - require "resources.functions.trim"; - require "resources.functions.channel_utils"; - ---prepare the api object - api = freeswitch.API(); - ---connect to the database - require "resources.functions.database_handle"; - dbh = database_handle('system'); - ---get the hostname - hostname = trim(api:execute("switchname", "")); - ---check if the session is ready - if ( session:ready() ) then - --answer the session - session:answer(); - - --get session variables - domain_uuid = session:getVariable("domain_uuid"); - domain_name = session:getVariable("domain_name"); - pin_number = session:getVariable("pin_number"); - sounds_dir = session:getVariable("sounds_dir"); - context = session:getVariable("context"); - caller_id_number = session:getVariable("caller_id_number"); - sofia_profile_name = session:getVariable("sofia_profile_name"); - - --set the sounds path for the language, dialect and voice - default_language = session:getVariable("default_language"); - default_dialect = session:getVariable("default_dialect"); - default_voice = session:getVariable("default_voice"); - if (not default_language) then default_language = 'en'; end - if (not default_dialect) then default_dialect = 'us'; end - if (not default_voice) then default_voice = 'callie'; end - - --set defaults - if (digit_min_length) then - --do nothing - else - digit_min_length = "2"; - end - - if (digit_max_length) then - --do nothing - else - digit_max_length = "11"; - end - - --if the pin number is provided then require it - if (pin_number) then - --sleep - session:sleep(500); - --get the user pin number - min_digits = 2; - max_digits = 20; - digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+"); - --validate the user pin number - pin_number_table = explode(",",pin_number); - for index,pin_number in pairs(pin_number_table) do - if (digits == pin_number) then - --set the variable to true - auth = true; - --set the authorized pin number that was used - session:setVariable("pin_number", pin_number); - --end the loop - break; - end - end - --if not authorized play a message and then hangup - if (not auth) then - session:streamFile("phrase:voicemail_fail_auth:#"); - session:hangup("NORMAL_CLEARING"); - return; - end - end - - --get the call groups the extension is a member of - sql = "SELECT call_group FROM v_extensions "; - sql = sql .. "WHERE domain_uuid = '"..domain_uuid.."' "; - sql = sql .. "AND (extension = '"..caller_id_number.."'"; - sql = sql .. "OR number_alias = '"..caller_id_number.."')"; - status = dbh:query(sql, function(row) - call_group = row.call_group; - freeswitch.consoleLog("NOTICE", "[intercept_group] call_group: "..call_group.."\n"); - end); - call_groups = explode(",", call_group); - - --get the extensions in the call groups - sql = "SELECT extension, number_alias FROM v_extensions "; - sql = sql .. "WHERE domain_uuid = '"..domain_uuid.."' "; - sql = sql .. "AND ("; - x = 0; - for key,call_group in pairs(call_groups) do - if (x == 0) then - if (string.len(call_group) > 0) then - sql = sql .. "call_group like '%"..call_group.."%' "; - else - sql = sql .. "call_group = '' "; - end - else - if (string.len(call_group) > 0) then - sql = sql .. "OR call_group like '%"..call_group.."%' "; - end - end - x = x + 1; - end - x = 0; - sql = sql .. ") "; - if (debug["sql"]) then - freeswitch.consoleLog("NOTICE", "[intercept_group] sql "..sql.."\n"); - end - extensions = {} - status = dbh:query(sql, function(row) - local member = row.extension - if row.number_alias and #row.number_alias > 0 then - member = row.number_alias - end - extensions[x] = member - freeswitch.consoleLog("NOTICE", "[intercept_group] member "..extensions[x].."\n"); - x = x + 1; - end); - - --connect to the database - if (file_exists(database_dir.."/core.db")) then - --dbh = freeswitch.Dbh("core:core"); -- when using sqlite - dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); - else - require "resources.functions.database_handle"; - dbh = database_handle('switch'); - end - - --exits the script if we didn't connect properly - assert(dbh:connected()); - - --check the database to get the uuid of a ringing call - call_hostname = ""; - sql = "SELECT uuid, call_uuid, hostname, ip_addr FROM channels "; - sql = sql .. "WHERE callstate in ('RINGING', 'EARLY') "; - --sql = sql .. "AND direction = 'outbound' "; - sql = sql .. "AND ("; - x = 0; - for key,extension in pairs(extensions) do - if (x == 0) then - sql = sql .. " presence_id = '"..extension.."@"..domain_name.."' "; - else - sql = sql .. "OR presence_id = '"..extension.."@"..domain_name.."' "; - end - x = x + 1; - end - sql = sql .. ") "; - sql = sql .. "and call_uuid is not null "; - sql = sql .. "and direction = 'outbound' "; - --if (domain_count > 1) then - -- sql = sql .. "and context = '"..context.."' "; - --end - sql = sql .. "limit 1 "; - if (debug["sql"]) then - freeswitch.consoleLog("NOTICE", "[intercept_group] sql "..sql.."\n"); - end - dbh:query(sql, function(row) - --for key, val in pairs(row) do - -- freeswitch.consoleLog("NOTICE", "row "..key.." "..val.."\n"); - --end - if row.uuid == row.call_uuid then - uuid = channel_variable(row.uuid, 'ent_originate_aleg_uuid') or - channel_variable(row.uuid, 'cc_member_session_uuid') or - channel_variable(row.uuid, 'fifo_bridge_uuid') or - row.uuid - else - uuid = row.call_uuid; - end - call_hostname = row.hostname; - ip_addr = row.ip_addr; - end); - end - - freeswitch.consoleLog("NOTICE", "Hostname:"..hostname.." Call Hostname:"..call_hostname.."\n"); - ---intercept a call that is ringing - if (uuid ~= nil) then - if (session:getVariable("billmsec") == nil) then - if (hostname == call_hostname) then - session:execute("intercept", uuid); - else - session:execute("export", "sip_h_X-intercept_uuid="..uuid); - session:execute("export", "sip_h_X-domain_uuid="..domain_uuid); - session:execute("export", "sip_h_X-domain_name="..domain_name); - port = freeswitch.getGlobalVariable(sofia_profile_name.."_sip_port"); - session:execute("bridge", "sofia/"..sofia_profile_name.."/*8@"..call_hostname..":"..port); - freeswitch.consoleLog("NOTICE", "Send call to other host.... \n"); - end - end - end - ---notes - --originate a call - --cmd = "originate user/1007@voip.example.com &intercept("..uuid..")"; - --api = freeswitch.API(); - --result = api:executeString(cmd); +require "intercept" diff --git a/resources/install/scripts/ivr_menu.lua b/resources/install/scripts/ivr_menu.lua index 554bcdc2f7..47b35679ed 100644 --- a/resources/install/scripts/ivr_menu.lua +++ b/resources/install/scripts/ivr_menu.lua @@ -407,8 +407,12 @@ if (row.ivr_menu_option_action == "menu-exec-app") then --get the action and data pos = string.find(row.ivr_menu_option_param, " ", 0, true); - action = string.sub(row.ivr_menu_option_param, 0, pos-1); - data = string.sub(row.ivr_menu_option_param, pos+1); + if pos then + action = string.sub(row.ivr_menu_option_param, 0, pos-1); + data = string.sub(row.ivr_menu_option_param, pos+1); + else + action, data = row.ivr_menu_option_param, "" + end --check if the option uses a regex regex = string.find(row.ivr_menu_option_digits, "(", 0, true); @@ -431,7 +435,11 @@ end if (action == "lua") then pos = string.find(data, " ", 0, true); - script = string.sub(data, 0, pos-1); + if pos then + script = string.sub(data, 0, pos-1); + else + script = data + end end end --if regex match diff --git a/resources/install/scripts/resources/functions/channel_utils.lua b/resources/install/scripts/resources/functions/channel_utils.lua index 5cf33c5f8f..3676f87d7d 100644 --- a/resources/install/scripts/resources/functions/channel_utils.lua +++ b/resources/install/scripts/resources/functions/channel_utils.lua @@ -1,4 +1,4 @@ -require 'resources.config' +require 'resources.functions.config' require 'resources.functions.trim' local Database = require 'resources.functions.database' @@ -23,6 +23,14 @@ function channel_evalute(uuid, cmd) return result end +function channel_display(uuid, text) + local cmd = ("uuid_display %s '%s'"):format(uuid, text) + local result = trim(api:executeString(cmd)) + if result:sub(1, 4) == '-ERR' then return nil, result end + if result == '_undef_' then return false end + return result +end + local _switchname local function switchname() if _switchname then return _switchname end diff --git a/resources/install/scripts/resources/functions/database.lua b/resources/install/scripts/resources/functions/database.lua index 50349b1b14..f8939126ff 100644 --- a/resources/install/scripts/resources/functions/database.lua +++ b/resources/install/scripts/resources/functions/database.lua @@ -1,4 +1,4 @@ -require 'resources.config' +require 'resources.functions.config' require 'resources.functions.file_exists' require 'resources.functions.database_handle' @@ -27,7 +27,11 @@ function Database.new(name) end function Database:query(sql, fn) - return self._dbh:query(sql, fn) + if (fn == nil) then + return self._dbh:query(sql) + else + return self._dbh:query(sql, fn) + end end function Database:first_row(sql) @@ -81,9 +85,9 @@ function Database.__self_test__(name) local db = Database.new(name or 'system') assert(db:connected()) - assert("1" == db:first_value("select 1 as v")) + assert("1" == db:first_value("select 1 as v union all select 2 as v")) - local t = assert(db:first_row("select 1 as v")) + local t = assert(db:first_row("select 1 as v union all select 2 as v")) assert(t.v == "1") t = assert(db:fetch_all("select 1 as v union all select 2 as v")) @@ -99,10 +103,13 @@ function Database.__self_test__(name) db:release() assert(not db:connected()) + print(" * databse - OK!") end end --- Database.__self_test__() +-- if debug.self_test then +-- Database.__self_test__() +-- end return Database \ No newline at end of file diff --git a/resources/templates/conf/autoload_configs/lua.conf.xml b/resources/templates/conf/autoload_configs/lua.conf.xml index 0758bb6762..534505dc3b 100644 --- a/resources/templates/conf/autoload_configs/lua.conf.xml +++ b/resources/templates/conf/autoload_configs/lua.conf.xml @@ -13,7 +13,7 @@ These entries will be pre-pended to the LUA_PATH environment variable --> - + diff --git a/resources/templates/conf/lang/en/wakeup/sounds.xml b/resources/templates/conf/lang/en/wakeup/sounds.xml index 8c41736405..57d54bfd11 100644 --- a/resources/templates/conf/lang/en/wakeup/sounds.xml +++ b/resources/templates/conf/lang/en/wakeup/sounds.xml @@ -5,49 +5,34 @@ - - - - - - - - - - - - - - - - - - - - + + - - - - + + + + + + + + + - + - - - - - + + + @@ -57,13 +42,7 @@ - - - - - - - + @@ -73,13 +52,10 @@ - - - + - - - + + @@ -90,12 +66,8 @@ - - - - - - + + @@ -104,26 +76,45 @@ - + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - - + + - + \ No newline at end of file diff --git a/resources/templates/provision/polycom/4.x/{$mac}.cfg b/resources/templates/provision/polycom/4.x/{$mac}.cfg index 0326802b6e..c8f8e4a624 100644 --- a/resources/templates/provision/polycom/4.x/{$mac}.cfg +++ b/resources/templates/provision/polycom/4.x/{$mac}.cfg @@ -1,11 +1,13 @@ \ No newline at end of file diff --git a/resources/templates/provision/polycom/5.x/{$mac}.cfg b/resources/templates/provision/polycom/5.x/{$mac}.cfg index 0326802b6e..c8f8e4a624 100755 --- a/resources/templates/provision/polycom/5.x/{$mac}.cfg +++ b/resources/templates/provision/polycom/5.x/{$mac}.cfg @@ -1,11 +1,13 @@ \ No newline at end of file diff --git a/resources/templates/provision/yealink/t22p/{$mac}.cfg b/resources/templates/provision/yealink/t22p/{$mac}.cfg index 7fef6e9bfc..ce904e36e6 100644 --- a/resources/templates/provision/yealink/t22p/{$mac}.cfg +++ b/resources/templates/provision/yealink/t22p/{$mac}.cfg @@ -223,8 +223,8 @@ account.1.nat.stun_server = #Configure the STUN server port, the default value is 3478. account.1.nat.stun_port = -#Enable or disable the NAT keep-alive; 0-Disabled, 1-Enabled (default); -account.1.nat.udp_update_enable = +#Enable or disable the NAT keep-alive; 0-Disabled, 1-Default (default), 2-Option, 3-Notify; +account.1.nat.udp_update_enable = 3 #Specify the keep-alive interval (in seconds), the default value is 30. account.1.nat.udp_update_time = diff --git a/resources/templates/provision/yealink/t23g/{$mac}.cfg b/resources/templates/provision/yealink/t23g/{$mac}.cfg index e09d088c44..8641aa3259 100644 --- a/resources/templates/provision/yealink/t23g/{$mac}.cfg +++ b/resources/templates/provision/yealink/t23g/{$mac}.cfg @@ -126,7 +126,7 @@ account.1.nat.stun_server = account.1.nat.stun_port = 3478 #Enable or disable the NAT keep-alive; 0-Disabled, 1-Default (default), 2-Option, 3-Notify; -account.1.nat.udp_update_enable = 1 +account.1.nat.udp_update_enable = 3 #Specify the keep-alive interval (in seconds), the default value is 30. account.1.nat.udp_update_time = 30 diff --git a/resources/templates/provision/yealink/t23p/{$mac}.cfg b/resources/templates/provision/yealink/t23p/{$mac}.cfg index e09d088c44..8641aa3259 100644 --- a/resources/templates/provision/yealink/t23p/{$mac}.cfg +++ b/resources/templates/provision/yealink/t23p/{$mac}.cfg @@ -126,7 +126,7 @@ account.1.nat.stun_server = account.1.nat.stun_port = 3478 #Enable or disable the NAT keep-alive; 0-Disabled, 1-Default (default), 2-Option, 3-Notify; -account.1.nat.udp_update_enable = 1 +account.1.nat.udp_update_enable = 3 #Specify the keep-alive interval (in seconds), the default value is 30. account.1.nat.udp_update_time = 30 diff --git a/resources/templates/provision/yealink/t26p/{$mac}.cfg b/resources/templates/provision/yealink/t26p/{$mac}.cfg index ecc4c4997b..2761774eaa 100644 --- a/resources/templates/provision/yealink/t26p/{$mac}.cfg +++ b/resources/templates/provision/yealink/t26p/{$mac}.cfg @@ -223,8 +223,8 @@ account.1.nat.stun_server = #Configure the STUN server port, the default value is 3478. account.1.nat.stun_port = -#Enable or disable the NAT keep-alive; 0-Disabled, 1-Enabled (default); -account.1.nat.udp_update_enable = +#Enable or disable the NAT keep-alive; 0-Disabled, 1-Default (default), 2-Option, 3-Notify; +account.1.nat.udp_update_enable = 3 #Specify the keep-alive interval (in seconds), the default value is 30. account.1.nat.udp_update_time = diff --git a/resources/templates/provision/yealink/t27p/{$mac}.cfg b/resources/templates/provision/yealink/t27p/{$mac}.cfg index e09d088c44..8641aa3259 100644 --- a/resources/templates/provision/yealink/t27p/{$mac}.cfg +++ b/resources/templates/provision/yealink/t27p/{$mac}.cfg @@ -126,7 +126,7 @@ account.1.nat.stun_server = account.1.nat.stun_port = 3478 #Enable or disable the NAT keep-alive; 0-Disabled, 1-Default (default), 2-Option, 3-Notify; -account.1.nat.udp_update_enable = 1 +account.1.nat.udp_update_enable = 3 #Specify the keep-alive interval (in seconds), the default value is 30. account.1.nat.udp_update_time = 30 diff --git a/resources/templates/provision/yealink/t28p/{$mac}.cfg b/resources/templates/provision/yealink/t28p/{$mac}.cfg index ecc4c4997b..2761774eaa 100644 --- a/resources/templates/provision/yealink/t28p/{$mac}.cfg +++ b/resources/templates/provision/yealink/t28p/{$mac}.cfg @@ -223,8 +223,8 @@ account.1.nat.stun_server = #Configure the STUN server port, the default value is 3478. account.1.nat.stun_port = -#Enable or disable the NAT keep-alive; 0-Disabled, 1-Enabled (default); -account.1.nat.udp_update_enable = +#Enable or disable the NAT keep-alive; 0-Disabled, 1-Default (default), 2-Option, 3-Notify; +account.1.nat.udp_update_enable = 3 #Specify the keep-alive interval (in seconds), the default value is 30. account.1.nat.udp_update_time = diff --git a/resources/templates/provision/yealink/t29g/{$mac}.cfg b/resources/templates/provision/yealink/t29g/{$mac}.cfg index e09d088c44..8641aa3259 100644 --- a/resources/templates/provision/yealink/t29g/{$mac}.cfg +++ b/resources/templates/provision/yealink/t29g/{$mac}.cfg @@ -126,7 +126,7 @@ account.1.nat.stun_server = account.1.nat.stun_port = 3478 #Enable or disable the NAT keep-alive; 0-Disabled, 1-Default (default), 2-Option, 3-Notify; -account.1.nat.udp_update_enable = 1 +account.1.nat.udp_update_enable = 3 #Specify the keep-alive interval (in seconds), the default value is 30. account.1.nat.udp_update_time = 30 diff --git a/resources/templates/provision/yealink/t32g/{$mac}.cfg b/resources/templates/provision/yealink/t32g/{$mac}.cfg index b7de551e22..a7f7534e5e 100644 --- a/resources/templates/provision/yealink/t32g/{$mac}.cfg +++ b/resources/templates/provision/yealink/t32g/{$mac}.cfg @@ -223,8 +223,8 @@ account.1.nat.stun_server = #Configure the STUN server port, the default value is 3478. account.1.nat.stun_port = -#Enable or disable the NAT keep-alive; 0-Disabled, 1-Enabled (default); -account.1.nat.udp_update_enable = +#Enable or disable the NAT keep-alive; 0-Disabled, 1-Default (default), 2-Option, 3-Notify; +account.1.nat.udp_update_enable = 3 #Specify the keep-alive interval (in seconds), the default value is 30. account.1.nat.udp_update_time = diff --git a/resources/templates/provision/yealink/t38g/{$mac}.cfg b/resources/templates/provision/yealink/t38g/{$mac}.cfg index e2f464c29b..cffa4df9dc 100644 --- a/resources/templates/provision/yealink/t38g/{$mac}.cfg +++ b/resources/templates/provision/yealink/t38g/{$mac}.cfg @@ -223,8 +223,8 @@ account.1.nat.stun_server = #Configure the STUN server port, the default value is 3478. account.1.nat.stun_port = -#Enable or disable the NAT keep-alive; 0-Disabled, 1-Enabled (default); -account.1.nat.udp_update_enable = +#Enable or disable the NAT keep-alive; 0-Disabled, 1-Default (default), 2-Option, 3-Notify; +account.1.nat.udp_update_enable = 3 #Specify the keep-alive interval (in seconds), the default value is 30. account.1.nat.udp_update_time = diff --git a/resources/templates/provision/yealink/t41p/{$mac}.cfg b/resources/templates/provision/yealink/t41p/{$mac}.cfg index e09d088c44..8641aa3259 100644 --- a/resources/templates/provision/yealink/t41p/{$mac}.cfg +++ b/resources/templates/provision/yealink/t41p/{$mac}.cfg @@ -126,7 +126,7 @@ account.1.nat.stun_server = account.1.nat.stun_port = 3478 #Enable or disable the NAT keep-alive; 0-Disabled, 1-Default (default), 2-Option, 3-Notify; -account.1.nat.udp_update_enable = 1 +account.1.nat.udp_update_enable = 3 #Specify the keep-alive interval (in seconds), the default value is 30. account.1.nat.udp_update_time = 30 diff --git a/resources/templates/provision/yealink/t42g/{$mac}.cfg b/resources/templates/provision/yealink/t42g/{$mac}.cfg index 94d6cc28a1..70c98e9022 100644 --- a/resources/templates/provision/yealink/t42g/{$mac}.cfg +++ b/resources/templates/provision/yealink/t42g/{$mac}.cfg @@ -126,7 +126,7 @@ account.1.nat.stun_server = account.1.nat.stun_port = 3478 #Enable or disable the NAT keep-alive; 0-Disabled, 1-Default (default), 2-Option, 3-Notify; -account.1.nat.udp_update_enable = 1 +account.1.nat.udp_update_enable = 3 #Specify the keep-alive interval (in seconds), the default value is 30. account.1.nat.udp_update_time = 30 diff --git a/resources/templates/provision/yealink/vp530/{$mac}.cfg b/resources/templates/provision/yealink/vp530/{$mac}.cfg index a380a3f81d..b35405d03e 100644 --- a/resources/templates/provision/yealink/vp530/{$mac}.cfg +++ b/resources/templates/provision/yealink/vp530/{$mac}.cfg @@ -253,8 +253,8 @@ account.1.nat.stun_server = #Configure the STUN server port, the default value is 3478. account.1.nat.stun_port = -#Enable or disable the NAT keep-alive; 0-Disabled, 1-Enabled (default); -account.1.nat.udp_update_enable = +#Enable or disable the NAT keep-alive; 0-Disabled, 1-Default (default), 2-Option, 3-Notify; +account.1.nat.udp_update_enable = 3 #Specify the keep-alive interval (in seconds), the default value is 30. account.1.nat.udp_update_time = diff --git a/resources/templates/provision/yealink/w52p/{$mac}.cfg b/resources/templates/provision/yealink/w52p/{$mac}.cfg index a6bc0d586a..2509a41fbf 100644 --- a/resources/templates/provision/yealink/w52p/{$mac}.cfg +++ b/resources/templates/provision/yealink/w52p/{$mac}.cfg @@ -147,8 +147,8 @@ account.1.nat.stun_server = #Configure the STUN server port, the default value is 3478. account.1.nat.stun_port = -#Enable or disable the NAT keep-alive; 0-Disabled, 1-Enabled (default); -account.1.nat.udp_update_enable = +#Enable or disable the NAT keep-alive; 0-Disabled, 1-Default (default), 2-Option, 3-Notify; +account.1.nat.udp_update_enable = 3 #Specify the keep-alive interval (in seconds), the default value is 30. account.1.nat.udp_update_time = diff --git a/themes/enhanced/template.php b/themes/enhanced/template.php index 3b5579bcb9..e5cf267146 100644 --- a/themes/enhanced/template.php +++ b/themes/enhanced/template.php @@ -251,7 +251,7 @@ form { margin: 0; } -input.btn, input.button { +input.btn, input.button, button { font-family: Candara, Calibri, Segoe, "Segoe UI", Optima, Arial, sans-serif; padding: 2px 6px 3px 6px; color: #fff; @@ -273,7 +273,7 @@ input.btn, input.button { -moz-opacity: 0.9; } -input.btn:hover, input.button:hover, img.list_control_icon:hover { +input.btn:hover, input.button:hover, img.list_control_icon:hover, button:hover { box-shadow: 0 0 5px #cddaf0; -webkit-box-shadow: 0 0 5px #cddaf0; -moz-box-shadow: 0 0 5px #cddaf0;