- 新增服务器控制页面,支持查看服务器状态和执行关机、重启操作 - 添加移动端适配页面,优化小屏显示效果 - 实现服务器信息展示、折叠面板、模态框等功能 - 添加 Docker 部署相关文件,支持容器化部署 - 新增测试脚本,验证 SSH 连接和命令执行功能
495 行
15 KiB
HTML
495 行
15 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Server Control</title>
|
|
<!-- 在 head 引入字体图标 -->
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
|
|
|
|
|
<style>
|
|
/* 移动端媒体查询 */
|
|
@media (max-width: 768px) {
|
|
/* 顶部固定栏 */
|
|
.mobile-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 15px;
|
|
background: white;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 1000;
|
|
}
|
|
|
|
/* 刷新按钮 */
|
|
.mobile-refresh-btn {
|
|
padding: 8px 16px;
|
|
background: #2196F3;
|
|
}
|
|
|
|
/* 服务器卡片布局 */
|
|
.server-card {
|
|
background: white;
|
|
margin: 10px;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
/* 状态标签 */
|
|
.status-badge {
|
|
padding: 5px 10px;
|
|
border-radius: 16px;
|
|
font-size: 12px;
|
|
}
|
|
.running { background: #e8f5e9; color: #155724; }
|
|
.stopped { background: #f8d7da; color: #721c24; }
|
|
|
|
/* 操作按钮 */
|
|
.mobile-controls {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
margin-top: 15px;
|
|
}
|
|
.custom-btn {
|
|
width: 100%;
|
|
}
|
|
|
|
/* 折叠面板 */
|
|
.mobile-toggle {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
width: 100%;
|
|
padding: 8px 12px;
|
|
background: #f1f1f1;
|
|
border: none;
|
|
border-radius: 4px;
|
|
}
|
|
.mobile-collapsed {
|
|
padding: 15px;
|
|
background: #f8f9fa;
|
|
}
|
|
}
|
|
|
|
/* 全局优化 */
|
|
.metric-box {
|
|
flex: 1 1 30%; /* 等分显示 */
|
|
}
|
|
|
|
.custom-btn {
|
|
touch-action: manipulation;
|
|
padding: 12px;
|
|
font-size: 16px;
|
|
}
|
|
|
|
|
|
</style>
|
|
|
|
<!-- 信息info -->
|
|
<style>
|
|
.quick-view {
|
|
display: flex;
|
|
justify-content: space-around;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.metric-box {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
width: 100px;
|
|
padding: 10px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
margin: 0 5px;
|
|
}
|
|
|
|
.metric-label {
|
|
font-size: 12px;
|
|
color: #666;
|
|
}
|
|
|
|
.metric-value {
|
|
font-size: 16px;
|
|
font-weight: bold;
|
|
margin-top: 5px;
|
|
}
|
|
|
|
.metric-value.green {
|
|
color: #4CAF50;
|
|
}
|
|
|
|
.metric-value.red {
|
|
color: #f44336;
|
|
}
|
|
|
|
.toggle-details {
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
border: none;
|
|
padding: 5px 10px;
|
|
cursor: pointer;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.collapsed-details {
|
|
display: none;
|
|
padding: 10px;
|
|
border-top: 1px solid #ddd;
|
|
}
|
|
|
|
.resource-row {
|
|
display: flex;
|
|
gap: 10px;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.resource-card {
|
|
flex: 1;
|
|
padding: 10px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
.card-title {
|
|
font-weight: bold;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.progress-bar {
|
|
height: 10px;
|
|
background-color: #f1f1f1;
|
|
border-radius: 3px;
|
|
width: 0;
|
|
}
|
|
|
|
.progress-text {
|
|
margin-top: 5px;
|
|
font-size: 12px;
|
|
}
|
|
|
|
.metric-table.small {
|
|
font-size: 12px;
|
|
}
|
|
|
|
</style>
|
|
<!-- 弹框 -->
|
|
<style>
|
|
/* 模态框样式 */
|
|
.modal {
|
|
display: none;
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: rgba(0,0,0,0.5);
|
|
z-index: 9999;
|
|
}
|
|
|
|
.modal-content {
|
|
background-color: white;
|
|
margin: 10% auto;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
width: 80%;
|
|
text-align: center;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
.modal-title {
|
|
font-size: 1.2em;
|
|
margin-bottom: 15px;
|
|
color: #2196F3;
|
|
}
|
|
|
|
.modal-message {
|
|
font-size: 1em;
|
|
margin-bottom: 25px;
|
|
color: #333;
|
|
}
|
|
|
|
.modal-buttons .btn {
|
|
padding: 10px 25px;
|
|
font-size: 14px;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
margin: 0 10px;
|
|
}
|
|
|
|
.modal-buttons .confirm-btn {
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
}
|
|
|
|
.modal-buttons .cancel-btn {
|
|
background-color: #f44336;
|
|
color: white;
|
|
}
|
|
|
|
.close {
|
|
float: right;
|
|
font-size: 20px;
|
|
cursor: pointer;
|
|
transition: color 0.3s;
|
|
}
|
|
|
|
.close:hover {
|
|
color: #2196F3;
|
|
}
|
|
|
|
/* 按钮样式优化 */
|
|
.custom-btn {
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
border: none;
|
|
padding: 8px 16px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
transition: background-color 0.3s;
|
|
}
|
|
|
|
.custom-btn:hover {
|
|
background-color: #45a049;
|
|
}
|
|
|
|
/* 不同操作的按钮颜色 */
|
|
[data-action="shutdown"] {
|
|
background-color: #f44336;
|
|
}
|
|
|
|
[data-action="shutdown"]:hover {
|
|
background-color: #d32f2f;
|
|
}
|
|
|
|
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="container">
|
|
<header class="mobile-header">
|
|
<h1>端侧设备控制</h1>
|
|
<button id="refresh-btn" class="mobile-refresh-btn">
|
|
<span class="button-text">刷新</span>
|
|
</button>
|
|
</header>
|
|
|
|
<div class="server-list">
|
|
{% for server in servers %}
|
|
<div class="server-card">
|
|
<div class="server-header">
|
|
<h2>{{ server.name }}</h2>
|
|
<div class="status-badge {{ server.status }}">
|
|
{% if server.status == 'running' %}
|
|
<span style="color: green;">运行中</span>
|
|
{% elif server.status == 'stopped' %}
|
|
<span style="color: red;">已停止</span>
|
|
{% else %}
|
|
<span style="color: orange;">未知状态</span>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
{% if server.status == 'running' %}
|
|
<div class="server-info">
|
|
<!-- 简化版关键指标 -->
|
|
<div class="quick-view">
|
|
<div class="metric-box">
|
|
<div class="metric-label">CPU 空闲</div>
|
|
<div class="metric-value {{ 'green' if server.info.cpu.id|float > 90 else 'yellow' }}">
|
|
{{ server.info.cpu.id }}%
|
|
</div>
|
|
</div>
|
|
<div class="metric-box">
|
|
<div class="metric-label">内存使用</div>
|
|
<div class="metric-value {{ 'red' if server.info.memory.used|float / server.info.memory.total|float > 0.8 }}">
|
|
{{ (server.info.memory.used|float / server.info.memory.total|float * 100)|round(1) }}%
|
|
</div>
|
|
</div>
|
|
<div class="metric-box">
|
|
<div class="metric-label">负载</div>
|
|
<div class="metric-value">
|
|
{{ server.info.load_avg[0] }}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 折叠面板 -->
|
|
<button class="toggle-details mobile-toggle" onclick="toggleDetails(this)">
|
|
<span>展开详细信息</span>
|
|
<i class="fas fa-chevron-down"></i>
|
|
</button>
|
|
<div class="collapsed-details mobile-collapsed">
|
|
<h4>系统信息</h4>
|
|
<div class="info-row">
|
|
<div class="info-item">
|
|
<span class="label">系统时间:</span>
|
|
<span class="value">{{ server.info.system_time }}</span>
|
|
</div>
|
|
<div class="info-item">
|
|
<span class="label">运行时间:</span>
|
|
<span class="value">{{ server.info.uptime }}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<h4>任务状态</h4>
|
|
<table class="metric-table small">
|
|
<tr><td>总任务数:</td><td>{{ server.info.tasks.total }}</td></tr>
|
|
<tr><td>运行中:</td><td>{{ server.info.tasks.running }}</td></tr>
|
|
<tr><td>休眠:</td><td>{{ server.info.tasks.sleeping }}</td></tr>
|
|
</table>
|
|
|
|
<h4>资源详情</h4>
|
|
<div class="resource-row">
|
|
<div class="resource-card">
|
|
<div class="card-title">CPU</div>
|
|
<div class="card-content">
|
|
<div class="progress-bar" style="width: {{ server.info.cpu.id }}%; background-color: #4CAF50;"></div>
|
|
<div class="progress-text">{{ server.info.cpu.id }}% 空闲</div>
|
|
</div>
|
|
</div>
|
|
<div class="resource-card">
|
|
<div class="card-title">内存</div>
|
|
<div class="card-content">
|
|
<div class="progress-bar" style="width: {{ (server.info.memory.used|float / server.info.memory.total|float)*100 }}%; background-color: #f44336;"></div>
|
|
<div class="progress-text">{{ (server.info.memory.used|float / 1024)|round(1) }}GB / {{ (server.info.memory.total|float / 1024)|round(1) }}GB</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
<div class="control-buttons mobile-controls">
|
|
<div class="control-buttons">
|
|
<!-- 每个服务器的按钮组包裹在表单内 -->
|
|
<form action="/control" method="POST">
|
|
<input type="hidden" name="server_ip" value="{{ server.ip }}">
|
|
<!-- 关机按钮 -->
|
|
<button class="custom-btn" type="button" data-action="shutdown">
|
|
<span class="button-text">关机</span>
|
|
</button>
|
|
<!-- 重启按钮 -->
|
|
<button class="custom-btn" type="button" data-action="reboot">
|
|
<span class="button-text">重启</span>
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
<!-- 在 body 结尾处添加模态框容器 -->
|
|
<div id="customModal" class="modal">
|
|
<div class="modal-content">
|
|
<span class="close">×</span>
|
|
<h3 class="modal-title"></h3>
|
|
<p class="modal-message"></p>
|
|
<div class="modal-buttons">
|
|
<button class="btn confirm-btn">确定</button>
|
|
<button class="btn cancel-btn">取消</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// 优化折叠动画
|
|
function toggleDetails(button) {
|
|
const parent = button.closest('.server-card');
|
|
const details = parent.querySelector('.collapsed-details');
|
|
details.style.display = details.style.display === 'block' ? 'none' : 'block';
|
|
button.querySelector('i').classList.toggle('fa-chevron-up');
|
|
}
|
|
|
|
// 防止频繁刷新
|
|
let refreshTimer;
|
|
document.getElementById('refresh-btn').addEventListener('click', () => {
|
|
clearTimeout(refreshTimer);
|
|
refreshTimer = setTimeout(location.reload, 500);
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
<script>
|
|
// 获取模态框元素
|
|
const modal = document.getElementById('customModal');
|
|
const modalTitle = document.querySelector('.modal-title');
|
|
const modalMessage = document.querySelector('.modal-message');
|
|
const confirmBtn = document.querySelector('.confirm-btn');
|
|
const cancelBtn = document.querySelector('.cancel-btn');
|
|
const closeBtn = document.querySelector('.close');
|
|
|
|
// 显示模态框函数
|
|
function showModal(title, message, onConfirm, onCancel) {
|
|
modalTitle.textContent = title;
|
|
modalMessage.textContent = message;
|
|
modal.style.display = 'block';
|
|
|
|
// 绑定事件
|
|
confirmBtn.onclick = () => {
|
|
modal.style.display = 'none';
|
|
onConfirm();
|
|
};
|
|
cancelBtn.onclick = () => {
|
|
modal.style.display = 'none';
|
|
onCancel();
|
|
};
|
|
closeBtn.onclick = () => {
|
|
modal.style.display = 'none';
|
|
onCancel();
|
|
};
|
|
|
|
// 点击背景关闭
|
|
window.onclick = (event) => {
|
|
if (event.target == modal) {
|
|
modal.style.display = 'none';
|
|
onCancel();
|
|
}
|
|
};
|
|
}
|
|
|
|
// 重写按钮点击事件
|
|
document.querySelectorAll('.control-buttons button').forEach(btn => {
|
|
btn.onclick = (e) => {
|
|
e.preventDefault();
|
|
const form = e.target.closest('form');
|
|
const action = form.action;
|
|
const formData = new FormData(form);
|
|
formData.set('action',btn.dataset.action)
|
|
console.log(formData);
|
|
|
|
showModal(
|
|
"操作确认",
|
|
e.target.textContent + "操作不可逆,确认继续?",
|
|
() => {
|
|
// 提交表单
|
|
fetch(action, {
|
|
method: 'POST',
|
|
body: new URLSearchParams(formData),
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
}
|
|
}).then(response => {
|
|
if (response.ok) {
|
|
location.reload(); // 刷新页面
|
|
} else {
|
|
alert("操作失败");
|
|
}
|
|
});
|
|
},
|
|
() => {} // 取消操作
|
|
);
|
|
return false;
|
|
};
|
|
});
|
|
</script>
|
|
|
|
|
|
</body> |