v_add_web_domain_alias 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/bin/bash
  2. # info: add web domain alias
  3. # options: user domain alias
  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. # Importing variables
  19. source $VESTA/conf/vars.conf
  20. source $V_CONF/vesta.conf
  21. source $V_FUNC/shared.func
  22. source $V_FUNC/domain.func
  23. #----------------------------------------------------------#
  24. # Verifications #
  25. #----------------------------------------------------------#
  26. # Checking arg number
  27. check_args '3' "$#" 'user domain dom_alias'
  28. # Checking argument format
  29. format_validation 'user' 'domain' 'dom_alias'
  30. # Checking web system is enabled
  31. is_system_enabled 'web'
  32. # Checking user
  33. is_user_valid
  34. # Checking user is active
  35. is_user_suspended
  36. # Checking domain exist
  37. is_web_domain_valid
  38. # Checking domain is not suspened
  39. is_domain_suspended 'web'
  40. # Checking alias on the server
  41. is_domain_new 'quiet' "$dom_alias"
  42. if [ $? -ne 0 ]; then
  43. # Checking alias owner
  44. is_domain_owner "$dom_alias"
  45. # Checking alias service
  46. is_web_domain_free "$dom_alias"
  47. fi
  48. # Checking package
  49. is_package_full 'web_alias'
  50. #----------------------------------------------------------#
  51. # Action #
  52. #----------------------------------------------------------#
  53. # Parsing domain values
  54. get_web_domain_values
  55. tpl_file="$V_WEBTPL/apache_$TPL.tpl"
  56. conf="$V_HOME/$user/conf/web/httpd.conf"
  57. # Parsing domain aliases
  58. if [ -z "$ALIAS" ]; then
  59. ALIAS="$dom_alias"
  60. else
  61. ALIAS="$ALIAS,$dom_alias"
  62. fi
  63. # Preparing domain values for the template substitution
  64. upd_web_domain_values
  65. # Recreating vhost
  66. del_web_config
  67. add_web_config
  68. if [ "$SSL" = 'yes' ]; then
  69. tpl_file="$V_WEBTPL/apache_$TPL.stpl"
  70. conf="$V_HOME/$user/conf/web/shttpd.conf"
  71. del_web_config
  72. add_web_config
  73. fi
  74. # Checking nginx
  75. if [ ! -z "$NGINX" ]; then
  76. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.tpl"
  77. conf="$V_HOME/$user/conf/web/nginx.conf"
  78. del_web_config
  79. add_web_config
  80. if [ "$SSL" = 'yes' ]; then
  81. proxy_string="proxy_pass https://$ip:$WEB_SSL_PORT;"
  82. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
  83. conf="$V_HOME/$user/conf/web/snginx.conf"
  84. del_web_config
  85. add_web_config
  86. fi
  87. fi
  88. #----------------------------------------------------------#
  89. # Vesta #
  90. #----------------------------------------------------------#
  91. # Adding new alias
  92. update_web_domain_value '$ALIAS' "$ALIAS"
  93. # Adding task to the vesta pipe
  94. restart_schedule 'web'
  95. log_history "$V_EVENT" "v_delete_web_domain_alias $user $domain $dom_alias"
  96. log_event 'system' "$V_EVENT"
  97. exit