gistfile1.txt
· 810 B · Text
Sin formato
function peers::list() {
local dir
dir="$(ctx::clients)"
if [[ -z "$(ls -A "$dir"/*.conf 2>/dev/null)" ]]; then
log::wg_list "No clients configured"
return 0
fi
for conf in "${dir}"/*.conf; do
local client_name
client_name=$(basename "$conf" .conf)
local ip
ip=$(grep "^Address" "$conf" | awk '{print $3}' | cut -d'/' -f1)
local public_key
public_key=$(keys::public "$client_name" 2>/dev/null || echo "unknown")
# Determine type from IP
local type="unknown"
for t in $(config::device_types); do
local subnet
subnet=$(config::subnet_for "$t")
if string::starts_with "$ip" "$subnet"; then
type="$t"
break
fi
done
printf " %-30s %-15s %-10s %s\n" \
"$client_name" "$ip" "$type" "$public_key"
done
| 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 |