v-change-web-domain-tpl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/bin/bash
  2. # info: change web domain template
  3. # options: USER DOMAIN TEMPLATE [RESTART]
  4. #
  5. # The function changes template of the web 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. restart=$4
  16. # Includes
  17. source $VESTA/func/main.sh
  18. source $VESTA/func/domain.sh
  19. source $VESTA/func/ip.sh
  20. source $VESTA/conf/vesta.conf
  21. #----------------------------------------------------------#
  22. # Verifications #
  23. #----------------------------------------------------------#
  24. check_args '3' "$#" 'USER DOMAIN TEMPLATE [RESTART]'
  25. validate_format 'user' 'domain' 'template'
  26. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  27. is_object_valid 'user' 'USER' "$user"
  28. is_object_unsuspended 'user' 'USER' "$user"
  29. is_object_valid 'web' 'DOMAIN' "$domain"
  30. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  31. is_web_template_valid
  32. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. # Parsing domain values
  36. get_domain_values 'web'
  37. ip=$(get_real_ip $IP)
  38. # Deleting domain
  39. tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.tpl"
  40. old_tpl=$TPL
  41. conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf"
  42. del_web_config
  43. # Deleting ssl vhost
  44. if [ "$SSL" = 'yes' ]; then
  45. tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.stpl"
  46. conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
  47. del_web_config
  48. fi
  49. # Defining variables for new vhost config
  50. upd_web_domain_values
  51. tpl_file="$WEBTPL/$WEB_SYSTEM/$template.tpl"
  52. # Adding domain to the web conf
  53. add_web_config
  54. # Running template trigger
  55. if [ -x $WEBTPL/$WEB_SYSTEM/$template.sh ]; then
  56. $WEBTPL/$WEB_SYSTEM/$template.sh $user $domain $ip $HOMEDIR $docroot
  57. fi
  58. # Checking SSL
  59. if [ "$SSL" = 'yes' ]; then
  60. conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf"
  61. tpl_file="$WEBTPL/$WEB_SYSTEM/$template.stpl"
  62. del_web_config
  63. add_web_config
  64. # Running template trigger
  65. if [ -x $WEBTPL/$WEB_SYSTEM/$template.sh ]; then
  66. $WEBTPL/$WEB_SYSTEM/$template.sh \
  67. "$user" "$domain" "$ip" "$HOMEDIR" "$sdocroot"
  68. fi
  69. fi
  70. #----------------------------------------------------------#
  71. # Vesta #
  72. #----------------------------------------------------------#
  73. # Changing tpl in config
  74. update_object_value 'web' 'DOMAIN' "$domain" '$TPL' "$template"
  75. # Restart web
  76. if [ "$restart" != 'no' ]; then
  77. $BIN/v-restart-web
  78. if [ $? -ne 0 ]; then
  79. exit E_RESTART
  80. fi
  81. fi
  82. # Logging
  83. log_history "changed web domain template for $domain to $template" '' 'admin'
  84. log_event "$OK" "$EVENT"
  85. exit