v_add_web_domain_ssl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/bin/bash
  2. # info: adding ssl for domain
  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. cert="$3"
  11. tpl_option="${4-single}"
  12. # Importing variables
  13. source $VESTA/conf/vars.conf
  14. source $V_FUNC/shared_func.sh
  15. source $V_FUNC/domain_func.sh
  16. #----------------------------------------------------------#
  17. # Verifications #
  18. #----------------------------------------------------------#
  19. # Checking arg number
  20. check_args '3' "$#" 'user domain certificate [sslhome]'
  21. # Checking argument format
  22. format_validation 'user' 'domain' 'certificate'
  23. # Checking web system is enabled
  24. is_system_enabled 'web'
  25. # Checking user
  26. is_user_valid
  27. # Checking user is active
  28. is_user_suspended
  29. # Checking domain exist
  30. is_web_domain_valid
  31. # Checking domain is not suspened
  32. is_domain_suspended 'web_domains'
  33. # Checking package
  34. is_package_full 'web_ssl'
  35. # Check ssl is not added
  36. is_web_domain_key_empty '$SSL'
  37. # Checking ssl certificate
  38. is_web_domain_cert_valid
  39. # Checking template
  40. templates=$(get_user_value '$TEMPLATES')
  41. template=$(get_web_domain_value '$TPL')
  42. is_template_valid 'web'
  43. #----------------------------------------------------------#
  44. # Action #
  45. #----------------------------------------------------------#
  46. # Defining variables for template replace
  47. port=$(get_web_port_ssl)
  48. ip=$(get_web_domain_value '$IP')
  49. aliases=$(get_web_domain_value '$ALIAS')
  50. aliases_idn=$(idn -t --quiet -a "$aliases")
  51. email="$user@$domain"
  52. ssl_cert="$V_HOME/$user/conf/$cert.crt"
  53. ssl_key="$V_HOME/$user/conf/$cert.key"
  54. case $tpl_option in
  55. single) docroot="$V_HOME/$user/domains/$domain/public_shtml" ;;
  56. same) docroot="$V_HOME/$user/domains/$domain/public_html" ;;
  57. *) check_args '3' "$#" 'user domain certificate [sslhome]'
  58. esac
  59. group="$user"
  60. conf="$V_HOME/$user/conf/shttpd.conf"
  61. tpl_file="$V_WEBTPL/apache_$template.stpl"
  62. # Adding domain to the httpd.conf
  63. httpd_add_config
  64. # Adding certificate to user dir
  65. if [ ! -e "$ssl_cert" ]; then
  66. cp -f $V_USERS/$user/cert/$cert.crt $ssl_cert
  67. cp -f $V_USERS/$user/cert/$cert.key $ssl_key
  68. fi
  69. # Running template post setup file
  70. if [ -e $V_WEBTPL/apache_$template.sh ]; then
  71. $V_WEBTPL/apache_$template.sh $user $domain $ip $V_HOME $docroot $port
  72. fi
  73. # Checking main vesta httpd config
  74. main_conf='/etc/httpd/conf.d/vesta.conf'
  75. main_conf_check=$(grep "$conf" $main_conf )
  76. if [ -z "$main_conf_check" ]; then
  77. echo "Include $conf" >>$main_conf
  78. fi
  79. #----------------------------------------------------------#
  80. # Vesta #
  81. #----------------------------------------------------------#
  82. # Increasing domain value
  83. increase_user_value "$user" '$U_WEB_SSL'
  84. # Adding ssl values
  85. update_web_domain_value '$SSL' 'yes'
  86. update_web_domain_value '$SSL_HOME' "$tpl_option"
  87. update_web_domain_value '$SSL_CERT' "$cert"
  88. # Logging
  89. log_history "$V_EVENT" "v_del_web_domain_ssl $user $domain"
  90. log_event 'system' "$V_EVENT"
  91. exit $OK