From f778282002065c359ab3bd84d20363dd864712b4 Mon Sep 17 00:00:00 2001 From: zocker-160 Date: Mon, 19 Feb 2018 20:04:05 +0100 Subject: [PATCH] check if selected client to revoke does exist --- openvpn-install.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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