226 lines
11 KiB
PHP
226 lines
11 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
// Passwords now stored per album in images/<album>/password.txt
|
|
|
|
// Simple admin login (hardcoded for demo)
|
|
$adminPassword = 'admin123';
|
|
$loggedIn = isset($_SESSION['admin']) && $_SESSION['admin'] === true;
|
|
|
|
// AJAX endpoint to get album info
|
|
if (isset($_GET['get_album_info']) && isset($_GET['album'])) {
|
|
$album = $_GET['album'];
|
|
$pwFile = __DIR__ . '/images/' . $album . '/info.yaml';
|
|
$pw = '';
|
|
$title = '';
|
|
if (file_exists($pwFile)) {
|
|
if (function_exists('yaml_parse_file')) {
|
|
$yaml = yaml_parse_file($pwFile);
|
|
$pw = isset($yaml['password']) ? $yaml['password'] : '';
|
|
$title = isset($yaml['title']) ? $yaml['title'] : '';
|
|
} else {
|
|
$lines = file($pwFile);
|
|
foreach ($lines as $line) {
|
|
if (preg_match('/^password:\s*(.+)$/', trim($line), $m)) {
|
|
$pw = $m[1];
|
|
}
|
|
if (preg_match('/^title:\s*(.+)$/', trim($line), $m)) {
|
|
$title = $m[1];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['password' => $pw, 'title' => $title]);
|
|
exit;
|
|
}
|
|
|
|
if (isset($_POST['admin_login'])) {
|
|
if ($_POST['admin_password'] === $adminPassword) {
|
|
$_SESSION['admin'] = true;
|
|
$loggedIn = true;
|
|
} else {
|
|
$error = 'Incorrect admin password.';
|
|
}
|
|
}
|
|
|
|
if ($loggedIn && isset($_POST['set_album_password'])) {
|
|
$album = $_POST['album_name'];
|
|
$pw = $_POST['album_password'];
|
|
$title = isset($_POST['album_title']) ? $_POST['album_title'] : '';
|
|
if ($album && $pw !== null) {
|
|
$pwFile = __DIR__ . '/images/' . $album . '/info.yaml';
|
|
$yamlArr = ['password' => $pw, 'title' => $title];
|
|
$yamlContent = "password: " . $pw . "\ntitle: " . $title . "\n";
|
|
if (function_exists('yaml_emit_file')) {
|
|
yaml_emit_file($pwFile, $yamlArr);
|
|
} else {
|
|
file_put_contents($pwFile, $yamlContent);
|
|
}
|
|
$success = "Password and title set for album '$album'.";
|
|
}
|
|
}
|
|
|
|
if (isset($_POST['logout'])) {
|
|
session_destroy();
|
|
header('Location: admin.php');
|
|
exit;
|
|
}
|
|
|
|
// Get album list
|
|
$dir = __DIR__ . '/images/';
|
|
$albums = [];
|
|
if (is_dir($dir)) {
|
|
foreach (scandir($dir) as $album) {
|
|
if ($album === '.' || $album === '..' || !is_dir($dir . $album)) continue;
|
|
$albums[] = $album;
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Admin - Album Passwords</title>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; background: #181818; color: #e0e0e0; }
|
|
.container { max-width: 500px; background: #222; padding: 24px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.32); margin: 0; }
|
|
h2 { text-align: center; color: #4fa3ff; }
|
|
label { font-weight: bold; color: #e0e0e0; }
|
|
input, select { width: 100%; padding: 8px; margin: 8px 0 16px 0; border-radius: 4px; border: 1px solid #444; background: #181818; color: #e0e0e0; }
|
|
#admin_password { width: 76%; min-width: 180px; display: inline-block; }
|
|
#album_password, #album_title { width: 95%; min-width: 180px; display: inline-block; }
|
|
button { padding: 8px 16px; background: #333; color: #fff; border: 1px solid #444; border-radius: 4px; font-weight: bold; cursor: pointer; }
|
|
button[name="logout"] { background: #d32f2f; }
|
|
.msg { color: #4caf50; }
|
|
.error { color: #d32f2f; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div style="display: flex; flex-direction: row; justify-content: center; align-items: flex-start; gap: 8px;">
|
|
<?php if ($loggedIn): ?>
|
|
<!-- Album List Container -->
|
|
<div class="album-list-container" style="width: 220px; min-width: 180px; background: #222; padding: 18px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.32); margin: 0;">
|
|
<h3 style="text-align:center;">Albums</h3>
|
|
<div id="albumList">
|
|
<?php foreach ($albums as $album): ?>
|
|
<?php
|
|
$thumb = '';
|
|
$albumDir = __DIR__ . '/images/' . $album . '/';
|
|
$thumbDir = $albumDir . 'thumbnails/';
|
|
$imgFile = '';
|
|
$extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'];
|
|
foreach (scandir($albumDir) as $file) {
|
|
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
|
|
if (in_array($ext, $extensions)) {
|
|
if (is_dir($thumbDir) && file_exists($thumbDir . $file)) {
|
|
$thumb = 'images/' . $album . '/thumbnails/' . $file;
|
|
} else {
|
|
$thumb = 'images/' . $album . '/' . $file;
|
|
}
|
|
$imgFile = $file;
|
|
break;
|
|
}
|
|
}
|
|
?>
|
|
<div class="album-item" data-album="<?= htmlspecialchars($album) ?>" style="cursor:pointer; margin-bottom:18px; border-radius:6px; border:1px solid #444; padding:8px; display:flex; align-items:center; background:#222; transition:box-shadow 0.2s;">
|
|
<img src="<?= htmlspecialchars($thumb) ?>" alt="thumb" style="width:48px;height:48px;object-fit:cover;border-radius:4px;margin-right:12px;border:1px solid #333;">
|
|
<span style="font-weight:bold; color:#e0e0e0;"><?= htmlspecialchars($album) ?></span>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
<!-- Admin Form Container -->
|
|
<div class="container" style="margin:0;">
|
|
<h2>Administrator Mode</h2>
|
|
<?php if (!$loggedIn): ?>
|
|
<form method="post">
|
|
<label for="admin_password">Admin Password:</label>
|
|
<input type="password" name="admin_password" id="admin_password" required>
|
|
<button type="submit" name="admin_login">Login</button>
|
|
<?php if (isset($error)) echo "<div class='error'>$error</div>"; ?>
|
|
</form>
|
|
<?php else: ?>
|
|
<form method="post" id="albumForm">
|
|
<input type="hidden" name="album_name" id="album_name" required>
|
|
<label for="album_password">Password:</label>
|
|
<input type="text" name="album_password" id="album_password" required>
|
|
<label for="album_title">Title:</label>
|
|
<input type="text" name="album_title" id="album_title">
|
|
<label for="album_link">Album Link:</label>
|
|
<div style="position:relative;width:100%;margin-bottom:16px;">
|
|
<input type="text" id="album_link" readonly style="background:#181818;color:#e0e0e0;width:98%;padding-right:40px;box-sizing:border-box; border: 1px solid #444;">
|
|
<button type="button" id="copyAlbumLink" style="position:absolute;right:14px;top:21%;padding:0 6px;background:#222;color:#888;border:1px solid #444;border-radius:4px;cursor:pointer;display:flex;align-items:center;justify-content:center;height:28px;min-height:0;">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#888" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
|
|
</button>
|
|
</div>
|
|
<button type="submit" name="set_album_password">Change</button>
|
|
</form>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
var albumNameInput = document.getElementById('album_name');
|
|
var pwInput = document.getElementById('album_password');
|
|
var titleInput = document.getElementById('album_title');
|
|
var albumLinkInput = document.getElementById('album_link');
|
|
var copyBtn = document.getElementById('copyAlbumLink');
|
|
var albumItems = document.querySelectorAll('.album-item');
|
|
function loadAlbumInfo(album) {
|
|
fetch('admin.php?get_album_info=1&album=' + encodeURIComponent(album))
|
|
.then(resp => resp.json())
|
|
.then(data => {
|
|
pwInput.value = data.password || '';
|
|
titleInput.value = data.title || '';
|
|
albumNameInput.value = album;
|
|
// Set album link (change URL as needed)
|
|
var link = window.location.origin + '/?album=' + encodeURIComponent(album);
|
|
albumLinkInput.value = link;
|
|
// Highlight selected album
|
|
albumItems.forEach(function(item) {
|
|
item.style.boxShadow = '';
|
|
item.style.background = '#222';
|
|
});
|
|
var selected = document.querySelector('.album-item[data-album="' + album.replace(/"/g, '\\"') + '"]');
|
|
if (selected) {
|
|
selected.style.boxShadow = '0 0 0 2px #4fa3ff';
|
|
selected.style.background = '#181818';
|
|
}
|
|
});
|
|
}
|
|
albumItems.forEach(function(item) {
|
|
item.addEventListener('click', function() {
|
|
var album = this.getAttribute('data-album');
|
|
loadAlbumInfo(album);
|
|
});
|
|
});
|
|
if (copyBtn) {
|
|
copyBtn.addEventListener('click', function() {
|
|
albumLinkInput.select();
|
|
albumLinkInput.setSelectionRange(0, 99999); // For mobile
|
|
try {
|
|
document.execCommand('copy');
|
|
var orig = copyBtn.innerHTML;
|
|
copyBtn.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#4caf50" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>';
|
|
setTimeout(function(){ copyBtn.innerHTML = orig; }, 1200);
|
|
} catch (err) {
|
|
var orig = copyBtn.innerHTML;
|
|
copyBtn.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#d32f2f" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>';
|
|
setTimeout(function(){ copyBtn.innerHTML = orig; }, 1200);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
</script>
|
|
<?php if (isset($success)) echo "<div class='msg'>$success</div>"; ?>
|
|
<form method="post" style="position:absolute;top:24px;right:32px;">
|
|
<button type="submit" name="logout" style="background:#d32f2f;">Logout</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
<footer style="text-align:center;padding:24px 0 12px 0;color:#888;font-size:16px;position:fixed;left:0;bottom:0;width:100%;background:#181818;">
|
|
Made with © <a href="https://github.com/Brandon4466/galpal" target="_blank" style="color:#4fa3ff;text-decoration:none;">GalPal</a>
|
|
</footer>
|
|
</html>
|