Skip to content

Commit ef33765

Browse files
committed
improved template logic
1 parent 3cec339 commit ef33765

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+710
-282
lines changed

bin/v_add_dns_domain

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ domain=$(idn -t --quiet -u "$2" )
1919
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
2020
domain_idn=$(idn -t --quiet -a "$domain")
2121
ip=$3
22-
template=${4-default}
22+
template=$4
2323
next_year=$(date +%F -d "+ 1 year")
2424
exp=${5-$next_year}
2525
soa=$6
@@ -36,13 +36,19 @@ source $VESTA/func/domain.sh
3636
#----------------------------------------------------------#
3737

3838
check_args '3' "$#" 'user domain ip [template] [exp] [soa] [ttl]'
39-
validate_format 'user' 'domain' 'ip' 'template' 'exp' 'ttl'
39+
validate_format 'user' 'domain' 'ip' 'exp' 'ttl'
4040
is_system_enabled "$DNS_SYSTEM"
4141
is_object_valid 'user' 'USER' "$user"
4242
is_object_unsuspended 'user' 'USER' "$user"
4343
is_domain_new 'dns'
4444
is_package_full 'DNS_DOMAINS'
45-
is_dns_template_valid
45+
if [ ! -z "$template" ]; then
46+
validate_format 'template'
47+
is_dns_template_valid
48+
else
49+
template=$(get_user_value '$TEMPLATE')
50+
is_dns_template_valid
51+
fi
4652

4753

4854
#----------------------------------------------------------#

bin/v_add_web_domain

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ domain=$(idn -t --quiet -u "$2" )
2020
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
2121
domain_idn=$(idn -t --quiet -a "$domain")
2222
ip=$3
23-
template=${4-default}
23+
template=$4
2424
restart=$5
2525

2626
# Includes
@@ -35,15 +35,21 @@ source $VESTA/func/ip.sh
3535
#----------------------------------------------------------#
3636

3737
check_args '3' "$#" 'user domain ip [template] [restart]'
38-
validate_format 'user' 'domain' 'ip' 'template'
38+
validate_format 'user' 'domain' 'ip'
3939
is_system_enabled "$WEB_SYSTEM"
4040
is_object_valid 'user' 'USER' "$user"
4141
is_object_unsuspended 'user' 'USER' "$user"
4242
is_domain_new 'web'
4343
is_ip_valid
4444
is_ip_avalable
4545
is_package_full 'WEB_DOMAINS'
46-
is_apache_template_valid
46+
if [ ! -z "$template" ]; then
47+
validate_format 'template'
48+
is_apache_template_valid
49+
else
50+
template=$(get_user_value '$TEMPLATE')
51+
is_apache_template_valid
52+
fi
4753

4854

4955
#----------------------------------------------------------#
@@ -74,28 +80,9 @@ email="$user@$domain"
7480
docroot="$HOMEDIR/$user/web/$domain/public_html"
7581
conf="$HOMEDIR/$user/conf/web/httpd.conf"
7682
tpl_file="$WEBTPL/apache_$template.tpl"
77-
78-
# Parsing template keys
79-
template_data=$(cat $WEBTPL/apache_$template.descr|grep -v '#')
80-
for keys in $template_data; do
81-
eval ${keys%%=*}=${keys#*=}
82-
done
83-
84-
# Checking error log status
85-
if [ "$ELOG" = 'no' ]; then
86-
elog='#'
87-
else
88-
elog=''
89-
fi
90-
91-
# Checking cgi
92-
if [ "$CGI" != 'yes' ]; then
93-
cgi='#'
94-
cgi_option='-ExecCGI'
95-
else
96-
cgi=''
97-
cgi_option='+ExecCGI'
98-
fi
83+
elog=''
84+
cgi=''
85+
cgi_option='+ExecCGI'
9986

10087
# Adding domain to the httpd.conf
10188
add_web_config
@@ -181,9 +168,9 @@ increase_user_value "$user" '$U_WEB_ALIASES'
181168

182169
# Defining domain variables
183170
str="DOMAIN='$domain' IP='$ip' IP6='' ALIAS='$aliases' TPL='$template'"
184-
str="$str $template_data SSL='no' SSL_HOME='single' NGINX='' NGINX_EXT=''"
185-
str="$str STATS='' STATS_USER='' STATS_CRYPT='' U_DISK='0' U_BANDWIDTH='0'"
186-
str="$str SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
171+
str="$str CGI='yes' ELOG='yes' SSL='no' SSL_HOME='single' NGINX=''"
172+
str="$str NGINX_EXT='' STATS='' STATS_USER='' STATS_CRYPT='' U_DISK='0'"
173+
str="$str U_BANDWIDTH='0' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
187174

188175
# Registering domain
189176
echo "$str" >> $USER_DATA/web.conf

bin/v_add_web_domain_alias

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ fi
7373

7474
# Checking nginx
7575
if [ ! -z "$NGINX" ]; then
76-
tpl_file="$WEBTPL/ngingx_$NGINX.tpl"
76+
tpl_file="$WEBTPL/nginx_$NGINX.tpl"
7777
conf="$HOMEDIR/$user/conf/web/nginx.conf"
7878
del_web_config
7979
add_web_config
8080

8181
if [ "$SSL" = 'yes' ]; then
82-
tpl_file="$WEBTPL/ngingx_$NGINX.stpl"
82+
tpl_file="$WEBTPL/nginx_$NGINX.stpl"
8383
conf="$HOMEDIR/$user/conf/web/snginx.conf"
8484
del_web_config
8585
add_web_config

bin/v_add_web_domain_elog

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ fi
6666

6767
# Checking nginx
6868
if [ ! -z "$NGINX" ]; then
69-
tpl_file="$WEBTPL/ngingx_$NGINX.tpl"
69+
tpl_file="$WEBTPL/nginx_$NGINX.tpl"
7070
conf="$HOMEDIR/$user/conf/web/nginx.conf"
7171
del_web_config
7272
add_web_config
7373

7474
if [ "$SSL" = 'yes' ]; then
75-
tpl_file="$WEBTPL/ngingx_$NGINX.stpl"
75+
tpl_file="$WEBTPL/nginx_$NGINX.stpl"
7676
conf="$HOMEDIR/$user/conf/web/snginx.conf"
7777
del_web_config
7878
add_web_config

bin/v_add_web_domain_nginx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
user=$1
1515
domain=$(idn -t --quiet -u "$2" )
1616
domain_idn=$(idn -t --quiet -a "$domain")
17-
template=${3-default}
17+
template=$3
1818
default_extentions="jpg,jpeg,gif,png,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls,\
1919
exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav,bmp,rtf,js,mp3,avi,mpeg,flv,html,htm"
2020
extentions=${4-$default_extentions}
@@ -31,14 +31,20 @@ source $VESTA/func/domain.sh
3131
#----------------------------------------------------------#
3232

3333
check_args '2' "$#" 'user domain [template] [extentions] [restart]'
34-
validate_format 'user' 'domain' 'template' 'extentions'
34+
validate_format 'user' 'domain' 'extentions'
3535
is_system_enabled "$PROXY_SYSTEM"
3636
is_object_valid 'user' 'USER' "$user"
3737
is_object_unsuspended 'user' 'USER' "$user"
3838
is_object_valid 'web' 'DOMAIN' "$domain"
3939
is_object_unsuspended 'web' 'DOMAIN' "$domain"
4040
is_object_value_empty 'web' 'DOMAIN' "$domain" '$NGINX'
41-
is_nginx_template_valid
41+
if [ ! -z "$template" ]; then
42+
validate_format 'template'
43+
is_nginx_template_valid
44+
else
45+
template=$(get_user_value '$TEMPLATE')
46+
is_nginx_template_valid
47+
fi
4248

4349

4450
#----------------------------------------------------------#
@@ -49,7 +55,7 @@ is_nginx_template_valid
4955
get_domain_values 'web'
5056
NGINX="$template"
5157
NGINX_EXT="$extentions"
52-
tpl_file="$WEBTPL/ngingx_$NGINX.tpl"
58+
tpl_file="$WEBTPL/nginx_$NGINX.tpl"
5359
conf="$HOMEDIR/$user/conf/web/nginx.conf"
5460

5561
# Preparing domain values for the template substitution
@@ -69,7 +75,7 @@ fi
6975

7076
# Checking ssl
7177
if [ "$SSL" = 'yes' ]; then
72-
tpl_file="$WEBTPL/ngingx_$NGINX.stpl"
78+
tpl_file="$WEBTPL/nginx_$NGINX.stpl"
7379
conf="$HOMEDIR/$user/conf/web/snginx.conf"
7480
add_web_config
7581

bin/v_add_web_domain_ssl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fi
9898
if [ ! -z "$NGINX" ]; then
9999
# Adding domain to the snginx.conf
100100
conf="$HOMEDIR/$user/conf/web/snginx.conf"
101-
tpl_file="$WEBTPL/ngingx_$NGINX.stpl"
101+
tpl_file="$WEBTPL/nginx_$NGINX.stpl"
102102
add_web_config
103103

104104
chown root:nginx $conf

bin/v_backup_user

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ then
163163

164164
# Nginx config
165165
if [ ! -z "$NGINX" ] ; then
166-
tpl_file="$WEBTPL/ngingx_$NGINX.tpl"
166+
tpl_file="$WEBTPL/nginx_$NGINX.tpl"
167167
conf="$HOMEDIR/$user/conf/web/nginx.conf"
168168
get_web_config_brds
169169
sed -n "$top_line,$bottom_line p" $conf > conf/nginx.conf
170170

171171
# SSL check
172172
if [ "$SSL" = 'yes' ] ; then
173-
tpl_file="$WEBTPL/ngingx_$NGINX.stpl"
173+
tpl_file="$WEBTPL/nginx_$NGINX.stpl"
174174
conf="$HOMEDIR/$user/conf/web/snginx.conf"
175175
get_web_config_brds
176176
sed -n "$top_line,$bottom_line p" $conf > conf/snginx.conf

bin/v_change_user_package

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ change_user_package() {
5959
echo "FNAME='$FNAME'
6060
LNAME='$LNAME'
6161
PACKAGE='$package'
62+
TEMPLATE='$TEMPLATE'
6263
WEB_DOMAINS='$WEB_DOMAINS'
6364
WEB_ALIASES='$WEB_ALIASES'
64-
WEB_TPL='$WEB_TPL'
6565
DNS_DOMAINS='$DNS_DOMAINS'
6666
DNS_RECORDS='$DNS_RECORDS'
6767
MAIL_DOMAINS='$MAIL_DOMAINS'

bin/v_change_user_template

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
# info: change user default template
3+
# options: user template
4+
#
5+
# The function changes default user web template.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
template=$2
15+
16+
# Includes
17+
source $VESTA/conf/vesta.conf
18+
source $VESTA/func/main.sh
19+
source $VESTA/func/domain.sh
20+
21+
22+
#----------------------------------------------------------#
23+
# Verifications #
24+
#----------------------------------------------------------#
25+
26+
check_args '2' "$#" 'user template'
27+
validate_format 'user' 'template'
28+
is_object_valid 'user' 'USER' "$user"
29+
is_object_unsuspended 'user' 'USER' "$user"
30+
is_apache_template_valid
31+
32+
33+
#----------------------------------------------------------#
34+
# Action #
35+
#----------------------------------------------------------#
36+
37+
38+
#----------------------------------------------------------#
39+
# Vesta #
40+
#----------------------------------------------------------#
41+
42+
# Changing user shell
43+
update_user_value "$user" '$TEMPLATE' "$template"
44+
45+
# Logging
46+
log_event "$OK" "$EVENT"
47+
48+
exit

bin/v_change_web_domain_ip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ fi
6060

6161
# Checking nginx
6262
if [ ! -z "$NGINX" ]; then
63-
tpl_file="$WEBTPL/ngingx_$NGINX.tpl"
63+
tpl_file="$WEBTPL/nginx_$NGINX.tpl"
6464
conf="$HOMEDIR/$user/conf/web/nginx.conf"
6565
replace_web_config
6666
fi
6767

6868
# Checking nginx
6969
if [ "$SSL" = 'yes' ] && [ ! -z "$NGINX" ]; then
70-
tpl_file="$WEBTPL/ngingx_$NGINX.stpl"
70+
tpl_file="$WEBTPL/nginx_$NGINX.stpl"
7171
conf="$HOMEDIR/$user/conf/web/snginx.conf"
7272
replace_web_config
7373
fi

0 commit comments

Comments
 (0)