<html>
<head>
<title>Statystyki ruchu</title>
<style type="text/css">
TD { font-family: arial, helvetica, sans-serif; }
</style>
</head>
<body bgcolor=#ffffff>
<?php
// funkcja odpowiedzialna za automatyczne dodawanie sufiksów do liczb
function print_sufix($number, $default = '') {
switch($default) {
case 'k':
echo number_format($number/1024, 2), "k";
break;
case 'M':
echo number_format($number/1024/1024, 2), "M";
break;
case 'G':
echo number_format($number/1024/1024/1024, 2), "G";
break;
default:
$sufix = '';
if ($number > 1024) {
$number /= 1024;
$sufix = 'k';
};
if ($number > 1024) {
$number /= 1024;
$sufix = 'M';
};
if ($number > 1024) {
$number /= 1024;
$sufix = 'G';
}
echo number_format($number, 2), $sufix;
}
}
$statistics_file = "/proc/net/ipt_account/mynetwork";
$bar_width = 200;
$bar_height = 10;
// pobranie statystyk
if (file_exists($statistics_file)) {
$statistics = file($statistics_file);
for ($i = 0; $i < count($statistics); $i++) {
$statistics[$i] = split(" ", $statistics[$i]);
}
$total_statistics = $statistics[0];
}
// funkcje sortujące
function cmp_wychodzacy($a, $b) {
if ($a[5] == $b[5]) return 0;
else if ($a[5] > $b[5]) return -1;
else return 1;
}
function cmp_wchodzacy($a, $b) {
if ($a[8] == $b[8]) return 0;
else if ($a[8] > $b[8]) return -1;
else return 1;
}
function cmp_stosunek($a, $b) {
$sa = $a[5]/($a[8]+$a[5]+1);
$sb = $b[5]/($b[8]+$b[5]+1);
if ($sa == $sb) return 0;
else if ($sa > $sb) return -1;
else return 1;
}
// sortowanie
switch ($_REQUEST['sortuj']) {
case 'wychodzacy':
usort($statistics, 'cmp_wychodzacy');
break;
case 'stosunek':
usort($statistics, 'cmp_stosunek');
break;
case 'wchodzacy':
default:
usort($statistics, 'cmp_wchodzacy');
}
?>
<center>
<h1>Statystyki ruchu dla komputerów z sieci 192.168.0.0/24</h1>
</center>
<form>
<table align="center" bgcolor=black cellpadding="4">
<tr bgcolor="#94ABC0" align=center><td colspan="5"><b>Parametry</b>
<tr bgcolor="#EDEDED">
<td>Sortuj według <select name="sortuj">
<option value="wchodzacy" <?php if ($_REQUEST['sortuj'] == "wchodzacy") print "selected"?>>wchodzący</option>
<option value="wychodzacy" <?php if ($_REQUEST['sortuj'] == "wychodzacy") print "selected"?>>wychodzący</option>
<option value="stosunek" <?php if ($_REQUEST['sortuj'] == "stosunek") print "selected"?>>stosunek wychodzący : wchodzący
</select>
<td>Jednostki <select name="jednostki">
<option value="">automatycznie</option>
<option value="k" <?php if ($_REQUEST['jednostki'] == "k") print "selected"?>>kB</option>
<option value="M" <?php if ($_REQUEST['jednostki'] == "M") print "selected"?>>MB</option>
<option value="G" <?php if ($_REQUEST['jednostki'] == "G") print "selected"?>>GB</option>
</select>
<td><input type=submit value="OK!">
</table>
</form>
<table align=center bgcolor=black cellpadding="4">
<tr bgcolor="#94ABC0" align=center><td><b>Pozycja</b><td><b>Komputer</b><td colspan=5><b>Statystyki ruchu</b>
<?php
$color = '#FFFFFF';
for ($i = 0, $pozycja = 0; $i < count($statistics); $i++) {
if ($statistics[$i][5] > 0 && $statistics[$i][8] > 0) {
if ($color == '#FFFFFF')
$color = '#EDEDED';
else
$color = '#FFFFFF';
echo '<tr bgcolor=',$color,'><td align=center rowspan=2>', ++$pozycja;
if ($statistics[$i][2] != "192.168.0.0")
echo '<td align=center rowspan=2>', $statistics[$i][2], '<br>(',gethostbyaddr($statistics[$i][2]),')';
else
echo '<td align=center rowspan=2>Wszystkie komputery';
echo
'<td><img src="bar_green.png" height="',$bar_height,'" width="', (float)$statistics[$i][8]/(float)($total_statistics[8] + 1) * $bar_width, '"><td align=right>',print_sufix($statistics[$i][8],$_REQUEST['jednostki']), '<td align=right>[', number_format((float)$statistics[$i][8]/(float)($total_statistics[8] + 1) * 100, 2), '%]<td rowspan=2 align=center><img src="bar_green.png" height="',$bar_height,'" width="', (float)$statistics[$i][8]/(float)($statistics[$i][8] + $statistics[$i][5] + 1) * $bar_width, '"><img src="bar_blue.png" height="',$bar_height,'" width="', (float)$statistics[$i][5]/(float)($statistics[$i][8] + $statistics[$i][5] + 1) * $bar_width, '"><br>[',number_format((float)100 * $statistics[$i][8]/(float)($statistics[$i][8] + $statistics[$i][5] + 1),2),'% : ',number_format((float)100 * $statistics[$i][5]/(float)($statistics[$i][5] + $statistics[$i][8] + 1),2),'%]','<td rowspan=2><a href="statistics.php?host=',$statistics[$i][2],'">Wykres</a>',
'<tr bgcolor=',$color,'><td><img src="bar_blue.png" height="',$bar_height,'" width="', (float)$statistics[$i][5]/(float)($total_statistics[5] + 1) * $bar_width, '"><td align=right>',print_sufix($statistics[$i][5],$_REQUEST['jednostki']), '<td align=right>[', number_format((float)$statistics[$i][5]/(float)($total_statistics[5] + 1) * 100, 2), '%]';
echo "\n";
}
}
echo '</table>', "\n";
?>
<br><br>
<table align=center>
<tr><td colspan=2 bgcolor="#94ABC0" align=center><b>Legenda</b></tr>
<tr><td align=center><img src="bar_green.png" height="10" width="30"><td align=left>ruch wchodziący</tr>
<tr><td align=center><img src="bar_blue.png" height="10" width="30"><td align=left>ruch wychodzący</tr>
</table>
</html>
</body>