Location: PHPKode > projects > IPTables log analyzer > iptablelog/admin/show_cache.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: show_cache.php,v 1.1 2007/04/04 16:44:05 tarbuck Exp $


require_once("../conf/config.php");
require_once("conf/config.php");
#require_once("utils/Misc.php");
?>
<html>
<head>
   <title>IPTables logs</title>   
   <meta content="text/html;charset=UTF-8" http-equiv="content-type">
   <link rel="stylesheet" type="text/css" href="<? echo $url_base . "/themes/" . $css_styles[$css_style] . "/" . $css_styles[$css_style]; ?>.css" />

</head>
<body>
<br>
<blockquote class="ModuleTitle">Cached Hostnames</blockquote>

<?php 

  $order_by = "ORDER BY ip";
  $where = '';
  if (!isset($_REQUEST['start'])) {
  	$start = 0;
  } else {
	$start = $_REQUEST['start'];
  }
  if (!isset($_REQUEST['limit'])) {
  	$limit = 50;
  } else {
	$limit = $_REQUEST['limit'];
  }
  $limit_clause = "LIMIT $start,$limit";

  $query = "SELECT count(ip) FROM host_cache WHERE 1=1 $where";
  $result = db_query ($query);
  $nb_records=db_nextvalue($result);

  $query = "SELECT INET_NTOA(ip) as ip_s, ip, host, static FROM host_cache WHERE 1=1 $where $order_by $limit_clause";

$result = db_query ($query);


?>

<blockquote>
<table cellspacing="1" cellpadding="1" width="100%">
  <tr bgcolor="#DDDDDD"><td>
<table cellspacing="1" cellpadding="1" width="100%">
<tr>
<td width="100%" align=center colspan=3>
<table cellspacing="1" cellpadding="1" width="100%">
<tr>
<td width="10%" align=left valign=top><font size=-2><?
if ($start <= $limit) { echo "&nbsp;"; } else {
        echo "<a href='show_cache.php?start=" . ($start - $limit) .
                "&limit=$limit'>&nbsp;&lt; Prev</a>";
}
echo "<br><a href='show_cache.php?start=0&limit=$limit'>&lt;&lt; First</a>";
?></font></td>
<td align=center><?

echo "<form name=cache_form method=post action=show_cache.php>\n"  .
        "<input type=hidden name=start value=$start>\nDisplaying " .
        "<select name=limit onchange='this.form.submit();'>\n";
foreach (array(10,25,50,100) as $i) {
        echo "<option";
        if ($i == $limit) { echo " selected"; }
        echo ">$i</option>\n";
}
echo "</select> of $nb_records hosts, from $start. \n &nbsp; ";
#echo "</td><td width=\"40%\" align=left valign=top>";
if ($nb_records > $limit) {
        $num_pages = ceil($nb_records / $limit);
        $this_page = ceil($start / $limit) + 1;
        echo "Page <select name=start onChange='this.form.submit()'>\n";
        if ($num_pages <= 10) {
                for ($i = 1;$i <= $num_pages;$i++) {
                        echo "<option value=" . $i * $limit;
                        if ($i == $this_page) { echo " selected"; }
                        echo ">$i</option>\n";
                }
        } else {
                if ($this_page > ($num_pages - 3)) {
                        $start_page = $num_pages - 5;
                        echo "<option value=0>1</option>\n<option value=0>...</option>\n";
                        for ($i = 9;$i < $start_page;$i += 10) {
                                echo "<option value=" . ($limit * $i) . ">" . ($i + 1) . "</option>\n";
                        }
                } elseif ($this_page > 3) {
                        $append_page = "";
                        echo "<option value=0>1</option>\n<option value=0>...</option>\n";
                        for ($i = ceil(($this_page + 3)/10)*10 -1;$i < $num_pages;$i += 10) {
                                $append_page .= "<option value=" . ($limit * $i) . ">" . ($i + 1) . "</option>\n";
                        }
                        if ($this_page > ($num_pages - 5)) {
                                $start_page = ($num_pages - 5);
                        } else {
                                $start_page = $this_page - 2 ;
                                $append_page .= "<option value=" . ($limit * ($num_pages - 1)) .
                                        ">...</option>\n<option value=" . ($limit * ($num_pages - 1)) .
                                        ">$num_pages</option>\n";

                        }
                        for ($i = 9;$i < $start_page;$i += 10) {
                                echo "<option value=" . ($limit * $i) . ">" . ($i + 1) . "</option>\n";
                        }
                } else {
                        $start_page = 1;
                        for ($i = 9;$i < $num_page;$i += 10) {
                                echo "<option value=" . ($limit * $i) . ">" . ($i + 1) . "</option>\n";
                        }
                        $append_page = "";
                        for ($i = ceil(($this_page + 3)/10)*10 -1;$i < $num_pages;$i += 10) {
                                $append_page .= "<option value=" . ($limit * $i) . ">" . ($i + 1) . "</option>\n";
                        }
                        $append_page .= "<option value=" . ($limit * ($num_pages - 1)) .
                                ">...</option>\n<option value=" . ($limit * ($num_pages - 1)) .
                                ">$num_pages</option>\n";
                }

                for ($i = $start_page - 1;$i <= ($start_page + 4);$i++) {
                        echo "<option value=" . $i * $limit;
                        if ($i == ($this_page - 1)) { echo " selected"; }
                        echo ">" . ($i + 1) . "</option>\n";
                }
                if (isset($append_page)) { echo $append_page; }
        }
        echo "</select>\n of $num_pages.";
}
echo "</form>\n";
?></td>
<td width="10%" align=right valign=top><font size=-2><?
        if (($start + $limit) < ($nb_records - $limit)) {
                echo "<a href=\"show_cache.php?start=" . ($start + $limit) .
                        "&limit=$limit\">Next &gt;</a>";
        }
?>&nbsp;
<br>
<a href='show_cache.php?start=<?
        echo $nb_records - $limit . "&limit=$limit";
?>'>Last &gt;&gt;</a></font>
</td>
</tr>
</table></td>
</tr>
<tr>
  <td><center>Ip Address</center></td>
<td><center>Hostname</center></td>
<td><center>Static?</center></td>
</tr>
<?
while($line = db_nextobject($result)){
    print "<tr bgcolor=\"#FFFFFF\">";
    print "<td><center>$line->ip_s</center></td>";
    print "<td>$line->host</td>";
    print "<td>$line->static</td>";
    print "</tr>\n";
  }

?>
<tr>
<td width="100%" align=center colspan=3>
<table cellspacing="1" cellpadding="1" width="100%">
<tr>
<td width="10%" align=left valign=top><font size=-2><?
if ($start <= $limit) { echo "&nbsp;"; } else {
        echo "<a href='show_cache.php?start=" . ($start - $limit) .
                "&limit=$limit'>&nbsp;&lt; Prev</a>";
}
echo "<br><a href='show_cache.php?start=0&limit=$limit'>&lt;&lt; First</a>";
?></font></td>

<td>&nbsp;</td>
<td width="10%" align=right valign=top><font size=-2><?
        if (($start + $limit) < ($nb_records - $limit)) {
                echo "<a href=\"show_cache.php?start=" . ($start + $limit) .
                        "&limit=$limit\">Next &gt;</a>";
        }
?>&nbsp;
<br>
<a href='show_cache.php?start=<?
        echo $nb_records - $limit . "&limit=$limit";
?>'>Last &gt;&gt;</a></font>
</td>
</tr>
</table></td></tr></table>
</td></tr>
</table>


</blockquote>
<center><a href="javascript:window.close()">close</a></center>
<br>
</body>
</html>
Return current item: IPTables log analyzer