v_add_web_domain_nginx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/bash
  2. # info: adding web domain nginx integration
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user="$1"
  8. domain="$2"
  9. template="${3-default}"
  10. default_extentions="jpg jpeg gif png ico css zip tgz gz rar bz2 doc xls exe\
  11. pdf ppt txt tar wav bmp rtf js mp3 avi mpeg"
  12. extentions="${4-$default_extentions}"
  13. extentions=${extentions// /|} # replacing spaces with pipe char
  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] [conn]'
  23. # Checking argument format
  24. format_validation 'user' 'domain' 'template' 'extentions'
  25. # Checking web 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_domains'
  35. # Check nginx is not added
  36. is_web_domain_key_empty '$NGINX'
  37. # Checking template
  38. is_template_valid "proxy"
  39. exit
  40. #----------------------------------------------------------#
  41. # Action #
  42. #----------------------------------------------------------#
  43. # Get template name
  44. tpl_name=$(get_web_domain_value '$TPL')
  45. tpl_file="$V_WEBTPL/$package-$tpl_name.tpl"
  46. # Defining config
  47. conf="$V_HOME/$user/conf/httpd.conf"
  48. # Defining search phrase
  49. search_phrase='ServerAlias'
  50. # Defining new alias string
  51. curr_alias=$(get_web_domain_value '$ALIAS')
  52. if [ -z "$curr_alias" ]; then
  53. new_alias="$dom_alias"
  54. else
  55. new_alias="$curr_alias,$dom_alias"
  56. fi
  57. # Defining replace string
  58. str_repl=" ServerAlias ${new_alias//,/ }"
  59. # Adding alias
  60. httpd_change_config
  61. # Checking ssl domain
  62. ssl=$(get_web_domain_value '$SSL')
  63. if [ "$ssl" = 'yes' ]; then
  64. # Defining ssl template
  65. tpl_file="$V_WEBTPL/$package-$tpl_name.ssl.tpl"
  66. # Defining ssl config
  67. conf="$V_HOME/$user/conf/shttpd.conf"
  68. # Adding alias
  69. httpd_change_config
  70. fi
  71. #----------------------------------------------------------#
  72. # Vesta #
  73. #----------------------------------------------------------#
  74. # Adding new alias
  75. update_web_domain_value '$ALIAS' "$new_alias"
  76. # Adding task to the vesta pipe
  77. restart_schedule 'web'
  78. log_history "$V_EVENT" "v_del_web_domain_alias $user $domain $dom_alias"
  79. log_event 'system' "$V_EVENT"
  80. exit $OK