|
|
<?php
|
|
|
require_once __DIR__ . '/../config/database.php';
|
|
|
require_once __DIR__ . '/../src/storage/Database.php';
|
|
|
require_once __DIR__ . '/../src/storage/ServiceRepository.php';
|
|
|
require_once __DIR__ . '/../src/storage/SystemSettingsRepository.php';
|
|
|
|
|
|
session_start();
|
|
|
|
|
|
// 身份验证
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
|
header('Location: index.php');
|
|
|
exit;
|
|
|
}
|
|
|
|
|
|
// 检查管理员权限
|
|
|
if (!$_SESSION['is_admin']) {
|
|
|
die('权限不足:只有管理员可以访问此页面');
|
|
|
}
|
|
|
|
|
|
$serviceRepo = new ServiceRepository();
|
|
|
$settingsRepo = new SystemSettingsRepository();
|
|
|
$message = '';
|
|
|
$error = '';
|
|
|
|
|
|
// 处理服务起停
|
|
|
if (isset($_GET['action'])) {
|
|
|
$serviceName = $_GET['service'] ?? '';
|
|
|
$action = $_GET['action'] ?? '';
|
|
|
|
|
|
if ($serviceName === 'smtp' || $serviceName === 'pop3') {
|
|
|
if ($action === 'start') {
|
|
|
// 启动服务(实际应该通过系统服务管理,这里只是更新状态)
|
|
|
$pid = null; // 实际应该获取进程ID
|
|
|
$serviceRepo->updateStatus($serviceName, true, $pid);
|
|
|
$message = strtoupper($serviceName) . "服务已启动";
|
|
|
} elseif ($action === 'stop') {
|
|
|
// 停止服务
|
|
|
$status = $serviceRepo->getStatus($serviceName);
|
|
|
if ($status && $status['pid']) {
|
|
|
// 尝试终止进程
|
|
|
@exec("kill {$status['pid']} 2>/dev/null");
|
|
|
}
|
|
|
$serviceRepo->updateStatus($serviceName, false, null);
|
|
|
$message = strtoupper($serviceName) . "服务已停止";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取服务状态
|
|
|
$smtpStatus = $serviceRepo->getStatus('smtp');
|
|
|
$pop3Status = $serviceRepo->getStatus('pop3');
|
|
|
$smtpRunning = $serviceRepo->isRunning('smtp');
|
|
|
$pop3Running = $serviceRepo->isRunning('pop3');
|
|
|
|
|
|
// 获取端口设置
|
|
|
$smtpPort = $settingsRepo->get('smtp_port', 25);
|
|
|
$pop3Port = $settingsRepo->get('pop3_port', 110);
|
|
|
?>
|
|
|
<!DOCTYPE html>
|
|
|
<html>
|
|
|
<head>
|
|
|
<title>服务管理 - 邮件服务器</title>
|
|
|
<meta charset="UTF-8">
|
|
|
<style>
|
|
|
body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background: #f5f5f5; }
|
|
|
.header { background: #007bff; color: white; padding: 15px; margin: -20px -20px 20px -20px; }
|
|
|
.menu { background: white; padding: 10px; margin-bottom: 20px; border-radius: 5px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
|
|
|
.menu a { margin-right: 15px; text-decoration: none; color: #007bff; }
|
|
|
.container { background: white; padding: 20px; border-radius: 5px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
|
|
|
.message { background: #d4edda; color: #155724; padding: 12px; border-radius: 5px; margin-bottom: 20px; }
|
|
|
.error { background: #f8d7da; color: #721c24; padding: 12px; border-radius: 5px; margin-bottom: 20px; }
|
|
|
.service-box { border: 1px solid #ddd; padding: 20px; margin-bottom: 20px; border-radius: 5px; }
|
|
|
.service-box h3 { margin-top: 0; }
|
|
|
.status { display: inline-block; padding: 6px 12px; border-radius: 4px; font-weight: 500; margin-right: 10px; }
|
|
|
.status-running { background: #28a745; color: white; }
|
|
|
.status-stopped { background: #dc3545; color: white; }
|
|
|
.btn { padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer; text-decoration: none; display: inline-block; }
|
|
|
.btn-success { background: #28a745; color: white; }
|
|
|
.btn-danger { background: #dc3545; color: white; }
|
|
|
.info { color: #666; font-size: 14px; margin-top: 10px; }
|
|
|
.note { background: #fff3cd; border: 1px solid #ffc107; padding: 15px; border-radius: 5px; margin-top: 20px; }
|
|
|
</style>
|
|
|
</head>
|
|
|
<body>
|
|
|
<div class="header">
|
|
|
<h1>邮件服务器管理后台</h1>
|
|
|
<div>欢迎, <?php echo htmlspecialchars($_SESSION['username']); ?>
|
|
|
(<a href="logout.php" style="color: white;">退出</a>)
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="menu">
|
|
|
<a href="index.php">仪表盘</a>
|
|
|
<a href="users.php">用户管理</a>
|
|
|
<a href="emails.php">邮件管理</a>
|
|
|
<a href="broadcast.php">群发邮件</a>
|
|
|
<a href="filters.php">过滤规则</a>
|
|
|
<a href="logs.php">系统日志</a>
|
|
|
<a href="services.php">服务管理</a>
|
|
|
<a href="settings.php">系统设置</a>
|
|
|
</div>
|
|
|
|
|
|
<div class="container">
|
|
|
<h2>服务管理</h2>
|
|
|
|
|
|
<?php if ($message): ?>
|
|
|
<div class="message"><?php echo $message; ?></div>
|
|
|
<?php endif; ?>
|
|
|
|
|
|
<?php if ($error): ?>
|
|
|
<div class="error"><?php echo $error; ?></div>
|
|
|
<?php endif; ?>
|
|
|
|
|
|
<!-- SMTP服务 -->
|
|
|
<div class="service-box">
|
|
|
<h3>SMTP服务(邮件发送)</h3>
|
|
|
<p>
|
|
|
<span class="status status-<?php echo $smtpRunning ? 'running' : 'stopped'; ?>">
|
|
|
<?php echo $smtpRunning ? '运行中' : '已停止'; ?>
|
|
|
</span>
|
|
|
<?php if ($smtpRunning): ?>
|
|
|
<a href="?service=smtp&action=stop" class="btn btn-danger" onclick="return confirm('确定要停止SMTP服务吗?');">停止服务</a>
|
|
|
<?php else: ?>
|
|
|
<a href="?service=smtp&action=start" class="btn btn-success" onclick="return confirm('确定要启动SMTP服务吗?');">启动服务</a>
|
|
|
<?php endif; ?>
|
|
|
</p>
|
|
|
<div class="info">
|
|
|
<strong>端口:</strong><?php echo $smtpPort; ?><br>
|
|
|
<strong>进程ID:</strong><?php echo $smtpStatus['pid'] ?? '-'; ?><br>
|
|
|
<strong>最后启动:</strong><?php echo $smtpStatus['last_started_at'] ?? '-'; ?><br>
|
|
|
<strong>最后停止:</strong><?php echo $smtpStatus['last_stopped_at'] ?? '-'; ?>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<!-- POP3服务 -->
|
|
|
<div class="service-box">
|
|
|
<h3>POP3服务(邮件接收)</h3>
|
|
|
<p>
|
|
|
<span class="status status-<?php echo $pop3Running ? 'running' : 'stopped'; ?>">
|
|
|
<?php echo $pop3Running ? '运行中' : '已停止'; ?>
|
|
|
</span>
|
|
|
<?php if ($pop3Running): ?>
|
|
|
<a href="?service=pop3&action=stop" class="btn btn-danger" onclick="return confirm('确定要停止POP3服务吗?');">停止服务</a>
|
|
|
<?php else: ?>
|
|
|
<a href="?service=pop3&action=start" class="btn btn-success" onclick="return confirm('确定要启动POP3服务吗?');">启动服务</a>
|
|
|
<?php endif; ?>
|
|
|
</p>
|
|
|
<div class="info">
|
|
|
<strong>端口:</strong><?php echo $pop3Port; ?><br>
|
|
|
<strong>进程ID:</strong><?php echo $pop3Status['pid'] ?? '-'; ?><br>
|
|
|
<strong>最后启动:</strong><?php echo $pop3Status['last_started_at'] ?? '-'; ?><br>
|
|
|
<strong>最后停止:</strong><?php echo $pop3Status['last_stopped_at'] ?? '-'; ?>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="note">
|
|
|
<strong>注意:</strong>此页面仅用于管理服务状态。实际启动服务需要使用命令行:
|
|
|
<ul>
|
|
|
<li>SMTP服务:<code>sudo php scripts/start_smtp.php</code></li>
|
|
|
<li>POP3服务:<code>sudo php scripts/start_pop3.php</code></li>
|
|
|
</ul>
|
|
|
</div>
|
|
|
</div>
|
|
|
</body>
|
|
|
</html>
|
|
|
|