mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-21 12:20:16 +00:00
d17d381049
DNS resolution even if the user does not route the local network through the tunnel. - Format listCONF in a similar way as listOVPN - Specifically look for a free octet in the last word of clients.txt and not just any word. Necessary otherwhise public keys starting with a number will match against an octet. Example: if line is 'name 5abcdefgh 4', then looking for ' 5' will match but '5$' will not (correctly). - 'pivpn -c' will show the Connected Clients List for WireGuard too
39 lines
No EOL
1.3 KiB
Bash
Executable file
39 lines
No EOL
1.3 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
cd /etc/wireguard/configs
|
|
if [ ! -s clients.txt ]; then
|
|
echo "::: There are no clients to list"
|
|
exit 1
|
|
fi
|
|
|
|
hr(){
|
|
numfmt --to=iec-i --suffix=B "$1"
|
|
}
|
|
|
|
DUMP="$(wg show wg0 dump | tail -n +2)"
|
|
|
|
printf "\e[1m::: Connected Clients List :::\e[0m\n"
|
|
|
|
{
|
|
printf "\e[4mName\e[0m \t \e[4mRemote IP\e[0m \t \e[4mVirtual IP\e[0m \t \e[4mBytes Received\e[0m \t \e[4mBytes Sent\e[0m \t \e[4mLast Seen\e[0m\n"
|
|
|
|
while IFS= read -r LINE; do
|
|
|
|
PUBLIC_KEY="$(awk '{ print $1 }' <<< "$LINE")"
|
|
REMOTE_IP="$(awk '{ print $3 }' <<< "$LINE")"
|
|
VIRTUAL_IP="$(awk '{ print $4 }' <<< "$LINE")"
|
|
BYTES_RECEIVED="$(awk '{ print $6 }' <<< "$LINE")"
|
|
BYTES_SENT="$(awk '{ print $7 }' <<< "$LINE")"
|
|
LAST_SEEN="$(awk '{ print $5 }' <<< "$LINE")"
|
|
CLIENT_NAME="$(grep "$PUBLIC_KEY" clients.txt | awk '{ print $1 }')"
|
|
|
|
if [ "$LAST_SEEN" -ne 0 ]; then
|
|
printf "%s \t %s \t %s \t %s \t %s \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$(hr "$BYTES_RECEIVED")" "$(hr "$BYTES_SENT")" "$(date -d @"$LAST_SEEN" '+%b %m %Y - %T')"
|
|
else
|
|
printf "%s \t %s \t %s \t %s \t %s \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$(hr "$BYTES_RECEIVED")" "$(hr "$BYTES_SENT")" "(not yet)"
|
|
fi
|
|
|
|
done <<< "$DUMP"
|
|
|
|
printf "\n"
|
|
} | column -t -s $'\t' |