v_add_web_domain_ssl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/bin/bash
  2. # info: adding ssl for domain
  3. # options: user domain ssl_dir [ssl_home]
  4. #
  5. # The function turns on SSL support for a domain. Parameter ssl_dir is a path
  6. # to directory where 2 or 3 ssl files can be found. Certificate file
  7. # domain.tld.crt and its key domain.tld.key are mandatory. Certificate
  8. # authority domain.tld.ca file is optional. If home directory parameter
  9. # (ssl_home) is not set, https domain uses public_shtml as separate
  10. # documentroot directory.
  11. #----------------------------------------------------------#
  12. # Variable&Function #
  13. #----------------------------------------------------------#
  14. # Argument defenition
  15. user=$1
  16. domain=$(idn -t --quiet -u "$2" )
  17. domain_idn=$(idn -t --quiet -a "$domain")
  18. ssl_dir=$3
  19. ssl_home=${4-single}
  20. # Importing variables
  21. source $VESTA/conf/vars.conf
  22. source $V_CONF/vesta.conf
  23. source $V_FUNC/shared.func
  24. source $V_FUNC/domain.func
  25. source $V_FUNC/ip.func
  26. #----------------------------------------------------------#
  27. # Verifications #
  28. #----------------------------------------------------------#
  29. # Checking arg number
  30. check_args '3' "$#" 'user domain ssl_dir [ssl_home]'
  31. # Checking argument format
  32. format_validation 'user' 'domain' 'ssl_dir'
  33. # Checking web system is enabled
  34. is_system_enabled 'web'
  35. # Checking user
  36. is_user_valid
  37. # Checking user is active
  38. is_user_suspended
  39. # Checking domain exist
  40. is_web_domain_valid
  41. # Checking domain is not suspened
  42. is_domain_suspended 'web'
  43. # Checking package
  44. is_package_full 'web_ssl'
  45. # Check ssl is not added
  46. is_web_domain_key_empty '$SSL'
  47. # Checking ssl certificate
  48. is_web_domain_cert_valid
  49. #----------------------------------------------------------#
  50. # Action #
  51. #----------------------------------------------------------#
  52. # Adding certificate to user data directory
  53. cp -f $ssl_dir/$domain.crt $V_USERS/$user/ssl/$domain.crt
  54. cp -f $ssl_dir/$domain.key $V_USERS/$user/ssl/$domain.key
  55. cp -f $ssl_dir/$domain.crt $V_USERS/$user/ssl/$domain.pem
  56. if [ -e "$ssl_dir/$domain.ca" ]; then
  57. cp -f $ssl_dir/$domain.ca $V_USERS/$user/ssl/$domain.ca
  58. cat $V_USERS/$user/ssl/$domain.ca >> $V_USERS/$user/ssl/$domain.pem
  59. fi
  60. # Parsing domain values
  61. get_web_domain_values
  62. conf="$V_HOME/$user/conf/shttpd.conf"
  63. tpl_file="$V_WEBTPL/apache_$TPL.stpl"
  64. SSL_HOME="$ssl_home"
  65. # Checking ip ownership
  66. is_sys_ip_owner
  67. # Preparing domain values for the template substitution
  68. upd_web_domain_values
  69. # Adding domain to the shttpd.conf
  70. add_web_config
  71. # Adding certificate to user dir
  72. cp -f $V_USERS/$user/ssl/$domain.crt $V_HOME/$user/conf/ssl.$domain.crt
  73. cp -f $V_USERS/$user/ssl/$domain.key $V_HOME/$user/conf/ssl.$domain.key
  74. cp -f $V_USERS/$user/ssl/$domain.pem $V_HOME/$user/conf/ssl.$domain.pem
  75. if [ -e "$V_USERS/$user/ssl/$domain.ca" ]; then
  76. cp -f $V_USERS/$user/ssl/$domain.ca $V_HOME/$user/conf/ssl.$domain.ca
  77. fi
  78. # Running template trigger
  79. if [ -x $V_WEBTPL/apache_$template.sh ]; then
  80. $V_WEBTPL/apache_$template.sh $user $domain $ip $V_HOME $docroot
  81. fi
  82. # Checking main vesta httpd config
  83. main_conf='/etc/httpd/conf.d/vesta.conf'
  84. main_conf_check=$(grep "$conf" $main_conf )
  85. if [ -z "$main_conf_check" ]; then
  86. echo "Include $conf" >> $main_conf
  87. fi
  88. # Checking nginx
  89. if [ ! -z "$NGINX" ]; then
  90. # Adding domain to the snginx.conf
  91. conf="$V_HOME/$user/conf/snginx.conf"
  92. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
  93. add_web_config
  94. # Checking vesta nginx config
  95. main_conf='/etc/nginx/conf.d/vesta_users.conf'
  96. main_conf_check=$(grep "$conf" $main_conf )
  97. if [ -z "$main_conf_check" ]; then
  98. echo "include $conf;" >>$main_conf
  99. fi
  100. fi
  101. #----------------------------------------------------------#
  102. # Vesta #
  103. #----------------------------------------------------------#
  104. # Increasing domain value
  105. increase_user_value "$user" '$U_WEB_SSL'
  106. # Adding ssl values
  107. update_web_domain_value '$SSL_HOME' "$SSL_HOME"
  108. update_web_domain_value '$SSL' 'yes'
  109. # Logging
  110. log_history "$V_EVENT" "v_delete_web_domain_ssl $user $domain"
  111. log_event 'system' "$V_EVENT"
  112. exit