This commit is contained in:
2026-06-24 17:45:24 +08:00
commit bc0223bf07
16 changed files with 1553 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
<?php
// 认证中间件 - 检查登录状态
session_start();
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
header('Location: index.php');
exit;
}
+111
View File
@@ -0,0 +1,111 @@
<?php
require_once 'auth.php';
require_once '../includes/db.php';
require_once '../includes/functions.php';
$success = '';
$error = '';
// 处理表单提交
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$site_title = $_POST['site_title'] ?? '';
$site_description = $_POST['site_description'] ?? '';
// 更新基本配置
updateConfig('site_title', $site_title);
updateConfig('site_description', $site_description);
// 处理 Logo 上传
if (isset($_FILES['logo']) && $_FILES['logo']['error'] === UPLOAD_ERR_OK) {
$logo = $_FILES['logo'];
$ext = strtolower(pathinfo($logo['name'], PATHINFO_EXTENSION));
// 验证文件类型
if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif'])) {
$logo_filename = 'logo_' . time() . '.' . $ext;
$logo_path = '../data/uploads/' . $logo_filename;
if (move_uploaded_file($logo['tmp_name'], $logo_path)) {
// 删除旧 logo(如果在 data/uploads/ 目录)
$old_logo = getConfig('logo_path');
if (strpos($old_logo, 'data/uploads/') === 0) {
$old_logo_path = '../' . $old_logo;
if (file_exists($old_logo_path)) {
unlink($old_logo_path);
}
}
updateConfig('logo_path', 'data/uploads/' . $logo_filename);
$success = '配置保存成功!';
} else {
$error = 'Logo 上传失败';
}
} else {
$error = 'Logo 只支持 JPG、PNG、GIF 格式';
}
} else {
$success = '配置保存成功!';
}
}
// 获取当前配置
$site_title = getConfig('site_title', 'OPS 运营管理系统');
$site_description = getConfig('site_description', '点击下方按钮下载移动端 APP');
$logo_path = getConfig('logo_path', 'logo.png');
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>网站配置</title>
<link rel="stylesheet" href="../assets/admin.css">
</head>
<body>
<div class="admin-container">
<header class="admin-header">
<h1>网站配置</h1>
<div class="header-actions">
<a href="dashboard.php" class="btn btn-secondary">返回管理面板</a>
<a href="logout.php" class="btn btn-secondary">退出</a>
</div>
</header>
<main class="admin-main">
<?php if ($success): ?>
<div class="alert alert-success"><?php echo e($success); ?></div>
<?php endif; ?>
<?php if ($error): ?>
<div class="alert alert-error"><?php echo e($error); ?></div>
<?php endif; ?>
<section class="config-section">
<h2>基本设置</h2>
<form method="POST" enctype="multipart/form-data" class="config-form">
<div class="form-group">
<label>网站标题 *</label>
<input type="text" name="site_title" value="<?php echo e($site_title); ?>" required>
</div>
<div class="form-group">
<label>软件说明</label>
<textarea name="site_description" rows="4"><?php echo e($site_description); ?></textarea>
</div>
<div class="form-group">
<label>网站 Logo</label>
<div class="logo-preview">
<img src="../<?php echo e($logo_path); ?>" alt="Logo" style="max-width: 200px; max-height: 200px;">
</div>
<input type="file" name="logo" accept="image/jpeg,image/png,image/gif">
<small class="form-hint">支持 JPG、PNG、GIF 格式</small>
</div>
<button type="submit" class="btn btn-primary">保存配置</button>
</form>
</section>
</main>
</div>
</body>
</html>
+91
View File
@@ -0,0 +1,91 @@
<?php
require_once 'auth.php';
require_once '../includes/db.php';
require_once '../includes/functions.php';
// 获取所有应用列表
$stmt = $db->query("SELECT * FROM apps ORDER BY upload_time DESC");
$apps = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>管理面板</title>
<link rel="stylesheet" href="../assets/admin.css">
</head>
<body>
<div class="admin-container">
<header class="admin-header">
<h1>管理面板</h1>
<div class="header-actions">
<span>欢迎,<?php echo e($_SESSION['username']); ?></span>
<a href="config.php" class="btn btn-secondary">网站配置</a>
<a href="logout.php" class="btn btn-secondary">退出</a>
</div>
</header>
<main class="admin-main">
<section class="upload-section">
<h2>上传新应用</h2>
<form action="upload.php" method="POST" enctype="multipart/form-data" class="upload-form">
<div class="form-row">
<div class="form-group">
<label>APK 文件 *</label>
<input type="file" name="apk_file" accept=".apk" required>
</div>
<div class="form-group">
<label>版本号</label>
<input type="text" name="version" placeholder="例如:1.0.0">
</div>
</div>
<div class="form-group">
<label>版本描述</label>
<textarea name="description" rows="3" placeholder="描述此版本的更新内容..."></textarea>
</div>
<button type="submit" class="btn btn-primary">上传应用</button>
</form>
</section>
<section class="apps-section">
<h2>已发布应用 (<?php echo count($apps); ?>)</h2>
<?php if (empty($apps)): ?>
<p class="empty-state">暂无已发布的应用</p>
<?php else: ?>
<table class="apps-table">
<thead>
<tr>
<th>文件名</th>
<th>版本</th>
<th>描述</th>
<th>大小</th>
<th>上传时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php foreach ($apps as $app): ?>
<tr>
<td><?php echo e($app['original_name']); ?></td>
<td><?php echo e($app['version'] ?: '-'); ?></td>
<td class="description"><?php echo e($app['description'] ?: '-'); ?></td>
<td><?php echo formatFileSize($app['file_size']); ?></td>
<td><?php echo date('Y-m-d H:i', strtotime($app['upload_time'])); ?></td>
<td>
<a href="../data/apps/<?php echo e($app['filename']); ?>" class="btn-small btn-info" download>下载</a>
<a href="delete.php?id=<?php echo $app['id']; ?>"
class="btn-small btn-danger"
onclick="return confirm('确定要删除此应用吗?')">删除</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</section>
</main>
</div>
</body>
</html>
+27
View File
@@ -0,0 +1,27 @@
<?php
require_once 'auth.php';
require_once '../includes/db.php';
$id = $_GET['id'] ?? 0;
if ($id > 0) {
// 获取应用信息
$stmt = $db->prepare("SELECT * FROM apps WHERE id = ?");
$stmt->execute([$id]);
$app = $stmt->fetch(PDO::FETCH_ASSOC);
if ($app) {
// 删除物理文件
$file_path = '../data/apps/' . $app['filename'];
if (file_exists($file_path)) {
unlink($file_path);
}
// 从数据库删除
$stmt = $db->prepare("DELETE FROM apps WHERE id = ?");
$stmt->execute([$id]);
}
}
header('Location: dashboard.php');
exit;
+137
View File
@@ -0,0 +1,137 @@
<?php
session_start();
// 如果已登录,跳转到管理面板
if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true) {
header('Location: dashboard.php');
exit;
}
$error = '';
// 处理登录请求
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
// 简单的硬编码验证(默认 admin/admin
if ($username === 'admin' && $password === 'admin') {
$_SESSION['admin_logged_in'] = true;
$_SESSION['username'] = $username;
header('Location: 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 {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.login-container {
background: #fff;
border-radius: 16px;
padding: 40px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
width: 100%;
max-width: 400px;
}
h1 {
font-size: 24px;
color: #333;
margin-bottom: 30px;
text-align: center;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
color: #666;
font-size: 14px;
margin-bottom: 8px;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 12px 16px;
border: 1px solid #ddd;
border-radius: 8px;
font-size: 14px;
transition: border-color 0.3s;
}
input[type="text"]:focus,
input[type="password"]:focus {
outline: none;
border-color: #667eea;
}
button {
width: 100%;
padding: 12px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 500;
cursor: pointer;
transition: transform 0.2s;
}
button:hover {
transform: translateY(-2px);
}
button:active {
transform: translateY(0);
}
.error {
background: #fee;
color: #c33;
padding: 12px;
border-radius: 8px;
font-size: 14px;
margin-bottom: 20px;
text-align: center;
}
</style>
</head>
<body>
<div class="login-container">
<h1>管理后台登录</h1>
<?php if ($error): ?>
<div class="error"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<form method="POST">
<div class="form-group">
<label>用户名</label>
<input type="text" name="username" required autofocus>
</div>
<div class="form-group">
<label>密码</label>
<input type="password" name="password" required>
</div>
<button type="submit">登录</button>
</form>
</div>
</body>
</html>
+7
View File
@@ -0,0 +1,7 @@
<?php
// 登出
session_start();
session_destroy();
header('Location: index.php');
exit;
+50
View File
@@ -0,0 +1,50 @@
<?php
require_once 'auth.php';
require_once '../includes/db.php';
// 处理文件上传
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!isset($_FILES['apk_file']) || $_FILES['apk_file']['error'] !== UPLOAD_ERR_OK) {
die('文件上传失败');
}
$file = $_FILES['apk_file'];
$version = $_POST['version'] ?? '';
$description = $_POST['description'] ?? '';
// 验证文件类型
$ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
if ($ext !== 'apk') {
die('只允许上传 APK 文件');
}
// 生成唯一文件名
$filename = time() . '_' . $file['name'];
$target_path = '../data/apps/' . $filename;
// 移动文件
if (!move_uploaded_file($file['tmp_name'], $target_path)) {
die('文件保存失败');
}
// 插入数据库
$stmt = $db->prepare("
INSERT INTO apps (filename, original_name, version, description, file_size)
VALUES (?, ?, ?, ?, ?)
");
$stmt->execute([
$filename,
$file['name'],
$version,
$description,
$file['size']
]);
// 重定向回管理面板
header('Location: dashboard.php');
exit;
}
// 如果不是 POST 请求,重定向回管理面板
header('Location: dashboard.php');
exit;