v-change-web-domain-tpl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 definition
  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. is_format_valid '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. del_web_config "$WEB_SYSTEM" "$TPL.tpl"
  40. if [ "$SSL" = 'yes' ]; then
  41. del_web_config "$WEB_SYSTEM" "$TPL.stpl"
  42. fi
  43. # Defining variables for new vhost config
  44. TPL=$template
  45. prepare_web_domain_values
  46. add_web_config "$WEB_SYSTEM" "$TPL.tpl"
  47. if [ "$SSL" = 'yes' ]; then
  48. add_web_config "$WEB_SYSTEM" "$TPL.stpl"
  49. fi
  50. #----------------------------------------------------------#
  51. # Vesta #
  52. #----------------------------------------------------------#
  53. # Changing tpl in config
  54. update_object_value 'web' 'DOMAIN' "$domain" '$TPL' "$template"
  55. # Restarting web
  56. if [ "$restart" != 'no' ]; then
  57. $BIN/v-restart-web
  58. check_result $? "Web restart failed" >/dev/null
  59. fi
  60. # Logging
  61. log_history "changed web domain template for $domain to $template" '' 'admin'
  62. log_event "$OK" "$ARGUMENTS"
  63. exit