v-add-web-domain-alias 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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=$2
  13. aliases=$3
  14. restart="$4"
  15. # Includes
  16. source $VESTA/func/main.sh
  17. source $VESTA/func/domain.sh
  18. source $VESTA/func/ip.sh
  19. source $VESTA/conf/vesta.conf
  20. # Additional argument formatting
  21. format_domain
  22. format_domain_idn
  23. format_aliases
  24. #----------------------------------------------------------#
  25. # Verifications #
  26. #----------------------------------------------------------#
  27. check_args '3' "$#" 'USER DOMAIN ALIASES [RESTART]'
  28. is_format_valid 'user' 'domain' 'dom_alias'
  29. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  30. is_object_valid 'user' 'USER' "$user"
  31. is_object_unsuspended 'user' 'USER' "$user"
  32. is_object_valid 'web' 'DOMAIN' "$domain"
  33. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  34. is_domain_new 'web' "$aliases"
  35. is_package_full 'WEB_ALIASES'
  36. #----------------------------------------------------------#
  37. # Action #
  38. #----------------------------------------------------------#
  39. # Parsing domain values
  40. get_domain_values 'web'
  41. # Preparing domain values for the template substitution
  42. local_ip=$(get_real_ip $IP)
  43. if [ -z "$ALIAS" ]; then
  44. ALIAS="$aliases"
  45. else
  46. ALIAS="$ALIAS,$aliases"
  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. $BIN/v-restart-web $restart
  73. check_result $? "Web restart failed" >/dev/null
  74. # Restarting proxy server
  75. $BIN/v-restart-proxy $restart
  76. check_result $? "Proxy restart failed" >/dev/null
  77. log_history "added $aliases for $domain"
  78. log_event "$OK" "$ARGUMENTS"
  79. exit