diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index fe72641fde..b53da681ab 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,35 @@ +2008-12-16 Evi Vanoost + + * general/logon_ok.php, godmode/agentes/modificar_agente.php, + godmode/agentes/planned_downtime.php, + godmode/agentes/manage_recontask.php, godmode/setup/news.php, + operation/agentes/datos_agente.php, operation/agentes/estado_agente.php, + operation/agentes/status_events.php, operation/agentes/tactical.php, + operation/events/events.php, operation/incidents/incidents.php, + operation/incidents/incident_detail.php, operation/messages/message.php: + Function updates and new function definitions + + * include/functions.php: safe_input used utf_decode which gives problems + with foreign chars since everything else is (or should be UTF-8) fixed. + format_datetime is no longer necessary - use print_timestamp for output. + Extended multibyte wrapper functions. + + * include/functions_db.php: give_server_name is now get_server_name; + dame_so_name is now get_os_name; dame_so_icon is now print_os_icon; + show_icon_group is now print_group_icon; give_network_profile_name is now + get_networkprofile_name; smal_event_table is now print_events_table + + * include/functions_events.php: print_events_table was moved here and + fixed. Now calculates the cutoff of event and agent text. + + * include/functions_html.php: Added title to print_table function and + updated documentation. print_timestamp now uses the new function + definitions (array) and handles 0-dates better. print_group_icon and + print_os_icon added and extended. Added print_agent_name. This function + fixes issues that show up when cutting off agent names with multibyte char + + * operation/servers/view_server.php: Rewrite with new functions + 2008-12-16 Esteban Sanchez * include/functions_html.php: Added missing documentation and fixed a diff --git a/pandora_console/general/logon_ok.php b/pandora_console/general/logon_ok.php index ae378a58a8..e83ad788f9 100644 --- a/pandora_console/general/logon_ok.php +++ b/pandora_console/general/logon_ok.php @@ -51,7 +51,7 @@ if ($news !== false) { echo ''; foreach ($news as $article) { echo ''; - echo ''; + echo ''; echo ''; diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index e1ccd525d6..e1eec37af5 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -261,12 +261,11 @@ if (mysql_num_rows($result)){ // Operating System icon - echo ""; + echo ""; // Group icon and name - echo ""; + echo ""; // Description echo ""; // Action diff --git a/pandora_console/godmode/agentes/planned_downtime.php b/pandora_console/godmode/agentes/planned_downtime.php index 74a5d61669..1b3deac086 100644 --- a/pandora_console/godmode/agentes/planned_downtime.php +++ b/pandora_console/godmode/agentes/planned_downtime.php @@ -246,7 +246,8 @@ if ($create_downtime || $update_downtime) { $data[1] = get_db_sql ("SELECT nombre FROM tgrupo WHERE id_grupo = ". $downtime["id_grupo"]); - $data[2] = ' - '.dame_so_name($downtime["id_os"]); + $data[2] = print_os_icon ($downtime["id_os"], true, true); + $data[3] = $downtime["ultimo_contacto"]; $data[4] = ''.give_network_profile_name ($row["id_network_profile"]).'', + ''.get_networkprofile_name ($row["id_network_profile"]).'', // GROUP - '', + print_group_icon ($row["id_group"], true), // INCIDENT (($row["create_incident"] == 1) ? __('Yes') : __('No')), // OS - (($row["id_os"] > 0) ? '' : __('Any')), + (($row["id_os"] > 0) ? print_os_icon ($row["id_os"], false, true) : __('Any')), // INTERVAL human_time_description_raw($row["interval_sweep"]), // ACTION diff --git a/pandora_console/godmode/setup/news.php b/pandora_console/godmode/setup/news.php index e4b54dc173..03e74da05e 100644 --- a/pandora_console/godmode/setup/news.php +++ b/pandora_console/godmode/setup/news.php @@ -31,61 +31,53 @@ if (! give_acl ($config['id_user'], 0, "PM")) { if (isset ($_POST["create"])) { // If create $subject = get_parameter ("subject"); $text = get_parameter ("text"); - $text = safe_sql_string ($text); - - $timestamp = $ahora = date ("Y/m/d H:i:s"); - $author = $config['id_user']; - $sql = "INSERT INTO tnews (subject, text, author, timestamp) VALUES ('$subject','$text', '$author', '$timestamp') "; - $result = mysql_query ($sql); - if (! $result) { - echo "

".__('Not created. Error inserting data')."

"; - } else { - echo "

".__('Created successfully')."

"; - $id_link = mysql_insert_id (); - } + $sql = sprintf ("INSERT INTO tnews (subject, text, author, timestamp) VALUES ('%s', '%s', '%s', NOW()) ", $subject, $text, $config["id_user"]); + $id_link = process_sql ($sql, "insert_id"); + + print_error_message ($id_link, __('Created successfully'), __('Not created. Error inserting data')); } if (isset ($_POST["update"])) { // if update - $id_news = get_parameter ("id_news"); + $id_news = (int) get_parameter ("id_news", 0); $subject = get_parameter ("subject"); $text = get_parameter ("text"); - $timestamp = $ahora = date("Y/m/d H:i:s"); - $sql_update ="UPDATE tnews SET subject = '".$subject."', text ='".$text."', timestamp = '$timestamp' WHERE id_news = '".$id_news."'"; - $result = mysql_query($sql_update); - if (! $result) - echo "

".__('Not updated. Error updating data')."

"; - else - echo "

".__('Updated successfully')."

"; + + $sql = sprintf ("UPDATE tnews SET subject = '%s', text ='%s', timestamp = NOW() WHERE id_news = %d", $subject, $text, $id_news); + + $result = process_sql ($sql); + + print_error_message ($result, __('Updated successfully'), __('Not updated. Error updating data')); } if (isset ($_GET["borrar"])) { // if delete - $id_news = get_parameter ("borrar"); - $sql_delete = "DELETE FROM tnews WHERE id_news = ".$id_news; - $result = mysql_query ($sql_delete); - if (! $result) - echo "

".__('Not deleted. Error deleting data')."

"; - else - echo "

".__('Deleted successfully')."

"; + $id_news = (int) get_parameter ("borrar", 0); + + $sql = sprintf ("DELETE FROM tnews WHERE id_news = %d", $id_news); + + $result = mysql_query ($sql); + + print_error_message ($result, __('Deleted successfully'), __('Not deleted. Error deleting data')); } // Main form view for Links edit if ((isset ($_GET["form_add"])) || (isset ($_GET["form_edit"]))) { if (isset($_GET["form_edit"])) { $creation_mode = 0; - $id_news = get_parameter ("id_news"); - $sql = 'SELECT * FROM tnews WHERE id_news = '.$id_news; - $result = mysql_query ($sql); - if ($row = mysql_fetch_array ($result)) { - $subject = $row["subject"]; - $text = $row["text"]; - $author = $row["author"]; - $timestamp = $row["timestamp"]; + $id_news = (int) get_parameter ("id_news", 0); + + $result = get_db_row ("tnews", "id_news", $id_news); + + if ($result !== false) { + $subject = $result["subject"]; + $text = $result["text"]; + $author = $result["author"]; + $timestamp = $result["timestamp"]; } else { echo "

".__('Name error')."

"; } } else { // form_add - $creation_mode =1; + $creation_mode = 1; $text = ""; $subject = ""; $author = $config['id_user']; diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 82df740e43..5977267c36 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -38,8 +38,9 @@ function pandora_help ($help_id, $return = false) { } /** - * Cleans a string by decoding from UTF-8 and replacing the HTML - * entities. + * Cleans a string by encoding to UTF-8 and replacing the HTML + * entities. UTF-8 is necessary for foreign chars like asian + * and our databases are (or should be) UTF-8 * * @param value String or array of strings to be cleaned. * @@ -52,7 +53,7 @@ function safe_input ($value) { array_walk ($value, 'safe_input'); return $value; } - return htmlentities (utf8_decode ($value), ENT_QUOTES); + return htmlentities (utf8_encode ($value), ENT_QUOTES, "UTF-8"); } /** @@ -362,33 +363,6 @@ function pagination ($count, $url, $offset, $pagination = 0) { echo ""; } - - -/** - * Format a unix timestamp to render a datetime string with specific format - * - * format comes with $config["date_format"] - * - * @param utimestamp Unixtimestamp integer format - * @param alt_format Alternative format, for use insted configþ[] - * - * @return - */ -function format_datetime ($timestamp, $alt_format = "") { - global $config; - - if (!is_int ($timestamp)) { - //Make function format agnostic - $timestamp = strtotime ($timestamp); - } - - if ($alt_format == "") - $alt_format = $config["date_format"]; - - return date ($alt_format, $timestamp); -} - - /** * Format a number with decimals and thousands separator. * @@ -1201,12 +1175,23 @@ function enterprise_include ($filename) { } if (!function_exists ("mb_strtoupper")) { - //Multibyte not loaded + //Multibyte not loaded - use wrapper functions + //You should really load multibyte especially for foreign charsets + function mb_strtoupper ($string, $encoding = false) { return strtoupper ($string); } + function mb_strtolower ($string, $encoding = false) { return strtoupper ($string); } + + function mb_substr ($string, $start, $length, $encoding = false) { + return substr ($string, $start, $length); + } + + function mb_strlen ($string, $encoding = false) { + return strlen ($string); + } } ?> diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 84d29c2454..ba07b903a7 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -774,7 +774,7 @@ function get_alert_last_fire_timestamp_in_period ($id_agent_module, $period, $da * * @return Name of the given server */ -function give_server_name ($id_server) { +function get_server_name ($id_server) { return (string) get_db_value ('name', 'tserver', 'id_server', (int) $id_server); } @@ -838,8 +838,8 @@ function dame_generic_string_data ($id) { * * @return Name of the given operating system. */ -function dame_so_name ($id_os) { - return (string) get_db_value ('name', 'tconfig_os', 'id_os', $id_os); +function get_os_name ($id_os) { + return (string) get_db_value ('name', 'tconfig_os', 'id_os', (int) $id_os); } /** @@ -854,20 +854,6 @@ function update_user_contact ($id_user) { process_sql ($sql); } -/** - * Get the icon of an operating system. - * - * The path of the icons is 'images/' which must be append by the - * caller (including slash and filename extension .png) - * - * @param id_os Operating system id - * - * @return Icon filename of the operating system - */ -function dame_so_icon ($id_os) { - return (string) get_db_value ('icon_name', 'tconfig_os', 'id_os', $id_os); -} - /** * Get the user email * @@ -1082,22 +1068,6 @@ function get_user_groups ($id_user = 0, $privilege = "AR") { return $user_groups; } - -/** - * Get group icon - * - * The path of the icons is 'images/' or 'images/group_small/', which - * must be append by the caller (including slash and filename - * extension .png) - * - * @param id_group Group id - * - * @return Icon filename of the given group - */ -function show_icon_group ($id_group) { - return (string) get_db_value ('icon', 'tgrupo', 'id_grupo', $id_group); -} - /** * Get module type icon. * @@ -1183,7 +1153,7 @@ function give_network_component_group_name ($id_network_component_group) { * * @return Name of the given network profile. */ -function give_network_profile_name ($id_network_profile) { +function get_networkprofile_name ($id_network_profile) { return (string) get_db_value ('name', 'tnetwork_profile', 'id_np', $id_network_profile); } @@ -1985,127 +1955,6 @@ function show_alert_row_mini ($id_combined_alert) { echo "
'.$article["subject"].'
'.__('by').' '.$article["author"].' '.__('at').' '.$article["timestamp"].'
'.__('by').' '.$article["author"].' '.__('at').' '.print_timestamp ($article["timestamp"], true).'
'; echo nl2br ($article["text"]); echo '
- "; + print_os_icon ($row["id_os"], false); + echo " - -   ".get_group_name ($id_grupo)."".print_group_icon ($id_grupo, true)."".$row["comentarios"]."
"; } -/** - * - * - * @param filter - * @param limit - * @param width - * - * @return - */ -function smal_event_table ($filter = "", $limit = 10, $width = 440) { - global $config; - $sql = sprintf ("SELECT * FROM tevento %s - ORDER BY timestamp DESC LIMIT %d", - $filter, $limit); - $result = get_db_all_rows_sql ($sql); - - if ($result === false) { - $result = array (); - echo '
'.__('No events').'
'; - } else { - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - - foreach ($result as $event) { - $id_grupo = $event["id_grupo"]; - if (! give_acl ($config["id_user"], $id_grupo, "AR")) { - continue; - } - - /* Only incident read access to view data ! */ - $tdclass = get_priority_class ($event["criticity"]); - $criticity_label = get_priority_name ($event["criticity"]); - /* Colored box */ - echo ""; - echo ""; - /* Event type */ - echo ""; - // Event description - echo ""; - if ($event["id_agente"] > 0) { - // Agent name - $agent_name = get_agent_name ($event["id_agente"]); - echo ""; - - // for System or SNMP generated alerts - } else { - if ($event["event_type"] == "system") { - echo ""; - } else { - echo ""; - } - } - - // User who validated event - echo ""; - // Timestamp - echo ""; - echo ""; - } - echo "
".__('Latest events')."
".__('St')."".__('Type')."".__('Event name')."".__('Agent name')."".__('User ID')."".__('Timestamp')."
"; - if ($event["estado"] == 0) { - echo ""; - } else { - echo ""; - } - echo ""; - switch ($event["event_type"]) { - case "unknown": - echo ""; - break; - case "alert_recovered": - echo ""; - break; - case "alert_manual_validation": - echo ""; - break; - case "monitor_up": - echo ""; - break; - case "monitor_down": - echo ""; - break; - case "alert_fired": - echo ""; - break; - case "system"; - echo ""; - break; - case "recon_host_detected"; - echo ""; - break; - } - echo ""; - echo substr ($event["evento"],0,45); - if (strlen ($event["evento"]) > 45) { - echo ".."; - } - echo ""; - echo substr ($agent_name, 0, 14); - if (strlen ($agent_name) > 14) - echo ".."; - echo ""; - echo "".__('System')."".__('Alert')."SNMP"; - if ($event["estado"] != 0) { - echo "".substr ($event["id_usuario"],0,8)." ".dame_nombre_real ($event["id_usuario"]).""; - } - echo ""; - echo human_time_comparation ($event["timestamp"]); - echo "
"; - } -} - - /** * *DEPRECATED* use get_server_info instead * Get statistical information for a given server diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 7012bb388b..21de21da9d 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -139,4 +139,138 @@ function create_event ($event, $id_group, $id_agent, $status = 0, $id_user = "", return (int) process_sql ($sql, "insert_id"); } + +/** + * Prints a small event table + * + * @param string $filter SQL WHERE clause + * @param int $limit How many events to show + * @param int $width How wide the table should be + * @param bool $return Prints out HTML if false + * + * @return string HTML with table element + */ +function print_events_table ($filter = "", $limit = 10, $width = 440, $return = false) { + global $config; + + $sql = sprintf ("SELECT * FROM tevento %s ORDER BY timestamp DESC LIMIT %d", $filter, $limit); + $result = get_db_all_rows_sql ($sql); + + if ($result === false) { + $return = '
'.__('No events').'
'; + if ($return === false) { + echo $return; + } + return $return; + } else { + $table->cellpadding = 4; + $table->cellspacing = 4; + $table->width = $width; + $table->class = "databox"; + $table->title = __('Latest events'); + $table->titlestyle = "background-color:#799E48;"; + $table->headclass = array (); + $table->head = array (); + $table->rowclass = array (); + $table->data = array (); + $table->align = array (); + + $table->head[0] = __('St'); + $table->align[0] = "center"; + + $table->head[1] = __('Type'); + $table->headclass[1] = "datos3 f9"; + $table->align[1] = "center"; + + $table->head[2] = __('Event name'); + + $table->head[3] = __('Agent name'); + + $table->head[4] = __('User ID'); + $table->headclass[4] = "datos3 f9"; + $table->align[4] = "center"; + + $table->head[5] = __('Timestamp'); + $table->headclass[5] = "datos3 f9"; + $table->align[5] = "right"; + + foreach ($result as $event) { + if (! give_acl ($config["id_user"], $event["id_grupo"], "AR")) { + continue; + } + $data = array (); + + /* Colored box */ + if ($event["estado"] == 0) { + $data[0] = ''; + } else { + $data[0] = ''; + } + + /* Event type */ + switch ($event["event_type"]) { + case "alert_recovered": + $data[1] = ''; + break; + case "alert_manual_validation": + $data[1] = ''; + break; + case "monitor_up": + $data[1] = ''; + break; + case "monitor_down": + $data[1] = ''; + break; + case "alert_fired": + $data[1] = ''; + break; + case "system"; + $data[1] = ''; + break; + case "recon_host_detected"; + $data[1] = ''; + break; + default: + $data[1] = ''; + break; + } + + // Event description wrap around by default at 44 or ~3 lines (10 seems to be a good ratio to wrap around for most sizes. Smaller number gets longer strings) + $data[2] = ''.safe_input (substr ($event["evento"],0, floor ($width / 10))); + + if (strlen ($event["evento"]) > floor ($width / 10)) { + $data[2] .= "..."; + } + $data[2] .= ''; + + if ($event["id_agente"] > 0) { + // Agent name + $data[3] = print_agent_name ($event["id_agente"], true, floor ($width / 20)); //At 440 this would be be 22 + // for System or SNMP generated alerts + } elseif ($event["event_type"] == "system") { + $data[3] = __('System'); + } else { + $data[3] = __('Alert')."SNMP"; + } + + // User who validated event + if ($event["estado"] != 0) { + $data[4] = print_username ($event["id_usuario"], true); + } else { + $data[4] = ''; + } + + // Timestamp + $data[5] = print_timestamp ($event["timestamp"], true); + + array_push ($table->rowclass, get_priority_class ($event["criticity"])); + array_push ($table->data, $data); + } + + $return = print_table ($table, $return); + unset ($table); + return $return; + } +} + ?> \ No newline at end of file diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 28294b3d0e..a6ac03a850 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -337,7 +337,7 @@ function print_textarea ($name, $rows, $columns, $value = '', $attributes = '', /** * Print a nicely formatted table. Code taken from moodle. * - * @param array $table is an object with several properties: + * @param object $table is an object with several properties: * $table->head - An array of heading names. * $table->align - An array of column alignments * $table->valign - An array of column alignments @@ -356,6 +356,9 @@ function print_textarea ($name, $rows, $columns, $value = '', $attributes = '', * $table->class - CSS table class * $table->id - Table ID (useful in JavaScript) * $table->headclass[] - An array of classes for each heading + * $table->title - Title of the table is a single string that will be on top of the table in the head spanning the whole table + * $table->titlestyle - Title style + * $table->titleclass - Title class * @param bool $return whether to return an output string or echo now * * @return string HTML code if return parameter is true. @@ -451,6 +454,18 @@ function print_table (&$table, $return = false) { if (!empty ($table->head)) { $countcols = count ($table->head); $output .= ''; + + if (isset ($table->title)) { + $output .= 'titlestyle)) { + $output .= ' style="'.$table->titlestyle.'"'; + } + if (isset ($table->titleclass)) { + $output .= ' class="'.$table->titleclass.'"'; + } + $output .= '>'.$table->title.''; + } + foreach ($table->head as $key => $heading) { if (!isset ($size[$key])) { $size[$key] = ''; @@ -737,21 +752,37 @@ function print_error_message ($result, $good = '', $bad = '', $attributes = '', * in the tag * * @param int $unixtime: Any type of timestamp really, but we prefer unixtime - * @param string $attributes: Any additional attributes (class, script etc.) - * @param string $tag: If it should be in a different tag than span * @param bool $return whether to output the string or return it + * @param array $option: An array with different options for this function + * Key html_attr: which html attributes to add (defaults to none) + * Key tag: Which html tag to use (defaults to span) * * @return string HTML code if return parameter is true. */ -function print_timestamp ($unixtime, $attributes = "", $tag = "span", $return = false) { +function print_timestamp ($unixtime, $return = false, $option = array ()) { global $config; + if (isset ($option["html_attr"])) { + $attributes = $option["html_attr"]; + } else { + $attributes = ""; + } + + if (isset ($option["tag"])) { + $tag = $option["tag"]; + } else { + $tag = "span"; + } + if (!is_numeric ($unixtime)) { $unixtime = strtotime ($unixtime); } //prominent_time is either timestamp or comparation - if ($config["prominent_time"] == "timestamp") { + if ($unixtime == 0) { + $title = __('Never'); + $data = __('Never'); + } elseif ($config["prominent_time"] == "timestamp") { $title = human_time_comparation ($unixtime); $data = date ($config["date_format"], $unixtime); } else { @@ -780,8 +811,8 @@ function print_timestamp ($unixtime, $attributes = "", $tag = "span", $return = /** * Prints a username with real name, link to the user_edit page etc. * - * @param string The username to render - * @param bool Whether to return or print + * @param string $username The username to render + * @param bool $return Whether to return or print * * @return string HTML code if return parameter is true. */ @@ -792,4 +823,87 @@ function print_username ($username, $return = false) { } return $string; } + +/** + * Print group icon within a link + * + * @param string $id_group Group id + * @param bool $return Whether to return or print + * @param string $path What path to use (relative to images/). Defaults to groups_small + * @return string HTML code if return parameter is true. + */ +function print_group_icon ($id_group, $return = false, $path = "groups_small") { + $icon = (string) get_db_value ('icon', 'tgrupo', 'id_grupo', (int) $id_group); + + if (empty ($icon)) { + return "-"; + } + + $return = ''; + $return .= ''.get_group_name ($id_group).''; + $return .= ''; + + if ($return === false) { + echo $return; + } + + return $return; +} + +/** + * Get the icon of an operating system. + * + * @param int $id_os Operating system id + * @param bool $name Whether to also append the name of the OS after the icon + * @param bool $return Whether to return or echo the result + * + * @return string HTML with icon of the OS + */ +function print_os_icon ($id_os, $name = true, $return = false) { + $icon = (string) get_db_value ('icon_name', 'tconfig_os', 'id_os', (int) $id_os); + $os_name = get_os_name ($id_os); + if (empty ($icon)) { + return "-"; + } + + $output = ''.$os_name.''; + + if ($name === true) { + $output .= ' - '.$os_name; + } + + if ($return === false) { + echo $output; + } + + return $output; +} + +/** + * Prints an agent name with the correct link + * + * @param int $agent Agent id + * @param bool $return Whether to return the string or echo it too + * @param int $cutoff After how much characters to cut off the inside of the link. The full agent name will remain in the roll-over + * + * @return string HTML with agent name and link +**/ +function print_agent_name ($id_agent, $return = false, $cutoff = 0) { + $agent_name = (string) get_agent_name ($id_agent); + $output = ''; + if ($cutoff > 0 && (mb_strlen ($agent_name, "UTF-8") > $cutoff)) { + $output .= mb_substr (utf8_decode ($agent_name), 0, $cutoff, "UTF-8").'...'; + } else { + $output .= $agent_name; + } + $output .= ''; + + //TODO: Add a pretty javascript (using jQuery) popup-box with agent details + + if ($return === false) { + echo $output; + } + + return $output; +} ?> diff --git a/pandora_console/operation/agentes/datos_agente.php b/pandora_console/operation/agentes/datos_agente.php index cbb78fae15..af3a1452e5 100644 --- a/pandora_console/operation/agentes/datos_agente.php +++ b/pandora_console/operation/agentes/datos_agente.php @@ -86,7 +86,7 @@ foreach ($result as $row) { } else { $data[0] = ''; } - $data[1] = print_timestamp ($row["utimestamp"], "", "span", true); + $data[1] = print_timestamp ($row["utimestamp"], true); if (is_numeric ($row["datos"])) { $data[2] = format_for_graph ($row["datos"]); } else { diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php index c23a094032..6908db64da 100644 --- a/pandora_console/operation/agentes/estado_agente.php +++ b/pandora_console/operation/agentes/estado_agente.php @@ -258,9 +258,9 @@ if ($agents !== false) { ".$nombre_agente.""; // Show SO icon :) - echo " - ".dame_so_name($id_os).""; + echo ""; + print_os_icon ($id_os, false); + echo ""; // If there are a module interval bigger than agent interval if ($biginterval > $intervalo) { echo " @@ -273,7 +273,7 @@ if ($agents !== false) { echo ''; echo ""; -echo ''; + print_group_icon ($id_grupo); echo " ". $numero_modulos." / ".$numero_monitor; @@ -321,17 +321,8 @@ echo '"; echo ""; - if ($ultimo_contacto == "0000-00-00 00:00:00") { - echo __('Never'); - } else { - $last_time = strtotime ($ultimo_contacto); - $diferencia = $now - $last_time; - $time = human_time_comparation ($ultimo_contacto); - $style = ''; - if ($diferencia > ($biginterval * 2)) - $style = 'style="color: #ff0000"'; - echo ''.$time.''; - } + print_timestamp ($ultimo_contacto); + echo ""; } echo ""; echo "
"; diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index f512cec411..e34618480c 100644 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -68,7 +68,7 @@ echo ''; //OS echo ''.__('OS').''; -echo ' - '.dame_so_name ($agent["id_os"]).' '.$agent["os_version"].''; +echo ''.print_os_icon ($agent["id_os"], true, true).' '.$agent["os_version"].''; // Parent echo ''.__('Parent').''; @@ -85,7 +85,8 @@ echo ''.$agent["comentarios"].''; // Group echo ''.__('Group').''; echo ''; -echo ' - '. get_group_name ($agent["id_grupo"]).''; +print_group_icon ($agent["id_grupo"]); +echo ''; // Agent version echo ''.__('Agent Version'). ''; @@ -97,11 +98,7 @@ echo ''.dame_numero_datos ($id_agente).''; // Last contact echo ''.__('Last contact')." / ".__('Remote').''; -if ($agent["ultimo_contacto"] == "0000-00-00 00:00:00") { - echo __('Never'); -} else { - echo $agent["ultimo_contacto"]; -} +print_timestamp ($agent["ultimo_contacto"]); echo " / "; diff --git a/pandora_console/operation/agentes/estado_monitores.php b/pandora_console/operation/agentes/estado_monitores.php index 77969ac476..d1330bd896 100644 --- a/pandora_console/operation/agentes/estado_monitores.php +++ b/pandora_console/operation/agentes/estado_monitores.php @@ -97,7 +97,7 @@ foreach ($modules as $module) { } else { $data[6] = ''; } - $data[6] .= print_timestamp ($module["utimestamp"], '', 'span', true); + $data[6] .= print_timestamp ($module["utimestamp"], true); $data[6] .= ''; if ($module["estado"] != 100) { diff --git a/pandora_console/operation/agentes/status_events.php b/pandora_console/operation/agentes/status_events.php index 2ebd1ee70c..49ffe22241 100644 --- a/pandora_console/operation/agentes/status_events.php +++ b/pandora_console/operation/agentes/status_events.php @@ -16,10 +16,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - // Load global vars -global $config; check_login(); if (!isset($id_agente)){ @@ -27,7 +24,9 @@ if (!isset($id_agente)){ exit; } +require_once ("include/functions_events.php"); + echo "

".__('Latest events for this agent')."

"; -smal_event_table ("WHERE id_agente = $id_agente", $limit = 10, $width=750); +print_events_table ("WHERE id_agente = $id_agente", $limit = 10, $width=750); ?> diff --git a/pandora_console/operation/agentes/tactical.php b/pandora_console/operation/agentes/tactical.php index f7e76f5f5d..c3f1b9c772 100644 --- a/pandora_console/operation/agentes/tactical.php +++ b/pandora_console/operation/agentes/tactical.php @@ -19,6 +19,7 @@ // Load global vars require_once ("include/config.php"); +require_once ("include/functions_events.php"); check_login (); @@ -258,7 +259,7 @@ if ($serverinfo) { } else { echo "
".__('There are no servers configured into the database')."
"; } -smal_event_table ("", 10, 450); +print_events_table ("", 10, 450); echo ''; ?> \ No newline at end of file diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 4bd512d30a..5c7dba396b 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -340,11 +340,7 @@ foreach ($result as $row) { $data[4] .= ''; } - if (!empty ($row["id_grupo"])) { - $data[5] = ''; - } else { - $data[5] = ''; - } + $data[5] = print_group_icon ($row["id_grupo"], true); if (!empty ($row["estado"])) { $data[6] = ''.substr ($row["id_usuario"],0,8).''; @@ -353,7 +349,7 @@ foreach ($result as $row) { } //Time - $data[7] = ''.human_time_comparation ($row["timestamp"]).''; + $data[7] = print_timestamp ($row["timestamp"], true); //Actions $data[8] = ''; diff --git a/pandora_console/operation/incidents/incident.php b/pandora_console/operation/incidents/incident.php index ce0066d5f7..ade1860b01 100644 --- a/pandora_console/operation/incidents/incident.php +++ b/pandora_console/operation/incidents/incident.php @@ -282,9 +282,9 @@ if ($count < 1) { $data[3] = print_incidents_priority_img ($row["prioridad"], true); - $data[4] = ''; + $data[4] = print_group_icon ($row["id_grupo"], true); - $data[5] = print_timestamp ($row["actualizacion"], "", "span", true); + $data[5] = print_timestamp ($row["actualizacion"], true); $data[6] = $row["origen"]; diff --git a/pandora_console/operation/incidents/incident_detail.php b/pandora_console/operation/incidents/incident_detail.php index d3410c141c..8621a7fb78 100644 --- a/pandora_console/operation/incidents/incident_detail.php +++ b/pandora_console/operation/incidents/incident_detail.php @@ -323,7 +323,7 @@ if (isset ($id_inc)) { foreach ($result as $row) { $data = array (); $data[0] = ''; - $data[1] = __('Author').': '.print_username ($row["id_usuario"], true).' ('.print_timestamp ($row["timestamp"], "", "span", true).')'; + $data[1] = __('Author').': '.print_username ($row["id_usuario"], true).' ('.print_timestamp ($row["timestamp"], true).')'; array_push ($table->data, $data); $data = array (); diff --git a/pandora_console/operation/messages/message.php b/pandora_console/operation/messages/message.php index f603955ea0..bd9092094d 100644 --- a/pandora_console/operation/messages/message.php +++ b/pandora_console/operation/messages/message.php @@ -214,7 +214,7 @@ if (isset ($_GET["leer"]) || (!isset ($_GET["nuevo"]) && !isset ($_GET["nuevo_g" } else { echo __('No subject'); } - echo ''.format_datetime(strtotime($row["timestamp"])).' + echo ''.print_timestamp ($row["timestamp"], true).' '; } diff --git a/pandora_console/operation/servers/view_server_detail.php b/pandora_console/operation/servers/view_server_detail.php index 593c4b3d2f..11141798f8 100644 --- a/pandora_console/operation/servers/view_server_detail.php +++ b/pandora_console/operation/servers/view_server_detail.php @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Load global vars -require("include/config.php"); +require_once ("include/config.php"); check_login (); @@ -28,141 +28,120 @@ if (! give_acl ($config['id_user'], 0, "AR")) { return; } - $modules_server = 0; $total_modules = 0; $total_modules_data = 0; - // -------------------------------- // FORCE A RECON TASK // -------------------------------- if (give_acl ($config['id_user'], 0, "PM")) { if (isset ($_GET["force"])) { - $id = entrada_limpia($_GET["force"]); - $sql = "UPDATE trecon_task set utimestamp = 0, status = 1 WHERE id_rt = $id "; - $result = mysql_query($sql); + $id = (int) get_parameter_get ("force", 0); + $sql = sprintf ("UPDATE trecon_task SET utimestamp = 0, status = 1 WHERE id_rt = %d", $id); + + process_sql ($sql); } } -$id_server = get_parameter ("server_id", -1); -$sql = "SELECT * FROM tserver WHERE id_server = $id_server"; -$result=mysql_query($sql); -$row=mysql_fetch_array($result); -$server_name = $row["name"]; -$id_server = $row[0]; +$id_server = (int) get_parameter ("server_id", -1); +$server_name = get_server_name ($id_server); +$recon_tasks = get_db_all_rows_field_filter ("trecon_task", "id_recon_server", $id_server); -echo "

". __('Configuration detail') . " - $server_name "; -echo " "; -echo ""; -echo ""; -echo ""; +echo "

". __('Configuration detail') . " - ".$server_name; +echo ' '; echo "

"; + // Show network tasks for Recon Server -if ($row["recon_server"]) { - $sql = "SELECT * FROM trecon_task WHERE id_recon_server = $id_server"; - // Connect DataBase - $result=mysql_query($sql); - if (mysql_num_rows($result)){ - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - $color=1; - while ($row=mysql_fetch_array($result)){ - if ($color == 1){ - $tdcolor = "datos"; - $color = 0; - } - else { - $tdcolor = "datos2"; - $color = 1; - } - $id_rt = $row["id_rt"]; - $name = $row["name"]; - $status = $row["status"]; - $utimestamp = $row["utimestamp"]; - $interval = $row["interval_sweep"]; - $create_incident = $row["create_incident"]; - $subnet = $row["subnet"]; - $id_os = $row["id_os"]; - $id_group = $row["id_group"]; - $id_network_profile = $row["id_network_profile"]; - - echo ""; - // Name - echo ""; - - echo "
".__('Force')."".__('Task name')."".__('Interval')."".__('Network')."".__('Status')."".__('Network profile')."".__('Group')."".__('OS') ."".__('Progress')."".__('Updated at')."".__('Op')."
"; - echo ""; - - echo ""; - echo "$name"; - // Interval - echo ""; - if ($interval != 0){ - if ($interval < 43200) - echo "~ ".floor ($interval / 3600)." ".__('hours'); - else - echo "~ ".floor ($interval / 86400)." ".__('days'); - } else - echo $interval; - - // Subnet - echo ""; - echo $subnet; - - // status - echo ""; - if ($status == -1) - echo __('Done'); - else - echo __('Pending'); - // Network profile - echo ""; - echo give_network_profile_name($id_network_profile); - - // Group - echo ""; - echo ""; - - // OS - echo ""; - if ($id_os > 0){ - $icon = get_db_sql ("SELECT icon_name FROM tconfig_os WHERE id_os = $id_os"); - echo ""; - } - - // Progress - echo ""; - if ($status < 0) - echo "-"; - else - echo ''; - - // Last execution - echo ""; - $keepalive = format_datetime ( $utimestamp ); - echo substr($keepalive,0,25).""; - if (give_acl ($config['id_user'], 0, "PM")) { - echo ""; - echo ""; - } - } - echo "
"; - } else { - echo "
"; - echo __("This server has no recon tasks assigned"); - echo "
"; - } +if ($recon_tasks === false) { + $recon_tasks = array (); } +$table->cellpadding = 4; +$table->cellspacing = 4; +$table->width = 725; +$table->class = "databox"; +$table->head = array (); +$table->data = array (); +$table->align = array (); + +$table->head[0] = ''; +$table->align[0] = "center"; + +$table->head[1] = __('Task name'); +$table->align[1] = "center"; + +$table->head[2] = __('Interval'); +$table->align[2] = "center"; + +$table->head[3] = __('Network'); +$table->align[3] = "center"; + +$table->head[4] = __('Status'); +$table->align[4] = "center"; + +$table->head[5] = __('Network profile'); +$table->align[5] = "center"; + +$table->head[6] = __('Group'); +$table->align[6] = "center"; + +$table->head[7] = __('OS'); +$table->align[7] = "center"; + +$table->head[8] = __('Progress'); +$table->align[8] = "center"; + +$table->head[9] = __('Updated at'); +$table->align[9] = "center"; + +$table->head[10] = ''; +$table->align[10] = "center"; + +foreach ($recon_tasks as $task) { + $data = array (); + + $data[0] = ''.__('Force').''; + + $data[1] = ''.$task["name"].''; + + $data[2] = human_time_description ($task["interval_sweep"]); + + $data[3] = $task["subnet"]; + + if ($task["status"] == -1) { + $data[4] = __('Done'); + } else { + $data[4] = __('Pending'); + } + + $data[5] = get_networkprofile_name ($task["id_network_profile"]); + + $data[6] = print_group_icon ($task["id_group"], true); + + $data[7] = print_os_icon ($task["id_os"], true); + + if ($task["status"] < 0 || $task["status"] > 100) { + $data[8] = "-"; + } else { + $data[8] = ''; + } + + $data[9] = print_timestamp ($task["utimestamp"], true); + + if (give_acl ($config["id_user"], $task["id_group"], "PM")) { + $data[10] = ''; + } else { + $data[10] = ''; + } + + array_push ($table->data, $data); +} + +if (empty ($table->data)) { + echo '
'.__("This server has no recon tasks assigned").'
'; +} else { + print_table ($table); +} +unset ($table); ?>