pivpn/scripts/openvpn/listOVPN.sh

57 lines
1.4 KiB
Bash
Raw Normal View History

2022-07-27 12:53:36 +00:00
#!/bin/bash
2019-10-14 10:27:28 +00:00
# PiVPN: list clients script
2022-07-27 12:53:36 +00:00
# Updated Script to include Expiration Dates and
# Clean up Escape Seq -- psgoundar
2019-10-14 10:27:28 +00:00
INDEX="/etc/openvpn/easy-rsa/pki/index.txt"
EASYRSA="/etc/openvpn/easy-rsa/easyrsa"
2022-07-27 12:53:36 +00:00
err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
}
if [[ ! -f "${INDEX}" ]]; then
err "The file: ${INDEX} was not found!"
exit 1
2019-10-14 10:27:28 +00:00
fi
2022-07-27 12:53:36 +00:00
if [[ ! -f "${EASYRSA}" ]]; then
err "The file: ${EASYRSA} was not found!"
exit 1
2020-10-01 11:23:31 +00:00
fi
2022-07-27 12:53:36 +00:00
"${EASYRSA}" update-db >> /dev/null 2>&1
2020-09-10 12:55:35 +00:00
2022-07-27 12:53:36 +00:00
printf ": NOTE : The first entry is your server, "
printf "which should always be valid!\n"
printf "\\n"
printf "\\e[1m::: Certificate Status List :::\\e[0m\\n"
2022-07-27 12:53:36 +00:00
{
2022-07-27 12:53:36 +00:00
printf "\\e[4mStatus\\e[0m \t \\e[4mName\\e[0m\\e[0m \t "
printf "\\e[4mExpiration\\e[0m\\n"
while read -r line || [[ -n "${line}" ]]; do
STATUS="$(echo "${line}" | awk '{print $1}')"
NAME="$(echo "${line}" | awk -FCN= '{print $2}')"
EXPD="$(echo "${line}" \
| awk '{if (length($2) == 15) print $2; else print "20"$2}' \
| cut -b 1-8 \
| date +"%b %d %Y" -f -)"
2022-07-27 12:53:36 +00:00
if [[ "${STATUS}" == "V" ]]; then
printf "Valid"
elif [[ "${STATUS}" == "R" ]]; then
printf "Revoked"
elif [[ "${STATUS}" == "E" ]]; then
printf "Expired"
2019-10-14 10:27:28 +00:00
else
2022-07-27 12:53:36 +00:00
printf "Unknown"
2019-10-14 10:27:28 +00:00
fi
2022-07-27 12:53:36 +00:00
printf " \t %s \t %s\\n" "$(echo -e "${NAME}")" "${EXPD}"
done < "${INDEX}"
printf "\\n"
} | column -t -s $'\t'