-
Notifications
You must be signed in to change notification settings - Fork 16
/
mailcert
146 lines (142 loc) · 4.54 KB
/
mailcert
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
#!/bin/bash
#########################################################################
# Plesk LetsEncrypt Certificate - copy to #
# Postfix - Dovecot - Courier - Webmin - QMail #
# Powie . www.powie.de #
# V1.05 #
# For Plesk / Debian #
#########################################################################
# first we define our common hostname as uses by our plesk host and cert!
HOSTNAME=$(hostname)
echo -e "Server name set to: \e[4m$HOSTNAME"
echo -e "\e[0mIf this is incorrect please set custom hostname in script."
#
# Set hostname here if custom. Example: HOSTNAME=server1.boisehosting.net
#HOSTNAME="artus.be-webspace.net"
#
# that's all for now
# nothing below need to be changed
#
#
#
# here we start
# This is our http conf we are looking into it
CONFFILE=/var/www/vhosts/system/${HOSTNAME}/conf/httpd.conf
CONFFILE2=/var/www/vhosts/system/${HOSTNAME}/conf/httpd_ip_default.conf
#we need some functions
#get the pem file from apache conf, because its written there after changes
getpemfile() {
#echo "suche"
CERT=$(grep -m 1 SSLCertificateFile ${CONFFILE})
CERTFILE=${CERT:20}
if [ ! "$CERTFILE" ]; then
CERT=$(grep -m 1 SSLCertificateFile ${CONFFILE2})
CERTFILE=${CERT:20}
fi
echo "Plesk certificate located at:${CERTFILE}"
}
#copy pem to dovecot
certfordovecot () {
if [ -e /etc/dovecot/private/ssl-cert-and-key.pem ]
then
if diff /etc/dovecot/private/ssl-cert-and-key.pem $CERTFILE > /dev/null
then
echo -e "\e[33mSkipped: \e[39mDovecot already up to date."
else
cp ${CERTFILE} /etc/dovecot/private/ssl-cert-and-key.pem
echo -e "\e[32mSUCCESS: \e[39mDovecot Certificate Updated"
service dovecot restart
fi
fi
}
#copy pem to postfix
certforpostfix () {
if [ -e /etc/postfix/postfix_default.pem ]
then
if diff /etc/postfix/postfix_default.pem $CERTFILE > /dev/null
then
echo -e "\e[33mSkipped: \e[39mPostfix already up to date."
else
cp ${CERTFILE} /etc/postfix/postfix_default.pem
echo -e "\e[32mSUCCESS: \e[39mPostfix Certificate Updated"
service postfix restart
fi
fi
}
#copy pem to courier
certforcourier () {
if [ -e /usr/share/imapd.pem ]
then
if diff /usr/share/imapd.pem $CERTFILE > /dev/null
then
echo -e "\e[33mSkipped: \e[39mCourier-IMAP already up to date."
else
cp ${CERTFILE} /usr/share/imapd.pem
echo -e "\e[32mSUCCESS: \e[39mCourier-IMAP Certificate Updated"
service xinetd restart
fi
fi
if [ -e /usr/share/pop3d.pem ]
then
if diff /usr/share/pop3d.pem $CERTFILE > /dev/null
then
echo -e "\e[33mSkipped: \e[39mCourier-POP3 already up to date."
else
cp ${CERTFILE} /usr/share/pop3d.pem
echo -e "\e[32mSUCCESS: \e[39mCourier-POP3 Certificate Updated"
service xinetd restart
fi
fi
}
#copy pem to webmin
certforwebmin () {
if [ -e /etc/webmin/miniserv.pem ]
then
if diff /etc/webmin/miniserv.pem $CERTFILE > /dev/null
then
echo -e "\e[33mSkipped: \e[39mWebmin already up to date."
else
cp ${CERTFILE} /etc/webmin/miniserv.pem
echo -e "\e[32mSUCCESS: \e[39mWebmin Certificate Updated"
service webmin restart
fi
fi
}
#copy pem to qmail
certforqmail () {
if [ -e /var/qmail/control/servercert.pem ]
then
if diff /var/qmail/control/servercert.pem $CERTFILE > /dev/null
then
echo -e "\e[33mSkipped: \e[39mQMail already up to date."
else
cp ${CERTFILE} /var/qmail/control/servercert.pem
echo -e "\e[32mSUCCESS: \e[39mQMail Certificate Updated"
service qmail restart
fi
fi
}
#copy the cert file to the services
copycerts() {
certfordovecot
certforpostfix
certforcourier
certforwebmin
certforqmail
}
#now we start
if [ -e ${CONFFILE} ]
then
getpemfile
if [ -e ${CERTFILE} ]
then
copycerts
exit 0
else
echo "cert file doesnt exists"
exit 1
fi
else
echo "conf file not found"
exit 1
fi