forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv_change_web_domain_tpl
More file actions
executable file
·179 lines (147 loc) · 4.67 KB
/
v_change_web_domain_tpl
File metadata and controls
executable file
·179 lines (147 loc) · 4.67 KB
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
#!/bin/bash
# info: change web domain template
# options: user domain template
#
# The function changes template of httpd.conf configuration file. The content
# of webdomain directories remains untouched.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
template=$3
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'user domain template'
validate_format 'user' 'domain' 'template'
is_system_enabled "$WEB_SYSTEM"
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
is_apache_template_valid
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Parsing domain values
get_domain_values 'web'
# Deleting domain
tpl_file="$WEBTPL/apache_$TPL.tpl"
old_tpl=$TPL
conf="$HOMEDIR/$user/conf/web/httpd.conf"
del_web_config
# Deleting ssl vhost
if [ "$SSL" = 'yes' ]; then
tpl_file="$WEBTPL/apache_$TPL.stpl"
conf="$HOMEDIR/$user/conf/web/shttpd.conf"
del_web_config
fi
# Defining variables for new vhost config
ip=$IP
email="$user@$domain"
group="$user"
docroot="$HOMEDIR/$user/web/$domain/public_html"
docroot_string="DocumentRoot $docroot"
conf="$HOMEDIR/$user/conf/web/httpd.conf"
tpl_file="$WEBTPL/apache_$template.tpl"
# Parsing domain aliases
i=1
j=1
OLD_IFS="$IFS"
IFS=','
for dom_alias in $ALIAS; do
dom_alias=$(idn -t --quiet -a $dom_alias)
# Spliting ServerAlias lines
check_8k="$server_alias $dom_alias"
if [ "${#check_8k}" -ge '8100' ]; then
if [ "$j" -eq 1 ]; then
alias_string="ServerAlias $server_alias"
else
alias_string="$alias_string\n ServerAlias $server_alias"
fi
(( ++j))
server_alias=''
fi
if [ "$i" -eq 1 ]; then
aliases_idn="$dom_alias"
server_alias="$dom_alias"
alias_string="ServerAlias $server_alias"
else
aliases_idn="$aliases_idn,$dom_alias"
server_alias="$server_alias $dom_alias"
fi
(( ++i))
done
if [ -z "$alias_string" ]; then
alias_string="ServerAlias $server_alias"
else
if [ ! -z "$server_alias" ]; then
alias_string="$alias_string\n ServerAlias $server_alias"
fi
fi
IFS=$OLD_IFS
# Parsing new template
template_data=$(cat $WEBTPL/apache_$template.descr | grep -v '#')
for keys in $template_data; do
eval ${keys%%=*}=${keys#*=}
done
# Checking error log
if [ "$ELOG" = 'no' ]; then
elog='#'
else
elog=''
fi
# Adding domain to the httpd.conf
add_web_config
# Running template trigger
if [ -x $WEBTPL/apache_$template.sh ]; then
$WEBTPL/apache_$template.sh $user $domain $ip $HOMEDIR $docroot
fi
# Checking ssl
if [ "$SSL" = 'yes' ]; then
# Defining SSL vars
ssl_crt="$HOMEDIR/$user/conf/web/ssl.$domain.crt"
ssl_key="$HOMEDIR/$user/conf/web/ssl.$domain.key"
ssl_pem="$HOMEDIR/$user/conf/web/ssl.$domain.pem"
ssl_ca="$HOMEDIR/$user/conf/web/ssl.$domain.ca"
if [ ! -e "$USER_DATA/web/ssl/$domain.ca" ]; then
ssl_ca_str='#'
fi
case $SSL_HOME in
single) docroot="$HOMEDIR/$user/web/$domain/public_shtml" ;;
same) docroot="$HOMEDIR/$user/web/$domain/public_html" ;;
esac
conf="$HOMEDIR/$user/conf/web/shttpd.conf"
tpl_file="$WEBTPL/apache_$template.stpl"
# Adding domain to the httpd.conf
add_web_config
# Running template trigger
if [ -x $WEBTPL/apache_$template.sh ]; then
$WEBTPL/apache_$template.sh \
"$user" "$domain" "$ip" "$HOMEDIR" "$docroot"
fi
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Changing tpl in config
update_object_value 'web' 'DOMAIN' "$domain" '$TPL' "$template"
# Updating db keys
for keys in $(cat $WEBTPL/apache_$template.descr|grep -v '#'); do
key=$(echo "$keys"| cut -f 1 -d '=' |sed -e "s/^/\$/g")
value=$(echo "$keys" |cut -f 2 -d \')
update_object_value 'web' 'DOMAIN' "$domain" "$key" "$value"
done
# Restart web
$BIN/v_restart_web "$EVENT"
# Logging
log_history "$EVENT"
log_event "$OK" "$EVENT"
exit