v-update-host-certificate 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument definition
  11. user=$1
  12. hostname=$2
  13. # Includes
  14. source $VESTA/func/main.sh
  15. source $VESTA/func/ip.sh
  16. source $VESTA/conf/vesta.conf
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. check_args '1' "$#" '[USER] [HOSTNAME]'
  21. is_format_valid 'user'
  22. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  23. is_system_enabled "$WEB_SSL" 'SSL_SUPPORT'
  24. is_object_valid 'user' 'USER' "$user"
  25. is_object_unsuspended 'user' 'USER' "$user"
  26. is_object_valid 'web' 'DOMAIN' "$hostname"
  27. is_object_unsuspended 'web' 'DOMAIN' "$hostname"
  28. #----------------------------------------------------------#
  29. # Action #
  30. #----------------------------------------------------------#
  31. # Get current datetime for backup of old files
  32. backup_datetime=`date '+%Y-%m-%d_%H-%M-%S'`
  33. # Keep a backup of the old certificate - todo: remove in production
  34. #mv $VESTA/ssl/certificate.crt $VESTA/ssl/certificate.crt_backup_$backup_datetime
  35. #mv $VESTA/ssl/certificate.key $VESTA/ssl/certificate.key_backup_$backup_datetime
  36. # Copy hostnames certificates from user dir
  37. cp /home/$user/conf/web/ssl.$hostname.pem $VESTA/ssl/certificate.crt
  38. cp /home/$user/conf/web/ssl.$hostname.key $VESTA/ssl/certificate.key
  39. # Assign exim permissions
  40. chown exim:mail $VESTA/ssl/certificate.crt
  41. chown exim:mail $VESTA/ssl/certificate.key
  42. # Restart exim, dovecot & vesta
  43. v-restart-mail
  44. v-restart-web-backend
  45. #----------------------------------------------------------#
  46. # Vesta #
  47. #----------------------------------------------------------#
  48. # Logging
  49. log_event "$OK" "$ARGUMENTS"
  50. exit