143 lines
5.8 KiB
HTML
143 lines
5.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>System Monitor</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<style>
|
|
body { font-family: Arial, sans-serif; background: #f4f4f4; margin: 0; padding: 0; }
|
|
.container { max-width: 600px; margin: 40px auto; background: #fff; padding: 24px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1);}
|
|
h1 { text-align: center; }
|
|
.stat { display: flex; justify-content: space-between; margin: 16px 0; font-size: 1.2em; }
|
|
.label { color: #555; }
|
|
.value { font-weight: bold; }
|
|
.refresh-btn { display: block; margin: 24px auto 0; padding: 8px 24px; font-size: 1em; border: none; border-radius: 4px; background: #0078d4; color: #fff; cursor: pointer; }
|
|
.refresh-btn:hover { background: #005fa3; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>System Monitor</h1>
|
|
<div class="stat"><span class="label">CPU Usage:</span> <span class="value" id="cpu">--</span></div>
|
|
<div class="stat"><span class="label">RAM Usage:</span> <span class="value" id="ram">--</span></div>
|
|
<div class="stat"><span class="label">SSD Usage:</span> <span class="value" id="disk">--</span></div>
|
|
<div class="stat"><span class="label">Uptime:</span> <span class="value" id="uptime">--</span></div>
|
|
</div>
|
|
|
|
<div class="container" style="margin-top:24px;">
|
|
<h1>Wall Messages</h1>
|
|
<form id="addMessageForm" style="margin-bottom:16px;">
|
|
<input type="text" id="newMessage" placeholder="Type a message..." style="width:70%;padding:8px;" required>
|
|
<button type="submit" class="refresh-btn" style="display:inline-block;margin:0;">Add</button>
|
|
</form>
|
|
<ul id="messages" style="list-style:none;padding:0;"></ul>
|
|
</div>
|
|
|
|
<script>
|
|
async function fetchStats() {
|
|
try {
|
|
const [cpu, ram, disk, uptime] = await Promise.all([
|
|
fetch('/cpu').then(res => res.json()),
|
|
fetch('/ram').then(res => res.json()),
|
|
fetch('/disk').then(res => res.json()),
|
|
fetch('/uptime').then(res => res.json())
|
|
]);
|
|
document.getElementById('cpu').textContent = cpu.cpu_percent + '%';
|
|
document.getElementById('ram').textContent = ram.percent + '%';
|
|
document.getElementById('disk').textContent = disk.percent + '%';
|
|
document.getElementById('uptime').textContent = uptime.uptime_seconds + ' s';
|
|
} catch (e) {
|
|
document.getElementById('cpu').textContent = 'Error';
|
|
document.getElementById('ram').textContent = 'Error';
|
|
document.getElementById('disk').textContent = 'Error';
|
|
document.getElementById('uptime').textContent = 'Error';
|
|
}
|
|
}
|
|
|
|
// Wall Messages CRUD
|
|
async function fetchMessages() {
|
|
const res = await fetch('/wall');
|
|
const messages = await res.json();
|
|
const ul = document.getElementById('messages');
|
|
ul.innerHTML = '';
|
|
messages.forEach(msg => {
|
|
const li = document.createElement('li');
|
|
li.style.display = 'flex';
|
|
li.style.justifyContent = 'space-between';
|
|
li.style.alignItems = 'center';
|
|
li.style.padding = '8px 0';
|
|
|
|
const span = document.createElement('span');
|
|
span.textContent = msg.text;
|
|
|
|
const editBtn = document.createElement('button');
|
|
editBtn.textContent = 'Edit';
|
|
editBtn.className = 'refresh-btn';
|
|
editBtn.style.background = '#ffa500';
|
|
editBtn.style.marginRight = '8px';
|
|
editBtn.onclick = () => editMessage(msg);
|
|
|
|
const delBtn = document.createElement('button');
|
|
delBtn.textContent = 'Delete';
|
|
delBtn.className = 'refresh-btn';
|
|
delBtn.style.background = '#d40000';
|
|
delBtn.onclick = () => deleteMessage(msg.id);
|
|
|
|
const btns = document.createElement('span');
|
|
btns.appendChild(editBtn);
|
|
btns.appendChild(delBtn);
|
|
|
|
li.appendChild(span);
|
|
li.appendChild(btns);
|
|
ul.appendChild(li);
|
|
});
|
|
}
|
|
|
|
async function addMessage(text) {
|
|
await fetch('/wall', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({text})
|
|
});
|
|
fetchMessages();
|
|
}
|
|
|
|
async function deleteMessage(id) {
|
|
await fetch(`/wall/${id}`, { method: 'DELETE' });
|
|
fetchMessages();
|
|
}
|
|
|
|
function editMessage(msg) {
|
|
const newText = prompt('Edit message:', msg.text);
|
|
if (newText !== null && newText.trim() !== '') {
|
|
updateMessage(msg.id, newText.trim());
|
|
}
|
|
}
|
|
|
|
async function updateMessage(id, text) {
|
|
await fetch(`/wall/${id}`, {
|
|
method: 'PUT',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({text})
|
|
});
|
|
fetchMessages();
|
|
}
|
|
|
|
document.getElementById('addMessageForm').onsubmit = function(e) {
|
|
e.preventDefault();
|
|
const input = document.getElementById('newMessage');
|
|
const text = input.value.trim();
|
|
if (text) {
|
|
addMessage(text);
|
|
input.value = '';
|
|
}
|
|
};
|
|
|
|
window.onload = function() {
|
|
fetchStats();
|
|
setInterval(fetchStats, 5000); // Fetch every 5 seconds
|
|
fetchMessages();
|
|
};
|
|
</script>
|
|
</body>
|
|
</html> |