feat: complete React + Flask rebuild of dashboard
Backend: - New Flask 3 app with service-layer architecture - Pydantic v2 models and unified API response format - psycopg3 connection pool with stored procedure support - 14 services: DB, SSH, K8s, BGD, RMQ (admin + game), realtime, player, economy, guild, world, progression, character, audit, chat - 30+ API endpoints covering players, guilds, economy, world, admin, server, files, director, chat - SSE real-time events for battlegroup, chat, metrics, connection status - SocketIO remote shell (xterm.js compatible) - Settings CRUD, moderation (ban/kick/unban), audit logging - Security: CSRF, rate limiting, CSP, HSTS, read-only SQL enforcement Frontend: - Vite + React 18 + TypeScript + Tailwind CSS - 14 Dune house themes via CSS custom properties - SWR for server state, Axios API client with interceptors - 14 pages: Overview, Player Explorer + Detail, Guild Manager, Vehicles, Buildings, Map Viewer, Accounts, Server Control, Admin Tools (7 tabs), Chat Monitor, Remote Shell, File Browser, Director, Settings - Player Detail with 6 tabs: overview, inventory, vehicles, buildings, progression, actions - Admin Tools: broadcast, economy, world, character, functions, raw query, audit log - Interactive canvas map viewer with zoom/pan/filter - Toast notifications, connection badges, theme switcher Other: - Updated .gitignore for frontend/backend structure - Updated README with new architecture, development guide, and project structure - Legacy app/ templates/ static/ remain untouched
This commit is contained in:
1 parent
fa620f4da9
commit
be845f76f1
76 files changed
+8410
-10
No files matched your search
@@ -0,0 +1,103 @@
|
||||
"""SSH service — remote command execution via paramiko."""
|
||||
|
||||
import logging
|
||||
import threading
|
||||
import paramiko
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SSHService:
|
||||
def __init__(self, host, user, ssh_key=None):
|
||||
self.host = host
|
||||
self.user = user
|
||||
self.ssh_key = ssh_key
|
||||
self._client = None
|
||||
self._lock = threading.Lock()
|
||||
key_status = self.ssh_key if self.ssh_key else "default ssh identity/agent"
|
||||
logger.info("SSHService initialized: %s@%s using %s", user, host, key_status)
|
||||
|
||||
def _get_client(self):
|
||||
with self._lock:
|
||||
if self._client is not None:
|
||||
transport = self._client.get_transport()
|
||||
if transport and transport.is_active():
|
||||
return self._client
|
||||
self._client = None
|
||||
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
connect_kwargs = {
|
||||
"hostname": self.host,
|
||||
"username": self.user,
|
||||
"timeout": 15,
|
||||
"allow_agent": True,
|
||||
"look_for_keys": True,
|
||||
}
|
||||
if self.ssh_key:
|
||||
connect_kwargs["key_filename"] = self.ssh_key
|
||||
|
||||
try:
|
||||
client.connect(**connect_kwargs)
|
||||
logger.debug("SSH connection established to %s@%s", self.user, self.host)
|
||||
except paramiko.AuthenticationException:
|
||||
logger.error("SSH authentication failed for %s@%s", self.user, self.host)
|
||||
raise
|
||||
except paramiko.SSHException as e:
|
||||
logger.error("SSH connection error: %s", e)
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error("Unexpected SSH error: %s", e)
|
||||
raise
|
||||
|
||||
self._client = client
|
||||
return self._client
|
||||
|
||||
def run(self, command, timeout=30):
|
||||
cmd_display = command[:150] + "..." if len(command) > 150 else command
|
||||
logger.debug("SSH executing: %s", cmd_display)
|
||||
|
||||
try:
|
||||
client = self._get_client()
|
||||
stdin, stdout, stderr = client.exec_command(command, timeout=timeout)
|
||||
out = stdout.read().decode("utf-8", errors="replace")
|
||||
err = stderr.read().decode("utf-8", errors="replace")
|
||||
rc = stdout.channel.recv_exit_status()
|
||||
|
||||
logger.debug("SSH result: rc=%d, stdout_len=%d, stderr_len=%d", rc, len(out), len(err))
|
||||
if err and rc != 0:
|
||||
logger.warning("SSH stderr (rc=%d): %s", rc, err[:200])
|
||||
if rc != 0:
|
||||
logger.warning("SSH command failed (rc=%d): cmd=%s err=%s", rc, cmd_display, err[:100] if err else "none")
|
||||
return out, err, rc
|
||||
except paramiko.SSHException as e:
|
||||
logger.error("SSH command error (%s): %s", self.host, e)
|
||||
self._client = None
|
||||
return "", str(e), -1
|
||||
except Exception as ex:
|
||||
logger.error("Unexpected SSH command error (%s): %s", self.host, ex)
|
||||
self._client = None
|
||||
return "", str(ex), -1
|
||||
|
||||
def check_connection(self):
|
||||
try:
|
||||
out, err, rc = self.run("echo ok", timeout=10)
|
||||
if rc == 0 and "ok" in out:
|
||||
logger.debug("SSH connection check passed")
|
||||
return True
|
||||
logger.warning("SSH connection check failed: rc=%d, out=%s", rc, out[:50])
|
||||
return False
|
||||
except Exception:
|
||||
logger.warning("SSH connection check failed with exception")
|
||||
return False
|
||||
|
||||
def close(self):
|
||||
with self._lock:
|
||||
if self._client:
|
||||
try:
|
||||
self._client.close()
|
||||
logger.debug("SSH connection closed")
|
||||
except Exception as e:
|
||||
logger.debug("Error closing SSH connection: %s", e)
|
||||
self._client = None
|
||||
Reference in new issue
Block a user