v_change_web_domain_tpl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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'
  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. i=1
  57. for dom_alias in ${aliases//,/ }; do
  58. dom_alias=$(idn -t --quiet -a $dom_alias)
  59. if [ "$i" -eq 1 ]; then
  60. aliases_idn="$dom_alias"
  61. else
  62. aliases_idn="$aliases_idn,$dom_alias"
  63. fi
  64. i=$((i + 1))
  65. done
  66. web_port=$(get_config_value '$WEB_PORT')
  67. email="$user@$domain"
  68. docroot="$V_HOME/$user/web/$domain/public_html"
  69. conf="$V_HOME/$user/conf/httpd.conf"
  70. tpl_file="$V_WEBTPL/apache_$template.tpl"
  71. group="$user"
  72. # Parsing template keys
  73. template_data=$(cat $V_WEBTPL/apache_$template.descr|grep -v '#')
  74. for keys in $template_data; do
  75. eval ${keys%%=*}=${keys#*=}
  76. done
  77. # Checking error log status
  78. if [ "$ELOG" = 'no' ]; then
  79. elog=' #'
  80. else
  81. elog=' '
  82. fi
  83. # Adding domain to the httpd.conf
  84. add_web_config
  85. # Running template trigger
  86. if [ -x $V_WEBTPL/apache_$template.sh ]; then
  87. $V_WEBTPL/apache_$template.sh $user $domain $ip $V_HOME $docroot
  88. fi
  89. # Checking ssl
  90. if [ ! -z "$cert" ]; then
  91. # Defining variables for ssl template replace
  92. web_ssl_port=$(get_config_value '$WEB_SSL_PORT')
  93. tpl_option=$(get_web_domain_value '$SSL_HOME')
  94. ssl_cert="$V_HOME/$user/conf/$cert.crt"
  95. ssl_key="$V_HOME/$user/conf/$cert.key"
  96. case $tpl_option in
  97. single) docroot="$V_HOME/$user/web/$domain/public_shtml" ;;
  98. *) docroot="$V_HOME/$user/web/$domain/public_html" ;;
  99. esac
  100. conf="$V_HOME/$user/conf/shttpd.conf"
  101. tpl_file="$V_WEBTPL/apache_$template.stpl"
  102. # Adding domain to the httpd.conf
  103. add_web_config
  104. # Running template trigger
  105. if [ -x $V_WEBTPL/apache_$template.sh ]; then
  106. $V_WEBTPL/apache_$template.sh \
  107. "$user" "$domain" "$ip" "$V_HOME" "$docroot"
  108. fi
  109. fi
  110. #----------------------------------------------------------#
  111. # Vesta #
  112. #----------------------------------------------------------#
  113. # Changing tpl in config
  114. update_web_domain_value '$TPL' "$template"
  115. # Updating db keys
  116. for keys in $(cat $V_WEBTPL/apache_$template.descr|grep -v '#'); do
  117. key=$(echo "$keys"| cut -f 1 -d '=' |sed -e "s/^/\$/g")
  118. value=$(echo "$keys" |cut -f 2 -d \')
  119. update_web_domain_value "$key" "$value"
  120. done
  121. # Adding task to the vesta pipe
  122. restart_schedule 'web'
  123. # Logging
  124. log_event 'system' "$V_EVENT"
  125. exit $OK