2019-10-14 10:27:28 +00:00
|
|
|
#!/bin/bash
|
2022-10-07 23:11:10 +00:00
|
|
|
### Constants
|
2019-10-14 10:27:28 +00:00
|
|
|
|
2022-10-07 23:11:10 +00:00
|
|
|
### Funcions
|
2022-07-27 12:53:36 +00:00
|
|
|
err() {
|
|
|
|
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
|
|
|
|
}
|
|
|
|
|
2022-10-07 23:11:10 +00:00
|
|
|
### Script
|
2021-02-13 11:09:11 +00:00
|
|
|
cd /etc/wireguard/configs || exit
|
2022-07-27 12:53:36 +00:00
|
|
|
|
|
|
|
if [[ ! -s clients.txt ]]; then
|
|
|
|
err "::: There are no clients to list"
|
|
|
|
exit 1
|
2019-10-14 10:27:28 +00:00
|
|
|
fi
|
|
|
|
|
2019-12-27 14:48:42 +00:00
|
|
|
printf "\e[1m::: Clients Summary :::\e[0m\n"
|
|
|
|
|
2019-10-14 10:27:28 +00:00
|
|
|
# Present the user with a summary of the clients, fetching info from dates.
|
2019-12-27 14:48:42 +00:00
|
|
|
{
|
2022-07-27 12:53:36 +00:00
|
|
|
echo -ne "\e[4mClient\e[0m \t \e[4mPublic key\e[0m \t "
|
|
|
|
echo -e "\e[4mCreation date\e[0m"
|
2019-10-14 10:27:28 +00:00
|
|
|
|
2022-07-27 12:53:36 +00:00
|
|
|
while read -r LINE; do
|
|
|
|
CLIENT_NAME="$(awk '{print $1}' <<< "${LINE}")"
|
|
|
|
PUBLIC_KEY="$(awk '{print $2}' <<< "${LINE}")"
|
|
|
|
CREATION_DATE="$(awk '{print $3}' <<< "${LINE}")"
|
2019-10-14 10:27:28 +00:00
|
|
|
# Dates are converted from UNIX time to human readable.
|
2022-07-27 12:53:36 +00:00
|
|
|
CD_FORMAT="$(date -d @"${CREATION_DATE}" +'%d %b %Y, %H:%M, %Z')"
|
|
|
|
echo -e "${CLIENT_NAME} \t ${PUBLIC_KEY} \t ${CD_FORMAT}"
|
|
|
|
done < clients.txt
|
2020-10-21 21:35:29 +00:00
|
|
|
} | column -t -s $'\t'
|
|
|
|
|
|
|
|
cd /etc/wireguard || return
|
2022-07-27 12:53:36 +00:00
|
|
|
|
2020-10-21 21:35:29 +00:00
|
|
|
echo "::: Disabled clients :::"
|
2020-12-09 23:07:28 +00:00
|
|
|
grep '\[disabled\] ### begin' wg0.conf | sed 's/#//g; s/begin//'
|