v_add_web_domain_ssl 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. ssl_dir=$3
  11. ssl_home=${4-single}
  12. # Importing variables
  13. source $VESTA/conf/vars.conf
  14. source $V_CONF/vesta.conf
  15. source $V_FUNC/shared.func
  16. source $V_FUNC/domain.func
  17. source $V_FUNC/ip.func
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. # Checking arg number
  22. check_args '3' "$#" 'user domain ssl_dir [ssl_home]'
  23. # Checking argument format
  24. format_validation 'user' 'domain' 'ssl_dir'
  25. # Checking web system is enabled
  26. is_system_enabled 'web'
  27. # Checking user
  28. is_user_valid
  29. # Checking user is active
  30. is_user_suspended
  31. # Checking domain exist
  32. is_web_domain_valid
  33. # Checking domain is not suspened
  34. is_domain_suspended 'web'
  35. # Checking package
  36. is_package_full 'web_ssl'
  37. # Check ssl is not added
  38. is_web_domain_key_empty '$SSL'
  39. # Checking ssl certificate
  40. is_web_domain_cert_valid
  41. #----------------------------------------------------------#
  42. # Action #
  43. #----------------------------------------------------------#
  44. # Adding certificate to user data directory
  45. cp -f $ssl_dir/$domain.crt $V_USERS/$user/ssl/$domain.crt
  46. cp -f $ssl_dir/$domain.key $V_USERS/$user/ssl/$domain.key
  47. cp -f $ssl_dir/$domain.crt $V_USERS/$user/ssl/$domain.pem
  48. if [ -e "$ssl_dir/$domain.ca" ]; then
  49. cp -f $ssl_dir/$domain.ca $V_USERS/$user/ssl/$domain.ca
  50. cat $V_USERS/$user/ssl/$domain.ca >> $V_USERS/$user/ssl/$domain.pem
  51. fi
  52. # Parsing domain values
  53. get_web_domain_values
  54. conf="$V_HOME/$user/conf/shttpd.conf"
  55. tpl_file="$V_WEBTPL/apache_$TPL.stpl"
  56. SSL_HOME="$ssl_home"
  57. # Checking ip ownership
  58. is_sys_ip_owner
  59. # Preparing domain values for the template substitution
  60. upd_web_domain_values
  61. # Adding domain to the shttpd.conf
  62. add_web_config
  63. # Adding certificate to user dir
  64. cp -f $V_USERS/$user/ssl/$domain.crt $V_HOME/$user/conf/ssl.$domain.crt
  65. cp -f $V_USERS/$user/ssl/$domain.key $V_HOME/$user/conf/ssl.$domain.key
  66. cp -f $V_USERS/$user/ssl/$domain.pem $V_HOME/$user/conf/ssl.$domain.pem
  67. if [ -e "$V_USERS/$user/ssl/$domain.ca" ]; then
  68. cp -f $V_USERS/$user/ssl/$domain.ca $V_HOME/$user/conf/ssl.$domain.ca
  69. fi
  70. # Running template trigger
  71. if [ -x $V_WEBTPL/apache_$template.sh ]; then
  72. $V_WEBTPL/apache_$template.sh $user $domain $ip $V_HOME $docroot
  73. fi
  74. # Checking main vesta httpd config
  75. main_conf='/etc/httpd/conf.d/vesta.conf'
  76. main_conf_check=$(grep "$conf" $main_conf )
  77. if [ -z "$main_conf_check" ]; then
  78. echo "Include $conf" >> $main_conf
  79. fi
  80. # Checking nginx
  81. if [ ! -z "$NGINX" ]; then
  82. # Adding domain to the snginx.conf
  83. conf="$V_HOME/$user/conf/snginx.conf"
  84. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
  85. add_web_config
  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_web_domain_value '$SSL_HOME' "$SSL_HOME"
  100. update_web_domain_value '$SSL' 'yes'
  101. # Logging
  102. log_history "$V_EVENT" "v_del_web_domain_ssl $user $domain"
  103. log_event 'system' "$V_EVENT"
  104. exit