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


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

# Argument definition
user=$1
restart=$2

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


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

check_args '1' "$#" 'USER [RESTART]'
is_format_valid 'user'
is_system_enabled "$WEB_SYSTEM" '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                              #
#----------------------------------------------------------#

# Restarting web server
$BIN/v-restart-web $restart
check_result $? "Web restart failed" >/dev/null

$BIN/v-restart-proxy $restart
check_result $? "Proxy restart failed" >/dev/null

# Logging
log_event "$OK" "$ARGUMENTS"

exit