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=$2
  13. template=$3
  14. restart=$4
  15. # Includes
  16. source $VESTA/func/main.sh
  17. source $VESTA/func/domain.sh
  18. source $VESTA/func/ip.sh
  19. source $VESTA/conf/vesta.conf
  20. # Additional argument formatting
  21. format_domain
  22. format_domain_idn
  23. #----------------------------------------------------------#
  24. # Verifications #
  25. #----------------------------------------------------------#
  26. check_args '3' "$#" 'USER DOMAIN TEMPLATE [RESTART]'
  27. is_format_valid 'user' 'domain' 'template'
  28. is_system_enabled "$WEB_SYSTEM" 'WEB_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_web_template_valid "$template"
  34. #----------------------------------------------------------#
  35. # Action #
  36. #----------------------------------------------------------#
  37. # Parsing domain values
  38. get_domain_values 'web'
  39. local_ip=$(get_real_ip $IP)
  40. # Deleting domain
  41. del_web_config "$WEB_SYSTEM" "$TPL.tpl"
  42. if [ "$SSL" = 'yes' ]; then
  43. del_web_config "$WEB_SYSTEM" "$TPL.stpl"
  44. fi
  45. # Defining variables for new vhost config
  46. prepare_web_domain_values
  47. add_web_config "$WEB_SYSTEM" "$template.tpl"
  48. if [ "$SSL" = 'yes' ]; then
  49. add_web_config "$WEB_SYSTEM" "$template.stpl"
  50. fi
  51. #----------------------------------------------------------#
  52. # Vesta #
  53. #----------------------------------------------------------#
  54. # Changing tpl in config
  55. update_object_value 'web' 'DOMAIN' "$domain" '$TPL' "$template"
  56. # Restarting web
  57. $BIN/v-restart-web $restart
  58. check_result $? "Web restart failed" >/dev/null
  59. # Logging
  60. log_history "changed web domain template for $domain to $template" '' 'admin'
  61. log_event "$OK" "$ARGUMENTS"
  62. exit