<?php if (!defined('DASHBOARD_ROOT')) exit; RBAC::require('manage.fleet'); CSRF::validate(); require_once DASHBOARD_ROOT . '/core/shield_relay.php'; $shieldTunnels = ShieldRelay::tunnelStatus(); $originResult = ShieldRelay::execLocal('wg show all 2>/dev/null'); $originInterfaces = []; if ($originResult['ok']) { $originInterfaces = parseWgOutput($originResult['output']); } $nodes = [ [ 'id' => '414342', 'name' => 'Shield', 'reachable' => $shieldTunnels['ok'], 'interfaces' => $shieldTunnels['interfaces'] ?? [], 'is_hub' => true, ], [ 'id' => '558201', 'name' => 'Origin', 'reachable' => true, 'interfaces' => $originInterfaces, 'is_hub' => false, ], ]; $spokeRoles = ['dns', 'proxy', 'filter', 'payment', 'email']; $spokeIds = ['199335', '244939', '333941', '669427', '773816']; $spokeNames = ['DNS', 'Proxy', 'Filter', 'Payment', 'Email']; foreach ($spokeRoles as $i => $role) { $spokeResult = ShieldRelay::exec($role, 'wg show all 2>/dev/null', 8); $interfaces = []; if ($spokeResult['ok']) { $interfaces = parseWgOutput($spokeResult['output']); } $nodes[] = [ 'id' => $spokeIds[$i], 'name' => $spokeNames[$i], 'reachable' => $spokeResult['ok'], 'interfaces' => $interfaces, 'route' => $spokeResult['route'] ?? '', ]; } echo json_encode(['ok' => true, 'nodes' => $nodes]); function parseWgOutput(string $raw): array { $interfaces = []; $current = null; $peerCount = 0; $lastHandshake = null; $transfer = ''; $port = ''; foreach (explode("\n", $raw) as $line) { $line = trim($line); if (preg_match('/^interface:\s+(.+)/', $line, $m)) { if ($current !== null) { $interfaces[] = [ 'name' => $current, 'port' => $port, 'peers' => $peerCount, 'last_handshake' => $lastHandshake, 'transfer' => $transfer, ]; } $current = $m[1]; $peerCount = 0; $lastHandshake = null; $transfer = ''; $port = ''; } if (preg_match('/listening port:\s+(\d+)/', $line, $m)) { $port = $m[1]; } if (preg_match('/^peer:/', $line)) { $peerCount++; } if (preg_match('/latest handshake:\s+(.+)/', $line, $m)) { $lastHandshake = $m[1]; } if (preg_match('/transfer:\s+(.+)/', $line, $m)) { $transfer = $m[1]; } } if ($current !== null) { $interfaces[] = [ 'name' => $current, 'port' => $port, 'peers' => $peerCount, 'last_handshake' => $lastHandshake, 'transfer' => $transfer, ]; } return $interfaces; } 