168 lines
5.3 KiB
PHP
168 lines
5.3 KiB
PHP
<?php
|
|
session_start();
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
header('X-Content-Type-Options: nosniff');
|
|
header('X-Frame-Options: DENY');
|
|
header('X-XSS-Protection: 1; mode=block');
|
|
|
|
$config = require 'config.php';
|
|
|
|
if (!isset($_SESSION['authenticated'])) {
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$key = $_POST['access_key'] ?? '';
|
|
if (hash('sha256', $key) === hash('sha256', $config['access_key'])) {
|
|
$_SESSION['authenticated'] = true;
|
|
header('Location: index.php');
|
|
exit;
|
|
} else {
|
|
$error = 'Неверный ключ';
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>mkach</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
body {
|
|
background: #000;
|
|
color: #0f0;
|
|
font-family: 'Courier New', monospace;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
min-height: 100vh;
|
|
font-size: 16px;
|
|
}
|
|
.container {
|
|
text-align: center;
|
|
background: rgba(0,20,0,0.8);
|
|
padding: 40px;
|
|
border: 1px solid #0f0;
|
|
border-radius: 5px;
|
|
box-shadow: 0 0 20px rgba(0,255,0,0.3);
|
|
}
|
|
h1 { margin-bottom: 30px; font-size: 2.5em; }
|
|
.form-group { margin-bottom: 20px; }
|
|
input[type="password"] {
|
|
background: #000;
|
|
border: 1px solid #0f0;
|
|
color: #0f0;
|
|
padding: 15px;
|
|
font-size: 18px;
|
|
width: 300px;
|
|
text-align: center;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
input[type="password"]:focus {
|
|
outline: none;
|
|
box-shadow: 0 0 10px rgba(0,255,0,0.5);
|
|
}
|
|
button {
|
|
background: #000;
|
|
border: 1px solid #0f0;
|
|
color: #0f0;
|
|
padding: 15px 30px;
|
|
font-size: 16px;
|
|
cursor: pointer;
|
|
font-family: 'Courier New', monospace;
|
|
transition: all 0.3s;
|
|
}
|
|
button:hover {
|
|
background: #0f0;
|
|
color: #000;
|
|
}
|
|
.error {
|
|
color: #f00;
|
|
margin-top: 15px;
|
|
font-size: 14px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>mkach</h1>
|
|
<form method="post">
|
|
<div class="form-group">
|
|
<input type="password" name="access_key" placeholder="Введите ключ доступа" required>
|
|
</div>
|
|
<button type="submit">Войти</button>
|
|
</form>
|
|
<?php if (isset($error)): ?>
|
|
<div class="error"><?= htmlspecialchars($error) ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
<?php
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$db = new PDO(
|
|
"mysql:host={$config['db']['host']};dbname={$config['db']['name']}",
|
|
$config['db']['user'],
|
|
$config['db']['pass']
|
|
);
|
|
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
} catch (PDOException $e) {
|
|
die('Connection failed');
|
|
}
|
|
|
|
try {
|
|
$db->exec('SET NAMES utf8');
|
|
$stmt = $db->query('SELECT * FROM boards ORDER BY board_id');
|
|
$boards = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
die('Database error');
|
|
}
|
|
|
|
if (isset($_GET['logout'])) {
|
|
session_destroy();
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>mkach - Доски</title>
|
|
<link rel="stylesheet" href="styles.css">
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<h1><?= $config['logo_enabled'] ? htmlspecialchars($config['logo_text']) : 'mkach' ?></h1>
|
|
<div class="header-buttons">
|
|
<a href="?logout=1" class="logout-btn">Выход</a>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($config['motd']): ?>
|
|
<div class="motd-container">
|
|
<div class="motd"><?= htmlspecialchars($config['motd']) ?></div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="boards-container">
|
|
<h2>Доски</h2>
|
|
<div class="boards-list">
|
|
<?php foreach ($boards as $board): ?>
|
|
<div class="board-item">
|
|
<a href="board.php?board=<?= urlencode($board['board_id']) ?>" class="board-link">
|
|
<span class="board-id">/<?= htmlspecialchars($board['board_id']) ?>/</span>
|
|
<span class="board-name"><?= htmlspecialchars($board['name']) ?></span>
|
|
<span class="board-desc"><?= htmlspecialchars($board['description']) ?></span>
|
|
</a>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|