[add] last 24h ban

This commit is contained in:
Knah Tsaeb 2015-06-01 15:02:21 +02:00
parent bf3e9aabef
commit 78aba94cde
2 changed files with 107 additions and 56 deletions

View File

@ -1,80 +1,77 @@
/*
Fail2BanCount - by k6b (kyle@kylefberry.net)
Fail2BanCount - by k6b (kyle@kylefberry.net)
*/
*/
body {
margin:0;
font-size:80%;
font-family: sans-serif;
text-align: center;
}
margin: 0;
font-size: 80%;
font-family: sans-serif;
text-align: center;
}
#header {
display: block;
width: 80%;
margin: auto;
}
display: block;
width: 80%;
margin: auto;
}
#container {
width: 80%;
margin: auto;
display: block;
}
width: 80%;
margin: auto;
display: block;
}
#footer {
width: 80%;
margin: auto;
display: block;
padding: 0.3em;
}
width: 80%;
margin: auto;
display: block;
padding: 0.3em;
}
.table {
width: auto;
margin: auto;
display: table;
}
width: auto;
margin: auto;
display: table;
}
.row {
display: table-row;
width: 100%
}
.row {
display: table-row;
width: 100%
}
.row
.menu {
width:50%;
padding:0.5em;
display: table-cell;
text-align: center;
font-weight: bold;
}
.row .menu {
padding: 0.5em;
display: table-cell;
text-align: center;
font-weight: bold;
}
.cell {
width:10em;
padding:0.4em;
display: table-cell;
text-align: center;
}
width: 10em;
padding: 0.4em;
display: table-cell;
text-align: center;
}
.cell-header {
padding:0.5em;
display: table-cell;
text-align: center;
text-decoration: underline;
font-weight: bold;
}
padding: 0.5em;
display: table-cell;
text-align: center;
text-decoration: underline;
font-weight: bold;
}
h1, h2, h3 {
padding: 0.1em 0.1em 0.2em 0.1em;
}
padding: 0.1em 0.1em 0.2em 0.1em;
}
a:link, a:visited, a:active {
text-decoration: none;
color:#000000;
}
text-decoration: none;
color: #000000;
}
a:hover {
color:#FF0000;
}
color: #FF0000;
}

View File

@ -24,6 +24,15 @@ $database = $config['mysqldb'];
// Page variable
$page = htmlspecialchars($_GET["page"]);
$orderby = htmlspecialchars($_GET["orderby"]);
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");
@ -95,6 +104,29 @@ $allbans_service = mysqli_query($db, "SELECT id,service,ip,ban_date,ban_time,cou
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;
}
// 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;
}
// 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.
@ -109,6 +141,7 @@ 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</div>\n";
echo "\t</div>\n";
switch ($page) {
@ -245,13 +278,34 @@ switch ($page) {
}
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;
}
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&#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";