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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 defenition
  10. user=$1
  11. domain=$(idn -t --quiet -u "$2" )
  12. domain_idn=$(idn -t --quiet -a "$domain")
  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/conf/vesta.conf
  20. source $VESTA/func/main.sh
  21. source $VESTA/func/domain.sh
  22. source $VESTA/func/ip.sh
  23. #----------------------------------------------------------#
  24. # Verifications #
  25. #----------------------------------------------------------#
  26. check_args '3' "$#" 'USER DOMAIN TEMPLATE [EXTENTIONS] [RESTART]'
  27. validate_format 'user' 'domain' 'template'
  28. is_system_enabled "$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_exist 'web' 'DOMAIN' "$domain" '$PROXY'
  34. is_proxy_template_valid
  35. #----------------------------------------------------------#
  36. # Action #
  37. #----------------------------------------------------------#
  38. # Parsing domain values
  39. get_domain_values 'web'
  40. tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.tpl"
  41. conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf"
  42. ip=$(get_real_ip $IP)
  43. # Delete old vhost
  44. del_web_config
  45. # Add new vhost
  46. PROXY="$template"
  47. PROXY_EXT="$extentions"
  48. upd_web_domain_values
  49. add_web_config
  50. chown root:$user $conf
  51. chmod 640 $conf
  52. # Checking SSL
  53. if [ "$SSL" = 'yes' ]; then
  54. tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.stpl"
  55. conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
  56. del_web_config
  57. add_web_config
  58. chown root:$user $conf
  59. chmod 640 $conf
  60. fi
  61. #----------------------------------------------------------#
  62. # Vesta #
  63. #----------------------------------------------------------#
  64. # Update config
  65. update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$PROXY"
  66. update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_EXT' "$extentions"
  67. # Restart web
  68. if [ "$restart" != 'no' ]; then
  69. $BIN/v-restart-proxy
  70. fi
  71. # Logging
  72. log_history "changed proxy template for $domain to $template"
  73. log_event "$OK" "$EVENT"
  74. exit