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.
115 lines
3.3 KiB
115 lines
3.3 KiB
4 months ago
|
#!/bin/bash
|
||
|
# info: update configs for web domain
|
||
|
# options: USER DOMAIN TEMPLATE [RESTART]
|
||
|
#
|
||
|
# example: v-unpdate-web-domain admin acme.com test_template
|
||
|
#
|
||
|
# This function of updating of the domain's configs.
|
||
|
|
||
|
#----------------------------------------------------------#
|
||
|
# Variables & Functions #
|
||
|
#----------------------------------------------------------#
|
||
|
|
||
|
# Argument definition
|
||
|
user=$1
|
||
|
domain=$2
|
||
|
domain_idn=$2
|
||
|
template=$3
|
||
|
restart=$4
|
||
|
|
||
|
# 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
|
||
|
# load config file
|
||
|
source_conf "$HESTIA/conf/hestia.conf"
|
||
|
|
||
|
# Additional argument formatting
|
||
|
format_domain
|
||
|
format_domain_idn
|
||
|
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
|
||
|
|
||
|
#----------------------------------------------------------#
|
||
|
# Verifications #
|
||
|
#----------------------------------------------------------#
|
||
|
|
||
|
check_args '2' "$#" 'USER DOMAIN [RESTART]'
|
||
|
is_format_valid 'user' 'domain'
|
||
|
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
|
||
|
is_object_valid 'user' 'USER' "$user"
|
||
|
is_object_valid 'web' 'DOMAIN' "$domain"
|
||
|
|
||
|
# Perform verification if read-only mode is enabled
|
||
|
check_hestia_demo_mode
|
||
|
|
||
|
#----------------------------------------------------------#
|
||
|
# Action #
|
||
|
#----------------------------------------------------------#
|
||
|
##TODO
|
||
|
# Parsing domain values
|
||
|
get_domain_values 'web'
|
||
|
local_ip=$(get_real_ip $IP)
|
||
|
|
||
|
# Preparing domain values for the template substitution
|
||
|
prepare_web_domain_values
|
||
|
|
||
|
if [ "$template" != "notemplate" ]; then
|
||
|
update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$template"
|
||
|
fi
|
||
|
|
||
|
echo "TPL=$TPL"
|
||
|
echo "PROXY=$PROXY.tpl"
|
||
|
echo "USER_DATA=$USER_DATA"
|
||
|
exit 0
|
||
|
|
||
|
# Rebuilding vhost
|
||
|
del_web_config "$WEB_SYSTEM" "$TPL.tpl"
|
||
|
add_web_config "$WEB_SYSTEM" "$TPL.tpl"
|
||
|
if [ "$SSL" = 'yes' ]; then
|
||
|
del_web_config "$WEB_SYSTEM" "$TPL.stpl"
|
||
|
add_web_config "$WEB_SYSTEM" "$TPL.stpl"
|
||
|
fi
|
||
|
|
||
|
# Rebuilding proxy configuration
|
||
|
if [ -n "$PROXY_SYSTEM" ] && [ -n "$PROXY" ]; then
|
||
|
del_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
|
||
|
add_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
|
||
|
if [ "$SSL" = 'yes' ]; then
|
||
|
del_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
|
||
|
add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
# Rebuilding backend configuration
|
||
|
if [ -n "$WEB_BACKEND" ]; then
|
||
|
prepare_web_backend "$BACKEND"
|
||
|
delete_web_backend
|
||
|
template=$(get_object_value 'web' 'DOMAIN' "$domain" '$BACKEND')
|
||
|
$BIN/v-add-web-domain-backend $user $domain $template $restart
|
||
|
fi
|
||
|
|
||
|
#----------------------------------------------------------#
|
||
|
# Hestia #
|
||
|
#----------------------------------------------------------#
|
||
|
|
||
|
# Update global configuration files
|
||
|
$BIN/v-rebuild-web-domain "$user" "$domain" 'no'
|
||
|
|
||
|
# 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" "Web" "Updated web domain (User: $user, Domain: $domain)."
|
||
|
log_event "$OK" "$ARGUMENTS"
|
||
|
|
||
|
exit
|