1629 lines
85 KiB
HTML
1629 lines
85 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 class="card chart-panel">
|
||
<div class="card-header">Node Resources <span class="chart-hint">5-minute history, updated every 5s</span></div>
|
||
<div class="card-body chart-panel-body">
|
||
<div class="chart-box">
|
||
<canvas id="chart-cpu" height="120"></canvas>
|
||
</div>
|
||
<div class="chart-box">
|
||
<canvas id="chart-mem" height="120"></canvas>
|
||
</div>
|
||
</div>
|
||
</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 style="display:grid;grid-template-columns:1fr 1fr;gap:20px;margin-bottom:20px;">
|
||
<div class="card">
|
||
<div class="card-header">
|
||
<span>Custom Notification</span>
|
||
<span id="bc-status" style="font-size:12px;color:var(--text-muted);"></span>
|
||
</div>
|
||
<div class="card-body">
|
||
<div style="margin-bottom:12px;padding:12px;background:var(--bg);border-radius:6px;font-size:13px;line-height:1.6;">
|
||
Send a custom in-game broadcast to all connected players right now.
|
||
Uses the confirmed In-Game Broadcast (RabbitMQ <code>heartbeats</code> exchange).
|
||
</div>
|
||
<div style="margin-bottom:12px;">
|
||
<label style="display:block;margin-bottom:4px;font-size:13px;">Title</label>
|
||
<input type="text" id="bc-title" value="Server Notice"
|
||
style="width:100%;padding:8px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;">
|
||
</div>
|
||
<div style="margin-bottom:12px;">
|
||
<label style="display:block;margin-bottom:4px;font-size:13px;">Message</label>
|
||
<textarea id="bc-message" rows="3"
|
||
style="width:100%;padding:8px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;resize:vertical;"></textarea>
|
||
</div>
|
||
<div style="display:flex;gap:12px;align-items:flex-end;flex-wrap:wrap;">
|
||
<label style="font-size:13px;">Duration (seconds, 5–300):
|
||
<input type="number" id="bc-duration" value="30" min="5" max="300"
|
||
style="display:block;width:120px;margin-top:4px;padding:8px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;">
|
||
</label>
|
||
<button id="bc-send-btn" style="padding:10px 24px;background:var(--accent);color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:14px;">Send Broadcast</button>
|
||
<span id="bc-msg" style="font-size:12px;color:var(--text-muted);"></span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<div class="card-header">
|
||
<span>Scheduled Notifications</span>
|
||
<span id="bn-indicator" style="font-size:12px;color:var(--text-muted);">Loading...</span>
|
||
</div>
|
||
<div class="card-body">
|
||
<div style="margin-bottom:12px;padding:12px;background:var(--bg);border-radius:6px;font-size:13px;line-height:1.6;">
|
||
Schedule a custom message to display in-game at specific dates, times and intervals.
|
||
One-shot entries fire once, then switch off automatically (settings are kept).
|
||
</div>
|
||
<div id="bn-list" style="margin-bottom:16px;font-size:13px;"></div>
|
||
<hr style="border-color:var(--border);margin:12px 0;">
|
||
<h4 id="bn-form-title" style="margin:0 0 8px;font-size:14px;">New scheduled notification</h4>
|
||
<input type="hidden" id="bn-id" value="">
|
||
<div style="margin-bottom:8px;">
|
||
<label style="display:block;margin-bottom:4px;font-size:13px;">Title</label>
|
||
<input type="text" id="bn-title" value="Server Notice"
|
||
style="width:100%;padding:8px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;">
|
||
</div>
|
||
<div style="margin-bottom:8px;">
|
||
<label style="display:block;margin-bottom:4px;font-size:13px;">Message</label>
|
||
<textarea id="bn-message" rows="2"
|
||
style="width:100%;padding:8px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;resize:vertical;"></textarea>
|
||
</div>
|
||
<div style="display:flex;gap:12px;align-items:center;flex-wrap:wrap;margin-bottom:12px;">
|
||
<label style="font-size:13px;">Duration (5–300s):
|
||
<input type="number" id="bn-duration" value="30" min="5" max="300"
|
||
style="width:90px;padding:6px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;">
|
||
</label>
|
||
<label style="display:flex;align-items:center;gap:8px;font-size:13px;cursor:pointer;">
|
||
<input type="checkbox" id="bn-enabled" checked style="width:16px;height:16px;"> Enabled
|
||
</label>
|
||
<label style="font-size:13px;">Repeats:
|
||
<select id="bn-mode" style="padding:6px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);">
|
||
<option value="daily">Daily</option>
|
||
<option value="weekly">Weekly</option>
|
||
<option value="monthly">Monthly</option>
|
||
<option value="once">One-shot</option>
|
||
</select>
|
||
</label>
|
||
</div>
|
||
<div id="bn-sched-daily" style="margin-bottom:12px;">
|
||
<div style="font-size:13px;margin-bottom:6px;">Times - pick a time, then Add:</div>
|
||
<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:8px;">
|
||
<input type="time" id="bn-daily-time-pick" value="12:00" style="padding:6px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;color-scheme:dark;">
|
||
<button id="bn-daily-add" style="padding:6px 14px;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;cursor:pointer;font-size:13px;">Add time</button>
|
||
</div>
|
||
<div id="bn-daily-chips" style="display:flex;gap:6px;flex-wrap:wrap;"></div>
|
||
</div>
|
||
<div id="bn-sched-weekly" style="margin-bottom:12px;display:none;">
|
||
<div style="font-size:13px;margin-bottom:6px;">Days:</div>
|
||
<div style="display:flex;gap:10px;flex-wrap:wrap;font-size:13px;margin-bottom:8px;">
|
||
<label><input type="checkbox" class="bn-weekday" value="0"> Mon</label>
|
||
<label><input type="checkbox" class="bn-weekday" value="1"> Tue</label>
|
||
<label><input type="checkbox" class="bn-weekday" value="2"> Wed</label>
|
||
<label><input type="checkbox" class="bn-weekday" value="3"> Thu</label>
|
||
<label><input type="checkbox" class="bn-weekday" value="4"> Fri</label>
|
||
<label><input type="checkbox" class="bn-weekday" value="5"> Sat</label>
|
||
<label><input type="checkbox" class="bn-weekday" value="6" checked> Sun</label>
|
||
</div>
|
||
<div style="font-size:13px;margin-bottom:6px;">Times - pick a time, then Add:</div>
|
||
<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:8px;">
|
||
<input type="time" id="bn-weekly-time-pick" value="12:00" style="padding:6px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;color-scheme:dark;">
|
||
<button id="bn-weekly-add" style="padding:6px 14px;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;cursor:pointer;font-size:13px;">Add time</button>
|
||
</div>
|
||
<div id="bn-weekly-chips" style="display:flex;gap:6px;flex-wrap:wrap;"></div>
|
||
</div>
|
||
<div id="bn-sched-monthly" style="margin-bottom:12px;display:none;">
|
||
<div style="font-size:13px;margin-bottom:6px;">Days of month - click to select:</div>
|
||
<div id="bn-monthly-grid" style="display:grid;grid-template-columns:repeat(8, minmax(34px, 44px));gap:6px;margin-bottom:8px;"></div>
|
||
<label style="font-size:13px;">Time:
|
||
<input type="time" id="bn-monthly-time" value="12:00" style="padding:6px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;color-scheme:dark;">
|
||
</label>
|
||
</div>
|
||
<div id="bn-sched-once" style="margin-bottom:12px;display:none;">
|
||
<label style="font-size:13px;">Date + time - pick from the calendar:
|
||
<input type="datetime-local" id="bn-once-at" style="padding:6px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;color-scheme:dark;">
|
||
</label>
|
||
</div>
|
||
<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap;">
|
||
<button id="bn-save" style="padding:8px 20px;background:var(--primary);color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;font-weight:600;">Save notification</button>
|
||
<button id="bn-reset" style="padding:8px 16px;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;cursor:pointer;font-size:13px;">New / Reset</button>
|
||
<span id="bn-msg" style="font-size:12px;color:var(--text-muted);"></span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;margin-bottom:20px;">
|
||
<div class="card">
|
||
<div class="card-header">
|
||
<span>Graceful Shutdown / Restart</span>
|
||
<span id="lc-status-indicator" style="font-size:12px;color:var(--text-muted);">No active countdown</span>
|
||
</div>
|
||
<div class="card-body">
|
||
<div style="margin-bottom:12px;padding:12px;background:var(--bg);border-radius:6px;font-size:13px;line-height:1.6;">
|
||
Graceful actions warn players in-game first via the In-Game Broadcast, then run
|
||
<code>battlegroup stop</code> / <code>restart</code>.
|
||
Notices at 15m, 10m, 5m, 3m, 2m, 1m, 30s (10s each), 10s (5s), then a final notice at 1s.
|
||
</div>
|
||
<div style="display:flex;gap:8px;margin-bottom:12px;flex-wrap:wrap;">
|
||
<button id="lc-btn-start" style="padding:8px 20px;background:#27ae60;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;font-weight:600;">Start (immediate)</button>
|
||
<button id="lc-btn-shutdown" style="padding:8px 20px;background:#e74c3c;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;font-weight:600;">Shutdown (graceful)</button>
|
||
<button id="lc-btn-restart" style="padding:8px 20px;background:#e67e22;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;font-weight:600;">Restart (graceful)</button>
|
||
<button id="lc-btn-cancel" style="padding:8px 20px;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;cursor:pointer;font-size:13px;" disabled>Cancel countdown</button>
|
||
<button id="lc-btn-refresh" style="padding:8px 20px;background:var(--primary);color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;">Refresh</button>
|
||
</div>
|
||
<div id="lc-status-output">
|
||
<pre id="lc-status-text" style="background:var(--bg);color:var(--text);padding:16px;border-radius:8px;font-size:12px;overflow-x:auto;white-space:pre-wrap;min-height:60px;">No active countdown.</pre>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<div class="card-header">
|
||
<span>Scheduled Restarts</span>
|
||
<span id="lc-sched-indicator" style="font-size:12px;color:var(--text-muted);">Loading...</span>
|
||
</div>
|
||
<div class="card-body">
|
||
<div style="margin-bottom:12px;padding:12px;background:var(--bg);border-radius:6px;font-size:13px;line-height:1.6;">
|
||
Same in-game countdown as above, but the notices say e.g.
|
||
<em>"Scheduled restart in 5 minutes (daily 05:00)."</em>
|
||
The countdown starts 15 minutes before the restart time.
|
||
</div>
|
||
<div style="display:flex;gap:12px;align-items:center;flex-wrap:wrap;margin-bottom:12px;">
|
||
<label style="display:flex;align-items:center;gap:8px;cursor:pointer;font-size:13px;">
|
||
<input type="checkbox" id="lc-sched-enabled" style="width:16px;height:16px;"> Enabled
|
||
</label>
|
||
<label style="font-size:13px;">Mode:
|
||
<select id="lc-sched-mode" style="padding:6px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);">
|
||
<option value="daily">Daily</option>
|
||
<option value="weekly">Weekly</option>
|
||
<option value="monthly">Monthly</option>
|
||
<option value="once">One-shot</option>
|
||
</select>
|
||
</label>
|
||
</div>
|
||
<div id="lc-sched-daily" style="margin-bottom:12px;">
|
||
<div style="font-size:13px;margin-bottom:6px;">Times - pick a time, then Add:</div>
|
||
<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:8px;">
|
||
<input type="time" id="lc-daily-time-pick" value="05:00" style="padding:6px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;color-scheme:dark;">
|
||
<button id="lc-daily-add" style="padding:6px 14px;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;cursor:pointer;font-size:13px;">Add time</button>
|
||
</div>
|
||
<div id="lc-daily-chips" style="display:flex;gap:6px;flex-wrap:wrap;"></div>
|
||
</div>
|
||
<div id="lc-sched-weekly" style="margin-bottom:12px;display:none;">
|
||
<div style="font-size:13px;margin-bottom:6px;">Days:</div>
|
||
<div style="display:flex;gap:10px;flex-wrap:wrap;font-size:13px;margin-bottom:8px;">
|
||
<label><input type="checkbox" class="lc-weekday" value="0"> Mon</label>
|
||
<label><input type="checkbox" class="lc-weekday" value="1"> Tue</label>
|
||
<label><input type="checkbox" class="lc-weekday" value="2"> Wed</label>
|
||
<label><input type="checkbox" class="lc-weekday" value="3"> Thu</label>
|
||
<label><input type="checkbox" class="lc-weekday" value="4"> Fri</label>
|
||
<label><input type="checkbox" class="lc-weekday" value="5"> Sat</label>
|
||
<label><input type="checkbox" class="lc-weekday" value="6" checked> Sun</label>
|
||
</div>
|
||
<div style="font-size:13px;margin-bottom:6px;">Times - pick a time, then Add:</div>
|
||
<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:8px;">
|
||
<input type="time" id="lc-weekly-time-pick" value="05:00" style="padding:6px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;color-scheme:dark;">
|
||
<button id="lc-weekly-add" style="padding:6px 14px;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;cursor:pointer;font-size:13px;">Add time</button>
|
||
</div>
|
||
<div id="lc-weekly-chips" style="display:flex;gap:6px;flex-wrap:wrap;"></div>
|
||
</div>
|
||
<div id="lc-sched-monthly" style="margin-bottom:12px;display:none;">
|
||
<div style="font-size:13px;margin-bottom:6px;">Days of month - click to select:</div>
|
||
<div id="lc-monthly-grid" style="display:grid;grid-template-columns:repeat(8, minmax(34px, 44px));gap:6px;margin-bottom:8px;"></div>
|
||
<label style="font-size:13px;">Time:
|
||
<input type="time" id="lc-monthly-time" value="05:00" style="padding:6px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;color-scheme:dark;">
|
||
</label>
|
||
</div>
|
||
<div id="lc-sched-once" style="margin-bottom:12px;display:none;">
|
||
<label style="font-size:13px;">Date + time - pick from the calendar:
|
||
<input type="datetime-local" id="lc-once-at" style="padding:6px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;color-scheme:dark;">
|
||
</label>
|
||
</div>
|
||
<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap;">
|
||
<button id="lc-sched-save" style="padding:8px 20px;background:var(--primary);color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;font-weight:600;">Save schedule</button>
|
||
<button id="lc-sched-enable" style="padding:8px 16px;background:#27ae60;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;">Enable</button>
|
||
<button id="lc-sched-disable" style="padding:8px 16px;background:#e67e22;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;">Disable</button>
|
||
<button id="lc-sched-clear" style="padding:8px 16px;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;cursor:pointer;font-size:13px;">Clear schedule</button>
|
||
<span id="lc-sched-message" style="font-size:12px;color:var(--text-muted);"></span>
|
||
</div>
|
||
<div style="margin-top:6px;font-size:11px;color:var(--text-muted);">Enable / Disable / Clear keep your saved days and times.</div>
|
||
<div style="margin-top:8px;font-size:12px;color:var(--text-muted);">Next restart: <span id="lc-sched-next">-</span></div>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;margin-bottom:20px;">
|
||
<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:var(--bg);color:var(--text);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">Active Server IDs</div>
|
||
<div class="card-body">
|
||
{% if active_servers %}
|
||
<div class="table-wrap">
|
||
<table>
|
||
<thead><tr><th>Server ID</th><th>Map</th><th>Actions</th></tr></thead>
|
||
<tbody>
|
||
{% for s in active_servers %}
|
||
<tr>
|
||
<td style="font-family:monospace;font-size:12px;font-weight:600;">{{ s.server_id }}</td>
|
||
<td style="color:var(--primary);">{{ s.map or '' }}</td>
|
||
<td>
|
||
{% if s.deployment %}
|
||
<button class="partition-btn" data-deploy="{{ s.deployment }}" data-map="{{ s.server_id }}" title="Restart this server's deployment. Players on this map will disconnect briefly." style="padding:4px 12px;background:#e67e22;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:12px;">Restart</button>
|
||
{% elif not deployments %}
|
||
<span style="color:var(--text-muted);font-size:11px;">K8s offline</span>
|
||
{% else %}
|
||
<span style="color:var(--text-muted);font-size:11px;">No deploy</span>
|
||
{% endif %}
|
||
</td>
|
||
</tr>
|
||
{% endfor %}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
{% else %}
|
||
<div class="empty">No active servers</div>
|
||
{% endif %}
|
||
</div>
|
||
</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 %}<div style="display:flex;gap:4px;flex-wrap:wrap;"><button class="partition-btn" data-deploy="{{ p.deployment }}" data-map="{{ p.map }}" title="Restart this partition's deployment. Players on this map will disconnect." style="padding:4px 10px;background:#e67e22;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:11px;">Restart</button><button class="partition-status-btn" data-deploy="{{ p.deployment }}" data-map="{{ p.map }}" title="Show rollout status for this partition's deployment." style="padding:4px 10px;background:#3498db;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:11px;">Status</button></div>{% elif not deployments %}<span style="color:var(--text-muted);font-size:11px;">K8s offline</span>{% else %}<span style="color:var(--text-muted);font-size:11px;">No deploy</span>{% 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 style="margin-bottom:10px;padding:10px;background:var(--bg);border-radius:6px;font-size:12px;line-height:1.5;color:var(--text-light);">
|
||
<strong>Button Guide:</strong>
|
||
<span style="display:inline-block;margin:0 10px 0 4px;"><span style="color:#e67e22;">Restart</span> - rolling restart of pods</span>
|
||
<span style="display:inline-block;margin:0 10px 0 4px;"><span style="color:#3498db;">Status</span> - rollout status</span>
|
||
<span style="display:inline-block;margin:0 10px 0 4px;"><span style="color:#e74c3c;">Scale to 0</span> - stop all pods</span>
|
||
<span style="display:inline-block;margin:0 10px 0 4px;"><span style="color:#27ae60;">Scale to 1</span> - start a pod</span>
|
||
</div>
|
||
<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" title="Performs a rolling restart of this deployment's pods. Players will disconnect briefly." 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" title="Show rollout status: whether the deployment is successfully rolled out, pending, or failed." 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" title="Scale to 0 replicas. Stops all pods for this deployment. Use to shut down a server." 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" title="Scale to 1 replica. Starts a single pod. Use to bring a stopped server back online." 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:var(--bg);color:var(--danger);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:var(--bg);color:var(--text);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">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:var(--bg);color:var(--text);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:var(--bg);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:var(--bg);color:var(--text);padding:12px;border-radius:8px;font-size:12px;overflow-x:auto;white-space:pre-wrap;"></pre>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;margin-bottom:20px;">
|
||
<div class="card">
|
||
<div class="card-header">
|
||
<span>Funcom Service Auth Token <span style="font-size:10px;color:var(--warn);font-weight:400;">[WIP]</span></span>
|
||
<span id="sat-status" style="font-size:12px;color:var(--text-muted);"></span>
|
||
</div>
|
||
<div class="card-body">
|
||
<div style="margin-bottom:12px;padding:10px 12px;background:var(--warn-bg, #fff3cd);border:1px solid var(--warn-border, #ffc107);border-radius:6px;font-size:12px;line-height:1.5;color:var(--warn-text, #856404);">
|
||
<strong>⚠ WIP - Use with caution.</strong> This feature is still experimental.
|
||
Only use if you understand the risks. Backup your <code>*.yaml</code> files first.
|
||
</div>
|
||
<div style="margin-bottom:12px;padding:12px;background:var(--bg);border-radius:6px;font-size:13px;line-height:1.6;">
|
||
<strong style="color:var(--primary);">ServiceAuthToken</strong> - Used by the game server to authenticate with Funcom's live services.
|
||
If this token is regenerated by Funcom, paste the new JWT below and save.
|
||
All consuming pods must be restarted afterward.
|
||
</div>
|
||
<div style="margin-bottom:12px;">
|
||
<textarea id="sat-token" rows="4"
|
||
style="width:100%;padding:10px 12px;background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:12px;font-family:monospace;resize:vertical;"
|
||
placeholder="Paste the new ServiceAuthToken JWT here..."></textarea>
|
||
</div>
|
||
<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap;">
|
||
<button id="sat-save-btn" onclick="saveServiceAuthToken()"
|
||
style="padding:8px 20px;background:var(--primary);color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;font-weight:600;">Save Token</button>
|
||
<span id="sat-message" style="font-size:12px;color:var(--text-muted);"></span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<div class="card-header" style="cursor:pointer;" onclick="document.getElementById('debug-section').classList.toggle('hidden');">
|
||
<span>Debug Logging</span>
|
||
<span id="debug-status" style="font-size:12px;color:var(--text-muted);">Loading...</span>
|
||
</div>
|
||
<div class="card-body" id="debug-section">
|
||
<div style="margin-bottom:12px;padding:12px;background:var(--bg);border-radius:6px;font-size:13px;line-height:1.6;color:var(--text);">
|
||
<strong style="color:var(--primary);">Verbose Logging:</strong> Enable to log detailed information about SSH commands, API requests, database queries, and service connections.
|
||
Logs are written to <code>logs/debug.log</code>. Sanitizes sensitive data (passwords, tokens) automatically.
|
||
</div>
|
||
<div style="display:flex;align-items:center;gap:16px;">
|
||
<label style="display:flex;align-items:center;gap:8px;cursor:pointer;">
|
||
<input type="checkbox" id="debug-toggle" style="width:18px;height:18px;">
|
||
<span style="font-size:14px;">Enable debug logging</span>
|
||
</label>
|
||
<span id="debug-indicator" style="font-size:12px;color:var(--text-muted);"></span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<div class="card">
|
||
<div class="card-header" style="cursor:pointer;" onclick="document.getElementById('audit-section').classList.toggle('hidden');">
|
||
<span>Audit Log Viewer</span>
|
||
<span id="audit-stats" style="font-size:12px;color:var(--text-muted);">Loading...</span>
|
||
</div>
|
||
<div class="card-body" id="audit-section">
|
||
<div style="margin-bottom:12px;display:flex;gap:12px;align-items:center;flex-wrap:wrap;">
|
||
<input type="text" id="audit-search" placeholder="Filter by action..." style="padding:8px 12px;background:var(--bg);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;width:180px;">
|
||
<input type="text" id="audit-user" placeholder="Filter by user..." style="padding:8px 12px;background:var(--bg);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;width:140px;">
|
||
<select id="audit-severity" style="padding:8px 12px;background:var(--bg);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;">
|
||
<option value="">All Severities</option>
|
||
<option value="info">Info</option>
|
||
<option value="warning">Warning</option>
|
||
<option value="error">Error</option>
|
||
</select>
|
||
<button onclick="loadAuditLogs()" style="padding:8px 16px;background:var(--primary);color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;">Filter</button>
|
||
<button onclick="refreshAuditLogs()" style="padding:8px 16px;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;cursor:pointer;font-size:13px;">Refresh</button>
|
||
</div>
|
||
<div style="margin-bottom:12px;display:flex;gap:16px;font-size:12px;color:var(--text-muted);">
|
||
<span>Total: <strong id="audit-total">0</strong></span>
|
||
<span>Info: <strong id="audit-info-count" style="color:#3498db;">0</strong></span>
|
||
<span>Warning: <strong id="audit-warning-count" style="color:#f39c12;">0</strong></span>
|
||
<span>Error: <strong id="audit-error-count" style="color:#e74c3c;">0</strong></span>
|
||
</div>
|
||
<div id="audit-logs-container" style="max-height:300px;overflow-y:auto;">
|
||
<table style="width:100%;border-collapse:collapse;font-size:12px;">
|
||
<thead style="position:sticky;top:0;background:var(--table-header);">
|
||
<tr style="text-align:left;color:var(--text-muted);">
|
||
<th style="padding:8px;border-bottom:1px solid var(--border);">Time</th>
|
||
<th style="padding:8px;border-bottom:1px solid var(--border);">Action</th>
|
||
<th style="padding:8px;border-bottom:1px solid var(--border);">User</th>
|
||
<th style="padding:8px;border-bottom:1px solid var(--border);">Severity</th>
|
||
<th style="padding:8px;border-bottom:1px solid var(--border);">Details</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="audit-logs-body">
|
||
<tr><td colspan="5" style="padding:20px;text-align:center;color:var(--text-muted);">Loading...</td></tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
{% endif %}
|
||
{% endblock %}
|
||
|
||
{% block scripts %}
|
||
<script>
|
||
// ── Node resource charts ──────────────────────────────────────────────
|
||
const MAX_POINTS = 720; // 1 hour at 5s intervals
|
||
const SPARKLINE_POINTS = 60; // 5 min for sparkline
|
||
let metricsHistory = []; // [{cpu_num, memory_gib, memory_pct_num, memory, cpu, ts}]
|
||
|
||
function parseCSSVar(name) {
|
||
return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
||
}
|
||
|
||
function drawCharts(history) {
|
||
const cpuVals = history.map(p => p.cpu_num);
|
||
const memVals = history.map(p => p.memory_gib);
|
||
const primaryColor = parseCSSVar('--primary') || '#c9a24e';
|
||
const successColor = parseCSSVar('--success') || '#27ae60';
|
||
|
||
const chartCpu = document.getElementById('chart-cpu');
|
||
const chartMem = document.getElementById('chart-mem');
|
||
if (!chartCpu || !window.Chart) return;
|
||
|
||
if (!window._cpuChart) {
|
||
const textColor = parseCSSVar('--text-muted') || '#9a8a7a';
|
||
const gridColor = parseCSSVar('--border') || '#e0d5c7';
|
||
const commonOpts = {
|
||
responsive: true, maintainAspectRatio: false,
|
||
animation: { duration: 300 },
|
||
plugins: { legend: { display: false } },
|
||
scales: {
|
||
x: { display: true, grid: { color: gridColor }, ticks: { color: textColor, font: { size: 10 }, maxTicksLimit: 8 } },
|
||
y: { display: true, grid: { color: gridColor }, ticks: { color: textColor, font: { size: 10 } } }
|
||
}
|
||
};
|
||
window._cpuChart = new Chart(chartCpu, {
|
||
type: 'line',
|
||
data: { labels: [], datasets: [{ label: 'CPU %', data: [], borderColor: primaryColor, backgroundColor: primaryColor + '20', fill: true, pointRadius: 0, borderWidth: 2, tension: 0.3 }] },
|
||
options: { ...commonOpts, scales: { ...commonOpts.scales, y: { ...commonOpts.scales.y, min: 0, max: 100, title: { display: true, text: 'CPU %', color: textColor, font: { size: 11 } } } } }
|
||
});
|
||
const memMax = window._totalMemGib ? Math.ceil(window._totalMemGib) : undefined;
|
||
window._memChart = new Chart(chartMem, {
|
||
type: 'line',
|
||
data: { labels: [], datasets: [{ label: 'Memory GiB', data: [], borderColor: successColor, backgroundColor: successColor + '20', fill: true, pointRadius: 0, borderWidth: 2, tension: 0.3 }] },
|
||
options: { ...commonOpts, scales: { ...commonOpts.scales, y: { ...commonOpts.scales.y, beginAtZero: true, max: memMax, title: { display: true, text: 'GiB', color: textColor, font: { size: 11 } } } } }
|
||
});
|
||
}
|
||
|
||
const labels = history.map(p => p.ts);
|
||
window._cpuChart.data.labels = labels;
|
||
window._cpuChart.data.datasets[0].data = cpuVals;
|
||
window._cpuChart.data.datasets[0].borderColor = primaryColor;
|
||
window._cpuChart.data.datasets[0].backgroundColor = primaryColor + '20';
|
||
window._cpuChart.update('none');
|
||
|
||
window._memChart.data.labels = labels;
|
||
window._memChart.data.datasets[0].data = memVals;
|
||
window._memChart.data.datasets[0].borderColor = successColor;
|
||
window._memChart.data.datasets[0].backgroundColor = successColor + '20';
|
||
if (window._totalMemGib) {
|
||
window._memChart.options.scales.y.max = Math.ceil(window._totalMemGib);
|
||
}
|
||
window._memChart.update('none');
|
||
}
|
||
|
||
async function fetchMetrics() {
|
||
try {
|
||
const resp = await fetch('/server/metrics');
|
||
const data = await resp.json();
|
||
if (data.cpu) {
|
||
document.getElementById('node-cpu').textContent = data.cpu;
|
||
|
||
const memPctNum = data.memory_pct_num || 0;
|
||
const memGib = data.memory_gib || 0;
|
||
if (!window._totalMemGib && memPctNum > 0) {
|
||
window._totalMemGib = memGib / (memPctNum / 100);
|
||
}
|
||
document.getElementById('node-mem').textContent = data.memory;
|
||
|
||
const now = new Date();
|
||
const ts = now.getHours().toString().padStart(2, '0') + ':' + now.getMinutes().toString().padStart(2, '0') + ':' + now.getSeconds().toString().padStart(2, '0');
|
||
const point = { cpu_num: data.cpu_num || 0, memory_gib: memGib, memory_pct_num: memPctNum, memory: data.memory, cpu: data.cpu, ts: ts };
|
||
metricsHistory.push(point);
|
||
if (metricsHistory.length > MAX_POINTS) metricsHistory.shift();
|
||
|
||
drawCharts(metricsHistory);
|
||
}
|
||
} catch (e) {}
|
||
}
|
||
|
||
function loadChartJS(src) {
|
||
return new Promise((resolve, reject) => {
|
||
if (window.Chart) { resolve(); return; }
|
||
const s = document.createElement('script');
|
||
s.src = src; s.onload = resolve; s.onerror = reject;
|
||
document.head.appendChild(s);
|
||
});
|
||
}
|
||
|
||
loadChartJS('https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js').then(() => {
|
||
fetchMetrics();
|
||
setInterval(fetchMetrics, 5000);
|
||
}).catch(() => {
|
||
// Chart.js failed to load, still update text values
|
||
setInterval(fetchMetrics, 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 csrfFetch('/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 = 'Working...';
|
||
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 csrfFetch('/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.querySelectorAll('.partition-status-btn').forEach(btn => {
|
||
btn.addEventListener('click', async function() {
|
||
const deploy = this.dataset.deploy;
|
||
const map = this.dataset.map;
|
||
const label = this.textContent.trim();
|
||
this.disabled = true;
|
||
this.textContent = 'Loading...';
|
||
const output = document.getElementById('action-output');
|
||
const outputText = document.getElementById('action-output-text');
|
||
output.style.display = 'block';
|
||
outputText.textContent = `Fetching status for ${deploy}...`;
|
||
try {
|
||
const form = new FormData();
|
||
form.append('deployment', deploy);
|
||
form.append('action', 'status');
|
||
const resp = await csrfFetch('/server/action', { method: 'POST', body: form });
|
||
const data = await resp.json();
|
||
outputText.textContent = data.output || (data.success ? 'No status output' : 'Failed');
|
||
} catch (e) {
|
||
outputText.textContent = 'Error: ' + e.message;
|
||
}
|
||
this.disabled = false;
|
||
this.textContent = label;
|
||
});
|
||
});
|
||
|
||
async function refreshPods() {
|
||
const btn = document.getElementById('refresh-pods');
|
||
const pre = document.getElementById('pods-text');
|
||
if (btn) { btn.disabled = true; btn.textContent = 'Loading...'; }
|
||
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;
|
||
}
|
||
if (btn) { btn.disabled = false; btn.textContent = 'Refresh Pods'; }
|
||
}
|
||
|
||
document.getElementById('refresh-pods')?.addEventListener('click', refreshPods);
|
||
|
||
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. The server must be stopped first - update is blocked while game pods are running.'
|
||
};
|
||
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 csrfFetch(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);
|
||
|
||
// Graceful lifecycle (countdown + scheduled restarts)
|
||
function lcSetBusy(busy) {
|
||
for (const id of ['lc-btn-start', 'lc-btn-shutdown', 'lc-btn-restart']) {
|
||
const btn = document.getElementById(id);
|
||
if (btn) btn.disabled = busy;
|
||
}
|
||
}
|
||
|
||
function lcRenderStatus(data) {
|
||
const pre = document.getElementById('lc-status-text');
|
||
const indicator = document.getElementById('lc-status-indicator');
|
||
const cancelBtn = document.getElementById('lc-btn-cancel');
|
||
if (!data.active) {
|
||
pre.textContent = 'No active countdown.';
|
||
indicator.textContent = 'No active countdown';
|
||
indicator.style.color = 'var(--text-muted)';
|
||
if (cancelBtn) cancelBtn.disabled = true;
|
||
return;
|
||
}
|
||
const actionAt = data.action_at ? new Date(data.action_at * 1000).toLocaleString() : 'unknown';
|
||
const lines = [
|
||
`Active: ${data.kind} (${data.reason || 'manual'}${data.context ? ' - ' + data.context : ''})`,
|
||
`Status: ${data.status}`,
|
||
`Action at: ${actionAt}`,
|
||
'',
|
||
'Notices sent:',
|
||
];
|
||
for (const s of (data.sent || [])) {
|
||
lines.push(` - ${s.mark}: ${s.ok ? 'sent' : 'FAILED - ' + (s.detail || 'error')}`);
|
||
}
|
||
if (data.error) lines.push('', 'Error: ' + data.error);
|
||
pre.textContent = lines.join('\n');
|
||
indicator.textContent = `${data.kind} countdown: ${data.status}`;
|
||
indicator.style.color = 'var(--warn)';
|
||
if (cancelBtn) cancelBtn.disabled = (data.status === 'executing');
|
||
}
|
||
|
||
async function lcRefresh() {
|
||
try {
|
||
const resp = await fetch('/server/lifecycle/status');
|
||
const data = await resp.json();
|
||
if (data.success === false && data.error) {
|
||
document.getElementById('lc-status-text').textContent = 'Error: ' + data.error;
|
||
return;
|
||
}
|
||
lcRenderStatus(data);
|
||
} catch (e) {
|
||
document.getElementById('lc-status-text').textContent = 'Error: ' + e.message;
|
||
}
|
||
}
|
||
|
||
async function lcAction(kind) {
|
||
const msgs = {
|
||
'start': 'Start the battlegroup now? This is immediate (no countdown).',
|
||
'shutdown': 'Graceful shutdown? Players get in-game warnings at 15m, 10m, 5m, 3m, 2m, 1m, 30s, 10s, then shutdown.',
|
||
'restart': 'Graceful restart? Players get in-game warnings at 15m, 10m, 5m, 3m, 2m, 1m, 30s, 10s, then restart.'
|
||
};
|
||
if (msgs[kind] && !confirm(msgs[kind])) return;
|
||
if ((kind === 'shutdown' || kind === 'restart') && !confirm('Are you sure? This will affect live players.')) return;
|
||
lcSetBusy(true);
|
||
try {
|
||
const url = kind === 'start' ? '/server/lifecycle/start' : `/server/lifecycle/${kind}`;
|
||
const resp = await csrfFetch(url, { method: 'POST' });
|
||
const data = await resp.json();
|
||
if (!data.success) {
|
||
document.getElementById('lc-status-text').textContent = 'Failed: ' + (data.output || data.error || 'unknown error');
|
||
}
|
||
await lcRefresh();
|
||
} catch (e) {
|
||
document.getElementById('lc-status-text').textContent = 'Error: ' + e.message;
|
||
}
|
||
lcSetBusy(false);
|
||
}
|
||
|
||
async function lcCancel() {
|
||
if (!confirm('Cancel the active countdown? No further warnings will be sent.')) return;
|
||
try {
|
||
const resp = await csrfFetch('/server/lifecycle/cancel', { method: 'POST' });
|
||
const data = await resp.json();
|
||
if (!data.success) alert('Cancel failed: ' + (data.error || data.output || 'unknown'));
|
||
await lcRefresh();
|
||
} catch (e) { alert('Cancel error: ' + e.message); }
|
||
}
|
||
|
||
// ── Shared picker helpers (no typing: wheels, calendars, click-to-select) ──
|
||
function escapeHtml(s) {
|
||
return String(s == null ? '' : s)
|
||
.replace(/&/g, '&')
|
||
.replace(/</g, '<')
|
||
.replace(/>/g, '>')
|
||
.replace(/"/g, '"')
|
||
.replace(/'/g, ''');
|
||
}
|
||
|
||
function renderTimeChips(containerId, times, onRemove) {
|
||
const c = document.getElementById(containerId);
|
||
c.innerHTML = '';
|
||
if (!times.length) {
|
||
c.innerHTML = '<span style="font-size:12px;color:var(--text-muted);">No times yet - pick one above and hit Add.</span>';
|
||
return;
|
||
}
|
||
times.forEach(t => {
|
||
const s = document.createElement('span');
|
||
s.textContent = t + ' ×';
|
||
s.title = 'Click to remove';
|
||
s.style.cssText = 'padding:4px 10px;background:var(--primary);color:#fff;border-radius:12px;font-size:12px;cursor:pointer;';
|
||
s.onclick = () => onRemove(t);
|
||
c.appendChild(s);
|
||
});
|
||
}
|
||
|
||
function addPickedTime(inputId, arr, rerender) {
|
||
const raw = document.getElementById(inputId).value;
|
||
if (!raw) return;
|
||
const t = raw.slice(0, 5);
|
||
if (!/^\d{2}:\d{2}$/.test(t)) return;
|
||
if (!arr.includes(t)) { arr.push(t); arr.sort(); }
|
||
rerender();
|
||
}
|
||
|
||
function renderDayGrid(containerId, selected, onToggle) {
|
||
const g = document.getElementById(containerId);
|
||
g.innerHTML = '';
|
||
for (let d = 1; d <= 31; d++) {
|
||
const b = document.createElement('button');
|
||
b.textContent = d;
|
||
b.type = 'button';
|
||
const on = selected.includes(d);
|
||
b.style.cssText = 'padding:6px 0;border-radius:6px;cursor:pointer;font-size:12px;' +
|
||
(on ? 'background:var(--primary);color:#fff;border:1px solid var(--primary);font-weight:700;'
|
||
: 'background:var(--bg);color:var(--text);border:1px solid var(--border);');
|
||
b.onclick = () => onToggle(d);
|
||
g.appendChild(b);
|
||
}
|
||
}
|
||
|
||
// ── Custom notification (send now) ──
|
||
async function bcSend() {
|
||
const btn = document.getElementById('bc-send-btn');
|
||
const msg = document.getElementById('bc-msg');
|
||
const status = document.getElementById('bc-status');
|
||
const title = document.getElementById('bc-title').value.trim();
|
||
const message = document.getElementById('bc-message').value.trim();
|
||
const duration = parseInt(document.getElementById('bc-duration').value) || 30;
|
||
if (!title || !message) {
|
||
msg.textContent = 'Title and message are required.';
|
||
msg.style.color = 'var(--danger)';
|
||
return;
|
||
}
|
||
btn.disabled = true;
|
||
btn.textContent = 'Sending...';
|
||
msg.textContent = 'Sending...';
|
||
msg.style.color = 'var(--text-muted)';
|
||
try {
|
||
const resp = await csrfFetch('/server/broadcast', {
|
||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ title, message, duration })
|
||
});
|
||
const data = await resp.json();
|
||
if (data.success) {
|
||
msg.textContent = 'Broadcast sent!';
|
||
msg.style.color = 'var(--success)';
|
||
status.textContent = 'Last sent just now';
|
||
} else {
|
||
msg.textContent = 'Error: ' + (data.output || data.error || 'unknown');
|
||
msg.style.color = 'var(--danger)';
|
||
}
|
||
} catch (e) {
|
||
msg.textContent = 'Error: ' + e.message;
|
||
msg.style.color = 'var(--danger)';
|
||
}
|
||
btn.disabled = false;
|
||
btn.textContent = 'Send Broadcast';
|
||
}
|
||
|
||
// ── Restart schedule (picker-driven) ──
|
||
const lcSched = { enabled: false, mode: 'daily', daily_times: [], weekly_days: [],
|
||
weekly_times: [], monthly_days: [], monthly_time: '05:00', once_at: '', next_run: '' };
|
||
|
||
function lcSchedModeChanged() {
|
||
const mode = document.getElementById('lc-sched-mode').value;
|
||
lcSched.mode = mode;
|
||
for (const m of ['daily', 'weekly', 'monthly', 'once']) {
|
||
document.getElementById('lc-sched-' + m).style.display = (m === mode) ? '' : 'none';
|
||
}
|
||
}
|
||
|
||
function lcRenderPickers() {
|
||
renderTimeChips('lc-daily-chips', lcSched.daily_times,
|
||
(t) => { lcSched.daily_times = lcSched.daily_times.filter(x => x !== t); lcRenderPickers(); });
|
||
renderTimeChips('lc-weekly-chips', lcSched.weekly_times,
|
||
(t) => { lcSched.weekly_times = lcSched.weekly_times.filter(x => x !== t); lcRenderPickers(); });
|
||
renderDayGrid('lc-monthly-grid', lcSched.monthly_days,
|
||
(d) => {
|
||
const i = lcSched.monthly_days.indexOf(d);
|
||
if (i >= 0) lcSched.monthly_days.splice(i, 1);
|
||
else { lcSched.monthly_days.push(d); lcSched.monthly_days.sort((a, b) => a - b); }
|
||
lcRenderPickers();
|
||
});
|
||
}
|
||
|
||
function lcApplyToForm(s) {
|
||
Object.assign(lcSched, {
|
||
enabled: !!s.enabled, mode: s.mode || 'daily',
|
||
daily_times: [...(s.daily_times || [])], weekly_days: [...(s.weekly_days || [])],
|
||
weekly_times: [...(s.weekly_times || [])], monthly_days: [...(s.monthly_days || [])],
|
||
monthly_time: s.monthly_time || '05:00', once_at: s.once_at || '', next_run: s.next_run || '',
|
||
});
|
||
document.getElementById('lc-sched-enabled').checked = lcSched.enabled;
|
||
document.getElementById('lc-sched-mode').value = lcSched.mode;
|
||
document.getElementById('lc-monthly-time').value = lcSched.monthly_time;
|
||
if (lcSched.once_at) {
|
||
try { document.getElementById('lc-once-at').value = lcSched.once_at.slice(0, 16); } catch (e) { /* ignore */ }
|
||
} else {
|
||
document.getElementById('lc-once-at').value = '';
|
||
}
|
||
const weekdays = new Set(lcSched.weekly_days.map(String));
|
||
document.querySelectorAll('.lc-weekday').forEach(cb => { cb.checked = weekdays.has(cb.value); });
|
||
document.getElementById('lc-sched-next').textContent = lcSched.next_run ? new Date(lcSched.next_run).toLocaleString() : '-';
|
||
document.getElementById('lc-sched-indicator').textContent = lcSched.enabled ? `Enabled (${lcSched.mode})` : 'Disabled';
|
||
lcSchedModeChanged();
|
||
lcRenderPickers();
|
||
}
|
||
|
||
function lcCollectFromForm() {
|
||
lcSched.enabled = document.getElementById('lc-sched-enabled').checked;
|
||
lcSched.mode = document.getElementById('lc-sched-mode').value;
|
||
lcSched.weekly_days = Array.from(document.querySelectorAll('.lc-weekday:checked')).map(cb => Number(cb.value));
|
||
lcSched.monthly_time = document.getElementById('lc-monthly-time').value || '05:00';
|
||
// Send the local calendar value as-is (no UTC conversion) so the
|
||
// server schedules it in server-local time.
|
||
lcSched.once_at = document.getElementById('lc-once-at').value || '';
|
||
return { ...lcSched };
|
||
}
|
||
|
||
async function lcLoadSchedule() {
|
||
const msg = document.getElementById('lc-sched-message');
|
||
try {
|
||
const resp = await fetch('/server/lifecycle/schedule');
|
||
const data = await resp.json();
|
||
if (!data.success) { msg.textContent = 'Failed to load schedule.'; return; }
|
||
lcApplyToForm(data.schedule || {});
|
||
} catch (e) { msg.textContent = 'Error: ' + e.message; }
|
||
}
|
||
|
||
async function lcSaveSchedule() {
|
||
const msg = document.getElementById('lc-sched-message');
|
||
msg.textContent = 'Saving...';
|
||
msg.style.color = 'var(--text-muted)';
|
||
try {
|
||
const resp = await csrfFetch('/server/lifecycle/schedule', {
|
||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify(lcCollectFromForm())
|
||
});
|
||
const data = await resp.json();
|
||
if (data.success) {
|
||
lcApplyToForm(data.schedule);
|
||
msg.textContent = 'Schedule saved.';
|
||
msg.style.color = 'var(--success)';
|
||
} else {
|
||
msg.textContent = 'Error: ' + (data.error || 'unknown');
|
||
msg.style.color = 'var(--danger)';
|
||
}
|
||
} catch (e) {
|
||
msg.textContent = 'Error: ' + e.message;
|
||
msg.style.color = 'var(--danger)';
|
||
}
|
||
}
|
||
|
||
async function lcSetEnabled(on) {
|
||
const msg = document.getElementById('lc-sched-message');
|
||
try {
|
||
const resp = await csrfFetch('/server/lifecycle/schedule/enabled', {
|
||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ enabled: on })
|
||
});
|
||
const data = await resp.json();
|
||
if (data.success) {
|
||
lcApplyToForm(data.schedule);
|
||
msg.textContent = on ? 'Schedule enabled.' : 'Schedule disabled - settings kept.';
|
||
msg.style.color = 'var(--success)';
|
||
} else {
|
||
msg.textContent = 'Error: ' + (data.error || 'unknown');
|
||
msg.style.color = 'var(--danger)';
|
||
}
|
||
} catch (e) {
|
||
msg.textContent = 'Error: ' + e.message;
|
||
msg.style.color = 'var(--danger)';
|
||
}
|
||
}
|
||
|
||
async function lcClearSchedule() {
|
||
if (!confirm('Clear the restart schedule? Days and times are kept, but the armed date and pending run are removed and the schedule is disabled.')) return;
|
||
const msg = document.getElementById('lc-sched-message');
|
||
try {
|
||
const resp = await csrfFetch('/server/lifecycle/schedule/clear', { method: 'POST' });
|
||
const data = await resp.json();
|
||
if (data.success) {
|
||
lcApplyToForm(data.schedule);
|
||
msg.textContent = 'Schedule cleared - days and times kept.';
|
||
msg.style.color = 'var(--success)';
|
||
} else {
|
||
msg.textContent = 'Error: ' + (data.error || 'unknown');
|
||
msg.style.color = 'var(--danger)';
|
||
}
|
||
} catch (e) {
|
||
msg.textContent = 'Error: ' + e.message;
|
||
msg.style.color = 'var(--danger)';
|
||
}
|
||
}
|
||
|
||
// ── Scheduled notifications ──
|
||
let bnEntries = [];
|
||
const bnForm = { id: '', daily_times: [], weekly_times: [], monthly_days: [] };
|
||
const BN_DAY_NAMES = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||
|
||
function bnModeChanged() {
|
||
const mode = document.getElementById('bn-mode').value;
|
||
for (const m of ['daily', 'weekly', 'monthly', 'once']) {
|
||
document.getElementById('bn-sched-' + m).style.display = (m === mode) ? '' : 'none';
|
||
}
|
||
}
|
||
|
||
function bnRenderPickers() {
|
||
renderTimeChips('bn-daily-chips', bnForm.daily_times,
|
||
(t) => { bnForm.daily_times = bnForm.daily_times.filter(x => x !== t); bnRenderPickers(); });
|
||
renderTimeChips('bn-weekly-chips', bnForm.weekly_times,
|
||
(t) => { bnForm.weekly_times = bnForm.weekly_times.filter(x => x !== t); bnRenderPickers(); });
|
||
renderDayGrid('bn-monthly-grid', bnForm.monthly_days,
|
||
(d) => {
|
||
const i = bnForm.monthly_days.indexOf(d);
|
||
if (i >= 0) bnForm.monthly_days.splice(i, 1);
|
||
else { bnForm.monthly_days.push(d); bnForm.monthly_days.sort((a, b) => a - b); }
|
||
bnRenderPickers();
|
||
});
|
||
}
|
||
|
||
function bnDescribe(e) {
|
||
if (e.mode === 'once') return 'one-shot ' + (e.once_at ? new Date(e.once_at).toLocaleString() : '(unscheduled)');
|
||
if (e.mode === 'daily') return 'daily ' + (e.daily_times || []).join(', ');
|
||
if (e.mode === 'weekly') {
|
||
const days = (e.weekly_days || []).map(d => BN_DAY_NAMES[d] || d).join(', ');
|
||
return `weekly ${days} ${(e.weekly_times || []).join(', ')}`;
|
||
}
|
||
if (e.mode === 'monthly') return `monthly day ${(e.monthly_days || []).join(', ')} ${e.monthly_time || ''}`;
|
||
return e.mode;
|
||
}
|
||
|
||
function bnRenderList() {
|
||
const list = document.getElementById('bn-list');
|
||
const indicator = document.getElementById('bn-indicator');
|
||
const active = bnEntries.filter(e => e.enabled).length;
|
||
indicator.textContent = bnEntries.length ? `${active}/${bnEntries.length} enabled` : 'None yet';
|
||
if (!bnEntries.length) {
|
||
list.innerHTML = '<p style="color:var(--text-muted);">No scheduled notifications yet - use the form below.</p>';
|
||
return;
|
||
}
|
||
list.innerHTML = '';
|
||
bnEntries.forEach(e => {
|
||
const row = document.createElement('div');
|
||
row.style.cssText = 'display:flex;gap:8px;align-items:center;flex-wrap:wrap;padding:8px 10px;margin-bottom:6px;background:var(--bg);border:1px solid var(--border);border-radius:6px;';
|
||
const next = e.next_run ? new Date(e.next_run).toLocaleString() : '-';
|
||
row.innerHTML =
|
||
`<strong style="font-size:13px;">${escapeHtml(e.title)}</strong>` +
|
||
`<span style="font-size:12px;color:var(--text-muted);">${escapeHtml(bnDescribe(e))}</span>` +
|
||
`<span style="font-size:12px;color:var(--text-muted);">next: ${next}</span>` +
|
||
`<span style="font-size:11px;font-weight:700;color:${e.enabled ? 'var(--success)' : 'var(--text-muted)'};">${e.enabled ? 'ON' : 'OFF'}</span>`;
|
||
const mkBtn = (label, bg, fn) => {
|
||
const b = document.createElement('button');
|
||
b.textContent = label;
|
||
b.style.cssText = `padding:4px 12px;background:${bg};color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:12px;`;
|
||
b.onclick = fn;
|
||
return b;
|
||
};
|
||
row.appendChild(mkBtn('Edit', 'var(--primary)', () => bnEdit(e.id)));
|
||
row.appendChild(mkBtn(e.enabled ? 'Disable' : 'Enable', e.enabled ? '#e67e22' : '#27ae60', () => bnToggle(e.id, !e.enabled)));
|
||
row.appendChild(mkBtn('Delete', '#e74c3c', () => bnDelete(e.id)));
|
||
list.appendChild(row);
|
||
});
|
||
}
|
||
|
||
async function bnLoad() {
|
||
const msg = document.getElementById('bn-msg');
|
||
try {
|
||
const resp = await fetch('/server/broadcasts/schedule');
|
||
const data = await resp.json();
|
||
if (!data.success) { msg.textContent = 'Failed to load.'; return; }
|
||
bnEntries = data.entries || [];
|
||
bnRenderList();
|
||
} catch (e) { msg.textContent = 'Error: ' + e.message; }
|
||
}
|
||
|
||
function bnResetForm() {
|
||
document.getElementById('bn-id').value = '';
|
||
document.getElementById('bn-form-title').textContent = 'New scheduled notification';
|
||
document.getElementById('bn-title').value = 'Server Notice';
|
||
document.getElementById('bn-message').value = '';
|
||
document.getElementById('bn-duration').value = 30;
|
||
document.getElementById('bn-enabled').checked = true;
|
||
document.getElementById('bn-mode').value = 'daily';
|
||
document.getElementById('bn-once-at').value = '';
|
||
document.getElementById('bn-monthly-time').value = '12:00';
|
||
bnForm.id = '';
|
||
bnForm.daily_times = ['12:00'];
|
||
bnForm.weekly_times = ['12:00'];
|
||
bnForm.monthly_days = [1];
|
||
const weekdays = new Set(['6']);
|
||
document.querySelectorAll('.bn-weekday').forEach(cb => { cb.checked = weekdays.has(cb.value); });
|
||
bnModeChanged();
|
||
bnRenderPickers();
|
||
}
|
||
|
||
function bnEdit(id) {
|
||
const e = bnEntries.find(x => x.id === id);
|
||
if (!e) return;
|
||
document.getElementById('bn-id').value = e.id;
|
||
document.getElementById('bn-form-title').textContent = 'Edit scheduled notification';
|
||
document.getElementById('bn-title').value = e.title || '';
|
||
document.getElementById('bn-message').value = e.message || '';
|
||
document.getElementById('bn-duration').value = e.duration || 30;
|
||
document.getElementById('bn-enabled').checked = !!e.enabled;
|
||
document.getElementById('bn-mode').value = e.mode || 'daily';
|
||
document.getElementById('bn-monthly-time').value = e.monthly_time || '12:00';
|
||
try { document.getElementById('bn-once-at').value = (e.once_at || '').slice(0, 16); }
|
||
catch (err) { document.getElementById('bn-once-at').value = ''; }
|
||
bnForm.id = e.id;
|
||
bnForm.daily_times = [...(e.daily_times || [])];
|
||
bnForm.weekly_times = [...(e.weekly_times || [])];
|
||
bnForm.monthly_days = [...(e.monthly_days || [])];
|
||
const weekdays = new Set((e.weekly_days || []).map(String));
|
||
document.querySelectorAll('.bn-weekday').forEach(cb => { cb.checked = weekdays.has(cb.value); });
|
||
bnModeChanged();
|
||
bnRenderPickers();
|
||
document.getElementById('bn-form-title').scrollIntoView({ block: 'nearest' });
|
||
}
|
||
|
||
function bnCollect() {
|
||
return {
|
||
id: document.getElementById('bn-id').value || undefined,
|
||
title: document.getElementById('bn-title').value.trim(),
|
||
message: document.getElementById('bn-message').value.trim(),
|
||
duration: parseInt(document.getElementById('bn-duration').value) || 30,
|
||
enabled: document.getElementById('bn-enabled').checked,
|
||
mode: document.getElementById('bn-mode').value,
|
||
daily_times: [...bnForm.daily_times],
|
||
weekly_times: [...bnForm.weekly_times],
|
||
weekly_days: Array.from(document.querySelectorAll('.bn-weekday:checked')).map(cb => Number(cb.value)),
|
||
monthly_days: [...bnForm.monthly_days],
|
||
monthly_time: document.getElementById('bn-monthly-time').value || '12:00',
|
||
once_at: document.getElementById('bn-once-at').value || '',
|
||
};
|
||
}
|
||
|
||
async function bnSave() {
|
||
const msg = document.getElementById('bn-msg');
|
||
const body = bnCollect();
|
||
if (!body.title || !body.message) {
|
||
msg.textContent = 'Title and message are required.';
|
||
msg.style.color = 'var(--danger)';
|
||
return;
|
||
}
|
||
msg.textContent = 'Saving...';
|
||
msg.style.color = 'var(--text-muted)';
|
||
try {
|
||
const resp = await csrfFetch('/server/broadcasts/schedule', {
|
||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify(body)
|
||
});
|
||
const data = await resp.json();
|
||
if (data.success) {
|
||
msg.textContent = 'Saved.';
|
||
msg.style.color = 'var(--success)';
|
||
await bnLoad();
|
||
bnResetForm();
|
||
} else {
|
||
msg.textContent = 'Error: ' + (data.error || 'unknown');
|
||
msg.style.color = 'var(--danger)';
|
||
}
|
||
} catch (e) {
|
||
msg.textContent = 'Error: ' + e.message;
|
||
msg.style.color = 'var(--danger)';
|
||
}
|
||
}
|
||
|
||
async function bnToggle(id, on) {
|
||
try {
|
||
const resp = await csrfFetch('/server/broadcasts/schedule/enabled', {
|
||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ id, enabled: on })
|
||
});
|
||
const data = await resp.json();
|
||
if (!data.success) alert('Failed: ' + (data.error || 'unknown'));
|
||
await bnLoad();
|
||
} catch (e) { alert('Error: ' + e.message); }
|
||
}
|
||
|
||
async function bnDelete(id) {
|
||
if (!confirm('Delete this scheduled notification?')) return;
|
||
try {
|
||
const resp = await csrfFetch('/server/broadcasts/schedule/delete', {
|
||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ id })
|
||
});
|
||
const data = await resp.json();
|
||
if (!data.success) alert('Delete failed.');
|
||
await bnLoad();
|
||
} catch (e) { alert('Error: ' + e.message); }
|
||
}
|
||
|
||
document.getElementById('lc-btn-start')?.addEventListener('click', () => lcAction('start'));
|
||
document.getElementById('lc-btn-shutdown')?.addEventListener('click', () => lcAction('shutdown'));
|
||
document.getElementById('lc-btn-restart')?.addEventListener('click', () => lcAction('restart'));
|
||
document.getElementById('lc-btn-cancel')?.addEventListener('click', lcCancel);
|
||
document.getElementById('lc-btn-refresh')?.addEventListener('click', lcRefresh);
|
||
document.getElementById('bc-send-btn')?.addEventListener('click', bcSend);
|
||
document.getElementById('lc-sched-mode')?.addEventListener('change', lcSchedModeChanged);
|
||
document.getElementById('lc-sched-save')?.addEventListener('click', lcSaveSchedule);
|
||
document.getElementById('lc-sched-enable')?.addEventListener('click', () => lcSetEnabled(true));
|
||
document.getElementById('lc-sched-disable')?.addEventListener('click', () => lcSetEnabled(false));
|
||
document.getElementById('lc-sched-clear')?.addEventListener('click', lcClearSchedule);
|
||
document.getElementById('lc-daily-add')?.addEventListener('click', () => addPickedTime('lc-daily-time-pick', lcSched.daily_times, lcRenderPickers));
|
||
document.getElementById('lc-weekly-add')?.addEventListener('click', () => addPickedTime('lc-weekly-time-pick', lcSched.weekly_times, lcRenderPickers));
|
||
document.getElementById('bn-mode')?.addEventListener('change', bnModeChanged);
|
||
document.getElementById('bn-save')?.addEventListener('click', bnSave);
|
||
document.getElementById('bn-reset')?.addEventListener('click', bnResetForm);
|
||
document.getElementById('bn-daily-add')?.addEventListener('click', () => addPickedTime('bn-daily-time-pick', bnForm.daily_times, bnRenderPickers));
|
||
document.getElementById('bn-weekly-add')?.addEventListener('click', () => addPickedTime('bn-weekly-time-pick', bnForm.weekly_times, bnRenderPickers));
|
||
lcRefresh();
|
||
lcLoadSchedule();
|
||
bnResetForm();
|
||
bnLoad();
|
||
setInterval(lcRefresh, 15000);
|
||
|
||
// 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 portDisplay = p.port !== null && p.port !== undefined ? p.port : 'N/A';
|
||
const hasPort = p.port !== null && p.port !== undefined;
|
||
const isBlocked = hasPort && (data.blocked || []).some(b => b.port === p.port);
|
||
const rules = hasPort ? Object.values(data.iptables_rules || {}).filter(r => r.includes('dpt:' + p.port)) : [];
|
||
const statusText = !hasPort ? '<span style="color:var(--text-muted);font-style:italic;">Not running</span>' : (isBlocked ? '<span style="color:#4ade80;font-weight:600;">Blocked</span>' : '<span style="color:#e74c3c;font-weight:600;">Open</span>');
|
||
const actionBtn = !hasPort
|
||
? '<span style="color:var(--text-muted);font-size:11px;">Start battlegroup to enable</span>'
|
||
: (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;">${portDisplay}</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 csrfFetch('/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();
|
||
|
||
// Audit Log Viewer
|
||
async function loadAuditLogs(action = '', user = '', severity = '', limit = 100, offset = 0) {
|
||
const tbody = document.getElementById('audit-logs-body');
|
||
const actionFilter = document.getElementById('audit-search').value;
|
||
const userFilter = document.getElementById('audit-user').value;
|
||
const severityFilter = document.getElementById('audit-severity').value;
|
||
|
||
try {
|
||
let url = '/api/audit/logs?limit=' + limit + '&offset=' + offset;
|
||
if (actionFilter) url += '&action=' + encodeURIComponent(actionFilter);
|
||
if (userFilter) url += '&user=' + encodeURIComponent(userFilter);
|
||
|
||
const resp = await fetch(url);
|
||
const data = await resp.json();
|
||
|
||
if (!data.success) {
|
||
tbody.innerHTML = '<tr><td colspan="5" style="padding:20px;text-align:center;color:var(--danger);">Error: ' + escapeHtml(data.error || 'unknown') + '</td></tr>';
|
||
return;
|
||
}
|
||
|
||
const logs = data.logs || [];
|
||
if (logs.length === 0) {
|
||
tbody.innerHTML = '<tr><td colspan="5" style="padding:20px;text-align:center;color:var(--text-muted);">No audit logs found</td></tr>';
|
||
document.getElementById('audit-total').textContent = '0';
|
||
return;
|
||
}
|
||
|
||
// Update stats
|
||
const infoCount = logs.filter(l => l.severity === 'info').length;
|
||
const warningCount = logs.filter(l => l.severity === 'warning').length;
|
||
const errorCount = logs.filter(l => l.severity === 'error').length;
|
||
document.getElementById('audit-total').textContent = logs.length;
|
||
document.getElementById('audit-info-count').textContent = infoCount;
|
||
document.getElementById('audit-warning-count').textContent = warningCount;
|
||
document.getElementById('audit-error-count').textContent = errorCount;
|
||
|
||
// Render table (all server data escaped - never raw innerHTML)
|
||
tbody.innerHTML = logs.map(log => {
|
||
const details = log.details ? JSON.stringify(log.details) : '-';
|
||
const severityColor = log.severity === 'error' ? 'color:#e74c3c;' : (log.severity === 'warning' ? 'color:#f39c12;' : 'color:#3498db;');
|
||
const timestamp = log.timestamp ? log.timestamp.replace('T', ' ').substring(0, 19) : '-';
|
||
return '<tr style="border-bottom:1px solid var(--border);">' +
|
||
'<td style="padding:8px;color:var(--text-muted);">' + escapeHtml(timestamp) + '</td>' +
|
||
'<td style="padding:8px;font-weight:600;">' + escapeHtml(log.action || '-') + '</td>' +
|
||
'<td style="padding:8px;">' + escapeHtml(log.user || '-') + '</td>' +
|
||
'<td style="padding:8px;' + severityColor + '">' + escapeHtml(log.severity || 'info') + '</td>' +
|
||
'<td style="padding:8px;color:var(--text-muted);font-size:11px;max-width:200px;overflow:hidden;text-overflow:ellipsis;">' + escapeHtml(details) + '</td>' +
|
||
'</tr>';
|
||
}).join('');
|
||
|
||
} catch (e) {
|
||
tbody.innerHTML = '<tr><td colspan="5" style="padding:20px;text-align:center;color:var(--danger);">Error: ' + escapeHtml(e.message) + '</td></tr>';
|
||
}
|
||
}
|
||
|
||
function refreshAuditLogs() {
|
||
loadAuditLogs();
|
||
}
|
||
|
||
// Load audit stats on page load
|
||
loadAuditLogs();
|
||
|
||
// Debug Logging
|
||
const debugToggle = document.getElementById('debug-toggle');
|
||
const debugStatus = document.getElementById('debug-status');
|
||
const debugIndicator = document.getElementById('debug-indicator');
|
||
|
||
async function loadDebugStatus() {
|
||
try {
|
||
const resp = await csrfFetch('/api/settings');
|
||
const data = await resp.json();
|
||
if (data.success) {
|
||
const debugEnabled = data.settings.logging.debug_enabled;
|
||
debugToggle.checked = debugEnabled;
|
||
if (debugEnabled) {
|
||
debugStatus.innerHTML = '<span style="color:var(--success);">✓ Enabled</span>';
|
||
debugIndicator.textContent = 'Debug logs writing to logs/debug.log';
|
||
} else {
|
||
debugStatus.innerHTML = '<span style="color:var(--text-muted);">○ Disabled</span>';
|
||
debugIndicator.textContent = '';
|
||
}
|
||
}
|
||
} catch (e) {
|
||
console.error('Failed to load debug status:', e);
|
||
}
|
||
}
|
||
|
||
debugToggle.addEventListener('change', async function() {
|
||
const enabled = this.checked;
|
||
try {
|
||
const resp = await csrfFetch('/api/settings/debug', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ enabled: enabled })
|
||
});
|
||
const data = await resp.json();
|
||
if (data.success) {
|
||
if (enabled) {
|
||
debugStatus.innerHTML = '<span style="color:var(--success);">✓ Enabled</span>';
|
||
debugIndicator.textContent = 'Debug logs writing to logs/debug.log';
|
||
alert('Debug logging enabled! Logs will be written to logs/debug.log');
|
||
} else {
|
||
debugStatus.innerHTML = '<span style="color:var(--text-muted);">○ Disabled</span>';
|
||
debugIndicator.textContent = '';
|
||
alert('Debug logging disabled.');
|
||
}
|
||
} else {
|
||
alert('Failed to toggle debug: ' + (data.error || 'Unknown error'));
|
||
this.checked = !enabled;
|
||
}
|
||
} catch (e) {
|
||
alert('Error toggling debug: ' + e.message);
|
||
this.checked = !enabled;
|
||
}
|
||
});
|
||
|
||
// Load debug status on page load
|
||
loadDebugStatus();
|
||
|
||
// Auto-load battlegroup and pods once on page load, then require manual refresh
|
||
bgRefreshStatus();
|
||
refreshPods();
|
||
|
||
// ServiceAuthToken
|
||
async function saveServiceAuthToken() {
|
||
const token = document.getElementById('sat-token').value.trim();
|
||
const btn = document.getElementById('sat-save-btn');
|
||
const msg = document.getElementById('sat-message');
|
||
const status = document.getElementById('sat-status');
|
||
|
||
if (!token) {
|
||
msg.textContent = 'Please paste the new token first.';
|
||
msg.style.color = 'var(--danger)';
|
||
return;
|
||
}
|
||
if (!confirm('Are you sure you want to replace the ServiceAuthToken?\n\nThis will update the K8s secret and YAML file. All consuming pods must be restarted for the change to take effect.')) return;
|
||
if (!confirm('Are you absolutely sure? An incorrect token may break server connectivity with Funcom live services.')) return;
|
||
|
||
btn.disabled = true;
|
||
btn.textContent = 'Saving...';
|
||
msg.textContent = 'Updating token...';
|
||
msg.style.color = 'var(--text-muted)';
|
||
status.textContent = 'Updating...';
|
||
|
||
try {
|
||
const resp = await csrfFetch('/api/server/service-auth-token', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ token })
|
||
});
|
||
const data = await resp.json();
|
||
if (data.success) {
|
||
msg.textContent = data.message || 'Token updated successfully.';
|
||
msg.style.color = 'var(--success)';
|
||
status.textContent = 'Token saved';
|
||
status.style.color = 'var(--success)';
|
||
document.getElementById('sat-token').value = '';
|
||
} else {
|
||
msg.textContent = 'Error: ' + (data.error || 'Unknown error');
|
||
msg.style.color = 'var(--danger)';
|
||
status.textContent = 'Failed';
|
||
status.style.color = 'var(--danger)';
|
||
}
|
||
} catch (e) {
|
||
msg.textContent = 'Error: ' + e.message;
|
||
msg.style.color = 'var(--danger)';
|
||
status.textContent = 'Error';
|
||
status.style.color = 'var(--danger)';
|
||
}
|
||
|
||
btn.disabled = false;
|
||
btn.textContent = 'Save Token';
|
||
}
|
||
</script>
|
||
{% endblock %}
|