v-update-host-certificate 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/bash
  2. # info: update hosts certificates for exim, dovecot & hestia-nginx
  3. # options: user
  4. # options: hostname
  5. #
  6. # Function updates certificates for hestia
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. whoami=$(whoami)
  11. if [ "$whoami" != "root" ] && [ "$whoami" != "admin" ] ; then
  12. echo "You must be root or admin to execute this script";
  13. exit 1;
  14. fi
  15. # Argument definition
  16. user=$1
  17. hostname=$2
  18. # Includes
  19. source $HESTIA/func/main.sh
  20. source $HESTIA/func/ip.sh
  21. source $HESTIA/conf/hestia.conf
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. check_args '1' "$#" '[USER] [HOSTNAME]'
  26. is_format_valid 'user'
  27. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  28. is_system_enabled "$WEB_SSL" 'SSL_SUPPORT'
  29. is_object_valid 'user' 'USER' "$user"
  30. is_object_unsuspended 'user' 'USER' "$user"
  31. is_object_valid 'web' 'DOMAIN' "$hostname"
  32. is_object_unsuspended 'web' 'DOMAIN' "$hostname"
  33. if [ ! -f "/home/$user/conf/web/$hostname/ssl.$hostname.pem" ]; then
  34. echo "This domain does not have certificate";
  35. exit 1;
  36. fi
  37. #----------------------------------------------------------#
  38. # Action #
  39. #----------------------------------------------------------#
  40. # Get current datetime for backup of old files
  41. backup_datetime=`date '+%Y-%m-%d_%H-%M-%S'`
  42. # Copy hostnames certificates from user dir
  43. cp /home/$user/conf/web/$hostname/ssl.$hostname.pem $HESTIA/ssl/certificate.crt
  44. cp /home/$user/conf/web/$hostname/ssl.$hostname.key $HESTIA/ssl/certificate.key
  45. # Checking exim username for later chowning
  46. exim_user="exim";
  47. check_exim_username=$(grep -c '^Debian-exim:' /etc/passwd)
  48. if [ "$check_exim_username" -eq 1 ]; then
  49. exim_user="Debian-exim"
  50. fi
  51. # Assign exim permissions
  52. chown $exim_user:mail $HESTIA/ssl/certificate.crt
  53. chown $exim_user:mail $HESTIA/ssl/certificate.key
  54. # Restart exim, dovecot & hestia
  55. $BIN/v-restart-mail
  56. if [ ! -z "$IMAP_SYSTEM" ]; then
  57. $BIN/v-restart-service "$IMAP_SYSTEM"
  58. fi
  59. if [ ! -z "$FTP_SYSTEM" ]; then
  60. $BIN/v-restart-service "$FTP_SYSTEM"
  61. fi
  62. if [ -f "/var/run/hestia-nginx.pid" ]; then
  63. kill -HUP $(cat /var/run/hestia-nginx.pid)
  64. fi
  65. #----------------------------------------------------------#
  66. # Hestia #
  67. #----------------------------------------------------------#
  68. # Logging
  69. log_event "$OK" "$ARGUMENTS"
  70. exit 0;