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


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

# Argument defenition
user=$1

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


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

check_args '1' "$#" 'user'
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
$BIN/v_restart_web "$EVENT"

# Logging
log_event "$OK" "$EVENT"

exit
