v_change_web_domain_sslcert 2.5 KB

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