v_change_web_domain_nginx_tpl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. # info: change web domain nginx template
  3. # options: user domain template [extentions] [restart]
  4. #
  5. # The function changes template of nginx.conf configuration file. The content
  6. # of webdomain directories remains untouched.
  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/conf/vesta.conf
  21. source $VESTA/func/main.sh
  22. source $VESTA/func/domain.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" '$NGINX'
  34. is_nginx_template_valid
  35. #----------------------------------------------------------#
  36. # Action #
  37. #----------------------------------------------------------#
  38. # Parsing domain values
  39. get_domain_values 'web'
  40. tpl_file="$WEBTPL/ngingx_$NGINX.tpl"
  41. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  42. # Delete old vhost
  43. del_web_config
  44. # Checking ssl
  45. if [ "$SSL" = 'yes' ]; then
  46. tpl_file="$WEBTPL/ngingx_$NGINX.stpl"
  47. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  48. del_web_config
  49. fi
  50. # Add new vhost
  51. NGINX="$template"
  52. NGINX_EXT="$extentions"
  53. tpl_file="$WEBTPL/ngingx_$NGINX.tpl"
  54. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  55. upd_web_domain_values
  56. add_web_config
  57. chown root:nginx $conf
  58. chmod 640 $conf
  59. # Checking ssl
  60. if [ "$SSL" = 'yes' ]; then
  61. tpl_file="$WEBTPL/ngingx_$NGINX.stpl"
  62. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  63. add_web_config
  64. chown root:nginx $conf
  65. chmod 640 $conf
  66. fi
  67. #----------------------------------------------------------#
  68. # Vesta #
  69. #----------------------------------------------------------#
  70. # Update config
  71. update_object_value 'web' 'DOMAIN' "$domain" '$NGINX' "$NGINX"
  72. update_object_value 'web' 'DOMAIN' "$domain" '$NGINX_EXT' "$extentions"
  73. # Restart web
  74. if [ "$restart" != 'no' ]; then
  75. $BIN/v_restart_web "$EVENT"
  76. fi
  77. # Logging
  78. log_history "$EVENT"
  79. log_event "$OK" "$EVENT"
  80. exit