forked from outroll/vesta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv-rebuild-web-domains
executable file
·180 lines (151 loc) · 5.23 KB
/
v-rebuild-web-domains
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
# info: rebuild dns domains
# options: USER [RESTART]
#
# The function rebuilds web configuration files.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
restart=$2
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/func/ip.sh
source $VESTA/func/rebuild.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'USER [RESTART]'
validate_format 'user'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
user_domains=0
user_ssl=0
user_aliases=0
suspended_web=0
conf=$USER_DATA/web.conf
fields='$DOMAIN'
nohead=1
domain_counter=0
# Adding log directory
mkdir -p /var/log/$WEB_SYSTEM/domains
chmod 771 /var/log/$WEB_SYSTEM/domains
# Clean up old config
rm -f $HOMEDIR/$user/conf/tmp_*.conf
# Starting loop
for domain in $(shell_list); do
template=$(get_object_value 'web' 'DOMAIN' "$domain" '$BACKEND')
if [ ! -z "$WEB_BACKEND" ]; then
$BIN/v-add-web-domain-backend $user $domain $template
fi
((++ domain_counter))
rebuild_web_domain_conf
done
# Touch vesta configs
web_conf="/etc/$WEB_SYSTEM/conf.d/vesta.conf"
touch $web_conf
if [ ! -z "$PROXY_SYSTEM" ]; then
proxy_conf="/etc/$PROXY_SYSTEM/conf.d/vesta.conf"
touch $proxy_conf
fi
# Checking if there is at least 1 domain
if [ "$domain_counter" -lt 1 ]; then
# Deleting web configs
rm -f $HOMEDIR/$user/conf/web/*
sed -i "/.*\/$user\/.*$WEB_SYSTEM.conf/d" $web_conf
if [ ! -z "$PROXY_SYSTEM" ]; then
sed -i "/.*\/$user\/.*$PROXY_SYSTEM.conf/d" $proxy_conf
fi
else
# Clean web configs
sed -i "/.*\/$user\/.*.conf/d" $web_conf
if [ ! -z "$PROXY_SYSTEM" ]; then
sed -i "/.*\/$user\/.*.conf/d" $proxy_conf
fi
# Renaming tmp config
tmp_conf="$HOMEDIR/$user/conf/web/tmp_$WEB_SYSTEM.conf"
conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
mv $tmp_conf $conf
# Checking include
web_include=$(grep "$conf" $web_conf )
if [ -z "$web_include" ] && [ "$WEB_SYSTEM" != 'nginx' ]; then
echo "Include $conf" >> $web_conf
fi
if [ -z "$web_include" ] && [ "$WEB_SYSTEM" = 'nginx' ]; then
echo "include $conf;" >> $web_conf
fi
# Checking SSL
if [ "$ssl_change" = 'yes' ]; then
tmp_conf="$HOMEDIR/$user/conf/web/tmp_s$WEB_SYSTEM.conf"
conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
mv $tmp_conf $conf
ssl_include=$(grep "$conf" $web_conf )
if [ -z "$ssl_include" ] && [ "$WEB_SYSTEM" != 'nginx' ]; then
echo "Include $conf" >> $web_conf
fi
if [ -z "$ssl_include" ] && [ "$WEB_SYSTEM" = 'nginx' ]; then
echo "include $conf;" >> $web_conf
fi
fi
# Checking proxy
if [ ! -z "$PROXY_SYSTEM" ]; then
if [ "$proxy_change" = 'yes' ]; then
tmp_conf="$HOMEDIR/$user/conf/web/tmp_$PROXY_SYSTEM.conf"
conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf"
mv $tmp_conf $conf
proxy_include=$(grep "$conf" $proxy_conf )
if [ -z "$proxy_include" ]; then
echo "include $conf;" >> $proxy_conf
fi
else
conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf"
sed -i "/.*\/$user\/.*$PROXY_SYSTEM.conf/d" $proxy_conf
rm -f $HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf
fi
# Checking SSL proxy
if [ "$proxy_change" = 'yes' ] && [ "$ssl_change" = 'yes' ]; then
tmp_conf="$HOMEDIR/$user/conf/web/tmp_s$PROXY_SYSTEM.conf"
conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
mv $tmp_conf $conf
proxy_include=$(grep "$conf" $proxy_conf )
if [ -z "$proxy_include" ]; then
echo "include $conf;" >> $proxy_conf
fi
else
conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
sed -i "/.*\/$user\/.*s$PROXY_SYSTEM.conf/d" $proxy_conf
rm -f $HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf
fi
fi
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating counters
update_user_value "$user" '$SUSPENDED_WEB' "$suspended_web"
update_user_value "$user" '$U_WEB_DOMAINS' "$user_domains"
update_user_value "$user" '$U_WEB_SSL' "$user_ssl"
update_user_value "$user" '$U_WEB_ALIASES' "$user_aliases"
# Restart web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
if [ ! -z "$PROXY_SYSTEM" ];then
$BIN/v-restart-proxy
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
fi
# Logging
log_event "$OK" "$EVENT"
exit