24 lines
848 B
Plaintext
24 lines
848 B
Plaintext
|
#!/bin/bash
|
||
|
# FILE: wgapi:back/lib/wg/user/list
|
||
|
# DESCRIPTION: List all devices from all users
|
||
|
# USAGE: list json|tsv
|
||
|
|
||
|
[ "$#" == "1" ] || exit
|
||
|
source ../../../env/vars
|
||
|
#/usr/bin/wg show ${TLD} allowed-ips
|
||
|
|
||
|
/usr/bin/wg show "${TLD}" allowed-ips \
|
||
|
| while read pubkey ipv4 ipv6; do
|
||
|
ipv4="${ipv4%%/*}"
|
||
|
ipv6="${ipv6%%/*}"
|
||
|
#TODO Combine these next two into one nslookup
|
||
|
username="$(../../ns/lookup/user ${ipv4})"
|
||
|
hostname="$(../../ns/lookup/host ${ipv4})"
|
||
|
if [ "${2}" == 'json' ]; then
|
||
|
#TODO Remove keys with empty ("") values
|
||
|
printf "{\"hostname\":\"${hostname}.${username}.${TLD}\",\"ipv4\":\"${ipv4}\",\"ipv6\":\"${ipv6}\",\"pubkey\":\"${pubkey}\"},"
|
||
|
elif [ "${2}" == 'tsv' ]; then
|
||
|
printf "${hostname}.${username}.${TLD}\t${ipv4}\t${ipv6}\t${pubkey}\n"
|
||
|
fi
|
||
|
done | sed 's/,$//' # Remove trailing comma from json
|