<?php
require_once("guiconfig.inc");

// Netbird 配置
$nb_bin = '/usr/local/bin/netbird';

// 获取节点状态
$peers = [];
exec("$nb_bin status --json", $peerOutput, $peerReturn);
if ($peerReturn === 0) {
    $peers = json_decode(implode('', $peerOutput), true)['peers']['details'] ?? [];
}
?>

<?php if (!empty($peers)): ?>
<table class="table table-striped table-hover">
    <thead>
        <tr>
            <th>节点名</th>
            <th>IP 地址</th>
            <th>连接类型</th>
            <th>直连</th>
            <th>状态</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($peers as $peer): ?>
        <tr class="<?= $peer['status'] === 'Connected' ? 'table-success' : 'table-danger'; ?>">
            <td><?= htmlspecialchars($peer['fqdn'] ?? '未知'); ?></td>
            <td><?= htmlspecialchars($peer['netbirdIp'] ?? '未知'); ?></td>
            <td><?= htmlspecialchars($peer['connectionType'] ?? '未知'); ?></td>
            <td><?= $peer['direct'] ? '是' : '否'; ?></td>
            <td><?= $peer['status'] === 'Connected' ? '在线' : '离线'; ?></td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>
<?php else: ?>
<p>当前无可用节点信息。</p>
<?php endif; ?>