From 6816921f471506ab2235e82fe3bf54f84df46550 Mon Sep 17 00:00:00 2001 From: fusionate Date: Wed, 17 May 2023 07:02:45 +0000 Subject: [PATCH] Extension - Edit: Updates for PHP 8.1 --- app/extensions/extension_edit.php | 190 ++++++++++++++---------------- 1 file changed, 88 insertions(+), 102 deletions(-) diff --git a/app/extensions/extension_edit.php b/app/extensions/extension_edit.php index 2071cb550e..4a0e6f2d49 100644 --- a/app/extensions/extension_edit.php +++ b/app/extensions/extension_edit.php @@ -47,7 +47,7 @@ $text = $language->get(); //set the action as an add or an update - if (is_uuid($_REQUEST["id"])) { + if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { $action = "update"; $extension_uuid = $_REQUEST["id"]; $page = $_REQUEST['page']; @@ -89,8 +89,8 @@ $extension = $database->select($sql, $parameters, 'column'); unset($sql, $parameters); } - $number_alias = $_POST["number_alias"]; - $password = $_POST["password"]; + $number_alias = $_POST["number_alias"] ?? null; + $password = $_POST["password"] ?? null; //server verification on account code $accountcode = $_POST["accountcode"]; @@ -111,13 +111,13 @@ //$device_uuid = $_POST["device_uuid"]; //$device_line = $_POST["device_line"]; $voicemail_password = $_POST["voicemail_password"]; - $voicemail_enabled = $_POST["voicemail_enabled"] ?: 'false'; + $voicemail_enabled = $_POST["voicemail_enabled"] ?? 'false'; $voicemail_mail_to = $_POST["voicemail_mail_to"]; $voicemail_transcription_enabled = $_POST["voicemail_transcription_enabled"]; $voicemail_file = $_POST["voicemail_file"]; $voicemail_local_after_email = $_POST["voicemail_local_after_email"]; $user_context = $_POST["user_context"]; - $range = $_POST["range"]; + $range = $_POST["range"] ?? null; $missed_call_app = $_POST["missed_call_app"]; $missed_call_data = $_POST["missed_call_data"]; $toll_allow = $_POST["toll_allow"]; @@ -130,13 +130,13 @@ $cidr = $_POST["cidr"]; $sip_force_contact = $_POST["sip_force_contact"]; $sip_force_expires = $_POST["sip_force_expires"]; - $nibble_account = $_POST["nibble_account"]; + $nibble_account = $_POST["nibble_account"] ?? null; $mwi_account = $_POST["mwi_account"]; $sip_bypass_media = $_POST["sip_bypass_media"]; $absolute_codec_string = $_POST["absolute_codec_string"]; $force_ping = $_POST["force_ping"]; $dial_string = $_POST["dial_string"]; - $enabled = $_POST["enabled"] ?: 'false'; + $enabled = $_POST["enabled"] ?? 'false'; $description = $_POST["description"]; //outbound caller id number - only allow numeric and + @@ -171,7 +171,7 @@ $toll_allow = str_replace(',',':', $toll_allow); //set assigned user variables - $user_uuid = $_POST["extension_users"][0]["user_uuid"]; + $user_uuid = $_POST["extension_users"][0]["user_uuid"] ?? null; //device provisioning variables if (is_array($_POST["devices"]) && @sizeof($_POST["devices"]) != 0) { @@ -186,7 +186,7 @@ } //get or set the device_uuid - if (is_array($device_mac_addresses) && @sizeof($device_mac_addresses) != 0) { + if (!empty($device_mac_addresses) && is_array($device_mac_addresses) && @sizeof($device_mac_addresses) != 0) { foreach ($device_mac_addresses as $d => $device_mac_address) { $device_mac_address = strtolower($device_mac_address); $device_mac_address = preg_replace('#[^a-fA-F0-9./]#', '', $device_mac_address); @@ -220,14 +220,14 @@ } unset($sql, $parameters); - $device_uuids[$d] = is_uuid($device_uuid) ? $device_uuid : uuid(); + $device_uuids[$d] = !empty($device_uuid) && is_uuid($device_uuid) ? $device_uuid : uuid(); } } } //delete the user from the v_extension_users - if ($_REQUEST["delete_type"] == "user" && is_uuid($_REQUEST["delete_uuid"]) && permission_exists("extension_delete")) { + if (!empty($_REQUEST["delete_type"]) && $_REQUEST["delete_type"] == "user" && is_uuid($_REQUEST["delete_uuid"]) && permission_exists("extension_delete")) { //set the variables $extension_uuid = $_REQUEST["id"]; $user_uuid = $_REQUEST["delete_uuid"]; @@ -257,7 +257,7 @@ //delete the line from the v_device_lines if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/devices')) { - if ($_REQUEST["delete_type"] == "device_line" && is_uuid($_REQUEST["delete_uuid"]) && permission_exists("extension_delete")) { + if (!empty($_REQUEST["delete_type"]) && $_REQUEST["delete_type"] == "device_line" && is_uuid($_REQUEST["delete_uuid"]) && permission_exists("extension_delete")) { //set the variables $device_line_uuid = $_REQUEST["delete_uuid"]; @@ -324,13 +324,13 @@ //prevent users from bypassing extension limit by using range if ($_SESSION['limit']['extensions']['numeric'] != '') { - if ($total_extensions + $range > $_SESSION['limit']['extensions']['numeric']){ + if (isset($total_extensions) && ($total_extensions ?? 0) + $range > $_SESSION['limit']['extensions']['numeric']) { $range = $_SESSION['limit']['extensions']['numeric'] - $total_extensions; } } //add or update the database - if ($_POST["persistformvar"] != "true") { + if (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true") { //prep missed call values for db insert/update switch ($missed_call_app) { @@ -685,7 +685,7 @@ $array["voicemails"][$i]["voicemail_local_after_email"] = $voicemail_local_after_email; } $array["voicemails"][$i]["voicemail_transcription_enabled"] = $voicemail_transcription_enabled; - $array["voicemails"][$i]["voicemail_tutorial"] = $voicemail_tutorial; + $array["voicemails"][$i]["voicemail_tutorial"] = $voicemail_tutorial ?? null; $array["voicemails"][$i]["voicemail_enabled"] = $voicemail_enabled; $array["voicemails"][$i]["voicemail_description"] = $description; @@ -764,7 +764,7 @@ if (permission_exists('extension_add') || permission_exists('extension_edit')) { //synchronize configuration - if (is_writable($_SESSION['switch']['extensions']['dir'])) { + if (!empty($_SESSION['switch']['extensions']['dir']) && is_writable($_SESSION['switch']['extensions']['dir'])) { require_once "app/extensions/resources/classes/extension.php"; $ext = new extension; $ext->xml(); @@ -819,7 +819,7 @@ } //pre-populate the form - if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { + if (count($_GET) > 0 && (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true")) { $extension_uuid = $_GET["id"]; $sql = "select * from v_extensions "; $sql .= "where extension_uuid = :extension_uuid "; @@ -884,8 +884,8 @@ $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { - $voicemail_password = str_replace("#", "", $row["voicemail_password"]); - $voicemail_mail_to = str_replace(" ", "", $row["voicemail_mail_to"]); + $voicemail_password = str_replace("#", "", $row["voicemail_password"] ?? ''); + $voicemail_mail_to = str_replace(" ", "", $row["voicemail_mail_to"] ?? ''); $voicemail_transcription_enabled = $row["voicemail_transcription_enabled"]; $voicemail_tutorial = $row["voicemail_tutorial"]; $voicemail_file = $row["voicemail_file"]; @@ -908,8 +908,8 @@ $sql .= "and l.domain_uuid = :domain_uuid "; $sql .= "and l.device_uuid = d.device_uuid "; $sql .= "order by l.line_number, d.device_mac_address asc "; - $parameters['user_id_1'] = $extension; - $parameters['user_id_2'] = $number_alias; + $parameters['user_id_1'] = $extension ?? null; + $parameters['user_id_2'] = $number_alias ?? null; $parameters['domain_uuid'] = $domain_uuid; $database = new database; $device_lines = $database->select($sql, $parameters, 'all'); @@ -934,7 +934,7 @@ unset($sql); //get assigned users - if (is_uuid($extension_uuid)) { + if (!empty($extension_uuid) && is_uuid($extension_uuid)) { $sql = "select u.username, e.user_uuid "; $sql .= "from v_extension_users as e, v_users as u "; $sql .= "where e.user_uuid = u.user_uuid "; @@ -957,7 +957,7 @@ //get the users $sql = "select * from v_users "; $sql .= "where domain_uuid = :domain_uuid "; - if (is_array($assigned_user_uuids) && @sizeof($assigned_user_uuids) != 0) { + if (!empty($assigned_user_uuids) && is_array($assigned_user_uuids) && @sizeof($assigned_user_uuids) != 0) { foreach ($assigned_user_uuids as $index => $assigned_user_uuid) { $sql .= "and user_uuid <> :user_uuid_".$index." "; $parameters['user_uuid_'.$index] = $assigned_user_uuid; @@ -994,11 +994,11 @@ } //change toll allow delimiter - $toll_allow = str_replace(':',',', $toll_allow); + $toll_allow = str_replace(':',',', $toll_allow ?? ''); //set the defaults if (empty($user_context)) { $user_context = $_SESSION['domain_name']; } - if (empty($max_registrations)) { $max_registrations = $_SESSION['extension']['max_registrations']['numeric']; } + if (empty($max_registrations)) { $max_registrations = $_SESSION['extension']['max_registrations']['numeric'] ?? ''; } if (empty($accountcode)) { $accountcode = get_accountcode(); } if (empty($limit_max)) { $limit_max = '5'; } if (empty($limit_destination)) { $limit_destination = '!USER_BUSY'; } @@ -1042,13 +1042,13 @@ echo " var new_ext = prompt('".$text['message-extension']."');\n"; echo " if (new_ext != null) {\n"; echo " if (!isNaN(new_ext)) {\n"; - echo " document.location.href='extension_copy.php?id=".escape($extension_uuid)."&ext=' + new_ext".(is_numeric($page) ? " + '&page=".$page."'" : null).";\n"; + echo " document.location.href='extension_copy.php?id=".escape($extension_uuid ?? '')."&ext=' + new_ext".(!empty($page) && is_numeric($page) ? " + '&page=".$page."'" : null).";\n"; echo " }\n"; echo " else {\n"; echo " var new_number_alias = prompt('".$text['message-number_alias']."');\n"; echo " if (new_number_alias != null) {\n"; echo " if (!isNaN(new_number_alias)) {\n"; - echo " document.location.href='extension_copy.php?id=".escape($extension_uuid)."&ext=' + new_ext + '&alias=' + new_number_alias".(is_numeric($page) ? " + '&page=".$page."'" : null).";\n"; + echo " document.location.href='extension_copy.php?id=".escape($extension_uuid ?? '')."&ext=' + new_ext + '&alias=' + new_number_alias".(!empty($page) && is_numeric($page) ? " + '&page=".$page."'" : null).";\n"; echo " }\n"; echo " }\n"; echo " }\n"; @@ -1068,15 +1068,15 @@ } echo "\n"; echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','link'=>'extensions.php'.(is_numeric($page) ? '?page='.$page : null)]); + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','link'=>'extensions.php'.(isset($page) && is_numeric($page) ? '?page='.$page : null)]); if ($action == 'update') { $button_margin = 'margin-left: 15px;'; if (permission_exists('xml_cdr_view')) { - echo button::create(['type'=>'button','label'=>$text['button-cdr'],'icon'=>'info-circle','style'=>$button_margin,'link'=>'../xml_cdr/xml_cdr.php?extension_uuid='.urlencode($extension_uuid)]); + echo button::create(['type'=>'button','label'=>$text['button-cdr'],'icon'=>'info-circle','style'=>($button_margin ?? ''),'link'=>'../xml_cdr/xml_cdr.php?extension_uuid='.urlencode($extension_uuid)]); unset($button_margin); } if (permission_exists('follow_me') || permission_exists('call_forward') || permission_exists('do_not_disturb')) { - echo button::create(['type'=>'button','label'=>$text['button-call_forward'],'icon'=>'project-diagram','style'=>$button_margin,'link'=>'../call_forward/call_forward_edit.php?id='.urlencode($extension_uuid)]); + echo button::create(['type'=>'button','label'=>$text['button-call_forward'],'icon'=>'project-diagram','style'=>($button_margin ?? ''),'link'=>'../call_forward/call_forward_edit.php?id='.urlencode($extension_uuid)]); unset($button_margin); } if (permission_exists('extension_setting_view')) { @@ -1100,7 +1100,7 @@ echo "\n"; echo "\n"; if ($action == "add" || permission_exists("extension_extension")) { - echo " \n"; + echo " \n"; echo " \n"; //help defeat browser auto-fill echo "
\n"; echo $text['description-extension']."\n"; @@ -1117,7 +1117,7 @@ echo " ".$text['label-number_alias']."\n"; echo "\n"; echo "\n"; - echo " \n"; + echo " \n"; echo " \n"; //help defeat browser auto-fill echo "
\n"; echo $text['description-number_alias']."\n"; @@ -1132,7 +1132,7 @@ echo "\n"; echo "\n"; echo " \n"; //help defeat browser auto-fill - echo " \n"; + echo " \n"; echo "
\n"; echo " ".$text['description-password']."\n"; echo "\n"; @@ -1184,7 +1184,7 @@ echo " "; echo " ".($action == "update" ? $text['label-users'] : $text['label-user']).""; echo " "; - if (is_array($assigned_users) && @sizeof($assigned_users) != 0 && $action == "update") { + if (!empty($assigned_users) && is_array($assigned_users) && @sizeof($assigned_users) != 0 && $action == "update") { echo " \n"; foreach($assigned_users as $field) { echo " \n"; @@ -1222,7 +1222,7 @@ echo "\n"; echo "\n"; @@ -1284,7 +1284,7 @@ for ($d = 0; $d <= 4; $d++) { echo " \n"; echo " \n"; echo "\n"; @@ -1406,7 +1406,7 @@ echo " ".$text['label-effective_caller_id_number']."\n"; echo "\n"; echo "\n"; @@ -1443,11 +1443,11 @@ echo $text['description-outbound_caller_id_name-select']."\n"; } else { - echo " \n"; + echo " \n"; } } else { - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-outbound_caller_id_name-custom']."\n"; } @@ -1484,11 +1484,11 @@ echo $text['description-outbound_caller_id_number-select']."\n"; } else { - echo " \n"; + echo " \n"; } } else { - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-outbound_caller_id_number-custom']."\n"; } @@ -1527,7 +1527,7 @@ } } else { - echo " \n"; + echo " \n"; } echo "
\n"; if (permission_exists('outbound_caller_id_select') && count($destinations) > 0) { @@ -1573,7 +1573,7 @@ } } else { - echo " \n"; + echo " \n"; } echo "
\n"; if (permission_exists('emergency_caller_id_select') && count($emergency_destinations) > 0){ @@ -1595,8 +1595,8 @@ echo " ".$text['label-directory_full_name']."\n"; echo "\n"; echo "\n"; @@ -1608,13 +1608,13 @@ echo "\n"; echo "\n"; echo "\n"; echo "\n"; @@ -1670,7 +1670,7 @@ echo " ".$text['label-limit_max']."\n"; echo "\n"; echo "\n"; @@ -1681,7 +1681,7 @@ echo " ".$text['label-limit_destination']."\n"; echo "\n"; echo "\n"; @@ -1718,7 +1718,7 @@ echo " ".$text['label-voicemail_mail_to']."\n"; echo "\n"; echo "\n"; @@ -1782,12 +1782,12 @@ echo "\n"; @@ -1800,7 +1800,7 @@ echo " ".$text['label-toll_allow']."\n"; echo "\n"; echo "\n"; echo "\n"; @@ -1839,7 +1839,7 @@ echo " ".$text['label-call_group']."\n"; echo "\n"; echo "\n"; @@ -1969,7 +1970,7 @@ echo " ".$text['label-user_context']."\n"; echo "\n"; echo "\n"; @@ -2001,7 +2002,7 @@ echo " ".$text['label-auth_acl']."\n"; echo "\n"; echo "\n"; @@ -2013,7 +2014,7 @@ echo " ".$text['label-cidr']."\n"; echo "\n"; echo "\n"; @@ -2027,14 +2028,14 @@ echo "\n"; echo "\n"; @@ -2059,7 +2060,7 @@ echo " ".$text['label-nibble_account']."\n"; echo "\n"; echo "\n"; @@ -2071,7 +2072,7 @@ echo " ".$text['label-mwi_account']."\n"; echo "\n"; echo "\n"; @@ -2084,14 +2085,14 @@ echo "\n"; echo "\n"; @@ -2119,24 +2120,9 @@ echo "\n"; echo "\n"; echo "\n"; @@ -2195,7 +2181,7 @@ echo " ".$text['label-description']."\n"; echo "\n"; echo "\n"; @@ -2204,7 +2190,7 @@ echo "
\n"; echo " \n"; //help defeat browser auto-fill - echo " \n"; + echo " \n"; echo "
\n"; echo " ".$text['description-voicemail_password']."\n"; echo "
"; - echo " \n"; echo " \n"; for ($n = 1; $n <=99; $n++) { echo " \n"; @@ -1358,7 +1358,7 @@ if (is_dir($template_dir.'/'.$row["name"])) { $templates = scandir($template_dir.'/'.$row["name"]); foreach($templates as $dir) { - if ($file != "." && $dir != ".." && $dir[0] != '.' && is_dir($template_dir.'/'.$row["name"].'/'.$dir)) { + if (!empty($file) && $file != "." && !empty($dir) && $dir != ".." && $dir[0] != '.' && !empty($template_dir) && is_dir($template_dir.'/'.$row["name"].'/'.$dir)) { $selected = $device_template == $row["name"]."/".$dir ? "selected='selected'" : null; echo " \n"; } @@ -1393,7 +1393,7 @@ echo " ".$text['label-effective_caller_id_name']."\n"; echo "\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-effective_caller_id_name']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-effective_caller_id_number']."\n"; echo "
\n"; - echo " \n"; - echo " \n"; + echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-directory_full_name']."\n"; echo "
\n"; echo " \n"; echo " \n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-max_registrations']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-limit_max']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-limit_destination']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-voicemail_mail_to']."\n"; echo "
\n"; echo " \n"; - $missed_call_data = ($missed_call_app == 'text') ? format_phone($missed_call_data) : $missed_call_data; - echo " \n"; + $missed_call_data = !empty($missed_call_app) && $missed_call_app == 'text' ? format_phone($missed_call_data ?? '') : $missed_call_data ?? ''; + echo " \n"; echo "
\n"; echo $text['description-missed_call']."\n"; echo "
\n"; - if (is_array($_SESSION['toll allow']['name'])) { + if (!empty($_SESSION['toll allow']['name']) && is_array($_SESSION['toll allow']['name'])) { echo " \n"; } else { - echo " \n"; + echo " \n"; } echo "
\n"; echo $text['description-toll_allow']."\n"; @@ -1827,7 +1827,7 @@ echo " ".$text['label-call_timeout']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-call_timeout']."\n"; echo "
\n"; - if (is_array($_SESSION['call group']['name'])) { + if (!empty($_SESSION['call group']['name']) && is_array($_SESSION['call group']['name'])) { echo " \n"; - } else { - echo " \n"; + } + else { + echo " \n"; } echo "
\n"; echo $text['description-call_group']."\n"; @@ -1934,7 +1935,7 @@ require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php"; $options = ''; $moh = new switch_music_on_hold; - echo $moh->select('hold_music', $hold_music, $options); + echo $moh->select('hold_music', $hold_music ?? '', $options); echo "
\n"; echo $text['description-hold_music']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-user_context']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-auth_acl']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-cidr']."\n"; echo "
\n"; echo " \n"; echo "
\n"; @@ -2047,7 +2048,7 @@ echo " ".$text['label-sip_force_expires']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-sip_force_expires']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-nibble_account']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-mwi_account']."\n"; echo "
\n"; echo " \n"; echo "
\n"; @@ -2105,7 +2106,7 @@ echo " ".$text['label-absolute_codec_string']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-absolute_codec_string']."\n"; echo "
\n"; echo " \n"; echo "
\n"; echo $text['description-force_ping']."\n"; @@ -2150,7 +2136,7 @@ echo " ".$text['label-dial_string']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-dial_string']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-description']."\n"; echo "
"; echo "

"; - if (is_numeric($page)) { + if (isset($page) && is_numeric($page)) { echo "\n"; } if ($action == "update") { @@ -2231,4 +2217,4 @@ //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file