v-add-web-domain-alias 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. # info: add web domain alias
  3. # options: USER DOMAIN ALIASES [RESTART]
  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 definition
  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 | sed -e 's/\.*$//g' -e 's/^\.*//g')
  17. dom_alias=$(echo $dom_alias | tr '[:upper:]' '[:lower:]')
  18. dom_alias_idn=$(idn -t --quiet -a "$dom_alias" )
  19. restart="$4"
  20. # Includes
  21. source $VESTA/func/main.sh
  22. source $VESTA/func/domain.sh
  23. source $VESTA/func/ip.sh
  24. source $VESTA/conf/vesta.conf
  25. #----------------------------------------------------------#
  26. # Verifications #
  27. #----------------------------------------------------------#
  28. check_args '3' "$#" 'USER DOMAIN ALIASES [RESTART]'
  29. is_format_valid 'user' 'domain' 'dom_alias'
  30. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  31. is_object_valid 'user' 'USER' "$user"
  32. is_object_unsuspended 'user' 'USER' "$user"
  33. is_object_valid 'web' 'DOMAIN' "$domain"
  34. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  35. is_domain_new 'web' "$dom_alias"
  36. is_package_full 'WEB_ALIASES'
  37. #----------------------------------------------------------#
  38. # Action #
  39. #----------------------------------------------------------#
  40. # Parsing domain values
  41. get_domain_values 'web'
  42. # Preparing domain values for the template substitution
  43. if [ -z "$ALIAS" ]; then
  44. ALIAS="$dom_alias"
  45. else
  46. ALIAS="$ALIAS,$dom_alias"
  47. fi
  48. prepare_web_domain_values
  49. # Rebuilding vhost
  50. del_web_config "$WEB_SYSTEM" "$TPL.tpl"
  51. add_web_config "$WEB_SYSTEM" "$TPL.tpl"
  52. if [ "$SSL" = 'yes' ]; then
  53. del_web_config "$WEB_SYSTEM" "$TPL.stpl"
  54. add_web_config "$WEB_SYSTEM" "$TPL.stpl"
  55. fi
  56. # Rebuilding proxy configuration
  57. if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
  58. del_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  59. add_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  60. if [ "$SSL" = 'yes' ]; then
  61. del_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  62. add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  63. fi
  64. fi
  65. #----------------------------------------------------------#
  66. # Vesta #
  67. #----------------------------------------------------------#
  68. # Adding new alias
  69. update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS"
  70. increase_user_value "$user" '$U_WEB_ALIASES'
  71. # Restarting web server
  72. if [ "$restart" != 'no' ]; then
  73. $BIN/v-restart-web
  74. check_result $? "Web restart failed" >/dev/null
  75. if [ ! -z "$PROXY_SYSTEM" ]; then
  76. $BIN/v-restart-proxy
  77. check_result $? "Proxy restart failed" >/dev/null
  78. fi
  79. fi
  80. log_history "added $dom_alias as alias for $domain"
  81. log_event "$OK" "$ARGUMENTS"
  82. exit