v-add-web-domain-proxy 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. # info: add webdomain proxy support
  3. # options: USER DOMAIN [TEMPLATE] [EXTENTIONS] [RESTART]
  4. #
  5. # The function enables proxy support for a domain. This can significantly
  6. # improve website speed.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument definition
  11. user=$1
  12. domain=$2
  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 '2' "$#" 'USER DOMAIN [TEMPLATE] [EXTENTIONS] [RESTART]'
  27. is_format_valid 'user' 'domain' 'extentions'
  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_empty 'web' 'DOMAIN' "$domain" '$PROXY'
  34. if [ -z $template ]; then
  35. template=$(get_user_value '$PROXY_TEMPLATE')
  36. fi
  37. is_proxy_template_valid $template
  38. #----------------------------------------------------------#
  39. # Action #
  40. #----------------------------------------------------------#
  41. # Defining domain parameters
  42. get_domain_values 'web'
  43. prepare_web_domain_values
  44. local_ip=$(get_real_ip $IP)
  45. # Preparing domain values for the template substitution
  46. PROXY_EXT="$extentions"
  47. add_web_config "$PROXY_SYSTEM" "$template.tpl"
  48. # Adding proxy for ssl
  49. if [ "$SSL" = 'yes' ]; then
  50. add_web_config "$PROXY_SYSTEM" "$template.stpl"
  51. fi
  52. #----------------------------------------------------------#
  53. # Vesta #
  54. #----------------------------------------------------------#
  55. # Update config
  56. update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$template"
  57. update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_EXT' "$extentions"
  58. # Restarting web server
  59. $BIN/v-restart-proxy $restart
  60. check_result $? "Proxy restart failed" >/dev/null
  61. log_history "enabled proxy support for $domain"
  62. log_event "$OK" "$ARGUMENTS"
  63. exit