From dc3c36846e009ba5a1ecb989164ab7d01f1dc01d Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 4 Mar 2020 11:24:58 -0700 Subject: [PATCH] SIP Profiles - Edit: Add bulk delete of Domains and Settings, dynamic delete button action. Remove deprecated Domain and Setting delete scripts. --- app/phrases/phrase_edit.php | 1 - .../resources/classes/sip_profiles.php | 161 +++++++++++ .../sip_profile_domain_delete.php | 81 ------ app/sip_profiles/sip_profile_edit.php | 250 +++++++++++------- .../sip_profile_setting_delete.php | 69 ----- 5 files changed, 316 insertions(+), 246 deletions(-) delete mode 100644 app/sip_profiles/sip_profile_domain_delete.php delete mode 100644 app/sip_profiles/sip_profile_setting_delete.php diff --git a/app/phrases/phrase_edit.php b/app/phrases/phrase_edit.php index 14f2a5db2b..ef8881c68d 100644 --- a/app/phrases/phrase_edit.php +++ b/app/phrases/phrase_edit.php @@ -73,7 +73,6 @@ exit; } - if (permission_exists('phrase_domain')) { $domain_uuid = $_POST["domain_uuid"]; } diff --git a/app/sip_profiles/resources/classes/sip_profiles.php b/app/sip_profiles/resources/classes/sip_profiles.php index b24f876205..9cf583b2d5 100644 --- a/app/sip_profiles/resources/classes/sip_profiles.php +++ b/app/sip_profiles/resources/classes/sip_profiles.php @@ -40,6 +40,11 @@ if (!class_exists('sip_profiles')) { private $toggle_field; private $toggle_values; + /** + * declare public variables + */ + public $sip_profile_uuid; + /** * called when the object is created */ @@ -182,6 +187,162 @@ if (!class_exists('sip_profiles')) { } } + public function delete_domains($records) { + //assign private variables + $this->permission_prefix = 'sip_profile_domain_'; + $this->list_page = 'sip_profile_edit.php?id='.$this->sip_profile_uuid; + $this->table = 'sip_profile_domains'; + $this->uuid_prefix = 'sip_profile_domain_'; + + if (permission_exists($this->permission_prefix.'delete')) { + + //add multi-lingual support + $language = new text; + $text = $language->get(); + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: '.$this->list_page); + exit; + } + + //delete multiple records + if (is_array($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'])) { + $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)) { + $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; + $database = new database; + $sip_profile_hostname = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); + } + + //delete the checked rows + if (is_array($array) && @sizeof($array) != 0) { + + //execute delete + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->delete($array); + unset($array); + + //save the sip profile xml + save_sip_profile_xml(); + + //apply settings reminder + $_SESSION["reload_xml"] = true; + + //get system hostname if necessary + if ($sip_profile_hostname == '') { + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + if ($fp) { + $sip_profile_hostname[] = event_socket_request($fp, 'api switchname'); + } + } + + //clear the cache + if ($sip_profile_hostname != '') { + $cache = new cache; + $cache->delete("configuration:sofia.conf:".$sip_profile_hostname); + } + + } + unset($records); + } + } + } + + public function delete_settings($records) { + //assign private variables + $this->permission_prefix = 'sip_profile_setting_'; + $this->list_page = 'sip_profile_edit.php?id='.$this->sip_profile_uuid; + $this->table = 'sip_profile_settings'; + $this->uuid_prefix = 'sip_profile_setting_'; + + if (permission_exists($this->permission_prefix.'delete')) { + + //add multi-lingual support + $language = new text; + $text = $language->get(); + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: '.$this->list_page); + exit; + } + + //delete multiple records + if (is_array($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'])) { + $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)) { + $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; + $database = new database; + $sip_profile_hostname = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); + } + + //delete the checked rows + if (is_array($array) && @sizeof($array) != 0) { + + //execute delete + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->delete($array); + unset($array); + + //save the sip profile xml + save_sip_profile_xml(); + + //apply settings reminder + $_SESSION["reload_xml"] = true; + + //get system hostname if necessary + if ($sip_profile_hostname == '') { + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + if ($fp) { + $sip_profile_hostname[] = event_socket_request($fp, 'api switchname'); + } + } + + //clear the cache + if ($sip_profile_hostname != '') { + $cache = new cache; + $cache->delete("configuration:sofia.conf:".$sip_profile_hostname); + } + + } + unset($records); + } + } + } + /** * toggle records */ diff --git a/app/sip_profiles/sip_profile_domain_delete.php b/app/sip_profiles/sip_profile_domain_delete.php deleted file mode 100644 index d025e49183..0000000000 --- a/app/sip_profiles/sip_profile_domain_delete.php +++ /dev/null @@ -1,81 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2016 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -//includes - require_once "root.php"; - require_once "resources/require.php"; - -//check permissions - require_once "resources/check_auth.php"; - if (permission_exists('sip_profile_domain_delete')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//get the id - $sip_profile_domain_uuid = $_GET["id"]; - -//delete the data - if (is_uuid($sip_profile_domain_uuid)) { - - //get the details of the sip profile - $sql = "select sip_profile_uuid "; - $sql .= "from v_sip_profile_domains "; - $sql .= "where sip_profile_domain_uuid = :sip_profile_domain_uuid "; - $parameters['sip_profile_domain_uuid'] = $sip_profile_domain_uuid; - $database = new database; - $sip_profile_uuid = $database->select($sql, $parameters, 'column'); - - //build array - $array['sip_profile_domains'][0]['sip_profile_domain_uuid'] = $sip_profile_domain_uuid; - - //execute delete - $database = new database; - $database->app_name = 'sip_profiles'; - $database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470'; - $database->delete($array); - unset($array); - - //set message - message::add($text['message-delete']); - - //redirect the user - header('Location: sip_profile_edit.php?id='.$sip_profile_uuid); - exit; - } - -//default redirect - header('Location: sip_profiles.php'); - exit; - -?> \ No newline at end of file diff --git a/app/sip_profiles/sip_profile_edit.php b/app/sip_profiles/sip_profile_edit.php index 2a393cf948..fea3e9749c 100644 --- a/app/sip_profiles/sip_profile_edit.php +++ b/app/sip_profiles/sip_profile_edit.php @@ -53,6 +53,25 @@ //get http post variables and set them to php variables if (is_array($_POST)) { + + //process the http post data by submitted action + if ($_POST['action'] != '' && is_uuid($_POST['sip_profile_uuid'])) { + $array[0]['checked'] = 'true'; + $array[0]['uuid'] = $_POST['sip_profile_uuid']; + + switch ($_POST['action']) { + case 'delete': + if (permission_exists('sip_profile_delete')) { + $obj = new sip_profiles; + $obj->delete($array); + } + break; + } + + header('Location: sip_profiles.php'); + exit; + } + $sip_profile_uuid = $_POST["sip_profile_uuid"]; $sip_profile_name = $_POST["sip_profile_name"]; $sip_profile_hostname = $_POST["sip_profile_hostname"]; @@ -60,6 +79,8 @@ $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 @@ -161,6 +182,34 @@ $database->save($array); $message = $database->message; + //revoke temporary permissions + $p->delete('sip_profile_domain_add', 'temp'); + $p->delete('sip_profile_setting_add', 'temp'); + + //remove checked domains + if ( + $action == 'update' + && permission_exists('sip_profile_domain_delete') + && is_array($sip_profile_domains_delete) + && @sizeof($sip_profile_domains_delete) != 0 + ) { + $obj = new sip_profiles; + $obj->sip_profile_uuid = $sip_profile_uuid; + $obj->delete_domains($sip_profile_domains_delete); + } + + //remove checked settings + if ( + $action == 'update' + && permission_exists('sip_profile_setting_delete') + && is_array($sip_profile_settings_delete) + && @sizeof($sip_profile_settings_delete) != 0 + ) { + $obj = new sip_profiles; + $obj->sip_profile_uuid = $sip_profile_uuid; + $obj->delete_settings($sip_profile_settings_delete); + } + //get the hostname if ($sip_profile_hostname == '') { $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); @@ -169,10 +218,6 @@ } } - //revoke temporary permissions - $p->delete('sip_profile_domain_add', 'temp'); - $p->delete('sip_profile_setting_add', 'temp'); - //clear the cache $cache = new cache; $cache->delete("configuration:sofia.conf:".$sip_profile_hostname); @@ -221,13 +266,15 @@ unset($sql, $parameters); //add an empty row - $x = 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'] = ''; - $sip_profile_settings[$x]['sip_profile_setting_enabled'] = ''; - $sip_profile_settings[$x]['sip_profile_setting_description'] = ''; + if (permission_exists('sip_profile_setting_add')) { + $x = count($sip_profile_settings); + $sip_profile_settings[$x]['sip_profile_setting_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'] = ''; + $sip_profile_settings[$x]['sip_profile_setting_enabled'] = ''; + $sip_profile_settings[$x]['sip_profile_setting_description'] = ''; + } //get the child data $sql = "select * from v_sip_profile_domains "; @@ -238,12 +285,14 @@ unset($sql, $parameters); //add an empty row - $x = 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'] = ''; - $sip_profile_domains[$x]['sip_profile_domain_parse'] = ''; + if (permission_exists('sip_profile_domain_add')) { + $x = count($sip_profile_domains); + $sip_profile_domains[$x]['sip_profile_domain_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'] = ''; + $sip_profile_domains[$x]['sip_profile_domain_parse'] = ''; + } //create token $object = new token; @@ -270,16 +319,28 @@ echo "
\n"; echo "
".$text['title-sip_profile']."
\n"; echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'style'=>'margin-right: 15px;','link'=>'sip_profiles.php']); - if ($action == 'update' && ( - permission_exists('dialplan_add') - || permission_exists('inbound_route_add') - || permission_exists('outbound_route_add') - || permission_exists('time_condition_add') - )) { - echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'style'=>'margin-right: 15px;','onclick'=>"var name = prompt('".$text['label-new_sip_profile_name']."'); if (name != null) { window.location='sip_profile_copy.php?id=".urlencode($sip_profile_uuid)."&name=' + name; }"]); + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'link'=>'sip_profiles.php']); + $button_margin = 'margin-left: 15px;'; + if ($action == 'update') { + if ( + permission_exists('dialplan_add') + || permission_exists('inbound_route_add') + || permission_exists('outbound_route_add') + || permission_exists('time_condition_add') + ) { + echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'style'=>$button_margin,'onclick'=>"var name = prompt('".$text['label-new_sip_profile_name']."'); if (name != null) { window.location='sip_profile_copy.php?id=".urlencode($sip_profile_uuid)."&name=' + name; }"]); + unset($button_margin); + } + if ( + permission_exists('sip_profile_delete') + || permission_exists('sip_profile_domain_delete') + || permission_exists('sip_profile_setting_delete') + ) { + echo button::create(['type'=>'submit','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'action','value'=>'delete','style'=>$button_margin,'onclick'=>"if (!confirm('".$text['confirm-delete']."')) { this.blur(); return false; }"]); + unset($button_margin); + } } - echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save']]); + echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'style'=>'margin-left: 15px;']); echo "
\n"; echo "
\n"; echo "
\n"; @@ -302,72 +363,65 @@ echo " ".$text['title-sip_profile_domains']."\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') && ( + (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) + )) { + echo " \n"; + } echo " \n"; $x = 0; foreach ($sip_profile_domains as $row) { + $bottom_border = !is_uuid($row['sip_profile_domain_uuid']) ? "border-bottom: none;" : null; echo " \n"; - if (is_uuid($row["sip_profile_domain_uuid"])) { - $sip_profile_domain_uuid = $row["sip_profile_domain_uuid"]; - } if (is_uuid($row["sip_profile_uuid"])) { $sip_profile_uuid = $row["sip_profile_uuid"]; } - echo " \n"; + echo " \n"; echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; } - echo " \n"; echo " \n"; //convert last empty labels to form elements - if ($row["sip_profile_domain_name"] == '' && $row["sip_profile_domain_alias"] == '' && $row["sip_profile_domain_parse"] == '') { + if (permission_exists('sip_profile_domain_add') && !is_uuid($row["sip_profile_domain_uuid"])) { echo "
 ".$text['label-sip_profile_domain_name']."".$text['label-sip_profile_domain_alias']."".$text['label-sip_profile_domain_parse']."".$text['label-sip_profile_domain_name']."".$text['label-sip_profile_domain_alias']."".$text['label-sip_profile_domain_parse']."\n"; + echo " ".$text['label-delete']."\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["sip_profile_domain_name"]) > 0) { - echo " ".$v_link_label_delete."\n"; + if (permission_exists('sip_profile_domain_delete')) { + if (is_uuid($row['sip_profile_domain_uuid'])) { + echo " "; + echo " \n"; + echo " \n"; + } + else { + echo " \n"; + } + echo "