-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtunnel-status.sh
More file actions
executable file
·96 lines (82 loc) · 3.29 KB
/
tunnel-status.sh
File metadata and controls
executable file
·96 lines (82 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
# tunnel-status.sh
# Display tunnel peer status with names from registry and live handshake data.
# Usage: tunnel-status.sh
#
# Copyright 2026 Quantum Pipes Technologies, LLC
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091
source "$SCRIPT_DIR/tunnel-preflight.sh"
# ---------------------------------------------------------------------------
# Header
# ---------------------------------------------------------------------------
echo ""
echo "========================================"
echo " ${TUNNEL_APP_NAME} Tunnel Status"
echo "========================================"
echo ""
# ---------------------------------------------------------------------------
# Relay info
# ---------------------------------------------------------------------------
if registry_get_relay >/dev/null 2>&1; then
relay_json="$(registry_get_relay)"
relay_ep="$(echo "$relay_json" | jq -r '.endpoint')"
relay_ip="$(echo "$relay_json" | jq -r '.tunnel_ip')"
echo "Relay: $relay_ep (Tunnel IP: $relay_ip)"
echo ""
else
log_warn "No relay configured"
echo ""
fi
# ---------------------------------------------------------------------------
# Registered peers
# ---------------------------------------------------------------------------
peer_count="$(registry_peer_count)"
echo "Active peers: $peer_count"
echo ""
if (( peer_count == 0 )); then
echo "No peers registered. Use tunnel-add-peer.sh <name> to add one."
exit 0
fi
# ---------------------------------------------------------------------------
# Merge registry names with live WireGuard data
# ---------------------------------------------------------------------------
printf '%-16s %-16s %-14s %-24s %s\n' "NAME" "Tunnel IP" "STATUS" "LAST HANDSHAKE" "ENDPOINT"
printf '%-16s %-16s %-14s %-24s %s\n' "----" "------" "------" "--------------" "--------"
# Build a lookup map from public_key -> live data
declare -A live_handshakes
declare -A live_endpoints
if wg_interface_exists 2>/dev/null; then
while IFS= read -r line; do
pk="$(echo "$line" | jq -r '.public_key')"
hs="$(echo "$line" | jq -r '.latest_handshake')"
ep="$(echo "$line" | jq -r '.endpoint')"
live_handshakes["$pk"]="$hs"
live_endpoints["$pk"]="$ep"
done < <(wg_show_peers)
fi
# Iterate registered peers
registry_list_peers | jq -c '.[]' | while IFS= read -r peer; do
name="$(echo "$peer" | jq -r '.name')"
tunnel_ip="$(echo "$peer" | jq -r '.tunnel_ip')"
pubkey="$(echo "$peer" | jq -r '.public_key')"
status="active"
handshake="${live_handshakes[$pubkey]:-never}"
endpoint="${live_endpoints[$pubkey]:-none}"
if [[ "$handshake" == "never" ]]; then
status="waiting"
else
status="connected"
fi
printf '%-16s %-16s %-14s %-24s %s\n' "$name" "$tunnel_ip" "$status" "$handshake" "$endpoint"
done
echo ""
# ---------------------------------------------------------------------------
# Show revoked peers (summary only)
# ---------------------------------------------------------------------------
revoked_count="$(registry_list_peers --all | jq '[.[] | select(.status == "revoked")] | length')"
if (( revoked_count > 0 )); then
echo "Revoked peers: $revoked_count (use --all to see details)"
fi