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

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

Class DatabaseStats {

  var $date = 10000;

  function DatabaseStats($aDate=FALSE) {
    if ($aDate !== FALSE) {
    	$this->date=$aDate;
    }
  }

  function display() {
    global $cache_delay;

    $cache = new Cache($cache_delay);

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

  }

  function generate() {
    global $dateToString;

    $query = "SELECT count(local_time) FROM ulog";
    $result = db_query ($query);
    $line = db_nextarray($result);

    $out .= "<table>";
    $out .= "<tr class='DatabaseStats'><td align='right'>$line[0]</td><td>packets in database</td></tr>\n";

    if ($this->date < 1000) { 
        $query = "SELECT count(local_time) FROM ulog WHERE local_time > UNIX_TIMESTAMP(ADDDATE(CURDATE(),INTERVAL -" . $this->date ." DAY))"; 
        $result = db_query ($query);
        $line = db_nextarray($result);
        $out .= "<tr class='DatabaseStats'><td align='right'>$line[0]</td><td>packets younger than ".$dateToString[$this->date]."</td></tr>";
    }


    $query = "SELECT count(local_time) FROM ulog where TO_DAYS(NOW()) - TO_DAYS(FROM_UNIXTIME(local_time)) < 1";
    $result = db_query ($query);
    $line = db_nextarray($result);
    
    $out .= "<tr class='DatabaseStats'><td align='right'>$line[0]</td><td>packets today</td></tr>"; 
    $out .= "</table>";

    $out .= "<span class='DatabaseStats'>First was at ";

    $query = "SELECT FROM_UNIXTIME(min(local_time)) as max FROM ulog";
    $result = db_query ($query);
    $line = db_nextarray($result);
    
    $out .= "$line[0]</span>";
    $out .= "<br>";
    $out .= "<span class='DatabaseStats'>Last was at ";

    $query = "SELECT FROM_UNIXTIME(max(local_time)) as max FROM ulog";
    $result = db_query ($query);
    $line = db_nextarray($result);
    
    $out .= "$line[0]</span>";

    return $out;

  }
}

?>
Return current item: IPTables log analyzer