v_add_web_domain_alias 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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=$(echo $domain | tr '[:upper:]' '[:lower:]')
  14. domain_idn=$(idn -t --quiet -a "$domain")
  15. dom_alias=$(idn -t --quiet -u "$3" )
  16. dom_alias=$(echo $dom_alias | tr '[:upper:]' '[:lower:]')
  17. dom_alias_idn=$(idn -t --quiet -a "$dom_alias" )
  18. # Includes
  19. source $VESTA/conf/vesta.conf
  20. source $VESTA/func/main.sh
  21. source $VESTA/func/domain.sh
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. check_args '3' "$#" 'user domain dom_alias'
  26. validate_format 'user' 'domain' 'dom_alias'
  27. is_system_enabled "$WEB_SYSTEM"
  28. is_object_valid 'user' 'USER' "$user"
  29. is_object_unsuspended 'user' 'USER' "$user"
  30. is_object_valid 'web' 'DOMAIN' "$domain"
  31. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  32. is_domain_new 'web' "$dom_alias"
  33. is_package_full 'WEB_ALIASES'
  34. #----------------------------------------------------------#
  35. # Action #
  36. #----------------------------------------------------------#
  37. # Parsing domain values
  38. get_domain_values 'web'
  39. tpl_file="$WEBTPL/apache_$TPL.tpl"
  40. conf="$HOMEDIR/$user/conf/web/httpd.conf"
  41. # Parsing domain aliases
  42. if [ -z "$ALIAS" ]; then
  43. ALIAS="$dom_alias"
  44. else
  45. ALIAS="$ALIAS,$dom_alias"
  46. fi
  47. # Preparing domain values for the template substitution
  48. upd_web_domain_values
  49. # Recreating vhost
  50. del_web_config
  51. add_web_config
  52. if [ "$SSL" = 'yes' ]; then
  53. tpl_file="$WEBTPL/apache_$TPL.stpl"
  54. conf="$HOMEDIR/$user/conf/web/shttpd.conf"
  55. del_web_config
  56. add_web_config
  57. fi
  58. # Checking nginx
  59. if [ ! -z "$NGINX" ]; then
  60. tpl_file="$WEBTPL/ngingx_vhost_$NGINX.tpl"
  61. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  62. del_web_config
  63. add_web_config
  64. if [ "$SSL" = 'yes' ]; then
  65. proxy_string="proxy_pass https://$ip:$WEB_SSL_PORT;"
  66. tpl_file="$WEBTPL/ngingx_vhost_$NGINX.stpl"
  67. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  68. del_web_config
  69. add_web_config
  70. fi
  71. fi
  72. #----------------------------------------------------------#
  73. # Vesta #
  74. #----------------------------------------------------------#
  75. # Adding new alias
  76. update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS"
  77. # Update counters
  78. increase_user_value "$user" '$U_WEB_ALIASES'
  79. # Adding task to the vesta pipe
  80. $BIN/v_restart_web "$EVENT"
  81. log_history "$EVENT"
  82. log_event "$OK" "$EVENT"
  83. exit