v-add-web-domain-proxy 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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=$(idn -t --quiet -u "$2" )
  13. domain_idn=$(idn -t --quiet -a "$domain")
  14. template=$3
  15. default_extentions="jpg,jpeg,gif,png,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls,\
  16. exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav,bmp,rtf,js,mp3,avi,mpeg,flv,html,htm"
  17. extentions=${4-$default_extentions}
  18. restart="$5"
  19. # Includes
  20. source $VESTA/func/main.sh
  21. source $VESTA/func/domain.sh
  22. source $VESTA/func/ip.sh
  23. source $VESTA/conf/vesta.conf
  24. #----------------------------------------------------------#
  25. # Verifications #
  26. #----------------------------------------------------------#
  27. check_args '2' "$#" 'USER DOMAIN [TEMPLATE] [EXTENTIONS] [RESTART]'
  28. is_format_valid 'user' 'domain' 'extentions'
  29. is_system_enabled "$PROXY_SYSTEM" 'PROXY_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_object_value_empty 'web' 'DOMAIN' "$domain" '$PROXY'
  35. if [ -z $template ]; then
  36. template=$(get_user_value '$PROXY_TEMPLATE')
  37. fi
  38. is_proxy_template_valid $template
  39. #----------------------------------------------------------#
  40. # Action #
  41. #----------------------------------------------------------#
  42. # Defining domain parameters
  43. get_domain_values 'web'
  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. if [ "$restart" != 'no' ]; then
  60. $BIN/v-restart-proxy
  61. check_result $? "Proxy restart failed" >/dev/null
  62. fi
  63. log_history "enabled proxy support for $domain"
  64. log_event "$OK" "$ARGUMENTS"
  65. exit