v_add_web_domain_alias 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/bin/bash
  2. # info: add web domain alias
  3. # options: user domain alias
  4. #
  5. # The call is intended for adding aliases to a domain (it is also called
  6. # "domain parking"). The function supports wildcards *.domain.tpl.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument defenition
  11. user=$1
  12. domain=$(idn -t --quiet -u "$2" )
  13. domain_idn=$(idn -t --quiet -a "$domain")
  14. dom_alias=$(idn -t --quiet -u "$3" )
  15. dom_alias_idn=$(idn -t --quiet -a "$dom_alias" )
  16. # Importing variables
  17. source $VESTA/conf/vars.conf
  18. source $V_CONF/vesta.conf
  19. source $V_FUNC/shared.func
  20. source $V_FUNC/domain.func
  21. #----------------------------------------------------------#
  22. # Verifications #
  23. #----------------------------------------------------------#
  24. # Checking arg number
  25. check_args '3' "$#" 'user domain dom_alias'
  26. # Checking argument format
  27. format_validation 'user' 'domain' 'dom_alias'
  28. # Checking web system is enabled
  29. is_system_enabled 'web'
  30. # Checking user
  31. is_user_valid
  32. # Checking user is active
  33. is_user_suspended
  34. # Checking domain exist
  35. is_web_domain_valid
  36. # Checking domain is not suspened
  37. is_domain_suspended 'web'
  38. # Checking alias on the server
  39. is_domain_new 'quiet' "$dom_alias"
  40. if [ $? -ne 0 ]; then
  41. # Checking alias owner
  42. is_domain_owner "$dom_alias"
  43. # Checking alias service
  44. is_web_domain_free "$dom_alias"
  45. fi
  46. # Checking package
  47. is_package_full 'web_alias'
  48. #----------------------------------------------------------#
  49. # Action #
  50. #----------------------------------------------------------#
  51. # Parsing domain values
  52. get_web_domain_values
  53. tpl_file="$V_WEBTPL/apache_$TPL.tpl"
  54. conf="$V_HOME/$user/conf/httpd.conf"
  55. # Parsing domain aliases
  56. if [ -z "$ALIAS" ]; then
  57. ALIAS="$dom_alias"
  58. else
  59. ALIAS="$ALIAS,$dom_alias"
  60. fi
  61. # Preparing domain values for the template substitution
  62. upd_web_domain_values
  63. # Recreating vhost
  64. del_web_config
  65. add_web_config
  66. if [ "$SSL" = 'yes' ]; then
  67. tpl_file="$V_WEBTPL/apache_$TPL.stpl"
  68. conf="$V_HOME/$user/conf/shttpd.conf"
  69. del_web_config
  70. add_web_config
  71. fi
  72. # Checking nginx
  73. if [ ! -z "$NGINX" ]; then
  74. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.tpl"
  75. conf="$V_HOME/$user/conf/nginx.conf"
  76. del_web_config
  77. add_web_config
  78. if [ "$SSL" = 'yes' ]; then
  79. proxy_string="proxy_pass https://$ip:$WEB_SSL_PORT;"
  80. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
  81. conf="$V_HOME/$user/conf/snginx.conf"
  82. del_web_config
  83. add_web_config
  84. fi
  85. fi
  86. #----------------------------------------------------------#
  87. # Vesta #
  88. #----------------------------------------------------------#
  89. # Adding new alias
  90. update_web_domain_value '$ALIAS' "$ALIAS"
  91. # Adding task to the vesta pipe
  92. restart_schedule 'web'
  93. log_history "$V_EVENT" "v_delete_web_domain_alias $user $domain $dom_alias"
  94. log_event 'system' "$V_EVENT"
  95. exit