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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/func/main.sh
  20. source $VESTA/func/domain.sh
  21. source $VESTA/func/ip.sh
  22. source $VESTA/conf/vesta.conf
  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" '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. old_tpl=$PROXY
  42. conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf"
  43. ip=$(get_real_ip $IP)
  44. # Delete old vhost
  45. del_web_config
  46. # Add new vhost
  47. PROXY="$template"
  48. PROXY_EXT="$extentions"
  49. tpl_file="$WEBTPL/$PROXY_SYSTEM/$template.tpl"
  50. upd_web_domain_values
  51. add_web_config
  52. chown root:$user $conf
  53. chmod 640 $conf
  54. # Checking SSL
  55. if [ "$SSL" = 'yes' ]; then
  56. tpl_file="$WEBTPL/$PROXY_SYSTEM/$old_tpl.stpl"
  57. conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf"
  58. del_web_config
  59. tpl_file="$WEBTPL/$PROXY_SYSTEM/$template.stpl"
  60. add_web_config
  61. chown root:$user $conf
  62. chmod 640 $conf
  63. fi
  64. # Running template trigger
  65. if [ -x $WEBTPL/$PROXY_SYSTEM/$template.sh ]; then
  66. $WEBTPL/$PROXY_SYSTEM/$template.sh $user $domain $ip $HOMEDIR $docroot
  67. fi
  68. #----------------------------------------------------------#
  69. # Vesta #
  70. #----------------------------------------------------------#
  71. # Update config
  72. update_object_value 'web' 'DOMAIN' "$domain" '$PROXY' "$PROXY"
  73. update_object_value 'web' 'DOMAIN' "$domain" '$PROXY_EXT' "$extentions"
  74. # Restart web
  75. if [ "$restart" != 'no' ]; then
  76. $BIN/v-restart-proxy
  77. if [ $? -ne 0 ]; then
  78. exit E_RESTART
  79. fi
  80. fi
  81. # Logging
  82. log_history "changed proxy template for $domain to $template"
  83. log_event "$OK" "$EVENT"
  84. exit