1533 |
richard |
1 |
<?php
|
|
|
2 |
//
|
|
|
3 |
// vnStat PHP frontend (c)2006-2010 Bjorge Dijkstra (bjd@jooz.net)
|
|
|
4 |
//
|
|
|
5 |
// This program is free software; you can redistribute it and/or modify
|
|
|
6 |
// it under the terms of the GNU General Public License as published by
|
|
|
7 |
// the Free Software Foundation; either version 2 of the License, or
|
|
|
8 |
// (at your option) any later version.
|
|
|
9 |
//
|
|
|
10 |
// This program is distributed in the hope that it will be useful,
|
|
|
11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
13 |
// GNU General Public License for more details.
|
|
|
14 |
//
|
|
|
15 |
// You should have received a copy of the GNU General Public License
|
|
|
16 |
// along with this program; if not, write to the Free Software
|
|
|
17 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
18 |
//
|
|
|
19 |
//
|
|
|
20 |
// see file COPYING or at http://www.gnu.org/licenses/gpl.html
|
|
|
21 |
// for more information.
|
|
|
22 |
//
|
|
|
23 |
require 'config.php';
|
|
|
24 |
require 'localize.php';
|
|
|
25 |
require 'vnstat.php';
|
|
|
26 |
|
|
|
27 |
validate_input();
|
|
|
28 |
|
|
|
29 |
require "./themes/$style/theme.php";
|
|
|
30 |
|
|
|
31 |
function write_side_bar()
|
|
|
32 |
{
|
|
|
33 |
global $iface, $page, $graph, $script, $style;
|
|
|
34 |
global $iface_list, $iface_title;
|
|
|
35 |
global $page_list, $page_title;
|
|
|
36 |
|
|
|
37 |
$p = "&graph=$graph&style=$style";
|
|
|
38 |
|
|
|
39 |
print "<ul class=\"iface\">\n";
|
|
|
40 |
foreach ($iface_list as $if)
|
|
|
41 |
{
|
|
|
42 |
print "<li class=\"iface\">";
|
|
|
43 |
if (isset($iface_title[$if]))
|
|
|
44 |
{
|
|
|
45 |
print $iface_title[$if];
|
|
|
46 |
}
|
|
|
47 |
else
|
|
|
48 |
{
|
|
|
49 |
print $if;
|
|
|
50 |
}
|
|
|
51 |
print "<ul class=\"page\">\n";
|
|
|
52 |
foreach ($page_list as $pg)
|
|
|
53 |
{
|
|
|
54 |
print "<li class=\"page\"><a href=\"$script?if=$if$p&page=$pg\">".$page_title[$pg]."</a></li>\n";
|
|
|
55 |
}
|
|
|
56 |
print "</ul></li>\n";
|
|
|
57 |
|
|
|
58 |
}
|
|
|
59 |
print "</ul>\n";
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
function kbytes_to_string($kb)
|
|
|
64 |
{
|
|
|
65 |
$units = array('TB','GB','MB','KB');
|
|
|
66 |
$scale = 1024*1024*1024;
|
|
|
67 |
$ui = 0;
|
|
|
68 |
|
|
|
69 |
while (($kb < $scale) && ($scale > 1))
|
|
|
70 |
{
|
|
|
71 |
$ui++;
|
|
|
72 |
$scale = $scale / 1024;
|
|
|
73 |
}
|
|
|
74 |
return sprintf("%0.2f %s", ($kb/$scale),$units[$ui]);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
function write_summary()
|
|
|
78 |
{
|
|
|
79 |
global $summary,$top,$day,$hour,$month;
|
|
|
80 |
|
|
|
81 |
$trx = $summary['totalrx']*1024+$summary['totalrxk'];
|
|
|
82 |
$ttx = $summary['totaltx']*1024+$summary['totaltxk'];
|
|
|
83 |
|
|
|
84 |
//
|
|
|
85 |
// build array for write_data_table
|
|
|
86 |
//
|
|
|
87 |
$sum[0]['act'] = 1;
|
|
|
88 |
$sum[0]['label'] = T('This hour');
|
|
|
89 |
$sum[0]['rx'] = $hour[0]['rx'];
|
|
|
90 |
$sum[0]['tx'] = $hour[0]['tx'];
|
|
|
91 |
|
|
|
92 |
$sum[1]['act'] = 1;
|
|
|
93 |
$sum[1]['label'] = T('This day');
|
|
|
94 |
$sum[1]['rx'] = $day[0]['rx'];
|
|
|
95 |
$sum[1]['tx'] = $day[0]['tx'];
|
|
|
96 |
|
|
|
97 |
$sum[2]['act'] = 1;
|
|
|
98 |
$sum[2]['label'] = T('This month');
|
|
|
99 |
$sum[2]['rx'] = $month[0]['rx'];
|
|
|
100 |
$sum[2]['tx'] = $month[0]['tx'];
|
|
|
101 |
|
|
|
102 |
$sum[3]['act'] = 1;
|
|
|
103 |
$sum[3]['label'] = T('All time');
|
|
|
104 |
$sum[3]['rx'] = $trx;
|
|
|
105 |
$sum[3]['tx'] = $ttx;
|
|
|
106 |
|
|
|
107 |
write_data_table(T('Summary'), $sum);
|
|
|
108 |
print "<br/>\n";
|
|
|
109 |
write_data_table(T('Top 10 days'), $top);
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
function write_data_table($caption, $tab)
|
|
|
114 |
{
|
|
|
115 |
print "<table width=\"100%\" cellspacing=\"0\">\n";
|
|
|
116 |
print "<caption>$caption</caption>\n";
|
|
|
117 |
print "<tr>";
|
|
|
118 |
print "<th class=\"label\" style=\"width:120px;\"> </th>";
|
|
|
119 |
print "<th class=\"label\">".T('In')."</th>";
|
|
|
120 |
print "<th class=\"label\">".T('Out')."</th>";
|
|
|
121 |
print "<th class=\"label\">".T('Total')."</th>";
|
|
|
122 |
print "</tr>\n";
|
|
|
123 |
|
|
|
124 |
for ($i=0; $i<count($tab); $i++)
|
|
|
125 |
{
|
|
|
126 |
if ($tab[$i]['act'] == 1)
|
|
|
127 |
{
|
|
|
128 |
$t = $tab[$i]['label'];
|
|
|
129 |
$rx = kbytes_to_string($tab[$i]['rx']);
|
|
|
130 |
$tx = kbytes_to_string($tab[$i]['tx']);
|
|
|
131 |
$total = kbytes_to_string($tab[$i]['rx']+$tab[$i]['tx']);
|
|
|
132 |
$id = ($i & 1) ? 'odd' : 'even';
|
|
|
133 |
print "<tr>";
|
|
|
134 |
print "<td class=\"label_$id\">$t</td>";
|
|
|
135 |
print "<td class=\"numeric_$id\">$rx</td>";
|
|
|
136 |
print "<td class=\"numeric_$id\">$tx</td>";
|
|
|
137 |
print "<td class=\"numeric_$id\">$total</td>";
|
|
|
138 |
print "</tr>\n";
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
print "</table>\n";
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
get_vnstat_data();
|
|
|
145 |
|
|
|
146 |
//
|
|
|
147 |
// html start
|
|
|
148 |
//
|
|
|
149 |
header('Content-type: text/html; charset=utf-8');
|
|
|
150 |
print '<?xml version="1.0"?>';
|
|
|
151 |
?>
|
|
|
152 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
|
153 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
|
154 |
<head>
|
|
|
155 |
<title>vnStat - PHP frontend</title>
|
|
|
156 |
<link rel="stylesheet" type="text/css" href="themes/<?php echo $style ?>/style.css"/>
|
|
|
157 |
</head>
|
|
|
158 |
<body>
|
|
|
159 |
|
|
|
160 |
<div id="wrap">
|
|
|
161 |
<div id="sidebar"><?php write_side_bar(); ?></div>
|
|
|
162 |
<div id="content">
|
|
|
163 |
<div id="header"><?php print T('Traffic data for')." $iface_title[$iface] ($iface)";?></div>
|
|
|
164 |
<div id="main">
|
|
|
165 |
<?php
|
|
|
166 |
$graph_params = "if=$iface&page=$page&style=$style";
|
|
|
167 |
if ($page != 's')
|
|
|
168 |
if ($graph_format == 'svg') {
|
|
|
169 |
print "<object type=\"image/svg+xml\" width=\"692\" height=\"297\" data=\"graph_svg.php?$graph_params\"></object>\n";
|
|
|
170 |
} else {
|
|
|
171 |
print "<img src=\"graph.php?$graph_params\" alt=\"graph\"/>\n";
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
if ($page == 's')
|
|
|
175 |
{
|
|
|
176 |
write_summary();
|
|
|
177 |
}
|
|
|
178 |
else if ($page == 'h')
|
|
|
179 |
{
|
|
|
180 |
write_data_table(T('Last 24 hours'), $hour);
|
|
|
181 |
}
|
|
|
182 |
else if ($page == 'd')
|
|
|
183 |
{
|
|
|
184 |
write_data_table(T('Last 30 days'), $day);
|
|
|
185 |
}
|
|
|
186 |
else if ($page == 'm')
|
|
|
187 |
{
|
|
|
188 |
write_data_table(T('Last 12 months'), $month);
|
|
|
189 |
}
|
|
|
190 |
?>
|
|
|
191 |
</div>
|
|
|
192 |
<div id="footer"><a href="http://www.sqweek.com/">vnStat PHP frontend</a> 1.5.1 - ©2006-2010 Bjorge Dijkstra (bjd _at_ jooz.net)</div>
|
|
|
193 |
</div>
|
|
|
194 |
</div>
|
|
|
195 |
|
|
|
196 |
</body></html>
|