This commit is contained in:
2026-05-24 04:17:53 +03:00
parent fccf7b1ea3
commit cb5f0c498e
5 changed files with 905 additions and 0 deletions
+137
View File
@@ -0,0 +1,137 @@
<?php
session_start();
$db_file = __DIR__ . '/datas.db';
if (!file_exists($db_file)) die("Сначала запустите <a href='install.php'>install.php</a>");
$db = new PDO('sqlite:' . $db_file);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Авторизация
if (isset($_POST['login'])) {
$stmt = $db->prepare("SELECT password FROM admin WHERE username = ?");
$stmt->execute([$_POST['username']]);
$row = $stmt->fetch();
if ($row && password_verify($_POST['password'], $row['password'])) {
$_SESSION['admin'] = true;
header("Location: index.php");
exit;
} else {
sleep(2); // Задержка при неверном пароле (мера безопасности)
$error = "Неверный логин или пароль";
}
}
// Выход
if (isset($_GET['logout'])) {
session_destroy();
header("Location: index.php");
exit;
}
// Проверка сессии
if (!isset($_SESSION['admin'])) {
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8"><title>Вход | S3 WebDAV</title>
<style>
:root { --md-sys-color-background: #1c1b1f; --md-sys-color-surface: #2b2930; --md-sys-color-primary: #d0bcff; --md-sys-color-on-primary: #381e72; --md-sys-color-on-surface: #e6e1e5; }
body { background: var(--md-sys-color-background); color: var(--md-sys-color-on-surface); font-family: system-ui, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
.card { background: var(--md-sys-color-surface); padding: 32px; border-radius: 24px; box-shadow: 0 4px 8px rgba(0,0,0,0.3); text-align: center; }
input { display: block; width: 100%; margin: 16px 0; padding: 16px; background: transparent; border: 1px solid #938f99; color: white; border-radius: 4px; box-sizing: border-box; }
button { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); border: none; padding: 12px 24px; border-radius: 100px; font-weight: 600; cursor: pointer; width: 100%; }
</style>
</head>
<body>
<div class="card">
<h2>Вход в панель</h2>
<?php if(isset($error)) echo "<p style='color:#ffb4ab;'>$error</p>"; ?>
<form method="POST">
<input type="text" name="username" placeholder="Логин" required>
<input type="password" name="password" placeholder="Пароль" required>
<button type="submit" name="login">Войти</button>
</form>
</div>
</body>
</html>
<?php
exit;
}
// Добавление нового S3
if (isset($_POST['add_s3'])) {
$stmt = $db->prepare("INSERT INTO s3_mounts (dav_user, dav_pass, s3_key, s3_secret, s3_region, s3_endpoint, s3_bucket) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([
$_POST['dav_user'], password_hash($_POST['dav_pass'], PASSWORD_DEFAULT),
$_POST['s3_key'], $_POST['s3_secret'], $_POST['s3_region'], $_POST['s3_endpoint'], $_POST['s3_bucket']
]);
header("Location: index.php");
exit;
}
// Удаление S3
if (isset($_GET['delete'])) {
$stmt = $db->prepare("DELETE FROM s3_mounts WHERE id = ?");
$stmt->execute([$_GET['delete']]);
header("Location: index.php");
exit;
}
$mounts = $db->query("SELECT * FROM s3_mounts")->fetchAll();
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8"><title>Управление S3 WebDAV</title>
<style>
:root { --bg: #1c1b1f; --surface: #2b2930; --primary: #d0bcff; --on-primary: #381e72; --text: #e6e1e5; --error: #ffb4ab; }
body { background: var(--bg); color: var(--text); font-family: system-ui, sans-serif; margin: 0; padding: 20px; }
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.card { background: var(--surface); padding: 24px; border-radius: 24px; margin-bottom: 24px; }
table { width: 100%; border-collapse: collapse; margin-top: 16px; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid #49454f; }
a.btn, button { background: var(--primary); color: var(--on-primary); text-decoration: none; padding: 10px 20px; border-radius: 100px; border: none; cursor: pointer; font-weight: bold; }
a.btn-error { background: var(--error); color: #690005; }
input { padding: 12px; margin: 8px 0; background: transparent; border: 1px solid #938f99; color: white; border-radius: 4px; width: calc(50% - 24px); }
</style>
</head>
<body>
<div class="header">
<h1>S3 → WebDAV Gateway</h1>
<a href="?logout=1" class="btn">Выход</a>
</div>
<div class="card">
<h2>Добавить S3 Подключение (WebDAV User)</h2>
<form method="POST">
<input type="text" name="dav_user" placeholder="WebDAV Логин" required>
<input type="password" name="dav_pass" placeholder="WebDAV Пароль" required><br>
<input type="text" name="s3_key" placeholder="S3 Access Key" required>
<input type="text" name="s3_secret" placeholder="S3 Secret Key" required><br>
<input type="text" name="s3_region" placeholder="S3 Region (например, us-east-1)" required>
<input type="url" name="s3_endpoint" placeholder="S3 Endpoint URL (с https://)" required><br>
<input type="text" name="s3_bucket" placeholder="S3 Bucket Name" required><br>
<button type="submit" name="add_s3" style="margin-top: 16px;">Добавить</button>
</form>
</div>
<div class="card">
<h2>Подключенные S3</h2>
<table>
<tr><th>WebDAV Логин</th><th>Bucket</th><th>Endpoint</th><th>Действия</th></tr>
<?php foreach($mounts as $m): ?>
<tr>
<td><?= htmlspecialchars($m['dav_user']) ?></td>
<td><?= htmlspecialchars($m['s3_bucket']) ?></td>
<td><?= htmlspecialchars($m['s3_endpoint']) ?></td>
<td>
<a href="?delete=<?= $m['id'] ?>" class="btn btn-error" onclick="return confirm('Удалить?')">Удалить</a>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
</body>
</html>