v-add-web-domain-alias 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # info: add web domain alias
  3. # options: USER DOMAIN ALIAS [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 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 | 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/conf/vesta.conf
  22. source $VESTA/func/main.sh
  23. source $VESTA/func/domain.sh
  24. #----------------------------------------------------------#
  25. # Verifications #
  26. #----------------------------------------------------------#
  27. check_args '3' "$#" 'USER DOMAIN DOM_ALIAS [RESTART]'
  28. validate_format 'user' 'domain' 'dom_alias'
  29. is_system_enabled "$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' "$dom_alias"
  35. is_package_full 'WEB_ALIASES'
  36. #----------------------------------------------------------#
  37. # Action #
  38. #----------------------------------------------------------#
  39. # Parsing domain values
  40. get_domain_values 'web'
  41. tpl_file="$WEBTPL/apache_$TPL.tpl"
  42. conf="$HOMEDIR/$user/conf/web/httpd.conf"
  43. ip=$(get_real_ip $IP)
  44. # Parsing domain aliases
  45. if [ -z "$ALIAS" ]; then
  46. ALIAS="$dom_alias"
  47. else
  48. ALIAS="$ALIAS,$dom_alias"
  49. fi
  50. # Preparing domain values for the template substitution
  51. upd_web_domain_values
  52. # Recreating vhost
  53. del_web_config
  54. add_web_config
  55. if [ "$SSL" = 'yes' ]; then
  56. tpl_file="$WEBTPL/apache_$TPL.stpl"
  57. conf="$HOMEDIR/$user/conf/web/shttpd.conf"
  58. del_web_config
  59. add_web_config
  60. fi
  61. # Checking nginx
  62. if [ ! -z "$NGINX" ]; then
  63. tpl_file="$WEBTPL/nginx_$NGINX.tpl"
  64. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  65. del_web_config
  66. add_web_config
  67. if [ "$SSL" = 'yes' ]; then
  68. tpl_file="$WEBTPL/nginx_$NGINX.stpl"
  69. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  70. del_web_config
  71. add_web_config
  72. fi
  73. fi
  74. #----------------------------------------------------------#
  75. # Vesta #
  76. #----------------------------------------------------------#
  77. # Adding new alias
  78. update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS"
  79. # Update counters
  80. increase_user_value "$user" '$U_WEB_ALIASES'
  81. # Adding task to the vesta pipe
  82. if [ "$restart" != 'no' ]; then
  83. $BIN/v-restart-web "$EVENT"
  84. fi
  85. log_history "added $dom_alias as alias for $domain"
  86. log_event "$OK" "$EVENT"
  87. exit