| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #!/bin/bash
- # info: update hosts certificates for exim, dovecot & hestia-nginx
- # options: user
- # options: hostname
- #
- # Function updates certificates for hestia
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- whoami=$(whoami)
- if [ "$whoami" != "root" ] && [ "$whoami" != "admin" ] ; then
- echo "You must be root or admin to execute this script";
- exit 1;
- fi
- # Argument definition
- user=$1
- hostname=$2
- # Includes
- source $HESTIA/func/main.sh
- source $HESTIA/func/ip.sh
- source $HESTIA/conf/hestia.conf
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- check_args '1' "$#" '[USER] [HOSTNAME]'
- is_format_valid 'user'
- is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
- is_system_enabled "$WEB_SSL" 'SSL_SUPPORT'
- is_object_valid 'user' 'USER' "$user"
- is_object_unsuspended 'user' 'USER' "$user"
- is_object_valid 'web' 'DOMAIN' "$hostname"
- is_object_unsuspended 'web' 'DOMAIN' "$hostname"
- if [ ! -f "/home/$user/conf/web/$hostname/ssl.$hostname.pem" ]; then
- echo "This domain does not have certificate";
- exit 1;
- fi
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Get current datetime for backup of old files
- backup_datetime=`date '+%Y-%m-%d_%H-%M-%S'`
- # Copy hostnames certificates from user dir
- cp /home/$user/conf/web/$hostname/ssl.$hostname.pem $HESTIA/ssl/certificate.crt
- cp /home/$user/conf/web/$hostname/ssl.$hostname.key $HESTIA/ssl/certificate.key
- # Checking exim username for later chowning
- exim_user="exim";
- check_exim_username=$(grep -c '^Debian-exim:' /etc/passwd)
- if [ "$check_exim_username" -eq 1 ]; then
- exim_user="Debian-exim"
- fi
- # Assign exim permissions
- chown $exim_user:mail $HESTIA/ssl/certificate.crt
- chown $exim_user:mail $HESTIA/ssl/certificate.key
- # Restart exim, dovecot & hestia
- $BIN/v-restart-mail
- if [ ! -z "$IMAP_SYSTEM" ]; then
- $BIN/v-restart-service "$IMAP_SYSTEM"
- fi
- if [ ! -z "$FTP_SYSTEM" ]; then
- $BIN/v-restart-service "$FTP_SYSTEM"
- fi
- if [ -f "/var/run/hestia-nginx.pid" ]; then
- kill -HUP $(cat /var/run/hestia-nginx.pid)
- fi
- #----------------------------------------------------------#
- # Hestia #
- #----------------------------------------------------------#
- # Logging
- log_event "$OK" "$ARGUMENTS"
- exit 0;
|