v_change_web_domain_tpl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. # Parsing new template
  51. template_data=$(cat $WEBTPL/apache_$template.descr | grep -v '#')
  52. for keys in $template_data; do
  53. eval ${keys%%=*}=${keys#*=}
  54. done
  55. # Checking error log
  56. if [ "$ELOG" = 'no' ]; then
  57. elog='#'
  58. else
  59. elog=''
  60. fi
  61. # Adding domain to the httpd.conf
  62. add_web_config
  63. # Running template trigger
  64. if [ -x $WEBTPL/apache_$template.sh ]; then
  65. $WEBTPL/apache_$template.sh $user $domain $ip $HOMEDIR $docroot
  66. fi
  67. # Checking ssl
  68. if [ "$SSL" = 'yes' ]; then
  69. conf="$HOMEDIR/$user/conf/web/shttpd.conf"
  70. tpl_file="$WEBTPL/apache_$template.stpl"
  71. add_web_config
  72. # Running template trigger
  73. if [ -x $WEBTPL/apache_$template.sh ]; then
  74. $WEBTPL/apache_$template.sh \
  75. "$user" "$domain" "$ip" "$HOMEDIR" "$sdocroot"
  76. fi
  77. fi
  78. #----------------------------------------------------------#
  79. # Vesta #
  80. #----------------------------------------------------------#
  81. # Changing tpl in config
  82. update_object_value 'web' 'DOMAIN' "$domain" '$TPL' "$template"
  83. # Updating db keys
  84. for keys in $(cat $WEBTPL/apache_$template.descr|grep -v '#'); do
  85. key=$(echo "$keys"| cut -f 1 -d '=' |sed -e "s/^/\$/g")
  86. value=$(echo "$keys" |cut -f 2 -d \')
  87. update_object_value 'web' 'DOMAIN' "$domain" "$key" "$value"
  88. done
  89. # Restart web
  90. if [ "$restart" != 'no' ]; then
  91. $BIN/v_restart_web "$EVENT"
  92. fi
  93. # Logging
  94. log_history "$EVENT"
  95. log_event "$OK" "$EVENT"
  96. exit