v7.3: graceful shutdown/restart with countdown, custom/scheduled notifications, update guard, file jail, security hardening, experimental tab removed

This commit is contained in:
Reditus committed 2026-09-21 14:51:37 +01:00
1 parent aee4028f5c
commit 54d9d5db25
31 files changed
+2764 -2363

No files matched your search

+2 -2
View File
@@ -57,10 +57,10 @@
{% for c in characters %}
<tr>
<td><a href="/players/{{ c.id }}">{{ c.player_name or 'Unknown' }}</a></td>
<td>{% if c.online_status %}<span class="badge badge-{{ c.online_status.lower() }}">{{ c.online_status }}</span>{% else %}&mdash;{% endif %}</td>
<td>{% if c.online_status %}<span class="badge badge-{{ c.online_status.lower() }}">{{ c.online_status }}</span>{% else %}-{% endif %}</td>
<td>{{ c.id }}</td>
<td>{{ c.map or 'N/A' }}</td>
<td>{% if c.faction_name %}<span class="badge badge-{{ c.faction_name.lower() }}">{{ c.faction_name }}</span>{% else %}&mdash;{% endif %}</td>
<td>{% if c.faction_name %}<span class="badge badge-{{ c.faction_name.lower() }}">{{ c.faction_name }}</span>{% else %}-{% endif %}</td>
<td style="font-size:11px;">{{ c.last_login_time.strftime('%Y-%m-%d %H:%M') if c.last_login_time else 'N/A' }}</td>
<td style="font-size:10px;font-family:monospace;max-width:180px;word-break:break-all;">{{ c.transform_text or '' }}</td>
</tr>
+2 -2
View File
@@ -33,8 +33,8 @@
{% for a in accounts %}
<tr>
<td><a href="/accounts/{{ a.id }}">{{ a.funcom_id or a.platform_name or 'Unknown' }}</a></td>
<td>{{ a.character_name or '&mdash;'|safe }}</td>
<td>{% if a.online_status %}<span class="badge badge-{{ a.online_status.lower() }}">{{ a.online_status }}</span>{% else %}&mdash;{% endif %}</td>
<td>{{ a.character_name or '-' }}</td>
<td>{% if a.online_status %}<span class="badge badge-{{ a.online_status.lower() }}">{{ a.online_status }}</span>{% else %}-{% endif %}</td>
<td style="font-size:11px;font-family:monospace;">{{ a.user }}</td>
<td style="font-size:11px;">{{ a.platform_id or 'N/A' }}</td>
<td>{{ a.player_count }}</td>
File diff suppressed because it is too large. Load diff
+4 -4
View File
@@ -10,7 +10,7 @@
<div id="backup-status" class="error-banner" style="display:none;"></div>
<div style="background:rgba(255,193,7,0.12);border:2px solid rgba(255,193,7,0.6);border-left:6px solid #ffc107;border-radius:8px;padding:14px 20px;margin-bottom:16px;">
<div style="font-size:14px;font-weight:700;color:#e8a317;margin-bottom:6px;">&#9888; WIP — Use with caution</div>
<div style="font-size:14px;font-weight:700;color:#e8a317;margin-bottom:6px;">&#9888; WIP - Use with caution</div>
<div style="font-size:13px;color:var(--text);line-height:1.5;">
This feature is still experimental. Test on a non-production environment first.
Keep offline backups of anything critical before using restore.
@@ -23,7 +23,7 @@
Backups contain <strong>sensitive information</strong> including database contents, K8s secrets, and server configuration.
Store backup files in a <strong>secure, offline location</strong>. Use a password to encrypt backups containing private data.
Do not share backup files or expose them in insecure storage.
<strong style="color:#ef4444;display:block;margin-top:8px;">&#9888; If you set a password, never forget it — lost passwords cannot be recovered and the backup will be permanently unrecoverable.</strong>
<strong style="color:#ef4444;display:block;margin-top:8px;">&#9888; If you set a password, don't forget it - there's no way to recover it, and the backup will be locked for good.</strong>
</div>
</div>
@@ -299,7 +299,7 @@
<!-- Verify Backup Password Modal -->
<div id="verify-pw-modal" class="modal-overlay" style="display:none;" onclick="if(event.target===this)closeModal('verify-pw-modal')">
<div class="modal" style="max-width:380px;">
<div class="modal-header"><h3>Verify Backup — <span id="verify-pw-label"></span></h3></div>
<div class="modal-header"><h3>Verify Backup - <span id="verify-pw-label"></span></h3></div>
<div class="modal-body" style="padding:20px;">
<label style="display:block;font-size:13px;color:var(--text-light);">
Password
@@ -706,7 +706,7 @@ async function startRestore() {
}
if (!confirm('This will OVERWRITE ALL DATA on the configured server. Are you sure?')) return;
if (!confirm('Last chance — are you absolutely sure you want to restore "' + name + '"?')) return;
if (!confirm('Last chance - are you absolutely sure you want to restore "' + name + '"?')) return;
const password = document.getElementById('restore-password').value;
+1 -1
View File
@@ -29,7 +29,7 @@
<td>{{ e.actor_id }}</td>
<td>{{ e.map or '' }}</td>
<td>{{ e.event_type }}</td>
<td>{% if e.actor_name %}{{ e.actor_name }}{% else %}&mdash;{% endif %}</td>
<td>{% if e.actor_name %}{{ e.actor_name }}{% else %}-{% endif %}</td>
<td style="font-size:11px;font-family:monospace;">{% if e.x %}{{ e.x|round(0)|int }}, {{ e.y|round(0)|int }}, {{ e.z|round(0)|int }}{% endif %}</td>
</tr>
{% else %}
+28 -6
View File
@@ -125,15 +125,37 @@ function formatSize(s) {
return sz.toFixed(i===0?0:1) + ' ' + u[i];
}
function escHtml(s) {
return String(s == null ? '' : s)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
}
function escAttr(s) {
// For values inside double-quoted onclick="..." JS single-quoted strings.
// The existing backslash/quote escaping is kept for JS; HTML-significant
// chars are entity-encoded (the browser decodes them before JS runs,
// so the actual values are unchanged).
return String(s == null ? '' : s)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}
function renderBreadcrumb(path) {
const p = path.split('/').filter(Boolean);
let h = '<span onclick="loadFiles(\'/\')">&#128193; /</span>';
let b = '';
for (let i=0;i<p.length;i++) {
b += '/'+p[i];
const seg = escHtml(p[i]);
h += i===p.length-1
? '<span class="sep">/</span><span class="current">'+p[i]+'</span>'
: '<span class="sep">/</span><span onclick="loadFiles(\''+b.replace(/'/g,"\\'")+'\')">'+p[i]+'</span>';
? '<span class="sep">/</span><span class="current">'+seg+'</span>'
: '<span class="sep">/</span><span onclick="loadFiles(\''+escAttr(b.replace(/'/g,"\\'"))+'\')">'+seg+'</span>';
}
return h;
}
@@ -156,14 +178,14 @@ async function loadFiles(path) {
let h = '';
for (const x of files) {
const fp = (path==='/'?'':path)+'/'+x.name;
const sp = fp.replace(/\\/g,'\\\\').replace(/'/g,"\\'");
const sn = x.name.replace(/\\/g,'\\\\').replace(/'/g,"\\'");
const sp = escAttr(fp.replace(/\\/g,'\\\\').replace(/'/g,"\\'"));
const sn = escAttr(x.name.replace(/\\/g,'\\\\').replace(/'/g,"\\'"));
const icon = x.is_dir ? '&#128193;' : getIcon(x.name);
const action = x.is_dir ? `loadFiles('${sp}')` : `openFile('${sp}','${sn}')`;
h += `<div class="fm-item" onclick="${action}">
<span class="fm-icon ${x.is_dir?'dir':''}">${icon}</span>
<span class="fm-fname ${x.is_dir?'dir':''}">${x.name}</span>
<span class="fm-fsize">${formatSize(x.size)}</span>
<span class="fm-fname ${x.is_dir?'dir':''}">${escHtml(x.name)}</span>
<span class="fm-fsize">${escHtml(formatSize(x.size))}</span>
<button class="fm-delete-btn" onclick="event.stopPropagation();deleteFile('${sp}','${sn}')" title="Delete">&#128465;</button>
</div>`;
}
+1 -1
View File
@@ -36,7 +36,7 @@
<td>{% if g.faction_name %}<span class="badge badge-{{ g.faction_name.lower() }}">{{ g.faction_name }}</span>{% else %}<span class="badge badge-neutral">Neutral</span>{% endif %}</td>
<td>{{ g.member_count }}</td>
<td>{% if g.online_count %}{{ g.online_count }}{% else %}0{% endif %}</td>
<td style="font-size:12px;color:var(--text-light);">{% if g.guild_description %}{{ g.guild_description[:80] }}{% if g.guild_description|length > 80 %}...{% endif %}{% else %}&mdash;{% endif %}</td>
<td style="font-size:12px;color:var(--text-light);">{% if g.guild_description %}{{ g.guild_description[:80] }}{% if g.guild_description|length > 80 %}...{% endif %}{% else %}-{% endif %}</td>
</tr>
{% else %}
<tr><td colspan="5" style="text-align:center;padding:20px;color:var(--text-light);">No guilds found</td></tr>
+1 -1
View File
@@ -65,7 +65,7 @@
</div>
<div class="map-layout">
<div id="map-container">
<div class="map-credit">Map images sourced from <a href="https://awakening.wiki/" target="_blank" rel="noopener">awakening.wiki</a> — a massive thank you for their incredible work mapping Arrakis!</div>
<div class="map-credit">Map images from <a href="https://awakening.wiki/" target="_blank" rel="noopener">awakening.wiki</a> - big thanks to them for mapping out Arrakis!</div>
</div>
<aside class="map-panel">
<section class="panel-section">
+7 -7
View File
@@ -60,7 +60,7 @@
</div>
{% endif %}
{% if is_online %}
<div style="width:100%;font-size:11px;color:#e67e22;margin-top:4px;">Player is online &mdash; edit vitals only when offline. Health data is currently WIP.</div>
<div style="width:100%;font-size:11px;color:#e67e22;margin-top:4px;">Player is online - edit vitals only when offline. Health data is currently WIP.</div>
{% endif %}
</div>
{% endif %}
@@ -162,11 +162,11 @@
<div style="font-size:10px;color:var(--text-muted);padding:4px 8px;">Note: Currency values may be stale due to game server behavior</div>
</div>
{% if is_online %}
<div style="font-size:12px;color:#e67e22;padding:8px 16px;">Player is online &mdash; editing disabled. Log out first.</div>
<div style="font-size:12px;color:#e67e22;padding:8px 16px;">Player is online - editing is disabled. Log out first.</div>
{% else %}
<button onclick="openCurrenciesModal()" class="btn-edit" style="margin:8px 16px;">Edit</button>
{% endif %}
<div style="font-size:11px;color:var(--text-muted);padding:4px 16px 8px;">Read-only. Balances reflect last game save — game server writes deltas on top of DB value.</div>
<div style="font-size:11px;color:var(--text-muted);padding:4px 16px 8px;">Read-only. Balances are from the last game save - the game server applies its own changes on top of these values.</div>
</div>
</div>
@@ -186,7 +186,7 @@
<tr><td>{{ s.track_type }}</td><td>{{ s.xp_amount | format_number }}</td><td>{{ s.level }}</td></tr>
{% endfor %}
{% if tech_knowledge is not none %}
<tr><td>Tech Knowledge Points</td><td>{{ tech_knowledge | format_number }}</td><td>&mdash;</td></tr>
<tr><td>Tech Knowledge Points</td><td>{{ tech_knowledge | format_number }}</td><td>-</td></tr>
{% endif %}
</tbody>
</table>
@@ -289,11 +289,11 @@
<div class="detail-section">
<h2>Inventory</h2>
{% if is_online %}
<div style="font-size:12px;color:#e67e22;padding:0 16px 8px;">Player is online &mdash; editing disabled. Log out first.</div>
<div style="font-size:12px;color:#e67e22;padding:0 16px 8px;">Player is online - editing is disabled. Log out first.</div>
{% endif %}
<div class="experimental-banner">
<span class="banner-icon">&#9888;</span>
<span class="banner-text">Inventory editing is still being forged in the deep desert. Items may not persist, or the sandworm may eat your edits. <strong>Use with caution</strong> — the spice must flow, but bugs may flow with it.</span>
<span class="banner-text">Inventory editing is still experimental and items might not save properly. Double-check your changes in-game. <strong>Use with caution</strong>.</span>
</div>
<div class="card">
<div class="card-body">
@@ -642,7 +642,7 @@
<form onsubmit="return submitEdit(this, '/api/edit_xp')">
<input type="hidden" name="player_id" value="{{ player.player_controller_id or '' }}">
<input type="hidden" name="track_type" value="{{ s.track_type }}">
<label>{{ s.track_type }} — XP: <input type="number" name="xp_amount" value="{{ s.xp_amount }}" style="width:100px;">
<label>{{ s.track_type }} - XP: <input type="number" name="xp_amount" value="{{ s.xp_amount }}" style="width:100px;">
Level: <input type="number" step="0.1" name="level" value="{{ s.level }}" style="width:80px;">
</label>
<button type="submit" class="btn-save" style="font-size:11px;padding:2px 8px;">Save</button>
+5 -5
View File
@@ -70,10 +70,10 @@
<tr>
<td><a href="/players/{{ p.id }}">{{ p.player_name or 'Unknown' }}</a></td>
<td>{% if p.online_status %}<span class="badge badge-{{ p.online_status.lower() }}">{{ p.online_status }}</span>{% else %}<span class="badge badge-offline">Unknown</span>{% endif %}</td>
<td>{% if p.faction_name %}<span class="badge badge-{{ p.faction_name.lower() }}">{{ p.faction_name }}</span>{% else %}&mdash;{% endif %}</td>
<td>{% if p.guild_name %}{{ p.guild_name }}{% else %}&mdash;{% endif %}</td>
<td>{{ p.map or '&mdash;'|safe }}</td>
<td style="font-size:12px;">{% if p.player_controller_id %}<span class="ip-cell" data-id="{{ p.player_controller_id }}" data-ip="{{ p.ip_address or '' }}">{{ p.ip_address or '—' }}</span>{% else %}&mdash;{% endif %}</td>
<td>{% if p.faction_name %}<span class="badge badge-{{ p.faction_name.lower() }}">{{ p.faction_name }}</span>{% else %}-{% endif %}</td>
<td>{% if p.guild_name %}{{ p.guild_name }}{% else %}-{% endif %}</td>
<td>{{ p.map or '-' }}</td>
<td style="font-size:12px;">{% if p.player_controller_id %}<span class="ip-cell" data-id="{{ p.player_controller_id }}" data-ip="{{ p.ip_address or '' }}">{{ p.ip_address or '-' }}</span>{% else %}-{% endif %}</td>
<td style="font-size:12px;">{{ p.funcom_id or p.account_email }}</td>
<td>{{ p.vehicle_count }}</td>
<td>{{ p.building_count }}</td>
@@ -228,7 +228,7 @@ document.querySelectorAll('.ip-cell').forEach(cell => {
const resp = await csrfFetch('/api/set_player_ip', { method: 'POST', body: form });
const data = await resp.json();
if (data.success) {
this.textContent = newIp || '—';
this.textContent = newIp || '-';
this.dataset.ip = newIp;
alert('IP updated!');
} else {
+816 -55
View File
@@ -93,6 +93,248 @@
</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">
@@ -126,6 +368,8 @@
</div>
</div>
</div>
<div class="card">
<div class="card-header">World Partitions</div>
<div class="table-wrap">
@@ -165,10 +409,10 @@
{% 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>
<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>
@@ -204,25 +448,6 @@
</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: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">Pod Status</div>
<div class="card-body">
@@ -233,6 +458,25 @@
</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>
@@ -240,11 +484,11 @@
</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.
<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.
<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>
@@ -263,12 +507,12 @@
<div class="card">
<div class="card-header" style="cursor:pointer;" onclick="document.getElementById('debug-section').classList.toggle('hidden');">
<span>🐛 Debug Logging</span>
<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.
<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;">
@@ -281,9 +525,11 @@
</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>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">
@@ -324,24 +570,6 @@
</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>
{% endif %}
{% endblock %}
@@ -558,7 +786,7 @@ 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.'
'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;
@@ -611,6 +839,539 @@ document.getElementById('bg-btn-restart')?.addEventListener('click', function()
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, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
}
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');
@@ -706,7 +1467,7 @@ async function loadAuditLogs(action = '', user = '', severity = '', limit = 100,
const data = await resp.json();
if (!data.success) {
tbody.innerHTML = '<tr><td colspan="5" style="padding:20px;text-align:center;color:var(--danger);">Error: ' + data.error + '</td></tr>';
tbody.innerHTML = '<tr><td colspan="5" style="padding:20px;text-align:center;color:var(--danger);">Error: ' + escapeHtml(data.error || 'unknown') + '</td></tr>';
return;
}
@@ -726,22 +1487,22 @@ async function loadAuditLogs(action = '', user = '', severity = '', limit = 100,
document.getElementById('audit-warning-count').textContent = warningCount;
document.getElementById('audit-error-count').textContent = errorCount;
// Render table
// 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);">' + timestamp + '</td>' +
'<td style="padding:8px;font-weight:600;">' + (log.action || '-') + '</td>' +
'<td style="padding:8px;">' + (log.user || '-') + '</td>' +
'<td style="padding:8px;' + severityColor + '">' + (log.severity || 'info') + '</td>' +
'<td style="padding:8px;color:var(--text-muted);font-size:11px;max-width:200px;overflow:hidden;text-overflow:ellipsis;">' + details + '</td>' +
'<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: ' + e.message + '</td></tr>';
tbody.innerHTML = '<tr><td colspan="5" style="padding:20px;text-align:center;color:var(--danger);">Error: ' + escapeHtml(e.message) + '</td></tr>';
}
}
+3 -3
View File
@@ -72,7 +72,7 @@
<!-- Pod Logs Modal -->
<div id="logs-modal" class="modal-overlay" style="display:none;" onclick="if(event.target===this)closeModal('logs-modal')">
<div class="modal" style="max-width:900px;">
<div class="modal-header"><h3>Pod Logs — <span id="logs-pod-name"></span></h3></div>
<div class="modal-header"><h3>Pod Logs - <span id="logs-pod-name"></span></h3></div>
<div id="logs-loading" style="padding:20px;text-align:center;color:var(--text-muted);">Loading logs...</div>
<pre id="logs-content" style="max-height:500px;overflow:auto;white-space:pre-wrap;display:none;margin:0;padding:16px;font-size:12px;background:var(--bg-card);color:var(--text);border-top:1px solid var(--border);"></pre>
<div class="modal-actions" style="padding:12px 16px;border-top:1px solid var(--border);">
@@ -84,7 +84,7 @@
<!-- Pod Describe Modal -->
<div id="describe-modal" class="modal-overlay" style="display:none;" onclick="if(event.target===this)closeModal('describe-modal')">
<div class="modal" style="max-width:900px;">
<div class="modal-header"><h3>Describe Pod — <span id="describe-pod-name"></span></h3></div>
<div class="modal-header"><h3>Describe Pod - <span id="describe-pod-name"></span></h3></div>
<div id="describe-loading" style="padding:20px;text-align:center;color:var(--text-muted);">Loading...</div>
<pre id="describe-content" style="max-height:500px;overflow:auto;white-space:pre-wrap;display:none;margin:0;padding:16px;font-size:12px;background:var(--bg-card);color:var(--text);border-top:1px solid var(--border);"></pre>
<div class="modal-actions" style="padding:12px 16px;border-top:1px solid var(--border);">
@@ -324,7 +324,7 @@ function promptDeletePod(name, safe) {
const btn = document.getElementById('delete-confirm-btn');
if (safe) {
title.textContent = 'Delete DB Backup Pod';
msg.innerHTML = 'This pod stores database backups. It is <strong>safe to delete</strong> — Kubernetes will recreate it automatically. Continue?';
msg.innerHTML = 'This pod stores database backups. It is <strong>safe to delete</strong> - Kubernetes will recreate it on its own. Continue?';
btn.className = 'btn-edit';
btn.textContent = 'Delete Backup Pod';
} else {
+2 -2
View File
@@ -53,8 +53,8 @@
<td><a href="/vehicles/{{ v.id }}">{{ v.id }}</a></td>
<td style="font-size:12px;">{{ v.class | class_name }}</td>
<td>{{ v.actor_name or 'N/A' }}</td>
<td>{% if v.owner_name %}<a href="/players/{{ v.owner_pawn_id }}" style="font-weight:500;">{{ v.owner_name }}</a>{% else %}&mdash;{% endif %}</td>
<td>{% if v.pilot_name %}<span class="badge badge-online">Active</span> <a href="/players/{{ v.pilot_pawn_id }}">{{ v.pilot_name }}</a>{% else %}&mdash;{% endif %}</td>
<td>{% if v.owner_name %}<a href="/players/{{ v.owner_pawn_id }}" style="font-weight:500;">{{ v.owner_name }}</a>{% else %}-{% endif %}</td>
<td>{% if v.pilot_name %}<span class="badge badge-online">Active</span> <a href="/players/{{ v.pilot_pawn_id }}">{{ v.pilot_name }}</a>{% else %}-{% endif %}</td>
<td>{{ v.map or 'N/A' }}</td>
<td style="font-size:11px;font-family:monospace;max-width:250px;word-break:break-all;">{{ v.transform_text or '' }}</td>
</tr>