| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #!/bin/bash
- # info: suspend user
- # options: USER [RESTART]
- # labels: panel
- #
- # example: v-suspend-user alice yes
- #
- # The function suspends a certain user and all his objects.
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Argument definition
- user=$1
- restart=$2
- # Includes
- # shellcheck source=/usr/local/hestia/func/main.sh
- source $HESTIA/func/main.sh
- # shellcheck source=/usr/local/hestia/conf/hestia.conf
- source $HESTIA/conf/hestia.conf
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- check_args '1' "$#" 'USER [RESTART]'
- is_format_valid 'user'
- is_object_valid 'user' 'USER' "$user"
- is_object_unsuspended 'user' 'USER' "$user"
- if [ "$user" = 'admin' ]; then
- exit
- fi
- # Perform verification if read-only mode is enabled
- check_hestia_demo_mode
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Do not restrict access to SFTP/FTP/SSH if POLICY_USER_VIEW_SUSPENDED is set to yes
- if [ -z "$POLICY_USER_VIEW_SUSPENDED" ] || [ "$POLICY_USER_VIEW_SUSPENDED" = 'no' ]; then
- # 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
- fi
- # Suspending web domains
- if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
- $BIN/v-suspend-web-domains $user $restart
- fi
- # Suspending mail domains
- if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then
- $BIN/v-suspend-mail-domains $user
- fi
- # Suspending dns domains
- if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS_SYSTEM" != 'no' ]; then
- $BIN/v-suspend-dns-domains $user $restart
- 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
- #----------------------------------------------------------#
- # Hestia #
- #----------------------------------------------------------#
- # Restarting system services
- $BIN/v-restart-web $restart
- check_result $? "Web restart failed" >/dev/null
- $BIN/v-restart-proxy $restart
- check_result $? "Proxy restart failed" >/dev/null
- $BIN/v-restart-dns $restart
- check_result $? "DNS restart failed" >/dev/null
- $BIN/v-restart-cron $restart
- check_result $? "Cron restart failed" >/dev/null
- # Changing suspend value
- update_user_value "$user" '$SUSPENDED' 'yes'
- increase_user_value 'admin' '$SUSPENDED_USERS'
- # Logging
- $BIN/v-log-action "system" "Info" "Users" "Suspended user account (Name: $user)."
- log_event "$OK" "$ARGUMENTS"
- exit
|