diff --git a/README.md b/README.md index 23a3957..9f75d6f 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,18 @@ export PASS="1" ./openvpn-install.sh ``` +### Headless User Removal + +The removal of an existing user can also be fully automated. Again, the key is to provide the (string) value of the `MENU_OPTION` variable along with the remaining mandatory variables before invoking the script. + +The following Bash script removes the existing user `bar` from an OpenVPN configuration +```bash +#!/bin/bash +export MENU_OPTION="2" +export CLIENT="bar" +./openvpn-install.sh +``` + ## Features - Installs and configures a ready-to-use OpenVPN server diff --git a/openvpn-install.sh b/openvpn-install.sh index 685f607..3e2e8ab 100755 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -1144,14 +1144,16 @@ function revokeClient() { echo "" echo "Select the existing client certificate you want to revoke" tail -n +2 /etc/openvpn/easy-rsa/pki/index.txt | grep "^V" | cut -d '=' -f 2 | nl -s ') ' - until [[ $CLIENTNUMBER -ge 1 && $CLIENTNUMBER -le $NUMBEROFCLIENTS ]]; do - if [[ $CLIENTNUMBER == '1' ]]; then - read -rp "Select one client [1]: " CLIENTNUMBER - else - read -rp "Select one client [1-$NUMBEROFCLIENTS]: " CLIENTNUMBER - fi + until [[ "$CLIENT" =~ ^[a-zA-Z0-9_]+$ ]]; do + until [[ $CLIENTNUMBER -ge 1 && $CLIENTNUMBER -le $NUMBEROFCLIENTS ]]; do + if [[ $CLIENTNUMBER == '1' ]]; then + read -rp "Select one client [1]: " CLIENTNUMBER + else + read -rp "Select one client [1-$NUMBEROFCLIENTS]: " CLIENTNUMBER + fi + done + CLIENT=$(tail -n +2 /etc/openvpn/easy-rsa/pki/index.txt | grep "^V" | cut -d '=' -f 2 | sed -n "$CLIENTNUMBER"p) done - 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/ || return ./easyrsa --batch revoke "$CLIENT" EASYRSA_CRL_DAYS=3650 ./easyrsa gen-crl