- 新增服务器控制页面,支持查看服务器状态和执行关机、重启操作 - 添加移动端适配页面,优化小屏显示效果 - 实现服务器信息展示、折叠面板、模态框等功能 - 添加 Docker 部署相关文件,支持容器化部署 - 新增测试脚本,验证 SSH 连接和命令执行功能
462 行
14 KiB
HTML
462 行
14 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>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
.container {
|
|
padding: 20px;
|
|
}
|
|
/* 在现有按钮样式后添加 */
|
|
#refresh-btn {
|
|
background-color: #2196F3; /* 蓝色主题色 */
|
|
margin: 15px 0;
|
|
}
|
|
|
|
#refresh-btn:hover {
|
|
background-color: #1976D2;
|
|
}
|
|
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-top: 20px;
|
|
}
|
|
table, th, td {
|
|
border: 1px solid #ddd;
|
|
}
|
|
th, td {
|
|
padding: 10px;
|
|
text-align: center;
|
|
}
|
|
th {
|
|
background-color: #f4f4f4;
|
|
}
|
|
button {
|
|
padding: 8px 16px;
|
|
font-size: 14px;
|
|
cursor: pointer;
|
|
}
|
|
.control-buttons {
|
|
display: flex;
|
|
justify-content: space-around;
|
|
}
|
|
.control-buttons button {
|
|
margin: 5px;
|
|
}
|
|
</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: 30%;
|
|
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">
|
|
<h1>端侧设备控制</h1>
|
|
<hr/>
|
|
<button id="refresh-btn" class="custom-btn" onclick="location.reload()">
|
|
<span class="button-text">刷新</span>
|
|
</button>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>服务器名称</th>
|
|
<th>服务器IP</th>
|
|
<th>状态</th>
|
|
<th>服务器信息</th>
|
|
<th>操作</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for server in servers %}
|
|
<tr>
|
|
<td>{{ server.name }}</td>
|
|
<td>{{ server.ip }}</td>
|
|
<td>
|
|
{% 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 %}
|
|
</td>
|
|
<!-- 在表格的服务器信息列中 -->
|
|
<td>
|
|
{% if server.status == 'running' %}
|
|
<div class="server-details">
|
|
<!-- 简化版关键指标 -->
|
|
<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" onclick="toggleDetails(this)">展开详细信息</button>
|
|
<div class="collapsed-details">
|
|
<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>
|
|
{% elif server.status == 'stopped' %}
|
|
<p style="color: red;">服务器已停止</p>
|
|
{% else %}
|
|
<p style="color: orange;">状态未知</p>
|
|
{% endif %}
|
|
</td>
|
|
<!-- 操作按钮部分 -->
|
|
<td>
|
|
<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>
|
|
</td>
|
|
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</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-details');
|
|
const details = parent.querySelector('.collapsed-details');
|
|
details.style.display = details.style.display === 'block' ? 'none' : 'block';
|
|
}
|
|
</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>
|
|
</html> |