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