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 <vanooste@rcbi.rochester.edu> + + * 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 <estebans@artica.es> * 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 '<table cellpadding="4" cellspacing="4" class="databox">'; foreach ($news as $article) { echo '<tr><th><b>'.$article["subject"].'</b></th></tr>'; - echo '<tr><td>'.__('by').' <b>'.$article["author"].'</b> '.__('at').' <i>'.$article["timestamp"].'</i></td></tr>'; + echo '<tr><td>'.__('by').' <b>'.$article["author"].'</b> '.__('at').' <i>'.print_timestamp ($article["timestamp"], true).'</i></td></tr>'; echo '<tr><td class="datos">'; echo nl2br ($article["text"]); echo '</td></tr>'; 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 "<td class='$tdcolor' align='center'> - <img src='images/".dame_so_icon($row["id_os"])."'></td>"; + echo "<td class='$tdcolor' align='center'>"; + print_os_icon ($row["id_os"], false); + echo "</td>"; // Group icon and name - echo "<td class='$tdcolor'> - <img src='images/groups_small/".show_icon_group($id_grupo).".png' class='bot' border='0'> - ".get_group_name ($id_grupo)."</td>"; + echo "<td class='$tdcolor' align='center'>".print_group_icon ($id_grupo, true)."</td>"; // Description echo "<td class='".$tdcolor."f9'>".$row["comentarios"]."</td>"; // 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] = '<img src="images/'.dame_so_icon($downtime["id_os"]).'"> - '.dame_so_name($downtime["id_os"]); + $data[2] = print_os_icon ($downtime["id_os"], true, true); + $data[3] = $downtime["ultimo_contacto"]; $data[4] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime&id_agent='. diff --git a/pandora_console/godmode/servers/manage_recontask.php b/pandora_console/godmode/servers/manage_recontask.php index 3910eae997..9652ad3630 100644 --- a/pandora_console/godmode/servers/manage_recontask.php +++ b/pandora_console/godmode/servers/manage_recontask.php @@ -110,13 +110,13 @@ if ($result !== false) { // Network (subnet) $row["subnet"], // Network profile name - '<a href="index.php?sec=gmodules&sec2=godmode/modules/manage_network_templates&id='.$row["id_network_profile"].'">'.give_network_profile_name ($row["id_network_profile"]).'</a>', + '<a href="index.php?sec=gmodules&sec2=godmode/modules/manage_network_templates&id='.$row["id_network_profile"].'">'.get_networkprofile_name ($row["id_network_profile"]).'</a>', // GROUP - '<img class="bot" src="images/groups_small/'.show_icon_group ($row["id_group"]).'.png" alt="">', + print_group_icon ($row["id_group"], true), // INCIDENT (($row["create_incident"] == 1) ? __('Yes') : __('No')), // OS - (($row["id_os"] > 0) ? '<img src="images/'.dame_so_icon ($row["id_os"]).'" />' : __('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 "<h3 class='error'>".__('Not created. Error inserting data')."</h3>"; - } else { - echo "<h3 class='suc'>".__('Created successfully')."</h3>"; - $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 "<h3 class='error'>".__('Not updated. Error updating data')."</h3>"; - else - echo "<h3 class='suc'>".__('Updated successfully')."</h3>"; + + $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 "<h3 class='error'>".__('Not deleted. Error deleting data')."</h3>"; - else - echo "<h3 class='suc'>".__('Deleted successfully')."</h3>"; + $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 "<h3 class='error'>".__('Name error')."</h3>"; } } 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 "</div>"; } - - -/** - * 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 "</table>"; } -/** - * - * - * @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 '<div class="nf">'.__('No events').'</div>'; - } else { - echo "<table cellpadding='4' cellspacing='4' width='$width' border=0 class='databox'>"; - echo "<tr>"; - echo "<th colspan='6' style='background-color:#799E48'>".__('Latest events')."</th>"; - echo "<tr>"; - echo "<th class='datos3 f9'>".__('St')."</th>"; - echo "<th class='datos3 f9'>".__('Type')."</th>"; - echo "<th class='datos3 f9'>".__('Event name')."</th>"; - echo "<th class='datos3 f9'>".__('Agent name')."</th>"; - echo "<th class='datos3 f9'>".__('User ID')."</th>"; - echo "<th class='datos3 f9'>".__('Timestamp')."</th>"; - - 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 "<tr>"; - echo "<td class='$tdclass' title='$criticity_label' align='center'>"; - if ($event["estado"] == 0) { - echo "<img src='images/pixel_red.png' width=20 height=20>"; - } else { - echo "<img src='images/pixel_green.png' width=20 height=20>"; - } - echo "</td>"; - /* Event type */ - echo "<td class='".$tdclass."' title='".$event["event_type"]."'>"; - switch ($event["event_type"]) { - case "unknown": - echo "<img src='images/err.png'>"; - break; - case "alert_recovered": - echo "<img src='images/error.png'>"; - break; - case "alert_manual_validation": - echo "<img src='images/eye.png'>"; - break; - case "monitor_up": - echo "<img src='images/lightbulb.png'>"; - break; - case "monitor_down": - echo "<img src='images/lightbulb_off.png'>"; - break; - case "alert_fired": - echo "<img src='images/bell.png'>"; - break; - case "system"; - echo "<img src='images/cog.png'>"; - break; - case "recon_host_detected"; - echo "<img src='images/network.png'>"; - break; - } - echo "</td>"; - // Event description - echo "<td class='".$tdclass."f9' title='".$event["evento"]."'>"; - echo substr ($event["evento"],0,45); - if (strlen ($event["evento"]) > 45) { - echo ".."; - } - echo "</td>"; - if ($event["id_agente"] > 0) { - // Agent name - $agent_name = get_agent_name ($event["id_agente"]); - echo "<td class='".$tdclass."f9' title='$agent_name'><a href='index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=".$event["id_agente"]."'><b>"; - echo substr ($agent_name, 0, 14); - if (strlen ($agent_name) > 14) - echo ".."; - echo "</b></a>"; - echo "</td>"; - - // for System or SNMP generated alerts - } else { - if ($event["event_type"] == "system") { - echo "<td class='$tdclass'>".__('System')."</td>"; - } else { - echo "<td class='$tdclass'>".__('Alert')."SNMP</td>"; - } - } - - // User who validated event - echo "<td class='$tdclass'>"; - if ($event["estado"] != 0) { - echo "<a href='index.php?sec=usuario&sec2=operation/users/user_edit&ver=".$event["id_usuario"]."'>".substr ($event["id_usuario"],0,8)."<a href='#' class='tip'> <span>".dame_nombre_real ($event["id_usuario"])."</span></a></a>"; - } - echo "</td>"; - // Timestamp - echo "<td class='".$tdclass."f9' title='".$event["timestamp"]."'>"; - echo human_time_comparation ($event["timestamp"]); - echo "</td>"; - echo "</tr>"; - } - echo "</table>"; - } -} - - /** * *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 = '<div class="nf">'.__('No events').'</div>'; + 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] = '<img src="images/pixel_red.png" width="20" height="20" title="'.get_priority_name ($event["criticity"]).'" />'; + } else { + $data[0] = '<img src="images/pixel_green.png" width="20" height="20" title="'.get_priority_name ($event["criticity"]).'" />'; + } + + /* Event type */ + switch ($event["event_type"]) { + case "alert_recovered": + $data[1] = '<img src="images/error.png" title="'.__('Alert recovered').'" />'; + break; + case "alert_manual_validation": + $data[1] = '<img src="images/eye.png" title="'.__('Alert manually validated').'" />'; + break; + case "monitor_up": + $data[1] = '<img src="images/lightbulb.png" title="'.__('Monitor up').'" />'; + break; + case "monitor_down": + $data[1] = '<img src="images/lightbulb_off.png" title="'.__('Monitor down').'" />'; + break; + case "alert_fired": + $data[1] = '<img src="images/bell.png" title="'.__('Alert fired').'" />'; + break; + case "system"; + $data[1] = '<img src="images/cog.png" title="'.__('System').'" />'; + break; + case "recon_host_detected"; + $data[1] = '<img src="images/network.png" title="'.__('Host detected by recon server').'" />'; + break; + default: + $data[1] = '<img src="images/err.png" title="'.$event["event_type"].'" />'; + 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] = '<span class="'.get_priority_class ($event["criticity"]).'f9" title="'.safe_input ($event["evento"]).'">'.safe_input (substr ($event["evento"],0, floor ($width / 10))); + + if (strlen ($event["evento"]) > floor ($width / 10)) { + $data[2] .= "..."; + } + $data[2] .= '</span>'; + + 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 .= '<thead><tr>'; + + if (isset ($table->title)) { + $output .= '<th colspan="'.$countcols.'"'; + if (isset ($table->titlestyle)) { + $output .= ' style="'.$table->titlestyle.'"'; + } + if (isset ($table->titleclass)) { + $output .= ' class="'.$table->titleclass.'"'; + } + $output .= '>'.$table->title.'</th></tr><tr>'; + } + 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 = '<a href="index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60&group_id='.$id_group.'">'; + $return .= '<img class="bot" src="images/'.$path.'/'.$icon.'.png" alt="'.get_group_name ($id_group).'" title="'.get_group_name ($id_group).'" />'; + $return .= '</a>'; + + 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 = '<img src="images/'.$icon.'" border="0" alt="'.$os_name.'" title="'.$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 = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agent.'" title="'.$agent_name.'"><b>'; + 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 .= '</b></a>'; + + //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) { <b>".$nombre_agente."</b></a></td>"; // Show SO icon :) - echo "<td class='$tdcolor' align='center'> - <img border=0 src='images/".dame_so_icon($id_os)."' - alt='".dame_so_name($id_os)."'></td>"; + echo "<td class='$tdcolor' align='center'>"; + print_os_icon ($id_os, false); + echo "</td>"; // If there are a module interval bigger than agent interval if ($biginterval > $intervalo) { echo "<td class='$tdcolor'> @@ -273,7 +273,7 @@ if ($agents !== false) { echo '<td class="'.$tdcolor.'" align="center">'; echo "<a href='index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60&group_id=$id_grupo'>"; -echo '<img class="bot" src="images/groups_small/'.show_icon_group($id_grupo).'.png" title="'. get_group_name ($id_grupo).'"></A></td>'; + print_group_icon ($id_grupo); echo "<td class='$tdcolor'> ". $numero_modulos." <b>/</b> ".$numero_monitor; @@ -321,17 +321,8 @@ echo '<img class="bot" src="images/groups_small/'.show_icon_group($id_grupo).'.p } echo "</td>"; echo "<td class='$tdcolor'>"; - 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 '<span '.$style.' title="'.format_datetime ($last_time).'">'.$time.'</span>'; - } + print_timestamp ($ultimo_contacto); + echo "</td>"; } echo "<tr>"; echo "</table><br>"; 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 '</td></tr>'; //OS echo '<tr><td class="datos"><b>'.__('OS').'</b></td>'; -echo '<td class="datos" colspan="2"><img src="images/'.dame_so_icon ($agent["id_os"]).'"> - '.dame_so_name ($agent["id_os"]).' '.$agent["os_version"].'</td></tr>'; +echo '<td class="datos" colspan="2">'.print_os_icon ($agent["id_os"], true, true).' '.$agent["os_version"].'</td></tr>'; // Parent echo '<tr><td class="datos2"><b>'.__('Parent').'</b></td>'; @@ -85,7 +85,8 @@ echo '<td class="datos2" colspan="2">'.$agent["comentarios"].'</td></tr>'; // Group echo '<tr><td class="datos"><b>'.__('Group').'</b></td>'; echo '<td class="datos" colspan="2">'; -echo '<img class="bot" src="images/groups_small/'.show_icon_group ($agent["id_grupo"]).'.png" /> - <a href="index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60&group_id='.$agent["id_grupo"].'">'. get_group_name ($agent["id_grupo"]).'</a></td></tr>'; +print_group_icon ($agent["id_grupo"]); +echo '</td></tr>'; // Agent version echo '<tr><td class="datos2"><b>'.__('Agent Version'). '</b></td>'; @@ -97,11 +98,7 @@ echo '<td class="datos" colspan=2>'.dame_numero_datos ($id_agente).'</td></tr>'; // Last contact echo '<tr><td class="datos2"><b>'.__('Last contact')." / ".__('Remote').'</b></td><td class="datos2 f9" colspan="2">'; -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] = '<span>'; } - $data[6] .= print_timestamp ($module["utimestamp"], '', 'span', true); + $data[6] .= print_timestamp ($module["utimestamp"], true); $data[6] .= '</span>'; 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 "<h3>".__('Latest events for this agent')."</h3>"; -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 "<div class='nf'>".__('There are no servers configured into the database')."</div>"; } -smal_event_table ("", 10, 450); +print_events_table ("", 10, 450); echo '</div>'; ?> \ 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] .= '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$row["id_agente"].'&tab=alert"><img src="images/bell.png" border="0" /></a>'; } - if (!empty ($row["id_grupo"])) { - $data[5] = '<img src="images/groups_small/'.show_icon_group ($row["id_grupo"]).'.png" title="'.get_group_name ($row["id_grupo"]).'" class="bot" />'; - } else { - $data[5] = ''; - } + $data[5] = print_group_icon ($row["id_grupo"], true); if (!empty ($row["estado"])) { $data[6] = '<a href="index.php?sec=usuario&sec2=operation/user/user_edit&ver='.$row["id_usuario"].'" title="'.dame_nombre_real ($row["id_usuario"]).'">'.substr ($row["id_usuario"],0,8).'</a>'; @@ -353,7 +349,7 @@ foreach ($result as $row) { } //Time - $data[7] = '<span class="f9" title="'.format_datetime ($row["timestamp"]).'">'.human_time_comparation ($row["timestamp"]).'</span>'; + $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] = '<img src="images/groups_small/'.show_icon_group ($row["id_grupo"]).'.png" title="'.get_group_name ($row["id_grupo"]).'" />'; + $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] = '<img src="images/page_white_text.png" border="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 '</b></a></td><td class="'.$tdcolor.'">'.format_datetime(strtotime($row["timestamp"])).'</td> + echo '</b></a></td><td class="'.$tdcolor.'">'.print_timestamp ($row["timestamp"], true).'</td> <td class="'.$tdcolor.'" align="center"><a href="index.php?sec=messages&sec2=operation/messages/message&borrar=1&id_mensaje='.$row["id_mensaje"].'"> <img src="images/cross.png" border="0"></a></td></tr>'; } 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 "<h2>". __('Configuration detail') . " - $server_name "; -echo " "; -echo "<a href='index.php?sec=estado_server&sec2=operation/servers/view_server_detail&server_id=$id_server'>"; -echo "<img src='images/refresh.png'>"; -echo "</A>"; +echo "<h2>". __('Configuration detail') . " - ".$server_name; +echo ' <a href="index.php?sec=estado_server&sec2=operation/servers/view_server_detail&server_id='.$id_server.'"><img src="images/refresh.png" /></a>'; echo "</h2>"; + // 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 "<table cellpadding='4' cellspacing='4' width='760' class='databox'>"; - echo "<tr><th class='datos'>".__('Force')."</th>"; - echo "<th class='datos'>".__('Task name')."</th>"; - echo "<th class='datos'>".__('Interval')."</th>"; - echo "<th class='datos'>".__('Network')."</th>"; - echo "<th class='datos'>".__('Status')."</th>"; - echo "<th class='datos'>".__('Network profile')."</th>"; - echo "<th class='datos'>".__('Group')."</th>"; - echo "<th class='datos'>".__('OS') ."</th>"; - echo "<th class='datos'>".__('Progress')."</th>"; - echo "<th class='datos'>".__('Updated at')."</th>"; - echo "<th class='datos'>".__('Op')."</th>"; - $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 "<tr>"; - // Name - echo "<td class='$tdcolor'>"; - echo "<a href='index.php?sec=estado_server&sec2=operation/servers/view_server_detail&server_id=$id_server&force=$id_rt'><img src='images/target.png' border='0'></a>"; - - echo "<td class='$tdcolor'>"; - echo "<b>$name</b>"; - // Interval - echo "<td class='$tdcolor'>"; - if ($interval != 0){ - if ($interval < 43200) - echo "~ ".floor ($interval / 3600)." ".__('hours'); - else - echo "~ ".floor ($interval / 86400)." ".__('days'); - } else - echo $interval; - - // Subnet - echo "<td class='$tdcolor'>"; - echo $subnet; - - // status - echo "<td class='$tdcolor' align='center'>"; - if ($status == -1) - echo __('Done'); - else - echo __('Pending'); - // Network profile - echo "<td class='$tdcolor'>"; - echo give_network_profile_name($id_network_profile); - - // Group - echo "<td class='$tdcolor' align='center'>"; - echo "<img class='bot' src='images/groups_small/".show_icon_group($id_group).".png'>"; - - // OS - echo "<td class='$tdcolor' align='center'>"; - if ($id_os > 0){ - $icon = get_db_sql ("SELECT icon_name FROM tconfig_os WHERE id_os = $id_os"); - echo "<img src='images/$icon'>"; - } - - // Progress - echo "<td class='$tdcolor' align='center'>"; - if ($status < 0) - echo "-"; - else - echo '<img src="reporting/fgraph.php?tipo=progress&percent='.$status.'&height=20&width=100">'; - - // Last execution - echo "<td class='".$tdcolor."f9'>"; - $keepalive = format_datetime ( $utimestamp ); - echo substr($keepalive,0,25)."</td>"; - - echo "<td class='$tdcolor'>"; - if (give_acl ($config['id_user'], 0, "PM")) { - echo "<a href='index.php?sec=gservers&sec2=godmode/servers/manage_recontask_form&update=$id_rt'>"; - echo "<img src='images/wrench_orange.png'></a>"; - } - } - echo "</table>"; - } else { - echo "<div class='nf'>"; - echo __("This server has no recon tasks assigned"); - echo "</div>"; - } +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] = '<a href="index.php?sec=estado_server&sec2=operation/servers/view_server_detail&server_id='.$id_server.'&force='.$task["id_rt"].'"><img src="images/target.png" border="0" alt="'.__('Force').'" title="'.__('Force').'" /></a>'; + + $data[1] = '<b>'.$task["name"].'</b>'; + + $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] = '<img src="reporting/fgraph.php?tipo=progress&percent='.$task["status"].'&height=20&width=100" />'; + } + + $data[9] = print_timestamp ($task["utimestamp"], true); + + if (give_acl ($config["id_user"], $task["id_group"], "PM")) { + $data[10] = '<a href="index.php?sec=gservers&sec2=godmode/servers/manage_recontask_form&update='.$task["id_rt"].'"><img src="images/wrench_orange.png" /></a>'; + } else { + $data[10] = ''; + } + + array_push ($table->data, $data); +} + +if (empty ($table->data)) { + echo '<div class="nf">'.__("This server has no recon tasks assigned").'</div>'; +} else { + print_table ($table); +} +unset ($table); ?>