Fixed the update of alert command usability.

This commit is contained in:
mdtrooper 2015-03-09 16:17:57 +01:00
parent 1141127a34
commit f475dc80bd
2 changed files with 81 additions and 68 deletions

View File

@ -34,7 +34,10 @@ if (defined('METACONSOLE'))
else
$sec = 'galertas';
$pure = get_parameter('pure', 0);
$pure = (int)get_parameter('pure', 0);
$update_command = (bool) get_parameter ('update_command');
$create_command = (bool) get_parameter ('create_command');
$delete_command = (bool) get_parameter ('delete_command');
if (is_ajax ()) {
$get_alert_command = (bool) get_parameter ('get_alert_command');
@ -125,6 +128,12 @@ if (is_ajax ()) {
return;
}
if ($update_command) {
require_once("configure_alert_command.php");
return;
}
// Header
if (defined('METACONSOLE'))
alerts_meta_print_header();
@ -133,9 +142,7 @@ else
enterprise_hook('open_meta_frame');
$update_command = (bool) get_parameter ('update_command');
$create_command = (bool) get_parameter ('create_command');
$delete_command = (bool) get_parameter ('delete_command');
if ($create_command) {
$name = (string) get_parameter ('name');
@ -180,57 +187,6 @@ if ($create_command) {
__('Could not be created'));
}
if ($update_command) {
$id = (int) get_parameter ('id');
$alert = alerts_get_alert_command ($id);
if ($alert['internal']) {
db_pandora_audit("ACL Violation", "Trying to access Alert Management");
require ("general/noaccess.php");
exit;
}
$name = (string) get_parameter ('name');
$command = (string) get_parameter ('command');
$description = (string) get_parameter ('description');
$fields_descriptions = array();
$fields_values = array();
$info_fields = '';
$values = array();
for ($i=1;$i<=10;$i++) {
$fields_descriptions[] = (string) get_parameter ('field'.$i.'_description');
$fields_values[] = (string) get_parameter ('field'.$i.'_values');
$info_fields .= ' Field'.$i.': ' . $fields_values[$i - 1];
}
$values['fields_values'] = io_json_mb_encode($fields_values);
$values['fields_descriptions'] = io_json_mb_encode($fields_descriptions);
$values['name'] = $name;
$values['command'] = $command;
$values['description'] = $description;
//Check it the new name is used in the other command.
$id_check = db_get_value ('id', 'talert_commands', 'name', $name);
if (($id_check != $id) && (!empty($id_check))) {
$result = '';
}
else {
$result = alerts_update_alert_command ($id, $values);
$info = 'Name: ' . $name . ' Command: ' . $command . ' Description: ' . $description. ' ' .$info_fields;
}
if ($result) {
db_pandora_audit("Command management", "Update alert command #" . $id, false, false, $info);
}
else {
db_pandora_audit("Command management", "Fail to update alert command #" . $id, false, false);
}
ui_print_result_message ($result,
__('Successfully updated'),
__('Could not be updated'));
}
if ($delete_command) {
$id = (int) get_parameter ('id');
@ -255,6 +211,8 @@ if ($delete_command) {
ui_print_result_message ($result,
__('Successfully deleted'),
__('Could not be deleted'));
}
$table->width = '98%';

View File

@ -15,6 +15,7 @@
// Load global vars
global $config;
require_once ($config['homedir'] . "/include/functions_alerts.php");
enterprise_include_once ('meta/include/functions_alerts_meta.php');
@ -27,9 +28,72 @@ if (! check_acl ($config['id_user'], 0, "LM")) {
exit;
}
$update_command = (bool) get_parameter ('update_command');
$id = (int) get_parameter ('id');
$pure = get_parameter('pure', 0);
// Header
if (defined('METACONSOLE'))
alerts_meta_print_header();
else
ui_print_page_header (__('Alerts') . ' &raquo; ' .
__('Configure alert command'), "images/gm_alerts.png", false, "alerts_config", true);
enterprise_hook('open_meta_frame');
if ($update_command) {
$id = (int) get_parameter ('id');
$alert = alerts_get_alert_command ($id);
if ($alert['internal']) {
db_pandora_audit("ACL Violation", "Trying to access Alert Management");
require ("general/noaccess.php");
exit;
}
$name = (string) get_parameter ('name');
$command = (string) get_parameter ('command');
$description = (string) get_parameter ('description');
$fields_descriptions = array();
$fields_values = array();
$info_fields = '';
$values = array();
for ($i=1;$i<=10;$i++) {
$fields_descriptions[] = (string) get_parameter ('field'.$i.'_description');
$fields_values[] = (string) get_parameter ('field'.$i.'_values');
$info_fields .= ' Field'.$i.': ' . $fields_values[$i - 1];
}
$values['fields_values'] = io_json_mb_encode($fields_values);
$values['fields_descriptions'] = io_json_mb_encode($fields_descriptions);
$values['name'] = $name;
$values['command'] = $command;
$values['description'] = $description;
//Check it the new name is used in the other command.
$id_check = db_get_value ('id', 'talert_commands', 'name', $name);
if (($id_check != $id) && (!empty($id_check))) {
$result = '';
}
else {
$result = alerts_update_alert_command ($id, $values);
$info = 'Name: ' . $name . ' Command: ' . $command . ' Description: ' . $description. ' ' .$info_fields;
}
if ($result) {
db_pandora_audit("Command management", "Update alert command #" . $id, false, false, $info);
}
else {
db_pandora_audit("Command management", "Fail to update alert command #" . $id, false, false);
}
ui_print_result_message ($result,
__('Successfully updated'),
__('Could not be updated'));
}
$name = '';
$command = '';
$description = '';
@ -53,15 +117,6 @@ if(!empty($fields_values)) {
$fields_values = json_decode($fields_values, true);
}
// Header
if (defined('METACONSOLE'))
alerts_meta_print_header();
else
ui_print_page_header (__('Alerts') . ' &raquo; ' .
__('Configure alert command'), "images/gm_alerts.png", false, "alerts_config", true);
enterprise_hook('open_meta_frame');
$table->width = '98%';
$table->style = array ();
$table->style[0] = 'font-weight: bold';