<table>
<tr>
<th>Name</th>
<th>Hits</th>
<th>Distinct attackers</th>
<th>Last hit</th>
</tr>
<?php
function disp_worm ($name, $url, $hits, $attackers, $last_hit)
{
echo " <tr>\n";
echo " <td><a href=\"$url\">$name</a>\n";
echo " <td>$hits</td>\n";
echo " <td>$attackers</td>\n";
echo " <td>$last_hit</td>\n";
echo " </tr>\n";
}
$statfile = fopen ("/var/lib/wormstat", "r");
while ($statfile != FALSE && !feof ($statfile))
{
$line = rtrim (fgets ($statfile, 1024));
// Let's parse wormstat output ('key: value')
list ($key, $value) = split (':', $line, 2);
$value = ltrim ($value);
switch ($key)
{
case 'name' : $w_name = $value; break;
case 'URL' : $w_url = $value; break;
case 'hits' : $w_hits = $value; break;
case 'attackers': $w_attackers = $value; break;
case 'last hit' : $w_last_hit = $value; break;
case '' :
if ($prev_key != '')
{
disp_worm ($w_name, $w_url, $w_hits, $w_attackers, $w_last_hit);
$w_last_hit = ""; // 'last hit' is not always defined, re-init here
}
break;
}
$prev_key = $key;
}
fclose ($statfile);
?>
</table>
|