v_change_web_domain_sslcert 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/bash
  2. # info: changing domain ssl certificate
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user="$1"
  8. domain=$(idn -t --quiet -u "$2" )
  9. domain_idn=$(idn -t --quiet -a "$domain")
  10. certificate="$3"
  11. # Importing variables
  12. source $VESTA/conf/vars.conf
  13. source $V_FUNC/shared_func.sh
  14. source $V_FUNC/domain_func.sh
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. # Checking arg number
  19. check_args '3' "$#" 'user domain certificate'
  20. # Checking argument format
  21. format_validation 'user' 'domain' 'certificate'
  22. # Checking web system is enabled
  23. is_system_enabled 'web'
  24. # Checking user
  25. is_user_valid
  26. # Checking user is active
  27. is_user_suspended
  28. # Checking domain exist
  29. is_web_domain_valid
  30. # Checking domain is not suspened
  31. is_domain_suspended 'web'
  32. # Check SSL is added
  33. is_web_domain_value_exist '$SSL_CERT'
  34. # Checking ssl certificate
  35. is_web_domain_cert_valid
  36. #----------------------------------------------------------#
  37. # Action #
  38. #----------------------------------------------------------#
  39. # Get template name
  40. tpl_name=$(get_web_domain_value '$TPL')
  41. tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
  42. # Defininig config
  43. conf="$V_HOME/$user/conf/shttpd.conf"
  44. # Defining ssl key and certificate
  45. ssl_cert="$V_HOME/$user/conf/$certificate.crt"
  46. ssl_key="$V_HOME/$user/conf/$certificate.key"
  47. # Defining search phrase
  48. search_phrase='SSLCertificateFile'
  49. # Defining replace string
  50. str_repl=" SSLCertificateFile $ssl_cert"
  51. # Changing sslhome
  52. change_web_config
  53. # Defining search phrase
  54. search_phrase='SSLCertificateKeyFile'
  55. # Defining replace string
  56. str_repl=" SSLCertificateKeyFile $ssl_key"
  57. # Changing sslhome
  58. change_web_config
  59. # Adding certificate to user dir
  60. if [ ! -e "$ssl_cert" ]; then
  61. cp -f $V_USERS/$user/cert/$certificate.crt $ssl_cert
  62. cp -f $V_USERS/$user/cert/$certificate.key $ssl_key
  63. fi
  64. #----------------------------------------------------------#
  65. # Vesta #
  66. #----------------------------------------------------------#
  67. # Get old sslhome value
  68. old_ssl_cert=$(get_web_domain_value '$SSL_CERT')
  69. # Adding sslcert in config
  70. update_web_domain_value '$SSL_CERT' "$certificate"
  71. # Adding task to the vesta pipe
  72. restart_schedule 'web'
  73. # Logging
  74. log_history "$V_EVENT" "$V_SCRIPT $user $domain $old_ssl_cert"
  75. log_event 'system' "$V_EVENT"
  76. exit $OK