forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv-change-sys-hestia-ssl
More file actions
executable file
·77 lines (60 loc) · 2.3 KB
/
v-change-sys-hestia-ssl
File metadata and controls
executable file
·77 lines (60 loc) · 2.3 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
#!/bin/bash
# info: change hestia ssl certificate
# options: SSL_DIR [RESTART]
#
# The function changes hestia SSL certificate and the key.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
domain='certificate'
ssl_dir=$1
restart=$2
# Includes
source $HESTIA/func/main.sh
source $HESTIA/func/domain.sh
source $HESTIA/conf/hestia.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'SSL_DIR [RESTART]'
is_format_valid 'ssl_dir'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Checking new certificate
certificate=$(cat $ssl_dir/$domain.crt |grep -n END)
certificate_count=$(echo "$certificate" |wc -l)
if [ "$certificate_count" -gt 1 ]; then
crt_end=$(echo "$certificate" |head -n1 |cut -f 1 -d :)
crt_lines=$(wc -l $ssl_dir/$domain.crt |cut -f1 -d ' ')
pem_begin=$((crt_lines - crt_end))
mv $ssl_dir/$domain.crt $ssl_dir/$domain.crt_full
head -n $crt_end $ssl_dir/$domain.crt_full > $ssl_dir/$domain.crt
tail -n $pem_begin $ssl_dir/$domain.crt_full > $ssl_dir/$domain.ca
is_web_domain_cert_valid
mv -f $ssl_dir/$domain.crt_full $ssl_dir/$domain.crt
rm -f $ssl_dir/$domain.ca
else
is_web_domain_cert_valid
fi
# Moving old certificate
mv $HESTIA/ssl/certificate.crt $HESTIA/ssl/certificate.crt.back
mv $HESTIA/ssl/certificate.key $HESTIA/ssl/certificate.key.back
# Adding new certificate
cp -f $ssl_dir/certificate.crt $HESTIA/ssl/certificate.crt
cp -f $ssl_dir/certificate.key $HESTIA/ssl/certificate.key
#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#
# Restarting web server
if [ "$restart" != 'no' ]; then
kill -HUP $(cat /var/run/hestia-nginx.pid)
$BIN/v-restart-mail
if [ ! -z "$IMAP_SYSTEM" ]; then
v-restart-service "$IMAP_SYSTEM"
fi
fi
# Logging
log_event "$OK" "$ARGUMENTS"
exit