v-add-web-domain-alias 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. # Parsing domain aliases
  44. if [ -z "$ALIAS" ]; then
  45. ALIAS="$dom_alias"
  46. else
  47. ALIAS="$ALIAS,$dom_alias"
  48. fi
  49. # Preparing domain values for the template substitution
  50. upd_web_domain_values
  51. # Recreating vhost
  52. del_web_config
  53. add_web_config
  54. if [ "$SSL" = 'yes' ]; then
  55. tpl_file="$WEBTPL/apache_$TPL.stpl"
  56. conf="$HOMEDIR/$user/conf/web/shttpd.conf"
  57. del_web_config
  58. add_web_config
  59. fi
  60. # Checking nginx
  61. if [ ! -z "$NGINX" ]; then
  62. tpl_file="$WEBTPL/nginx_$NGINX.tpl"
  63. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  64. del_web_config
  65. add_web_config
  66. if [ "$SSL" = 'yes' ]; then
  67. tpl_file="$WEBTPL/nginx_$NGINX.stpl"
  68. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  69. del_web_config
  70. add_web_config
  71. fi
  72. fi
  73. #----------------------------------------------------------#
  74. # Vesta #
  75. #----------------------------------------------------------#
  76. # Adding new alias
  77. update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS"
  78. # Update counters
  79. increase_user_value "$user" '$U_WEB_ALIASES'
  80. # Adding task to the vesta pipe
  81. if [ "$restart" != 'no' ]; then
  82. $BIN/v-restart-web "$EVENT"
  83. fi
  84. log_history "added $dom_alias as alias for $domain"
  85. log_event "$OK" "$EVENT"
  86. exit