Reformatted the code

This commit is contained in:
Giulio Coa 2022-07-27 14:53:36 +02:00
parent 47e8908489
commit af20461590
24 changed files with 2655 additions and 2021 deletions

View file

@ -1,42 +1,57 @@
#!/usr/bin/env bash
#!/bin/bash
# PiVPN: list clients script
# Updated Script to include Expiration Dates and Clean up Escape Seq -- psgoundar
# Updated Script to include Expiration Dates and
# Clean up Escape Seq -- psgoundar
INDEX="/etc/openvpn/easy-rsa/pki/index.txt"
if [ ! -f "${INDEX}" ]; then
echo "The file: $INDEX was not found!"
exit 1
err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
}
if [[ ! -f "${INDEX}" ]]; then
err "The file: ${INDEX} was not found!"
exit 1
fi
EASYRSA="/etc/openvpn/easy-rsa/easyrsa"
if [ ! -f "${EASYRSA}" ]; then
echo "The file: $EASYRSA was not found!"
exit 1
if [[ ! -f "${EASYRSA}" ]]; then
err "The file: ${EASYRSA} was not found!"
exit 1
fi
$EASYRSA update-db >> /dev/null 2>&1
"${EASYRSA}" update-db >> /dev/null 2>&1
printf ": NOTE : The first entry is your server, which should always be valid!\n"
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"
{
printf "\\e[4mStatus\\e[0m \t \\e[4mName\\e[0m\\e[0m \t \\e[4mExpiration\\e[0m\\n"
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 -)
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 -)"
if [ "${STATUS}" == "V" ]; then
printf "Valid \t %s \t %s\\n" "$(echo -e "$NAME")" "$EXPD"
elif [ "${STATUS}" == "R" ]; then
printf "Revoked \t %s \t %s\\n" "$(echo -e "$NAME")" "$EXPD"
elif [ "${STATUS}" == "E" ]; then
printf "Expired \t %s \t %s\\n" "$(echo -e "$NAME")" "$EXPD"
if [[ "${STATUS}" == "V" ]]; then
printf "Valid"
elif [[ "${STATUS}" == "R" ]]; then
printf "Revoked"
elif [[ "${STATUS}" == "E" ]]; then
printf "Expired"
else
printf "Unknown \t %s \t %s\\n" "$(echo -e "$NAME")" "$EXPD"
printf "Unknown"
fi
done <${INDEX}
printf "\\n"
printf " \t %s \t %s\\n" "$(echo -e "${NAME}")" "${EXPD}"
done < "${INDEX}"
printf "\\n"
} | column -t -s $'\t'