Compare commits

..

No commits in common. "c67f0eabfe6f8d2a41be7a85060e224374043cf8" and "7dc603fd42090373f61f9eba5c6c5bf2d0881243" have entirely different histories.

13 changed files with 2938 additions and 3563 deletions

View file

@ -1,425 +1,416 @@
<?php <?php
session_start(); // 加载配置
require_once '../auth_check.php'; $config = include '../config.php';
checkAdminAuth();
$csrf_token = generateCSRFToken(); // 数据库连接函数

function getDatabaseConnection() {
// 加载配置 global $config;
$config = include '../config.php'; try {

if ($config['database_type'] === 'mysql') {
// 数据库连接函数 $dsn = "mysql:host={$config['database_config']['host']};port={$config['database_config']['port']};dbname={$config['database_config']['name']};charset=utf8mb4";
function getDatabaseConnection() { return new PDO($dsn, $config['database_config']['user'], $config['database_config']['password']);
global $config; } else if ($config['database_type'] === 'sqlite') {
try { $dsn = "sqlite:{$config['database_config']['path']}";
if ($config['database_type'] === 'mysql') { return new PDO($dsn);
$dsn = "mysql:host={$config['database_config']['host']};port={$config['database_config']['port']};dbname={$config['database_config']['name']};charset=utf8mb4"; }
return new PDO($dsn, $config['database_config']['user'], $config['database_config']['password']); } catch (PDOException $e) {
} else if ($config['database_type'] === 'sqlite') { die('数据库连接失败: ' . $e->getMessage());
$dsn = "sqlite:{$config['database_config']['path']}"; }
return new PDO($dsn); }
}
} catch (PDOException $e) { // 连接数据库
die('数据库连接失败: ' . $e->getMessage()); $pdo = getDatabaseConnection();
}
} // 从数据库获取网站信息

$stmt = $pdo->query("SELECT name, description FROM site_info LIMIT 1");
// 连接数据库 $siteInfo = $stmt->fetch(PDO::FETCH_ASSOC);
$pdo = getDatabaseConnection();

// 如果找不到网站信息,使用配置文件中的默认值
// 从数据库获取网站信息 if (!$siteInfo) {
$stmt = $pdo->query("SELECT name, description FROM site_info LIMIT 1"); $siteInfo = [
$siteInfo = $stmt->fetch(PDO::FETCH_ASSOC); 'name' => $config['site_name'] ?? '二次元网站备案系统',

'description' => $config['site_description'] ?? '管理和审核网站备案申请'
// 如果找不到网站信息,使用配置文件中的默认值 ];
if (!$siteInfo) { }
$siteInfo = [
'name' => $config['site_name'] ?? '二次元网站备案系统', // 处理表单提交
'description' => $config['site_description'] ?? '管理和审核网站备案申请' $success = '';
]; $errors = [];
} if ($_SERVER['REQUEST_METHOD'] === 'POST') {

// 验证表单数据
// 处理表单提交 $data = [];
$success = '';
$errors = []; // 验证网站名称
if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (empty($_POST['website_name'])) {
// 验证CSRF令牌 $errors[] = '网站名称不能为空';
verifyCSRFToken($_POST['csrf_token'] ?? ''); } else {
$data['website_name'] = trim($_POST['website_name']);
// 验证表单数据 }
$data = [];

// 验证网站类型
// 验证网站名称 if (empty($_POST['website_category'])) {
if (empty($_POST['website_name'])) { $errors[] = '请选择网站类型';
$errors[] = '网站名称不能为空'; } else {
} else { $data['website_category'] = $_POST['website_category'];
$data['website_name'] = trim($_POST['website_name']); }
}

// 验证网站负责人
// 验证网站类型 if (empty($_POST['contact_person'])) {
if (empty($_POST['website_category'])) { $errors[] = '网站负责人不能为空';
$errors[] = '请选择网站类型'; } else {
} else { $data['contact_person'] = trim($_POST['contact_person']);
$data['website_category'] = $_POST['website_category']; }
}

// 验证联系电话
// 验证网站负责人 if (empty($_POST['contact_phone'])) {
if (empty($_POST['contact_person'])) { $errors[] = '联系电话不能为空';
$errors[] = '网站负责人不能为空'; } else {
} else { $data['contact_phone'] = trim($_POST['contact_phone']);
$data['contact_person'] = trim($_POST['contact_person']); }
}

// 验证联系邮箱
// 验证联系电话 if (empty($_POST['contact_email'])) {
if (empty($_POST['contact_phone'])) { $errors[] = '联系邮箱不能为空';
$errors[] = '联系电话不能为空'; } elseif (!filter_var($_POST['contact_email'], FILTER_VALIDATE_EMAIL)) {
} else { $errors[] = '请输入有效的邮箱地址';
$data['contact_phone'] = trim($_POST['contact_phone']); } else {
} $data['contact_email'] = trim($_POST['contact_email']);

}
// 验证联系邮箱
if (empty($_POST['contact_email'])) { // 验证网站地址
$errors[] = '联系邮箱不能为空'; if (empty($_POST['website_url'])) {
} elseif (!filter_var($_POST['contact_email'], FILTER_VALIDATE_EMAIL)) { $errors[] = '网站地址不能为空';
$errors[] = '请输入有效的邮箱地址'; } else {
} else { // 移除可能的http://或https://前缀
$data['contact_email'] = trim($_POST['contact_email']); $website = trim($_POST['website_url']);
} $website = preg_replace('#^https?://#', '', $website);

$data['website_url'] = $website;
// 验证网站地址 }
if (empty($_POST['website_url'])) {
$errors[] = '网站地址不能为空'; // 验证网站描述
} else { if (empty($_POST['website_description'])) {
// 移除可能的http://或https://前缀 $errors[] = '网站描述不能为空';
$website = trim($_POST['website_url']); } else {
$website = preg_replace('#^https?://#', '', $website); $data['website_description'] = trim($_POST['website_description']);
$data['website_url'] = $website; }
}

// 验证状态
// 验证网站描述 if (empty($_POST['status'])) {
if (empty($_POST['website_description'])) { $errors[] = '请选择状态';
$errors[] = '网站描述不能为空'; } else {
} else { $data['status'] = $_POST['status'];
$data['website_description'] = trim($_POST['website_description']); }
}

// 如果没有错误,保存数据
// 验证状态 if (empty($errors)) {
if (empty($_POST['status'])) { // 生成唯一备案编号 (ICP-年月日-6位ID)
$errors[] = '请选择状态'; // 生成8位数字备案编号
} else { $data['registration_number'] = str_pad(rand(10000000, 99999999), 8, '0', STR_PAD_LEFT);
$data['status'] = $_POST['status']; $data['created_at'] = date('Y-m-d H:i:s');
}

if ($data['status'] === 'approved' || $data['status'] === 'rejected') {
// 如果没有错误,保存数据 $data['processed_at'] = $data['created_at'];
if (empty($errors)) { }
// 生成8位数字备案编号
$data['registration_number'] = str_pad(rand(10000000, 99999999), 8, '0', STR_PAD_LEFT); // 初始化reason字段
$data['created_at'] = date('Y-m-d H:i:s'); $data['reason'] = $_POST['reason'] ?? '';

if ($data['status'] === 'approved' || $data['status'] === 'rejected') { try {
$data['processed_at'] = $data['created_at']; // 插入数据到数据库
} $stmt = $pdo->prepare("INSERT INTO registrations (website_name, website_category, contact_person, contact_phone, contact_email, website_url, website_description, status, created_at, processed_at, registration_number, reason) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([
// 初始化reason字段 $data['website_name'],
$data['reason'] = $_POST['reason'] ?? ''; $data['website_category'],

$data['contact_person'],
try { $data['contact_phone'],
// 插入数据到数据库 $data['contact_email'],
$stmt = $pdo->prepare("INSERT INTO registrations (website_name, website_category, contact_person, contact_phone, contact_email, website_url, website_description, status, created_at, processed_at, registration_number, reason) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $data['website_url'],
$stmt->execute([ $data['website_description'],
$data['website_name'], $data['status'],
$data['website_category'], $data['created_at'],
$data['contact_person'], $data['processed_at'] ?? null,
$data['contact_phone'], $data['registration_number'],
$data['contact_email'], $data['reason']
$data['website_url'], ]);
$data['website_description'],
$data['status'], $success = '备案信息添加成功!备案编号: 初ICP备' . $data['registration_number'] . '备';
$data['created_at'], } catch (PDOException $e) {
$data['processed_at'] ?? null, $errors[] = '添加备案信息失败: ' . $e->getMessage();
$data['registration_number'], }
$data['reason'] }
]); }

?>
$success = '备案信息添加成功!备案编号: 初ICP备' . $data['registration_number'] . '备'; <html lang="zh-CN">
} catch (PDOException $e) { <head>
$errors[] = '添加备案信息失败: ' . $e->getMessage(); <meta charset="UTF-8">
} <meta name="viewport" content="width=device-width, initial-scale=1.0">
} <title>添加备案信息 - <?php echo $siteInfo['name']; ?></title>
} <style>
?> * {
<html lang="zh-CN"> margin: 0;
<head> padding: 0;
<meta charset="UTF-8"> box-sizing: border-box;
<meta name="viewport" content="width=device-width, initial-scale=1.0"> }
<title>添加备案信息 - <?php echo $siteInfo['name']; ?></title> body {
<style> background-color: #f0f2f5;
* { color: #333;
margin: 0; line-height: 1.6;
padding: 0; }
box-sizing: border-box; .container {
} max-width: 800px;
body { margin: 0 auto;
background-color: #f0f2f5; padding: 20px;
color: #333; }
line-height: 1.6; .header-frosted {
} position: fixed;
.container { top: 0;
max-width: 800px; left: 0;
margin: 0 auto; right: 0;
padding: 20px; background: rgba(255, 255, 255, 0.7);
} backdrop-filter: blur(10px);
.header-frosted { -webkit-backdrop-filter: blur(10px);
position: fixed; color: #333;
top: 0; padding: 15px 20px;
left: 0; display: flex;
right: 0; justify-content: space-between;
background: rgba(255, 255, 255, 0.7); align-items: center;
backdrop-filter: blur(10px); box-shadow: 0 2px 10px rgba(0,0,0,0.1);
-webkit-backdrop-filter: blur(10px); z-index: 1000;
color: #333; }
padding: 15px 20px; .header-nav {
display: flex; display: flex;
justify-content: space-between; gap: 20px;
align-items: center; }
box-shadow: 0 2px 10px rgba(0,0,0,0.1); .header-nav span {
z-index: 1000; cursor: pointer;
} color: #7873f5;
.header-nav { font-weight: bold;
display: flex; transition: color 0.3s ease;
gap: 20px; }
} .header-nav span:hover {
.header-nav span { color: #605acf;
cursor: pointer; }
color: #7873f5; header {
font-weight: bold; background: linear-gradient(135deg, #ff6ec7, #7873f5);
transition: color 0.3s ease; color: white;
} padding: 80px 0 40px;
.header-nav span:hover { text-align: center;
color: #605acf; border-radius: 10px;
} margin-bottom: 30px;
header { box-shadow: 0 4px 12px rgba(0,0,0,0.1);
background: linear-gradient(135deg, #ff6ec7, #7873f5); margin-top: 60px;
color: white; }
padding: 80px 0 40px; h1 {
text-align: center; font-size: 2rem;
border-radius: 10px; margin-bottom: 10px;
margin-bottom: 30px; }
box-shadow: 0 4px 12px rgba(0,0,0,0.1); .card {
margin-top: 60px; background: white;
} border-radius: 10px;
h1 { padding: 30px;
font-size: 2rem; margin-bottom: 30px;
margin-bottom: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.05);
} }
.card { h2 {
background: white; color: #7873f5;
border-radius: 10px; margin-bottom: 20px;
padding: 30px; padding-bottom: 10px;
margin-bottom: 30px; border-bottom: 2px solid #f0f0f0;
box-shadow: 0 2px 10px rgba(0,0,0,0.05); }
} .form-group {
h2 { margin-bottom: 20px;
color: #7873f5; }
margin-bottom: 20px; label {
padding-bottom: 10px; display: block;
border-bottom: 2px solid #f0f0f0; margin-bottom: 8px;
} font-weight: bold;
.form-group { color: #555;
margin-bottom: 20px; }
} input[type="text"],
label { input[type="email"],
display: block; textarea,
margin-bottom: 8px; select {
font-weight: bold; width: 100%;
color: #555; padding: 12px;
} border: 1px solid #ddd;
input[type="text"], border-radius: 6px;
input[type="email"], font-size: 1rem;
textarea, transition: border 0.3s ease;
select { }
width: 100%; input[type="text"]:focus,
padding: 12px; input[type="email"]:focus,
border: 1px solid #ddd; textarea:focus,
border-radius: 6px; select:focus {
font-size: 1rem; border-color: #7873f5;
transition: border 0.3s ease; outline: none;
} box-shadow: 0 0 0 3px rgba(120, 115, 245, 0.2);
input[type="text"]:focus, }
input[type="email"]:focus, textarea {
textarea:focus, height: 150px;
select:focus { resize: vertical;
border-color: #7873f5; }
outline: none; .btn {
box-shadow: 0 0 0 3px rgba(120, 115, 245, 0.2); display: inline-block;
} background: #7873f5;
textarea { color: white;
height: 150px; padding: 12px 25px;
resize: vertical; border-radius: 30px;
} text-decoration: none;
.btn { font-weight: bold;
display: inline-block; transition: background 0.3s ease;
background: #7873f5; border: none;
color: white; cursor: pointer;
padding: 12px 25px; font-size: 1rem;
border-radius: 30px; }
text-decoration: none; .btn:hover {
font-weight: bold; background: #605acf;
transition: background 0.3s ease; }
border: none; .btn-container {
cursor: pointer; text-align: center;
font-size: 1rem; margin-top: 30px;
} }
.btn:hover { .back-link {
background: #605acf; display: inline-block;
} margin-top: 15px;
.btn-container { color: #7873f5;
text-align: center; text-decoration: none;
margin-top: 30px; }
} .back-link:hover {
.back-link { text-decoration: underline;
display: inline-block; }
margin-top: 15px; .error {
color: #7873f5; color: #e74c3c;
text-decoration: none; font-size: 0.9rem;
} margin-top: 5px;
.back-link:hover { }
text-decoration: underline; .success {
} color: #2ecc71;
.error { padding: 15px;
color: #e74c3c; background: #f1f9f1;
font-size: 0.9rem; border-radius: 6px;
margin-top: 5px; margin-bottom: 20px;
} border-left: 4px solid #2ecc71;
.success { }
color: #2ecc71; .logout-btn {
padding: 15px; background: #e74c3c;
background: #f1f9f1; color: white;
border-radius: 6px; border: none;
margin-bottom: 20px; padding: 8px 15px;
border-left: 4px solid #2ecc71; border-radius: 30px;
} cursor: pointer;
.logout-btn { font-weight: bold;
background: #e74c3c; transition: background 0.3s ease;
color: white; }
border: none; .logout-btn:hover {
padding: 8px 15px; background: #c0392b;
border-radius: 30px; }
cursor: pointer; </style>
font-weight: bold; </head>
transition: background 0.3s ease; <body>
} <div class="header-frosted">
.logout-btn:hover { <h3><?php echo $siteInfo['name']; ?> - 管理员面板</h3>
background: #c0392b; <div class="header-nav">
} <span onclick="window.location.href='admin_dashboard.php'">控制面板</span>
</style> <span onclick="window.location.href='admin_dashboard.php?view=all'">所有备案</span>
</head> <span onclick="window.location.href='admin_dashboard.php?view=pending'">待审核备案</span>
<body> <span onclick="window.location.href='add_registration.php'">添加备案</span>
<div class="header-frosted"> <span onclick="window.location.href='settings.php'">系统设置</span>
<h3><?php echo $siteInfo['name']; ?> - 管理员面板</h3> <button class="logout-btn" onclick="window.location.href='admin_login.php?action=logout'">退出登录</button>
<div class="header-nav"> </div>
<span onclick="window.location.href='admin_dashboard.php'">控制面板</span> </div>
<span onclick="window.location.href='admin_dashboard.php?view=all'">所有备案</span> <div class="container">
<span onclick="window.location.href='admin_dashboard.php?view=pending'">待审核备案</span> <header>
<span onclick="window.location.href='add_registration.php'">添加备案</span> <h1><?php echo $siteInfo['name']; ?> - 添加备案信息</h1>
<span onclick="window.location.href='settings.php'">系统设置</span> <p>直接添加新的备案信息</p>
<button class="logout-btn" onclick="window.location.href='admin_login.php?action=logout'">退出登录</button> </header>
</div>
</div> <div class="card">
<div class="container"> <h2>添加备案信息</h2>
<header>
<h1><?php echo $siteInfo['name']; ?> - 添加备案信息</h1> <?php if ($success): ?>
<p>直接添加新的备案信息</p> <div class="success"><?php echo $success; ?></div>
</header> <?php endif; ?>


<div class="card"> <?php if (!empty($errors)): ?>
<h2>添加备案信息</h2> <?php foreach ($errors as $error): ?>

<div class="error"><?php echo $error; ?></div>
<?php if ($success): ?> <?php endforeach; ?>
<div class="success"><?php echo $success; ?></div> <?php endif; ?>
<?php endif; ?>

<form method="post" enctype="multipart/form-data">
<?php if (!empty($errors)): ?> <div class="form-group">
<?php foreach ($errors as $error): ?> <label for="website_name">网站名称 *</label>
<div class="error"><?php echo $error; ?></div> <input type="text" id="website_name" name="website_name" required placeholder="请输入网站的名称">
<?php endforeach; ?> </div>
<?php endif; ?>

<div class="form-group">
<form method="post" enctype="multipart/form-data"> <label for="website_category">网站类型 *</label>
<input type="hidden" name="csrf_token" value="<?php echo $csrf_token; ?>"> <select id="website_category" name="website_category" required>
<option value="">请选择</option>
<div class="form-group"> <option value="anime">动漫网站</option>
<label for="website_name">网站名称 *</label> <option value="game">游戏网站</option>
<input type="text" id="website_name" name="website_name" required placeholder="请输入网站的名称"> <option value="blog">个人博客</option>
</div> <option value="other">其他类型</option>

</select>
<div class="form-group"> </div>
<label for="website_category">网站类型 *</label>
<select id="website_category" name="website_category" required> <div class="form-group">
<option value="">请选择</option> <label for="contact_person">网站负责人 *</label>
<option value="anime">动漫网站</option> <input type="text" id="contact_person" name="contact_person" required placeholder="请输入网站负责人姓名">
<option value="game">游戏网站</option> </div>
<option value="blog">个人博客</option>
<option value="other">其他类型</option> <div class="form-group">
</select> <label for="contact_phone">联系电话 *</label>
</div> <input type="text" id="contact_phone" name="contact_phone" required placeholder="请输入联系电话">

</div>
<div class="form-group">
<label for="contact_person">网站负责人 *</label> <div class="form-group">
<input type="text" id="contact_person" name="contact_person" required placeholder="请输入网站负责人姓名"> <label for="contact_email">联系邮箱 *</label>
</div> <input type="email" id="contact_email" name="contact_email" required placeholder="请输入联系邮箱">

</div>
<div class="form-group">
<label for="contact_phone">联系电话 *</label> <div class="form-group">
<input type="text" id="contact_phone" name="contact_phone" required placeholder="请输入联系电话"> <label for="website_url">网站地址 *</label>
</div> <input type="text" id="website_url" name="website_url" required placeholder="请输入网站域名不带http://">

</div>
<div class="form-group">
<label for="contact_email">联系邮箱 *</label> <div class="form-group">
<input type="email" id="contact_email" name="contact_email" required placeholder="请输入联系邮箱"> <label for="website_description">网站描述 *</label>
</div> <textarea id="website_description" name="website_description" required placeholder="请简要描述网站内容"></textarea>

</div>
<div class="form-group">
<label for="website_url">网站地址 *</label> <div class="form-group">
<input type="text" id="website_url" name="website_url" required placeholder="请输入网站域名不带http://"> <label for="status">状态 *</label>
</div> <select id="status" name="status" required>

<option value="pending">待审核</option>
<div class="form-group"> <option value="approved">已通过</option>
<label for="website_description">网站描述 *</label> <option value="rejected">已拒绝</option>
<textarea id="website_description" name="website_description" required placeholder="请简要描述网站内容"></textarea> </select>
</div> </div>


<div class="form-group"> <div class="form-group" id="reason_group" style="display: none;">
<label for="status">状态 *</label> <label for="reason">处理说明 *</label>
<select id="status" name="status" required> <textarea id="reason" name="reason" placeholder="请输入审核通过或拒绝的原因"></textarea>
<option value="pending">待审核</option> </div>
<option value="approved">已通过</option>
<option value="rejected">已拒绝</option> <script>
</select> // 当状态改变时,显示或隐藏处理说明字段
</div> document.getElementById('status').addEventListener('change', function() {

var reasonGroup = document.getElementById('reason_group');
<div class="form-group" id="reason_group" style="display: none;"> if (this.value === 'approved' || this.value === 'rejected') {
<label for="reason">处理说明 *</label> reasonGroup.style.display = 'block';
<textarea id="reason" name="reason" placeholder="请输入审核通过或拒绝的原因"></textarea> } else {
</div> reasonGroup.style.display = 'none';

}
<script> });
// 当状态改变时,显示或隐藏处理说明字段 </script>
document.getElementById('status').addEventListener('change', function() {
var reasonGroup = document.getElementById('reason_group'); <div class="btn-container">
if (this.value === 'approved' || this.value === 'rejected') { <button type="submit" class="btn">添加备案</button>
reasonGroup.style.display = 'block'; <a href="admin_dashboard.php" class="back-link">返回控制面板</a>
} else { </div>
reasonGroup.style.display = 'none'; </form>
} </div>
}); </div>
</script> </body>

<div class="btn-container">
<button type="submit" class="btn">添加备案</button>
<a href="admin_dashboard.php" class="back-link">返回控制面板</a>
</div>
</form>
</div>
</div>
</body>
</html> </html>

File diff suppressed because it is too large Load diff

View file

@ -1,227 +1,161 @@
<?php <?php
session_start(); // 加载配置

$config = include '../config.php';
// 加载配置
$config = include '../config.php'; // 数据库连接函数

function getDatabaseConnection() {
// 数据库连接函数 global $config;
function getDatabaseConnection() { try {
global $config; if ($config['database_type'] === 'mysql') {
try { $dsn = "mysql:host={$config['database_config']['host']};port={$config['database_config']['port']};dbname={$config['database_config']['name']};charset=utf8mb4";
if ($config['database_type'] === 'mysql') { return new PDO($dsn, $config['database_config']['user'], $config['database_config']['password']);
$dsn = "mysql:host={$config['database_config']['host']};port={$config['database_config']['port']};dbname={$config['database_config']['name']};charset=utf8mb4"; } else if ($config['database_type'] === 'sqlite') {
$pdo = new PDO($dsn, $config['database_config']['user'], $config['database_config']['password']); $dsn = "sqlite:{$config['database_config']['path']}";
} else if ($config['database_type'] === 'sqlite') { return new PDO($dsn);
$dsn = "sqlite:{$config['database_config']['path']}"; }
$pdo = new PDO($dsn); } catch (PDOException $e) {
} die('数据库连接失败: ' . $e->getMessage());
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }
return $pdo; }
} catch (PDOException $e) {
die('数据库连接失败'); // 处理注销请求
} if (isset($_GET['action']) && $_GET['action'] === 'logout') {
} setcookie('admin_logged_in', '', time() - 3600, '/');

header('Location: admin_login.php');
// 处理注销请求 exit;
if (isset($_GET['action']) && $_GET['action'] === 'logout') { }
session_unset();
session_destroy(); // 检查是否已登录
header('Location: admin_login.php'); if (isset($_COOKIE['admin_logged_in']) && $_COOKIE['admin_logged_in'] === 'true') {
exit; header('Location: admin_dashboard.php');
} exit;

}
// 检查是否已登录
if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true) { $error = '';
header('Location: admin_dashboard.php'); // 处理登录请求
exit; if ($_SERVER['REQUEST_METHOD'] === 'POST') {
} $username = $_POST['username'] ?? '';

$password = $_POST['password'] ?? '';
// 防止暴力破解:记录失败次数
if (!isset($_SESSION['login_attempts'])) { // 连接数据库
$_SESSION['login_attempts'] = 0; $pdo = getDatabaseConnection();
$_SESSION['last_attempt'] = time();
} // 查询管理员信息

$stmt = $pdo->prepare("SELECT password_hash FROM admins WHERE username = ?");
// 重置计数器5分钟后 $stmt->execute([$username]);
if (time() - $_SESSION['last_attempt'] > 300) { $admin = $stmt->fetch(PDO::FETCH_ASSOC);
$_SESSION['login_attempts'] = 0;
} // 验证密码

if ($admin && password_verify($password, $admin['password_hash'])) {
$error = ''; // 设置登录cookie有效期1小时

setcookie('admin_logged_in', 'true', time() + 3600, '/');
// 处理登录请求 header('Location: admin_dashboard.php');
if ($_SERVER['REQUEST_METHOD'] === 'POST') { exit;
// 检查是否超过最大尝试次数5次 } else {
if ($_SESSION['login_attempts'] >= 5) { $error = '用户名或密码错误';
$error = '登录尝试次数过多请5分钟后重试'; }
} else { }
// 验证CSRF令牌 ?>
if (!isset($_POST['csrf_token']) || $_POST['csrf_token'] !== $_SESSION['csrf_token']) { <!DOCTYPE html>
$error = '安全验证失败,请重新登录'; <html lang="zh-CN">
} else { <head>
$username = $_POST['username'] ?? ''; <meta charset="UTF-8">
$password = $_POST['password'] ?? ''; <meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>管理员登录 - 二次元网站备案系统</title>
// 输入验证 <style>
if (empty($username) || empty($password)) { * {
$error = '用户名和密码不能为空'; margin: 0;
} else { padding: 0;
// 连接数据库 box-sizing: border-box;
$pdo = getDatabaseConnection(); }

body {
// 查询管理员信息 background-color: #f0f2f5;
$stmt = $pdo->prepare("SELECT id, password_hash FROM admins WHERE username = ?"); color: #333;
$stmt->execute([$username]); line-height: 1.6;
$admin = $stmt->fetch(PDO::FETCH_ASSOC); display: flex;

justify-content: center;
// 验证密码 align-items: center;
if ($admin && password_verify($password, $admin['password_hash'])) { height: 100vh;
// 登录成功,重置尝试次数 }
$_SESSION['login_attempts'] = 0; .login-container {
background: white;
// 设置会话变量 border-radius: 10px;
$_SESSION['admin_logged_in'] = true; padding: 40px;
$_SESSION['admin_id'] = $admin['id']; box-shadow: 0 2px 10px rgba(0,0,0,0.1);
$_SESSION['admin_username'] = $username; width: 100%;
$_SESSION['last_activity'] = time(); max-width: 400px;
}
// 重新生成会话ID h1 {
session_regenerate_id(true); color: #7873f5;
margin-bottom: 30px;
header('Location: admin_dashboard.php'); text-align: center;
exit; }
} else { .form-group {
$_SESSION['login_attempts']++; margin-bottom: 20px;
$_SESSION['last_attempt'] = time(); }
$error = '用户名或密码错误'; label {
} display: block;
} margin-bottom: 8px;
} font-weight: bold;
} color: #555;
} }

input[type="text"],
// 生成CSRF令牌 input[type="password"] {
if (!isset($_SESSION['csrf_token'])) { width: 100%;
$_SESSION['csrf_token'] = bin2hex(random_bytes(32)); padding: 12px;
} border: 1px solid #ddd;
?> border-radius: 6px;
<!DOCTYPE html> font-size: 1rem;
<html lang="zh-CN"> transition: border 0.3s ease;
<head> }
<meta charset="UTF-8"> input[type="text"]:focus,
<meta name="viewport" content="width=device-width, initial-scale=1.0"> input[type="password"]:focus {
<title>管理员登录 - 二次元网站备案系统</title> border-color: #7873f5;
<style> outline: none;
* { box-shadow: 0 0 0 3px rgba(120, 115, 245, 0.2);
margin: 0; }
padding: 0; .btn {
box-sizing: border-box; display: inline-block;
} background: #7873f5;
body { color: white;
background-color: #f0f2f5; padding: 12px 25px;
color: #333; border-radius: 30px;
line-height: 1.6; text-decoration: none;
display: flex; font-weight: bold;
justify-content: center; transition: background 0.3s ease;
align-items: center; border: none;
height: 100vh; cursor: pointer;
} font-size: 1rem;
.login-container { width: 100%;
background: white; }
border-radius: 10px; .btn:hover {
padding: 40px; background: #605acf;
box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
width: 100%; .error {
max-width: 400px; color: #e74c3c;
} font-size: 0.9rem;
h1 { margin-top: 15px;
color: #7873f5; text-align: center;
margin-bottom: 30px; }
text-align: center; </style>
} </head>
.form-group { <body>
margin-bottom: 20px; <div class="login-container">
} <h1>管理员登录</h1>
label { <form method="post" class="login-form">
display: block; <div class="form-group">
margin-bottom: 8px; <label for="username">用户名</label>
font-weight: bold; <input type="text" id="username" name="username" required placeholder="请输入管理员用户名">
color: #555; </div>
} <div class="form-group">
input[type="text"], <label for="password">密码</label>
input[type="password"] { <input type="password" id="password" name="password" required placeholder="请输入管理员密码">
width: 100%; </div>
padding: 12px; <button type="submit" class="btn">登录</button>
border: 1px solid #ddd; <?php if (!empty($error)): ?>
border-radius: 6px; <div class="error"><?php echo $error; ?></div>
font-size: 1rem; <?php endif; ?>
transition: border 0.3s ease; </form>
} </div>
input[type="text"]:focus, </body>
input[type="password"]:focus {
border-color: #7873f5;
outline: none;
box-shadow: 0 0 0 3px rgba(120, 115, 245, 0.2);
}
.btn {
display: inline-block;
background: #7873f5;
color: white;
padding: 12px 25px;
border-radius: 30px;
text-decoration: none;
font-weight: bold;
transition: background 0.3s ease;
border: none;
cursor: pointer;
font-size: 1rem;
width: 100%;
}
.btn:hover {
background: #605acf;
}
.error {
color: #e74c3c;
font-size: 0.9rem;
margin-top: 15px;
text-align: center;
}
.info {
color: #666;
font-size: 0.85rem;
margin-top: 20px;
text-align: center;
}
</style>
</head>
<body>
<div class="login-container">
<h1>管理员登录</h1>
<form method="post" class="login-form">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>">
<div class="form-group">
<label for="username">用户名</label>
<input type="text" id="username" name="username" required placeholder="请输入管理员用户名" autocomplete="username">
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" id="password" name="password" required placeholder="请输入管理员密码" autocomplete="current-password">
</div>
<button type="submit" class="btn">登录</button>
<?php if (!empty($error)): ?>
<div class="error"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<?php if ($_SESSION['login_attempts'] >= 3): ?>
<div class="info">
剩余尝试次数: <?php echo 5 - $_SESSION['login_attempts']; ?>
</div>
<?php endif; ?>
</form>
</div>
</body>
</html> </html>

View file

@ -1,62 +1,63 @@
<?php <?php
session_start(); // 管理员审核通过备案申请
require_once '../auth_check.php';
checkAdminAuth(); // 检查是否已登录

if (!isset($_COOKIE['admin_logged_in']) || $_COOKIE['admin_logged_in'] !== 'true') {
// 检查是否提供了申请ID header('Location: admin_login.php');
if (!isset($_POST['registration_id'])) { exit;
die('缺少备案申请ID'); }
}

// 检查是否提供了申请ID
$registrationId = $_POST['registration_id']; if (!isset($_POST['registration_id'])) {
$reason = $_POST['reason'] ?? '审核通过'; die('缺少备案申请ID');

}
// 正确加载配置
$config = include '../config.php'; $registrationId = $_POST['registration_id'];
if (!$config || !is_array($config)) { $reason = $_POST['reason'] ?? '审核通过';
die('配置文件加载失败');
} // 加载配置

$config = include '../config.php';
// 初始化数据库连接
require_once '../db_init.php'; // 初始化数据库连接
require_once '../email_utils.php'; require_once '../db_init.php';

require_once '../email_utils.php';
// 更新备案申请状态为通过
try { // 更新备案申请状态为通过
// 开始事务 try {
$pdo->beginTransaction(); // 开始事务

$pdo->beginTransaction();
// 获取备案信息
$stmt = $pdo->prepare("SELECT * FROM registrations WHERE id = ?"); // 获取备案信息
$stmt->execute([$registrationId]); $stmt = $pdo->prepare("SELECT * FROM registrations WHERE id = ?");
$registration = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->execute([$registrationId]);

$registration = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$registration) {
die('未找到该备案申请'); if (!$registration) {
} die('未找到该备案申请');

}
// 更新状态
$stmt = $pdo->prepare("UPDATE registrations SET status = 'approved', processed_at = NOW(), reason = ? WHERE id = ?"); // 更新状态
$stmt->execute([$reason, $registrationId]); $stmt = $pdo->prepare("UPDATE registrations SET status = 'approved', processed_at = NOW(), reason = ? WHERE id = ?");

$stmt->execute([$reason, $registrationId]);
// 提交事务
$pdo->commit(); // 提交事务

$pdo->commit();
// 发送邮件通知
try { // 发送邮件通知
$emailUtils = new EmailUtils($pdo); try {
$emailUtils->sendApprovalEmail($registration); $emailUtils = new EmailUtils($pdo);
} catch (Exception $e) { $emailUtils->sendApprovalEmail($registration);
// 邮件发送失败,记录日志但不影响主流程 } catch (Exception $e) {
error_log('发送审核通过邮件失败: ' . $e->getMessage()); // 邮件发送失败,记录日志但不影响主流程
} error_log('发送审核通过邮件失败: ' . $e->getMessage());

}
// 重定向回管理员面板
header('Location: admin_dashboard.php?success=1&message=备案申请已成功通过'); // 重定向回管理员面板
exit; header('Location: admin_dashboard.php?success=1&message=备案申请已成功通过');
} catch (PDOException $e) { exit;
// 回滚事务 } catch (PDOException $e) {
$pdo->rollBack(); // 回滚事务
die('更新备案申请状态失败: ' . $e->getMessage()); $pdo->rollBack();
} die('更新备案申请状态失败: ' . $e->getMessage());
}
?> ?>

View file

@ -1,309 +1,287 @@
<?php <?php
session_start(); // 管理管理员账户脚本
require_once '../auth_check.php'; // 使用方法: 访问此文件并按照提示操作
checkAdminAuth();

error_reporting(E_ALL);
error_reporting(E_ALL); ini_set('display_errors', 1);
ini_set('display_errors', 1);

// 加载配置
// 正确加载配置 $config = include '../config.php';
$config = include '../config.php';
if (!$config || !is_array($config)) { // 数据库连接函数
die('配置文件加载失败'); function getDatabaseConnection() {
} global $config;

try {
// 数据库连接函数 if ($config['database_type'] === 'mysql') {
function getDatabaseConnection() { $dsn = "mysql:host={$config['database_config']['host']};port={$config['database_config']['port']};dbname={$config['database_config']['name']};charset=utf8mb4";
global $config; return new PDO($dsn, $config['database_config']['user'], $config['database_config']['password']);
try { } else if ($config['database_type'] === 'sqlite') {
if ($config['database_type'] === 'mysql') { $dsn = "sqlite:{$config['database_config']['path']}";
$dsn = "mysql:host={$config['database_config']['host']};port={$config['database_config']['port']};dbname={$config['database_config']['name']};charset=utf8mb4"; return new PDO($dsn);
return new PDO($dsn, $config['database_config']['user'], $config['database_config']['password']); }
} else if ($config['database_type'] === 'sqlite') { } catch (PDOException $e) {
$dsn = "sqlite:{$config['database_config']['path']}"; die('数据库连接失败: ' . $e->getMessage());
return new PDO($dsn); }
} }
} catch (PDOException $e) {
die('数据库连接失败: ' . $e->getMessage()); // 连接数据库
} $pdo = getDatabaseConnection();
}

// 获取所有管理员账户
// 连接数据库 function getAllAdmins($pdo) {
$pdo = getDatabaseConnection(); $stmt = $pdo->query("SELECT id, username, created_at FROM admins");

return $stmt->fetchAll(PDO::FETCH_ASSOC);
// 获取所有管理员账户 }
function getAllAdmins($pdo) {
$stmt = $pdo->query("SELECT id, username, created_at FROM admins"); // 检查用户名是否已存在
return $stmt->fetchAll(PDO::FETCH_ASSOC); function checkUsernameExists($pdo, $username) {
} $stmt = $pdo->prepare("SELECT COUNT(*) FROM admins WHERE username = ?");

$stmt->execute([$username]);
// 检查用户名是否已存在 return $stmt->fetchColumn() > 0;
function checkUsernameExists($pdo, $username) { }
$stmt = $pdo->prepare("SELECT COUNT(*) FROM admins WHERE username = ?");
$stmt->execute([$username]); // 添加新管理员
return $stmt->fetchColumn() > 0; function addAdmin($pdo, $username, $password) {
} if (checkUsernameExists($pdo, $username)) {

return ['success' => false, 'message' => '用户名已存在'];
// 添加新管理员 }
function addAdmin($pdo, $username, $password) {
if (checkUsernameExists($pdo, $username)) { $password_hash = password_hash($password, PASSWORD_DEFAULT);
return ['success' => false, 'message' => '用户名已存在']; try {
} $stmt = $pdo->prepare("INSERT INTO admins (username, password_hash) VALUES (?, ?)");

$stmt->execute([$username, $password_hash]);
$password_hash = password_hash($password, PASSWORD_DEFAULT); return ['success' => true, 'message' => '管理员添加成功'];
try { } catch (PDOException $e) {
$stmt = $pdo->prepare("INSERT INTO admins (username, password_hash) VALUES (?, ?)"); return ['success' => false, 'message' => '添加失败: ' . $e->getMessage()];
$stmt->execute([$username, $password_hash]); }
return ['success' => true, 'message' => '管理员添加成功']; }
} catch (PDOException $e) {
return ['success' => false, 'message' => '添加失败: ' . $e->getMessage()]; // 删除管理员
} function deleteAdmin($pdo, $id) {
} try {

$stmt = $pdo->prepare("DELETE FROM admins WHERE id = ?");
// 删除管理员 $stmt->execute([$id]);
function deleteAdmin($pdo, $id) { return ['success' => true, 'message' => '管理员删除成功'];
try { } catch (PDOException $e) {
$stmt = $pdo->prepare("DELETE FROM admins WHERE id = ?"); return ['success' => false, 'message' => '删除失败: ' . $e->getMessage()];
$stmt->execute([$id]); }
return ['success' => true, 'message' => '管理员删除成功']; }
} catch (PDOException $e) {
return ['success' => false, 'message' => '删除失败: ' . $e->getMessage()]; // 处理表单提交
} $message = '';
} $success = false;


// 处理表单提交 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$message = ''; if (isset($_POST['action'])) {
$success = false; switch ($_POST['action']) {

case 'add':
if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username = trim($_POST['username']);
// 验证CSRF令牌 $password = trim($_POST['password']);
if (!isset($_POST['csrf_token']) || $_POST['csrf_token'] !== $_SESSION['csrf_token']) { $confirm_password = trim($_POST['confirm_password']);
$message = '安全验证失败';
} else { if (empty($username) || empty($password)) {
if (isset($_POST['action'])) { $message = '用户名和密码不能为空';
switch ($_POST['action']) { } elseif ($password !== $confirm_password) {
case 'add': $message = '两次输入的密码不一致';
$username = trim($_POST['username']); } elseif (strlen($password) < 6) {
$password = trim($_POST['password']); $message = '密码长度不能少于6位';
$confirm_password = trim($_POST['confirm_password']); } else {

$result = addAdmin($pdo, $username, $password);
if (empty($username) || empty($password)) { $success = $result['success'];
$message = '用户名和密码不能为空'; $message = $result['message'];
} elseif ($password !== $confirm_password) { }
$message = '两次输入的密码不一致'; break;
} elseif (strlen($password) < 6) {
$message = '密码长度不能少于6位'; case 'delete':
} else { $id = (int)$_POST['id'];
$result = addAdmin($pdo, $username, $password); $result = deleteAdmin($pdo, $id);
$success = $result['success']; $success = $result['success'];
$message = $result['message']; $message = $result['message'];
} break;
break; }

}
case 'delete': }
$id = (int)$_POST['id'];
// 防止删除自己 // 获取所有管理员
if ($id == $_SESSION['admin_id']) { $admins = getAllAdmins($pdo);
$message = '不能删除当前登录的管理员账户';
} else { ?>
$result = deleteAdmin($pdo, $id); <!DOCTYPE html>
$success = $result['success']; <html lang="zh-CN">
$message = $result['message']; <head>
} <meta charset="UTF-8">
break; <meta name="viewport" content="width=device-width, initial-scale=1.0">
} <title>管理员账户管理</title>
} <style>
} * {
} margin: 0;

padding: 0;
// 生成CSRF令牌 box-sizing: border-box;
$csrf_token = generateCSRFToken(); font-family: 'ZD', sans-serif;

}
// 获取所有管理员 body {
$admins = getAllAdmins($pdo); background-color: #f0f2f5;
?> color: #333;
<!DOCTYPE html> line-height: 1.6;
<html lang="zh-CN"> padding: 20px;
<head> }
<meta charset="UTF-8"> .container {
<meta name="viewport" content="width=device-width, initial-scale=1.0"> max-width: 800px;
<title>管理员账户管理</title> margin: 0 auto;
<style> background-color: #fff;
* { border-radius: 10px;
margin: 0; padding: 30px;
padding: 0; box-shadow: 0 2px 10px rgba(0,0,0,0.1);
box-sizing: border-box; }
font-family: 'ZD', sans-serif; h1 {
} color: #7873f5;
body { margin-bottom: 20px;
background-color: #f0f2f5; text-align: center;
color: #333; }
line-height: 1.6; table {
padding: 20px; width: 100%;
} border-collapse: collapse;
.container { margin-bottom: 30px;
max-width: 800px; }
margin: 0 auto; th, td {
background-color: #fff; padding: 12px 15px;
border-radius: 10px; text-align: left;
padding: 30px; border-bottom: 1px solid #ddd;
box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
} th {
h1 { background-color: #f8f9fa;
color: #7873f5; font-weight: bold;
margin-bottom: 20px; }
text-align: center; tr:hover {
} background-color: #f5f5f5;
table { }
width: 100%; .btn {
border-collapse: collapse; display: inline-block;
margin-bottom: 30px; background: #7873f5;
} color: white;
th, td { padding: 8px 15px;
padding: 12px 15px; border-radius: 4px;
text-align: left; text-decoration: none;
border-bottom: 1px solid #ddd; font-weight: bold;
} transition: background 0.3s ease;
th { border: none;
background-color: #f8f9fa; cursor: pointer;
font-weight: bold; font-size: 0.9rem;
} }
tr:hover { .btn:hover {
background-color: #f5f5f5; background: #605acf;
} }
.btn { .btn-danger {
display: inline-block; background: #e74c3c;
background: #7873f5; }
color: white; .btn-danger:hover {
padding: 8px 15px; background: #c0392b;
border-radius: 4px; }
text-decoration: none; .form-group {
font-weight: bold; margin-bottom: 20px;
transition: background 0.3s ease; }
border: none; label {
cursor: pointer; display: block;
font-size: 0.9rem; margin-bottom: 8px;
} font-weight: bold;
.btn:hover { color: #555;
background: #605acf; }
} input[type="text"],
.btn-danger { input[type="password"] {
background: #e74c3c; width: 100%;
} padding: 12px;
.btn-danger:hover { border: 1px solid #ddd;
background: #c0392b; border-radius: 6px;
} font-size: 1rem;
.form-group { }
margin-bottom: 20px; .message {
} padding: 15px;
label { margin-bottom: 20px;
display: block; border-radius: 4px;
margin-bottom: 8px; font-weight: bold;
font-weight: bold; }
color: #555; .success {
} background-color: #d4edda;
input[type="text"], color: #155724;
input[type="password"] { border: 1px solid #c3e6cb;
width: 100%; }
padding: 12px; .error {
border: 1px solid #ddd; background-color: #f8d7da;
border-radius: 6px; color: #721c24;
font-size: 1rem; border: 1px solid #f5c6cb;
} }
.message { .card {
padding: 15px; background: white;
margin-bottom: 20px; border-radius: 10px;
border-radius: 4px; padding: 20px;
font-weight: bold; margin-bottom: 30px;
} box-shadow: 0 2px 10px rgba(0,0,0,0.05);
.success { }
background-color: #d4edda; </style>
color: #155724; </head>
border: 1px solid #c3e6cb; <body>
} <div class="container">
.error { <h1>管理员账户管理</h1>
background-color: #f8d7da;
color: #721c24; <?php if (!empty($message)): ?>
border: 1px solid #f5c6cb; <div class="message <?php echo $success ? 'success' : 'error'; ?>">
} <?php echo $message; ?>
.card { </div>
background: white; <?php endif; ?>
border-radius: 10px;
padding: 20px; <div class="card">
margin-bottom: 30px; <h2>当前管理员账户</h2>
box-shadow: 0 2px 10px rgba(0,0,0,0.05); <table>
} <thead>
</style> <tr>
</head> <th>ID</th>
<body> <th>用户名</th>
<div class="container"> <th>创建时间</th>
<h1>管理员账户管理</h1> <th>操作</th>

</tr>
<?php if (!empty($message)): ?> </thead>
<div class="message <?php echo $success ? 'success' : 'error'; ?>"> <tbody>
<?php echo $message; ?> <?php foreach ($admins as $admin): ?>
</div> <tr>
<?php endif; ?> <td><?php echo $admin['id']; ?></td>

<td><?php echo $admin['username']; ?></td>
<div class="card"> <td><?php echo $admin['created_at']; ?></td>
<h2>当前管理员账户</h2> <td>
<table> <form method="post" style="display: inline;">
<thead> <input type="hidden" name="action" value="delete">
<tr> <input type="hidden" name="id" value="<?php echo $admin['id']; ?>">
<th>ID</th> <button type="submit" class="btn btn-danger" onclick="return confirm('确定要删除这个管理员账户吗?');">删除</button>
<th>用户名</th> </form>
<th>创建时间</th> </td>
<th>操作</th> </tr>
</tr> <?php endforeach; ?>
</thead> </tbody>
<tbody> </table>
<?php foreach ($admins as $admin): ?> </div>
<tr>
<td><?php echo $admin['id']; ?></td> <div class="card">
<td><?php echo htmlspecialchars($admin['username']); ?></td> <h2>添加新管理员</h2>
<td><?php echo $admin['created_at']; ?></td> <form method="post">
<td> <input type="hidden" name="action" value="add">
<?php if ($admin['id'] != $_SESSION['admin_id']): ?> <div class="form-group">
<form method="post" style="display: inline;"> <label for="username">用户名</label>
<input type="hidden" name="csrf_token" value="<?php echo $csrf_token; ?>"> <input type="text" id="username" name="username" required placeholder="输入新管理员用户名">
<input type="hidden" name="action" value="delete"> </div>
<input type="hidden" name="id" value="<?php echo $admin['id']; ?>"> <div class="form-group">
<button type="submit" class="btn btn-danger" onclick="return confirm('确定要删除这个管理员账户吗?');">删除</button> <label for="password">密码</label>
</form> <input type="password" id="password" name="password" required placeholder="输入密码至少6位">
<?php else: ?> </div>
<span style="color: #999;">当前账户</span> <div class="form-group">
<?php endif; ?> <label for="confirm_password">确认密码</label>
</td> <input type="password" id="confirm_password" name="confirm_password" required placeholder="再次输入密码">
</tr> </div>
<?php endforeach; ?> <button type="submit" class="btn">添加管理员</button>
</tbody> </form>
</table> </div>
</div>

<div style="text-align: center; margin-top: 30px;">
<div class="card"> <a href="admin_dashboard.php" class="btn">返回管理面板</a>
<h2>添加新管理员</h2> </div>
<form method="post"> </div>
<input type="hidden" name="csrf_token" value="<?php echo $csrf_token; ?>"> </body>
<input type="hidden" name="action" value="add">
<div class="form-group">
<label for="username">用户名</label>
<input type="text" id="username" name="username" required placeholder="输入新管理员用户名">
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" id="password" name="password" required placeholder="输入密码至少6位">
</div>
<div class="form-group">
<label for="confirm_password">确认密码</label>
<input type="password" id="confirm_password" name="confirm_password" required placeholder="再次输入密码">
</div>
<button type="submit" class="btn">添加管理员</button>
</form>
</div>

<div style="text-align: center; margin-top: 30px;">
<a href="admin_dashboard.php" class="btn">返回管理面板</a>
</div>
</div>
</body>
</html> </html>

View file

@ -1,66 +1,67 @@
<?php <?php
session_start(); // 管理员拒绝备案申请
require_once '../auth_check.php';
checkAdminAuth(); // 检查是否已登录

if (!isset($_COOKIE['admin_logged_in']) || $_COOKIE['admin_logged_in'] !== 'true') {
// 检查是否提供了申请ID header('Location: admin_login.php');
if (!isset($_POST['registration_id'])) { exit;
die('缺少备案申请ID'); }
}

// 检查是否提供了申请ID
$registrationId = $_POST['registration_id']; if (!isset($_POST['registration_id'])) {
$reason = $_POST['reason'] ?? ''; die('缺少备案申请ID');

}
if (empty($reason)) {
die('请提供拒绝原因'); $registrationId = $_POST['registration_id'];
} $reason = $_POST['reason'] ?? '';


// 正确加载配置 if (empty($reason)) {
$config = include '../config.php'; die('请提供拒绝原因');
if (!$config || !is_array($config)) { }
die('配置文件加载失败');
} // 加载配置

$config = include '../config.php';
// 初始化数据库连接
require_once '../db_init.php'; // 初始化数据库连接
require_once '../email_utils.php'; require_once '../db_init.php';

require_once '../email_utils.php';
// 更新备案申请状态为拒绝
try { // 更新备案申请状态为拒绝
// 开始事务 try {
$pdo->beginTransaction(); // 开始事务

$pdo->beginTransaction();
// 获取备案信息
$stmt = $pdo->prepare("SELECT * FROM registrations WHERE id = ?"); // 获取备案信息
$stmt->execute([$registrationId]); $stmt = $pdo->prepare("SELECT * FROM registrations WHERE id = ?");
$registration = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->execute([$registrationId]);

$registration = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$registration) {
die('未找到该备案申请'); if (!$registration) {
} die('未找到该备案申请');

}
// 更新状态
$stmt = $pdo->prepare("UPDATE registrations SET status = 'rejected', processed_at = NOW(), reason = ? WHERE id = ?"); // 更新状态
$stmt->execute([$reason, $registrationId]); $stmt = $pdo->prepare("UPDATE registrations SET status = 'rejected', processed_at = NOW(), reason = ? WHERE id = ?");

$stmt->execute([$reason, $registrationId]);
// 提交事务
$pdo->commit(); // 提交事务

$pdo->commit();
// 发送邮件通知
try { // 发送邮件通知
$emailUtils = new EmailUtils($pdo); try {
$emailUtils->sendRejectionEmail($registration); $emailUtils = new EmailUtils($config);
} catch (Exception $e) { $emailUtils->sendRejectionEmail($registration);
// 邮件发送失败,记录日志但不影响主流程 } catch (Exception $e) {
error_log('发送拒绝通知邮件失败: ' . $e->getMessage()); // 邮件发送失败,记录日志但不影响主流程
} error_log('发送拒绝通知邮件失败: ' . $e->getMessage());

}
// 重定向回管理员面板
header('Location: admin_dashboard.php?success=1&message=备案申请已拒绝'); // 重定向回管理员面板
exit; header('Location: admin_dashboard.php?success=1&message=备案申请已拒绝');
} catch (PDOException $e) { exit;
// 回滚事务 } catch (PDOException $e) {
$pdo->rollBack(); // 回滚事务
die('更新备案申请状态失败: ' . $e->getMessage()); $pdo->rollBack();
} die('更新备案申请状态失败: ' . $e->getMessage());
}
?> ?>

View file

@ -1,476 +0,0 @@
<?php
session_start();
require_once '../auth_check.php';
checkAdminAuth();
$csrf_token = generateCSRFToken();

// 加载配置
$config = include '../config.php';

// 数据库连接函数
function getDatabaseConnection() {
global $config;
try {
if ($config['database_type'] === 'mysql') {
$dsn = "mysql:host={$config['database_config']['host']};port={$config['database_config']['port']};dbname={$config['database_config']['name']};charset=utf8mb4";
return new PDO($dsn, $config['database_config']['user'], $config['database_config']['password']);
} else if ($config['database_type'] === 'sqlite') {
$dsn = "sqlite:{$config['database_config']['path']}";
return new PDO($dsn);
}
} catch (PDOException $e) {
die('数据库连接失败: ' . $e->getMessage());
}
}

// 连接数据库
$pdo = getDatabaseConnection();

// 从数据库获取网站信息
$stmt = $pdo->query("SELECT name, description FROM site_info LIMIT 1");
$siteInfo = $stmt->fetch(PDO::FETCH_ASSOC);

// 如果找不到网站信息,使用配置文件中的默认值
if (!$siteInfo) {
$siteInfo = [
'name' => $config['site_name'] ?? '二次元网站备案系统',
'description' => $config['site_description'] ?? '管理和审核网站备案申请'
];
}

// 从数据库获取邮件配置
$stmt = $pdo->query("SELECT * FROM email_config LIMIT 1");
$emailConfig = $stmt->fetch(PDO::FETCH_ASSOC);

// 如果找不到邮件配置,使用默认值
if (!$emailConfig) {
$emailConfig = [
'smtp_host' => '',
'smtp_port' => 465,
'smtp_username' => '',
'smtp_password' => '',
'smtp_encryption' => 'ssl',
'from_email' => '',
'from_name' => $siteInfo['name']
];
}

// 处理表单提交
$success = '';
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 验证CSRF令牌
verifyCSRFToken($_POST['csrf_token'] ?? '');
// 处理站点设置
$siteName = trim($_POST['site_name']);
$siteDescription = trim($_POST['site_description']);

// 处理邮件设置
$smtpHost = trim($_POST['smtp_host']);
$smtpPort = (int)$_POST['smtp_port'];
$smtpUsername = trim($_POST['smtp_username']);
$smtpPassword = trim($_POST['smtp_password']);
$smtpEncryption = $_POST['smtp_encryption'];
$fromEmail = trim($_POST['from_email']);
$fromName = trim($_POST['from_name']);

// 验证必填字段
if (empty($siteName)) {
$errors[] = '站点名称不能为空';
}

if (empty($smtpHost) || empty($smtpUsername) || empty($smtpPassword) || empty($fromEmail)) {
$errors[] = '邮件配置的必填字段不能为空';
}

if (empty($errors)) {
try {
// 开始事务
$pdo->beginTransaction();

// 更新站点信息
if ($siteInfo) {
$stmt = $pdo->prepare("UPDATE site_info SET name = ?, description = ?");
$stmt->execute([$siteName, $siteDescription]);
} else {
$stmt = $pdo->prepare("INSERT INTO site_info (name, description) VALUES (?, ?)");
$stmt->execute([$siteName, $siteDescription]);
}

// 更新邮件配置
if ($emailConfig) {
$stmt = $pdo->prepare("UPDATE email_config SET smtp_host = ?, smtp_port = ?, smtp_username = ?, smtp_password = ?, smtp_encryption = ?, from_email = ?, from_name = ?");
$stmt->execute([$smtpHost, $smtpPort, $smtpUsername, $smtpPassword, $smtpEncryption, $fromEmail, $fromName]);
} else {
$stmt = $pdo->prepare("INSERT INTO email_config (smtp_host, smtp_port, smtp_username, smtp_password, smtp_encryption, from_email, from_name) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$smtpHost, $smtpPort, $smtpUsername, $smtpPassword, $smtpEncryption, $fromEmail, $fromName]);
}

// 提交事务
$pdo->commit();

$success = '设置已成功保存';

// 更新本地变量以反映更改
$siteInfo['name'] = $siteName;
$siteInfo['description'] = $siteDescription;
$emailConfig = [
'smtp_host' => $smtpHost,
'smtp_port' => $smtpPort,
'smtp_username' => $smtpUsername,
'smtp_password' => $smtpPassword,
'smtp_encryption' => $smtpEncryption,
'from_email' => $fromEmail,
'from_name' => $fromName
];
} catch (PDOException $e) {
// 回滚事务
$pdo->rollBack();
$errors[] = '保存设置失败: ' . $e->getMessage();
}
}
}

// 确保email_config表存在
function ensureEmailConfigTableExists($pdo) {
try {
// 根据数据库类型选择自增关键字
global $config;
$auto_increment = ($config['database_type'] === 'mysql') ? 'AUTO_INCREMENT' : 'AUTOINCREMENT';
$int_type = ($config['database_type'] === 'mysql') ? 'INT' : 'INTEGER';

$pdo->exec("CREATE TABLE IF NOT EXISTS email_config (
id $int_type PRIMARY KEY $auto_increment,
smtp_host VARCHAR(255) NOT NULL,
smtp_port INTEGER NOT NULL,
smtp_username VARCHAR(255) NOT NULL,
smtp_password VARCHAR(255) NOT NULL,
smtp_encryption VARCHAR(10) NOT NULL,
from_email VARCHAR(255) NOT NULL,
from_name VARCHAR(255) NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)");
} catch (PDOException $e) {
die('创建email_config表失败: ' . $e->getMessage());
}
}

// 确保表存在
ensureEmailConfigTableExists($pdo);
?>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>系统设置 - <?php echo $siteInfo['name']; ?></title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #f0f2f5;
color: #333;
line-height: 1.6;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.header-frosted {
position: fixed;
top: 0;
left: 0;
right: 0;
background: rgba(255, 255, 255, 0.7);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
color: #333;
padding: 15px 20px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
z-index: 1000;
}
.header-nav {
display: flex;
gap: 20px;
}
.header-nav span {
cursor: pointer;
color: #7873f5;
font-weight: bold;
transition: color 0.3s ease;
}
.header-nav span:hover {
color: #605acf;
}
header {
background: linear-gradient(135deg, #ff6ec7, #7873f5);
color: white;
padding: 80px 0 40px;
text-align: center;
border-radius: 10px;
margin-bottom: 30px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
margin-top: 60px;
}
h1 {
font-size: 2rem;
margin-bottom: 10px;
}
.card {
background: white;
border-radius: 10px;
padding: 30px;
margin-bottom: 30px;
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}
h2 {
color: #7873f5;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 2px solid #f0f0f0;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: bold;
color: #555;
}
input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 1rem;
transition: border 0.3s ease;
}
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus {
border-color: #7873f5;
outline: none;
box-shadow: 0 0 0 3px rgba(120, 115, 245, 0.2);
}
textarea {
height: 150px;
resize: vertical;
}
.btn {
display: inline-block;
background: #7873f5;
color: white;
padding: 12px 25px;
border-radius: 30px;
text-decoration: none;
font-weight: bold;
transition: background 0.3s ease;
border: none;
cursor: pointer;
font-size: 1rem;
}
.btn:hover {
background: #605acf;
}
.btn-container {
text-align: center;
margin-top: 30px;
}
.back-link {
display: inline-block;
margin-top: 15px;
color: #7873f5;
text-decoration: none;
}
.back-link:hover {
text-decoration: underline;
}
.error {
color: #e74c3c;
font-size: 0.9rem;
margin-top: 5px;
}
.success {
color: #2ecc71;
padding: 15px;
background: #f1f9f1;
border-radius: 6px;
margin-bottom: 20px;
border-left: 4px solid #2ecc71;
}
.logout-btn {
background: #e74c3c;
color: white;
border: none;
padding: 8px 15px;
border-radius: 30px;
cursor: pointer;
font-weight: bold;
transition: background 0.3s ease;
}
.logout-btn:hover {
background: #c0392b;
}
.tab-container {
margin-bottom: 20px;
}
.tab {
display: inline-block;
padding: 10px 20px;
background: #f0f0f0;
border-radius: 5px 5px 0 0;
cursor: pointer;
font-weight: bold;
color: #777;
transition: all 0.3s ease;
}
.tab.active {
background: white;
color: #7873f5;
border-top: 2px solid #7873f5;
}
.tab-content {
display: none;
background: white;
padding: 20px;
border-radius: 0 5px 5px 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.tab-content.active {
display: block;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function() {
// 选项卡切换
const tabs = document.querySelectorAll('.tab');
tabs.forEach(tab => {
tab.addEventListener('click', function() {
// 移除所有active类
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));

// 添加active类到当前选项卡
this.classList.add('active');
const target = this.getAttribute('data-target');
document.getElementById(target).classList.add('active');
});
});
});
</script>
</head>
<body>
<div class="header-frosted">
<h3><?php echo $siteInfo['name']; ?> - 管理员面板</h3>
<div class="header-nav">
<span onclick="window.location.href='admin_dashboard.php'">控制面板</span>
<span onclick="window.location.href='admin_dashboard.php?view=all'">所有备案</span>
<span onclick="window.location.href='admin_dashboard.php?view=pending'">待审核备案</span>
<span onclick="window.location.href='add_registration.php'">添加备案</span>
<span onclick="window.location.href='settings.php'">系统设置</span>
<button class="logout-btn" onclick="window.location.href='admin_login.php?action=logout'">退出登录</button>
</div>
</div>
<div class="container">
<header>
<h1><?php echo $siteInfo['name']; ?> - 系统设置</h1>
<p>配置站点信息和邮件设置</p>
</header>

<div class="card">
<h2>系统设置</h2>

<?php if ($success): ?>
<div class="success"><?php echo $success; ?></div>
<?php endif; ?>

<?php if (!empty($errors)): ?>
<?php foreach ($errors as $error): ?>
<div class="error"><?php echo $error; ?></div>
<?php endforeach; ?>
<?php endif; ?>

<div class="tab-container">
<div class="tab active" data-target="site-settings">站点设置</div>
<div class="tab" data-target="email-settings">邮件设置</div>
</div>

<form method="post">
<input type="hidden" name="csrf_token" value="<?php echo $csrf_token; ?>">
<div id="site-settings" class="tab-content active">
<div class="form-group">
<label for="site_name">站点名称 *</label>
<input type="text" id="site_name" name="site_name" required value="<?php echo htmlspecialchars($siteInfo['name']); ?>">
</div>

<div class="form-group">
<label for="site_description">站点描述</label>
<textarea id="site_description" name="site_description"><?php echo htmlspecialchars($siteInfo['description']); ?></textarea>
</div>
</div>

<div id="email-settings" class="tab-content">
<div class="form-group">
<label for="smtp_host">SMTP 服务器 *</label>
<input type="text" id="smtp_host" name="smtp_host" required value="<?php echo htmlspecialchars($emailConfig['smtp_host']); ?>">
</div>

<div class="form-group">
<label for="smtp_port">SMTP 端口 *</label>
<input type="text" id="smtp_port" name="smtp_port" required value="<?php echo htmlspecialchars($emailConfig['smtp_port']); ?>">
</div>

<div class="form-group">
<label for="smtp_encryption">加密方式 *</label>
<select id="smtp_encryption" name="smtp_encryption" required>
<option value="ssl" <?php echo $emailConfig['smtp_encryption'] === 'ssl' ? 'selected' : ''; ?>>SSL</option>
<option value="tls" <?php echo $emailConfig['smtp_encryption'] === 'tls' ? 'selected' : ''; ?>>TLS</option>
<option value="none" <?php echo $emailConfig['smtp_encryption'] === 'none' ? 'selected' : ''; ?>>无</option>
</select>
</div>

<div class="form-group">
<label for="smtp_username">SMTP 用户名 *</label>
<input type="text" id="smtp_username" name="smtp_username" required value="<?php echo htmlspecialchars($emailConfig['smtp_username']); ?>">
</div>

<div class="form-group">
<label for="smtp_password">SMTP 密码 *</label>
<input type="password" id="smtp_password" name="smtp_password" required value="<?php echo htmlspecialchars($emailConfig['smtp_password']); ?>">
</div>

<div class="form-group">
<label for="from_email">发件人邮箱 *</label>
<input type="email" id="from_email" name="from_email" required value="<?php echo htmlspecialchars($emailConfig['from_email']); ?>">
</div>

<div class="form-group">
<label for="from_name">发件人名称 *</label>
<input type="text" id="from_name" name="from_name" required value="<?php echo htmlspecialchars($emailConfig['from_name']); ?>">
</div>
</div>

<div class="btn-container">
<button type="submit" class="btn">保存设置</button>
<a href="admin_dashboard.php" class="back-link">返回控制面板</a>
</div>
</form>
</div>
</div>
</body>
</html>

View file

@ -1,44 +0,0 @@
<?php
// 统一身份验证和安全检查模块
session_start();

// 验证管理员登录状态
function checkAdminAuth() {
// 检查 session 而不是 cookie
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
header('Location: /admin/admin_login.php');
exit;
}
// 检查会话超时1小时
if (isset($_SESSION['last_activity']) && (time() - $_SESSION['last_activity'] > 3600)) {
session_unset();
session_destroy();
header('Location: /admin/admin_login.php?timeout=1');
exit;
}
$_SESSION['last_activity'] = time();
// 重新生成会话ID以防止会话固定攻击
if (!isset($_SESSION['regenerated'])) {
session_regenerate_id(true);
$_SESSION['regenerated'] = true;
}
}

// 生成CSRF令牌
function generateCSRFToken() {
if (!isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
return $_SESSION['csrf_token'];
}

// 验证CSRF令牌
function verifyCSRFToken($token) {
if (!isset($_SESSION['csrf_token']) || $token !== $_SESSION['csrf_token']) {
die('CSRF token validation failed');
}
}
?>

View file

@ -1,80 +1,104 @@
<?php <?php
// 数据库初始化脚本 // 数据库初始化脚本
// 安全检查:如果系统已安装,禁止访问 // 这个脚本用于创建必要的数据库表结构
if (file_exists('.installed')) {
die('系统已安装。数据库初始化已被禁用。'); // 加载配置
} $config = include 'config.php';


// 正确加载配置 // 数据库连接函数
$config = include 'config.php'; function getDatabaseConnection() {
if (!$config || !is_array($config)) { global $config;
die('配置文件加载失败'); try {
} if ($config['database_type'] === 'mysql') {

$dsn = "mysql:host={$config['database_config']['host']};port={$config['database_config']['port']};dbname={$config['database_config']['name']};charset=utf8mb4";
// 数据库连接函数 return new PDO($dsn, $config['database_config']['user'], $config['database_config']['password']);
function getDatabaseConnection() { } else if ($config['database_type'] === 'sqlite') {
global $config; $dsn = "sqlite:{$config['database_config']['path']}";
try { return new PDO($dsn);
if ($config['database_type'] === 'mysql') { }
$dsn = "mysql:host={$config['database_config']['host']};port={$config['database_config']['port']};dbname={$config['database_config']['name']};charset=utf8mb4"; } catch (PDOException $e) {
return new PDO($dsn, $config['database_config']['user'], $config['database_config']['password']); die('数据库连接失败: ' . $e->getMessage());
} else if ($config['database_type'] === 'sqlite') { }
$dsn = "sqlite:{$config['database_config']['path']}"; }
return new PDO($dsn);
} // 连接数据库
} catch (PDOException $e) { $pdo = getDatabaseConnection();
die('数据库连接失败: ' . $e->getMessage());
} // 创建表的SQL语句
} // 根据数据库类型选择合适的自增语法

$autoIncrement = $config['database_type'] === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT';
// 连接数据库
$pdo = getDatabaseConnection(); $queries = [

// 创建管理员表
// 根据数据库类型选择合适的自增语法 "CREATE TABLE IF NOT EXISTS admins (
$autoIncrement = $config['database_type'] === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT'; id INTEGER PRIMARY KEY $autoIncrement,

username VARCHAR(50) NOT NULL UNIQUE,
$queries = [ password_hash VARCHAR(255) NOT NULL,
// 创建管理员表 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
"CREATE TABLE IF NOT EXISTS admins ( )",
id INTEGER PRIMARY KEY $autoIncrement,
username VARCHAR(50) NOT NULL UNIQUE, // 创建网站信息表
password_hash VARCHAR(255) NOT NULL, "CREATE TABLE IF NOT EXISTS site_info (
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP id INTEGER PRIMARY KEY $autoIncrement,
)", name VARCHAR(100) NOT NULL,

description TEXT,
// 创建网站信息表 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
"CREATE TABLE IF NOT EXISTS site_info ( )",
id INTEGER PRIMARY KEY $autoIncrement,
name VARCHAR(100) NOT NULL, // 创建备案申请表
description TEXT, "CREATE TABLE IF NOT EXISTS registrations (
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP id INTEGER PRIMARY KEY $autoIncrement,
)", website_name VARCHAR(255) NOT NULL,

website_url VARCHAR(255) NOT NULL,
// 创建备案申请表 contact_person VARCHAR(100) NOT NULL,
"CREATE TABLE IF NOT EXISTS registrations ( contact_email VARCHAR(255) NOT NULL,
id INTEGER PRIMARY KEY $autoIncrement, contact_phone VARCHAR(255) NOT NULL,
website_name VARCHAR(255) NOT NULL, website_category VARCHAR(100) NOT NULL,
website_url VARCHAR(255) NOT NULL, website_description TEXT NOT NULL,
contact_person VARCHAR(100) NOT NULL, status VARCHAR(20) DEFAULT 'pending',
contact_email VARCHAR(255) NOT NULL, reason TEXT,
contact_phone VARCHAR(255) NOT NULL, registration_number VARCHAR(50),
website_category VARCHAR(100) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
website_description TEXT NOT NULL, processed_at TIMESTAMP
status VARCHAR(20) DEFAULT 'pending', )"
reason TEXT, ];
registration_number VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, // 执行SQL语句
processed_at TIMESTAMP try {
)" foreach ($queries as $query) {
]; $pdo->exec($query);

}
// 执行SQL语句
try { // 初始化管理员账户
foreach ($queries as $query) { $stmt = $pdo->prepare("SELECT COUNT(*) FROM admins");
$pdo->exec($query); $stmt->execute();
} $count = $stmt->fetchColumn();
echo "数据库表结构初始化完成<br>";
} catch (PDOException $e) { if ($count === 0) {
die('创建表结构失败: ' . $e->getMessage()); // 创建默认管理员账户
} $username = $config['admin']['username'];
$password = $config['admin']['password'];
$passwordHash = password_hash($password, PASSWORD_DEFAULT);

$stmt = $pdo->prepare("INSERT INTO admins (username, password_hash) VALUES (?, ?)");
$stmt->execute([$username, $passwordHash]);

echo "管理员账户已创建!用户名: $username, 密码: $password <br>";
echo "请登录后立即修改密码!<br>";
}

// 初始化网站信息
$stmt = $pdo->prepare("SELECT COUNT(*) FROM site_info");
$stmt->execute();
$count = $stmt->fetchColumn();

if ($count === 0) {
$stmt = $pdo->prepare("INSERT INTO site_info (name, description) VALUES (?, ?)");
$stmt->execute([$config['site_name'], $config['site_description']]);
}

// 表结构初始化完成
} catch (PDOException $e) {
die('创建表结构失败: ' . $e->getMessage());
}
?> ?>

358
index.php
View file

@ -1,176 +1,184 @@
<!DOCTYPE html> <!DOCTYPE html>
<?php <?php
// 检查是否已安装 // 检查是否已安装
if (!file_exists('config.php')) { if (!file_exists('config.php')) {
header('Location: install.php'); // 调试信息
exit; error_log('index.php: config.php不存在重定向到install.php');
} header('Location: install.php');

exit;
// 正确加载配置 }
$config = include 'config.php';
if (!$config || !is_array($config)) { // 加载配置
die('配置文件加载失败'); $config = include 'config.php';
} ?>
?> <?php include 'common_header.php'; ?>
<?php include 'common_header.php'; ?>

<div class="container">
<div class="container"> <style>
<style> * {
* { margin: 0;
margin: 0; padding: 0;
padding: 0; box-sizing: border-box;
box-sizing: border-box; }
} body {
body { background-image: url('img/Camera_XHS_17522965447511000g0082k8vvumgii0505o57.jpg');
background-image: url('img/Camera_XHS_17522965447511000g0082k8vvumgii0505o57.jpg'); background-size: cover;
background-size: cover; background-position: center;
background-position: center; background-attachment: fixed;
background-attachment: fixed; color: #333;
color: #333; line-height: 1.6;
line-height: 1.6; background-color: #f0f2f5;
background-color: #f0f2f5; }
} /* 页眉样式已移至common_header.php */
.container { .container {
max-width: 1200px; max-width: 1200px;
margin: 0 auto; margin: 0 auto;
padding: 20px; padding: 20px;
margin-top: 90px; margin-top: 90px; /* 为固定的页眉留出空间 */
} }
h1 { h1 {
font-size: 2.5rem; font-size: 2.5rem;
margin-bottom: 10px; margin-bottom: 10px;
color: white; color: white;
text-shadow: 0 2px 4px rgba(0,0,0,0.5); text-shadow: 0 2px 4px rgba(0,0,0,0.5);
} }
.subtitle { .subtitle {
font-size: 1.2rem; font-size: 1.2rem;
opacity: 0.9; opacity: 0.9;
color: white; color: white;
text-shadow: 0 1px 2px rgba(0,0,0,0.5); text-shadow: 0 1px 2px rgba(0,0,0,0.5);
} }
.card { .card {
background: white; background: white;
border-radius: 10px; border-radius: 10px;
padding: 30px; padding: 30px;
margin-bottom: 30px; margin-bottom: 30px;
box-shadow: 0 2px 10px rgba(0,0,0,0.05); box-shadow: 0 2px 10px rgba(0,0,0,0.05);
transition: transform 0.3s ease, box-shadow 0.3s ease; transition: transform 0.3s ease, box-shadow 0.3s ease;
} }
.form-group {
margin-bottom: 20px; .form-group {
} margin-bottom: 20px;
label { }
display: block;
margin-bottom: 8px; label {
font-weight: bold; display: block;
color: #555; margin-bottom: 8px;
} font-weight: bold;
input[type="text"], color: #555;
select { }
width: 100%;
padding: 12px; input[type="text"],
border: 1px solid #ddd; select {
border-radius: 6px; width: 100%;
font-size: 1rem; padding: 12px;
transition: border 0.3s ease; border: 1px solid #ddd;
} border-radius: 6px;
input[type="text"]:focus, font-size: 1rem;
select:focus { transition: border 0.3s ease;
border-color: #7873f5; }
outline: none;
box-shadow: 0 0 0 3px rgba(120, 115, 245, 0.2); input[type="text"]:focus,
} select:focus {
.btn-container { border-color: #7873f5;
text-align: center; outline: none;
margin-top: 30px; box-shadow: 0 0 0 3px rgba(120, 115, 245, 0.2);
} }
.card:hover {
transform: translateY(-5px); .btn-container {
box-shadow: 0 5px 15px rgba(0,0,0,0.1); text-align: center;
} margin-top: 30px;
h2 { }
color: #7873f5; .card:hover {
margin-bottom: 20px; transform: translateY(-5px);
padding-bottom: 10px; box-shadow: 0 5px 15px rgba(0,0,0,0.1);
border-bottom: 2px solid #f0f0f0; }
} h2 {
.btn { color: #7873f5;
display: inline-block; margin-bottom: 20px;
background: #7873f5; padding-bottom: 10px;
color: white; border-bottom: 2px solid #f0f0f0;
padding: 12px 25px; }
border-radius: 30px; .btn {
text-decoration: none; display: inline-block;
font-weight: bold; background: #7873f5;
transition: background 0.3s ease; color: white;
border: none; padding: 12px 25px;
cursor: pointer; border-radius: 30px;
font-size: 1rem; text-decoration: none;
} font-weight: bold;
.btn:hover { transition: background 0.3s ease;
background: #605acf; border: none;
} cursor: pointer;
.features { font-size: 1rem;
display: flex; }
flex-wrap: wrap; .btn:hover {
gap: 20px; background: #605acf;
margin-top: 30px; }
} .features {
.feature-item { display: flex;
flex: 1 1 300px; flex-wrap: wrap;
background: #f9f9ff; gap: 20px;
padding: 20px; margin-top: 30px;
border-radius: 8px; }
border-left: 4px solid #7873f5; .feature-item {
} flex: 1 1 300px;
.feature-item h3 { background: #f9f9ff;
color: #7873f5; padding: 20px;
margin-bottom: 10px; border-radius: 8px;
} border-left: 4px solid #7873f5;
footer { }
text-align: center; .feature-item h3 {
padding: 20px; color: #7873f5;
color: #777; margin-bottom: 10px;
margin-top: 20px; }
} footer {
@media (max-width: 768px) { text-align: center;
h1 { padding: 20px;
font-size: 2rem; color: #777;
} margin-top: 20px;
.container { }
padding: 15px; @media (max-width: 768px) {
} h1 {
#randomImage { font-size: 2rem;
max-height: 200px; }
} .container {
} padding: 15px;
</style> }
</head> #randomImage {
<body> max-height: 200px;
<div class="container"> }
<div class="card"> }
<h2>备案查询</h2> </style>
<p style="margin-bottom: 20px;">输入备案编号或网站地址查询备案信息</p> </head>

<body>
<form method="get" action="search.php">
<div class="form-group"> <div class="container">
<label for="search_type">查询类型</label> <div class="card">
<select id="search_type" name="search_type"> <h2>备案查询</h2>
<option value="registration_number">备案编号</option> <p style="margin-bottom: 20px;">输入备案编号或网站地址查询备案信息</p>
<option value="website">网站地址</option>
</select> <form method="get" action="search.php">
</div> <div class="form-group">

<label for="search_type">查询类型</label>
<div class="form-group"> <select id="search_type" name="search_type">
<label for="search_query">查询内容</label> <option value="registration_number">备案编号</option>
<input type="text" id="search_query" name="search_query" placeholder="请输入查询内容" value="<?php if (isset($_GET['search_query'])) echo htmlspecialchars($_GET['search_query']); ?>"> <option value="website">网站地址</option>
</div> </select>

</div>
<div class="btn-container">
<button type="submit" class="btn">查询</button> <div class="form-group">
</div> <label for="search_query">查询内容</label>
</form> <input type="text" id="search_query" name="search_query" placeholder="请输入查询内容" value="<?php if (isset($_GET['search_query'])) echo htmlspecialchars($_GET['search_query']); ?>">
</div> </div>
</div>
</body> <div class="btn-container">
<button type="submit" class="btn">查询</button>
</div>
</form>
</div>

<!-- 页脚已删除 -->
</div>
</body>
</html> </html>

File diff suppressed because it is too large Load diff

View file

@ -1,312 +1,314 @@
<?php <?php
// 检查是否已安装 // 检查是否已安装
if (!file_exists('config.php')) { if (!file_exists('config.php')) {
header('Location: install.php'); header('Location: install.php');
exit; exit;
} }


// 正确加载配置 // 加载配置
$config = include 'config.php'; $config = include 'config.php';
if (!$config || !is_array($config)) {
die('配置文件加载失败'); // 初始化数据库连接
} require_once 'db_init.php';


// 初始化数据库连接 // 处理表单提交
require_once 'db_init.php'; $success = '';

$errors = [];
// 处理表单提交 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$success = ''; // 验证表单数据
$errors = []; $data = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 验证表单数据 // 验证网站名称
$data = []; if (empty($_POST['website_name'])) {

$errors[] = '网站名称不能为空';
// 验证网站名称 } else {
if (empty($_POST['website_name'])) { $data['website_name'] = trim($_POST['website_name']);
$errors[] = '网站名称不能为空'; }
} else {
$data['website_name'] = trim($_POST['website_name']); // 验证网站类型
} if (empty($_POST['website_category'])) {

$errors[] = '请选择网站类型';
// 验证网站类型 } else {
if (empty($_POST['website_category'])) { $data['website_category'] = $_POST['website_category'];
$errors[] = '请选择网站类型'; }
} else {
$data['website_category'] = $_POST['website_category']; // 验证网站负责人
} if (empty($_POST['contact_person'])) {

$errors[] = '网站负责人不能为空';
// 验证网站负责人 } else {
if (empty($_POST['contact_person'])) { $data['contact_person'] = trim($_POST['contact_person']);
$errors[] = '网站负责人不能为空'; }
} else {
$data['contact_person'] = trim($_POST['contact_person']); // 验证联系电话
} if (empty($_POST['contact_phone'])) {

$errors[] = '联系电话不能为空';
// 验证联系电话 } else {
if (empty($_POST['contact_phone'])) { $data['contact_phone'] = trim($_POST['contact_phone']);
$errors[] = '联系电话不能为空'; }
} else {
$data['contact_phone'] = trim($_POST['contact_phone']); // 验证联系邮箱
} if (empty($_POST['contact_email'])) {

$errors[] = '联系邮箱不能为空';
// 验证联系邮箱 } elseif (!filter_var($_POST['contact_email'], FILTER_VALIDATE_EMAIL)) {
if (empty($_POST['contact_email'])) { $errors[] = '请输入有效的邮箱地址';
$errors[] = '联系邮箱不能为空'; } else {
} elseif (!filter_var($_POST['contact_email'], FILTER_VALIDATE_EMAIL)) { $data['contact_email'] = trim($_POST['contact_email']);
$errors[] = '请输入有效的邮箱地址'; }
} else {
$data['contact_email'] = trim($_POST['contact_email']); // 验证网站地址
} if (empty($_POST['website_url'])) {

$errors[] = '网站地址不能为空';
// 验证网站地址 } else {
if (empty($_POST['website_url'])) { $website = trim($_POST['website_url']);
$errors[] = '网站地址不能为空'; $website = preg_replace('#^https?://#', '', $website); // 统一格式
} else { $data['website_url'] = $website;
$website = trim($_POST['website_url']); }
$website = preg_replace('#^https?://#', '', $website);
$data['website_url'] = $website; // 验证网站描述
} if (empty($_POST['website_description'])) {

$errors[] = '网站描述不能为空';
// 验证网站描述 } else {
if (empty($_POST['website_description'])) { $data['website_description'] = trim($_POST['website_description']);
$errors[] = '网站描述不能为空'; }
} else {
$data['website_description'] = trim($_POST['website_description']); // 如果没有错误,保存数据
} if (empty($errors)) {

// 生成唯一备案编号 (ICP-年月日-6位ID)
// 如果没有错误,保存数据 // 生成8位数字备案编号
if (empty($errors)) { $data['registration_number'] = str_pad(rand(10000000, 99999999), 8, '0', STR_PAD_LEFT);
// 生成8位数字备案编号 $data['created_at'] = date('Y-m-d H:i:s');
$data['registration_number'] = str_pad(rand(10000000, 99999999), 8, '0', STR_PAD_LEFT); $data['status'] = 'pending'; // 默认为待审核
$data['created_at'] = date('Y-m-d H:i:s'); $data['reason'] = '';
$data['status'] = 'pending';
$data['reason'] = ''; try {

// 插入数据到数据库
try { $stmt = $pdo->prepare("INSERT INTO registrations (website_name, website_url, contact_person, contact_email, contact_phone, website_category, website_description, status, reason, registration_number, created_at, processed_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
// 插入数据到数据库 $stmt->execute([
$stmt = $pdo->prepare("INSERT INTO registrations (website_name, website_url, contact_person, contact_email, contact_phone, website_category, website_description, status, reason, registration_number, created_at, processed_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $data['website_name'],
$stmt->execute([ $data['website_url'],
$data['website_name'], $data['contact_person'],
$data['website_url'], $data['contact_email'],
$data['contact_person'], $data['contact_phone'],
$data['contact_email'], $data['website_category'],
$data['contact_phone'], $data['website_description'],
$data['website_category'], $data['status'],
$data['website_description'], $data['reason'],
$data['status'], $data['registration_number'],
$data['reason'], $data['created_at'],
$data['registration_number'], null
$data['created_at'], ]);
null
]); $success = '备案信息添加成功!备案编号: 初ICP备' . $data['registration_number'] . '备';

} catch (PDOException $e) {
$success = '备案信息添加成功!备案编号: 初ICP备' . $data['registration_number'] . '备'; $errors[] = '添加备案信息失败: ' . $e->getMessage();
} catch (PDOException $e) { }
$errors[] = '添加备案信息失败: ' . $e->getMessage(); }
} }
}
} // 从数据库获取网站信息

$stmt = $pdo->query("SELECT name, description FROM site_info LIMIT 1");
// 从数据库获取网站信息 $siteInfo = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = $pdo->query("SELECT name, description FROM site_info LIMIT 1");
$siteInfo = $stmt->fetch(PDO::FETCH_ASSOC); // 如果找不到网站信息,使用配置文件中的默认值

if (!$siteInfo) {
// 如果找不到网站信息,使用配置文件中的默认值 $siteInfo = [
if (!$siteInfo) { 'name' => $config['site_name'] ?? '网站备案系统',
$siteInfo = [ 'description' => $config['site_description'] ?? 'ICP备案管理平台'
'name' => $config['site_name'] ?? '网站备案系统', ];
'description' => $config['site_description'] ?? 'ICP备案管理平台' }
]; ?>
} <?php include 'common_header.php'; ?>
?>
<?php include 'common_header.php'; ?> <style>

.container {
<style> max-width: 800px;
.container { margin: 0 auto;
max-width: 800px; padding: 20px;
margin: 0 auto; margin-top: 20px;
padding: 20px; }
margin-top: 20px; .header-content {
} background: linear-gradient(135deg, #ff6ec7, #7873f5);
.header-content { color: white;
background: linear-gradient(135deg, #ff6ec7, #7873f5); padding: 40px 0;
color: white; text-align: center;
padding: 40px 0; border-radius: 10px;
text-align: center; margin-bottom: 30px;
border-radius: 10px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);
margin-bottom: 30px; }
box-shadow: 0 4px 12px rgba(0,0,0,0.1); h1 {
} font-size: 2.5rem;
h1 { margin-bottom: 10px;
font-size: 2.5rem; text-shadow: 0 2px 4px rgba(0,0,0,0.2);
margin-bottom: 10px; }
text-shadow: 0 2px 4px rgba(0,0,0,0.2); .subtitle {
} font-size: 1.2rem;
.subtitle { opacity: 0.9;
font-size: 1.2rem; }
opacity: 0.9; .card {
} background: white;
.card { border-radius: 10px;
background: white; padding: 30px;
border-radius: 10px; margin-bottom: 30px;
padding: 30px; box-shadow: 0 2px 10px rgba(0,0,0,0.05);
margin-bottom: 30px; }
box-shadow: 0 2px 10px rgba(0,0,0,0.05); h2 {
} color: #7873f5;
h2 { margin-bottom: 20px;
color: #7873f5; padding-bottom: 10px;
margin-bottom: 20px; border-bottom: 2px solid #f0f0f0;
padding-bottom: 10px; }
border-bottom: 2px solid #f0f0f0; .form-group {
} margin-bottom: 20px;
.form-group { }
margin-bottom: 20px; label {
} display: block;
label { margin-bottom: 8px;
display: block; font-weight: bold;
margin-bottom: 8px; color: #555;
font-weight: bold; }
color: #555; input[type="text"],
} input[type="email"],
input[type="text"], textarea,
input[type="email"], select {
textarea, width: 100%;
select { padding: 12px;
width: 100%; border: 1px solid #ddd;
padding: 12px; border-radius: 6px;
border: 1px solid #ddd; font-size: 1rem;
border-radius: 6px; transition: border 0.3s ease;
font-size: 1rem; }
transition: border 0.3s ease; input[type="text"]:focus,
} input[type="email"]:focus,
input[type="text"]:focus, textarea:focus,
input[type="email"]:focus, select:focus {
textarea:focus, border-color: #7873f5;
select:focus { outline: none;
border-color: #7873f5; box-shadow: 0 0 0 3px rgba(120, 115, 245, 0.2);
outline: none; }
box-shadow: 0 0 0 3px rgba(120, 115, 245, 0.2); textarea {
} height: 150px;
textarea { resize: vertical;
height: 150px; }
resize: vertical; .btn {
} display: inline-block;
.btn { background: #7873f5;
display: inline-block; color: white;
background: #7873f5; padding: 12px 25px;
color: white; border-radius: 30px;
padding: 12px 25px; text-decoration: none;
border-radius: 30px; font-weight: bold;
text-decoration: none; transition: background 0.3s ease;
font-weight: bold; border: none;
transition: background 0.3s ease; cursor: pointer;
border: none; font-size: 1rem;
cursor: pointer; }
font-size: 1rem; .btn:hover {
} background: #605acf;
.btn:hover { }
background: #605acf; .btn-container {
} text-align: center;
.btn-container { margin-top: 30px;
text-align: center; }
margin-top: 30px; .back-link {
} display: inline-block;
.back-link { margin-top: 15px;
display: inline-block; color: #7873f5;
margin-top: 15px; text-decoration: none;
color: #7873f5; }
text-decoration: none; .back-link:hover {
} text-decoration: underline;
.back-link:hover { }
text-decoration: underline; .error {
} color: #e74c3c;
.error { font-size: 0.9rem;
color: #e74c3c; margin-top: 5px;
font-size: 0.9rem; }
margin-top: 5px; .success {
} color: #2ecc71;
.success { padding: 15px;
color: #2ecc71; background: #f1f9f1;
padding: 15px; border-radius: 6px;
background: #f1f9f1; margin-bottom: 20px;
border-radius: 6px; border-left: 4px solid #2ecc71;
margin-bottom: 20px; }
border-left: 4px solid #2ecc71; @media (max-width: 768px) {
} #randomImage {
@media (max-width: 768px) { max-height: 200px;
#randomImage { }
max-height: 200px; }
} </style>
} </head>
</style> <body>
</head> <div class="header-content">
<body> <h1>网站备案申请</h1>
<div class="header-content"> <p class="subtitle">填写以下信息完成网站备案申请</p>
<h1>网站备案申请</h1> </div>
<p class="subtitle">填写以下信息完成网站备案申请</p>
</div> <div class="card">

<h2>网站备案申请</h2>
<div class="card">
<h2>网站备案申请</h2> <?php if ($success): ?>

<div class="success"><?php echo $success; ?></div>
<?php if ($success): ?> <?php endif; ?>
<div class="success"><?php echo $success; ?></div>
<?php endif; ?> <?php if (!empty($errors)): ?>

<?php foreach ($errors as $error): ?>
<?php if (!empty($errors)): ?> <div class="error"><?php echo $error; ?></div>
<?php foreach ($errors as $error): ?> <?php endforeach; ?>
<div class="error"><?php echo $error; ?></div> <?php endif; ?>
<?php endforeach; ?>
<?php endif; ?> <form method="post">

<div class="form-group">
<form method="post"> <label for="website_name">网站名称 *</label>
<div class="form-group"> <input type="text" id="website_name" name="website_name" required placeholder="请输入网站的名称">
<label for="website_name">网站名称 *</label> </div>
<input type="text" id="website_name" name="website_name" required placeholder="请输入网站的名称">
</div> <div class="form-group">

<label for="website_category">网站类型 *</label>
<div class="form-group"> <select id="website_category" name="website_category" required>
<label for="website_category">网站类型 *</label> <option value="">请选择</option>
<select id="website_category" name="website_category" required> <option value="anime">动漫网站</option>
<option value="">请选择</option> <option value="game">游戏网站</option>
<option value="anime">动漫网站</option> <option value="blog">个人博客</option>
<option value="game">游戏网站</option> <option value="other">其他类型</option>
<option value="blog">个人博客</option> </select>
<option value="other">其他类型</option> </div>
</select>
</div> <div class="form-group">

<label for="contact_person">网站负责人 *</label>
<div class="form-group"> <input type="text" id="contact_person" name="contact_person" required placeholder="请输入网站负责人姓名">
<label for="contact_person">网站负责人 *</label> </div>
<input type="text" id="contact_person" name="contact_person" required placeholder="请输入网站负责人姓名">
</div> <div class="form-group">

<label for="contact_phone">联系电话 *</label>
<div class="form-group"> <input type="text" id="contact_phone" name="contact_phone" required placeholder="请输入联系电话">
<label for="contact_phone">联系电话 *</label> </div>
<input type="text" id="contact_phone" name="contact_phone" required placeholder="请输入联系电话">
</div> <div class="form-group">

<label for="contact_email">联系邮箱 *</label>
<div class="form-group"> <input type="email" id="contact_email" name="contact_email" required placeholder="请输入联系邮箱">
<label for="contact_email">联系邮箱 *</label> </div>
<input type="email" id="contact_email" name="contact_email" required placeholder="请输入联系邮箱">
</div> <div class="form-group">

<label for="website_url">网站地址 *</label>
<div class="form-group"> <input type="text" id="website_url" name="website_url" required placeholder="请输入网站域名不带http://">
<label for="website_url">网站地址 *</label> </div>
<input type="text" id="website_url" name="website_url" required placeholder="请输入网站域名不带http://">
</div> <div class="form-group">

<label for="website_description">网站描述 *</label>
<div class="form-group"> <textarea id="website_description" name="website_description" required placeholder="请简要描述网站内容"></textarea>
<label for="website_description">网站描述 *</label> </div>
<textarea id="website_description" name="website_description" required placeholder="请简要描述网站内容"></textarea>
</div> <div class="btn-container">

<button type="submit" class="btn">提交备案</button>
<div class="btn-container"> <a href="index.php" class="back-link">返回首页</a>
<button type="submit" class="btn">提交备案</button> </div>
<a href="index.php" class="back-link">返回首页</a> </form>
</div> </div>
</form> </div>
</div>
</div> <!-- common_footer.php 文件不存在,已移除引用 -->
</body>
</div>
</body>
</html> </html>

View file

@ -1,257 +1,258 @@
<?php <?php
// 检查是否已安装 // 检查是否已安装
if (!file_exists('config.php')) { if (!file_exists('config.php')) {
header('Location: install.php'); header('Location: install.php');
exit; exit;
} }


// 正确加载配置 // 加载配置
$config = include 'config.php'; $config = include 'config.php';
if (!$config || !is_array($config)) { ?>
die('配置文件加载失败'); <?php include 'common_header.php'; ?>
}
?> <div class="container">
<?php include 'common_header.php'; ?> <style>

* {
<div class="container"> margin: 0;
<style> padding: 0;
* { box-sizing: border-box;
margin: 0; }
padding: 0; body {
box-sizing: border-box; background-color: #f0f2f5;
} color: #333;
body { line-height: 1.6;
background-color: #f0f2f5; }
color: #333; .container {
line-height: 1.6; max-width: 800px;
} margin: 0 auto;
.container { padding: 20px;
max-width: 800px; margin-top: 20px;
margin: 0 auto; }
padding: 20px; .header-content {
margin-top: 20px; background: linear-gradient(135deg, #ff6ec7, #7873f5);
} color: white;
.header-content { padding: 20px 0;
background: linear-gradient(135deg, #ff6ec7, #7873f5); text-align: center;
color: white; border-radius: 10px;
padding: 20px 0; margin-bottom: 30px;
text-align: center; box-shadow: 0 4px 12px rgba(0,0,0,0.1);
border-radius: 10px; }
margin-bottom: 30px; h1 {
box-shadow: 0 4px 12px rgba(0,0,0,0.1); font-size: 1.8rem;
} margin-bottom: 10px;
h1 { }
font-size: 1.8rem; .card {
margin-bottom: 10px; background: white;
} border-radius: 10px;
.card { padding: 30px;
background: white; margin-bottom: 30px;
border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.05);
padding: 30px; }
margin-bottom: 30px; h2 {
box-shadow: 0 2px 10px rgba(0,0,0,0.05); color: #7873f5;
} margin-bottom: 20px;
h2 { padding-bottom: 10px;
color: #7873f5; border-bottom: 2px solid #f0f0f0;
margin-bottom: 20px; }
padding-bottom: 10px; .form-group {
border-bottom: 2px solid #f0f0f0; margin-bottom: 20px;
} }
.form-group { label {
margin-bottom: 20px; display: block;
} margin-bottom: 8px;
label { font-weight: bold;
display: block; color: #555;
margin-bottom: 8px; }
font-weight: bold; input[type="text"],
color: #555; select {
} width: 100%;
input[type="text"], padding: 12px;
select { border: 1px solid #ddd;
width: 100%; border-radius: 6px;
padding: 12px; font-size: 1rem;
border: 1px solid #ddd; transition: border 0.3s ease;
border-radius: 6px; }
font-size: 1rem; input[type="text"]:focus,
transition: border 0.3s ease; select:focus {
} border-color: #7873f5;
input[type="text"]:focus, outline: none;
select:focus { box-shadow: 0 0 0 3px rgba(120, 115, 245, 0.2);
border-color: #7873f5; }
outline: none; .btn {
box-shadow: 0 0 0 3px rgba(120, 115, 245, 0.2); display: inline-block;
} background: #7873f5;
.btn { color: white;
display: inline-block; padding: 12px 25px;
background: #7873f5; border-radius: 30px;
color: white; text-decoration: none;
padding: 12px 25px; font-weight: bold;
border-radius: 30px; transition: background 0.3s ease;
text-decoration: none; border: none;
font-weight: bold; cursor: pointer;
transition: background 0.3s ease; font-size: 1rem;
border: none; }
cursor: pointer; .btn:hover {
font-size: 1rem; background: #605acf;
} }
.btn:hover { .btn-container {
background: #605acf; text-align: center;
} margin-top: 30px;
.btn-container { }
text-align: center; .back-link {
margin-top: 30px; display: inline-block;
} margin-top: 15px;
.back-link { color: #7873f5;
display: inline-block; text-decoration: none;
margin-top: 15px; }
color: #7873f5; .back-link:hover {
text-decoration: none; text-decoration: underline;
} }
.back-link:hover { .error {
text-decoration: underline; color: #e74c3c;
} font-size: 0.9rem;
.error { margin-top: 5px;
color: #e74c3c; }
font-size: 0.9rem; .search-results {
margin-top: 5px; margin-top: 30px;
} }
.search-results { .result-item {
margin-top: 30px; background: #f9f9ff;
} padding: 20px;
.result-item { border-radius: 8px;
background: #f9f9ff; margin-bottom: 20px;
padding: 20px; border-left: 4px solid #7873f5;
border-radius: 8px; }
margin-bottom: 20px; .result-item h3 {
border-left: 4px solid #7873f5; color: #7873f5;
} margin-bottom: 10px;
.result-item h3 { }
color: #7873f5; .result-item p {
margin-bottom: 10px; margin-bottom: 8px;
} }
.result-item p { .result-label {
margin-bottom: 8px; font-weight: bold;
} color: #555;
.result-label { }
font-weight: bold; .no-results {
color: #555; text-align: center;
} padding: 30px;
.no-results { color: #777;
text-align: center; }
padding: 30px; @media (max-width: 768px) {
color: #777; #randomImage {
} max-height: 200px;
@media (max-width: 768px) { }
#randomImage { }
max-height: 200px; </style>
} <div class="header-content">
} <h1>网站备案查询</h1>
</style> <p>输入备案编号或网站地址查询备案信息</p>
<div class="header-content"> </div>
<h1>网站备案查询</h1>
<p>输入备案编号或网站地址查询备案信息</p> <div class="card">
</div> <h2>查询备案信息</h2>


<div class="card"> <form method="get">
<h2>查询备案信息</h2> <div class="form-group">

<label for="search_type">查询类型</label>
<form method="get"> <select id="search_type" name="search_type">
<div class="form-group"> <option value="registration_number" <?php if (isset($_GET['search_type']) && $_GET['search_type'] == 'registration_number') echo 'selected'; ?>>备案编号</option>
<label for="search_type">查询类型</label> <option value="website" <?php if (isset($_GET['search_type']) && $_GET['search_type'] == 'website') echo 'selected'; ?>>网站地址</option>
<select id="search_type" name="search_type"> </select>
<option value="registration_number" <?php if (isset($_GET['search_type']) && $_GET['search_type'] == 'registration_number') echo 'selected'; ?>>备案编号</option> </div>
<option value="website" <?php if (isset($_GET['search_type']) && $_GET['search_type'] == 'website') echo 'selected'; ?>>网站地址</option>
</select> <div class="form-group">
</div> <label for="search_query">查询内容</label>

<input type="text" id="search_query" name="search_query" placeholder="请输入查询内容" value="<?php if (isset($_GET['search_query'])) echo htmlspecialchars($_GET['search_query']); ?>">
<div class="form-group"> </div>
<label for="search_query">查询内容</label>
<input type="text" id="search_query" name="search_query" placeholder="请输入查询内容" value="<?php if (isset($_GET['search_query'])) echo htmlspecialchars($_GET['search_query']); ?>"> <div class="btn-container">
</div> <button type="submit" class="btn">查询</button>

</div>
<div class="btn-container"> <span class="back-link">返回首页</span>
<button type="submit" class="btn">查询</button> </form>
<a href="index.php" class="back-link">返回首页</a>
</div> <div class="search-results">
</form> <?php

// 加载配置
<div class="search-results"> $config = include 'config.php';
<?php
// 设置默认配置值 // 设置默认配置值
$site_name = $config['site_name'] ?? '网站备案系统'; $site_name = $config['site_name'] ?? '网站备案系统';
$site_description = $config['site_description'] ?? 'ICP备案管理平台'; $site_description = $config['site_description'] ?? 'ICP备案管理平台';


// 初始化数据库连接 // 初始化数据库连接
require_once 'db_init.php'; require_once 'db_init.php';


// 处理查询请求 // 处理查询请求
if (isset($_GET['search_query']) && !empty($_GET['search_query'])) { if (isset($_GET['search_query']) && !empty($_GET['search_query'])) {
$search_type = $_GET['search_type']; $search_type = $_GET['search_type'];
$search_query = trim($_GET['search_query']); $search_query = trim($_GET['search_query']);
$results = []; $results = [];


// 检查数据库连接 // 检查数据库连接
if (isset($pdo) && $pdo) { if (isset($pdo) && $pdo) {
try { try {
// 准备SQL查询 // 准备SQL查询
if ($search_type === 'registration_number') { if ($search_type === 'registration_number') {
$stmt = $pdo->prepare("SELECT * FROM registrations WHERE registration_number LIKE :query"); $stmt = $pdo->prepare("SELECT * FROM registrations WHERE registration_number LIKE :query");
$stmt->execute(['query' => '%' . $search_query . '%']); $stmt->execute(['query' => '%' . $search_query . '%']);
} elseif ($search_type === 'website') { } elseif ($search_type === 'website') {
$stmt = $pdo->prepare("SELECT * FROM registrations WHERE website_url LIKE :query"); $stmt = $pdo->prepare("SELECT * FROM registrations WHERE website_url LIKE :query");
$stmt->execute(['query' => '%' . $search_query . '%']); $stmt->execute(['query' => '%' . $search_query . '%']);
} elseif ($search_type === 'email') { } elseif ($search_type === 'email') {
$stmt = $pdo->prepare("SELECT * FROM registrations WHERE contact_email LIKE :query"); $stmt = $pdo->prepare("SELECT * FROM registrations WHERE contact_email LIKE :query");
$stmt->execute(['query' => '%' . $search_query . '%']); $stmt->execute(['query' => '%' . $search_query . '%']);
} }


$results = $stmt->fetchAll(PDO::FETCH_ASSOC); $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) { } catch (PDOException $e) {
echo '<div class="error">查询失败: ' . $e->getMessage() . '</div>'; echo '<div class="error">查询失败: ' . $e->getMessage() . '</div>';
} }
} else { } else {
echo '<div class="error">数据库连接失败,请检查配置文件。</div>'; echo '<div class="error">数据库连接失败,请检查配置文件。</div>';
} }


// 显示查询结果 // 显示查询结果
if (!empty($results)) { if (!empty($results)) {
echo '<h3>查询结果 (共 ' . count($results) . ' 条)</h3>'; echo '<h3>查询结果 (共 ' . count($results) . ' 条)</h3>';
foreach ($results as $result) { foreach ($results as $result) {
echo '<div class="result-item">'; echo '<div class="result-item">';
echo '<h3>' . htmlspecialchars($result['website_name']) . '</h3>'; echo '<h3>' . htmlspecialchars($result['website_name']) . '</h3>';
echo '<p><span class="result-label">备案编号:</span>初ICP备' . htmlspecialchars($result['registration_number']) . '备</p>'; echo '<p><span class="result-label">备案编号:</span>初ICP备' . htmlspecialchars($result['registration_number']) . '备</p>';
// 显示网站类型 // 显示网站类型
$categoryMap = [ $categoryMap = [
'anime' => '动漫网站', 'anime' => '动漫网站',
'game' => '游戏网站', 'game' => '游戏网站',
'blog' => '个人博客', 'blog' => '个人博客',
'other' => '其他类型' 'other' => '其他类型'
]; ];
echo '<p><span class="result-label">网站类型:</span>' . htmlspecialchars($categoryMap[$result['website_category']] ?? '未知类型') . '</p>'; echo '<p><span class="result-label">网站类型:</span>' . htmlspecialchars($categoryMap[$result['website_category']] ?? '未知类型') . '</p>';
echo '<p><span class="result-label">网站负责人:</span>' . htmlspecialchars($result['contact_person']) . '</p>'; echo '<p><span class="result-label">网站负责人:</span>' . htmlspecialchars($result['contact_person']) . '</p>';
echo '<p><span class="result-label">联系电话:</span>' . htmlspecialchars($result['contact_phone']) . '</p>'; echo '<p><span class="result-label">联系电话:</span>' . htmlspecialchars($result['contact_phone']) . '</p>';
echo '<p><span class="result-label">联系邮箱:</span>' . htmlspecialchars($result['contact_email']) . '</p>'; echo '<p><span class="result-label">联系邮箱:</span>' . htmlspecialchars($result['contact_email']) . '</p>';
echo '<p><span class="result-label">网站地址:</span><a href="http://' . htmlspecialchars($result['website_url']) . '" target="_blank">' . htmlspecialchars($result['website_url']) . '</a></p>'; echo '<p><span class="result-label">网站地址:</span><a href="http://' . htmlspecialchars($result['website_url']) . '" target="_blank">' . htmlspecialchars($result['website_url']) . '</a></p>';
echo '<p><span class="result-label">提交日期:</span>' . htmlspecialchars($result['created_at']) . '</p>'; echo '<p><span class="result-label">提交日期:</span>' . htmlspecialchars($result['created_at']) . '</p>';
echo '<p><span class="result-label">处理日期:</span>' . htmlspecialchars($result['processed_at'] ?? '未处理') . '</p>'; echo '<p><span class="result-label">处理日期:</span>' . htmlspecialchars($result['processed_at'] ?? '未处理') . '</p>';
echo '<p><span class="result-label">状态:</span>' . ($result['status'] === 'pending' ? '待审核' : ($result['status'] === 'approved' ? '已通过' : '已拒绝')) . '</p>'; echo '<p><span class="result-label">状态:</span>' . ($result['status'] === 'pending' ? '待审核' : ($result['status'] === 'approved' ? '已通过' : '已拒绝')) . '</p>';
echo '<p><span class="result-label">网站描述:</span>' . nl2br(htmlspecialchars($result['website_description'])) . '</p>'; echo '<p><span class="result-label">网站描述:</span>' . nl2br(htmlspecialchars($result['website_description'])) . '</p>';
if (!empty($result['reason'])) { if (!empty($result['reason'])) {
echo '<p><span class="result-label">处理说明:</span>' . nl2br(htmlspecialchars($result['reason'])) . '</p>'; echo '<p><span class="result-label">处理说明:</span>' . nl2br(htmlspecialchars($result['reason'])) . '</p>';
} }
echo '</div>'; echo '</div>';
} }
} else { } else {
echo '<div class="no-results">'; echo '<div class="no-results">';
echo '<p>没有找到符合条件的备案信息</p>'; echo '<p>没有找到符合条件的备案信息</p>';
echo '</div>'; echo '</div>';
} }
} }
?> ?>
</div> </div>
</div> </div>
</div>
</body> </div>
</html> </body>
</html>