myvesta/bin/v-change-web-domain-tpl
2015-10-28 16:34:41 +02:00

107 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
# info: change web domain template
# options: USER DOMAIN TEMPLATE [RESTART]
#
# The function changes template of the web configuration file. The content
# of webdomain directories remains untouched.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
template=$3
restart=$4
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/func/ip.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN TEMPLATE [RESTART]'
validate_format 'user' 'domain' 'template'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
is_web_template_valid
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Parsing domain values
get_domain_values 'web'
ip=$(get_real_ip $IP)
# Deleting domain
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
old_tpl=$TPL
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
del_web_config
# Deleting ssl vhost
if [ "$SSL" = 'yes' ]; then
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
del_web_config
fi
# Defining variables for new vhost config
upd_web_domain_values
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.tpl"
# Adding domain to the web conf
add_web_config
# Running template trigger
if [ -x $WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.sh ]; then
$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.sh \
$user $domain $ip $HOMEDIR $docroot
fi
# Checking SSL
if [ "$SSL" = 'yes' ]; then
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.stpl"
add_web_config
# Running template trigger
if [ -x $WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.sh ]; then
$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.sh \
"$user" "$domain" "$ip" "$HOMEDIR" "$sdocroot"
fi
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Changing tpl in config
update_object_value 'web' 'DOMAIN' "$domain" '$TPL' "$template"
# Restarting web
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
check_result $? "Web restart failed" >/dev/null
fi
# Logging
log_history "changed web domain template for $domain to $template" '' 'admin'
log_event "$OK" "$EVENT"
exit