v_change_web_domain_tpl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/bin/bash
  2. # info: changing domain template
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user="$1"
  8. domain=$(idn -t --quiet -u "$2" )
  9. domain_idn=$(idn -t --quiet -a "$domain")
  10. template="$3"
  11. # Importing variables
  12. source $VESTA/conf/vars.conf
  13. source $V_FUNC/shared_func.sh
  14. source $V_FUNC/domain_func.sh
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. # Checking arg number
  19. check_args '3' "$#" 'user domain template'
  20. # Checking argument format
  21. format_validation 'user' 'domain' 'template'
  22. # Checking web system is enabled
  23. is_system_enabled 'web'
  24. # Checking user
  25. is_user_valid
  26. # Checking user is active
  27. is_user_suspended
  28. # Checking domain exist
  29. is_web_domain_valid
  30. # Checking domain is not suspened
  31. is_domain_suspended 'web_domains'
  32. # Checking template
  33. templates=$(get_user_value '$WEB_TPL')
  34. is_template_valid "web"
  35. #----------------------------------------------------------#
  36. # Action #
  37. #----------------------------------------------------------#
  38. # Get template name
  39. tpl_name=$(get_web_domain_value '$TPL')
  40. tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
  41. conf="$V_HOME/$user/conf/httpd.conf"
  42. # Deleting domain
  43. del_web_config
  44. # Checking ssl
  45. cert=$(get_web_domain_value '$SSL_CERT')
  46. if [ ! -z "$cert" ]; then
  47. # Get tpl
  48. tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
  49. conf="$V_HOME/$user/conf/shttpd.conf"
  50. # Deleting domain
  51. del_web_config
  52. fi
  53. # Defining variables for template replace
  54. ip=$(get_web_domain_value '$IP')
  55. aliases=$(get_web_domain_value '$ALIAS')
  56. aliases_idn=$(idn -t --quiet -a "$aliases")
  57. web_port=$(get_config_value '$WEB_PORT')
  58. email="$user@$domain"
  59. docroot="$V_HOME/$user/domains/$domain/public_html"
  60. conf="$V_HOME/$user/conf/httpd.conf"
  61. tpl_file="$V_WEBTPL/apache_$template.tpl"
  62. group="$user"
  63. # Parsing template keys
  64. template_data=$(cat $V_WEBTPL/apache_$template.descr|grep -v '#')
  65. for keys in $template_data; do
  66. eval ${keys%%=*}=${keys#*=}
  67. done
  68. # Checking error log status
  69. if [ "$ELOG" = 'no' ]; then
  70. elog=' #'
  71. else
  72. elog=' '
  73. fi
  74. # Adding domain to the httpd.conf
  75. add_web_config
  76. # Running template trigger
  77. if [ -x $V_WEBTPL/apache_$template.sh ]; then
  78. $V_WEBTPL/apache_$template.sh $user $domain $ip $V_HOME $docroot
  79. fi
  80. # Checking ssl
  81. if [ ! -z "$cert" = 'yes' ]; then
  82. # Defining variables for ssl template replace
  83. web_ssl_port=$(get_config_value '$WEB_SSL_PORT')
  84. tpl_option=$(get_web_domain_value '$SSL_HOME')
  85. ssl_cert="$V_HOME/$user/conf/$cert.crt"
  86. ssl_key="$V_HOME/$user/conf/$cert.key"
  87. case $tpl_option in
  88. single) docroot="$V_HOME/$user/domains/$domain/public_shtml" ;;
  89. *) docroot="$V_HOME/$user/domains/$domain/public_html" ;;
  90. esac
  91. conf="$V_HOME/$user/conf/shttpd.conf"
  92. tpl_file="$V_WEBTPL/apache_$template.stpl"
  93. # Adding domain to the httpd.conf
  94. add_web_config
  95. # Running template trigger
  96. if [ -x $V_WEBTPL/apache_$template.sh ]; then
  97. $V_WEBTPL/apache_$template.sh \
  98. "$user" "$domain" "$ip" "$V_HOME" "$docroot"
  99. fi
  100. fi
  101. #----------------------------------------------------------#
  102. # Vesta #
  103. #----------------------------------------------------------#
  104. # Changing tpl in config
  105. update_web_domain_value '$TPL' "$template"
  106. # Updating db keys
  107. for keys in $(cat $V_WEBTPL/apache_$template.descr|grep -v '#'); do
  108. key=$(echo "$keys"| cut -f 1 -d '=' |sed -e "s/^/\$/g")
  109. value=$(echo "$keys" |cut -f 2 -d \')
  110. update_web_domain_value "$key" "$value"
  111. done
  112. # Adding task to the vesta pipe
  113. restart_schedule 'web'
  114. # Logging
  115. log_event 'system' "$V_EVENT"
  116. exit $OK