simple refactoring
This commit is contained in:
parent
819700cbbe
commit
4a1318bb1d
|
@ -241,7 +241,7 @@ ____
|
||||||
| 1 |**add\|del**|add or delete client config|**REQUIRED**|
|
| 1 |**add\|del**|add or delete client config|**REQUIRED**|
|
||||||
| 2 |**\<username\>**|client username|**REQUIRED**|
|
| 2 |**\<username\>**|client username|**REQUIRED**|
|
||||||
| 3 |**\<password\>**|client password||
|
| 3 |**\<password\>**|client password||
|
||||||
| 4 |**[-f]**|service will restart after username delete||
|
| 4 |**[-f]**,**[--force]**|service will restart after username delete||
|
||||||
|
|
||||||
Example usage:
|
Example usage:
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
# sending config and info to email
|
# sending config and info to email
|
||||||
#
|
#
|
||||||
# DEPENDENCIES:
|
# DEPENDENCIES:
|
||||||
|
# - privileged rights
|
||||||
# - chpasswd
|
# - chpasswd
|
||||||
# - openvpn
|
# - openvpn
|
||||||
# - easy-rsa
|
# - easy-rsa
|
||||||
|
@ -17,7 +18,7 @@
|
||||||
# 1: "add|del" - add or delete client config
|
# 1: "add|del" - add or delete client config
|
||||||
# 2: username - client username
|
# 2: username - client username
|
||||||
# 3: password - client password
|
# 3: password - client password
|
||||||
# -f - service will restart after username delete
|
# -f|--force - service will restart after username delete
|
||||||
#
|
#
|
||||||
# FUNCTIONS:
|
# FUNCTIONS:
|
||||||
#
|
#
|
||||||
|
@ -284,19 +285,31 @@ easyrsavar="${easyrsadir}/vars"
|
||||||
easyrsacap="openvpnca"
|
easyrsacap="openvpnca"
|
||||||
ovpncfgdir="/etc/openvpn/client"
|
ovpncfgdir="/etc/openvpn/client"
|
||||||
ovpncfgdef="${ovpncfgdir}/client.conf.default"
|
ovpncfgdef="${ovpncfgdir}/client.conf.default"
|
||||||
logs=/var/log/openvpn/$(basename -s .sh "$0").log
|
|
||||||
|
|
||||||
clienttodo=$1
|
clienttodo=$1
|
||||||
clientname=$2
|
clientname=$2
|
||||||
clientpass=$3
|
clientpass=$3
|
||||||
|
|
||||||
|
resetforce=0
|
||||||
|
for argument in "${@}"; do
|
||||||
|
case $argument in
|
||||||
|
-f | --force )
|
||||||
|
resetforce=1
|
||||||
|
;;
|
||||||
|
-* )
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
time=$(date +%s)
|
time=$(date +%s)
|
||||||
|
logs=/dev/null
|
||||||
|
|
||||||
#
|
#
|
||||||
# MAIN:
|
# MAIN:
|
||||||
#
|
#
|
||||||
|
|
||||||
if checkroot; then
|
if checkroot; then
|
||||||
|
logs=/var/log/openvpn/$(basename -s .sh "$0").log
|
||||||
if [ "${clienttodo}" == "add" ] && \
|
if [ "${clienttodo}" == "add" ] && \
|
||||||
[ -n "${clientname}" ] && \
|
[ -n "${clientname}" ] && \
|
||||||
[ "${#clientpass}" -ge 8 ]; then
|
[ "${#clientpass}" -ge 8 ]; then
|
||||||
|
@ -313,28 +326,15 @@ if checkroot; then
|
||||||
startsendmail
|
startsendmail
|
||||||
fi
|
fi
|
||||||
elif [ "${clienttodo}" == "del" ] && [ -n "${clientname}" ]; then
|
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 || \
|
if id -u "${clientname}" >/dev/null 2>&1 || \
|
||||||
grep -w "${clientname}" ${easyrsaidx} || \
|
grep -w "${clientname}" ${easyrsaidx} || \
|
||||||
[ -e "${ovpncfgdir}/${clientname}.ovpn" ]; then
|
[ -e "${ovpncfgdir}/${clientname}.ovpn" ]; then
|
||||||
deleteuser
|
deleteuser
|
||||||
addtologs "deleted Linux user '${clientname}'"
|
addtologs "deleted Linux user '${clientname}'"
|
||||||
deletecert
|
deletecert && addtologs "deleted certificate for ${clientname}"
|
||||||
deleteovpn
|
deleteovpn && addtologs "deleted ovpn config file for ${clientname}"
|
||||||
deletetars
|
deletetars && addtologs "deleted tar with config file for ${clientname}"
|
||||||
deleteinfo
|
deleteinfo && addtologs "deleted info file for ${clientname}"
|
||||||
if [ "${resetforce}" -eq 1 ];then
|
if [ "${resetforce}" -eq 1 ];then
|
||||||
addtologs "restarting openvpn@server..."
|
addtologs "restarting openvpn@server..."
|
||||||
systemctl restart openvpn@server
|
systemctl restart openvpn@server
|
||||||
|
|
Loading…
Reference in New Issue
Block a user