From c74ef9cf9c2a13bb755bc74ee306d8b66bb219bb Mon Sep 17 00:00:00 2001 From: Reditus Date: Fri, 15 May 2026 02:18:17 +0100 Subject: [PATCH] Update to latest version --- $null | 0 .specstory/.project.json | 5 +++ .specstory/cli/config.toml | 79 ++++++++++++++++++++++++++++++++++++ app/config.py | 12 ++++-- app/routes/auth.py | 2 +- app/routes/main.py | 22 +++++++--- setup.ps1 | 56 ++++++++++++++++++++----- templates/base.html | 37 ++++++----------- templates/director.html | 6 +-- templates/file_view.html | 2 +- templates/files.html | 2 +- templates/login.html | 2 +- templates/player_detail.html | 14 +++---- templates/players.html | 14 +++---- templates/server.html | 8 ++-- 15 files changed, 191 insertions(+), 70 deletions(-) create mode 100644 $null create mode 100644 .specstory/.project.json create mode 100644 .specstory/cli/config.toml diff --git a/$null b/$null new file mode 100644 index 0000000..e69de29 diff --git a/.specstory/.project.json b/.specstory/.project.json new file mode 100644 index 0000000..9de9622 --- /dev/null +++ b/.specstory/.project.json @@ -0,0 +1,5 @@ +{ + "workspace_id": "6c5e-09e0-3a93-f4a1", + "workspace_id_at": "2026-05-14T10:44:35Z", + "project_name": "DuneDashboard" +} \ No newline at end of file diff --git a/.specstory/cli/config.toml b/.specstory/cli/config.toml new file mode 100644 index 0000000..9336aae --- /dev/null +++ b/.specstory/cli/config.toml @@ -0,0 +1,79 @@ +# SpecStory CLI Configuration +# +# This is the project-level config file for SpecStory CLI. +# All settings here apply to this project unless overridden by CLI flags. +# +# Uncomment (remove the #) the line and edit any setting below to change the default behavior. +# For more information, see: https://docs.specstory.com/integrations/terminal-coding-agents/usage + +[local_sync] +# Write markdown files locally. (default: true) +# enabled = false # equivalent to --only-cloud-sync + +# Custom output directory for markdown files. +# Default: ./.specstory/history (relative to the project directory) +# output_dir = "~/.specstory/history" # equivalent to --output-dir "~/.specstory/history" + +# Use local timezone for file name and content timestamps (default: false, UTC) +# local_time_zone = true # equivalent to --local-time-zone + +[cloud_sync] +# Sync session data to SpecStory Cloud. (default: true, when logged in to SpecStory Cloud) +# enabled = false # equivalent to --no-cloud-sync + +[logging] +# Write logs to .specstory/debug/debug.log (default: false) +# log = true # equivalent to --log + +# Debug-level output, requires console or log (default: false) +# debug = true # equivalent to --debug + +# Custom output directory for debug data. +# Default: ./.specstory/debug (relative to the project directory) +# debug_dir = "~/.specstory/debug" # equivalent to --debug-dir "~/.specstory/debug" + +# Error/warn/info output to stdout (default: false) +# console = true # equivalent to --console + +# Suppress all non-error output (default: false) +# silent = true # equivalent to --silent + +[version_check] +# Check for new versions of the CLI on startup. +# Default: true +# enabled = false # equivalent to --no-version-check + +[analytics] +# Send anonymous product usage analytics to help improve SpecStory. +# Default: true +# enabled = false # equivalent to --no-usage-analytics + +[telemetry] +# OTLP gRPC collector endpoint (e.g., "localhost:4317" or "http://localhost:4317") +# endpoint = "localhost:4317" + +# Override the default service name (default: "specstory-cli") +# service_name = "my-service-name" + +# Include user prompt text in telemetry spans (default: true) +# prompts = false + +[providers] +# Agent execution commands by provider (used by specstory run) +# Pass custom flags (e.g. claude_cmd = "claude --allow-dangerously-skip-permissions") +# Use of these is equivalent to -c "custom command" + +# Claude Code command +# claude_cmd = "claude" + +# Codex CLI command +# codex_cmd = "codex" + +# Cursor CLI command +# cursor_cmd = "cursor-agent" + +# Droid CLI command +# droid_cmd = "droid" + +# Gemini CLI command +# gemini_cmd = "gemini" diff --git a/app/config.py b/app/config.py index 2593825..069c572 100644 --- a/app/config.py +++ b/app/config.py @@ -45,8 +45,8 @@ DEFAULTS = { 'port': 18888, }, 'firewall': { - 'block_filebrowser': False, - 'block_director': False, + 'block_filebrowser': True, + 'block_director': True, 'block_postgres': True, }, 'cache': { @@ -171,17 +171,21 @@ def load_settings(settings_path=None): # Backward compatibility: migrate old plaintext password to hash # This is a one-time migration that hashes the password and removes plaintext auth = settings.get('auth', {}) + password_migrated = False if auth.get('password') and not auth.get('password_hash'): try: from argon2 import PasswordHasher ph = PasswordHasher() settings['auth']['password_hash'] = ph.hash(str(auth['password'])) - # Remove plaintext after hashing del settings['auth']['password'] + password_migrated = True logger.info("Migrated plaintext password to Argon2 hash") except ImportError: logger.error("argon2-cffi not installed. Password hashing unavailable.") - # Fallback: keep plaintext for now but log warning settings['auth']['password_hash'] = None + if password_migrated: + settings['dashboard']['secret_key'] = secrets.token_hex(32) + logger.warning("Rotated secret_key to invalidate sessions after password migration") + return settings diff --git a/app/routes/auth.py b/app/routes/auth.py index 45d8e14..0583670 100644 --- a/app/routes/auth.py +++ b/app/routes/auth.py @@ -24,7 +24,7 @@ def init_auth(app, settings, limiter=None): return None @app.route('/login', methods=['GET', 'POST']) - @limiter.limit("10 per minute") if limiter else lambda f: f + @limiter.limit("5 per hour") if limiter else lambda f: f def login(): if current_user.is_authenticated: return redirect(url_for('overview')) diff --git a/app/routes/main.py b/app/routes/main.py index c69138f..05117f0 100644 --- a/app/routes/main.py +++ b/app/routes/main.py @@ -317,14 +317,24 @@ def register_routes(app, services, settings): def events_page(): game_events = [] event_logs = [] + + def safe_query(table, cols, order_col, limit): + try: + return db.query(f"SELECT {cols} FROM {table} ORDER BY {order_col} DESC LIMIT {limit}") or [] + except Exception as e: + logger.error(f"Error fetching {table}: {e}") + return [] + try: - game_events = db.query("SELECT id, event_type, actor_id, actor_name, map, universe_time, x, y, z FROM dune.game_events ORDER BY universe_time DESC LIMIT 50") or [] - except Exception as e: - logger.error(f"Error fetching game_events: {e}") + game_events = safe_query("dune.game_events", "*", "universe_time", 50) + except Exception: + pass + try: - event_logs = db.query("SELECT id, event_type, category, function_name, message, event_time, meta FROM dune.event_log ORDER BY event_time DESC LIMIT 100") or [] - except Exception as e: - logger.error(f"Error fetching event_logs: {e}") + event_logs = safe_query("dune.event_log", "*", "event_time", 100) + except Exception: + pass + return render_template('events.html', game_events=game_events, event_logs=event_logs) # Chat diff --git a/setup.ps1 b/setup.ps1 index b99f149..91fc352 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -167,22 +167,56 @@ $FileBrowserPort = "18888" $AuthUser = "admin" $AuthPass = "" -# Try to detect VM IP from known_hosts -$KnownHosts = Join-Path $env:USERPROFILE ".ssh\known_hosts" -if (Test-Path $KnownHosts) { - $content = Get-Content $KnownHosts - $ips = @() - foreach ($line in $content) { - if ($line -match '\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b') { - $ips += $matches[1] +# Try to detect VM IP - prioritize local Hyper-V, then local network IPs from known_hosts +function Test-IsLocalIP($ip) { + if ($ip -match '^192\.168\.') { return $true } + if ($ip -match '^10\.') { return $true } + if ($ip -match '^172\.(1[6-9]|2[0-9]|3[0-1])\.') { return $true } + return $false +} + +# First: try direct Hyper-V detection +$vmIp = $null +try { + $vmAdapter = Get-VMNetworkAdapter -VMName 'dune-awakening' -ErrorAction SilentlyContinue + if ($vmAdapter -and $vmAdapter.IPAddresses) { + $localIp = $vmAdapter.IPAddresses | Where-Object { Test-IsLocalIP $_ } + if ($localIp) { + $vmIp = $localIp[0] + Write-Host " Detected local Hyper-V VM IP: $vmIp" -ForegroundColor Green } } - if ($ips.Count -gt 0) { - $VmHost = $ips[-1] - Write-Host " Detected VM IP from SSH history: $VmHost" -ForegroundColor Green +} catch { } + +if (-not $vmIp) { + # Fallback: scan known_hosts and prioritize local IPs + $KnownHosts = Join-Path $env:USERPROFILE ".ssh\known_hosts" + if (Test-Path $KnownHosts) { + $content = Get-Content $KnownHosts + $localIps = @() + $publicIps = @() + foreach ($line in $content) { + if ($line -match '\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b') { + $ip = $matches[1] + if (Test-IsLocalIP $ip) { + $localIps += $ip + } else { + $publicIps += $ip + } + } + } + if ($localIps.Count -gt 0) { + $vmIp = $localIps[-1] + Write-Host " Detected local IP from SSH history: $vmIp" -ForegroundColor Green + } elseif ($publicIps.Count -gt 0) { + $vmIp = $publicIps[-1] + Write-Host " Detected IP from SSH history: $vmIp (verify this is your local VM)" -ForegroundColor Yellow + } } } +if ($vmIp) { $VmHost = $vmIp } + # Auto-detect external IP (try external service first, then local interfaces) try { $HostIp = (Invoke-WebRequest -Uri "https://api.ipify.org" -UseBasicParsing -TimeoutSec 5).Content.Trim() diff --git a/templates/base.html b/templates/base.html index e64e140..b54be77 100644 --- a/templates/base.html +++ b/templates/base.html @@ -3,8 +3,8 @@ - {% block title %}Dune Awakening Server Dashboard{% endblock %} + @@ -40,8 +40,15 @@
- {% block scripts %}{% endblock %} + {% block scripts %}{% endblock %} - + \ No newline at end of file diff --git a/templates/director.html b/templates/director.html index 3a99f00..4b7c6dc 100644 --- a/templates/director.html +++ b/templates/director.html @@ -634,7 +634,7 @@ document.getElementById('btn-clear-world')?.addEventListener('click', async func this.disabled = true; this.textContent = 'Clearing...'; try { - const resp = await fetch('/api/director/character_transfer_clear', { method: 'POST' }); + const resp = await csrfFetch('/api/director/character_transfer_clear', { method: 'POST' }); if (!resp.ok) throw new Error(`HTTP ${resp.status}`); document.getElementById('world-status-msg').textContent = 'World status overrides cleared.'; this.textContent = 'Cleared!'; @@ -655,7 +655,7 @@ document.getElementById('btn-apply-transfer')?.addEventListener('click', async f FreeToTransferCharactersTo: document.getElementById('free-transfer-to').checked }; try { - const resp = await fetch('/api/director/character_transfer', { + const resp = await csrfFetch('/api/director/character_transfer', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(config) @@ -674,7 +674,7 @@ document.getElementById('btn-clear-transfer')?.addEventListener('click', async f this.disabled = true; this.textContent = 'Clearing...'; try { - const resp = await fetch('/api/director/character_transfer_clear', { method: 'POST' }); + const resp = await csrfFetch('/api/director/character_transfer_clear', { method: 'POST' }); if (!resp.ok) throw new Error(`HTTP ${resp.status}`); document.getElementById('transfer-status-msg').textContent = 'Transfer settings cleared.'; this.textContent = 'Cleared!'; diff --git a/templates/file_view.html b/templates/file_view.html index 4eb0946..9ffd0c3 100644 --- a/templates/file_view.html +++ b/templates/file_view.html @@ -121,7 +121,7 @@ async function saveFile() { const form = new FormData(); form.append('path', filePath); form.append('content', editor.value); - const resp = await fetch('/api/files/save', { method: 'POST', body: form }); + const resp = await csrfFetch('/api/files/save', { method: 'POST', body: form }); const data = await resp.json(); if (!data.success) { error.textContent = 'Error: ' + (data.error || 'Failed to save file'); diff --git a/templates/files.html b/templates/files.html index 9c8b201..f929802 100644 --- a/templates/files.html +++ b/templates/files.html @@ -93,7 +93,7 @@ async function loadFiles(path) { try { const form = new FormData(); form.append('path', path); - const resp = await fetch('/api/files/list', { method: 'POST', body: form }); + const resp = await csrfFetch('/api/files/list', { method: 'POST', body: form }); const data = await resp.json(); if (!data.success) { list.innerHTML = ''; diff --git a/templates/login.html b/templates/login.html index 22a6b8f..75d0cd5 100644 --- a/templates/login.html +++ b/templates/login.html @@ -110,7 +110,7 @@ {% endwith %}
- +
diff --git a/templates/player_detail.html b/templates/player_detail.html index 2ba4bd8..ebfff9c 100644 --- a/templates/player_detail.html +++ b/templates/player_detail.html @@ -468,7 +468,7 @@ function closeModal(id) { async function submitEdit(form, url) { const data = new FormData(form); try { - const resp = await fetch(url, { method: 'POST', body: data }); + const resp = await csrfFetch(url, { method: 'POST', body: data }); const result = await resp.json(); if (result.success) { alert('Saved successfully!'); @@ -486,7 +486,7 @@ async function submitSpecEdit() { const form = document.getElementById('spec-form'); const data = new FormData(form); try { - const resp = await fetch('/api/edit_tech_knowledge', { method: 'POST', body: data }); + const resp = await csrfFetch('/api/edit_tech_knowledge', { method: 'POST', body: data }); const result = await resp.json(); if (result.success) { alert('XP saved!'); @@ -526,7 +526,7 @@ async function submitCurrencyEdit(currencyId) { data.append('currency_id', currencyId); data.append('new_balance', newBalance); try { - const resp = await fetch('/api/edit_currency', { method: 'POST', body: data }); + const resp = await csrfFetch('/api/edit_currency', { method: 'POST', body: data }); const result = await resp.json(); if (result.success) { alert('Currency updated successfully!'); @@ -543,7 +543,7 @@ async function submitVitalsEdit() { const form = document.getElementById('vitals-form'); const data = new FormData(form); try { - const resp = await fetch('/api/edit_vitals', { method: 'POST', body: data }); + const resp = await csrfFetch('/api/edit_vitals', { method: 'POST', body: data }); const result = await resp.json(); if (result.success) { alert('Vitals updated successfully!'); @@ -565,7 +565,7 @@ async function editItem(itemId, field, currentValue) { data.append('field', field); data.append('value', newValue); try { - const resp = await fetch('/api/edit_item', { method: 'POST', body: data }); + const resp = await csrfFetch('/api/edit_item', { method: 'POST', body: data }); const result = await resp.json(); if (result.success) { const span = document.getElementById('item-' + field.replace('_', '-') + '-' + itemId); @@ -584,7 +584,7 @@ async function deleteItem(itemId, templateName) { const data = new FormData(); data.append('item_id', itemId); try { - const resp = await fetch('/api/delete_item', { method: 'POST', body: data }); + const resp = await csrfFetch('/api/delete_item', { method: 'POST', body: data }); const result = await resp.json(); if (result.success) { const row = document.getElementById('item-row-' + itemId); @@ -606,7 +606,7 @@ async function submitAddItem() { const form = document.getElementById('add-item-form'); const data = new FormData(form); try { - const resp = await fetch('/api/add_item', { method: 'POST', body: data }); + const resp = await csrfFetch('/api/add_item', { method: 'POST', body: data }); const result = await resp.json(); if (result.success) { alert('Item added successfully!'); diff --git a/templates/players.html b/templates/players.html index ec46812..7d6b80e 100644 --- a/templates/players.html +++ b/templates/players.html @@ -117,7 +117,7 @@ document.querySelectorAll('.btn-action[data-action="kick"]').forEach(btn => { try { const form = new FormData(); form.append('player_id', pid); - const resp = await fetch('/api/kick_player', { method: 'POST', body: form }); + const resp = await csrfFetch('/api/kick_player', { method: 'POST', body: form }); const data = await resp.json(); alert(data.success ? data.message : 'Error: ' + (data.error || 'Failed')); } catch (e) { @@ -141,7 +141,7 @@ document.querySelectorAll('.btn-action[data-action="ban"]').forEach(btn => { form.append('duration', duration); form.append('reason', reason); form.append('note', note); - const resp = await fetch('/api/ban_player', { method: 'POST', body: form }); + const resp = await csrfFetch('/api/ban_player', { method: 'POST', body: form }); const data = await resp.json(); alert(data.success ? `Banned ${name} for ${duration} minutes` : 'Error: ' + (data.error || 'Failed')); } catch (e) { @@ -157,7 +157,7 @@ document.querySelectorAll('.btn-action[data-action="unban"]').forEach(btn => { try { const form = new FormData(); form.append('player_id', pid); - const resp = await fetch('/api/unban_player', { method: 'POST', body: form }); + const resp = await csrfFetch('/api/unban_player', { method: 'POST', body: form }); const data = await resp.json(); alert(data.success ? `Unbanned ${name}` : 'Error: ' + (data.error || 'Failed')); } catch (e) { @@ -172,7 +172,7 @@ document.querySelectorAll('.btn-action[data-action="viewban"]').forEach(btn => { try { const form = new FormData(); form.append('player_id', pid); - const resp = await fetch('/api/get_player_ban', { method: 'POST', body: form }); + const resp = await csrfFetch('/api/get_player_ban', { method: 'POST', body: form }); const data = await resp.json(); if (data.banned) { alert(`Ban Info for ${name}:\n\nDuration: ${data.duration} minutes\nReason: ${data.reason}\nNote: ${data.note || 'None'}\nBanned: ${data.banned_at}\nExpires: ${data.expires_at}`); @@ -191,7 +191,7 @@ document.querySelectorAll('.btn-action[data-action="history"]').forEach(btn => { try { const form = new FormData(); form.append('player_id', pid); - const resp = await fetch('/api/get_player_history', { method: 'POST', body: form }); + const resp = await csrfFetch('/api/get_player_history', { method: 'POST', body: form }); const data = await resp.json(); if (data.history && data.history.length > 0) { let msg = `Action History for ${name}:\n\n`; @@ -225,7 +225,7 @@ document.querySelectorAll('.ip-cell').forEach(cell => { const form = new FormData(); form.append('player_id', pid); form.append('ip_address', newIp); - const resp = await fetch('/api/set_player_ip', { method: 'POST', body: form }); + const resp = await csrfFetch('/api/set_player_ip', { method: 'POST', body: form }); const data = await resp.json(); if (data.success) { this.textContent = newIp || '—'; @@ -244,7 +244,7 @@ async function detectIps() { try { const btn = document.querySelector('button[onclick="detectIps()"]'); if (btn) { btn.disabled = true; btn.textContent = 'Detecting...'; } - const resp = await fetch('/api/detect_player_ips', { method: 'POST' }); + const resp = await csrfFetch('/api/detect_player_ips', { method: 'POST' }); const data = await resp.json(); if (data.success) { console.log('IP detection:', data.message); diff --git a/templates/server.html b/templates/server.html index 5174b2d..933e6de 100644 --- a/templates/server.html +++ b/templates/server.html @@ -270,7 +270,7 @@ document.querySelectorAll('.btn-action').forEach(btn => { const form = new FormData(); form.append('deployment', deploy); form.append('action', action); - const resp = await fetch('/server/action', { method: 'POST', body: form }); + 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) { @@ -298,7 +298,7 @@ document.querySelectorAll('.partition-btn').forEach(btn => { const form = new FormData(); form.append('deployment', deploy); form.append('action', 'restart'); - const resp = await fetch('/server/action', { method: 'POST', body: form }); + 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) { @@ -344,7 +344,7 @@ async function bgAction(action, btn) { const url = action === 'update' ? '/server/battlegroup/update' : '/server/battlegroup/action'; const form = new FormData(); form.append('action', action); - const resp = await fetch(url, { method: 'POST', body: form }); + const 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) { @@ -435,7 +435,7 @@ async function loadFwStatus() { try { const form = new FormData(); form.append('port', port); - const resp = await fetch('/server/firewall/' + action, { method: 'POST', body: form }); + 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();