v_add_web_domain_alias 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 | tr '[:upper:]' '[:lower:]')
  17. dom_alias_idn=$(idn -t --quiet -a "$dom_alias" )
  18. restart="$4"
  19. # Includes
  20. source $VESTA/conf/vesta.conf
  21. source $VESTA/func/main.sh
  22. source $VESTA/func/domain.sh
  23. #----------------------------------------------------------#
  24. # Verifications #
  25. #----------------------------------------------------------#
  26. check_args '3' "$#" 'user domain dom_alias [restart]'
  27. validate_format 'user' 'domain' 'dom_alias'
  28. is_system_enabled "$WEB_SYSTEM"
  29. is_object_valid 'user' 'USER' "$user"
  30. is_object_unsuspended 'user' 'USER' "$user"
  31. is_object_valid 'web' 'DOMAIN' "$domain"
  32. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  33. is_domain_new 'web' "$dom_alias"
  34. is_package_full 'WEB_ALIASES'
  35. #----------------------------------------------------------#
  36. # Action #
  37. #----------------------------------------------------------#
  38. # Parsing domain values
  39. get_domain_values 'web'
  40. tpl_file="$WEBTPL/apache_$TPL.tpl"
  41. conf="$HOMEDIR/$user/conf/web/httpd.conf"
  42. # Parsing domain aliases
  43. if [ -z "$ALIAS" ]; then
  44. ALIAS="$dom_alias"
  45. else
  46. ALIAS="$ALIAS,$dom_alias"
  47. fi
  48. # Preparing domain values for the template substitution
  49. upd_web_domain_values
  50. # Recreating vhost
  51. del_web_config
  52. add_web_config
  53. if [ "$SSL" = 'yes' ]; then
  54. tpl_file="$WEBTPL/apache_$TPL.stpl"
  55. conf="$HOMEDIR/$user/conf/web/shttpd.conf"
  56. del_web_config
  57. add_web_config
  58. fi
  59. # Checking nginx
  60. if [ ! -z "$NGINX" ]; then
  61. tpl_file="$WEBTPL/nginx_$NGINX.tpl"
  62. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  63. del_web_config
  64. add_web_config
  65. if [ "$SSL" = 'yes' ]; then
  66. tpl_file="$WEBTPL/nginx_$NGINX.stpl"
  67. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  68. del_web_config
  69. add_web_config
  70. fi
  71. fi
  72. #----------------------------------------------------------#
  73. # Vesta #
  74. #----------------------------------------------------------#
  75. # Adding new alias
  76. update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS"
  77. # Update counters
  78. increase_user_value "$user" '$U_WEB_ALIASES'
  79. # Adding task to the vesta pipe
  80. if [ "$restart" != 'no' ]; then
  81. $BIN/v_restart_web "$EVENT"
  82. fi
  83. log_history "$EVENT"
  84. log_event "$OK" "$EVENT"
  85. exit