v-add-web-domain-alias 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. local_ip=$(get_real_ip $IP)
  44. if [ -z "$ALIAS" ]; then
  45. ALIAS="$dom_alias"
  46. else
  47. ALIAS="$ALIAS,$dom_alias"
  48. fi
  49. prepare_web_domain_values
  50. # Rebuilding vhost
  51. del_web_config "$WEB_SYSTEM" "$TPL.tpl"
  52. add_web_config "$WEB_SYSTEM" "$TPL.tpl"
  53. if [ "$SSL" = 'yes' ]; then
  54. del_web_config "$WEB_SYSTEM" "$TPL.stpl"
  55. add_web_config "$WEB_SYSTEM" "$TPL.stpl"
  56. fi
  57. # Rebuilding proxy configuration
  58. if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then
  59. del_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  60. add_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  61. if [ "$SSL" = 'yes' ]; then
  62. del_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  63. add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  64. fi
  65. fi
  66. #----------------------------------------------------------#
  67. # Vesta #
  68. #----------------------------------------------------------#
  69. # Adding new alias
  70. update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS"
  71. increase_user_value "$user" '$U_WEB_ALIASES'
  72. # Restarting web server
  73. if [ "$restart" != 'no' ]; then
  74. $BIN/v-restart-web
  75. check_result $? "Web restart failed" >/dev/null
  76. if [ ! -z "$PROXY_SYSTEM" ]; then
  77. $BIN/v-restart-proxy
  78. check_result $? "Proxy restart failed" >/dev/null
  79. fi
  80. fi
  81. log_history "added $dom_alias as alias for $domain"
  82. log_event "$OK" "$ARGUMENTS"
  83. exit