v-change-web-domain-tpl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "$template"
  32. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. # Parsing domain values
  36. get_domain_values 'web'
  37. local_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. prepare_web_domain_values
  45. add_web_config "$WEB_SYSTEM" "$template.tpl"
  46. if [ "$SSL" = 'yes' ]; then
  47. add_web_config "$WEB_SYSTEM" "$template.stpl"
  48. fi
  49. #----------------------------------------------------------#
  50. # Vesta #
  51. #----------------------------------------------------------#
  52. # Changing tpl in config
  53. update_object_value 'web' 'DOMAIN' "$domain" '$TPL' "$template"
  54. # Restarting web
  55. if [ "$restart" != 'no' ]; then
  56. $BIN/v-restart-web
  57. check_result $? "Web restart failed" >/dev/null
  58. fi
  59. # Logging
  60. log_history "changed web domain template for $domain to $template" '' 'admin'
  61. log_event "$OK" "$ARGUMENTS"
  62. exit