v_add_web_domain_nginx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/bash
  2. # info: adding nginx support
  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. template="${3-default}"
  11. default_extentions="jpg,jpeg,gif,png,ico,css,zip,tgz,gz,rar,bz2,doc,xls,exe,\
  12. pdf,ppt,txt,tar,wav,bmp,rtf,js,mp3,avi,mpeg,html,htm"
  13. extentions="${4-$default_extentions}"
  14. # Importing variables
  15. source $VESTA/conf/vars.conf
  16. source $V_FUNC/shared_func.sh
  17. source $V_FUNC/domain_func.sh
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. # Checking arg number
  22. check_args '2' "$#" 'user domain [template] [extentions]'
  23. # Checking argument format
  24. format_validation 'user' 'domain' 'template' 'extentions'
  25. # Checking proxy system is enabled
  26. is_system_enabled 'proxy'
  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. # Check nginx is not added
  36. is_web_domain_key_empty '$NGINX'
  37. # Checking template
  38. is_template_valid "proxy"
  39. #----------------------------------------------------------#
  40. # Action #
  41. #----------------------------------------------------------#
  42. # Defining domain parameters
  43. ip=$(get_web_domain_value '$IP')
  44. web_port=$(get_config_value '$WEB_PORT')
  45. proxy_port=$(get_config_value '$PROXY_PORT')
  46. domain_idn=$(idn -t --quiet -a "$domain")
  47. group="$user"
  48. docroot="$V_HOME/$user/web/$domain/public_html"
  49. email="$user@$domain"
  50. aliases=$(get_web_domain_value '$ALIAS')
  51. aliases_idn=$(idn -t --quiet -a "$aliases")
  52. # Checking error log status
  53. elog=$(get_web_domain_value '$ELOG')
  54. if [ "$elog" = 'no' ]; then
  55. elog=' #'
  56. else
  57. elog=' '
  58. fi
  59. # Adding domain to the nginx.conf
  60. tpl_file="$V_WEBTPL/ngingx_vhost_$template.tpl"
  61. conf="$V_HOME/$user/conf/nginx.conf"
  62. add_web_config
  63. # Checking vesta nginx config
  64. main_conf='/etc/nginx/conf.d/vesta_users.conf'
  65. main_conf_check=$(grep "$conf" $main_conf )
  66. if [ -z "$main_conf_check" ]; then
  67. echo "include $conf;" >>$main_conf
  68. fi
  69. # Checking ssl
  70. cert=$(get_web_domain_value '$SSL_CERT')
  71. if [ ! -z "$cert" ]; then
  72. # Defining certificate params
  73. ssl_cert="$V_HOME/$user/conf/$cert.crt"
  74. ssl_key="$V_HOME/$user/conf/$cert.key"
  75. tpl_option=$(get_web_domain_value '$SSL_HOME')
  76. case $tpl_option in
  77. single) docroot="$V_HOME/$user/web/$domain/public_shtml" ;;
  78. same) docroot="$V_HOME/$user/web/$domain/public_html" ;;
  79. *) check_args '3' "$#" 'user domain certificate [sslhome]'
  80. esac
  81. web_ssl_port=$(get_config_value '$WEB_SSL_PORT')
  82. proxy_ssl_port=$(get_config_value '$PROXY_SSL_PORT')
  83. # Adding domain to the snginx.conf
  84. conf="$V_HOME/$user/conf/snginx.conf"
  85. tpl_file="$V_WEBTPL/ngingx_vhost_$template.stpl"
  86. add_web_config
  87. # Checking vesta nginx config
  88. main_conf='/etc/nginx/conf.d/vesta_users.conf'
  89. main_conf_check=$(grep "$conf" $main_conf )
  90. if [ -z "$main_conf_check" ]; then
  91. echo "include $conf;" >>$main_conf
  92. fi
  93. fi
  94. #----------------------------------------------------------#
  95. # Vesta #
  96. #----------------------------------------------------------#
  97. # Adding nginx params to config
  98. update_web_domain_value '$NGINX' "$template"
  99. update_web_domain_value '$NGINX_EXT' "$extentions"
  100. # Adding task to the vesta pipe
  101. restart_schedule 'web'
  102. log_history "$V_EVENT" "v_del_web_domain_nginx $user $domain"
  103. log_event 'system' "$V_EVENT"
  104. exit $OK