160 lines
5.1 KiB
PHP
160 lines
5.1 KiB
PHP
<?php
|
|
$start = microtime(true);
|
|
$config = parse_ini_file('bin/bancount.cfg');
|
|
echo "<!DOCTYPE html>\n";
|
|
echo "<html lang='en'>\n";
|
|
echo "<head>\n";
|
|
echo "\t<title>", $config['title'], "</title>\n";
|
|
echo "\t<meta http-equiv='content-type' content='text/html; charset=utf-8' />\n";
|
|
echo "\t<meta name='description' content=", $config['title'], " />\n";
|
|
echo "\t<!-- CSS/STYLESHEET -->\n";
|
|
echo "\t<link rel='stylesheet' href='/bancount.css' type='text/css' />\n";
|
|
echo "</head>\n";
|
|
echo "<body>\n";
|
|
echo "<div id='header'>\n";
|
|
// Fail2BanCount - Displays information from the database
|
|
// I won't claim this is all my original code, as it has
|
|
// been borrowed from various places online. Use it as you
|
|
// like.
|
|
// Database connection info
|
|
$db_host = $config['mysqlhost'];
|
|
$db_user = $config['mysqluser'];
|
|
$db_pwd = $config['mysqlpw'];
|
|
$database = $config['mysqldb'];
|
|
// Page variable
|
|
$page = htmlspecialchars($_GET["page"]);
|
|
$sortBy = htmlspecialchars($_GET["sortBy"]);
|
|
$order = htmlspecialchars($_GET["order"]);
|
|
$newOrder = testOrder($order);
|
|
if ($order == 'a') {
|
|
$order = 'asc';
|
|
} else {
|
|
$order = 'desc';
|
|
}
|
|
function testOrder($order) {
|
|
if ($order == 'd') {
|
|
return 'a';
|
|
} else {
|
|
return 'd';
|
|
}
|
|
}
|
|
|
|
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 '</fieldset><br />';
|
|
}
|
|
|
|
// Connect to MySQL
|
|
if (!$db = mysqli_connect($db_host, $db_user, $db_pwd)) {
|
|
die("Can't connect to database");
|
|
}
|
|
if (!mysqli_select_db($db, $database)) {
|
|
mysqli_close($db);
|
|
die("Can't select database");
|
|
}
|
|
// Get some information from the database
|
|
// Find IPs banned more than once
|
|
$multiplebans = 1;
|
|
// Find the IPs currently banned
|
|
// Find the total number of IPs banned
|
|
$totalbans = mysqli_query($db, "SELECT MAX(id) FROM bans");
|
|
if (!$totalbans) {
|
|
die("Query failed.3");
|
|
}
|
|
while ($row = mysqli_fetch_array($totalbans)) {
|
|
$numbans = $row['MAX(id)'];
|
|
}
|
|
// Find the total number of IPs unbanned
|
|
$totalunbans = mysqli_query($db, "SELECT MAX(id) FROM unbans");
|
|
if (!$totalunbans) {
|
|
die("Query failed.4");
|
|
}
|
|
while ($row = mysqli_fetch_array($totalunbans)) {
|
|
$numunbans = $row['MAX(id)'];
|
|
}
|
|
$currentlybanned = $numbans - $numunbans;
|
|
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");
|
|
while ($rows = mysqli_fetch_assoc($getDayWithBan)) {
|
|
$allDate[] = $rows['ban_date'];
|
|
}
|
|
if (empty($allDate)) {
|
|
$allDate = array();
|
|
}
|
|
return $allDate;
|
|
}
|
|
|
|
function printFlag($countryCode) {
|
|
if (empty($countryCode)) {
|
|
return '';
|
|
} elseif (file_exists('img/flag/16/'.strtolower($countryCode).'.png')) {
|
|
return '<img src="img/flag/16/'.strtolower($countryCode).'.png" alt="'.$countryCode.' flag" title="'.$countryCode.'"/>';
|
|
} else {
|
|
return 'Unknown <img src="img/flag/16/unknow.png" alt="'.$countryCode.'" title="img/flag/16/'.strtolower($countryCode).'.png"/>';
|
|
}
|
|
}
|
|
|
|
// Find the number of currently banned IP's using subtraction.
|
|
// I'm sure I can do this with a single MySQL query and get
|
|
// rid of the above 2 queries all together.
|
|
$currentlybanned = $numbans - $numunbans;
|
|
// Print some HTML
|
|
echo "\t<h1>", $config['title'], "</h1>\n";
|
|
echo "</div>\n";
|
|
echo "<div id='container'>\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=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\t<a href='?page=topTenService' class='menu'>Top 10 services</a>\n";
|
|
echo "\t\t</div>\n";
|
|
echo "\t</div>\n";
|
|
if ($page === 'home' || empty($page)) {
|
|
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 === 'topTenService') {
|
|
require 'page/topTenService.php';
|
|
}
|
|
if ($page === 'allBans') {
|
|
require 'page/allBans.php';
|
|
}
|
|
echo "</div>\n";
|
|
echo '<p><a href="#header">Go top</a></p>';
|
|
$stop = microtime(true);
|
|
$total = round($stop - $start, 4);
|
|
echo 'Generate in ', $total, ' secondes</br>';
|
|
echo "<div id='footer'>\n";
|
|
echo "\t©", 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";
|
|
?>
|