11#! /bin/bash
22# info: add web domain
3- # options: USER DOMAIN IP [RESTART]
3+ # options: USER DOMAIN IP [RESTART] [ALIASES] [PROXY_EXTENTIONS]
44#
55# The function adds virtual host to a server. In cases when a template is
66# undefined in the script, the template "default" will be used. The alias of
@@ -20,9 +20,12 @@ domain=$(idn -t --quiet -u "$2" )
2020domain=$( echo $domain | sed -e ' s/\.*$//g' -e ' s/^\.*//g' )
2121domain=$( echo $domain | tr ' [:upper:]' ' [:lower:]' )
2222domain_idn=$( idn -t --quiet -a " $domain " )
23- ip=$3
23+ ip=$3 ; IP= $3
2424restart=$4
25- alises=$5
25+ aliases=$5
26+ default_extentions=" jpg,jpeg,gif,png,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls,\
27+ exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav,bmp,rtf,js,mp3,avi,mpeg,flv,html,htm"
28+ extentions=${6-$default_extentions }
2629
2730# Includes
2831source $VESTA /func/main.sh
@@ -35,8 +38,8 @@ source $VESTA/conf/vesta.conf
3538# Verifications #
3639# ----------------------------------------------------------#
3740
38- check_args ' 3' " $# " ' USER DOMAIN IP [RESTART]'
39- validate_format ' user' ' domain' ' ip'
41+ check_args ' 3' " $# " ' USER DOMAIN IP [RESTART] [ALIASES] [PROXY_EXTENTIONS] '
42+ validate_format ' user' ' domain' ' ip' ' extentions '
4043is_system_enabled " $WEB_SYSTEM " ' WEB_SYSTEM'
4144is_object_valid ' user' ' USER' " $user "
4245is_object_unsuspended ' user' ' USER' " $user "
@@ -46,50 +49,56 @@ is_ip_avalable
4649is_package_full ' WEB_DOMAINS'
4750template=$( get_user_value ' $WEB_TEMPLATE' )
4851is_web_template_valid
52+ if [ ! -z " $aliases " ]; then
53+ for domain_alias in $( echo " ${aliases// ,/ } " ) ; do
54+ is_domain_new ' web' " $domain_alias " ' alias'
55+ done
56+ fi
57+ if [ ! -z " $PROXY_SYSTEM " ]; then
58+ proxy=$( get_user_value ' $PROXY_TEMPLATE' )
59+ is_proxy_template_valid $proxy
60+ fi
4961
5062
5163# ----------------------------------------------------------#
5264# Action #
5365# ----------------------------------------------------------#
5466
55- # Define real ip in case of NAT
56- IP=$ip
57- ip=$( get_real_ip $ip )
58-
59- # Defining domain aliases
60- ip_name=$( get_ip_name)
61- ip_name_idn=$( idn -t --quiet -a " $ip_name " )
62- domain_alias=" www.$domain "
63- domain_alias_idn=" www.$domain_idn "
64- if [ ! -z " $ip_name " ]; then
65- domain_alias_dash=" ${domain// ./ -} .$ip_name "
66- domain_alias_dash_idn=" ${domain_idn// ./ -} .$ip_name_idn "
67- aliases=" $domain_alias ,$domain_alias_dash "
68- aliases_idn=" $domain_alias_idn ,$domain_alias_dash_idn "
69- alias_string=" ServerAlias $domain_alias_idn $domain_alias_dash_idn "
70- else
71- aliases=" $domain_alias "
72- aliases_idn=" $domain_alias_idn "
73- alias_string=" ServerAlias $domain_alias_idn "
67+ # Checking domain backend in case PHP-FPM is configured
68+ if [ ! -z " $WEB_BACKEND " ]; then
69+ is_web_backend_pool_valid
70+ $BIN /v-add-web-domain-backend $user $domain
71+ rc=$?
72+ if [ $rc -ne 0 ]; then
73+ exit $rc
74+ fi
75+ get_domain_backend_values
76+ backend=$( get_user_value ' $BACKEND_TEMPLATE' )
7477fi
7578
76- # Defining vars for add_config function
79+ # Defining variables for add_config function
80+ ip=$( get_real_ip $ip )
7781group=" $user "
7882email=" info@$domain "
7983docroot=" $HOMEDIR /$user /web/$domain /public_html"
8084tpl_file=" $WEBTPL /$WEB_SYSTEM /$WEB_BACKEND /$template .tpl"
8185conf=" $HOMEDIR /$user /conf/web/$WEB_SYSTEM .conf"
8286
83- # Checking backend
84- if [ ! -z " $WEB_BACKEND " ]; then
85- is_web_backend_pool_valid
86- $BIN /v-add-web-domain-backend $user $domain
87- rc=$?
88- if [ $rc -ne 0 ]; then
89- exit $rc
87+ # Defining domain aliases
88+ ip_name=$( get_ip_name)
89+ if [ -z " $aliases " ]; then
90+ if [ -z " $ip_name " ]; then
91+ aliases=" www.$domain "
92+ else
93+ aliases=" www.$domain ,${domain// ./ -} .$ip_name "
94+ fi
95+ else
96+ if [ ! -z " $ip_name " ]; then
97+ aliases=" $aliases ,${domain// ./ -} .$ip_name "
9098 fi
91- get_domain_backend_values
9299fi
100+ aliases_idn=$( idn -t --quiet -a $aliases )
101+ alias_string=" ServerAlias ${aliases_idn// ,/ } "
93102
94103# Adding web config
95104add_web_config
@@ -166,6 +175,23 @@ if [ -z "$web_include" ] && [ "$WEB_SYSTEM" = 'nginx' ]; then
166175 echo " include $conf ;" >> $web_conf
167176fi
168177
178+ # Checking proxy system
179+ if [ ! -z " $PROXY_SYSTEM " ]; then
180+ PROXY_EXT=" $extentions "
181+ tpl_file=" $WEBTPL /$PROXY_SYSTEM /$proxy .tpl"
182+ conf=" $HOMEDIR /$user /conf/web/$PROXY_SYSTEM .conf"
183+ add_web_config
184+ chown root:$user $conf
185+ chmod 640 $conf
186+ proxy_conf=" /etc/$PROXY_SYSTEM /conf.d/vesta.conf"
187+ if [ -z " $( grep " $conf " $proxy_conf ) " ]; then
188+ echo " include $conf ;" >> $proxy_conf
189+ fi
190+ if [ -x $WEBTPL /$PROXY_SYSTEM /$template .sh ]; then
191+ $WEBTPL /$PROXY_SYSTEM /$template .sh $user $domain $ip $HOMEDIR $docroot
192+ fi
193+ fi
194+
169195
170196# ----------------------------------------------------------#
171197# Vesta #
@@ -177,10 +203,9 @@ increase_user_value "$user" '$U_WEB_DOMAINS'
177203increase_user_value " $user " ' $U_WEB_ALIASES'
178204
179205# Defining domain variables
180- BACKEND_TPL=$( grep BACKEND_TEMPLATE $USER_DATA /user.conf | cut -f 2 -d \' )
181206str=" DOMAIN='$domain ' IP='$IP ' IP6='' ALIAS='$aliases ' TPL='$template '"
182- str=" $str SSL='no' SSL_HOME='same' FTP_USER='' FTP_MD5=''"
183- str=" $str BACKEND ='$BACKEND_TPL ' PROXY='' PROXY_EXT='' STATS='' STATS_USER=''"
207+ str=" $str SSL='no' SSL_HOME='same' FTP_USER='' FTP_MD5='' BACKEND=' $backend ' "
208+ str=" $str PROXY ='$proxy ' PROXY_EXT='$extentions ' STATS='' STATS_USER=''"
184209str=" $str STATS_CRYPT='' U_DISK='0' U_BANDWIDTH='0' SUSPENDED='no'"
185210str=" $str TIME='$TIME ' DATE='$DATE '"
186211
@@ -193,6 +218,12 @@ if [ "$restart" != 'no' ]; then
193218 if [ $? -ne 0 ]; then
194219 exit $E_RESTART
195220 fi
221+ if [ ! -z " $PROXY_SYSTEM " ]; then
222+ $BIN /v-restart-proxy
223+ if [ $? -ne 0 ]; then
224+ exit $E_RESTART
225+ fi
226+ fi
196227fi
197228
198229# Logging
0 commit comments