Skip to content

Commit 9e522be

Browse files
Merge pull request hestiacp#571 from Neilpang/master
add a new command v-update-web-domain-ssl, to update the ssl certificate when the certificate is renewed.
2 parents 5c95768 + 50b3044 commit 9e522be

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

bin/v-update-web-domain-ssl

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
# info: updating ssl certificate for domain
3+
# options: USER DOMAIN SSL_DIR [RESTART]
4+
#
5+
# The function updates the SSL certificate for a domain. Parameter ssl_dir is a path
6+
# to directory where 2 or 3 ssl files can be found. Certificate file
7+
# domain.tld.crt and its key domain.tld.key are mandatory. Certificate
8+
# authority domain.tld.ca file is optional.
9+
10+
11+
#----------------------------------------------------------#
12+
# Variable&Function #
13+
#----------------------------------------------------------#
14+
15+
# Argument definition
16+
user=$1
17+
domain=$(idn -t --quiet -u "$2" )
18+
domain_idn=$(idn -t --quiet -a "$domain")
19+
ssl_dir=$3
20+
restart="$4"
21+
22+
# Includes
23+
source $VESTA/func/main.sh
24+
source $VESTA/func/domain.sh
25+
source $VESTA/func/ip.sh
26+
source $VESTA/conf/vesta.conf
27+
28+
29+
#----------------------------------------------------------#
30+
# Verifications #
31+
#----------------------------------------------------------#
32+
33+
check_args '3' "$#" 'USER DOMAIN SSL_DIR [RESTART]'
34+
validate_format 'user' 'domain' 'ssl_dir'
35+
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
36+
is_system_enabled "$WEB_SSL" 'SSL_SUPPORT'
37+
is_object_valid 'user' 'USER' "$user"
38+
is_object_unsuspended 'user' 'USER' "$user"
39+
is_object_valid 'web' 'DOMAIN' "$domain"
40+
is_object_unsuspended 'web' 'DOMAIN' "$domain"
41+
is_object_value_exist 'web' 'DOMAIN' "$domain" '$SSL'
42+
is_web_domain_cert_valid
43+
44+
45+
#----------------------------------------------------------#
46+
# Action #
47+
#----------------------------------------------------------#
48+
49+
# Adding certificate to user data directory
50+
cp -f $ssl_dir/$domain.crt $USER_DATA/ssl/$domain.crt
51+
cp -f $ssl_dir/$domain.key $USER_DATA/ssl/$domain.key
52+
cp -f $ssl_dir/$domain.crt $USER_DATA/ssl/$domain.pem
53+
if [ -e "$ssl_dir/$domain.ca" ]; then
54+
cp -f $ssl_dir/$domain.ca $USER_DATA/ssl/$domain.ca
55+
echo >> $USER_DATA/ssl/$domain.pem
56+
cat $USER_DATA/ssl/$domain.ca >> $USER_DATA/ssl/$domain.pem
57+
fi
58+
chmod 660 $USER_DATA/ssl/$domain.*
59+
60+
61+
62+
# Adding certificate to user dir
63+
cp -f $USER_DATA/ssl/$domain.crt $HOMEDIR/$user/conf/web/ssl.$domain.crt
64+
cp -f $USER_DATA/ssl/$domain.key $HOMEDIR/$user/conf/web/ssl.$domain.key
65+
cp -f $USER_DATA/ssl/$domain.pem $HOMEDIR/$user/conf/web/ssl.$domain.pem
66+
if [ -e "$USER_DATA/ssl/$domain.ca" ]; then
67+
cp -f $USER_DATA/ssl/$domain.ca $HOMEDIR/$user/conf/web/ssl.$domain.ca
68+
fi
69+
70+
71+
72+
#----------------------------------------------------------#
73+
# Vesta #
74+
#----------------------------------------------------------#
75+
76+
# Restarting web server
77+
if [ "$restart" != 'no' ]; then
78+
$BIN/v-restart-web
79+
check_result $? "Web restart failed" >/dev/null
80+
81+
if [ ! -z "$PROXY_SYSTEM" ]; then
82+
$BIN/v-restart-proxy
83+
check_result $? "Proxy restart failed" >/dev/null
84+
fi
85+
fi
86+
87+
# Logging
88+
log_history "update ssl certificate for $domain"
89+
log_event "$OK" "$EVENT"
90+
91+
exit

0 commit comments

Comments
 (0)