Skip to content

Commit 6168985

Browse files
committed
web function refactoring
1 parent 72eddc3 commit 6168985

File tree

1 file changed

+34
-47
lines changed

1 file changed

+34
-47
lines changed

bin/v-change-web-domain-backend-tpl

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,21 @@ source $VESTA/conf/vesta.conf
2929
#----------------------------------------------------------#
3030

3131
check_args '3' "$#" 'USER DOMAIN TEMPLATE [RESTART]'
32-
validate_format 'user' 'domain' 'template'
32+
is_format_valid 'user' 'domain' 'template'
3333
is_system_enabled "$WEB_BACKEND" 'WEB_BACKEND'
3434
is_object_valid 'user' 'USER' "$user"
3535
is_object_unsuspended 'user' 'USER' "$user"
3636
is_object_valid 'web' 'DOMAIN' "$domain"
3737
is_object_unsuspended 'web' 'DOMAIN' "$domain"
3838
is_web_backend_template_valid $template
39-
is_web_backend_pool_valid
4039

4140

4241
#----------------------------------------------------------#
4342
# Action #
4443
#----------------------------------------------------------#
4544

45+
prepare_web_backend
46+
4647
# Deleting backend
4748
rm -f $pool/$backend.conf
4849

@@ -71,34 +72,26 @@ if [ "$backend" = "$user" ]; then
7172
nohead=1
7273

7374
for domain in $(shell_list); do
74-
75-
# Parsing domain values
7675
get_domain_values 'web'
77-
ip=$(get_real_ip $IP)
78-
79-
# Deleting old vhost
80-
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
81-
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
82-
del_web_config
76+
local_ip=$(get_real_ip $IP)
77+
prepare_web_domain_values
8378

84-
# Deleting old ssl vhost
79+
# Rebuilding vhost
80+
del_web_config "$WEB_SYSTEM" "$TPL.tpl"
81+
add_web_config "$WEB_SYSTEM" "$TPL.tpl"
8582
if [ "$SSL" = 'yes' ]; then
86-
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
87-
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
88-
del_web_config
83+
del_web_config "$WEB_SYSTEM" "$TPL.stpl"
84+
add_web_config "$WEB_SYSTEM" "$TPL.stpl"
8985
fi
9086

91-
# Adding new vhost
92-
upd_web_domain_values
93-
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
94-
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
95-
add_web_config
96-
97-
# Adding new ssl vhost
98-
if [ "$SSL" = 'yes' ]; then
99-
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
100-
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
101-
add_web_config
87+
# Rebuilding proxy configuration
88+
if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
89+
del_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
90+
add_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
91+
if [ "$SSL" = 'yes' ]; then
92+
del_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
93+
add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
94+
fi
10295
fi
10396

10497
# Update config
@@ -117,31 +110,25 @@ if [ "$backend" = "$user" ]; then
117110
else
118111
# Parsing domain values
119112
get_domain_values 'web'
120-
ip=$(get_real_ip $IP)
113+
local_ip=$(get_real_ip $IP)
114+
prepare_web_domain_values
121115

122-
# Deleting old vhost
123-
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
124-
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
125-
del_web_config
126-
127-
# Deleting old ssl vhost
116+
# Rebuilding vhost
117+
del_web_config "$WEB_SYSTEM" "$TPL.tpl"
118+
add_web_config "$WEB_SYSTEM" "$TPL.tpl"
128119
if [ "$SSL" = 'yes' ]; then
129-
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
130-
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
131-
del_web_config
120+
del_web_config "$WEB_SYSTEM" "$TPL.stpl"
121+
add_web_config "$WEB_SYSTEM" "$TPL.stpl"
132122
fi
133123

134-
# Adding new vhost
135-
upd_web_domain_values
136-
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.tpl"
137-
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
138-
add_web_config
139-
140-
# Adding new ssl vhost
141-
if [ "$SSL" = 'yes' ]; then
142-
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
143-
tpl_file="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$TPL.stpl"
144-
add_web_config
124+
# Rebuilding proxy configuration
125+
if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
126+
del_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
127+
add_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
128+
if [ "$SSL" = 'yes' ]; then
129+
del_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
130+
add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
131+
fi
145132
fi
146133

147134
# Update config
@@ -166,6 +153,6 @@ fi
166153

167154
# Logging
168155
log_history "changed backend template for $domain to $template"
169-
log_event "$OK" "$EVENT"
156+
log_event "$OK" "$ARGUMENTS"
170157

171158
exit

0 commit comments

Comments
 (0)