diff --git a/scripts/makeOVPN.sh b/scripts/makeOVPN.sh index 4b5a52d..4dddbc0 100644 --- a/scripts/makeOVPN.sh +++ b/scripts/makeOVPN.sh @@ -8,6 +8,7 @@ OKEY=".key" KEY=".3des.key" CA="ca.crt" TA="ta.key" +INDEX="/etc/openvpn/easy-rsa/keys/index.txt" INSTALL_USER=$(cat /etc/pivpn/INSTALL_USER) # Functions def @@ -44,7 +45,7 @@ function keyPASS() { stty -echo while true do - printf "Enter the password for the Client: " + printf "Enter the password for the client: " read -r PASSWD printf "\n" printf "Enter the password again to verify: " @@ -111,6 +112,20 @@ if [[ -z "$NAME" ]]; then exit 1 fi +# Check if name is already in use +while read -r line || [ -n "$line" ]; do + if [ "$(echo "$line" | sed -e 's/^.*CN=\([^/]*\)\/.*/\1/')" = "$NAME" ]; then + echo "Name is already in use" + exit 1 + fi +done <$INDEX + +# Check if name is reserved +if [ "$NAME" = "ta" ] || [ "$NAME" = "server" ] || [ "$NAME" = "ca" ]; then + echo "Sorry, this name is unavailable, please choose another one" + exit 1 +fi + cd /etc/openvpn/easy-rsa || exit source /etc/openvpn/easy-rsa/vars