diff --git a/app/sip_profiles/resources/classes/sip_profiles.php b/app/sip_profiles/resources/classes/sip_profiles.php index cc1ef75573..834dce3562 100644 --- a/app/sip_profiles/resources/classes/sip_profiles.php +++ b/app/sip_profiles/resources/classes/sip_profiles.php @@ -203,14 +203,14 @@ if (!class_exists('sip_profiles')) { //filter out unchecked sip profiles, build the delete array foreach ($records as $x => $record) { - if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid']; $array[$this->table][$x]['sip_profile_uuid'] = $this->sip_profile_uuid; } } //get necessary sip profile details - if (is_uuid($this->sip_profile_uuid)) { + if (!empty($this->sip_profile_uuid) && is_uuid($this->sip_profile_uuid)) { $sql = "select sip_profile_hostname from v_sip_profiles "; $sql .= "where sip_profile_uuid = :sip_profile_uuid "; $parameters['sip_profile_uuid'] = $this->sip_profile_uuid; @@ -220,7 +220,7 @@ if (!class_exists('sip_profiles')) { } //delete the checked rows - if (is_array($array) && @sizeof($array) != 0) { + if (!empty($array) && @sizeof($array) != 0) { //execute delete $database = new database; @@ -277,18 +277,18 @@ if (!class_exists('sip_profiles')) { } //delete multiple records - if (is_array($records) && @sizeof($records) != 0) { + if (!empty($records) && @sizeof($records) != 0) { //filter out unchecked sip profiles, build the delete array foreach ($records as $x => $record) { - if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid']; $array[$this->table][$x]['sip_profile_uuid'] = $this->sip_profile_uuid; } } //get necessary sip profile details - if (is_uuid($this->sip_profile_uuid)) { + if (!empty($this->sip_profile_uuid) && is_uuid($this->sip_profile_uuid)) { $sql = "select sip_profile_hostname from v_sip_profiles "; $sql .= "where sip_profile_uuid = :sip_profile_uuid "; $parameters['sip_profile_uuid'] = $this->sip_profile_uuid; @@ -298,7 +298,7 @@ if (!class_exists('sip_profiles')) { } //delete the checked rows - if (is_array($array) && @sizeof($array) != 0) { + if (!empty($array) && @sizeof($array) != 0) { //execute delete $database = new database; @@ -356,11 +356,11 @@ if (!class_exists('sip_profiles')) { //get current toggle state foreach ($records as $x => $record) { - if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { $uuids[] = "'".$record['uuid']."'"; } } - if (is_array($uuids) && @sizeof($uuids) != 0) { + if (!empty($uuids) && @sizeof($uuids) != 0) { $sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, sip_profile_hostname from v_".$this->table." "; $sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") "; $database = new database; @@ -383,7 +383,7 @@ if (!class_exists('sip_profiles')) { } //save the changes - if (is_array($array) && @sizeof($array) != 0) { + if (!empty($array) && @sizeof($array) != 0) { //save the array $database = new database; @@ -410,7 +410,7 @@ if (!class_exists('sip_profiles')) { } //clear the cache - if (is_array($hostnames) && @sizeof($hostnames) != 0) { + if (!empty($hostnames) && @sizeof($hostnames) != 0) { $hostnames = array_unique($hostnames); $cache = new cache; foreach ($hostnames as $hostname) { diff --git a/app/sip_profiles/sip_profile_edit.php b/app/sip_profiles/sip_profile_edit.php index 54fc022fee..6293a7bd98 100644 --- a/app/sip_profiles/sip_profile_edit.php +++ b/app/sip_profiles/sip_profile_edit.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2016-2020 + Portions created by the Initial Developer are Copyright (C) 2016-2023 the Initial Developer. All Rights Reserved. Contributor(s): @@ -46,19 +46,31 @@ $text = $language->get(); //action add or update - if (is_uuid($_REQUEST["id"])) { + if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { $action = "update"; $sip_profile_uuid = $_REQUEST["id"]; } else { $action = "add"; + $sip_profile_uuid = uuid(); } +//set the defaults + $sip_profile_uuid = ''; + $sip_profile_name = ''; + $sip_profile_hostname = ''; + $sip_profile_enabled = 'false'; + $sip_profile_description = ''; + $sip_profile_domains = []; + $sip_profile_settings = []; + $sip_profile_domains_delete = []; + $sip_profile_settings_delete = []; + //get http post variables and set them to php variables - if (count($_POST) > 0) { + if (!empty($_POST)) { //process the http post data by submitted action - if ($_POST['action'] != '' && is_uuid($_POST['sip_profile_uuid'])) { + if (!empty($_POST['action']) && is_uuid($_POST['sip_profile_uuid'])) { $array[0]['checked'] = 'true'; $array[0]['uuid'] = $_POST['sip_profile_uuid']; @@ -75,15 +87,16 @@ exit; } - $sip_profile_uuid = $_POST["sip_profile_uuid"]; - $sip_profile_name = $_POST["sip_profile_name"]; - $sip_profile_hostname = $_POST["sip_profile_hostname"]; - $sip_profile_enabled = $_POST["sip_profile_enabled"] ?: 'false'; - $sip_profile_description = $_POST["sip_profile_description"]; - $sip_profile_domains = $_POST["sip_profile_domains"]; - $sip_profile_settings = $_POST["sip_profile_settings"]; - $sip_profile_domains_delete = $_POST["sip_profile_domains_delete"]; - $sip_profile_settings_delete = $_POST["sip_profile_settings_delete"]; + //get the HTTP values + $sip_profile_uuid = $_POST["sip_profile_uuid"]; + $sip_profile_name = $_POST["sip_profile_name"]; + $sip_profile_hostname = $_POST["sip_profile_hostname"]; + $sip_profile_enabled = $_POST["sip_profile_enabled"] ?: 'false'; + $sip_profile_description = $_POST["sip_profile_description"]; + $sip_profile_domains = $_POST["sip_profile_domains"]; + $sip_profile_settings = $_POST["sip_profile_settings"]; + $sip_profile_domains_delete = $_POST["sip_profile_domains_delete"]; + $sip_profile_settings_delete = $_POST["sip_profile_settings_delete"]; } //process the user data and save it to the database @@ -129,13 +142,13 @@ } $database = new database; $rows = $database->select($sql, $parameters, 'all'); - if (is_array($rows) && @sizeof($rows) != 0) { + if (!empty($rows) && @sizeof($rows) != 0) { foreach ($rows as $array) { $sip_profile_names[] = $array['sip_profile_name']; } } unset($sql); - if (is_array($sip_profile_names) && @sizeof($sip_profile_names) != 0 && in_array($sip_profile_name, $sip_profile_names)) { + if (!empty($sip_profile_names) && @sizeof($sip_profile_names) != 0 && in_array($sip_profile_name, $sip_profile_names)) { //set message message::add($text['message-sip_profile_unique'], 'negative', 5000); @@ -178,7 +191,7 @@ $y = 0; foreach ($sip_profile_settings as $row) { if (!empty($row['sip_profile_setting_uuid'])) { - if (is_uuid($row['sip_profile_setting_uuid'])) { + if (!empty($row['sip_profile_setting_uuid']) && is_uuid($row['sip_profile_setting_uuid'])) { $sip_profile_setting_uuid = $row['sip_profile_setting_uuid']; } else { @@ -216,7 +229,7 @@ if ( $action == 'update' && permission_exists('sip_profile_domain_delete') - && is_array($sip_profile_domains_delete) + && !empty($sip_profile_domains_delete) && @sizeof($sip_profile_domains_delete) != 0 ) { $obj = new sip_profiles; @@ -228,7 +241,7 @@ if ( $action == 'update' && permission_exists('sip_profile_setting_delete') - && is_array($sip_profile_settings_delete) + && !empty($sip_profile_settings_delete) && @sizeof($sip_profile_settings_delete) != 0 ) { $obj = new sip_profiles; @@ -266,7 +279,7 @@ } //pre-populate the form - if (is_array($_GET) && $_POST["persistformvar"] != "true") { + if (!empty($_GET["id"]) && empty($_POST["persistformvar"])) { $sip_profile_uuid = $_GET["id"]; $sql = "select * from v_sip_profiles "; $sql .= "where sip_profile_uuid = :sip_profile_uuid "; @@ -296,8 +309,8 @@ //add an empty row if (permission_exists('sip_profile_setting_add')) { - $x = count($sip_profile_settings); - $sip_profile_settings[$x]['sip_profile_setting_uuid'] = ''; + $x = empty($sip_profile_settings) ? 0 : count($sip_profile_settings); + $sip_profile_settings[$x]['sip_profile_setting_uuid'] = uuid(); $sip_profile_settings[$x]['sip_profile_uuid'] = $sip_profile_uuid; $sip_profile_settings[$x]['sip_profile_setting_name'] = ''; $sip_profile_settings[$x]['sip_profile_setting_value'] = ''; @@ -315,8 +328,8 @@ //add an empty row if (permission_exists('sip_profile_domain_add')) { - $x = count($sip_profile_domains); - $sip_profile_domains[$x]['sip_profile_domain_uuid'] = ''; + $x = empty($sip_profile_domains) ? 0 : count($sip_profile_domains); + $sip_profile_domains[$x]['sip_profile_domain_uuid'] = uuid(); $sip_profile_domains[$x]['sip_profile_uuid'] = $sip_profile_uuid; $sip_profile_domains[$x]['sip_profile_domain_name'] = ''; $sip_profile_domains[$x]['sip_profile_domain_alias'] = ''; @@ -326,7 +339,7 @@ //create js array of existing sip profile names to prevent duplicates $sql = "select sip_profile_name from v_sip_profiles"; $database = new database; - $rows = $database->select($sql, $parameters, 'all'); + $rows = $database->select($sql, null, 'all'); if (is_array($rows) && @sizeof($rows) != 0) { foreach ($rows as $array) { $sip_profile_names[] = $array['sip_profile_name']; @@ -357,18 +370,18 @@ echo "\n"; @@ -388,15 +401,14 @@ || permission_exists('time_condition_add') ) { echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'name'=>'btn_copy','style'=>$button_margin,'onclick'=>"modal_open('modal-copy','new_profile_name');"]); - unset($button_margin); } if ( permission_exists('sip_profile_delete') || permission_exists('sip_profile_domain_delete') || permission_exists('sip_profile_setting_delete') ) { + $button_margin = 'margin-left: 3px;'; echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','style'=>$button_margin,'onclick'=>"modal_open('modal-delete','btn_delete');"]); - unset($button_margin); } } echo button::create(['type'=>'button','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','style'=>'margin-left: 15px;','onclick'=>"if (document.getElementById('sip_profile_name').value != '' && !sip_profile_names_other.includes(document.getElementById('sip_profile_name').value)) { $('#frm').submit(); } else { display_message('".$text['message-sip_profile_unique']."', 'negative', 5000); }"]); @@ -461,8 +473,7 @@ echo " ".$text['label-sip_profile_domain_name']."\n"; echo " ".$text['label-sip_profile_domain_alias']."\n"; echo " ".$text['label-sip_profile_domain_parse']."\n"; - if ( - permission_exists('sip_profile_domain_delete') && ( + if (permission_exists('sip_profile_domain_delete') && ( (permission_exists('sip_profile_domain_add') && is_array($sip_profile_domains) && @sizeof($sip_profile_domains) > 1) || (!permission_exists('sip_profile_domain_add') && is_array($sip_profile_domains) && @sizeof($sip_profile_domains) != 0) )) { @@ -474,19 +485,22 @@ echo " \n"; $x = 0; foreach ($sip_profile_domains as $row) { - $bottom_border = !is_uuid($row['sip_profile_domain_uuid']) ? "border-bottom: none;" : null; + $bottom_border = empty($row['sip_profile_domain_uuid']) ? "border-bottom: none;" : null; echo " \n"; - if (is_uuid($row["sip_profile_uuid"])) { + if (!empty($sip_profile_uuid) && is_uuid($row["sip_profile_uuid"])) { $sip_profile_uuid = $row["sip_profile_uuid"]; } - echo " \n"; + $label_sip_profile_domain_alias = !empty($row["sip_profile_domain_alias"]) ? $text['label-'.$row["sip_profile_domain_alias"]] : ''; + $label_sip_profile_domain_parse = !empty($row["sip_profile_domain_alias"]) ? $text['label-'.$row["sip_profile_domain_alias"]] : ''; + + 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 (permission_exists('sip_profile_domain_delete')) { - if (is_uuid($row['sip_profile_domain_uuid'])) { + if (!empty($sip_profile_uuid) && is_uuid($row['sip_profile_domain_uuid'])) { echo " "; echo " \n"; echo " \n"; @@ -514,7 +528,7 @@ } echo " \n"; //convert last empty labels to form elements - if (permission_exists('sip_profile_domain_add') && !is_uuid($row["sip_profile_domain_uuid"])) { + if (permission_exists('sip_profile_domain_add') && empty($row["sip_profile_domain_uuid"])) { echo "