Skip to content

Commit 91794b5

Browse files
committed
added nginx support
1 parent 7138585 commit 91794b5

File tree

3 files changed

+74
-8
lines changed

3 files changed

+74
-8
lines changed

bin/v_rebuild_web_domains

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@
88
# Argument defenition
99
user="$1"
1010

11+
1112
# Importing variables
1213
source $VESTA/conf/vars.conf
1314
source $V_FUNC/shared_func.sh
1415
source $V_FUNC/domain_func.sh
1516
source $V_FUNC/ip_func.sh
1617

18+
url="${2-$V_SUSPEND_URL}"
1719

1820
#----------------------------------------------------------#
1921
# Verifications #
2022
#----------------------------------------------------------#
2123

2224
# Checking arg number
23-
check_args '1' "$#" 'user'
25+
check_args '1' "$#" 'user [suspend_url]'
2426

2527
# Checking argument format
26-
format_validation 'user'
28+
format_validation 'user' 'url'
2729

2830
# Checking web system is enabled
2931
is_system_enabled 'web'
@@ -48,7 +50,7 @@ search_string="DOMAIN"
4850
# Defining fileds to select
4951
field='$DOMAIN'
5052

51-
# Parsing unsuspeneded domains
53+
# Parsing all domains
5254
domains=$(dom_clear_search)
5355

5456
# Starting loop
@@ -59,13 +61,13 @@ for domain in $domains; do
5961
tpl_file="$V_WEBTPL/apache_$template.tpl"
6062
ip=$(get_web_domain_value '$IP')
6163
web_port=$(get_config_value '$WEB_PORT')
62-
domain=$(get_web_domain_value '$DOMAIN')
6364
domain_idn=$(idn -t --quiet -a "$domain")
6465
group="$user"
6566
docroot="$V_HOME/$user/web/$domain/public_html"
6667
email="$user@$domain"
6768
aliases=$(get_web_domain_value '$ALIAS')
6869
aliases_idn=$(idn -t --quiet -a "$aliases")
70+
suspend=$(get_web_domain_value '$SUSPEND')
6971

7072
# Checking error log status
7173
elog=$(get_web_domain_value '$ELOG')
@@ -99,6 +101,18 @@ for domain in $domains; do
99101
change_web_config
100102
fi
101103

104+
# Checking suspend
105+
if [ "$suspend" = 'yes' ]; then
106+
# Defining search phrase
107+
search_phrase='DocumentRoot '
108+
109+
# Defining replace string
110+
str_repl=" Redirect / http://$url"
111+
112+
# Suspending vhost
113+
change_web_config
114+
fi
115+
102116
# Checking ssl
103117
cert=$(get_web_domain_value '$SSL_CERT')
104118
if [ ! -z "$cert" ]; then
@@ -136,23 +150,50 @@ for domain in $domains; do
136150
str_repl=' Options +Includes -Indexes -ExecCGI'
137151
change_web_config
138152
fi
153+
154+
# Checking suspend
155+
if [ "$suspend" = 'yes' ]; then
156+
# Defining search phrase
157+
search_phrase='DocumentRoot '
158+
159+
# Defining replace string
160+
str_repl=" Redirect / http://$url"
161+
162+
# Suspending vhost
163+
change_web_config
164+
fi
139165
fi
140166

141167
# Checking nginx
142168
nginx=$(get_web_domain_value '$NGINX')
143169
if [ ! -z "$nginx" ]; then
144170
proxy_port=$(get_config_value '$PROXY_PORT')
145-
ext=$(get_web_domain_value '$NGINX_EXT')
171+
extentions=$(get_web_domain_value '$NGINX_EXT')
146172
tpl_file="$V_WEBTPL/ngingx_vhost_$nginx.tpl"
147173
conf="$V_HOME/$user/conf/tmp_nginx.conf"
148174
add_web_config
149175

176+
if [ "$suspend" = 'yes' ]; then
177+
search_phrase='proxy_pass'
178+
str_repl=" rewrite ^(.*)\$ http://$url;"
179+
change_web_config
180+
fi
181+
150182
if [ ! -z "$cert" ]; then
151-
proxy_ssl_port=$(get_config_value '$PROXY_SSL_PORT')
152183
tpl_file="$V_WEBTPL/ngingx_vhost_$nginx.stpl"
153184
conf="$V_HOME/$user/conf/tmp_snginx.conf"
154185
add_web_config
186+
187+
if [ "$suspend" = 'yes' ]; then
188+
search_phrase='proxy_pass'
189+
str_repl=" rewrite ^(.*)\$ http://$url;"
190+
change_web_config
191+
fi
192+
155193
fi
194+
195+
196+
ngix_change='yes'
156197
fi
157198

158199
done
@@ -185,12 +226,13 @@ if [ ! -z "$ssl_cert" ]; then
185226
fi
186227

187228
# Checking nginx
188-
if [ ! -z "$nginx" ]; then
229+
if [ "$ngix_change" = 'yes' ]; then
189230
nginx_conf='/etc/nginx/conf.d/vesta_users.conf'
190231
tmp_conf="$V_HOME/$user/conf/tmp_nginx.conf"
191232
conf="$V_HOME/$user/conf/nginx.conf"
192233
mv $tmp_conf $conf
193234

235+
194236
nginx_conf_check=$(grep "$conf" $nginx_conf )
195237
if [ -z "$nginx_conf_check" ]; then
196238
echo "include $conf;" >>$nginx_conf

bin/v_unsuspend_web_domains

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ domains=$(dom_clear_search)
5050
# Starting unsuspend loop
5151
for domain in $domains; do
5252

53+
domain_idn=$(idn -t --quiet -a "$domain")
54+
5355
# Get template name
5456
tpl_name=$(get_web_domain_value '$TPL')
5557
tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
@@ -89,6 +91,26 @@ for domain in $domains; do
8991
change_web_config
9092
fi
9193

94+
# Check nginx vhost
95+
nginx=$(get_web_domain_value '$NGINX')
96+
if [ ! -z "$nginx" ]; then
97+
ip=$(get_web_domain_value '$IP')
98+
web_port=$(get_config_value '$WEB_PORT')
99+
tpl_file="$V_WEBTPL/ngingx_vhost_$nginx.tpl"
100+
conf="$V_HOME/$user/conf/nginx.conf"
101+
search_phrase='rewrite ^(.*)$'
102+
str_repl=" proxy_pass http://$ip:$web_port;"
103+
change_web_config
104+
fi
105+
106+
if [ ! -z "$nginx" ] && [ ! -z "$cert" ]; then
107+
web_ssl_port=$(get_config_value '$WEB_SSL_PORT')
108+
tpl_file="$V_WEBTPL/ngingx_vhost_$nginx.stpl"
109+
conf="$V_HOME/$user/conf/snginx.conf"
110+
str_repl=" proxy_pass https://$ip:$web_ssl_port;"
111+
change_web_config
112+
fi
113+
92114
# Adding unsuspend in config
93115
update_web_domain_value '$SUSPEND' 'no'
94116
done

func/domain_func.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ change_web_config() {
281281
-e 's/\//\\\//g')
282282

283283
# Changing config
284-
sed -i "$str_numb s/.*/$str_repl/" $conf
284+
if [ ! -z "$str" ]; then
285+
sed -i "$str_numb s/.*/$str_repl/" $conf
286+
fi
285287
}
286288

287289
get_web_domain_value() {

0 commit comments

Comments
 (0)