v_add_web_domain_ssl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. chmod 660 $V_USERS/$user/ssl/$domain.*
  61. # Parsing domain values
  62. get_web_domain_values
  63. conf="$V_HOME/$user/conf/web/shttpd.conf"
  64. tpl_file="$V_WEBTPL/apache_$TPL.stpl"
  65. SSL_HOME="$ssl_home"
  66. # Checking ip ownership
  67. is_sys_ip_owner
  68. # Preparing domain values for the template substitution
  69. upd_web_domain_values
  70. # Adding domain to the shttpd.conf
  71. add_web_config
  72. chown root:apache $conf
  73. chmod 640 $conf
  74. # Adding certificate to user dir
  75. cp -f $V_USERS/$user/ssl/$domain.crt $V_HOME/$user/conf/web/ssl.$domain.crt
  76. cp -f $V_USERS/$user/ssl/$domain.key $V_HOME/$user/conf/web/ssl.$domain.key
  77. cp -f $V_USERS/$user/ssl/$domain.pem $V_HOME/$user/conf/web/ssl.$domain.pem
  78. if [ -e "$V_USERS/$user/ssl/$domain.ca" ]; then
  79. cp -f $V_USERS/$user/ssl/$domain.ca $V_HOME/$user/conf/web/ssl.$domain.ca
  80. fi
  81. # Running template trigger
  82. if [ -x $V_WEBTPL/apache_$template.sh ]; then
  83. $V_WEBTPL/apache_$template.sh $user $domain $ip $V_HOME $docroot
  84. fi
  85. # Checking main vesta httpd config
  86. main_conf='/etc/httpd/conf.d/vesta.conf'
  87. main_conf_check=$(grep "$conf" $main_conf )
  88. if [ -z "$main_conf_check" ]; then
  89. echo "Include $conf" >> $main_conf
  90. fi
  91. # Checking nginx
  92. if [ ! -z "$NGINX" ]; then
  93. # Adding domain to the snginx.conf
  94. conf="$V_HOME/$user/conf/web/snginx.conf"
  95. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
  96. add_web_config
  97. chown root:nginx $conf
  98. chmod 640 $conf
  99. # Checking vesta nginx config
  100. main_conf='/etc/nginx/conf.d/vesta_users.conf'
  101. main_conf_check=$(grep "$conf" $main_conf )
  102. if [ -z "$main_conf_check" ]; then
  103. echo "include $conf;" >>$main_conf
  104. fi
  105. fi
  106. #----------------------------------------------------------#
  107. # Vesta #
  108. #----------------------------------------------------------#
  109. # Increasing domain value
  110. increase_user_value "$user" '$U_WEB_SSL'
  111. # Adding ssl values
  112. update_web_domain_value '$SSL_HOME' "$SSL_HOME"
  113. update_web_domain_value '$SSL' 'yes'
  114. # Logging
  115. log_history "$V_EVENT" "v_delete_web_domain_ssl $user $domain"
  116. log_event 'system' "$V_EVENT"
  117. exit