diff --git a/openvpn-install.sh b/openvpn-install.sh index ee420ca..62c5642 100644 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -110,6 +110,18 @@ if [[ -e /etc/openvpn/server.conf ]]; then else read -p "Select one client [1-$NUMBEROFCLIENTS]: " CLIENTNUMBER fi + #check if selected client does exist + if [[ !("$CLIENTNUMBER" =~ ^[0-9]+$) ]]; then + echo "" + echo "error: please enter a valid number!" + exit + fi + if [[ "$CLIENTNUMBER" < "1" || "$CLIENTNUMBER" > "$NUMBEROFCLIENTS" || ${#CLIENTNUMBER} != ${#NUMBEROFCLIENTS} ]]; then + echo "" + echo "error: could not find client number $CLIENTNUMBER." + exit + fi + echo "INPUT: $CLIENTNUMBER" CLIENT=$(tail -n +2 /etc/openvpn/easy-rsa/pki/index.txt | grep "^V" | cut -d '=' -f 2 | sed -n "$CLIENTNUMBER"p) cd /etc/openvpn/easy-rsa/ ./easyrsa --batch revoke $CLIENT @@ -422,4 +434,4 @@ verb 3" > /etc/openvpn/client-common.txt echo "" echo "Your client configuration is available at" ~/"$CLIENT.ovpn" echo "If you want to add more clients, you simply need to run this script again!" -fi \ No newline at end of file +fi