|
| 1 | +#!/bin/bash |
| 2 | +# info: update hosts certificates for exim, dovecot & vesta-web |
| 3 | +# options: user |
| 4 | +# options: hostname |
| 5 | +# |
| 6 | +# Function updates certificates for vesta |
| 7 | + |
| 8 | + |
| 9 | +#----------------------------------------------------------# |
| 10 | +# Variable&Function # |
| 11 | +#----------------------------------------------------------# |
| 12 | + |
| 13 | +# Argument definition |
| 14 | +user=$1 |
| 15 | +hostname=$2 |
| 16 | + |
| 17 | +# Includes |
| 18 | +source $VESTA/func/main.sh |
| 19 | +source $VESTA/func/ip.sh |
| 20 | +source $VESTA/conf/vesta.conf |
| 21 | + |
| 22 | + |
| 23 | +#----------------------------------------------------------# |
| 24 | +# Verifications # |
| 25 | +#----------------------------------------------------------# |
| 26 | + |
| 27 | +check_args '1' "$#" '[USER] [HOSTNAME]' |
| 28 | +is_format_valid 'user' |
| 29 | +is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM' |
| 30 | +is_system_enabled "$WEB_SSL" 'SSL_SUPPORT' |
| 31 | +is_object_valid 'user' 'USER' "$user" |
| 32 | +is_object_unsuspended 'user' 'USER' "$user" |
| 33 | +is_object_valid 'web' 'DOMAIN' "$hostname" |
| 34 | +is_object_unsuspended 'web' 'DOMAIN' "$hostname" |
| 35 | + |
| 36 | +#----------------------------------------------------------# |
| 37 | +# Action # |
| 38 | +#----------------------------------------------------------# |
| 39 | + |
| 40 | +# Get current datetime for backup of old files |
| 41 | +backup_datetime=`date '+%Y-%m-%d_%H-%M-%S'` |
| 42 | + |
| 43 | +# Keep a backup of the old certificate - todo: remove in production |
| 44 | +#mv $VESTA/ssl/certificate.crt $VESTA/ssl/certificate.crt_backup_$backup_datetime |
| 45 | +#mv $VESTA/ssl/certificate.key $VESTA/ssl/certificate.key_backup_$backup_datetime |
| 46 | + |
| 47 | +# Copy hostnames certificates from user dir |
| 48 | +cp /home/$user/conf/web/ssl.$hostname.pem $VESTA/ssl/certificate.crt |
| 49 | +cp /home/$user/conf/web/ssl.$hostname.key $VESTA/ssl/certificate.key |
| 50 | + |
| 51 | +# Assign exim permissions |
| 52 | +chown exim:mail $VESTA/ssl/certificate.crt |
| 53 | +chown exim:mail $VESTA/ssl/certificate.key |
| 54 | + |
| 55 | +# Restart exim, dovecot & vesta |
| 56 | +v-restart-mail |
| 57 | +v-restart-web-backend |
| 58 | + |
| 59 | + |
| 60 | +#----------------------------------------------------------# |
| 61 | +# Vesta # |
| 62 | +#----------------------------------------------------------# |
| 63 | + |
| 64 | +# Logging |
| 65 | +log_event "$OK" "$ARGUMENTS" |
| 66 | + |
| 67 | +exit |
0 commit comments