From c28448b94a28bd85debd48009bf014e3e63548ef Mon Sep 17 00:00:00 2001 From: Swamy Goundar Date: Sat, 28 Mar 2020 19:36:55 -0700 Subject: [PATCH 1/5] Updated listOVPN to Include Expiration Dates --- scripts/openvpn/listOVPN.sh | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/scripts/openvpn/listOVPN.sh b/scripts/openvpn/listOVPN.sh index ec0ffd7..cb3130f 100755 --- a/scripts/openvpn/listOVPN.sh +++ b/scripts/openvpn/listOVPN.sh @@ -1,27 +1,31 @@ #!/usr/bin/env bash # PiVPN: list clients script +# Updated Script to include Expiration Dates and Clean up Escape Seq -- psgoundar INDEX="/etc/openvpn/easy-rsa/pki/index.txt" -printf "\n" +printf "\\n" if [ ! -f "${INDEX}" ]; then echo "The file: $INDEX was not found!" exit 1 fi printf ": NOTE : The first entry should always be your valid server!\n" -printf "\n" -printf "\e[1m::: Certificate Status List :::\e[0m\n" -printf " ::\e[4m Status \e[0m||\e[4m Name \e[0m:: \n" +printf "\\n" +printf "\\e[1m::: Certificate Status List :::\\e[0m\\n" +printf "\\e[4mStatus\\e[0m :: \\e[4mName\\e[0m\\e[0m :: \\e[4mExpiration \\e[0m\\n" while read -r line || [ -n "$line" ]; do STATUS=$(echo "$line" | awk '{print $1}') - NAME=$(echo "$line" | sed -e 's:.*/CN=::') + NAME=$(echo "$line" | awk '{print $5}' | awk -F= '{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 :: %s\n" "$NAME" + printf " Valid :: %s :: %s\\n" "$NAME" "$EXPD" elif [ "${STATUS}" == "R" ]; then - printf " Revoked :: %s\n" "$NAME" + printf " Revoked :: %s :: %s\\n" "$NAME" "$EXPD" else - printf " Unknown :: %s\n" "$NAME" + printf " Unknown :: %s :: %s\\n" "$NAME" "$EXPD" fi -done <${INDEX} -printf "\n" + +done <${INDEX} | column -t +printf "\\n" \ No newline at end of file From 289e85e3064bac13e662e5c9ea7185b5f8c80f28 Mon Sep 17 00:00:00 2001 From: Swamy Goundar Date: Sat, 28 Mar 2020 20:48:44 -0700 Subject: [PATCH 2/5] Fixed issue with Name when OU is defined in CA --- scripts/openvpn/listOVPN.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/openvpn/listOVPN.sh b/scripts/openvpn/listOVPN.sh index cb3130f..99f5be2 100755 --- a/scripts/openvpn/listOVPN.sh +++ b/scripts/openvpn/listOVPN.sh @@ -16,7 +16,7 @@ printf "\\e[4mStatus\\e[0m :: \\e[4mName\\e[0m\\e[0m :: \\e[4mExpiratio while read -r line || [ -n "$line" ]; do STATUS=$(echo "$line" | awk '{print $1}') - NAME=$(echo "$line" | awk '{print $5}' | awk -F= '{print $2}') + NAME=$(echo "$line" | awk '{print $5}' | 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 From ec6880eb99234937ddbcb3c0c65e414023ef4197 Mon Sep 17 00:00:00 2001 From: psgoundar Date: Wed, 1 Apr 2020 19:44:37 -0700 Subject: [PATCH 3/5] Apply suggestions from code review Format Changes Reviewed. Co-Authored-By: Orazio --- scripts/openvpn/listOVPN.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/openvpn/listOVPN.sh b/scripts/openvpn/listOVPN.sh index 99f5be2..b90bd58 100755 --- a/scripts/openvpn/listOVPN.sh +++ b/scripts/openvpn/listOVPN.sh @@ -3,7 +3,6 @@ # Updated Script to include Expiration Dates and Clean up Escape Seq -- psgoundar INDEX="/etc/openvpn/easy-rsa/pki/index.txt" -printf "\\n" if [ ! -f "${INDEX}" ]; then echo "The file: $INDEX was not found!" exit 1 @@ -12,7 +11,8 @@ fi printf ": NOTE : The first entry should always be your valid server!\n" printf "\\n" printf "\\e[1m::: Certificate Status List :::\\e[0m\\n" -printf "\\e[4mStatus\\e[0m :: \\e[4mName\\e[0m\\e[0m :: \\e[4mExpiration \\e[0m\\n" +{ +printf "\\e[4mStatus\\e[0m \t \\e[4mName\\e[0m\\e[0m \t \\e[4mExpiration\\e[0m\\n" while read -r line || [ -n "$line" ]; do STATUS=$(echo "$line" | awk '{print $1}') @@ -20,12 +20,14 @@ while read -r line || [ -n "$line" ]; do 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 :: %s :: %s\\n" "$NAME" "$EXPD" + printf "Valid \t %s \t %s\\n" "$NAME" "$EXPD" elif [ "${STATUS}" == "R" ]; then - printf " Revoked :: %s :: %s\\n" "$NAME" "$EXPD" + printf " Revoked \t %s \t %s\\n" "$NAME" "$EXPD" else - printf " Unknown :: %s :: %s\\n" "$NAME" "$EXPD" + printf "Unknown \t %s \t %s\\n" "$NAME" "$EXPD" fi -done <${INDEX} | column -t -printf "\\n" \ No newline at end of file +done <${INDEX} +printf "\\n" +} | column -t -s $'\t' +printf "\\n" From fb1cd97c28b9716a0b91f4612416591a2a6a4e18 Mon Sep 17 00:00:00 2001 From: psgoundar Date: Sun, 5 Apr 2020 14:34:53 -0700 Subject: [PATCH 4/5] Update scripts/openvpn/listOVPN.sh Co-Authored-By: Orazio --- scripts/openvpn/listOVPN.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/openvpn/listOVPN.sh b/scripts/openvpn/listOVPN.sh index b90bd58..3e29dbf 100755 --- a/scripts/openvpn/listOVPN.sh +++ b/scripts/openvpn/listOVPN.sh @@ -22,7 +22,7 @@ while read -r line || [ -n "$line" ]; do if [ "${STATUS}" == "V" ]; then printf "Valid \t %s \t %s\\n" "$NAME" "$EXPD" elif [ "${STATUS}" == "R" ]; then - printf " Revoked \t %s \t %s\\n" "$NAME" "$EXPD" + printf "Revoked \t %s \t %s\\n" "$NAME" "$EXPD" else printf "Unknown \t %s \t %s\\n" "$NAME" "$EXPD" fi From 4039a0d173e624340922f88dfafaf64939b5f389 Mon Sep 17 00:00:00 2001 From: psgoundar Date: Sun, 5 Apr 2020 14:35:33 -0700 Subject: [PATCH 5/5] Update scripts/openvpn/listOVPN.sh Co-Authored-By: Orazio --- scripts/openvpn/listOVPN.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/openvpn/listOVPN.sh b/scripts/openvpn/listOVPN.sh index 3e29dbf..1a7da35 100755 --- a/scripts/openvpn/listOVPN.sh +++ b/scripts/openvpn/listOVPN.sh @@ -30,4 +30,3 @@ while read -r line || [ -n "$line" ]; do done <${INDEX} printf "\\n" } | column -t -s $'\t' -printf "\\n"