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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. domain_idn=$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. # Additional argument formatting
  24. format_domain
  25. format_domain_idn
  26. # TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
  27. #----------------------------------------------------------#
  28. # Verifications #
  29. #----------------------------------------------------------#
  30. check_args '3' "$#" 'USER DOMAIN TEMPLATE [EXTENTIONS] [RESTART]'
  31. is_format_valid 'user' 'domain' 'template'
  32. is_system_enabled "$PROXY_SYSTEM" 'PROXY_SYSTEM'
  33. is_object_valid 'user' 'USER' "$user"
  34. is_object_unsuspended 'user' 'USER' "$user"
  35. is_object_valid 'web' 'DOMAIN' "$domain"
  36. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  37. is_object_value_exist 'web' 'DOMAIN' "$domain" '$PROXY'
  38. is_proxy_template_valid $template
  39. #----------------------------------------------------------#
  40. # Action #
  41. #----------------------------------------------------------#
  42. # Parsing domain values
  43. get_domain_values 'web'
  44. local_ip=$(get_real_ip $IP)
  45. # Delete old vhost
  46. del_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  47. if [ "$SSL" = 'yes' ]; then
  48. del_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  49. fi
  50. # Add new vhost
  51. PROXY="$template"
  52. PROXY_EXT="$extentions"
  53. prepare_web_domain_values
  54. add_web_config "$PROXY_SYSTEM" "$PROXY.tpl"
  55. if [ "$SSL" = 'yes' ]; then
  56. add_web_config "$PROXY_SYSTEM" "$PROXY.stpl"
  57. fi
  58. #----------------------------------------------------------#
  59. # Vesta #
  60. #----------------------------------------------------------#
  61. # Updating config
  62. update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$PROXY"
  63. update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_EXT' "$extentions"
  64. # Restarting proxy
  65. $BIN/v-restart-proxy $restart
  66. check_result $? "Proxy restart failed" >/dev/null
  67. # Logging
  68. log_history "changed proxy template for $domain to $template"
  69. log_event "$OK" "$ARGUMENTS"
  70. exit