<?php if (!defined('DASHBOARD_ROOT')) exit; RBAC::require('manage.fleet'); require_once DASHBOARD_ROOT . '/core/shield_relay.php'; $action = $_GET['action'] ?? 'status'; switch ($action) { case 'status': $tunnels = ShieldRelay::tunnelStatus(); $pings = ShieldRelay::pingAll(); $tunnelMap = [ 'origin_mesh' => [ 'name' => 'Origin ↔ Shield', 'type' => 'mesh', 'origin_ip' => '10.69.69.2', 'shield_ip' => '10.69.69.1', 'origin_port'=> 56381, 'shield_port'=> 51820, 'status' => ($pings['shield']['online'] ?? false) ? 'active' : 'down', 'latency' => $pings['shield']['latency'] ?? 0, ], 'spoke_tunnels' => [], ]; $spokeConfig = [ 'dns' => ['shield_ip' => '10.69.69.1', 'spoke_ip' => '10.69.69.5', 'iface' => 'wg7', 'shield_port' => 51820, 'spoke_port' => 11953], 'proxy' => ['shield_ip' => '10.69.69.1', 'spoke_ip' => '10.69.69.3', 'iface' => 'wg7', 'shield_port' => 51820, 'spoke_port' => 0], 'filter' => ['shield_ip' => '10.69.69.1', 'spoke_ip' => '10.69.69.4', 'iface' => 'wg7', 'shield_port' => 51820, 'spoke_port' => 0], 'payment' => ['shield_ip' => '10.69.69.1', 'spoke_ip' => '10.69.69.6', 'iface' => 'wg7', 'shield_port' => 51820, 'spoke_port' => 0], 'email' => ['shield_ip' => '10.69.69.1', 'spoke_ip' => '10.69.69.7', 'iface' => 'wg7', 'shield_port' => 51820, 'spoke_port' => 43217], ]; foreach ($spokeConfig as $role => $cfg) { $shieldIface = null; foreach (($tunnels['interfaces'] ?? []) as $iface) { if ($iface['interface'] === $cfg['iface']) { $shieldIface = $iface; break; } } $isOnline = $pings[$role]['online'] ?? false; $tunnelMap['spoke_tunnels'][] = [ 'name' => 'Shield ↔ ' . ucfirst($role), 'role' => $role, 'shield_ip' => $cfg['shield_ip'], 'spoke_ip' => $cfg['spoke_ip'], 'shield_port' => $cfg['shield_port'], 'spoke_port' => $cfg['spoke_port'], 'interface' => $cfg['iface'], 'status' => $isOnline ? 'active' : 'down', 'last_handshake' => $shieldIface['last_handshake'] ?? null, 'transfer' => $shieldIface['transfer'] ?? '', 'latency' => $pings[$role]['latency'] ?? 0, 'route' => $pings[$role]['route'] ?? '', ]; } echo json_encode(['ok' => true, 'tunnels' => $tunnelMap]); break; case 'ping': $pings = ShieldRelay::pingAll(); echo json_encode(['ok' => true, 'results' => $pings]); break; default: echo json_encode(['ok' => false, 'error' => 'Unknown action']); } 