最后活跃于 1 month ago

nuno 修订了这个 Gist 1 month ago. 转到此修订

1 file changed, 33 insertions

gistfile1.txt(文件已创建)

@@ -0,0 +1,33 @@
1 + function peers::list() {
2 + local dir
3 + dir="$(ctx::clients)"
4 +
5 + if [[ -z "$(ls -A "$dir"/*.conf 2>/dev/null)" ]]; then
6 + log::wg_list "No clients configured"
7 + return 0
8 + fi
9 +
10 + for conf in "${dir}"/*.conf; do
11 + local client_name
12 + client_name=$(basename "$conf" .conf)
13 +
14 + local ip
15 + ip=$(grep "^Address" "$conf" | awk '{print $3}' | cut -d'/' -f1)
16 +
17 + local public_key
18 + public_key=$(keys::public "$client_name" 2>/dev/null || echo "unknown")
19 +
20 + # Determine type from IP
21 + local type="unknown"
22 + for t in $(config::device_types); do
23 + local subnet
24 + subnet=$(config::subnet_for "$t")
25 + if string::starts_with "$ip" "$subnet"; then
26 + type="$t"
27 + break
28 + fi
29 + done
30 +
31 + printf " %-30s %-15s %-10s %s\n" \
32 + "$client_name" "$ip" "$type" "$public_key"
33 + done
上一页 下一页