567 lines
20 KiB
Python
567 lines
20 KiB
Python
import os
|
|
import sys
|
|
import time
|
|
import paramiko
|
|
|
|
HOST = "140.44.44.80"
|
|
USER = "root"
|
|
KEY_FILE = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
|
|
|
|
def main():
|
|
print(f"Connecting to {USER}@{HOST}...")
|
|
ssh = paramiko.SSHClient()
|
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
ssh.connect(HOST, username=USER, key_filename=KEY_FILE, timeout=10)
|
|
print("Connected!")
|
|
|
|
def run(cmd, check=True):
|
|
print(f"\n>>> [RUN] {cmd}")
|
|
stdin, stdout, stderr = ssh.exec_command(cmd)
|
|
while not stdout.channel.exit_status_ready():
|
|
time.sleep(0.5)
|
|
out = stdout.read().decode()
|
|
err = stderr.read().decode()
|
|
rc = stdout.channel.recv_exit_status()
|
|
if out:
|
|
print(out.strip())
|
|
if err and "warning" not in err.lower():
|
|
print(f"[STDERR] {err.strip()}", file=sys.stderr)
|
|
if check and rc != 0:
|
|
print(f"[FAIL] Exit code: {rc}", file=sys.stderr)
|
|
return rc, out, err
|
|
|
|
# 1. Create directories
|
|
run("mkdir -p /opt/game-web/html")
|
|
|
|
# 2. Write the python generator script
|
|
py_script = '''#!/usr/bin/env python3
|
|
import json
|
|
import subprocess
|
|
import datetime
|
|
import os
|
|
import yaml
|
|
|
|
GAMES = [
|
|
{
|
|
"id": "valheim",
|
|
"name": "Valheim",
|
|
"tagline": "Viking Survival Craft (Crossplay)",
|
|
"icon": "⚔️",
|
|
"container": "gameseed-valheim",
|
|
"ports": "2456 - 2457 UDP",
|
|
"public_endpoint": "174.106.252.96:2456",
|
|
"local_endpoint": "140.44.44.80:2456",
|
|
"server_name": "SnarfNet Valheim Valhalla",
|
|
"world_name": "Snarfheim",
|
|
"password": "SnarfNet2026!",
|
|
"save_path": "/opt/game-servers/valheim/worlds (NVMe)",
|
|
"steam_app_id": "896660",
|
|
},
|
|
{
|
|
"id": "enshrouded",
|
|
"name": "Enshrouded",
|
|
"tagline": "Action RPG Survival",
|
|
"icon": "🌲",
|
|
"container": "gameseed-enshrouded",
|
|
"ports": "15636 - 15637 UDP",
|
|
"public_endpoint": "174.106.252.96:15636",
|
|
"local_endpoint": "140.44.44.80:15636",
|
|
"server_name": "SnarfNet Enshrouded Sanctuary",
|
|
"world_name": "Sanctuary",
|
|
"password": "SnarfNet2026!",
|
|
"save_path": "/opt/game-servers/enshrouded/savegame (NVMe)",
|
|
"steam_app_id": "2278520",
|
|
},
|
|
{
|
|
"id": "vrising",
|
|
"name": "V Rising",
|
|
"tagline": "Gothic Action RPG",
|
|
"icon": "🧛",
|
|
"container": "gameseed-vrising",
|
|
"ports": "9876 - 9877 UDP",
|
|
"public_endpoint": "174.106.252.96:9876",
|
|
"local_endpoint": "140.44.44.80:9876",
|
|
"server_name": "SnarfNet V Rising Vampire Lair",
|
|
"world_name": "SnarfNet_Vampires",
|
|
"password": "SnarfNet2026!",
|
|
"save_path": "/opt/game-servers/vrising/Saves (NVMe)",
|
|
"steam_app_id": "1829350",
|
|
},
|
|
{
|
|
"id": "stationeers",
|
|
"name": "Stationeers",
|
|
"tagline": "Hardcore Space Colonization",
|
|
"icon": "🚀",
|
|
"container": "gameseed-stationeers",
|
|
"ports": "27015 - 27016 UDP",
|
|
"public_endpoint": "174.106.252.96:27016",
|
|
"local_endpoint": "140.44.44.80:27016",
|
|
"server_name": "SnarfNet Stationeers Moonbase",
|
|
"world_name": "Moon",
|
|
"password": "SnarfNet2026!",
|
|
"save_path": "/opt/game-servers/stationeers/saves (NVMe)",
|
|
"steam_app_id": "600760",
|
|
},
|
|
{
|
|
"id": "fs25",
|
|
"name": "Farming Simulator 25",
|
|
"tagline": "Agriculture & Machinery Simulator",
|
|
"icon": "🚜",
|
|
"container": "gameseed-farming-simulator-25",
|
|
"ports": "10823 TCP/UDP",
|
|
"public_endpoint": "174.106.252.96:10823",
|
|
"local_endpoint": "140.44.44.80:10823",
|
|
"server_name": "SnarfNet FS25 Countryside",
|
|
"world_name": "Countryside",
|
|
"password": "SnarfNetAdmin2026!",
|
|
"save_path": "/opt/game-servers/fs25/savegame (NVMe)",
|
|
"steam_app_id": "2300320",
|
|
}
|
|
]
|
|
|
|
def get_container_status(container_name):
|
|
cmd = ["docker", "inspect", container_name]
|
|
res = subprocess.run(cmd, capture_output=True, text=True)
|
|
if res.returncode != 0:
|
|
return "shutdown", "Not Found", "Container not created"
|
|
try:
|
|
data = json.loads(res.stdout)[0]
|
|
state = data.get("State", {})
|
|
status = state.get("Status", "unknown").lower()
|
|
started_at = state.get("StartedAt", "")
|
|
health = state.get("Health", {}).get("Status", "")
|
|
|
|
if status == "running":
|
|
if health == "unhealthy":
|
|
return "error", "Unhealthy", "Container running but failing health checks"
|
|
elif health == "starting":
|
|
return "starting", "Starting", "Initializing container and game world"
|
|
return "active", "Active / Online", f"Running since {started_at[:19].replace('T', ' ')}"
|
|
elif status == "restarting":
|
|
return "error", "Error / Restarting", "Container is crash-looping or awaiting assets"
|
|
elif status == "exited":
|
|
return "shutdown", "Shutdown", f"Exited (code {state.get('ExitCode')})"
|
|
else:
|
|
return status, status.capitalize(), f"State: {status}"
|
|
except Exception as e:
|
|
return "error", "Error", str(e)
|
|
|
|
def get_host_metrics():
|
|
try:
|
|
uptime = subprocess.check_output(["uptime", "-p"], text=True).strip()
|
|
except Exception:
|
|
uptime = "Up"
|
|
|
|
try:
|
|
mem_raw = subprocess.check_output(["free", "-m"], text=True).splitlines()[1].split()
|
|
mem_total = round(int(mem_raw[1]) / 1024, 1)
|
|
mem_used = round(int(mem_raw[2]) / 1024, 1)
|
|
mem_str = f"{mem_used} GB / {mem_total} GB"
|
|
except Exception:
|
|
mem_str = "N/A"
|
|
|
|
try:
|
|
df_nvme = subprocess.check_output(["df", "-h", "/mnt/nvme-games"], text=True).splitlines()[1].split()
|
|
disk_str = f"{df_nvme[2]} used / {df_nvme[1]} total ({df_nvme[3]} free)"
|
|
except Exception:
|
|
disk_str = "1 TB NVMe"
|
|
|
|
return uptime, mem_str, disk_str
|
|
|
|
def main():
|
|
now_str = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S EST")
|
|
uptime, mem_str, disk_str = get_host_metrics()
|
|
|
|
cards_html = ""
|
|
active_count = 0
|
|
|
|
for g in GAMES:
|
|
status_key, status_title, status_desc = get_container_status(g["container"])
|
|
if status_key == "active":
|
|
active_count += 1
|
|
badge_class = "badge-active"
|
|
dot_class = "dot-active"
|
|
elif status_key == "starting":
|
|
badge_class = "badge-starting"
|
|
dot_class = "dot-starting"
|
|
elif status_key == "error":
|
|
badge_class = "badge-error"
|
|
dot_class = "dot-error"
|
|
else:
|
|
badge_class = "badge-shutdown"
|
|
dot_class = "dot-shutdown"
|
|
|
|
cards_html += f"""
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<div class="title-group">
|
|
<span class="game-icon">{g['icon']}</span>
|
|
<div>
|
|
<h2>{g['name']}</h2>
|
|
<span class="tagline">{g['tagline']}</span>
|
|
</div>
|
|
</div>
|
|
<div class="status-badge {badge_class}">
|
|
<span class="dot {dot_class}"></span>
|
|
{status_title}
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="status-desc">{status_desc}</div>
|
|
<div class="endpoint-grid">
|
|
<div class="endpoint-item">
|
|
<label>Public WAN Address</label>
|
|
<code>{g['public_endpoint']}</code>
|
|
</div>
|
|
<div class="endpoint-item">
|
|
<label>Local LAN Address</label>
|
|
<code>{g['local_endpoint']}</code>
|
|
</div>
|
|
<div class="endpoint-item">
|
|
<label>Port(s) & Protocol</label>
|
|
<span class="val">{g['ports']}</span>
|
|
</div>
|
|
<div class="endpoint-item">
|
|
<label>Server Password</label>
|
|
<span class="password-box">{g['password']}</span>
|
|
</div>
|
|
</div>
|
|
<div class="meta-row">
|
|
<span><strong>Server Name:</strong> {g['server_name']}</span>
|
|
<span><strong>World:</strong> {g['world_name']}</span>
|
|
</div>
|
|
<div class="meta-row-sub">
|
|
<span><strong>Save Location:</strong> {g['save_path']}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
"""
|
|
|
|
html = f"""<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>SnarfNet Game Servers</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;600&display=swap" rel="stylesheet">
|
|
<style>
|
|
:root {{
|
|
--bg: #0b0f17;
|
|
--surface: #141c2b;
|
|
--surface-border: #233149;
|
|
--surface-hover: #1c273c;
|
|
--text-main: #f0f4fc;
|
|
--text-muted: #8ea1c0;
|
|
--primary: #3b82f6;
|
|
--primary-glow: rgba(59, 130, 246, 0.25);
|
|
--green: #10b981;
|
|
--green-glow: rgba(16, 185, 129, 0.2);
|
|
--amber: #f59e0b;
|
|
--red: #ef4444;
|
|
--radius-lg: 16px;
|
|
--radius-md: 10px;
|
|
}}
|
|
* {{ margin: 0; padding: 0; box-sizing: border-box; }}
|
|
body {{
|
|
background: var(--bg);
|
|
color: var(--text-main);
|
|
font-family: 'Inter', -apple-system, sans-serif;
|
|
padding: 32px 20px;
|
|
min-height: 100vh;
|
|
}}
|
|
.container {{
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
}}
|
|
header {{
|
|
margin-bottom: 32px;
|
|
background: linear-gradient(135deg, rgba(20, 28, 43, 0.9) 0%, rgba(14, 21, 33, 0.8) 100%);
|
|
border: 1px solid var(--surface-border);
|
|
border-radius: var(--radius-lg);
|
|
padding: 28px 32px;
|
|
backdrop-filter: blur(10px);
|
|
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
|
|
}}
|
|
.header-top {{
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
flex-wrap: wrap;
|
|
gap: 16px;
|
|
margin-bottom: 20px;
|
|
}}
|
|
.brand {{
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 16px;
|
|
}}
|
|
.brand-icon {{
|
|
font-size: 2.4rem;
|
|
background: var(--primary-glow);
|
|
padding: 10px;
|
|
border-radius: var(--radius-md);
|
|
border: 1px solid rgba(59, 130, 246, 0.4);
|
|
}}
|
|
h1 {{
|
|
font-size: 1.85rem;
|
|
font-weight: 800;
|
|
letter-spacing: -0.02em;
|
|
background: linear-gradient(135deg, #ffffff 0%, #a5b4fc 100%);
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
}}
|
|
.subtitle {{
|
|
color: var(--text-muted);
|
|
font-size: 0.9rem;
|
|
margin-top: 4px;
|
|
}}
|
|
.server-stats {{
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 16px;
|
|
border-top: 1px solid rgba(35, 49, 73, 0.6);
|
|
padding-top: 20px;
|
|
}}
|
|
.stat-item {{
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 4px;
|
|
}}
|
|
.stat-label {{
|
|
font-size: 0.75rem;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.05em;
|
|
color: var(--text-muted);
|
|
font-weight: 600;
|
|
}}
|
|
.stat-value {{
|
|
font-size: 1.05rem;
|
|
font-weight: 700;
|
|
color: #e2e8f0;
|
|
}}
|
|
.grid {{
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(540px, 1fr));
|
|
gap: 24px;
|
|
}}
|
|
@media (max-width: 640px) {{
|
|
.grid {{ grid-template-columns: 1fr; }}
|
|
}}
|
|
.card {{
|
|
background: var(--surface);
|
|
border: 1px solid var(--surface-border);
|
|
border-radius: var(--radius-lg);
|
|
overflow: hidden;
|
|
transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
|
|
}}
|
|
.card:hover {{
|
|
border-color: rgba(59, 130, 246, 0.5);
|
|
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
|
|
transform: translateY(-2px);
|
|
}}
|
|
.card-header {{
|
|
padding: 20px 24px;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
border-bottom: 1px solid var(--surface-border);
|
|
background: rgba(11, 15, 23, 0.3);
|
|
}}
|
|
.title-group {{
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 14px;
|
|
}}
|
|
.game-icon {{
|
|
font-size: 2rem;
|
|
}}
|
|
h2 {{
|
|
font-size: 1.25rem;
|
|
font-weight: 700;
|
|
letter-spacing: -0.01em;
|
|
}}
|
|
.tagline {{
|
|
font-size: 0.8rem;
|
|
color: var(--text-muted);
|
|
display: block;
|
|
margin-top: 2px;
|
|
}}
|
|
.status-badge {{
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
padding: 6px 12px;
|
|
border-radius: 9999px;
|
|
font-size: 0.75rem;
|
|
font-weight: 700;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.05em;
|
|
}}
|
|
.badge-active {{ background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.4); }}
|
|
.badge-starting {{ background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.4); }}
|
|
.badge-error {{ background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.4); }}
|
|
.badge-shutdown {{ background: rgba(100, 116, 139, 0.15); color: #94a3b8; border: 1px solid rgba(100, 116, 139, 0.3); }}
|
|
.dot {{ width: 8px; height: 8px; border-radius: 50%; }}
|
|
.dot-active {{ background: #10b981; box-shadow: 0 0 8px #10b981; }}
|
|
.dot-starting {{ background: #f59e0b; box-shadow: 0 0 8px #f59e0b; }}
|
|
.dot-error {{ background: #ef4444; box-shadow: 0 0 8px #ef4444; }}
|
|
.dot-shutdown {{ background: #64748b; }}
|
|
.card-body {{
|
|
padding: 22px 24px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 16px;
|
|
}}
|
|
.status-desc {{
|
|
font-size: 0.82rem;
|
|
color: var(--text-muted);
|
|
background: rgba(11, 15, 23, 0.4);
|
|
padding: 8px 12px;
|
|
border-radius: var(--radius-md);
|
|
border-left: 3px solid #3b82f6;
|
|
}}
|
|
.endpoint-grid {{
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 12px;
|
|
}}
|
|
.endpoint-item {{
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 4px;
|
|
background: rgba(11, 15, 23, 0.6);
|
|
padding: 10px 14px;
|
|
border-radius: var(--radius-md);
|
|
border: 1px solid rgba(35, 49, 73, 0.4);
|
|
}}
|
|
.endpoint-item label {{
|
|
font-size: 0.7rem;
|
|
color: var(--text-muted);
|
|
text-transform: uppercase;
|
|
font-weight: 600;
|
|
}}
|
|
code {{
|
|
font-family: 'JetBrains Mono', monospace;
|
|
font-size: 0.85rem;
|
|
color: #60a5fa;
|
|
word-break: break-all;
|
|
}}
|
|
.val {{
|
|
font-family: 'JetBrains Mono', monospace;
|
|
font-size: 0.85rem;
|
|
color: #e2e8f0;
|
|
}}
|
|
.password-box {{
|
|
font-family: 'JetBrains Mono', monospace;
|
|
font-size: 0.85rem;
|
|
color: #34d399;
|
|
font-weight: 600;
|
|
}}
|
|
.meta-row, .meta-row-sub {{
|
|
display: flex;
|
|
justify-content: space-between;
|
|
font-size: 0.8rem;
|
|
color: var(--text-muted);
|
|
border-top: 1px dashed rgba(35, 49, 73, 0.6);
|
|
padding-top: 10px;
|
|
}}
|
|
footer {{
|
|
margin-top: 40px;
|
|
text-align: center;
|
|
font-size: 0.8rem;
|
|
color: var(--text-muted);
|
|
}}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<header>
|
|
<div class="header-top">
|
|
<div class="brand">
|
|
<div class="brand-icon">🎮</div>
|
|
<div>
|
|
<h1>SnarfNet Game Servers</h1>
|
|
<div class="subtitle">sngame4lnxp01 • 140.44.44.80 (Compute VLAN) • Public IP: 174.106.252.96</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="server-stats">
|
|
<div class="stat-item">
|
|
<span class="stat-label">Active Games</span>
|
|
<span class="stat-value">{active_count} of {len(GAMES)} Online</span>
|
|
</div>
|
|
<div class="stat-item">
|
|
<span class="stat-label">Memory Utilization</span>
|
|
<span class="stat-value">{mem_str}</span>
|
|
</div>
|
|
<div class="stat-item">
|
|
<span class="stat-label">NVMe Game Storage</span>
|
|
<span class="stat-value">{disk_str}</span>
|
|
</div>
|
|
<div class="stat-item">
|
|
<span class="stat-label">System Uptime</span>
|
|
<span class="stat-value">{uptime}</span>
|
|
</div>
|
|
<div class="stat-item">
|
|
<span class="stat-label">Last Status Probe</span>
|
|
<span class="stat-value">{now_str}</span>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="grid">
|
|
{cards_html}
|
|
</main>
|
|
|
|
<footer>
|
|
SnarfNet Dedicated Game Management Plane • Auto-refreshed hourly via cron • Powered by Docker on NVMe Storage
|
|
</footer>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
"""
|
|
with open("/opt/game-web/html/index.html", "w", encoding="utf-8") as f:
|
|
f.write(html)
|
|
print("Generated /opt/game-web/html/index.html successfully!")
|
|
|
|
# Restart web container if running
|
|
res = subprocess.run(["docker", "ps", "-q", "-f", "name=gameseed-web"], capture_output=True, text=True)
|
|
if res.stdout.strip():
|
|
subprocess.run(["docker", "restart", "gameseed-web"])
|
|
print("Restarted gameseed-web container.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
'''
|
|
|
|
# Write py script to remote
|
|
sftp = ssh.open_sftp()
|
|
with sftp.open("/opt/game-web/update_status.py", "w") as f:
|
|
f.write(py_script)
|
|
sftp.close()
|
|
run("chmod +x /opt/game-web/update_status.py")
|
|
|
|
# 3. Generate initial index.html
|
|
run("python3 /opt/game-web/update_status.py")
|
|
|
|
# 4. Start Nginx container
|
|
run("docker run -d --name gameseed-web --restart unless-stopped -p 8080:80 -v /opt/game-web/html:/usr/share/nginx/html:ro nginx:alpine || true")
|
|
run("docker ps -f name=gameseed-web")
|
|
|
|
# 5. Configure hourly cron job
|
|
cron_line = "0 * * * * /usr/bin/python3 /opt/game-web/update_status.py > /var/log/gameseed-web.log 2>&1"
|
|
run(f"(crontab -l 2>/dev/null | grep -v 'update_status.py'; echo '{cron_line}') | crontab -")
|
|
run("crontab -l")
|
|
|
|
# 6. Test local curl
|
|
run("curl -I http://localhost:8080")
|
|
|
|
ssh.close()
|
|
print("\nWeb server and hourly cron setup completed successfully!")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|