v_change_web_domain_tpl 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #!/bin/bash
  2. # info: change web domain template
  3. # options: user domain template
  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. # Importing variables
  16. source $VESTA/conf/vars.conf
  17. source $V_CONF/vesta.conf
  18. source $V_FUNC/shared.func
  19. source $V_FUNC/domain.func
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. # Checking arg number
  24. check_args '3' "$#" 'user domain template'
  25. # Checking argument format
  26. format_validation 'user' 'domain' 'template'
  27. # Checking web system is enabled
  28. is_system_enabled 'web'
  29. # Checking user
  30. is_user_valid
  31. # Checking user is active
  32. is_user_suspended
  33. # Checking domain exist
  34. is_web_domain_valid
  35. # Checking domain is not suspened
  36. is_domain_suspended 'web'
  37. # Checking template
  38. templates=$(get_user_value '$WEB_TPL')
  39. is_template_valid "web"
  40. #----------------------------------------------------------#
  41. # Action #
  42. #----------------------------------------------------------#
  43. # Parsing domain values
  44. get_web_domain_values
  45. # Deleting domain
  46. tpl_file="$V_WEBTPL/apache_$TPL.tpl"
  47. old_tpl=$TPL
  48. conf="$V_HOME/$user/conf/web/httpd.conf"
  49. del_web_config
  50. # Deleting ssl vhost
  51. if [ "$SSL" = 'yes' ]; then
  52. tpl_file="$V_WEBTPL/apache_$TPL.stpl"
  53. conf="$V_HOME/$user/conf/web/shttpd.conf"
  54. del_web_config
  55. fi
  56. # Defining variables for new vhost config
  57. ip=$IP
  58. email="$user@$domain"
  59. group="$user"
  60. docroot="$V_HOME/$user/web/$domain/public_html"
  61. docroot_string="DocumentRoot $docroot"
  62. conf="$V_HOME/$user/conf/web/httpd.conf"
  63. tpl_file="$V_WEBTPL/apache_$template.tpl"
  64. # Parsing domain aliases
  65. i=1
  66. j=1
  67. OLD_IFS="$IFS"
  68. IFS=','
  69. for dom_alias in $ALIAS; do
  70. dom_alias=$(idn -t --quiet -a $dom_alias)
  71. # Spliting ServerAlias lines
  72. check_8k="$server_alias $dom_alias"
  73. if [ "${#check_8k}" -ge '8100' ]; then
  74. if [ "$j" -eq 1 ]; then
  75. alias_string="ServerAlias $server_alias"
  76. else
  77. alias_string="$alias_string\n ServerAlias $server_alias"
  78. fi
  79. (( ++j))
  80. server_alias=''
  81. fi
  82. if [ "$i" -eq 1 ]; then
  83. aliases_idn="$dom_alias"
  84. server_alias="$dom_alias"
  85. alias_string="ServerAlias $server_alias"
  86. else
  87. aliases_idn="$aliases_idn,$dom_alias"
  88. server_alias="$server_alias $dom_alias"
  89. fi
  90. (( ++i))
  91. done
  92. if [ -z "$alias_string" ]; then
  93. alias_string="ServerAlias $server_alias"
  94. else
  95. if [ ! -z "$server_alias" ]; then
  96. alias_string="$alias_string\n ServerAlias $server_alias"
  97. fi
  98. fi
  99. IFS=$OLD_IFS
  100. # Parsing new template
  101. template_data=$(cat $V_WEBTPL/apache_$template.descr | grep -v '#')
  102. for keys in $template_data; do
  103. eval ${keys%%=*}=${keys#*=}
  104. done
  105. # Checking error log
  106. if [ "$ELOG" = 'no' ]; then
  107. elog='#'
  108. else
  109. elog=''
  110. fi
  111. # Adding domain to the httpd.conf
  112. add_web_config
  113. # Running template trigger
  114. if [ -x $V_WEBTPL/apache_$template.sh ]; then
  115. $V_WEBTPL/apache_$template.sh $user $domain $ip $V_HOME $docroot
  116. fi
  117. # Checking ssl
  118. if [ "$SSL" = 'yes' ]; then
  119. # Defining SSL vars
  120. ssl_crt="$V_HOME/$user/conf/web/ssl.$domain.crt"
  121. ssl_key="$V_HOME/$user/conf/web/ssl.$domain.key"
  122. ssl_pem="$V_HOME/$user/conf/web/ssl.$domain.pem"
  123. ssl_ca="$V_HOME/$user/conf/web/ssl.$domain.ca"
  124. if [ ! -e "$V_USERS/$user/web/ssl/$domain.ca" ]; then
  125. ssl_ca_str='#'
  126. fi
  127. case $SSL_HOME in
  128. single) docroot="$V_HOME/$user/web/$domain/public_shtml" ;;
  129. same) docroot="$V_HOME/$user/web/$domain/public_html" ;;
  130. esac
  131. conf="$V_HOME/$user/conf/web/shttpd.conf"
  132. tpl_file="$V_WEBTPL/apache_$template.stpl"
  133. # Adding domain to the httpd.conf
  134. add_web_config
  135. # Running template trigger
  136. if [ -x $V_WEBTPL/apache_$template.sh ]; then
  137. $V_WEBTPL/apache_$template.sh \
  138. "$user" "$domain" "$ip" "$V_HOME" "$docroot"
  139. fi
  140. fi
  141. #----------------------------------------------------------#
  142. # Vesta #
  143. #----------------------------------------------------------#
  144. # Changing tpl in config
  145. update_web_domain_value '$TPL' "$template"
  146. # Updating db keys
  147. for keys in $(cat $V_WEBTPL/apache_$template.descr|grep -v '#'); do
  148. key=$(echo "$keys"| cut -f 1 -d '=' |sed -e "s/^/\$/g")
  149. value=$(echo "$keys" |cut -f 2 -d \')
  150. update_web_domain_value "$key" "$value"
  151. done
  152. # Adding task to the vesta pipe
  153. restart_schedule 'web'
  154. # Logging
  155. log_history "$V_EVENT" "v_change_web_domain_tpl $user $domain $old_tpl"
  156. log_event 'system' "$V_EVENT"
  157. exit