varaverk: add Partner card — known hosts, owner tags, Tailscale online status
This commit is contained in:
@@ -249,6 +249,45 @@ function vv_network_stats(): array {
|
||||
];
|
||||
}
|
||||
|
||||
function vv_partner_state(): array {
|
||||
$vars = vv_conf_vars();
|
||||
$myName = trim(shell_exec('hostname -s') ?: '');
|
||||
|
||||
// Parse Tailscale peer status once
|
||||
$tsData = json_decode(shell_exec('tailscale status --json 2>/dev/null') ?: '{}', true) ?? [];
|
||||
$tsPeers = [];
|
||||
foreach ($tsData['Peer'] ?? [] as $peer) {
|
||||
// DNSName is "hostname.tailnet.ts.net." — take the first label (full, not truncated)
|
||||
$dns = $peer['DNSName'] ?? '';
|
||||
$h = $dns ? strtolower(explode('.', $dns)[0]) : strtolower($peer['HostName'] ?? '');
|
||||
if ($h) $tsPeers[$h] = (bool)($peer['Online'] ?? false);
|
||||
}
|
||||
|
||||
$hosts = [];
|
||||
foreach (['HOST1', 'HOST2', 'HOST3', 'HOST4'] as $id) {
|
||||
$hostname = $vars[$id] ?? '';
|
||||
if (!$hostname) continue;
|
||||
$isMe = strcasecmp($hostname, $myName) === 0;
|
||||
$isOwner = strcasecmp($id, $vars['PARTNERSHIP_OWNER_HOST'] ?? '') === 0;
|
||||
$online = $isMe ? true : ($tsPeers[strtolower($hostname)] ?? null);
|
||||
$hosts[] = [
|
||||
'id' => $id,
|
||||
'hostname' => $hostname,
|
||||
'owner' => $vars[$id . '_OWNER'] ?? '',
|
||||
'is_me' => $isMe,
|
||||
'is_owner' => $isOwner,
|
||||
'online' => $online,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'enabled' => ($vars['PARTNERSHIP_ENABLED'] ?? 'false') === 'true',
|
||||
'owner_host' => $vars['PARTNERSHIP_OWNER_HOST'] ?? '',
|
||||
'sync_min' => (int)($vars['PARTNERSHIP_SYNC_INTERVAL'] ?? 15),
|
||||
'hosts' => $hosts,
|
||||
];
|
||||
}
|
||||
|
||||
function vv_fallback_state(): array {
|
||||
// State file written by fallback.sh
|
||||
$stateFile = '/tmp/fallback_state.db';
|
||||
|
||||
Reference in New Issue
Block a user