myvesta/bin/v-change-web-domain-tpl
2016-06-24 16:31:43 +03:00

81 lines
2.2 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 definition
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]'
is_format_valid '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 "$template"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Parsing domain values
get_domain_values 'web'
local_ip=$(get_real_ip $IP)
# Deleting domain
del_web_config "$WEB_SYSTEM" "$TPL.tpl"
if [ "$SSL" = 'yes' ]; then
del_web_config "$WEB_SYSTEM" "$TPL.stpl"
fi
# Defining variables for new vhost config
prepare_web_domain_values
add_web_config "$WEB_SYSTEM" "$TPL.tpl"
if [ "$SSL" = 'yes' ]; then
add_web_config "$WEB_SYSTEM" "$TPL.stpl"
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" "$ARGUMENTS"
exit