Location: PHPKode > projects > IPTables log analyzer > iptablelog/modules/TopProto.php
<?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: TopProto.php,v 1.2 2007/02/22 16:51:03 tarbuck Exp $

require_once("$file_base/utils/Cache.php");

Class TopProto {

  function TopProto() {
  }

  function generate() {
    global $chain;
    global $date;

    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 p.name AS proto,count(u.local_time) as nb FROM ulog u  LEFT OUTER JOIN protos p ON u.ip_protocol = p.num WHERE 1=1 $date_where $chain_where GROUP BY proto ORDER BY nb DESC";
    $result = db_query ($query);
    
    $out .= "<table width='100%'>\n";
    $out .= "<tr class='ModuleTabTitle'><td>Proto</td><td>Nb</td></tr>\n";
    while($line = db_nextobject($result)){
      $out .= "<tr class='TopDomainsEntry'><td>";
      $out .= "$line->proto";
      $out .= "</td><td>$line->nb</td></tr>\n";
    }
    $out .= "</table>\n";

    return $out;
  }

  function display() {
    global $cache_delay;

    $cache = new Cache($cache_delay);

    $str = $cache->get("TopProto");
    if (strlen($str)==0) {
      print "<!-- The module is regenerated -->\n";
      $str = $this->generate();
      $cache->put("TopProto",$str);
    }
    print $str;
  }

}

?>
Return current item: IPTables log analyzer