mirror of
https://github.com/myvesta/vesta.git
synced 2024-12-03 02:40:25 -08:00
120 lines
3.1 KiB
Bash
Executable File
120 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# info: delete user
|
|
# options: USER
|
|
#
|
|
# This function deletes a certain user and all his resources such as domains,
|
|
# databases, cron jobs, etc.
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Variable&Function #
|
|
#----------------------------------------------------------#
|
|
|
|
# Argument definition
|
|
user=$1
|
|
restart=$2
|
|
|
|
# Includes
|
|
source $VESTA/func/main.sh
|
|
source $VESTA/func/domain.sh
|
|
source $VESTA/func/db.sh
|
|
source $VESTA/func/ip.sh
|
|
source $VESTA/conf/vesta.conf
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Verifications #
|
|
#----------------------------------------------------------#
|
|
|
|
check_args '1' "$#" 'USER'
|
|
is_format_valid 'user'
|
|
is_object_valid 'user' 'USER' "$user"
|
|
is_object_unsuspended 'user' 'USER' "$user"
|
|
if [ "$user" = 'admin' ]; then
|
|
exit
|
|
fi
|
|
|
|
#----------------------------------------------------------#
|
|
# Action #
|
|
#----------------------------------------------------------#
|
|
|
|
# Deleting web domains
|
|
if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
|
|
$BIN/v-unsuspend-web-domains $user $restart
|
|
$BIN/v-delete-web-domains $user $restart
|
|
check_result "$?" "web domain deletion failed"
|
|
fi
|
|
|
|
# Deleting dns domains
|
|
if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS_SYSTEM" != 'no' ]; then
|
|
$BIN/v-unsuspend-dns-domains $user $restart
|
|
$BIN/v-delete-dns-domains $user $restart
|
|
check_result "$?" "dns domain deletion failed"
|
|
fi
|
|
|
|
# Deleting mail domains
|
|
if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then
|
|
$BIN/v-unsuspend-mail-domains $user
|
|
$BIN/v-delete-mail-domains $user
|
|
check_result "$?" "mail domain deletion failed"
|
|
fi
|
|
|
|
# Deleting databases
|
|
if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then
|
|
$BIN/v-unsuspend-databases $user
|
|
$BIN/v-delete-databases $user
|
|
check_result "$?" "database deletion failed"
|
|
fi
|
|
|
|
# Releasing user ips
|
|
$BIN/v-delete-user-ips "$user"
|
|
check_result "$?" "user ip release failed"
|
|
|
|
# Deleteing user pipes
|
|
sed -i "/ $user$/d" $VESTA/data/queue/disk.pipe
|
|
sed -i "/ $user$/d" $VESTA/data/queue/traffic.pipe
|
|
|
|
# Deleting sftp jail
|
|
if [ ! -z "$SFTPJAIL_KEY" ]; then
|
|
$BIN/v-delete-user-sftp-jail $user
|
|
fi
|
|
|
|
# Deleting system user
|
|
/usr/sbin/userdel -f $user >> /dev/null 2>&1
|
|
if [ $? -ne 0 ]; then
|
|
sed -i "/^$user:/d" /etc/passwd
|
|
sed -i "/^$user:/d" /etc/shadow
|
|
fi
|
|
|
|
/usr/sbin/groupdel $user >> /dev/null 2>&1
|
|
if [ $? -ne 0 ]; then
|
|
sed -i "/^$user:/d" /etc/group
|
|
fi
|
|
|
|
# Deleting user directories
|
|
chattr -i $HOMEDIR/$user/conf
|
|
rm -rf $HOMEDIR/$user
|
|
if [ -f "/hdd/home/$user" ]; then
|
|
rm -rf /hdd/home/$user
|
|
fi
|
|
rm -f /var/spool/mail/$user
|
|
rm -f /var/spool/cron/$user
|
|
rm -f /var/spool/cron/crontabs/$user
|
|
rm -rf $USER_DATA
|
|
|
|
# Updating admin counter
|
|
if [ "$user" != 'admin' ]; then
|
|
decrease_user_value 'admin' '$U_USERS'
|
|
fi
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Vesta #
|
|
#----------------------------------------------------------#
|
|
|
|
# Logging
|
|
log_history "deleted system user $user" '' 'admin'
|
|
log_event "$OK" "$ARGUMENTS"
|
|
|
|
exit
|