admin panel and password protection

This commit is contained in:
2025-07-26 19:00:14 -07:00
parent 3ca3676b36
commit ce8c47d50d
4 changed files with 265 additions and 58 deletions

View File

@@ -1,24 +1,57 @@
<?php
$dir = __DIR__ . '/images/';
$thumbDir = $dir . 'thumbnails/';
$extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'];
$images = [];
if (is_dir($dir)) {
foreach (scandir($dir) as $file) {
$dir = __DIR__ . '/images/';
$extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'];
$albums = [];
$passwordFile = __DIR__ . '/passwords.json';
$passwords = file_exists($passwordFile) ? json_decode(file_get_contents($passwordFile), true) : [];
// If album is requested, check password
if (isset($_GET['album'])) {
$album = $_GET['album'];
$pw = isset($_GET['password']) ? $_GET['password'] : null;
if (!is_dir($dir . $album)) {
http_response_code(404);
echo json_encode(['error' => 'Album not found']);
exit;
}
if (isset($passwords[$album]) && $passwords[$album] !== '') {
if ($pw !== $passwords[$album]) {
http_response_code(403);
echo json_encode(['error' => 'Password required']);
exit;
}
}
$albumImages = [];
$thumbDir = $dir . $album . '/thumbnails/';
$albumDir = $dir . $album . '/';
foreach (scandir($albumDir) as $file) {
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (in_array($ext, $extensions)) {
$thumbPath = 'images/thumbnails/' . $file;
$fullPath = 'images/' . $file;
// Check if thumbnail exists
$thumbPath = 'images/' . $album . '/thumbnails/' . $file;
$fullPath = 'images/' . $album . '/' . $file;
if (file_exists($thumbDir . $file)) {
$images[] = ['thumb' => $thumbPath, 'full' => $fullPath];
$albumImages[] = ['thumb' => $thumbPath, 'full' => $fullPath];
} else {
$images[] = ['thumb' => $fullPath, 'full' => $fullPath];
$albumImages[] = ['thumb' => $fullPath, 'full' => $fullPath];
}
}
}
header('Content-Type: application/json');
echo json_encode($albumImages);
exit;
}
// Otherwise, return album list (for landing page)
if (is_dir($dir)) {
foreach (scandir($dir) as $album) {
if ($album === '.' || $album === '..' || !is_dir($dir . $album)) continue;
$albums[$album] = [
'protected' => isset($passwords[$album]) && $passwords[$album] !== '',
];
}
}
header('Content-Type: application/json');
echo json_encode($images);
echo json_encode($albums);
?>