vesta/bin/v_change_web_domain_tpl
2011-07-05 21:47:10 +03:00

152 lines
3.8 KiB
Bash
Executable File

#!/bin/bash
# info: changing domain template
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user="$1"
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
template="$3"
# Importing variables
source $VESTA/conf/vars.conf
source $V_FUNC/shared_func.sh
source $V_FUNC/domain_func.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '3' "$#" 'user domain template'
# Checking argument format
format_validation 'user' 'domain' 'template'
# Checking web system is enabled
is_system_enabled 'web'
# Checking user
is_user_valid
# Checking user is active
is_user_suspended
# Checking domain exist
is_web_domain_valid
# Checking domain is not suspened
is_domain_suspended 'web_domains'
# Checking template
templates=$(get_user_value '$WEB_TPL')
is_template_valid "web"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Get template name
tpl_name=$(get_web_domain_value '$TPL')
tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
conf="$V_HOME/$user/conf/httpd.conf"
# Deleting domain
del_web_config
# Checking ssl
cert=$(get_web_domain_value '$SSL_CERT')
if [ ! -z "$cert" ]; then
# Get tpl
tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
conf="$V_HOME/$user/conf/shttpd.conf"
# Deleting domain
del_web_config
fi
# Defining variables for template replace
ip=$(get_web_domain_value '$IP')
aliases=$(get_web_domain_value '$ALIAS')
aliases_idn=$(idn -t --quiet -a "$aliases")
web_port=$(get_config_value '$WEB_PORT')
email="$user@$domain"
docroot="$V_HOME/$user/domains/$domain/public_html"
conf="$V_HOME/$user/conf/httpd.conf"
tpl_file="$V_WEBTPL/apache_$template.tpl"
group="$user"
# Parsing template keys
template_data=$(cat $V_WEBTPL/apache_$template.descr|grep -v '#')
for keys in $template_data; do
eval ${keys%%=*}=${keys#*=}
done
# Checking error log status
if [ "$ELOG" = 'no' ]; then
elog=' #'
else
elog=' '
fi
# Adding domain to the httpd.conf
add_web_config
# Running template trigger
if [ -x $V_WEBTPL/apache_$template.sh ]; then
$V_WEBTPL/apache_$template.sh $user $domain $ip $V_HOME $docroot
fi
# Checking ssl
if [ ! -z "$cert" = 'yes' ]; then
# Defining variables for ssl template replace
web_ssl_port=$(get_config_value '$WEB_SSL_PORT')
tpl_option=$(get_web_domain_value '$SSL_HOME')
ssl_cert="$V_HOME/$user/conf/$cert.crt"
ssl_key="$V_HOME/$user/conf/$cert.key"
case $tpl_option in
single) docroot="$V_HOME/$user/domains/$domain/public_shtml" ;;
*) docroot="$V_HOME/$user/domains/$domain/public_html" ;;
esac
conf="$V_HOME/$user/conf/shttpd.conf"
tpl_file="$V_WEBTPL/apache_$template.stpl"
# Adding domain to the httpd.conf
add_web_config
# Running template trigger
if [ -x $V_WEBTPL/apache_$template.sh ]; then
$V_WEBTPL/apache_$template.sh \
"$user" "$domain" "$ip" "$V_HOME" "$docroot"
fi
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Changing tpl in config
update_web_domain_value '$TPL' "$template"
# Updating db keys
for keys in $(cat $V_WEBTPL/apache_$template.descr|grep -v '#'); do
key=$(echo "$keys"| cut -f 1 -d '=' |sed -e "s/^/\$/g")
value=$(echo "$keys" |cut -f 2 -d \')
update_web_domain_value "$key" "$value"
done
# Adding task to the vesta pipe
restart_schedule 'web'
# Logging
log_event 'system' "$V_EVENT"
exit $OK