| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
- //
- // vnStat PHP frontend (c)2006-2010 Bjorge Dijkstra (bjd@jooz.net)
- //
- // 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 2 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program; if not, write to the Free Software
- // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- //
- //
- // see file COPYING or at http://www.gnu.org/licenses/gpl.html
- // for more information.
- //
- require 'config.php';
- require 'localize.php';
- require 'vnstat.php';
- validate_input();
- require "./themes/$style/theme.php";
- function write_side_bar()
- {
- global $iface, $page, $graph, $script, $style;
- global $iface_list, $iface_title;
- global $page_list, $page_title;
- $p = "&graph=$graph&style=$style";
- print "<ul class=\"iface\">\n";
- foreach ($iface_list as $if)
- {
- if ($iface == $if) {
- print "<li class=\"iface active\">";
- } else {
- print "<li class=\"iface\">";
- }
- print "<a href=\"$script?if=$if$p\">";
- if (isset($iface_title[$if]))
- {
- print $iface_title[$if];
- }
- else
- {
- print $if;
- }
- print "</a>";
- print "<ul class=\"page\">\n";
- foreach ($page_list as $pg)
- {
- print "<li class=\"page\"><a href=\"$script?if=$if$p&page=$pg\">".$page_title[$pg]."</a></li>\n";
- }
- print "</ul></li>\n";
- }
- print "</ul>\n";
- }
- function kbytes_to_string($kb)
- {
- global $byte_notation;
- $units = array('TiB','GiB','MiB','KiB');
- $scale = 1024*1024*1024;
- $ui = 0;
- $custom_size = isset($byte_notation) && in_array($byte_notation, $units);
- while ((($kb < $scale) && ($scale > 1)) || $custom_size)
- {
- $ui++;
- $scale = $scale / 1024;
- if ($custom_size && $units[$ui] == $byte_notation) {
- break;
- }
- }
- return sprintf("%0.2f %s", ($kb/$scale),$units[$ui]);
- }
- function write_summary()
- {
- global $summary,$top,$day,$hour,$month;
- $trx = $summary['totalrx']*1024+$summary['totalrxk'];
- $ttx = $summary['totaltx']*1024+$summary['totaltxk'];
- //
- // build array for write_data_table
- //
- $sum = array();
- if (count($day) > 0 && count($hour) > 0 && count($month) > 0) {
- $sum[0]['act'] = 1;
- $sum[0]['label'] = T('This hour');
- $sum[0]['rx'] = $hour[0]['rx'];
- $sum[0]['tx'] = $hour[0]['tx'];
- $sum[1]['act'] = 1;
- $sum[1]['label'] = T('This day');
- $sum[1]['rx'] = $day[0]['rx'];
- $sum[1]['tx'] = $day[0]['tx'];
- $sum[2]['act'] = 1;
- $sum[2]['label'] = T('This month');
- $sum[2]['rx'] = $month[0]['rx'];
- $sum[2]['tx'] = $month[0]['tx'];
- $sum[3]['act'] = 1;
- $sum[3]['label'] = T('All time');
- $sum[3]['rx'] = $trx;
- $sum[3]['tx'] = $ttx;
- }
- write_data_table(T('Summary'), $sum);
- print "<br/>\n";
- write_data_table(T('Top 10 days'), $top);
- }
- function write_data_table($caption, $tab)
- {
- print "<table width=\"100%\" cellspacing=\"0\">\n";
- print "<caption>$caption</caption>\n";
- print "<tr>";
- print "<th class=\"label\" style=\"width:120px;\"> </th>";
- print "<th class=\"label\">".T('In')."</th>";
- print "<th class=\"label\">".T('Out')."</th>";
- print "<th class=\"label\">".T('Total')."</th>";
- print "</tr>\n";
- for ($i=0; $i<count($tab); $i++)
- {
- if ($tab[$i]['act'] == 1)
- {
- $t = $tab[$i]['label'];
- $rx = kbytes_to_string($tab[$i]['rx']);
- $tx = kbytes_to_string($tab[$i]['tx']);
- $total = kbytes_to_string($tab[$i]['rx']+$tab[$i]['tx']);
- $id = ($i & 1) ? 'odd' : 'even';
- print "<tr>";
- print "<td class=\"label_$id\">$t</td>";
- print "<td class=\"numeric_$id\">$rx</td>";
- print "<td class=\"numeric_$id\">$tx</td>";
- print "<td class=\"numeric_$id\">$total</td>";
- print "</tr>\n";
- }
- }
- print "</table>\n";
- }
- get_vnstat_data();
- //
- // html start
- //
- header('Content-type: text/html; charset=utf-8');
- print '<?xml version="1.0"?>';
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>vnStat - PHP frontend</title>
- <link rel="stylesheet" type="text/css" href="themes/<?php echo $style ?>/style.css"/>
- <!-- 添加 Bootstrap 5 -->
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
- <!-- 添加一些现代图标 -->
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
- </head>
- <body>
- <div id="wrap">
- <div id="sidebar"><?php write_side_bar(); ?></div>
- <div id="content">
- <div id="header"><?php print T('Traffic data for').(isset($iface_title[$iface]) ? $iface_title[$iface] : '')." ($iface)";?></div>
- <div id="main">
- <?php
- $graph_params = "if=$iface&page=$page&style=$style";
- if ($page != 's')
- if ($graph_format == 'svg') {
- print "<object type=\"image/svg+xml\" width=\"692\" height=\"297\" data=\"graph_svg.php?$graph_params\"></object>\n";
- } else {
- print "<img src=\"graph.php?$graph_params\" alt=\"graph\"/>\n";
- }
- if ($page == 's')
- {
- write_summary();
- }
- else if ($page == 'h')
- {
- write_data_table(T('Last 24 hours'), $hour);
- }
- else if ($page == 'd')
- {
- write_data_table(T('Last 30 days'), $day);
- }
- else if ($page == 'm')
- {
- write_data_table(T('Last 12 months'), $month);
- }
- ?>
- </div>
- <div id="footer"><a href="http://www.sqweek.com/">vnStat PHP frontend</a> 2.0.0 - ©2006-2024 Bjorge Dijkstra (bjd _at_ jooz.net)</div>
- </div>
- </div>
- </body></html>
|