From 4aa9a7f9d881b28125d62ae258fac948602ea008 Mon Sep 17 00:00:00 2001 From: Swamy Goundar Date: Sat, 2 May 2020 02:21:35 -0700 Subject: [PATCH 1/6] Added List Certificate Function --- openvpn-install | 1 + openvpn-install.sh | 42 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) create mode 160000 openvpn-install diff --git a/openvpn-install b/openvpn-install new file mode 160000 index 0000000..95be2fa --- /dev/null +++ b/openvpn-install @@ -0,0 +1 @@ +Subproject commit 95be2fa3f039c6d9667430c3b858e03da606199b diff --git a/openvpn-install.sh b/openvpn-install.sh index 5f49ada..3f7effd 100755 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -1291,6 +1291,34 @@ function removeOpenVPN() { fi } +function listcerts () { +# Original Script from PiVPN: list clients script +# Modified Script to add Certificate expiration Date -- psgoundar +INDEX="/etc/openvpn/easy-rsa/pki/index.txt" +printf "\\n" +if [ ! -f "${INDEX}" ]; then + echo "The file: $INDEX was not found!" + exit 1 +fi +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" | 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 + printf " Valid :: %s :: %s\\n" "$NAME" "$EXPD" + elif [ "${STATUS}" == "R" ]; then + #printf " Revoked :: %s :: %s\\n" "$NAME" "$EXPD" + continue + else + printf " Unknown :: %s :: %s\\n" "$NAME" "$EXPD" + fi +done <${INDEX} | column -t +printf "\\n" +} + function manageMenu() { echo "Welcome to OpenVPN-install!" echo "The git repository is available at: https://github.com/angristan/openvpn-install" @@ -1300,10 +1328,11 @@ function manageMenu() { echo "What do you want to do?" echo " 1) Add a new user" echo " 2) Revoke existing user" - echo " 3) Remove OpenVPN" - echo " 4) Exit" - until [[ $MENU_OPTION =~ ^[1-4]$ ]]; do - read -rp "Select an option [1-4]: " MENU_OPTION + echo " 3) List Current Issued Certificates" + echo " 4) Remove OpenVPN" + echo " 5) Exit" + until [[ $MENU_OPTION =~ ^[1-5]$ ]]; do + read -rp "Select an option [1-5]: " MENU_OPTION done case $MENU_OPTION in @@ -1314,9 +1343,12 @@ function manageMenu() { revokeClient ;; 3) - removeOpenVPN + listcerts ;; 4) + removeOpenVPN + ;; + 5) exit 0 ;; esac From 27476923475e870debcaefc7969510cfa685b679 Mon Sep 17 00:00:00 2001 From: Swamy Goundar Date: Fri, 3 Jul 2020 19:59:11 -0700 Subject: [PATCH 2/6] Fixed Case, Tab Issues --- openvpn-install.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/openvpn-install.sh b/openvpn-install.sh index 6bac896..0b160ed 100755 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -1286,7 +1286,7 @@ function removeOpenVPN() { fi } -function listcerts () { +function listCerts () { # Original Script from PiVPN: list clients script # Modified Script to add Certificate expiration Date -- psgoundar INDEX="/etc/openvpn/easy-rsa/pki/index.txt" @@ -1303,12 +1303,11 @@ 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" - continue + 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" @@ -1323,7 +1322,7 @@ function manageMenu() { echo "What do you want to do?" echo " 1) Add a new user" echo " 2) Revoke existing user" - echo " 3) List Current Issued Certificates" + echo " 3) List current issued certificates" echo " 4) Remove OpenVPN" echo " 5) Exit" until [[ $MENU_OPTION =~ ^[1-5]$ ]]; do @@ -1338,7 +1337,7 @@ function manageMenu() { revokeClient ;; 3) - listcerts + listCerts ;; 4) removeOpenVPN From 78041b86c616152f1fde842596b20ee1bdd2b7d7 Mon Sep 17 00:00:00 2001 From: Swamy Goundar Date: Fri, 3 Jul 2020 20:30:14 -0700 Subject: [PATCH 3/6] Delete Submodule --- openvpn-install | 1 - 1 file changed, 1 deletion(-) delete mode 160000 openvpn-install diff --git a/openvpn-install b/openvpn-install deleted file mode 160000 index 95be2fa..0000000 --- a/openvpn-install +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 95be2fa3f039c6d9667430c3b858e03da606199b From fba92491a2a1b35f5dd3d55885811ffa6c591c5d Mon Sep 17 00:00:00 2001 From: psgoundar Date: Sat, 4 Jul 2020 21:09:24 -0700 Subject: [PATCH 4/6] Update openvpn-install.sh Co-authored-by: randomshell --- openvpn-install.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openvpn-install.sh b/openvpn-install.sh index 0b160ed..6709a20 100755 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -1296,7 +1296,9 @@ if [ ! -f "${INDEX}" ]; then exit 1 fi 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 "\\n%6s\\t%14s\\t%22s\\n" "Status" "Name" "Expiration" +printf '=%.0s' {1..50} +printf '\n' while read -r line || [ -n "$line" ]; do STATUS=$(echo "$line" | awk '{print $1}') NAME=$(echo "$line" | awk '{print $5}' | awk -FCN= '{print $2}') From 63e915b2b47ea9fa1235b690a379a7085d13a598 Mon Sep 17 00:00:00 2001 From: psgoundar Date: Sat, 4 Jul 2020 21:12:10 -0700 Subject: [PATCH 5/6] Apply suggestions from code review Co-authored-by: randomshell --- openvpn-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openvpn-install.sh b/openvpn-install.sh index 6709a20..ef50936 100755 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -1301,7 +1301,7 @@ printf '=%.0s' {1..50} printf '\n' while read -r line || [ -n "$line" ]; do STATUS=$(echo "$line" | awk '{print $1}') - NAME=$(echo "$line" | awk '{print $5}' | awk -FCN= '{print $2}') + NAME=$(echo "$line" | cut -d '=' -f2) 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 b90c15512a7a6a773da90edbe3adcac65830785d Mon Sep 17 00:00:00 2001 From: psgoundar Date: Wed, 8 Jul 2020 20:18:25 -0700 Subject: [PATCH 6/6] Update openvpn-install.sh Co-authored-by: randomshell --- openvpn-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openvpn-install.sh b/openvpn-install.sh index ef50936..7a2fbe4 100755 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -1302,7 +1302,7 @@ printf '\n' while read -r line || [ -n "$line" ]; do STATUS=$(echo "$line" | awk '{print $1}') NAME=$(echo "$line" | cut -d '=' -f2) - EXPD=$(echo "$line" | awk '{if (length($2) == 15) print $2; else print "20"$2}' | cut -b 1-8 | date +"%b %d %Y" -f -) + EXPD=$(echo "$line" | awk '{if (length($3) == 13) print "20"$3; else print "20"$2}' | cut -b 1-8 | date +"%b %d %Y" -f -) if [ "${STATUS}" == "V" ]; then printf "Valid \t %s \t %s\\n" "$NAME" "$EXPD"