diff --git a/README.md b/README.md index 251bb2d..1828d36 100644 --- a/README.md +++ b/README.md @@ -241,7 +241,7 @@ ____ | 1 |**add\|del**|add or delete client config|**REQUIRED**| | 2 |**\**|client username|**REQUIRED**| | 3 |**\**|client password|| -| 4 |**[-f]**|service will restart after username delete|| +| 4 |**[-f]**,**[--force]**|service will restart after username delete|| Example usage: diff --git a/ovpn-client-management.sh b/ovpn-client-management.sh index 5476731..1159274 100644 --- a/ovpn-client-management.sh +++ b/ovpn-client-management.sh @@ -6,6 +6,7 @@ # sending config and info to email # # DEPENDENCIES: +# - privileged rights # - chpasswd # - openvpn # - easy-rsa @@ -17,7 +18,7 @@ # 1: "add|del" - add or delete client config # 2: username - client username # 3: password - client password -# -f - service will restart after username delete +# -f|--force - service will restart after username delete # # FUNCTIONS: # @@ -284,19 +285,31 @@ easyrsavar="${easyrsadir}/vars" easyrsacap="openvpnca" ovpncfgdir="/etc/openvpn/client" ovpncfgdef="${ovpncfgdir}/client.conf.default" -logs=/var/log/openvpn/$(basename -s .sh "$0").log clienttodo=$1 clientname=$2 clientpass=$3 +resetforce=0 +for argument in "${@}"; do + case $argument in + -f | --force ) + resetforce=1 + ;; + -* ) + ;; + esac +done + time=$(date +%s) +logs=/dev/null # # MAIN: # if checkroot; then + logs=/var/log/openvpn/$(basename -s .sh "$0").log if [ "${clienttodo}" == "add" ] && \ [ -n "${clientname}" ] && \ [ "${#clientpass}" -ge 8 ]; then @@ -313,28 +326,15 @@ if checkroot; then startsendmail fi elif [ "${clienttodo}" == "del" ] && [ -n "${clientname}" ]; then - resetforce=0 - while :; do - case "${3-}" in - -f | --force) - resetforce=1 - shift - ;; - *) - break - ;; - esac - shift - done if id -u "${clientname}" >/dev/null 2>&1 || \ grep -w "${clientname}" ${easyrsaidx} || \ [ -e "${ovpncfgdir}/${clientname}.ovpn" ]; then deleteuser addtologs "deleted Linux user '${clientname}'" - deletecert - deleteovpn - deletetars - deleteinfo + deletecert && addtologs "deleted certificate for ${clientname}" + deleteovpn && addtologs "deleted ovpn config file for ${clientname}" + deletetars && addtologs "deleted tar with config file for ${clientname}" + deleteinfo && addtologs "deleted info file for ${clientname}" if [ "${resetforce}" -eq 1 ];then addtologs "restarting openvpn@server..." systemctl restart openvpn@server