v_add_web_domain_ssl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. source $V_FUNC/ip_func.sh
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. # Checking arg number
  21. check_args '3' "$#" 'user domain certificate [sslhome]'
  22. # Checking argument format
  23. format_validation 'user' 'domain' 'certificate'
  24. # Checking web system is enabled
  25. is_system_enabled 'web'
  26. # Checking user
  27. is_user_valid
  28. # Checking user is active
  29. is_user_suspended
  30. # Checking domain exist
  31. is_web_domain_valid
  32. # Checking domain is not suspened
  33. is_domain_suspended 'web'
  34. # Checking package
  35. is_package_full 'web_ssl'
  36. # Checking ip ownership
  37. ip=$(get_web_domain_value '$IP')
  38. is_sys_ip_owner
  39. # Check ssl is not added
  40. is_web_domain_key_empty '$SSL_CERT'
  41. # Checking ssl certificate
  42. is_web_domain_cert_valid
  43. # Checking template
  44. templates=$(get_user_value '$WEB_TPL')
  45. template=$(get_web_domain_value '$TPL')
  46. is_template_valid 'web'
  47. #----------------------------------------------------------#
  48. # Action #
  49. #----------------------------------------------------------#
  50. # Defining variables for template replace
  51. web_ssl_port=$(get_config_value '$WEB_SSL_PORT')
  52. aliases=$(get_web_domain_value '$ALIAS')
  53. aliases_idn=$(idn -t --quiet -a "$aliases")
  54. email="$user@$domain"
  55. ssl_cert="$V_HOME/$user/conf/$cert.crt"
  56. ssl_key="$V_HOME/$user/conf/$cert.key"
  57. case $tpl_option in
  58. single) docroot="$V_HOME/$user/web/$domain/public_shtml" ;;
  59. same) docroot="$V_HOME/$user/web/$domain/public_html" ;;
  60. *) check_args '3' "$#" 'user domain certificate [sslhome]'
  61. esac
  62. group="$user"
  63. conf="$V_HOME/$user/conf/shttpd.conf"
  64. tpl_file="$V_WEBTPL/apache_$template.stpl"
  65. # Checking error log status
  66. elog=$(get_web_domain_value '$ELOG')
  67. if [ "$elog" = 'no' ]; then
  68. elog=' #'
  69. else
  70. elog=' '
  71. fi
  72. # Adding domain to the httpd.conf
  73. add_web_config
  74. # Adding certificate to user dir
  75. if [ ! -e "$ssl_cert" ]; then
  76. cp -f $V_USERS/$user/cert/$cert.crt $ssl_cert
  77. cp -f $V_USERS/$user/cert/$cert.key $ssl_key
  78. fi
  79. # Running template trigger
  80. if [ -x $V_WEBTPL/apache_$template.sh ]; then
  81. $V_WEBTPL/apache_$template.sh $user $domain $ip $V_HOME $docroot
  82. fi
  83. # Checking main vesta httpd config
  84. main_conf='/etc/httpd/conf.d/vesta.conf'
  85. main_conf_check=$(grep "$conf" $main_conf )
  86. if [ -z "$main_conf_check" ]; then
  87. echo "Include $conf" >>$main_conf
  88. fi
  89. #----------------------------------------------------------#
  90. # Vesta #
  91. #----------------------------------------------------------#
  92. # Increasing domain value
  93. increase_user_value "$user" '$U_WEB_SSL'
  94. # Adding ssl values
  95. update_web_domain_value '$SSL_HOME' "$tpl_option"
  96. update_web_domain_value '$SSL_CERT' "$cert"
  97. # Logging
  98. log_history "$V_EVENT" "v_del_web_domain_ssl $user $domain"
  99. log_event 'system' "$V_EVENT"
  100. exit $OK