From d8d89c758b5cae348694c3ca60be4d15c76ec672 Mon Sep 17 00:00:00 2001 From: redfast00 Date: Tue, 4 Oct 2016 20:54:09 +0200 Subject: [PATCH] Prevent overwriting files --- scripts/makeOVPN.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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