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
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'] ?? '管理和审核网站备案申请'
];
}

// 处理表单提交
$success = '';
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 验证CSRF令牌
verifyCSRFToken($_POST['csrf_token'] ?? '');
// 验证表单数据
$data = [];

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

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

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

// 验证联系电话
if (empty($_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)) {
$errors[] = '请输入有效的邮箱地址';
} else {
$data['contact_email'] = trim($_POST['contact_email']);
}

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

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

// 验证状态
if (empty($_POST['status'])) {
$errors[] = '请选择状态';
} else {
$data['status'] = $_POST['status'];
}

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

try {
// 插入数据到数据库
$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([
$data['website_name'],
$data['website_category'],
$data['contact_person'],
$data['contact_phone'],
$data['contact_email'],
$data['website_url'],
$data['website_description'],
$data['status'],
$data['created_at'],
$data['processed_at'] ?? null,
$data['registration_number'],
$data['reason']
]);

$success = '备案信息添加成功!备案编号: 初ICP备' . $data['registration_number'] . '备';
} catch (PDOException $e) {
$errors[] = '添加备案信息失败: ' . $e->getMessage();
}
}
}
?>
<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"],
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,
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;
}
</style>
</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; ?>

<form method="post" enctype="multipart/form-data">
<input type="hidden" name="csrf_token" value="<?php echo $csrf_token; ?>">
<div class="form-group">
<label for="website_name">网站名称 *</label>
<input type="text" id="website_name" name="website_name" required placeholder="请输入网站的名称">
</div>

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

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

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

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

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

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

<div class="form-group">
<label for="status">状态 *</label>
<select id="status" name="status" required>
<option value="pending">待审核</option>
<option value="approved">已通过</option>
<option value="rejected">已拒绝</option>
</select>
</div>

<div class="form-group" id="reason_group" style="display: none;">
<label for="reason">处理说明 *</label>
<textarea id="reason" name="reason" placeholder="请输入审核通过或拒绝的原因"></textarea>
</div>

<script>
// 当状态改变时,显示或隐藏处理说明字段
document.getElementById('status').addEventListener('change', function() {
var reasonGroup = document.getElementById('reason_group');
if (this.value === 'approved' || this.value === 'rejected') {
reasonGroup.style.display = 'block';
} else {
reasonGroup.style.display = 'none';
}
});
</script>

<div class="btn-container">
<button type="submit" class="btn">添加备案</button>
<a href="admin_dashboard.php" class="back-link">返回控制面板</a>
</div>
</form>
</div>
</div>
</body>
<?php
// 加载配置
$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'] ?? '管理和审核网站备案申请'
];
}

// 处理表单提交
$success = '';
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 验证表单数据
$data = [];

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

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

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

// 验证联系电话
if (empty($_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)) {
$errors[] = '请输入有效的邮箱地址';
} else {
$data['contact_email'] = trim($_POST['contact_email']);
}

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

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

// 验证状态
if (empty($_POST['status'])) {
$errors[] = '请选择状态';
} else {
$data['status'] = $_POST['status'];
}

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

try {
// 插入数据到数据库
$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([
$data['website_name'],
$data['website_category'],
$data['contact_person'],
$data['contact_phone'],
$data['contact_email'],
$data['website_url'],
$data['website_description'],
$data['status'],
$data['created_at'],
$data['processed_at'] ?? null,
$data['registration_number'],
$data['reason']
]);

$success = '备案信息添加成功!备案编号: 初ICP备' . $data['registration_number'] . '备';
} catch (PDOException $e) {
$errors[] = '添加备案信息失败: ' . $e->getMessage();
}
}
}
?>
<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"],
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,
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;
}
</style>
</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; ?>

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

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

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

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

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

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

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

<div class="form-group">
<label for="status">状态 *</label>
<select id="status" name="status" required>
<option value="pending">待审核</option>
<option value="approved">已通过</option>
<option value="rejected">已拒绝</option>
</select>
</div>

<div class="form-group" id="reason_group" style="display: none;">
<label for="reason">处理说明 *</label>
<textarea id="reason" name="reason" placeholder="请输入审核通过或拒绝的原因"></textarea>
</div>

<script>
// 当状态改变时,显示或隐藏处理说明字段
document.getElementById('status').addEventListener('change', function() {
var reasonGroup = document.getElementById('reason_group');
if (this.value === 'approved' || this.value === 'rejected') {
reasonGroup.style.display = 'block';
} else {
reasonGroup.style.display = 'none';
}
});
</script>

<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>

File diff suppressed because it is too large Load diff

View file

@ -1,227 +1,161 @@
<?php
session_start();

// 加载配置
$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";
$pdo = new PDO($dsn, $config['database_config']['user'], $config['database_config']['password']);
} else if ($config['database_type'] === 'sqlite') {
$dsn = "sqlite:{$config['database_config']['path']}";
$pdo = new PDO($dsn);
}
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo;
} catch (PDOException $e) {
die('数据库连接失败');
}
}

// 处理注销请求
if (isset($_GET['action']) && $_GET['action'] === 'logout') {
session_unset();
session_destroy();
header('Location: admin_login.php');
exit;
}

// 检查是否已登录
if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true) {
header('Location: admin_dashboard.php');
exit;
}

// 防止暴力破解:记录失败次数
if (!isset($_SESSION['login_attempts'])) {
$_SESSION['login_attempts'] = 0;
$_SESSION['last_attempt'] = time();
}

// 重置计数器5分钟后
if (time() - $_SESSION['last_attempt'] > 300) {
$_SESSION['login_attempts'] = 0;
}

$error = '';

// 处理登录请求
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 检查是否超过最大尝试次数5次
if ($_SESSION['login_attempts'] >= 5) {
$error = '登录尝试次数过多请5分钟后重试';
} else {
// 验证CSRF令牌
if (!isset($_POST['csrf_token']) || $_POST['csrf_token'] !== $_SESSION['csrf_token']) {
$error = '安全验证失败,请重新登录';
} else {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';

// 输入验证
if (empty($username) || empty($password)) {
$error = '用户名和密码不能为空';
} else {
// 连接数据库
$pdo = getDatabaseConnection();

// 查询管理员信息
$stmt = $pdo->prepare("SELECT id, password_hash FROM admins WHERE username = ?");
$stmt->execute([$username]);
$admin = $stmt->fetch(PDO::FETCH_ASSOC);

// 验证密码
if ($admin && password_verify($password, $admin['password_hash'])) {
// 登录成功,重置尝试次数
$_SESSION['login_attempts'] = 0;
// 设置会话变量
$_SESSION['admin_logged_in'] = true;
$_SESSION['admin_id'] = $admin['id'];
$_SESSION['admin_username'] = $username;
$_SESSION['last_activity'] = time();
// 重新生成会话ID
session_regenerate_id(true);
header('Location: admin_dashboard.php');
exit;
} else {
$_SESSION['login_attempts']++;
$_SESSION['last_attempt'] = time();
$error = '用户名或密码错误';
}
}
}
}
}

// 生成CSRF令牌
if (!isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>管理员登录 - 二次元网站备案系统</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #f0f2f5;
color: #333;
line-height: 1.6;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.login-container {
background: white;
border-radius: 10px;
padding: 40px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
}
h1 {
color: #7873f5;
margin-bottom: 30px;
text-align: center;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: bold;
color: #555;
}
input[type="text"],
input[type="password"] {
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="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>
<?php
// 加载配置
$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());
}
}

// 处理注销请求
if (isset($_GET['action']) && $_GET['action'] === 'logout') {
setcookie('admin_logged_in', '', time() - 3600, '/');
header('Location: admin_login.php');
exit;
}

// 检查是否已登录
if (isset($_COOKIE['admin_logged_in']) && $_COOKIE['admin_logged_in'] === 'true') {
header('Location: admin_dashboard.php');
exit;
}

$error = '';
// 处理登录请求
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';

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

// 查询管理员信息
$stmt = $pdo->prepare("SELECT password_hash FROM admins WHERE username = ?");
$stmt->execute([$username]);
$admin = $stmt->fetch(PDO::FETCH_ASSOC);

// 验证密码
if ($admin && password_verify($password, $admin['password_hash'])) {
// 设置登录cookie有效期1小时
setcookie('admin_logged_in', 'true', time() + 3600, '/');
header('Location: admin_dashboard.php');
exit;
} else {
$error = '用户名或密码错误';
}
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>管理员登录 - 二次元网站备案系统</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #f0f2f5;
color: #333;
line-height: 1.6;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.login-container {
background: white;
border-radius: 10px;
padding: 40px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
}
h1 {
color: #7873f5;
margin-bottom: 30px;
text-align: center;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: bold;
color: #555;
}
input[type="text"],
input[type="password"] {
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="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;
}
</style>
</head>
<body>
<div class="login-container">
<h1>管理员登录</h1>
<form method="post" class="login-form">
<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="请输入管理员密码">
</div>
<button type="submit" class="btn">登录</button>
<?php if (!empty($error)): ?>
<div class="error"><?php echo $error; ?></div>
<?php endif; ?>
</form>
</div>
</body>
</html>

View file

@ -1,62 +1,63 @@
<?php
session_start();
require_once '../auth_check.php';
checkAdminAuth();

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

$registrationId = $_POST['registration_id'];
$reason = $_POST['reason'] ?? '审核通过';

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

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

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

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

if (!$registration) {
die('未找到该备案申请');
}

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

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

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

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

// 检查是否已登录
if (!isset($_COOKIE['admin_logged_in']) || $_COOKIE['admin_logged_in'] !== 'true') {
header('Location: admin_login.php');
exit;
}

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

$registrationId = $_POST['registration_id'];
$reason = $_POST['reason'] ?? '审核通过';

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

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

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

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

if (!$registration) {
die('未找到该备案申请');
}

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

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

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

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

View file

@ -1,309 +1,287 @@
<?php
session_start();
require_once '../auth_check.php';
checkAdminAuth();

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

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

// 数据库连接函数
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();

// 获取所有管理员账户
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 addAdmin($pdo, $username, $password) {
if (checkUsernameExists($pdo, $username)) {
return ['success' => false, 'message' => '用户名已存在'];
}

$password_hash = password_hash($password, PASSWORD_DEFAULT);
try {
$stmt = $pdo->prepare("INSERT INTO admins (username, password_hash) VALUES (?, ?)");
$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]);
return ['success' => true, 'message' => '管理员删除成功'];
} catch (PDOException $e) {
return ['success' => false, 'message' => '删除失败: ' . $e->getMessage()];
}
}

// 处理表单提交
$message = '';
$success = false;

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 验证CSRF令牌
if (!isset($_POST['csrf_token']) || $_POST['csrf_token'] !== $_SESSION['csrf_token']) {
$message = '安全验证失败';
} else {
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'add':
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$confirm_password = trim($_POST['confirm_password']);

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

case 'delete':
$id = (int)$_POST['id'];
// 防止删除自己
if ($id == $_SESSION['admin_id']) {
$message = '不能删除当前登录的管理员账户';
} else {
$result = deleteAdmin($pdo, $id);
$success = $result['success'];
$message = $result['message'];
}
break;
}
}
}
}

// 生成CSRF令牌
$csrf_token = generateCSRFToken();

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

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

<div class="card">
<h2>当前管理员账户</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>用户名</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php foreach ($admins as $admin): ?>
<tr>
<td><?php echo $admin['id']; ?></td>
<td><?php echo htmlspecialchars($admin['username']); ?></td>
<td><?php echo $admin['created_at']; ?></td>
<td>
<?php if ($admin['id'] != $_SESSION['admin_id']): ?>
<form method="post" style="display: inline;">
<input type="hidden" name="csrf_token" value="<?php echo $csrf_token; ?>">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="id" value="<?php echo $admin['id']; ?>">
<button type="submit" class="btn btn-danger" onclick="return confirm('确定要删除这个管理员账户吗?');">删除</button>
</form>
<?php else: ?>
<span style="color: #999;">当前账户</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>

<div class="card">
<h2>添加新管理员</h2>
<form method="post">
<input type="hidden" name="csrf_token" value="<?php echo $csrf_token; ?>">
<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>
<?php
// 管理管理员账户脚本
// 使用方法: 访问此文件并按照提示操作

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

// 加载配置
$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();

// 获取所有管理员账户
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 addAdmin($pdo, $username, $password) {
if (checkUsernameExists($pdo, $username)) {
return ['success' => false, 'message' => '用户名已存在'];
}

$password_hash = password_hash($password, PASSWORD_DEFAULT);
try {
$stmt = $pdo->prepare("INSERT INTO admins (username, password_hash) VALUES (?, ?)");
$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]);
return ['success' => true, 'message' => '管理员删除成功'];
} catch (PDOException $e) {
return ['success' => false, 'message' => '删除失败: ' . $e->getMessage()];
}
}

// 处理表单提交
$message = '';
$success = false;

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'add':
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$confirm_password = trim($_POST['confirm_password']);

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

case 'delete':
$id = (int)$_POST['id'];
$result = deleteAdmin($pdo, $id);
$success = $result['success'];
$message = $result['message'];
break;
}
}
}

// 获取所有管理员
$admins = getAllAdmins($pdo);

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

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

<div class="card">
<h2>当前管理员账户</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>用户名</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php foreach ($admins as $admin): ?>
<tr>
<td><?php echo $admin['id']; ?></td>
<td><?php echo $admin['username']; ?></td>
<td><?php echo $admin['created_at']; ?></td>
<td>
<form method="post" style="display: inline;">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="id" value="<?php echo $admin['id']; ?>">
<button type="submit" class="btn btn-danger" onclick="return confirm('确定要删除这个管理员账户吗?');">删除</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>

<div class="card">
<h2>添加新管理员</h2>
<form method="post">
<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>

View file

@ -1,66 +1,67 @@
<?php
session_start();
require_once '../auth_check.php';
checkAdminAuth();

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

$registrationId = $_POST['registration_id'];
$reason = $_POST['reason'] ?? '';

if (empty($reason)) {
die('请提供拒绝原因');
}

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

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

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

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

if (!$registration) {
die('未找到该备案申请');
}

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

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

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

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

// 检查是否已登录
if (!isset($_COOKIE['admin_logged_in']) || $_COOKIE['admin_logged_in'] !== 'true') {
header('Location: admin_login.php');
exit;
}

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

$registrationId = $_POST['registration_id'];
$reason = $_POST['reason'] ?? '';

if (empty($reason)) {
die('请提供拒绝原因');
}

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

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

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

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

if (!$registration) {
die('未找到该备案申请');
}

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

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

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

// 重定向回管理员面板
header('Location: admin_dashboard.php?success=1&message=备案申请已拒绝');
exit;
} catch (PDOException $e) {
// 回滚事务
$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
// 数据库初始化脚本
// 安全检查:如果系统已安装,禁止访问
if (file_exists('.installed')) {
die('系统已安装。数据库初始化已被禁用。');
}

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

// 数据库连接函数
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();

// 根据数据库类型选择合适的自增语法
$autoIncrement = $config['database_type'] === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT';

$queries = [
// 创建管理员表
"CREATE TABLE IF NOT EXISTS admins (
id INTEGER PRIMARY KEY $autoIncrement,
username VARCHAR(50) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
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,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)",

// 创建备案申请表
"CREATE TABLE IF NOT EXISTS registrations (
id INTEGER PRIMARY KEY $autoIncrement,
website_name VARCHAR(255) NOT NULL,
website_url VARCHAR(255) NOT NULL,
contact_person VARCHAR(100) NOT NULL,
contact_email VARCHAR(255) NOT NULL,
contact_phone VARCHAR(255) NOT NULL,
website_category VARCHAR(100) NOT NULL,
website_description TEXT NOT NULL,
status VARCHAR(20) DEFAULT 'pending',
reason TEXT,
registration_number VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
processed_at TIMESTAMP
)"
];

// 执行SQL语句
try {
foreach ($queries as $query) {
$pdo->exec($query);
}
echo "数据库表结构初始化完成<br>";
} catch (PDOException $e) {
die('创建表结构失败: ' . $e->getMessage());
}
<?php
// 数据库初始化脚本
// 这个脚本用于创建必要的数据库表结构

// 加载配置
$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();

// 创建表的SQL语句
// 根据数据库类型选择合适的自增语法
$autoIncrement = $config['database_type'] === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT';

$queries = [
// 创建管理员表
"CREATE TABLE IF NOT EXISTS admins (
id INTEGER PRIMARY KEY $autoIncrement,
username VARCHAR(50) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
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,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)",

// 创建备案申请表
"CREATE TABLE IF NOT EXISTS registrations (
id INTEGER PRIMARY KEY $autoIncrement,
website_name VARCHAR(255) NOT NULL,
website_url VARCHAR(255) NOT NULL,
contact_person VARCHAR(100) NOT NULL,
contact_email VARCHAR(255) NOT NULL,
contact_phone VARCHAR(255) NOT NULL,
website_category VARCHAR(100) NOT NULL,
website_description TEXT NOT NULL,
status VARCHAR(20) DEFAULT 'pending',
reason TEXT,
registration_number VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
processed_at TIMESTAMP
)"
];

// 执行SQL语句
try {
foreach ($queries as $query) {
$pdo->exec($query);
}

// 初始化管理员账户
$stmt = $pdo->prepare("SELECT COUNT(*) FROM admins");
$stmt->execute();
$count = $stmt->fetchColumn();

if ($count === 0) {
// 创建默认管理员账户
$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>
<?php
// 检查是否已安装
if (!file_exists('config.php')) {
header('Location: install.php');
exit;
}

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

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

<form method="get" action="search.php">
<div class="form-group">
<label for="search_type">查询类型</label>
<select id="search_type" name="search_type">
<option value="registration_number">备案编号</option>
<option value="website">网站地址</option>
</select>
</div>

<div class="form-group">
<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>

<div class="btn-container">
<button type="submit" class="btn">查询</button>
</div>
</form>
</div>
</div>
</body>
<!DOCTYPE html>
<?php
// 检查是否已安装
if (!file_exists('config.php')) {
// 调试信息
error_log('index.php: config.php不存在重定向到install.php');
header('Location: install.php');
exit;
}

// 加载配置
$config = include 'config.php';
?>
<?php include 'common_header.php'; ?>

<div class="container">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-image: url('img/Camera_XHS_17522965447511000g0082k8vvumgii0505o57.jpg');
background-size: cover;
background-position: center;
background-attachment: fixed;
color: #333;
line-height: 1.6;
background-color: #f0f2f5;
}
/* 页眉样式已移至common_header.php */
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
margin-top: 90px; /* 为固定的页眉留出空间 */
}
h1 {
font-size: 2.5rem;
margin-bottom: 10px;
color: white;
text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.subtitle {
font-size: 1.2rem;
opacity: 0.9;
color: white;
text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.card {
background: white;
border-radius: 10px;
padding: 30px;
margin-bottom: 30px;
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.form-group {
margin-bottom: 20px;
}

label {
display: block;
margin-bottom: 8px;
font-weight: bold;
color: #555;
}

input[type="text"],
select {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 1rem;
transition: border 0.3s ease;
}

input[type="text"]:focus,
select:focus {
border-color: #7873f5;
outline: none;
box-shadow: 0 0 0 3px rgba(120, 115, 245, 0.2);
}

.btn-container {
text-align: center;
margin-top: 30px;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
h2 {
color: #7873f5;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 2px solid #f0f0f0;
}
.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;
}
.features {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-top: 30px;
}
.feature-item {
flex: 1 1 300px;
background: #f9f9ff;
padding: 20px;
border-radius: 8px;
border-left: 4px solid #7873f5;
}
.feature-item h3 {
color: #7873f5;
margin-bottom: 10px;
}
footer {
text-align: center;
padding: 20px;
color: #777;
margin-top: 20px;
}
@media (max-width: 768px) {
h1 {
font-size: 2rem;
}
.container {
padding: 15px;
}
#randomImage {
max-height: 200px;
}
}
</style>
</head>
<body>

<div class="container">
<div class="card">
<h2>备案查询</h2>
<p style="margin-bottom: 20px;">输入备案编号或网站地址查询备案信息</p>

<form method="get" action="search.php">
<div class="form-group">
<label for="search_type">查询类型</label>
<select id="search_type" name="search_type">
<option value="registration_number">备案编号</option>
<option value="website">网站地址</option>
</select>
</div>

<div class="form-group">
<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>

<div class="btn-container">
<button type="submit" class="btn">查询</button>
</div>
</form>
</div>

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

File diff suppressed because it is too large Load diff

View file

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

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

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

// 处理表单提交
$success = '';
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 验证表单数据
$data = [];

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

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

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

// 验证联系电话
if (empty($_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)) {
$errors[] = '请输入有效的邮箱地址';
} else {
$data['contact_email'] = trim($_POST['contact_email']);
}

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

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

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

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([
$data['website_name'],
$data['website_url'],
$data['contact_person'],
$data['contact_email'],
$data['contact_phone'],
$data['website_category'],
$data['website_description'],
$data['status'],
$data['reason'],
$data['registration_number'],
$data['created_at'],
null
]);

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

// 从数据库获取网站信息
$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'] ?? 'ICP备案管理平台'
];
}
?>
<?php include 'common_header.php'; ?>

<style>
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
margin-top: 20px;
}
.header-content {
background: linear-gradient(135deg, #ff6ec7, #7873f5);
color: white;
padding: 40px 0;
text-align: center;
border-radius: 10px;
margin-bottom: 30px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
h1 {
font-size: 2.5rem;
margin-bottom: 10px;
text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.subtitle {
font-size: 1.2rem;
opacity: 0.9;
}
.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"],
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,
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;
}
@media (max-width: 768px) {
#randomImage {
max-height: 200px;
}
}
</style>
</head>
<body>
<div class="header-content">
<h1>网站备案申请</h1>
<p class="subtitle">填写以下信息完成网站备案申请</p>
</div>

<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; ?>

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

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

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

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

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

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

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

<div class="btn-container">
<button type="submit" class="btn">提交备案</button>
<a href="index.php" class="back-link">返回首页</a>
</div>
</form>
</div>
</div>
</body>
<?php
// 检查是否已安装
if (!file_exists('config.php')) {
header('Location: install.php');
exit;
}

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

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

// 处理表单提交
$success = '';
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 验证表单数据
$data = [];

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

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

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

// 验证联系电话
if (empty($_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)) {
$errors[] = '请输入有效的邮箱地址';
} else {
$data['contact_email'] = trim($_POST['contact_email']);
}

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

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

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

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([
$data['website_name'],
$data['website_url'],
$data['contact_person'],
$data['contact_email'],
$data['contact_phone'],
$data['website_category'],
$data['website_description'],
$data['status'],
$data['reason'],
$data['registration_number'],
$data['created_at'],
null
]);

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

// 从数据库获取网站信息
$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'] ?? 'ICP备案管理平台'
];
}
?>
<?php include 'common_header.php'; ?>

<style>
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
margin-top: 20px;
}
.header-content {
background: linear-gradient(135deg, #ff6ec7, #7873f5);
color: white;
padding: 40px 0;
text-align: center;
border-radius: 10px;
margin-bottom: 30px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
h1 {
font-size: 2.5rem;
margin-bottom: 10px;
text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.subtitle {
font-size: 1.2rem;
opacity: 0.9;
}
.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"],
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,
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;
}
@media (max-width: 768px) {
#randomImage {
max-height: 200px;
}
}
</style>
</head>
<body>
<div class="header-content">
<h1>网站备案申请</h1>
<p class="subtitle">填写以下信息完成网站备案申请</p>
</div>

<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; ?>

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

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

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

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

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

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

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

<div class="btn-container">
<button type="submit" class="btn">提交备案</button>
<a href="index.php" class="back-link">返回首页</a>
</div>
</form>
</div>
</div>

<!-- common_footer.php 文件不存在,已移除引用 -->

</div>
</body>
</html>

View file

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

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

<div class="container">
<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;
margin-top: 20px;
}
.header-content {
background: linear-gradient(135deg, #ff6ec7, #7873f5);
color: white;
padding: 20px 0;
text-align: center;
border-radius: 10px;
margin-bottom: 30px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
h1 {
font-size: 1.8rem;
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"],
select {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 1rem;
transition: border 0.3s ease;
}
input[type="text"]:focus,
select: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;
}
.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;
}
.search-results {
margin-top: 30px;
}
.result-item {
background: #f9f9ff;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
border-left: 4px solid #7873f5;
}
.result-item h3 {
color: #7873f5;
margin-bottom: 10px;
}
.result-item p {
margin-bottom: 8px;
}
.result-label {
font-weight: bold;
color: #555;
}
.no-results {
text-align: center;
padding: 30px;
color: #777;
}
@media (max-width: 768px) {
#randomImage {
max-height: 200px;
}
}
</style>
<div class="header-content">
<h1>网站备案查询</h1>
<p>输入备案编号或网站地址查询备案信息</p>
</div>

<div class="card">
<h2>查询备案信息</h2>

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

<div class="form-group">
<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>

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

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

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

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

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

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

// 显示查询结果
if (!empty($results)) {
echo '<h3>查询结果 (共 ' . count($results) . ' 条)</h3>';
foreach ($results as $result) {
echo '<div class="result-item">';
echo '<h3>' . htmlspecialchars($result['website_name']) . '</h3>';
echo '<p><span class="result-label">备案编号:</span>初ICP备' . htmlspecialchars($result['registration_number']) . '备</p>';
// 显示网站类型
$categoryMap = [
'anime' => '动漫网站',
'game' => '游戏网站',
'blog' => '个人博客',
'other' => '其他类型'
];
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_phone']) . '</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>' . htmlspecialchars($result['created_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>' . nl2br(htmlspecialchars($result['website_description'])) . '</p>';
if (!empty($result['reason'])) {
echo '<p><span class="result-label">处理说明:</span>' . nl2br(htmlspecialchars($result['reason'])) . '</p>';
}
echo '</div>';
}
} else {
echo '<div class="no-results">';
echo '<p>没有找到符合条件的备案信息</p>';
echo '</div>';
}
}
?>
</div>
</div>
</div>
</body>
</html>
<?php
// 检查是否已安装
if (!file_exists('config.php')) {
header('Location: install.php');
exit;
}

// 加载配置
$config = include 'config.php';
?>
<?php include 'common_header.php'; ?>

<div class="container">
<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;
margin-top: 20px;
}
.header-content {
background: linear-gradient(135deg, #ff6ec7, #7873f5);
color: white;
padding: 20px 0;
text-align: center;
border-radius: 10px;
margin-bottom: 30px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
h1 {
font-size: 1.8rem;
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"],
select {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 1rem;
transition: border 0.3s ease;
}
input[type="text"]:focus,
select: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;
}
.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;
}
.search-results {
margin-top: 30px;
}
.result-item {
background: #f9f9ff;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
border-left: 4px solid #7873f5;
}
.result-item h3 {
color: #7873f5;
margin-bottom: 10px;
}
.result-item p {
margin-bottom: 8px;
}
.result-label {
font-weight: bold;
color: #555;
}
.no-results {
text-align: center;
padding: 30px;
color: #777;
}
@media (max-width: 768px) {
#randomImage {
max-height: 200px;
}
}
</style>
<div class="header-content">
<h1>网站备案查询</h1>
<p>输入备案编号或网站地址查询备案信息</p>
</div>

<div class="card">
<h2>查询备案信息</h2>

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

<div class="form-group">
<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>

<div class="btn-container">
<button type="submit" class="btn">查询</button>
</div>
<span class="back-link">返回首页</span>
</form>

<div class="search-results">
<?php
// 加载配置
$config = include 'config.php';

// 设置默认配置值
$site_name = $config['site_name'] ?? '网站备案系统';
$site_description = $config['site_description'] ?? 'ICP备案管理平台';

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

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

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

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

// 显示查询结果
if (!empty($results)) {
echo '<h3>查询结果 (共 ' . count($results) . ' 条)</h3>';
foreach ($results as $result) {
echo '<div class="result-item">';
echo '<h3>' . htmlspecialchars($result['website_name']) . '</h3>';
echo '<p><span class="result-label">备案编号:</span>初ICP备' . htmlspecialchars($result['registration_number']) . '备</p>';
// 显示网站类型
$categoryMap = [
'anime' => '动漫网站',
'game' => '游戏网站',
'blog' => '个人博客',
'other' => '其他类型'
];
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_phone']) . '</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>' . htmlspecialchars($result['created_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>' . nl2br(htmlspecialchars($result['website_description'])) . '</p>';
if (!empty($result['reason'])) {
echo '<p><span class="result-label">处理说明:</span>' . nl2br(htmlspecialchars($result['reason'])) . '</p>';
}
echo '</div>';
}
} else {
echo '<div class="no-results">';
echo '<p>没有找到符合条件的备案信息</p>';
echo '</div>';
}
}
?>
</div>
</div>

</div>
</body>
</html>