Skip to content

Commit 38b7557

Browse files
committed
Securing v-update-host-certificate and few small fixes
1 parent 9decddd commit 38b7557

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

bin/v-update-host-certificate

100644100755
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# info: update hosts certificates for exim, dovecot & vesta-web
2+
# info: update hosts certificates for exim, dovecot & vesta-nginx
33
# options: user
44
# options: hostname
55
#
@@ -10,6 +10,13 @@
1010
# Variable&Function #
1111
#----------------------------------------------------------#
1212

13+
whoami=$(whoami)
14+
if [ "$whoami" != "root" ] && [ "$whoami" != "admin" ] ; then
15+
echo "You must be root or admin to execute this script";
16+
exit 1;
17+
fi
18+
19+
1320
# Argument definition
1421
user=$1
1522
hostname=$2
@@ -33,6 +40,11 @@ is_object_unsuspended 'user' 'USER' "$user"
3340
is_object_valid 'web' 'DOMAIN' "$hostname"
3441
is_object_unsuspended 'web' 'DOMAIN' "$hostname"
3542

43+
if [ ! -f "/home/$user/conf/web/ssl.$hostname.pem" ]; then
44+
echo "This domain does not have certificate";
45+
exit 1;
46+
fi
47+
3648
#----------------------------------------------------------#
3749
# Action #
3850
#----------------------------------------------------------#
@@ -48,9 +60,16 @@ backup_datetime=`date '+%Y-%m-%d_%H-%M-%S'`
4860
cp /home/$user/conf/web/ssl.$hostname.pem $VESTA/ssl/certificate.crt
4961
cp /home/$user/conf/web/ssl.$hostname.key $VESTA/ssl/certificate.key
5062

63+
# Checking exim username for later chowning
64+
exim_user="exim";
65+
check_exim_username=$(grep -c '^Debian-exim:' /etc/passwd)
66+
if [ "$check_exim_username" -eq 1 ]; then
67+
exim_user="Debian-exim"
68+
fi
69+
5170
# Assign exim permissions
52-
chown exim:mail $VESTA/ssl/certificate.crt
53-
chown exim:mail $VESTA/ssl/certificate.key
71+
chown $exim_user:mail $VESTA/ssl/certificate.crt
72+
chown $exim_user:mail $VESTA/ssl/certificate.key
5473

5574
# Restart exim, dovecot & vesta
5675
v-restart-mail
@@ -64,4 +83,4 @@ v-restart-web-backend
6483
# Logging
6584
log_event "$OK" "$ARGUMENTS"
6685

67-
exit
86+
exit 0;

0 commit comments

Comments
 (0)