v-change-web-domain-proxy-tpl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. # info: change web domain proxy template
  3. # options: USER DOMAIN TEMPLATE [EXTENTIONS] [RESTART]
  4. #
  5. # The function changes proxy template
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. domain=$(idn -t --quiet -u "$2" )
  12. domain_idn=$(idn -t --quiet -a "$domain")
  13. template=$3
  14. default_extentions="jpg,jpeg,gif,png,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls,\
  15. exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav,bmp,rtf,js,mp3,avi,mpeg,flv,html,htm"
  16. extentions=${4-$default_extentions}
  17. restart="$5"
  18. # Includes
  19. source $VESTA/func/main.sh
  20. source $VESTA/func/domain.sh
  21. source $VESTA/func/ip.sh
  22. source $VESTA/conf/vesta.conf
  23. #----------------------------------------------------------#
  24. # Verifications #
  25. #----------------------------------------------------------#
  26. check_args '3' "$#" 'USER DOMAIN TEMPLATE [EXTENTIONS] [RESTART]'
  27. is_format_valid 'user' 'domain' 'template'
  28. is_system_enabled "$PROXY_SYSTEM" 'PROXY_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_object_value_exist 'web' 'DOMAIN' "$domain" '$PROXY'
  34. is_proxy_template_valid $template
  35. #----------------------------------------------------------#
  36. # Action #
  37. #----------------------------------------------------------#
  38. # Parsing domain values
  39. get_domain_values 'web'
  40. ip=$(get_real_ip $IP)
  41. # Delete old vhost
  42. del_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  43. if [ "$SSL" = 'yes' ]; then
  44. del_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  45. fi
  46. # Add new vhost
  47. PROXY="$template"
  48. PROXY_EXT="$extentions"
  49. prepare_web_domain_values
  50. add_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  51. if [ "$SSL" = 'yes' ]; then
  52. add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  53. fi
  54. #----------------------------------------------------------#
  55. # Vesta #
  56. #----------------------------------------------------------#
  57. # Updating config
  58. update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$PROXY"
  59. update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_EXT' "$extentions"
  60. # Restarting proxy
  61. if [ "$restart" != 'no' ]; then
  62. $BIN/v-restart-proxy
  63. check_result $? "Proxy restart failed" >/dev/null
  64. fi
  65. # Logging
  66. log_history "changed proxy template for $domain to $template"
  67. log_event "$OK" "$ARGUMENTS"
  68. exit