diff --git a/html/includes/front/common.inc.php b/html/includes/front/boxes.inc.php similarity index 64% rename from html/includes/front/common.inc.php rename to html/includes/front/boxes.inc.php index 155def0f7a..f02d0a06c3 100644 --- a/html/includes/front/common.inc.php +++ b/html/includes/front/boxes.inc.php @@ -1,6 +1,6 @@ * @@ -10,7 +10,20 @@ * option) any later version. Please see LICENSE.txt at the top level of * the source code distribution for details. */ - ?> +\n
\n"); + +foreach (get_matching_files($config['html_dir']."/includes/front/", "/^top_.*\.php$/") as $file) { + echo("
\n"); + include_once($file); + echo("
\n"); +} + +echo("
\n"); +echo("\n"); + +?> diff --git a/html/includes/front/top_device_bits.inc.php b/html/includes/front/top_device_bits.inc.php new file mode 100644 index 0000000000..bdf9dbcb14 --- /dev/null +++ b/html/includes/front/top_device_bits.inc.php @@ -0,0 +1,42 @@ + + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +$minutes = 15; +$seconds = $minutes * 60; +$top = $config['front_page_settings']['top']['devices']; +$query = " + SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total + FROM ports as p, devices as d + WHERE d.device_id = p.device_id + AND unix_timestamp() - p.poll_time < $seconds + AND ( p.ifInOctets_rate > 0 + OR p.ifOutOctets_rate > 0 ) + GROUP BY d.device_id + ORDER BY total desc + LIMIT $top +"; + + +echo("Top $top devices (last $minutes minutes)\n"); +echo("\n"); +foreach (dbFetchRows($query) as $result) { + echo("". + "". + "". + "\n"); +} +echo("
".generate_device_link($result, shorthost($result['hostname']))."".generate_device_link($result, + generate_minigraph_image($result, $config['time']['day'], $config['time']['now'], "device_bits", "no", 150, 21, '&'), array(), 0, 0, 0)."
\n"); + +?> diff --git a/html/includes/front/top_graphs.inc.php b/html/includes/front/top_graphs.inc.php deleted file mode 100644 index b9876a386d..0000000000 --- a/html/includes/front/top_graphs.inc.php +++ /dev/null @@ -1,38 +0,0 @@ - - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. - */ - -require_once("includes/front/common.inc.php"); - -echo('
'); -echo('
'); - -echo('
'); -require_once("includes/front/top_ports.inc.php"); -echo('
'); - -/* -echo('
'); -echo('
Something
'); -echo('

Next 1

'); -echo('
'); - -echo('
'); -echo('
Something else
'); -echo('

Next 2

'); -echo('
'); -*/ - -echo('
'); -echo('
'); - -?> diff --git a/html/includes/front/top_ports.inc.php b/html/includes/front/top_ports.inc.php index cdcd887e19..a2015327af 100644 --- a/html/includes/front/top_ports.inc.php +++ b/html/includes/front/top_ports.inc.php @@ -26,14 +26,14 @@ $query = " LIMIT $top "; -echo("Top $top ports (last $minutes minutes)"); -echo(''); +echo("Top $top ports (last $minutes minutes)\n"); +echo("
\n"); foreach (dbFetchRows($query) as $result) { - echo(''); + "\n"); } -echo('
'. + echo("
". generate_device_link($result, shorthost($result['hostname'])). - ''.generate_port_link($result). - ''.generate_port_link($result, generate_port_thumbnail($result)).'
".generate_port_link($result). + "".generate_port_link($result, generate_port_thumbnail($result))."
'); +echo("\n"); ?> diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 4a9ac24101..cd1d95fd3f 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -113,10 +113,10 @@ function get_percentage_colours($percentage) } -function generate_minigraph_image($device, $start, $end, $type, $legend = 'no', $width = 275, $height = 100) +function generate_minigraph_image($device, $start, $end, $type, $legend = 'no', $width = 275, $height = 100, $sep = '&') { - return ''; + return ''; } function generate_device_url($device, $vars=array()) @@ -124,7 +124,7 @@ function generate_device_url($device, $vars=array()) return generate_url(array('page' => 'device', 'device' => $device['device_id']), $vars); } -function generate_device_link($device, $text=NULL, $vars=array(), $start=0, $end=0) +function generate_device_link($device, $text=NULL, $vars=array(), $start=0, $end=0, $escape_text=1) { global $config; @@ -169,7 +169,7 @@ function generate_device_link($device, $text=NULL, $vars=array(), $start=0, $end $contents .= ''; } - $text = htmlentities($text); + if ($escape_text) { $text = htmlentities($text); } $link = overlib_link($url, $text, escape_quotes($contents), $class); if (device_permitted($device['device_id'])) @@ -644,4 +644,31 @@ function report_this_text($message) return $message.'\nPlease report this to the developers at '.$config['project_issues'].'\n'; } +# Find all the files in the given directory that match the pattern +function get_matching_files($dir, $match = "/\.php$/") +{ + global $config; + + if ($handle = opendir($dir)) + { + while (false !== ($file = readdir($handle))) + { + if ($file != "." && $file != ".." && preg_match($match, $file) === 1) + { + $list[] = $file; + } + } + closedir($handle); + } + return $list; +} + +# Include all the files in the given directory that match the pattern +function include_matching_files($dir, $match = "/\.php$/") +{ + foreach (get_matching_files($dir, $match) as $file) { + include_once($file); + } +} + ?> diff --git a/html/pages/front/default.php b/html/pages/front/default.php index 080d12fca1..01c9ebcaff 100644 --- a/html/pages/front/default.php +++ b/html/pages/front/default.php @@ -1,6 +1,6 @@