v_add_web_domain_alias 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/bin/bash
  2. # info: adding web domain alias
  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. dom_alias=$(idn -t --quiet -u "$3" )
  11. dom_alias_idn=$(idn -t --quiet -a "$dom_alias" )
  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. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. # Checking arg number
  21. check_args '3' "$#" 'user domain dom_alias'
  22. # Checking argument format
  23. format_validation 'user' 'domain' 'dom_alias'
  24. # Checking web system is enabled
  25. is_system_enabled 'web'
  26. # Checking user
  27. is_user_valid
  28. # Checking user is active
  29. is_user_suspended
  30. # Checking domain exist
  31. is_web_domain_valid
  32. # Checking domain is not suspened
  33. is_domain_suspended 'web'
  34. # Checking alias on the server
  35. is_domain_new 'quiet' "$dom_alias"
  36. if [ $? -ne $OK ]; then
  37. # Checking alias owner
  38. is_domain_owner "$dom_alias"
  39. # Checking alias service
  40. is_web_domain_free "$dom_alias"
  41. fi
  42. # Checking package
  43. is_package_full 'web_alias'
  44. #----------------------------------------------------------#
  45. # Action #
  46. #----------------------------------------------------------#
  47. # Parsing domain values
  48. get_web_domain_values
  49. tpl_file="$V_WEBTPL/apache_$TPL.tpl"
  50. conf="$V_HOME/$user/conf/httpd.conf"
  51. # Parsing domain aliases
  52. if [ -z "$ALIAS" ]; then
  53. ALIAS="$dom_alias"
  54. else
  55. ALIAS="$ALIAS,$dom_alias"
  56. fi
  57. # Preparing domain values for the template substitution
  58. upd_web_domain_values
  59. # Recreating vhost
  60. del_web_config
  61. add_web_config
  62. if [ "$SSL" = 'yes' ]; then
  63. tpl_file="$V_WEBTPL/apache_$TPL.stpl"
  64. conf="$V_HOME/$user/conf/shttpd.conf"
  65. del_web_config
  66. add_web_config
  67. fi
  68. # Checking nginx
  69. if [ ! -z "$NGINX" ]; then
  70. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.tpl"
  71. conf="$V_HOME/$user/conf/nginx.conf"
  72. del_web_config
  73. add_web_config
  74. if [ "$SSL" = 'yes' ]; then
  75. proxy_string="proxy_pass https://$ip:$WEB_SSL_PORT;"
  76. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
  77. conf="$V_HOME/$user/conf/snginx.conf"
  78. del_web_config
  79. add_web_config
  80. fi
  81. fi
  82. #----------------------------------------------------------#
  83. # Vesta #
  84. #----------------------------------------------------------#
  85. # Adding new alias
  86. update_web_domain_value '$ALIAS' "$ALIAS"
  87. # Adding task to the vesta pipe
  88. restart_schedule 'web'
  89. log_history "$V_EVENT" "v_del_web_domain_alias $user $domain $dom_alias"
  90. log_event 'system' "$V_EVENT"
  91. exit