Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Certificate List Function V2 #669

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions openvpn-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,35 @@ 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 "\\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" | 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 -)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expiration date is wrong for revoked clients, we should use the column provided instead of calculating it.

psgoundar marked this conversation as resolved.
Show resolved Hide resolved

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"
else
printf "Unknown \t %s \t %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"
Expand All @@ -1295,10 +1324,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
Expand All @@ -1309,9 +1339,12 @@ function manageMenu() {
revokeClient
;;
3)
removeOpenVPN
listCerts
;;
4)
removeOpenVPN
;;
5)
exit 0
;;
esac
Expand Down