2. Шлюз, Debian Lenny 5.04. Два сетевых интерфейса: eth0 смотрит к провайдеру, eth1 (192.168.0.126) - в локальную сеть.
Что было сделано:
а) Установил vnstat:
# aptitude install vnstat.
б) Создал базы данных для интерфейсов eth0 и eth1:
#vnstat -u -i eth0
#vnstat -u -i eth1
в) Проверил,программа vnstat работает:
Код: Выделить всё
# vnstat
rx / tx / total / estimated
eth1:
yesterday 489.15 MB / 7.47 GB / 7.95 GB
today 589.03 MB / 9.44 GB / 10.01 GB / 15.25 GB
eth0:
yesterday 7.46 GB / 471.18 MB / 7.92 GB
today 9.45 GB / 564.80 MB / 10.00 GB / 15.24 GBг) Создал директорию /var/www/html/vnstat.local/, куда, скопировал файлы vnStat PHP frontend 1.4.1. Владелец - www-data, права 755.
д) В файле /etc/apache2/sites-available/default, внёс запись:
Код: Выделить всё
<VirtualHost *:80>
ServerName www.vnstat.local
ServerAlias "vnstat.local"
DocumentRoot /var/www/html/vnstat.local
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory "/var/www/html/vnstat.local/">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>е) В конфигурационном файле bind9 (прямая зона), присутствует запись:
Код: Выделить всё
vnstat.local. IN A 192.168.0.126и) Конфигурационный файл vmstat /var/www/html/vnstat.local/config.php:
Код: Выделить всё
<?php
//
// vnStat PHP frontend 1.4.1 (c)2006-2008 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.
//
error_reporting(E_ALL | E_NOTICE);
//
// configuration parameters
//
// edit these to reflect your particular situation
//
$locale = 'en_US.UTF-8';
$language = 'ru';
// list of network interfaces monitored by vnStat
// по умолчанию $iface_list = array('eth0', 'sixxs');
// see file COPYING or at http://www.gnu.org/licenses/gpl.html
// for more information.
//
error_reporting(E_ALL | E_NOTICE);
//
// configuration parameters
//
// edit these to reflect your particular situation
//
$locale = 'en_US.UTF-8';
$language = 'ru';
// list of network interfaces monitored by vnStat
// по умолчанию $iface_list = array('eth0', 'sixxs');
$iface_list = array('eth0','eth1');
//
// optional names for interfaces
// if there's no name set for an interface then the interface identifier
// will be displayed instead
//
$iface_title['eth0'] = 'Internet';
$iface_title['eth1'] = 'Internal';
//$iface_title['sixxs'] = 'SixXS IPv6';
//
// There are two possible sources for vnstat data. If the $vnstat_bin
// variable is set then vnstat is called directly from the PHP script
// to get the interface data.
//
// The other option is to periodically dump the vnstat interface data to
// a file (e.g. by a cronjob). In that case the $vnstat_bin variable
// must be cleared and set $data_dir to the location where the dumps
// are stored. Dumps must be named 'vnstat_dump_$iface'.
//
// You can generate vnstat dumps with the command:
// vnstat --dumpdb -i $iface > /path/to/data_dir/vnstat_dump_$iface
//
$vnstat_bin = '/usr/bin/vnstat';
$data_dir = './dumps';
// graphics format to use: svg or png
$graph_format='svg';
// Font to use for PNG graphs
define('GRAPH_FONT',dirname(__FILE__).'/VeraBd.ttf');
// Font to use for SVG graphs
define('SVG_FONT', 'Verdana');
// Default theme
define('DEFAULT_COLORSCHEME', 'light');
?>ж) Файл /var/www/html/vnstat.local/index.php:
Код: Выделить всё
<?php
//
// vnStat PHP frontend 1.4.1 (c)2006-2008 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)
{
print "<li class=\"iface\">";
if (isset($iface_title[$if]))
{
print $iface_title[$if];
}
else
{
print $if;
}
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)
{
$units = array('TB','GB','MB','KB');
$scale = 1024*1024*1024;
$ui = 0;
while (($kb < $scale) && ($scale > 1))
{
$ui++;
$scale = $scale / 1024;
}
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[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"/>
</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')." $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> 1.4.1 - ©2006-2008 Bjorge Dijkstra (bjd _at_ jooz.net)</div>
</div>
</div>
</body></html>з) В результате, вышеописанных действий, набираю в браузере http://vnstat.local, и вижу страницу vnstat c записью об ошибке:
Код: Выделить всё
Notice: Undefined index: totalrx in /var/www/html/vnstat.local/index.php on line 81
Notice: Undefined index: totalrxk in /var/www/html/vnstat.local/index.php on line 81
Notice: Undefined index: totaltx in /var/www/html/vnstat.local/index.php on line 82
Notice: Undefined index: totaltxk in /var/www/html/vnstat.local/index.php on line 82Соответственно входящий, исходящий трафик, показан по нулям.
Насколько понял, проблема в index.php:
Код: Выделить всё
....
$trx = $summary['totalrx']*1024+$summary['totalrxk'];
$ttx = $summary['totaltx']*1024+$summary['totaltxk'];
.....Точнее, неопределены переменные totalrx и totalrxk.
Теперь вопрос, как это всё победить?