461 lines
22 KiB
HTML
461 lines
22 KiB
HTML
{% extends "base.html" %}
|
|
{% block title %}Server - Dune Awakening Dashboard{% endblock %}
|
|
{% block content %}
|
|
|
|
<div class="page-header">
|
|
<h1>Server Status & Control</h1>
|
|
</div>
|
|
|
|
{% if tunnel_down %}
|
|
<div class="error-banner danger"><strong>SSH Tunnel Not Detected</strong></div>
|
|
{% elif db_error %}
|
|
<div class="error-banner danger"><strong>Database Error:</strong> {{ db_error }}</div>
|
|
{% else %}
|
|
|
|
<div class="stats-grid">
|
|
<div class="stat-card">
|
|
<div class="label">Online Players</div>
|
|
<div class="value online">{{ online_count }}</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="label">Overmap Players</div>
|
|
<div class="value">{{ overmap_count }}</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="label">Active Servers</div>
|
|
<div class="value">{{ active_servers|length }}</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="label">World Partitions</div>
|
|
<div class="value">{{ partitions|length }}</div>
|
|
</div>
|
|
{% if node_metrics.cpu %}
|
|
<div class="stat-card">
|
|
<div class="label">Node CPU</div>
|
|
<div class="value" id="node-cpu">{{ node_metrics.cpu }}</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="label">Node Memory</div>
|
|
<div class="value" id="node-mem">{{ node_metrics.memory }}</div>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;margin-bottom:20px;">
|
|
<div class="card">
|
|
<div class="card-header">Players Per Map</div>
|
|
<div class="card-body">
|
|
{% if per_map %}
|
|
{% for m in per_map %}
|
|
<div class="faction-bar">
|
|
<span class="bar-label" style="font-weight:600;">{{ m.map }}</span>
|
|
<div class="bar-bg">
|
|
<div class="bar-fill" style="background:var(--primary);width:{{ (m.count / online_count * 100)|round(1) if online_count > 0 else 0 }}%;min-width:2px;"></div>
|
|
</div>
|
|
<span class="bar-count">{{ m.count }}</span>
|
|
</div>
|
|
{% endfor %}
|
|
{% else %}
|
|
<div class="empty">No data</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">Online Players</div>
|
|
<div class="card-body">
|
|
{% if online_players %}
|
|
<table style="width:100%;">
|
|
{% for p in online_players %}
|
|
<tr>
|
|
<td><a href="/players/{{ p.character_name }}" style="font-weight:500;">{{ p.character_name or 'Unknown' }}</a></td>
|
|
<td>{{ p.map or 'N/A' }}</td>
|
|
<td><span class="badge badge-{{ p.online_status.lower() }}">{{ p.online_status }}</span></td>
|
|
</tr>
|
|
{% endfor %}
|
|
</table>
|
|
{% else %}
|
|
<div class="empty">No players online</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">Active Server IDs</div>
|
|
<div class="card-body">
|
|
{% if active_servers %}
|
|
<ul style="list-style:none;">
|
|
{% for s in active_servers %}
|
|
<li style="padding:4px 0;font-family:monospace;font-size:12px;">
|
|
<span style="font-weight:600;">{{ s.server_id }}</span>
|
|
{% if s.map %} — <span style="color:var(--primary);">{{ s.map }}</span>{% endif %}
|
|
</li>
|
|
{% endfor %}
|
|
</ul>
|
|
{% else %}
|
|
<div class="empty">No active servers</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">World Partitions</div>
|
|
<div class="table-wrap">
|
|
<table>
|
|
<thead>
|
|
<tr><th>Partition ID</th><th>Server ID</th><th>Map</th><th>Dimension</th><th>Blocked</th><th>Label</th><th>Actions</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for p in partitions %}
|
|
<tr>
|
|
<td>{{ p.partition_id }}</td>
|
|
<td style="font-family:monospace;font-size:11px;">{{ p.server_id }}</td>
|
|
<td>{{ p.map }}</td>
|
|
<td>{{ p.dimension_index }}</td>
|
|
<td>{{ 'Yes' if p.blocked else 'No' }}</td>
|
|
<td>{{ p.label or '' }}</td>
|
|
<td>{% if p.deployment %}<button class="partition-btn" data-deploy="{{ p.deployment }}" data-map="{{ p.map }}" style="padding:4px 12px;background:#e67e22;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:12px;">Restart</button>{% else %}—{% endif %}</td>
|
|
</tr>
|
|
{% else %}
|
|
<tr><td colspan="7" class="empty">No partitions found</td></tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<span>Kubernetes Deployments</span>
|
|
{% if deploys_ok %}
|
|
<span style="font-size:12px;color:var(--success);">SSH connected</span>
|
|
{% else %}
|
|
<span style="font-size:12px;color:var(--danger);">SSH unavailable (key not loaded or VM unreachable)</span>
|
|
{% endif %}
|
|
</div>
|
|
<div class="card-body">
|
|
{% if deploys_ok %}
|
|
<div class="table-wrap">
|
|
<table>
|
|
<thead><tr><th>Deployment</th><th>Actions</th></tr></thead>
|
|
<tbody>
|
|
{% for d in deployments %}
|
|
<tr>
|
|
<td style="font-family:monospace;font-size:13px;">{{ d.replace('deployment.apps/','') }}</td>
|
|
<td>
|
|
<button class="btn-action" data-deploy="{{ d }}" data-action="restart" style="padding:4px 12px;background:#e67e22;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:12px;">Restart</button>
|
|
<button class="btn-action" data-deploy="{{ d }}" data-action="status" style="padding:4px 12px;background:#3498db;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:12px;">Status</button>
|
|
<button class="btn-action" data-deploy="{{ d }}" data-action="scale_0" style="padding:4px 12px;background:#e74c3c;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:12px;">Scale to 0</button>
|
|
<button class="btn-action" data-deploy="{{ d }}" data-action="scale_1" style="padding:4px 12px;background:#27ae60;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:12px;">Scale to 1</button>
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
{% else %}
|
|
<p style="color:var(--text-light);font-size:14px;">
|
|
To enable server control, ensure the SSH key is available at
|
|
<code>$env:TEMP\dune-awakening-server-sshKey</code> and the VM is reachable.
|
|
</p>
|
|
{% if ssh_error %}
|
|
<pre style="background:#1a1a2e;color:#e74c3c;padding:12px;border-radius:6px;font-size:12px;margin-top:8px;">{{ ssh_error }}</pre>
|
|
{% endif %}
|
|
{% endif %}
|
|
<div id="action-output" style="margin-top:16px;display:none;">
|
|
<div class="card-header">Command Output</div>
|
|
<pre id="action-output-text" style="background:#1a1a2e;color:#e0d5c7;padding:16px;border-radius:8px;font-size:12px;overflow-x:auto;white-space:pre-wrap;margin-top:8px;"></pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<span>Battlegroup Control</span>
|
|
<span id="bg-status-indicator" style="font-size:12px;color:var(--text-muted);">Click "Refresh Status" to load</span>
|
|
</div>
|
|
<div class="card-body">
|
|
<div style="display:flex;gap:8px;margin-bottom:16px;flex-wrap:wrap;">
|
|
<button id="bg-btn-start" class="bg-btn" style="padding:8px 20px;background:#27ae60;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;font-weight:600;">Start</button>
|
|
<button id="bg-btn-stop" class="bg-btn" style="padding:8px 20px;background:#e74c3c;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;font-weight:600;">Stop</button>
|
|
<button id="bg-btn-restart" class="bg-btn" style="padding:8px 20px;background:#e67e22;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;font-weight:600;">Restart</button>
|
|
<button id="bg-btn-update" class="bg-btn" style="padding:8px 20px;background:#9b59b6;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;font-weight:600;">Update</button>
|
|
<button id="bg-btn-refresh" style="padding:8px 20px;background:var(--primary);color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;">Refresh Status</button>
|
|
</div>
|
|
<div id="bg-status-output">
|
|
<pre id="bg-status-text" style="background:#1a1a2e;color:#e0d5c7;padding:16px;border-radius:8px;font-size:12px;overflow-x:auto;white-space:pre-wrap;min-height:100px;">Click "Refresh Status" to load battlegroup status...</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<span>Admin Management</span>
|
|
<span style="font-size:12px;color:var(--text-muted);">Coming Soon</span>
|
|
</div>
|
|
<div class="card-body">
|
|
<p style="font-size:14px;color:var(--text-light);">
|
|
Server admin assignment and player permission management interface.
|
|
Requires integration with game server authentication system.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">Pod Status</div>
|
|
<div class="card-body">
|
|
<button id="refresh-pods" style="padding:8px 16px;background:var(--primary);color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;">Refresh Pods</button>
|
|
<div id="pods-output" style="margin-top:12px;">
|
|
<pre id="pods-text" style="background:#1a1a2e;color:#e0d5c7;padding:16px;border-radius:8px;font-size:12px;overflow-x:auto;white-space:pre-wrap;">Click refresh to load pod status...</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<span>Firewall Security</span>
|
|
<span id="fw-status-indicator" style="font-size:12px;color:var(--text-muted);">Loading...</span>
|
|
</div>
|
|
<div class="card-body">
|
|
<div style="margin-bottom:12px;padding:12px;background:#1a1a2e;border-radius:6px;font-size:13px;line-height:1.6;">
|
|
<strong style="color:#e74c3c;">Security Recommendation:</strong> The following services are exposed to the internet without authentication.
|
|
Block them so only localhost (the dashboard via SSH tunnel) can reach them.
|
|
</div>
|
|
<div id="fw-ports-list" style="margin-bottom:16px;"></div>
|
|
<button id="fw-btn-refresh" style="padding:8px 20px;background:var(--primary);color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;">Refresh Status</button>
|
|
<div id="fw-action-output" style="margin-top:12px;display:none;">
|
|
<pre id="fw-action-text" style="background:#1a1a2e;color:#e0d5c7;padding:12px;border-radius:8px;font-size:12px;overflow-x:auto;white-space:pre-wrap;"></pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{% endif %}
|
|
{% endblock %}
|
|
|
|
{% block scripts %}
|
|
<script>
|
|
// Auto-refresh node metrics every 5 seconds
|
|
setInterval(async function() {
|
|
try {
|
|
const resp = await fetch('/server/metrics');
|
|
const data = await resp.json();
|
|
if (data.cpu) {
|
|
document.getElementById('node-cpu').textContent = data.cpu;
|
|
document.getElementById('node-mem').textContent = data.memory;
|
|
}
|
|
} catch (e) {}
|
|
}, 5000);
|
|
|
|
document.querySelectorAll('.btn-action').forEach(btn => {
|
|
btn.addEventListener('click', async function() {
|
|
const deploy = this.dataset.deploy;
|
|
const action = this.dataset.action;
|
|
const label = this.textContent.trim();
|
|
if (action === 'restart' || action === 'scale_0') {
|
|
const confirmMsg = action === 'restart'
|
|
? `Restart deployment "${deploy}"?`
|
|
: `Scale deployment "${deploy}" to 0 replicas (shutdown)?`;
|
|
if (!confirm(confirmMsg)) return;
|
|
if (!confirm('Are you sure? This will affect live players.')) return;
|
|
}
|
|
this.disabled = true;
|
|
this.textContent = 'Working...';
|
|
const output = document.getElementById('action-output');
|
|
const outputText = document.getElementById('action-output-text');
|
|
output.style.display = 'block';
|
|
outputText.textContent = `Running ${action} on ${deploy}...`;
|
|
try {
|
|
const form = new FormData();
|
|
form.append('deployment', deploy);
|
|
form.append('action', action);
|
|
const resp = await fetch('/server/action', { method: 'POST', body: form });
|
|
const data = await resp.json();
|
|
outputText.textContent = data.output || (data.success ? 'Done' : 'Failed');
|
|
} catch (e) {
|
|
outputText.textContent = 'Error: ' + e.message;
|
|
}
|
|
this.disabled = false;
|
|
this.textContent = label;
|
|
});
|
|
});
|
|
|
|
document.querySelectorAll('.partition-btn').forEach(btn => {
|
|
btn.addEventListener('click', async function() {
|
|
const deploy = this.dataset.deploy;
|
|
const map = this.dataset.map;
|
|
const label = this.textContent.trim();
|
|
if (!confirm(`Restart "${map}" partition (${deploy})?`)) return;
|
|
if (!confirm('Are you sure? Players on this map will be disconnected.')) return;
|
|
this.disabled = true;
|
|
this.textContent = 'Restarting...';
|
|
const output = document.getElementById('action-output');
|
|
const outputText = document.getElementById('action-output-text');
|
|
output.style.display = 'block';
|
|
outputText.textContent = `Restarting ${deploy}...`;
|
|
try {
|
|
const form = new FormData();
|
|
form.append('deployment', deploy);
|
|
form.append('action', 'restart');
|
|
const resp = await fetch('/server/action', { method: 'POST', body: form });
|
|
const data = await resp.json();
|
|
outputText.textContent = data.output || (data.success ? 'Restart initiated' : 'Failed');
|
|
} catch (e) {
|
|
outputText.textContent = 'Error: ' + e.message;
|
|
}
|
|
this.disabled = false;
|
|
this.textContent = label;
|
|
});
|
|
});
|
|
|
|
document.getElementById('refresh-pods')?.addEventListener('click', async function() {
|
|
this.disabled = true;
|
|
this.textContent = 'Loading...';
|
|
const pre = document.getElementById('pods-text');
|
|
pre.textContent = 'Fetching pod list...';
|
|
try {
|
|
const resp = await fetch('/server/pods');
|
|
const data = await resp.json();
|
|
pre.textContent = data.output || (data.success ? 'No pods found' : 'Failed: ' + data.output);
|
|
} catch (e) {
|
|
pre.textContent = 'Error: ' + e.message;
|
|
}
|
|
this.disabled = false;
|
|
this.textContent = 'Refresh Pods';
|
|
});
|
|
|
|
async function bgAction(action, btn) {
|
|
const confirmMsgs = {
|
|
'stop': 'Stop the battlegroup? This will disconnect all players.',
|
|
'restart': 'Restart the battlegroup? This will disconnect all players.',
|
|
'update': 'Update the battlegroup? This will download new images and restart. This may take several minutes.'
|
|
};
|
|
if (confirmMsgs[action] && !confirm(confirmMsgs[action])) return;
|
|
if ((action === 'stop' || action === 'restart') && !confirm('Are you sure? This will affect live players.')) return;
|
|
|
|
btn.disabled = true;
|
|
const originalText = btn.textContent;
|
|
btn.textContent = action === 'update' ? 'Updating (may take several minutes)...' : 'Working...';
|
|
const pre = document.getElementById('bg-status-text');
|
|
pre.textContent = `Running ${action}...`;
|
|
|
|
try {
|
|
const url = action === 'update' ? '/server/battlegroup/update' : '/server/battlegroup/action';
|
|
const form = new FormData();
|
|
form.append('action', action);
|
|
const resp = await fetch(url, { method: 'POST', body: form });
|
|
const data = await resp.json();
|
|
pre.textContent = data.output || (data.success ? `${action} completed successfully` : `Failed: ${data.output}`);
|
|
} catch (e) {
|
|
pre.textContent = 'Error: ' + e.message;
|
|
}
|
|
btn.disabled = false;
|
|
btn.textContent = originalText;
|
|
}
|
|
|
|
async function bgRefreshStatus() {
|
|
const btn = document.getElementById('bg-btn-refresh');
|
|
const pre = document.getElementById('bg-status-text');
|
|
const indicator = document.getElementById('bg-status-indicator');
|
|
btn.disabled = true;
|
|
btn.textContent = 'Loading...';
|
|
pre.textContent = 'Fetching battlegroup status...';
|
|
try {
|
|
const resp = await fetch('/server/battlegroup/status');
|
|
const data = await resp.json();
|
|
pre.textContent = data.output || (data.success ? 'No status available' : 'Failed: ' + data.output);
|
|
indicator.textContent = data.success ? 'Status loaded' : 'Failed to load';
|
|
indicator.style.color = data.success ? 'var(--success)' : 'var(--danger)';
|
|
} catch (e) {
|
|
pre.textContent = 'Error: ' + e.message;
|
|
indicator.textContent = 'Error';
|
|
indicator.style.color = 'var(--danger)';
|
|
}
|
|
btn.disabled = false;
|
|
btn.textContent = 'Refresh Status';
|
|
}
|
|
|
|
document.getElementById('bg-btn-start')?.addEventListener('click', function() { bgAction('start', this); });
|
|
document.getElementById('bg-btn-stop')?.addEventListener('click', function() { bgAction('stop', this); });
|
|
document.getElementById('bg-btn-restart')?.addEventListener('click', function() { bgAction('restart', this); });
|
|
document.getElementById('bg-btn-update')?.addEventListener('click', function() { bgAction('update', this); });
|
|
document.getElementById('bg-btn-refresh')?.addEventListener('click', bgRefreshStatus);
|
|
|
|
// Firewall Security
|
|
async function loadFwStatus() {
|
|
const indicator = document.getElementById('fw-status-indicator');
|
|
const list = document.getElementById('fw-ports-list');
|
|
const btn = document.getElementById('fw-btn-refresh');
|
|
btn.disabled = true;
|
|
btn.textContent = 'Loading...';
|
|
indicator.textContent = 'Checking...';
|
|
|
|
try {
|
|
const resp = await fetch('/server/firewall');
|
|
const data = await resp.json();
|
|
if (!data.success) {
|
|
indicator.textContent = 'SSH unavailable';
|
|
indicator.style.color = 'var(--danger)';
|
|
list.innerHTML = '<p style="color:var(--text-light);font-size:14px;">SSH tunnel is required for firewall control.</p>';
|
|
btn.disabled = false;
|
|
btn.textContent = 'Refresh Status';
|
|
return;
|
|
}
|
|
|
|
const allPorts = [...(data.blocked || []), ...(data.available || [])];
|
|
let html = '<table style="width:100%;font-size:13px;"><thead><tr><th>Service</th><th>Port</th><th>Status</th><th>Action</th></tr></thead><tbody>';
|
|
for (const p of allPorts) {
|
|
const isBlocked = (data.blocked || []).some(b => b.port === p.port);
|
|
const rules = Object.values(data.iptables_rules || {}).filter(r => r.includes('dpt:' + p.port));
|
|
const statusText = isBlocked ? '<span style="color:#4ade80;font-weight:600;">Blocked</span>' : '<span style="color:#e74c3c;font-weight:600;">Open</span>';
|
|
const actionBtn = isBlocked
|
|
? `<button class="fw-btn" data-port="${p.port}" data-action="unblock" style="padding:4px 12px;background:#e74c3c;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:12px;">Unblock</button>`
|
|
: `<button class="fw-btn" data-port="${p.port}" data-action="block" style="padding:4px 12px;background:#27ae60;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:12px;">Block</button>`;
|
|
html += `<tr><td style="padding:6px 0;">${p.name}</td><td style="font-family:monospace;">${p.port}</td><td>${statusText}</td><td>${actionBtn}</td></tr>`;
|
|
}
|
|
html += '</tbody></table>';
|
|
list.innerHTML = html;
|
|
indicator.textContent = 'Status loaded';
|
|
indicator.style.color = 'var(--success)';
|
|
|
|
document.querySelectorAll('.fw-btn').forEach(btn => {
|
|
btn.addEventListener('click', async function() {
|
|
const port = this.dataset.port;
|
|
const action = this.dataset.action;
|
|
if (!confirm((action === 'block' ? 'Block' : 'Unblock') + ' port ' + port + ' from external access?')) return;
|
|
this.disabled = true;
|
|
this.textContent = 'Working...';
|
|
|
|
const output = document.getElementById('fw-action-output');
|
|
const outputText = document.getElementById('fw-action-text');
|
|
output.style.display = 'block';
|
|
outputText.textContent = (action === 'block' ? 'Blocking' : 'Unblocking') + ' port ' + port + '...';
|
|
|
|
try {
|
|
const form = new FormData();
|
|
form.append('port', port);
|
|
const resp = await fetch('/server/firewall/' + action, { method: 'POST', body: form });
|
|
const result = await resp.json();
|
|
outputText.textContent = result.output || (result.success ? 'Done' : 'Failed');
|
|
await loadFwStatus();
|
|
} catch (e) {
|
|
outputText.textContent = 'Error: ' + e.message;
|
|
}
|
|
});
|
|
});
|
|
} catch (e) {
|
|
indicator.textContent = 'Error loading status';
|
|
indicator.style.color = 'var(--danger)';
|
|
list.innerHTML = '<p style="color:var(--danger);">Error: ' + e.message + '</p>';
|
|
}
|
|
|
|
btn.disabled = false;
|
|
btn.textContent = 'Refresh Status';
|
|
}
|
|
|
|
document.getElementById('fw-btn-refresh')?.addEventListener('click', loadFwStatus);
|
|
loadFwStatus();
|
|
</script>
|
|
{% endblock %}
|