Update gab/index.php
This commit is contained in:
+24
-106
@@ -1,136 +1,54 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$password = "GabrielIsDeBeste123";
|
$correct_password = "GabrielIsDeBeste123";
|
||||||
|
|
||||||
$ip = $_SERVER['REMOTE_ADDR'];
|
$ip = $_SERVER['REMOTE_ADDR'];
|
||||||
$dir = __DIR__ . "/bans";
|
$banDir = __DIR__ . "/bans";
|
||||||
|
|
||||||
if (!is_dir($dir)) {
|
if (!is_dir($banDir)) {
|
||||||
mkdir($dir);
|
mkdir($banDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = "$dir/" . md5($ip) . ".json";
|
$banFile = $banDir . "/" . md5($ip) . ".json";
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
"attempts" => 0,
|
"attempts" => 0,
|
||||||
"ban_until" => 0
|
"ban_until" => 0
|
||||||
];
|
];
|
||||||
|
|
||||||
if (file_exists($file)) {
|
if (file_exists($banFile)) {
|
||||||
$data = json_decode(file_get_contents($file), true);
|
$data = json_decode(file_get_contents($banFile), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time() < $data["ban_until"]) {
|
if (time() < $data["ban_until"]) {
|
||||||
die("Verbannen tot " . date("Y-m-d H:i:s", $data["ban_until"]));
|
http_response_code(403);
|
||||||
|
exit("IP geblokkeerd tot " . date("Y-m-d H:i:s", $data["ban_until"]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
// Basic Auth check
|
||||||
|
if (!isset($_SERVER['PHP_AUTH_PW']) ||
|
||||||
if ($_POST["password"] === $password) {
|
$_SERVER['PHP_AUTH_PW'] !== $correct_password) {
|
||||||
|
|
||||||
unlink($file);
|
|
||||||
echo "Ingelogd!";
|
|
||||||
exit;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$data["attempts"]++;
|
$data["attempts"]++;
|
||||||
|
|
||||||
if ($data["attempts"] >= 10) {
|
if ($data["attempts"] >= 10) {
|
||||||
$data["ban_until"] = time() + 86400; // 1 dag
|
$data["ban_until"] = time() + 86400; // 24 uur
|
||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents($file, json_encode($data));
|
file_put_contents($banFile, json_encode($data));
|
||||||
}
|
|
||||||
|
header('WWW-Authenticate: Basic realm="Foto Viewer"');
|
||||||
|
header('HTTP/1.0 401 Unauthorized');
|
||||||
|
exit('Wachtwoord vereist');
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset bij succes
|
||||||
|
if (file_exists($banFile)) {
|
||||||
|
unlink($banFile);
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
|
||||||
<form method="post">
|
|
||||||
<input type="password" name="password">
|
|
||||||
<button>Login</button>
|
|
||||||
</form>
|
|
||||||
<?php
|
|
||||||
$images = array_values(array_filter(scandir('.'), function($file) {
|
$images = array_values(array_filter(scandir('.'), function($file) {
|
||||||
return preg_match('/\.(jpg|jpeg|png|gif|webp)$/i', $file);
|
return preg_match('/\.(jpg|jpeg|png|gif|webp)$/i', $file);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="nl">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Foto Viewer</title>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
background: #111;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
height: 100vh;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
img {
|
|
||||||
max-width: 95vw;
|
|
||||||
max-height: 95vh;
|
|
||||||
object-fit: contain;
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
position: fixed;
|
|
||||||
top: 50%;
|
|
||||||
transform: translateY(-50%);
|
|
||||||
font-size: 2rem;
|
|
||||||
padding: 10px 20px;
|
|
||||||
background: rgba(0,0,0,0.5);
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
#prev { left: 20px; }
|
|
||||||
#next { right: 20px; }
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<button id="prev">◀</button>
|
|
||||||
<img id="image">
|
|
||||||
<button id="next">▶</button>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
const images = <?= json_encode($images) ?>;
|
|
||||||
|
|
||||||
let current = 0;
|
|
||||||
const img = document.getElementById('image');
|
|
||||||
|
|
||||||
function showImage() {
|
|
||||||
img.src = images[current];
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('prev').onclick = () => {
|
|
||||||
current = (current - 1 + images.length) % images.length;
|
|
||||||
showImage();
|
|
||||||
};
|
|
||||||
|
|
||||||
document.getElementById('next').onclick = () => {
|
|
||||||
current = (current + 1) % images.length;
|
|
||||||
showImage();
|
|
||||||
};
|
|
||||||
|
|
||||||
document.addEventListener('keydown', e => {
|
|
||||||
if (e.key === 'ArrowLeft') {
|
|
||||||
document.getElementById('prev').click();
|
|
||||||
} else if (e.key === 'ArrowRight') {
|
|
||||||
document.getElementById('next').click();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
showImage();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user