From 89940d403cdaf891ff01f3ff6c5a8654dc4c22d8 Mon Sep 17 00:00:00 2001 From: juanmanuelr Date: Wed, 1 Feb 2012 10:57:43 +0000 Subject: [PATCH] 2012-02-01 Juan Manuel Ramon * operation/incidents/incident.php: removed trace. * operation/agentes/alerts_status.php index.php operation/users/user_edit.php general/shortcut_bar.php: Added shortcut bar. * pandoradb.sql pandoradb.postgreSQL.sql pandoradb.oracle.sql extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql: Added shorcut field in tusuario table. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5457 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 17 ++ .../pandoradb_migrate_4.0.x_to_4.1.mysql.sql | 1 + .../pandoradb_migrate_4.0.x_to_4.1.oracle.sql | 3 +- ...doradb_migrate_4.0.x_to_4.1.postgreSQL.sql | 1 + pandora_console/general/shortcut_bar.php | 273 ++++++++++++++++++ pandora_console/index.php | 10 +- .../operation/agentes/alerts_status.php | 14 + .../operation/incidents/incident.php | 2 +- pandora_console/operation/users/user_edit.php | 29 ++ pandora_console/pandoradb.oracle.sql | 3 +- pandora_console/pandoradb.postgreSQL.sql | 3 +- pandora_console/pandoradb.sql | 1 + 12 files changed, 349 insertions(+), 8 deletions(-) create mode 100644 pandora_console/general/shortcut_bar.php diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index c8345d3775..9ec624d72f 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,20 @@ +2012-02-01 Juan Manuel Ramon + + * operation/incidents/incident.php: removed trace. + + * operation/agentes/alerts_status.php + index.php + operation/users/user_edit.php + general/shortcut_bar.php: Added shortcut bar. + + * pandoradb.sql + pandoradb.postgreSQL.sql + pandoradb.oracle.sql + extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql + extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql + extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql: Added shorcut + field in tusuario table. + 2012-01-31 Juan Manuel Ramon * include/functions_reporting: Fixed bug when the module has only diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql index 6b88c04c89..3bfd204bf6 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql @@ -54,6 +54,7 @@ CREATE TABLE IF NOT EXISTS `tnetflow_report_content` ( -- ----------------------------------------------------- ALTER TABLE `tusuario` ADD COLUMN `disabled` int(4) NOT NULL DEFAULT 0; +ALTER TABLE `tusuario` ADD COLUMN `shortcut` tinyint(1) DEFAULT 0; -- ----------------------------------------------------- -- Table `tincidencia` diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql index 75c8929940..8ff2ad5bf0 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql @@ -3,7 +3,8 @@ -- ----------------------------------------------------- alter table tusuario add (disabled NUMBER(10,0) default 0 NOT NULL); - +alter table tusuario add (shortcut NUMBER(5, 0) DEFAULT 0); + -- ----------------------------------------------------- -- Table "tnetflow_filter" -- ----------------------------------------------------- diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql index 138cf20655..f3f06b1074 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql @@ -3,6 +3,7 @@ -- ----------------------------------------------------- ALTER TABLE "tusuario" ADD COLUMN "disabled" INTEGER NOT NULL DEFAULT 0; +ALTER TABLE "tusuario" ADD COLUMN "shortcut" SMALLINT DEFAULT 0; -- ----------------------------------------------------- -- Table `tnetflow_filter` diff --git a/pandora_console/general/shortcut_bar.php b/pandora_console/general/shortcut_bar.php new file mode 100644 index 0000000000..fbbcb900d5 --- /dev/null +++ b/pandora_console/general/shortcut_bar.php @@ -0,0 +1,273 @@ + $config['id_user'])); + + // If shortcut bar is disabled return to index.php + if ($shortcut_state == 0) + return; + + if (is_ajax()) { + require_once("include/functions_events.php"); + + + $update_shortcut_state = get_parameter('update_shortcut_state', 0); + $get_critical_events = get_parameter('get_critical_events', 0); + $get_opened_incidents = get_parameter('get_opened_incidents', 0); + + // Update if shortcut is visible or hidden + if ($update_shortcut_state){ + $value = get_parameter('value', 0); + db_process_sql_update('tusuario', array('shortcut' => $value), array('id_user' => $config['id_user'])); + } + + // Get critical events (realtime update) + if ($get_critical_events){ + $own_info = get_user_info ($config['id_user']); + + if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM")) + $own_groups = array_keys(users_get_groups($config['id_user'], "LM")); + else + $own_groups = array_keys(users_get_groups($config['id_user'], "LM", false)); + + // Get events in the last 8 hours + $shortcut_events_update = events_get_group_events($own_groups, 28800, time()); + if ($shortcut_events_update == false) + $shortcut_events_update = array(); + + $critical_events_update = 0; + foreach($shortcut_events_update as $event_update){ + if ($event_update['criticity'] == 4 and $event_update['estado'] == 0){ + $critical_events++; + } + } + + echo $critical_events_update; + } + + // Select only opened incidents + if ($get_opened_incidents){ + $own_info = get_user_info ($config['id_user']); + + if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM")) + $own_groups = array_keys(users_get_groups($config['id_user'], "LM")); + else + $own_groups = array_keys(users_get_groups($config['id_user'], "LM", false)); + + $sql = "SELECT count(*) total_incidents FROM tincidencia WHERE + id_grupo IN (".implode (",",array_keys ($own_groups)).") AND estado IN (0) + ORDER BY actualizacion"; + + $result_incidents_update = db_get_all_rows_sql ($sql); + + + if ($result_incidents_update === false) + $shortcut_incidents = 0; + else + $shortcut_incidents = $result_incidents_update[0]['total_incidents']; + + echo $shortcut_incidents; + } + + return; + } + + if ($shortcut_state == 2){ + echo "
"; + }else{ + echo "
"; + } + html_print_image("images/pandora_textlogo.png", false, array("title" => __("Press here to activate shortcut bar"))); + echo "
"; + if ($shortcut_state == 2){ + echo "
"; + } else { + echo "
"; + } + + echo "     "; + echo ""; + html_print_image("images/bell.png", false, array("title" => __("Alerts fired"))); + echo " "; + + // Calculate alerts fired + $data_reporting = reporting_get_group_stats(); + + echo "" . $data_reporting['monitor_alerts_fired'] . ""; + echo ""; + echo "     "; + echo ""; + html_print_image("images/lightning_go.png", false, array("title" => __("Critical events"))); + echo " "; + + // Calculate critical events (not validated) + $own_info = get_user_info ($config['id_user']); + + if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM")) + $own_groups = array_keys(users_get_groups($config['id_user'], "LM")); + else + $own_groups = array_keys(users_get_groups($config['id_user'], "LM", false)); + + // Get events in the last 8 hours + $shortcut_events = events_get_group_events($own_groups, 28800, time()); + if ($shortcut_events == false) + $shortcut_events = array(); + + $critical_events = 0; + foreach($shortcut_events as $event){ + if ($event['criticity'] == 4 and $event['estado'] == 0){ + $critical_events++; + } + } + + echo "" . $critical_events . ""; + echo ""; + echo "     "; + // Calculate opened incidents (id integria incidents are not enabled) + if ($config['integria_enabled'] == 0){ + echo ""; + html_print_image("images/book_edit.png", false, array("title" => __("Incidents opened"))); + echo " "; + // Select only opened incidents + $sql = "SELECT count(*) total_incidents FROM tincidencia WHERE + id_grupo IN (".implode (",",array_keys ($own_groups)).") AND estado IN (0) + ORDER BY actualizacion"; + + $result_incidents = db_get_all_rows_sql ($sql); + + + if ($result_incidents === false) + $shortcut_incidents = 0; + else + $shortcut_incidents = $result_incidents[0]['total_incidents']; + + + echo "" . $shortcut_incidents . ""; + echo ""; + echo "     "; + } + echo "   "; + echo "|"; + echo "    "; + echo "    "; + + echo ""; + html_print_image("images/reporting.png", false, array("title" => __("View reports"))); + echo ""; + + echo "     "; + + echo ""; + html_print_image("images/email.png", false, array("title" => __("Create new message"))); + echo ""; + + // Login in Console and shortcut bar is disabled + // This will show and hide the shortcut value in Javascript code + if (isset($_POST['nick']) and $shortcut_state != 2){ + html_print_input_hidden("login_console", 1); + } else { + html_print_input_hidden("login_console", 0); + } + + html_print_input_hidden("shortcut_id_user", $config['id_user']); + echo "
"; + +?> + + diff --git a/pandora_console/index.php b/pandora_console/index.php index 05e50b03cd..978a1e66fe 100644 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -21,7 +21,7 @@ if (function_exists ('mb_internal_encoding')) { // Set to 1 to do not check for installer or config file (for development!). // Activate gives more error information, not useful for production sites -$develop_bypass = 0; +$develop_bypass = 1; if ($develop_bypass != 1) { // If no config file, automatically try to install @@ -96,8 +96,7 @@ if (!empty ($config["https"]) && empty ($_SERVER['HTTPS'])) { $config["pure"] = (bool) get_parameter ("pure"); // Auto Refresh page (can now be disabled anywhere in the script) -$config["refr"] = (int) get_parameter ("refr"); - +$config["refr"] = (int) get_parameter ("refr", $config["refr"]); ob_start (); echo ''."\n"; @@ -160,6 +159,7 @@ elseif (! isset ($config['id_user']) && isset ($_GET["login"])) { $pass = get_parameter_post ("pass"); //This is the variable with the password $nick = db_escape_string_sql($nick); $pass = db_escape_string_sql($pass); + // process_user_login is a virtual function which should be defined in each auth file. // It accepts username and password. The rest should be internal to the auth file. // The auth file can set $config["auth_error"] to an informative error output or reference their internal error messages to it @@ -194,6 +194,7 @@ elseif (! isset ($config['id_user']) && isset ($_GET["login"])) { } elseif (! isset ($config['id_user'])) { // There is no user connected + require_once ('general/login_page.php'); while (@ob_end_flush ()); exit (""); @@ -221,7 +222,7 @@ extensions_load_extensions ($config['extensions']); // Header if ($config["pure"] == 0) { echo '
'; @@ -267,6 +268,7 @@ else { else echo '
'.__('Sorry! I can\'t find the page!').''; } else require ("general/logon_ok.php"); + require("general/shortcut_bar.php"); } if ($config["pure"] == 0) { diff --git a/pandora_console/operation/agentes/alerts_status.php b/pandora_console/operation/agentes/alerts_status.php index bf34318695..71b110a547 100644 --- a/pandora_console/operation/agentes/alerts_status.php +++ b/pandora_console/operation/agentes/alerts_status.php @@ -18,6 +18,20 @@ global $config; // Login check check_login (); +if (is_ajax()){ + require_once("include/functions_reporting.php"); + + $get_alert_fired = get_parameter("get_alert_fired", 0); + + if ($get_alert_fired){ + // Calculate alerts fired + $data_reporting = reporting_get_group_stats(); + echo $data_reporting['monitor_alerts_fired']; + } + + return; +} + require_once ("include/functions_agents.php"); require_once ('operation/agentes/alerts_status.functions.php'); require_once ('include/functions_users.php'); diff --git a/pandora_console/operation/incidents/incident.php b/pandora_console/operation/incidents/incident.php index ca30d91f34..18aad4ccb0 100755 --- a/pandora_console/operation/incidents/incident.php +++ b/pandora_console/operation/incidents/incident.php @@ -125,7 +125,7 @@ elseif ($action == "insert") { $sql = sprintf ("INSERT INTO tincidencia (inicio, actualizacion, titulo, descripcion, id_usuario, origen, estado, prioridad, id_grupo, id_creator, id_agent) VALUES (NOW(), NOW(), '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', %d)", $titulo, $descripcion, $config["id_user"], $origen, $estado, $prioridad, $grupo, $config["id_user"], $id_agent); $id_inc = db_process_sql ($sql, "insert_id"); -html_debug_print($sql); + if ($id_inc === false) { echo '

'.__('Error creating incident').'

'; } diff --git a/pandora_console/operation/users/user_edit.php b/pandora_console/operation/users/user_edit.php index dbba1bb165..1ef6fedf23 100644 --- a/pandora_console/operation/users/user_edit.php +++ b/pandora_console/operation/users/user_edit.php @@ -42,9 +42,34 @@ if (($config["id_user"] == $id || check_acl ($config["id_user"], users_get_group $view_mode = true; } +if (is_ajax ()){ + + $shortcut_update = get_parameter("shortcut_update", 0); + + // Update of user to show/don't show shortcut bar + if ($shortcut_update){ + + // First we get the actual state + $shortcut_value = db_get_value_filter('shortcut', 'tusuario', array('id_user' => $id)); + + //Deactivate shorcut var + if ($shortcut_value == 1){ + db_process_sql_update('tusuario', array('shortcut' => 0), array('id_user' => $id)); + } + // Activate shortcut var + else { + db_process_sql_update('tusuario', array('shortcut' => 1), array('id_user' => $id)); + } + + } + + return; +} + // Header ui_print_page_header (__('User detail editor'), "images/group.png", false, "", false, ""); +// Update user info if (isset ($_GET["modified"]) && !$view_mode) { $upd_info = array (); $upd_info["fullname"] = get_parameter_post ("fullname", $user_info["fullname"]); @@ -64,6 +89,7 @@ if (isset ($_GET["modified"]) && !$view_mode) { } $upd_info["flash_chart"] = get_parameter ("flash_charts", $config["flash_charts"]); + $upd_info["shortcut"] = get_parameter ("shortcut_bar", 0); if ( !empty ($password_new)) { if ($config["user_can_update_password"] && $password_confirm == $password_new) { @@ -197,6 +223,9 @@ echo html_print_input_text ('block_size', $block_size, '', 5, 5, true); echo html_print_checkbox('default_block_size', 1, $user_info["block_size"] == 0, true); echo __('Default').' ('.$config["global_block_size"].')'; +echo ''.__('Shortcut bar') . ui_print_help_tip(__('This will activate a shortcut bar with alerts, events, messages... information'), true) . ''; +echo html_print_checkbox('shortcut_bar', 1, $user_info["shortcut"], true); + echo ''; echo '
'; diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index 30798c6824..2392cae7ad 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -856,7 +856,8 @@ CREATE TABLE tusuario ( block_size NUMBER(10, 0) default 20 NOT NULL, flash_chart NUMBER(10, 0) default 1 NOT NULL, id_skin NUMBER(10, 0) DEFAULT 0 NOT NULL, - disabled NUMBER(10, 0) default 0 NOT NULL + disabled NUMBER(10, 0) default 0 NOT NULL, + shortcut NUMBER(5, 0) DEFAULT 0 ); CREATE TABLE tusuario_perfil ( diff --git a/pandora_console/pandoradb.postgreSQL.sql b/pandora_console/pandoradb.postgreSQL.sql index 9f7b91e818..627be42216 100644 --- a/pandora_console/pandoradb.postgreSQL.sql +++ b/pandora_console/pandoradb.postgreSQL.sql @@ -686,7 +686,8 @@ CREATE TABLE "tusuario" ( "block_size" INTEGER NOT NULL default 20, "flash_chart" INTEGER NOT NULL default 1, "id_skin" INTEGER NOT NULL DEFAULT 0, - "disabled" INTEGER NOT NULL default 1 + "disabled" INTEGER NOT NULL default 1, + "shortcut" SMALLINT DEFAULT 0 ); CREATE TABLE "tusuario_perfil" ( diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index c6aee04421..0c92b54dd7 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -762,6 +762,7 @@ CREATE TABLE IF NOT EXISTS `tusuario` ( `flash_chart` int(4) NOT NULL DEFAULT 1, `id_skin` int(10) unsigned NOT NULL, `disabled` int(4) NOT NULL DEFAULT 0, + `shortcut` tinyint(1) DEFAULT 0, UNIQUE KEY `id_user` (`id_user`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;