v-change-web-domain-tpl 2.8 KB

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