[add] implement view in separate page

This commit is contained in:
Knah Tsaeb 2015-06-18 10:11:20 +02:00
parent 78aba94cde
commit 3f66739e44
11 changed files with 294 additions and 222 deletions

1
.htaccess Normal file
View File

@ -0,0 +1 @@
Options -Indexes

36
COPYING
View File

@ -1,10 +1,17 @@
Files: *
License: GNU GPL
Copyright : (c) 2012 - 2015 Kyle F. Berry (k6b) <kyle@kyleberry.com>
(c) 2015 Knah Tsaeb <knah-tsaeb_myfail2baninfo@knah-tsaeb.org>
Copyright : (c) 2012 - 2015 Kyle F. Berry (k6b) <kyle at kyleberry dot com>
(c) 2015 Knah Tsaeb <knah-tsaeb_myfail2baninfo at knah-tsaeb dot org>
All knah-tsaeb work are under ZLIB/LIBPNG LICENSE
All knah-tsaeb work's are under ZLIB/LIBPNG LICENSE
Files : jquery.tabbedcontent.min.js
License : MIT
Copyright : (c) 2015 Òscar Casajuana <elboletaire at underave dot net> http://elboletaire.github.io/tabbedcontent/index.html
Files : zepto.min.js
License : MIT
Copyright : (c) 2015 Thomas Fuchs http://zeptojs.com
--------------------
GNU GENERAL PUBLIC LICENSE
Version 1, February 1989
@ -275,4 +282,25 @@ freely, subject to the following restrictions:
2. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
3. This notice may not be removed or altered from any source distribution.
------------------------------------------
Copyright (c) 2015 Òscar Casajuana <elboletaire at underave dot net>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -1,4 +1,6 @@
mysqlhost="127.0.0.1"
mysqldb="fail2bancount"
mysqlpw=""
mysqluser="fail2bancount"
title="MyFail2BanInfo"
title="MyFail2BanInfo"
launchDate="DD-MM-YYYY"

253
index.php
View File

@ -17,7 +17,7 @@ echo "<div id='header'>\n";
// been borrowed from various places online. Use it as you
// like.
// Database connection info
$db_host = '127.0.0.1';
$db_host = $config['mysqlhost'];
$db_user = $config['mysqluser'];
$db_pwd = $config['mysqlpw'];
$database = $config['mysqldb'];
@ -28,8 +28,8 @@ function n_print($data, $name = '') {
$aBackTrace = debug_backtrace();
echo '<h2>', $name, '</h2>';
echo '<fieldset style="border: 1px solid orange; padding: 5px;color: #333; background-color: #fff;">';
echo '<legend style="border:1px solid orange;padding: 1px;background-color:#eee;color:orange;">', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '</legend>';
echo '<pre>', htmlentities(print_r($data, 1)), '</pre>';
echo '<legend style="border:1px solid orange;padding: 1px;background-color:#eee;color:orange;">', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '</legend>';
echo '<pre>', htmlentities(print_r($data, 1)), '</pre>';
echo '</fieldset><br />';
}
@ -43,19 +43,13 @@ if (!mysqli_select_db($db, $database)) {
}
// Get some information from the database
// Find IPs banned more than once
$multiplebans = mysqli_query($db, "SELECT ip,COUNT(*) count,country FROM bans GROUP BY ip HAVING count > 1 ORDER BY count DESC");
if (!$multiplebans) {
die("Query failed.");
}
$multiplebans = 1;
// Find the IPs currently banned
$currentbans = mysqli_query($db, "SELECT service,ip,ban_date,ban_time,country FROM bans WHERE bans.id NOT IN ( SELECT unbans.id FROM unbans WHERE bans.id=unbans.id)");
if (!$currentbans) {
die("Query failed.");
}
// Find the total number of IPs banned
$totalbans = mysqli_query($db, "SELECT MAX(id) FROM bans");
if (!$totalbans) {
die("Query failed.");
die("Query failed.3");
}
while ($row = mysqli_fetch_array($totalbans)) {
$numbans = $row['MAX(id)'];
@ -63,58 +57,17 @@ while ($row = mysqli_fetch_array($totalbans)) {
// Find the total number of IPs unbanned
$totalunbans = mysqli_query($db, "SELECT MAX(id) FROM unbans");
if (!$totalunbans) {
die("Query failed.");
die("Query failed.4");
}
while ($row = mysqli_fetch_array($totalunbans)) {
$numunbans = $row['MAX(id)'];
}
// Find multiple country bans
$countrybans = mysqli_query($db, "SELECT country,COUNT(*) count FROM bans GROUP BY country ORDER BY count DESC LIMIT 10");
if (!$countrybans) {
die("Query failed.");
}
// Display every IP banned
// Order by ID
$allbans = mysqli_query($db, "SELECT id,service,ip,ban_date,ban_time,country FROM bans ORDER BY id");
if (!$multiplebans) {
die("Query failed.");
}
// Order by IP
$allbans_ip = mysqli_query($db, "SELECT id,service,ip,ban_date,ban_time,country FROM bans ORDER BY ip, id");
if (!$multiplebans) {
die("Query failed.");
}
// Order by Date
$allbans_date = mysqli_query($db, "SELECT id,service,ip,ban_date,ban_time,country FROM bans ORDER BY ban_date, id");
if (!$multiplebans) {
die("Query failed.");
}
// Order by Time
$allbans_time = mysqli_query($db, "SELECT id,service,ip,ban_date,ban_time,country FROM bans ORDER BY ban_time, id");
if (!$multiplebans) {
die("Query failed.");
}
// Order by Country
$allbans_country = mysqli_query($db, "SELECT id,service,ip,ban_date,ban_time,country FROM bans ORDER BY country, id");
if (!$multiplebans) {
die("Query failed.");
}
// Order by Service
$allbans_service = mysqli_query($db, "SELECT id,service,ip,ban_date,ban_time,country FROM bans ORDER BY service, id");
if (!$multiplebans) {
die("Query failed.");
}
function getLast24hBan($db) {
$getLast24hBan = mysqli_query($db, "SELECT service,ip,ban_date,ban_time,country FROM bans WHERE concat_ws(' ',ban_date, ban_time) >= now() - INTERVAL 1 DAY ORDER BY id");
while ($rows = mysqli_fetch_assoc($getLast24hBan)) {
$lastBan[] = $rows;
}
if (empty($lastBan)) {
$lastBan = array();
}
return $lastBan;
}
if ($currentlybanned != 1) {
$grammer = "IPs are";
} else {
$grammer = "IP is";
}
// Get day with ban
function getDayWithBan($db) {
$getDayWithBan = mysqli_query($db, "SELECT DISTINCT ban_date FROM bans ORDER BY ban_date");
@ -135,169 +88,35 @@ $currentlybanned = $numbans - $numunbans;
echo "\t<h1>", $config['title'], "</h1>\n";
echo "</div>\n";
echo "<div id='container'>\n";
echo "\t<h3>$numbans IPs have been banned.</h3>\n";
echo "\t<h3>$numbans IPs have been banned since $config[launchDate]</h3>\n";
// Menu
echo "\t<div class='table'>\n";
echo "\t\t<div class='row'>\n";
echo "\t\t\t<a href='?page=home' class='menu'>Home</a>\n";
echo "\t\t\t<a href='?page=allbans' class='menu'>All Bans</a>\n";
echo "\t\t\t<a href='?page=last' class='menu'>Last 24h ban</a>\n";
echo "\t\t\t<a href='?page=recidivist' class='menu'>Recidivist</a>\n";
echo "\t\t\t<a href='?page=currentBan' class='menu'>Current ban</a>\n";
echo "\t\t\t<a href='?page=lastBan' class='menu'>Last 24h</a>\n";
echo "\t\t\t<a href='?page=allBans' class='menu'>All time</a>\n";
echo "\t\t\t<a href='?page=topTen' class='menu'>Top 10 countries</a>\n";
echo "\t\t</div>\n";
echo "\t</div>\n";
switch ($page) {
default :
// Begin creating the first table of IPs that have been banned
// more than once.
echo "\t<h2>Recidivist</h2>\n";
echo "\t<div class='table'>\n";
echo "\t\t<div class='row'>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tIP\n\t\t\t</div>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tBans\n\t\t\t</div>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tCountry\n\t\t\t</div>\n";
echo "\t\t</div>\n";
// Print the data obtained from the MySQL database
// Print the first table
while ($row = mysqli_fetch_row($multiplebans)) {
echo "\t\t<div class='row'>\n";
foreach ($row as $cell)
echo "\t\t\t<div class='cell'>\n\t\t\t\t$cell\n\t\t\t</div>\n";
echo "\t\t</div>\n";
}
echo "\t</div>\n";
mysqli_free_result($multiplebans);
// Use correct grammer
if ($currentlybanned != 1) {
$grammer = "IPs are";
} else {
$grammer = "IP is";
}
echo "\t<h3>Currently $currentlybanned $grammer banned.</h3>\n";
// Only print the second table if we have an IP
// currently banned.
if ($numbans > $numunbans) {
// Print the data obtained from the MySQL database
// Table title
echo "\t<h2>Currently Banned</h2>\n";
// Create the second table, of currently banned IPs
echo "\t<div class='table'>\n";
echo "\t\t<div class='row'>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tService\n\t\t\t</div>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tIP\n\t\t\t</div>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tDate\n\t\t\t</div>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tTime\n\t\t\t</div>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tCountry\n\t\t\t</div>\n";
echo "\t\t</div>\n";
// Print out the second table
while ($row = mysqli_fetch_row($currentbans)) {
echo "\t\t<div class='row'>\n";
foreach ($row as $cell)
echo "\t\t\t<div class='cell'>\n\t\t\t\t$cell\n\t\t\t</div>\n";
echo "\t\t</div>\n";
}
echo "\t</div>\n";
mysqli_free_result($currentbans);
}
// Print more HTML
echo "\t<h2>Top 10 Countries</h2>\n";
// Begin creating the second table of counrtys that have been banned
// more than once.
echo "\t<div class='table'>\n";
echo "\t\t<div class='row'>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tCountry\n\t\t\t</div>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tBans\n\t\t\t</div>\n";
echo "\t\t</div>\n";
// Print the first table
while ($row = mysqli_fetch_row($countrybans)) {
echo "\t\t<div class='row'>\n";
foreach ($row as $cell)
echo "\t\t\t<div class='cell'>\n\t\t\t\t$cell\n\t\t\t</div>\n";
echo "\t\t</div>\n";
}
echo "\t</div>\n";
mysqli_free_result($countrybans);
break;
case "allbans" :
echo "\t<div class='table'>\n";
echo "\t\t<div class='row'>\n";
echo "\t\t\t<a href='?page=allbans&amp;orderby=id' class='cell-header'>\n\t\t\t\t\n\t\t\t</a>\n";
echo "\t\t\t<a href='?page=allbans&amp;orderby=service' class='cell-header'>\n\t\t\t\t<u>Service</u>\n\t\t\t</a>\n";
echo "\t\t\t<a href='?page=allbans&amp;orderby=ip' class='cell-header'>\n\t\t\t\t<u>IP</u>\n\t\t\t</a>\n";
echo "\t\t\t<a href='?page=allbans&amp;orderby=date' class='cell-header'>\n\t\t\t\t<u>Ban Date</u>\n\t\t\t</a>\n";
echo "\t\t\t<a href='?page=allbans&amp;orderby=time' class='cell-header'>\n\t\t\t\t<u>Ban Time</u>\n\t\t\t</a>\n";
echo "\t\t\t<a href='?page=allbans&amp;orderby=country' class='cell-header'>\n\t\t\t\t<u>Country</u>\n\t\t\t</a>\n";
echo "\t\t</div>\n";
switch ($orderby) {
default :
case "id" :
while ($row = mysqli_fetch_row($allbans)) {
echo "\t\t<div class='row'>\n";
foreach ($row as $cell)
echo "\t\t\t<div class='cell'>\n\t\t\t\t$cell\n\t\t\t</div>\n";
echo "\t\t</div>\n";
}
case "ip" :
while ($row = mysqli_fetch_row($allbans_ip)) {
echo "\t\t<div class='row'>\n";
foreach ($row as $cell)
echo "\t\t\t<div class='cell'>\n\t\t\t\t$cell\n\t\t\t</div>\n";
echo "\t\t</div>\n";
}
break;
case "date" :
while ($row = mysqli_fetch_row($allbans_date)) {
echo "\t\t<div class='row'>\n";
foreach ($row as $cell)
echo "\t\t\t<div class='cell'>\n\t\t\t\t$cell\n\t\t\t</div>\n";
echo "\t\t</div>\n";
}
break;
case "time" :
while ($row = mysqli_fetch_row($allbans_time)) {
echo "\t\t<div class='row'>\n";
foreach ($row as $cell)
echo "\t\t\t<div class='cell'>\n\t\t\t\t$cell\n\t\t\t</div>\n";
echo "\t\t</div>\n";
}
break;
case "country" :
while ($row = mysqli_fetch_row($allbans_country)) {
echo "\t\t<div class='row'>\n";
foreach ($row as $cell)
echo "\t\t\t<div class='cell'>\n\t\t\t\t$cell\n\t\t\t</div>\n";
echo "\t\t</div>\n";
}
break;
case "service" :
while ($row = mysqli_fetch_row($allbans_service)) {
echo "\t\t<div class='row'>\n";
foreach ($row as $cell)
echo "\t\t\t<div class='cell'>\n\t\t\t\t$cell\n\t\t\t</div>\n";
echo "\t\t</div>\n";
}
break;
}
echo "\t</div>\n";
break;
case 'last' :
//id,service,ip,ban_date,ban_time,country
$getLast24hBan = getLast24hBan($db);
echo "\t<div class='table'>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tService\n\t\t\t</div>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tIP\n\t\t\t</div>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tDate\n\t\t\t</div>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tTime\n\t\t\t</div>\n";
echo "\t\t\t<div class='cell-header'>\n\t\t\t\tCountry\n\t\t\t</div>\n";
foreach ($getLast24hBan as $value) {
echo '<div class="row">
<div class="cell">', $value['service'], '</div>
<div class="cell">', $value['ip'], '</div>
<div class="cell">', $value['ban_date'], '</div>
<div class="cell">', $value['ban_time'], '</div>
<div class="cell">', $value['country'], '</div>
</div>';
}
echo '</div>';
break;
if ($page === 'home') {
require 'page/home.php';
}
if ($page === 'recidivist') {
require 'page/recidivist.php';
}
if ($page === 'currentBan') {
require 'page/currentBan.php';
}
if ($page === 'lastBan') {
require 'page/lastBan.php';
}
if ($page === 'topTen') {
require 'page/topTen.php';
}
if ($page === 'allBans') {
require 'page/allBans.php';
}
echo "</div>\n";
echo '<p><a href="#header">Go top</a></p>';
@ -305,7 +124,7 @@ $stop = microtime(true);
$total = round($stop - $start, 4);
echo 'Generate in ', $total, ' secondes</br>';
echo "<div id='footer'>\n";
echo "\t&#169;", date("Y"), " released under GNU GPL base on <a href='http://kylefberry.net'>k6b</a> work this version are made by Knah Tsaeb\n";
echo "\t&#169;", date("Y"), " released under GNU GPL base on <a href='http://kylefberry.net'>k6b</a> work this version are made by Knah Tsaeb\n";
echo "</div>\n";
echo "</body>\n";
echo "</html>\n";

1
page/.htaccess Normal file
View File

@ -0,0 +1 @@
Deny from All

38
page/allBans.php Normal file
View File

@ -0,0 +1,38 @@
<?php
// Order by ID
function getAllBan($db, $order = 'id') {
$sql = "SELECT id,service,ip,ban_date,ban_time,country FROM bans ORDER BY $order";
$res = mysqli_query($db, $sql);
while ($rows = mysqli_fetch_assoc($res)) {
$allBan[] = $rows;
}
if (empty($allBan)) {
$allBan = array();
}
return $allBan;
}
?>
<div class='table'>
<div class='row'>
<a href='?page=allBans&amp;orderby=service' class='cell-header'><u>Service</u></a>
<a href='?page=allBans&amp;orderby=ip' class='cell-header'><u>IP</u></a>
<a href='?page=allBans&amp;orderby=ban_date' class='cell-header'><u>Ban Date</u></a>
<a href='?page=allBans&amp;orderby=ban_time' class='cell-header'><u>Ban Time</u></a>
<a href='?page=allBans&amp;orderby=country' class='cell-header'><u>Country</u></a>
</div>
<?php
if (empty($orderby)) {
$orderby = 'id';
}
$allBan = getAllBan($db, $orderby);
foreach ($allBan as $value) {
echo '<div class="row">';
echo '<div class="cell">', $value['service'], '</div>';
echo '<div class="cell">', $value['ip'], '</div>';
echo '<div class="cell">', $value['ban_date'], '</div>';
echo '<div class="cell">', $value['ban_time'], '</div>';
echo '<div class="cell">', $value['country'], '</div>';
echo '</div>';
}
?>
</div>

48
page/currentBan.php Normal file
View File

@ -0,0 +1,48 @@
<?php
function getCurrentBan($db) {
$sql = mysqli_query($db, "SELECT service,ip,ban_date,ban_time,country FROM bans WHERE bans.id NOT IN ( SELECT unbans.id FROM unbans WHERE bans.id=unbans.id)");
while ($rows = mysqli_fetch_assoc($sql)) {
$currentBan[] = $rows;
}
if (empty($currentBan)) {
$currentBan = array();
}
mysqli_free_result($sql);
return $currentBan;
}
echo '<h3>Currently ',$currentlybanned,' ',$grammer,' banned.</h3>';
?>
<h2>Currently Banned</h2>
<div class='table'>
<div class='row'>
<div class='cell-header'>
Service
</div>
<div class='cell-header'>
IP
</div>
<div class='cell-header'>
Date
</div>
<div class='cell-header'>
Time
</div>
<div class='cell-header'>
Country
</div>
</div>
<?php
$currentBan = getCurrentBan($db);
foreach ($currentBan as $value) {
echo '<div class="row">
<div class="cell">', $value['service'], '</div>
<div class="cell">', $value['ip'], '</div>
<div class="cell">', $value['ban_date'], '</div>
<div class="cell">', $value['ban_time'], '</div>
<div class="cell">', $value['country'], '</div>
</div>';
}
?>
</div>

6
page/home.php Normal file
View File

@ -0,0 +1,6 @@
<h2>Welcome</h2>
<div>
<p>
MyFail2BanInfo is simple webapps for shows some information about your Fail2ban log.
</p>
</div>

53
page/lastBan.php Normal file
View File

@ -0,0 +1,53 @@
<?php
function getLast24hBan($db) {
$getLast24hBan = mysqli_query($db, "SELECT service,ip,ban_date,ban_time,country FROM bans WHERE concat_ws(' ',ban_date, ban_time) >= now() - INTERVAL 1 DAY ORDER BY id");
while ($rows = mysqli_fetch_assoc($getLast24hBan)) {
$lastBan[] = $rows;
}
if (empty($lastBan)) {
$lastBan = array();
}
return $lastBan;
}
?>
<div class='table'>
<div class='cell-header'>
Service
</div>
<div class='cell-header'>
IP
</div>
<div class='cell-header'>
Date
</div>
<div class='cell-header'>
Time
</div>
<div class='cell-header'>
Country
</div>
<?php
$getLast24hBan = getLast24hBan($db);
foreach ($getLast24hBan as $value) {
echo '
<div class="row">
<div class="cell">
', $value['service'], '
</div>
<div class="cell">
', $value['ip'], '
</div>
<div class="cell">
', $value['ban_date'], '
</div>
<div class="cell">
', $value['ban_time'], '
</div>
<div class="cell">
', $value['country'], '
</div>
</div>';
}
echo '
</div>
';

42
page/recidivist.php Normal file
View File

@ -0,0 +1,42 @@
<?php
function getRecidivist($db) {
$sql = mysqli_query($db, "SELECT ip, COUNT(*) count,country FROM bans GROUP BY ip HAVING count > 1 ORDER BY count DESC");
if (!$sql) {
die("Query failed. 1");
}
while ($rows = mysqli_fetch_assoc($sql)) {
$multiplebans[] = $rows;
}
mysqli_free_result($sql);
if (empty($multiplebans)) {
$multiplebans = array();
}
return $multiplebans;
}
$multiplebans = getRecidivist($db);
?>
<h2>Recidivist (<?php echo count($multiplebans); ?>)
</h2>
<div class='table'>
<div class='row'>
<div class='cell-header'>
IP
</div>
<div class='cell-header'>
Bans
</div>
<div class='cell-header'>
Country
</div>
</div>
<?php
foreach ($multiplebans as $value) {
echo '<div class="row">
<div class="cell">', $value['ip'], '</div>
<div class="cell">', $value['count'], '</div>
<div class="cell">', $value['country'], '</div>
</div>';
}
?>
</div>

34
page/topTen.php Normal file
View File

@ -0,0 +1,34 @@
<?php
// Find multiple country bans
function topTen($db) {
$countrybans = mysqli_query($db, "SELECT country,COUNT(*) count FROM bans GROUP BY country ORDER BY count DESC LIMIT 10");
while ($rows = mysqli_fetch_assoc($countrybans)) {
$topTen[] = $rows;
}
if (empty($topTen)) {
$topTen = array();
}
mysqli_free_result($countrybans);
return $topTen;
}
?>
<h2>Top 10 Countries</h2>
<div class='table'>
<div class='row'>
<div class='cell-header'>
Country
</div>
<div class='cell-header'>
Bans
</div>
</div>
<?php
$topTen = topTen($db);
foreach ($topTen as $value) {
echo '<div class="row">';
echo '<div class="cell">', $value['country'], '</div>';
echo '<div class="cell">', $value['count'], '</div>';
echo '</div>';
}
?>
</div>