<?php
/////////////////////////////////////////////////////////////////////////////////////
// IPTable log analyzer
// Copyright (C) 2002 Gerald GARCIA
//
// 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 Plac<B2>e - Suite 330, Boston, MA 02111-1307, USA.
//
// Contact author : hide@address.com
/////////////////////////////////////////////////////////////////////////////////////
// $Id: TopDomains.php,v 1.5 2007/03/30 22:39:21 tarbuck Exp $
require_once("$file_base/utils/Cache.php");
Class TopDomains {
function TopDomains() {
}
function display() {
global $cache_delay;
$cache = new Cache($cache_delay);
$str = $cache->get("TopDomains");
if (strlen($str)==0) {
print "<!-- The module is regenerated -->\n";
$str = $this->generate();
$cache->put("TopDomains",$str);
}
print $str;
}
function generate() {
global $chain;
global $date;
global $domain_len;
global $url_base;
if ($chain != 'ALL') {
$chain_where = "AND u.oob_prefix='$chain'";
}
if ($date < 1000) {
$date_where = "AND u.local_time > UNIX_TIMESTAMP(ADDDATE(CURDATE(),INTERVAL -$date DAY))";
}
$query = "SELECT SUBSTRING_INDEX(hc.host,'.',-$domain_len) AS domain, count(u.id) as nb FROM ulog u JOIN host_cache hc ON u.ip_saddr = hc.ip WHERE 1=1 $chain_where $date_where GROUP BY SUBSTRING_INDEX(hc.host,'.',-$domain_len) ORDER BY nb DESC LIMIT 10";
$result = db_query ($query);
$out .= "<table width='100%'>\n";
$out .= "<tr class='ModuleTabTitle'><td>Domain</td><td>Nb</td></tr>\n";
while($line = db_nextobject($result)){
$out .= "<tr class='TopDomainsEntry'><td>";
$query = "SELECT INET_NTOA(ip) AS ip_s FROM host_cache WHERE host='" . $line->domain ."'";
$result2 = db_query($query);
if ($ip = db_nextvalue($result2)) {
$out .= "<a href='$url_base/from_host.php?ip=$ip'>$line->domain</a>";
} else {
$out .= "<a href='$url_base/from_domain.php?domain=$line->domain'>$line->domain</a>";
}
$out .= "</td><td align=right>$line->nb</td></tr>\n";
}
$out .= "</table>\n";
return $out;
}
}
?>