Update openvpn-install.sh

Added a new option for creating multiple clients at the same time
This commit is contained in:
Reza Ghasemi 2022-07-23 01:05:00 -04:00 committed by GitHub
parent c0a3562f64
commit 47723a0679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -441,11 +441,12 @@ else
echo echo
echo "Select an option:" echo "Select an option:"
echo " 1) Add a new client" echo " 1) Add a new client"
echo " 2) Revoke an existing client" echo " 2) Add Multiple clients"
echo " 3) Remove OpenVPN" echo " 3) Revoke an existing client"
echo " 4) Exit" echo " 4) Remove OpenVPN"
echo " 5) Exit"
read -p "Option: " option read -p "Option: " option
until [[ "$option" =~ ^[1-4]$ ]]; do until [[ "$option" =~ ^[1-5]$ ]]; do
echo "$option: invalid selection." echo "$option: invalid selection."
read -p "Option: " option read -p "Option: " option
done done
@ -468,7 +469,29 @@ else
echo "$client added. Configuration available in:" ~/"$client.ovpn" echo "$client added. Configuration available in:" ~/"$client.ovpn"
exit exit
;; ;;
# Adding 15-20 clinets is a little boring when you must run the script many times on a new server
# so I added option 2 to add all clients at the same time :)
2) 2)
echo
echo "Enter your names seperated by space:"
echo "Example: name1 name2 name3 "
read -r -p "Names: " -a names
for unsanitized_client in "${names[@]}"; do
client=$(sed 's/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-]/_/g' <<< "$unsanitized_client")
while [[ -z "$client" || -e /etc/openvpn/server/easy-rsa/pki/issued/"$client".crt ]]; do
echo "$client: invalid name."
read -p "Name: " unsanitized_client
client=$(sed 's/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-]/_/g' <<< "$unsanitized_client")
done
cd /etc/openvpn/server/easy-rsa/
EASYRSA_CERT_EXPIRE=3650 ./easyrsa build-client-full "$client" nopass
new_client
echo
echo "$client added. Configuration available in:" ~/"$client.ovpn"
done
exit
;;
3)
# This option could be documented a bit better and maybe even be simplified # This option could be documented a bit better and maybe even be simplified
# ...but what can I say, I want some sleep too # ...but what can I say, I want some sleep too
number_of_clients=$(tail -n +2 /etc/openvpn/server/easy-rsa/pki/index.txt | grep -c "^V") number_of_clients=$(tail -n +2 /etc/openvpn/server/easy-rsa/pki/index.txt | grep -c "^V")
@ -508,7 +531,7 @@ else
fi fi
exit exit
;; ;;
3) 4)
echo echo
read -p "Confirm OpenVPN removal? [y/N]: " remove read -p "Confirm OpenVPN removal? [y/N]: " remove
until [[ "$remove" =~ ^[yYnN]*$ ]]; do until [[ "$remove" =~ ^[yYnN]*$ ]]; do
@ -560,7 +583,7 @@ else
fi fi
exit exit
;; ;;
4) 5)
exit exit
;; ;;
esac esac