Skip to content

Commit 47bdaeb

Browse files
author
Serghey Rodin
committed
user notification support
1 parent a225118 commit 47bdaeb

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

bin/v-add-letsencrypt-domain

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: adding letsencrypt ssl cetificate for domain
3-
# options: USER DOMAIN [ALIASES] [RESTART]
3+
# options: USER DOMAIN [ALIASES] [RESTART] [NOTIFY]
44
#
55
# The function turns on SSL support for a domain. Parameter ssl_dir is a path
66
# to directory where 2 or 3 ssl files can be found. Certificate file
@@ -19,6 +19,7 @@ user=$1
1919
domain=$2
2020
aliases=$3
2121
restart=$4
22+
notify=$5
2223

2324
# Includes
2425
source $VESTA/func/main.sh
@@ -30,45 +31,61 @@ source $VESTA/conf/vesta.conf
3031
# Verifications #
3132
#----------------------------------------------------------#
3233

33-
check_args '2' "$#" 'USER DOMAIN [ALIASES] [RESTART]'
34+
check_args '2' "$#" 'USER DOMAIN [ALIASES] [RESTART] [NOTIFY]'
3435
is_format_valid 'user' 'domain'
3536
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
3637
is_system_enabled "$WEB_SSL" 'SSL_SUPPORT'
3738
is_object_valid 'user' 'USER' "$user"
3839
is_object_unsuspended 'user' 'USER' "$user"
3940
is_object_valid 'web' 'DOMAIN' "$domain"
4041
is_object_unsuspended 'web' 'DOMAIN' "$domain"
41-
is_object_value_empty 'web' 'DOMAIN' "$domain" '$LETSENCRYPT'
42-
get_domain_values 'web'
42+
4343

4444
#----------------------------------------------------------#
4545
# Action #
4646
#----------------------------------------------------------#
4747

48+
# Parsing domain data
49+
get_domain_values 'web'
50+
4851
# Registering LetsEncrypt user account
4952
$BIN/v-add-letsencrypt-user $user
50-
check_result $? "LE account registration" >/dev/null
53+
if [ "$?" -ne 0 ]; then
54+
send_notice "LETSENCRYPT" "Account registration failed"
55+
check_result $E_CONNECT "LE account registration" >/dev/null
56+
fi
57+
58+
# Parsing LetsEncrypt account data
5159
source $USER_DATA/ssl/le.conf
5260
email=$EMAIL
5361

5462
# Validating domain and aliases
5563
i=1
5664
for alias in $(echo $domain,$aliases |tr ',' '\n' |sort -u); do
5765
$BIN/v-check-letsencrypt-domain $user $alias
58-
check_result $? "LE domain validation" >/dev/null
66+
if [ "$?" -ne 0 ]; then
67+
send_notice "LETSENCRYPT" "$alias validation failed"
68+
check_result $E_INVALID "LE domain validation" >/dev/null
69+
fi
70+
71+
# Checking LE limits per account
5972
if [ "$i" -gt 100 ]; then
73+
send_notice 'LETSENCRYPT' 'Limit of domains per account is reached'
6074
check_result $E_LIMIT "LE can't sign more than 100 domains"
6175
fi
6276
i=$((i++))
6377
done
64-
78+
exit
6579
# Generating CSR
6680
ssl_dir=$($BIN/v-generate-ssl-cert "$domain" "$email" "US" "California" \
6781
"San Francisco" "Vesta" "IT" "$aliases" |tail -n1 |awk '{print $2}')
6882

6983
# Signing CSR
7084
crt=$($BIN/v-sign-letsencrypt-csr $user $domain $ssl_dir)
71-
check_result $? "$crt"
85+
if [ "$?" -ne 0 ]; then
86+
send_notice "LETSENCRYPT" "$alias validation failed"
87+
check_result "$E_INVALID" "LE $domain validation"
88+
fi
7289
echo "$crt" > $ssl_dir/$domain.crt
7390

7491
# Dowloading CA certificate
@@ -85,13 +102,15 @@ fi
85102
# Adding SSL
86103
$BIN/v-delete-web-domain-ssl $user $domain >/dev/null 2>&1
87104
$BIN/v-add-web-domain-ssl $user $domain $ssl_dir
88-
check_result $? "SSL install" >/dev/null
89-
90-
if [ -z "$LETSENCRYPT" ]; then
91-
add_object_key "web" 'DOMAIN' "$domain" 'LETSENCRYPT' 'FTP_USER'
105+
if [ "$?" -ne '0' ]; then
106+
send_notice 'LETSENCRYPT' "$domain certificate installation failed"
107+
check_result $? "SSL install" >/dev/null
92108
fi
93109

94110
# Updating letsencrypt key
111+
if [ -z "$LETSENCRYPT" ]; then
112+
add_object_key "web" 'DOMAIN' "$domain" 'LETSENCRYPT' 'FTP_USER'
113+
fi
95114
update_object_value 'web' 'DOMAIN' "$domain" '$LETSENCRYPT' 'yes'
96115

97116

@@ -100,11 +119,13 @@ update_object_value 'web' 'DOMAIN' "$domain" '$LETSENCRYPT' 'yes'
100119
#----------------------------------------------------------#
101120

102121
# Restarting web
103-
if [ "$restart" != 'no' ]; then
104-
$BIN/v-restart-web $restart
105-
check_result $? "Web restart failed" >/dev/null
122+
$BIN/v-restart-web $restart
123+
if [ "$?" -ne 0 ]; then
124+
send_notice 'LETSENCRYPT' "web server needs to be restarted manually"
106125
fi
107126

127+
# Notifying user
128+
send_notice 'LETSENCRYPT' "$domain SSL has been installed successfully"
108129

109130
# Logging
110131
log_event "$OK" "$ARGUMENTS"

0 commit comments

Comments
 (0)