myvesta/bin/v-suspend-user
2015-06-03 18:40:10 +03:00

102 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# info: suspend user
# options: USER [RESTART]
#
# The function suspends a certain user and all his objects.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
restart=$2
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'USER [RESTART]'
validate_format 'user'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
if [ "$user" = 'admin' ]; then
exit
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Adding '!' in front of the password
/usr/sbin/usermod --lock $user
# Suspending ftp accounts
for ftp in $(grep ^$user_.* /etc/passwd| cut -f 1 -d : ); do
/usr/sbin/usermod --lock $ftp 2>/dev/null
done
# Suspending web domains
if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
$BIN/v-suspend-web-domains $user $restart
fi
# Suspending dns domains
if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS_SYSTEM" != 'no' ]; then
$BIN/v-suspend-dns-domains $user $restart
fi
# Suspending mail domains
if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then
$BIN/v-suspend-mail-domains $user
fi
# Suspending datbabases
if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then
$BIN/v-suspend-databases $user
fi
# Suspending cron jobs
if [ ! -z "$CRON_SYSTEM" ] && [ "$CRON_SYSTEM" != 'no' ]; then
$BIN/v-suspend-cron-jobs $user $restart
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Restart web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
$BIN/v-restart-cron
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
# Changing suspend value
update_user_value "$user" '$SUSPENDED' 'yes'
increase_user_value 'admin' '$SUSPENDED_USERS'
# Logging
log_event "$OK" "$EVENT"
exit