v_change_web_domain_sslcert 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. # info: change domain ssl certificate
  3. # options: user domain ssl_dir
  4. #
  5. # The function changes SSL domain certificate and the key. If ca file present
  6. # it will be replaced as well.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument defenition
  11. user=$1
  12. domain=$(idn -t --quiet -u "$2" )
  13. domain_idn=$(idn -t --quiet -a "$domain")
  14. ssl_dir=$3
  15. # Importing variables
  16. source $VESTA/conf/vars.conf
  17. source $V_CONF/vesta.conf
  18. source $V_FUNC/shared.func
  19. source $V_FUNC/domain.func
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. # Checking arg number
  24. check_args '3' "$#" 'user domain ssl_dir'
  25. # Checking argument format
  26. format_validation 'user' 'domain' 'ssl_dir'
  27. # Checking web system is enabled
  28. is_system_enabled 'web'
  29. # Checking user
  30. is_user_valid
  31. # Checking user is active
  32. is_user_suspended
  33. # Checking domain exist
  34. is_web_domain_valid
  35. # Checking domain is not suspened
  36. is_domain_suspended 'web'
  37. # Check SSL is added
  38. is_web_domain_value_exist '$SSL'
  39. # Checking ssl certificate
  40. is_web_domain_cert_valid
  41. #----------------------------------------------------------#
  42. # Action #
  43. #----------------------------------------------------------#
  44. # Deleting old certificate
  45. tmpdir=$(mktemp -p $V_HOME/$user/web/$domain/private -d)
  46. rm -f $V_HOME/$user/conf/ssl.$domain.*
  47. mv $V_USERS/$user/ssl/$domain.* $tmpdir
  48. chown -R $user:$user $tmpdir
  49. # Adding new certificate to user data directory
  50. cp -f $ssl_dir/$domain.crt $V_USERS/$user/ssl/$domain.crt
  51. cp -f $ssl_dir/$domain.key $V_USERS/$user/ssl/$domain.key
  52. cp -f $ssl_dir/$domain.crt $V_USERS/$user/ssl/$domain.pem
  53. if [ -e "$ssl_dir/$domain.ca" ]; then
  54. cp -f $ssl_dir/$domain.ca $V_USERS/$user/ssl/$domain.ca
  55. cat $V_USERS/$user/ssl/$domain.ca >> $V_USERS/$user/ssl/$domain.pem
  56. fi
  57. # Adding new certificate to user dir
  58. cp -f $V_USERS/$user/ssl/$domain.crt $V_HOME/$user/conf/ssl.$domain.crt
  59. cp -f $V_USERS/$user/ssl/$domain.key $V_HOME/$user/conf/ssl.$domain.key
  60. cp -f $V_USERS/$user/ssl/$domain.pem $V_HOME/$user/conf/ssl.$domain.pem
  61. if [ -e "$V_USERS/$user/ssl/$domain.ca" ]; then
  62. cp -f $V_USERS/$user/ssl/$domain.ca $V_HOME/$user/conf/ssl.$domain.ca
  63. fi
  64. #----------------------------------------------------------#
  65. # Vesta #
  66. #----------------------------------------------------------#
  67. # Adding task to the vesta pipe
  68. restart_schedule 'web'
  69. # Logging
  70. log_history "$V_EVENT" "$V_SCRIPT $user $domain $tmpdir"
  71. log_event 'system' "$V_EVENT"
  72. exit