You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hestiacp/bin/v-rebuild-web-domain

122 lines
3.8 KiB

#!/bin/bash
# info: rebuild web domain
# options: USER DOMAIN [RESTART]
#
# example: v-rebuild-web-domain user domain.tld
#
# This function rebuilds web configuration files.
#----------------------------------------------------------#
# Variables & Functions #
#----------------------------------------------------------#
# Argument definition
user=$1
domain=$2
restart=$3
# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# shellcheck source=/usr/local/hestia/func/domain.sh
source $HESTIA/func/domain.sh
# shellcheck source=/usr/local/hestia/func/ip.sh
source $HESTIA/func/ip.sh
# shellcheck source=/usr/local/hestia/func/rebuild.sh
source $HESTIA/func/rebuild.sh
# shellcheck source=/usr/local/hestia/func/syshealth.sh
source $HESTIA/func/syshealth.sh
# load config file
source_conf "$HESTIA/conf/hestia.conf"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN [RESTART]'
is_format_valid 'user' 'domain' 'restart'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
check_user=$(is_object_unsuspended 'user' 'USER' "$user")
if [ -n "$check_user" ]; then
exit
fi
is_object_valid 'web' 'DOMAIN' "$domain"
# Perform verification if read-only mode is enabled
check_hestia_demo_mode
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
confd=$(get_conf_d_name "$WEB_SYSTEM")
# Deleting old web configs
if [ -e "/etc/$WEB_SYSTEM/$confd/hestia.conf" ]; then
sed -i "/.*\/$user\/conf\/web\//d" /etc/$WEB_SYSTEM/$confd/hestia.conf
fi
if [ -e "$HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.conf" ]; then
rm -f $HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.conf
rm -f /etc/$WEB_SYSTEM/$confd/domains/$domain.conf
fi
if [ -e "$HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.ssl.conf" ]; then
rm $HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.ssl.conf
rm -f /etc/$WEB_SYSTEM/$confd/domains/$domain.ssl.conf
fi
pconfd=$(get_conf_d_name "$PROXY_SYSTEM")
# Deleting old proxy configs
if [ -n "$PROXY_SYSTEM" ]; then
if [ -e "/etc/$PROXY_SYSTEM/$pconfd/hestia.conf" ]; then
sed -i "/.*\/$user\/conf\/web\//d" /etc/$PROXY_SYSTEM/$pconfd/hestia.conf
fi
if [ -e "$HOMEDIR/$user/conf/web/$domain/$PROXY_SYSTEM.conf" ]; then
rm -f $HOMEDIR/$user/conf/web/$domain/$PROXY_SYSTEM.conf
rm -f /etc/$PROXY_SYSTEM/$pconfd/domains/$domain.conf
fi
if [ -e "$HOMEDIR/$user/conf/web/$domain/$PROXY_SYSTEM.ssl.conf" ]; then
rm -f $HOMEDIR/$user/conf/web/$domain/$PROXY_SYSTEM.ssl.conf
rm -f /etc/$PROXY_SYSTEM/$pconfd/domains/$domain.ssl.conf
fi
fi
# Deleting backend configs
if [ -n "$WEB_BACKEND" ]; then
template=$(get_object_value 'web' 'DOMAIN' "$domain" '$BACKEND')
if [ -z "$template" ]; then
template="default"
update_object_value 'web' 'DOMAIN' "$domain" '$BACKEND' 'default'
fi
prepare_web_backend
delete_web_backend
$BIN/v-add-web-domain-backend $user $domain $template $restart
fi
rebuild_web_domain_conf
#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#
# Updating user counters
$BIN/v-update-user-counters "$user"
# 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
$BIN/v-log-action "system" "Info" "System" "Rebuilt web domain (User: $user, Domain: $domain)."
log_event "$OK" "$ARGUMENTS"
exit