#!/bin/bash
# info: unsuspend web domains
# options: USER [RESTART]
#
# The function of unsuspending all user's sites.


#----------------------------------------------------------#
#                    Variable&Function                     #
#----------------------------------------------------------#

# Argument defenition
user=$1
restart=$2

# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
source $VESTA/func/domain.sh


#----------------------------------------------------------#
#                    Verifications                         #
#----------------------------------------------------------#

check_args '1' "$#" 'USER [RESTART]'
validate_format 'user'
is_system_enabled "$WEB_SYSTEM"
is_object_valid 'user' 'USER' "$user"


#----------------------------------------------------------#
#                       Action                             #
#----------------------------------------------------------#

# Starting unsuspend loop
for domain in $(search_objects 'web' 'SUSPENDED' "yes" 'DOMAIN'); do
    $BIN/v-unsuspend-web-domain "$user" "$domain" 'no'
done


#----------------------------------------------------------#
#                       Vesta                              #
#----------------------------------------------------------#

# Restart web server
if [ "$restart" != 'no' ]; then
    $BIN/v-restart-web "$EVENT"
fi

# Logging
log_event "$OK" "$EVENT"

exit
