v-add-web-domain-proxy 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 defenition
  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. validate_format '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
  39. #----------------------------------------------------------#
  40. # Action #
  41. #----------------------------------------------------------#
  42. # Defining domain parameters
  43. get_domain_values 'web'
  44. PROXY="$template"
  45. PROXY_EXT="$extentions"
  46. tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.tpl"
  47. conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf"
  48. ip=$(get_real_ip $IP)
  49. # Preparing domain values for the template substitution
  50. upd_web_domain_values
  51. add_web_config
  52. # Set permission and ownership
  53. chown root:$user $conf
  54. chmod 640 $conf
  55. # Checking proxy config
  56. proxy_conf="/etc/$PROXY_SYSTEM/conf.d/vesta.conf"
  57. if [ -z "$(grep "$conf" $proxy_conf)" ]; then
  58. echo "include $conf;" >> $proxy_conf
  59. fi
  60. # Checking ssl
  61. if [ "$SSL" = 'yes' ]; then
  62. tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.stpl"
  63. conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
  64. add_web_config
  65. chown root:$user $conf
  66. chmod 640 $conf
  67. proxy_conf="/etc/$PROXY_SYSTEM/conf.d/vesta.conf"
  68. if [ -z "$(grep "$conf" $proxy_conf)" ]; then
  69. echo "include $conf;" >> $proxy_conf
  70. fi
  71. fi
  72. # Running template trigger
  73. if [ -x $WEBTPL/$PROXY_SYSTEM/$template.sh ]; then
  74. $WEBTPL/$PROXY_SYSTEM/$template.sh $user $domain $ip $HOMEDIR $docroot
  75. fi
  76. #----------------------------------------------------------#
  77. # Vesta #
  78. #----------------------------------------------------------#
  79. # Update config
  80. update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$PROXY"
  81. update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_EXT' "$extentions"
  82. # Restart web server
  83. if [ "$restart" != 'no' ]; then
  84. $BIN/v-restart-proxy
  85. if [ $? -ne 0 ]; then
  86. exit E_RESTART
  87. fi
  88. fi
  89. log_history "enabled proxy support for $domain"
  90. log_event "$OK" "$EVENT"
  91. exit