From 6dab454830ba442270cf35123ef8df6edf936924 Mon Sep 17 00:00:00 2001 From: Reditus Date: Tue, 12 May 2026 01:55:01 +0100 Subject: [PATCH] Replace hardcoded IPs with placeholders in templates and services --- app/services/admin.py | 2 +- setup.ps1 | 55 +++++++++++++++++++++++++---------------- templates/guilds.html | 2 +- templates/overview.html | 2 +- templates/players.html | 2 +- 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/app/services/admin.py b/app/services/admin.py index cc5a207..a420050 100644 --- a/app/services/admin.py +++ b/app/services/admin.py @@ -266,7 +266,7 @@ class AdminService: name_match = re.search(r'Name=([^?#]+)', line) if name_match: current_player = name_match.group(1).split('#')[0] - if current_player and current_ip and current_ip != '65.21.198.100': + if current_player and current_ip and current_ip != 'YOUR_SERVER_IP': ip_to_player[current_ip] = current_player current_ip = None diff --git a/setup.ps1 b/setup.ps1 index e19d9ee..ddaaee8 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -164,36 +164,43 @@ $AuthPass = "changeme" # Try to detect server IP from known_hosts $KnownHosts = Join-Path $env:USERPROFILE ".ssh\known_hosts" if (Test-Path $KnownHosts) { - $hosts = Select-String -Path $KnownHosts -Pattern '^\d+\.\d+\.\d+\.\d+' | ForEach-Object { - if ($_ -match '^(\d+\.\d+\.\d+\.\d+)') { $matches[1] } - } | Select-Object -Unique - if ($hosts.Count -gt 0) { - $ServerHost = $hosts[-1] - Write-Host " Detected previous server IP: $ServerHost" -ForegroundColor Green + $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] + } + } + if ($ips.Count -gt 0) { + $ServerHost = $ips[-1] + Write-Host " Detected server IP from SSH history: $ServerHost" -ForegroundColor Green } } -# Test SSH if we have a key and a real IP -if ($FoundKey -and $ServerHost -ne "YOUR_SERVER_IP") { - # Test SSH - $testOut = ssh -i $FoundKey -o StrictHostKeyChecking=accept-new -o ConnectTimeout=10 -o BatchMode=yes "dune@$ServerHost" "echo ok" 2>$null - if ($testOut -eq "ok") { - Write-Host " SSH connection OK" -ForegroundColor Green +# Ask for IP first so we can try SSH to detect namespace +Write-Host "" +$val = Read-Host " Server Host [$ServerHost]" +if ($val) { $ServerHost = $val } - # Auto-detect namespace - $nsOut = ssh -i $FoundKey -o StrictHostKeyChecking=accept-new -o ConnectTimeout=10 -o BatchMode=yes "dune@$ServerHost" "sudo kubectl get namespaces -o name" 2>$null +# Try SSH with the confirmed IP to auto-detect namespace +if ($FoundKey -and $ServerHost -ne "YOUR_SERVER_IP") { + Write-Host " Testing SSH connection..." -ForegroundColor Yellow + $testOut = cmd /c "ssh -i `"$FoundKey`" -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 -o BatchMode=yes dune@$ServerHost echo ok 2>nul" + if ($testOut -match "ok") { + Write-Host " SSH connection OK" -ForegroundColor Green + $nsOut = cmd /c "ssh -i `"$FoundKey`" -o StrictHostKeyChecking=accept-new -o ConnectTimeout=10 -o BatchMode=yes dune@$ServerHost sudo kubectl get namespaces -o name 2>nul" if ($nsOut) { foreach ($line in $nsOut -split "`n") { $ns = $line -replace 'namespace/', '' if ($ns -match '^funcom-seabass-') { $K8sNamespace = $ns - Write-Host " Namespace: $K8sNamespace" -ForegroundColor Green + Write-Host " Auto-detected namespace: $K8sNamespace" -ForegroundColor Green break } } } } else { - Write-Host " [WARN] SSH failed. Using defaults." -ForegroundColor Yellow + Write-Host " [WARN] SSH failed for $ServerHost. You may need to enter the namespace manually." -ForegroundColor Yellow } } @@ -202,17 +209,23 @@ Write-Host "" Write-Host " Review settings (press Enter to accept, or type new value):" -ForegroundColor Cyan Write-Host "" -$val = Read-Host " Server Host [$ServerHost]" -if ($val) { $ServerHost = $val } +Write-Host " Server Host: $ServerHost" $val = Read-Host " Server User [$ServerUser]" if ($val) { $ServerUser = $val } -$val = Read-Host " SSH Key Path [$FoundKey]" -if ($val) { $FoundKey = $val } +Write-Host " SSH Key Path: $FoundKey" -$val = Read-Host " K8s Namespace [$K8sNamespace]" +if (-not $K8sNamespace) { + Write-Host " [INFO] To find your namespace, run: ssh dune@YOUR_IP 'sudo kubectl get namespaces'" -ForegroundColor Cyan + $K8sHint = "funcom-seabass-" +} else { + $K8sHint = $K8sNamespace +} + +$val = Read-Host " K8s Namespace [$K8sHint]" if ($val) { $K8sNamespace = $val } +elseif (-not $K8sNamespace) { $K8sNamespace = "" } $val = Read-Host " Dashboard Port [$DashboardPort]" if ($val) { $DashboardPort = $val } diff --git a/templates/guilds.html b/templates/guilds.html index da5567a..cc5f190 100644 --- a/templates/guilds.html +++ b/templates/guilds.html @@ -11,7 +11,7 @@
SSH Tunnel Not Detected
Start the SSH tunnel first, then refresh. -
ssh -i $env:TEMP\dune-awakening-server-sshKey -L 15433:localhost:15433 -N dune@65.21.198.100 +
ssh -i $env:TEMP\dune-awakening-server-sshKey -L 15433:localhost:15433 -N dune@YOUR_SERVER_IP
{% elif db_error %}
Database Error: {{ db_error }}
diff --git a/templates/overview.html b/templates/overview.html index 2d576aa..70b352f 100644 --- a/templates/overview.html +++ b/templates/overview.html @@ -13,7 +13,7 @@ The PostgreSQL database is not reachable. Start the SSH tunnel in a separate terminal:

$key = "$env:TEMP\dune-awakening-server-sshKey"
- ssh -i $key -L 15433:localhost:15433 -N dune@65.21.198.100 + ssh -i $key -L 15433:localhost:15433 -N dune@YOUR_SERVER_IP {% elif db_error %}
diff --git a/templates/players.html b/templates/players.html index dc4ebba..ec46812 100644 --- a/templates/players.html +++ b/templates/players.html @@ -11,7 +11,7 @@
SSH Tunnel Not Detected
Start the SSH tunnel first, then refresh. -
ssh -i $env:TEMP\dune-awakening-server-sshKey -L 15433:localhost:15433 -N dune@65.21.198.100 +
ssh -i $env:TEMP\dune-awakening-server-sshKey -L 15433:localhost:15433 -N dune@YOUR_SERVER_IP
{% elif db_error %}
Database Error: {{ db_error }}