v_add_web_domain_ssl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_domains'
  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'
  41. # Checking ssl certificate
  42. is_web_domain_cert_valid
  43. # Checking template
  44. templates=$(get_user_value '$TEMPLATES')
  45. template=$(get_web_domain_value '$TPL')
  46. is_template_valid 'web'
  47. #----------------------------------------------------------#
  48. # Action #
  49. #----------------------------------------------------------#
  50. # Defining variables for template replace
  51. port=$(get_web_port_ssl)
  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/domains/$domain/public_shtml" ;;
  59. same) docroot="$V_HOME/$user/domains/$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. # Adding domain to the httpd.conf
  66. httpd_add_config
  67. # Adding certificate to user dir
  68. if [ ! -e "$ssl_cert" ]; then
  69. cp -f $V_USERS/$user/cert/$cert.crt $ssl_cert
  70. cp -f $V_USERS/$user/cert/$cert.key $ssl_key
  71. fi
  72. # Running template trigger
  73. if [ -e $V_WEBTPL/apache_$template.sh ]; then
  74. $V_WEBTPL/apache_$template.sh $user $domain $ip $V_HOME $docroot $port
  75. fi
  76. # Checking main vesta httpd config
  77. main_conf='/etc/httpd/conf.d/vesta.conf'
  78. main_conf_check=$(grep "$conf" $main_conf )
  79. if [ -z "$main_conf_check" ]; then
  80. echo "Include $conf" >>$main_conf
  81. fi
  82. #----------------------------------------------------------#
  83. # Vesta #
  84. #----------------------------------------------------------#
  85. # Increasing domain value
  86. increase_user_value "$user" '$U_WEB_SSL'
  87. # Adding ssl values
  88. update_web_domain_value '$SSL' 'yes'
  89. update_web_domain_value '$SSL_HOME' "$tpl_option"
  90. update_web_domain_value '$SSL_CERT' "$cert"
  91. # Logging
  92. log_history "$V_EVENT" "v_del_web_domain_ssl $user $domain"
  93. log_event 'system' "$V_EVENT"
  94. exit $OK