v_add_web_domain_ssl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. # Includes
  21. source $VESTA/conf/vesta.conf
  22. source $VESTA/func/main.sh
  23. source $VESTA/func/domain.sh
  24. source $VESTA/func/ip.sh
  25. #----------------------------------------------------------#
  26. # Verifications #
  27. #----------------------------------------------------------#
  28. check_args '3' "$#" 'user domain ssl_dir [ssl_home]'
  29. validate_format 'user' 'domain' 'ssl_dir'
  30. is_system_enabled "$WEB_SYSTEM"
  31. is_object_valid 'user' 'USER' "$user"
  32. is_object_unsuspended 'user' 'USER' "$user"
  33. is_object_valid 'web' 'DOMAIN' "$domain"
  34. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  35. is_object_value_empty 'web' 'DOMAIN' "$domain" '$SSL'
  36. is_ip_owner
  37. is_web_domain_cert_valid
  38. #----------------------------------------------------------#
  39. # Action #
  40. #----------------------------------------------------------#
  41. # Adding certificate to user data directory
  42. cp -f $ssl_dir/$domain.crt $USER_DATA/ssl/$domain.crt
  43. cp -f $ssl_dir/$domain.key $USER_DATA/ssl/$domain.key
  44. cp -f $ssl_dir/$domain.crt $USER_DATA/ssl/$domain.pem
  45. if [ -e "$ssl_dir/$domain.ca" ]; then
  46. cp -f $ssl_dir/$domain.ca $USER_DATA/ssl/$domain.ca
  47. cat $USER_DATA/ssl/$domain.ca >> $USER_DATA/ssl/$domain.pem
  48. fi
  49. chmod 660 $USER_DATA/ssl/$domain.*
  50. # Parsing domain values
  51. get_domain_values 'web'
  52. conf="$HOMEDIR/$user/conf/web/shttpd.conf"
  53. tpl_file="$WEBTPL/apache_$TPL.stpl"
  54. SSL_HOME="$ssl_home"
  55. # Preparing domain values for the template substitution
  56. upd_web_domain_values
  57. # Adding domain to the shttpd.conf
  58. add_web_config
  59. chown root:apache $conf
  60. chmod 640 $conf
  61. # Adding certificate to user dir
  62. cp -f $USER_DATA/ssl/$domain.crt $HOMEDIR/$user/conf/web/ssl.$domain.crt
  63. cp -f $USER_DATA/ssl/$domain.key $HOMEDIR/$user/conf/web/ssl.$domain.key
  64. cp -f $USER_DATA/ssl/$domain.pem $HOMEDIR/$user/conf/web/ssl.$domain.pem
  65. if [ -e "$USER_DATA/ssl/$domain.ca" ]; then
  66. cp -f $USER_DATA/ssl/$domain.ca $HOMEDIR/$user/conf/web/ssl.$domain.ca
  67. fi
  68. # Running template trigger
  69. if [ -x $WEBTPL/apache_$template.sh ]; then
  70. $WEBTPL/apache_$template.sh $user $domain $ip $HOMEDIR $docroot
  71. fi
  72. # Checking main vesta httpd config
  73. main_conf='/etc/httpd/conf.d/vesta.conf'
  74. main_conf_check=$(grep "$conf" $main_conf )
  75. if [ -z "$main_conf_check" ]; then
  76. echo "Include $conf" >> $main_conf
  77. fi
  78. # Checking nginx
  79. if [ ! -z "$NGINX" ]; then
  80. # Adding domain to the snginx.conf
  81. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  82. tpl_file="$WEBTPL/ngingx_vhost_$NGINX.stpl"
  83. add_web_config
  84. chown root:nginx $conf
  85. chmod 640 $conf
  86. # Checking vesta nginx config
  87. main_conf='/etc/nginx/conf.d/vesta_users.conf'
  88. main_conf_check=$(grep "$conf" $main_conf )
  89. if [ -z "$main_conf_check" ]; then
  90. echo "include $conf;" >>$main_conf
  91. fi
  92. fi
  93. #----------------------------------------------------------#
  94. # Vesta #
  95. #----------------------------------------------------------#
  96. # Increasing domain value
  97. increase_user_value "$user" '$U_WEB_SSL'
  98. # Adding ssl values
  99. update_object_value 'web' 'DOMAIN' "$domain" '$SSL_HOME' "$SSL_HOME"
  100. update_object_value 'web' 'DOMAIN' "$domain" '$SSL' "yes"
  101. # Restart web server
  102. $BIN/v_restart_web "$EVENT"
  103. # Logging
  104. log_history "$EVENT"
  105. log_event "$OK" "$EVENT"
  106. exit