v_change_web_domain_tpl 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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/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/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. conf="$V_HOME/$user/conf/httpd.conf"
  62. tpl_file="$V_WEBTPL/apache_$template.tpl"
  63. # Parsing domain aliases
  64. i=1
  65. j=1
  66. OLD_IFS="$IFS"
  67. IFS=','
  68. for dom_alias in $ALIAS; do
  69. dom_alias=$(idn -t --quiet -a $dom_alias)
  70. # Spliting ServerAlias lines
  71. check_8k="$server_alias $dom_alias"
  72. if [ "${#check_8k}" -ge '8100' ]; then
  73. if [ "$j" -eq 1 ]; then
  74. alias_string="ServerAlias $server_alias"
  75. else
  76. alias_string="$alias_string\n ServerAlias $server_alias"
  77. fi
  78. (( ++j))
  79. server_alias=''
  80. fi
  81. if [ "$i" -eq 1 ]; then
  82. aliases_idn="$dom_alias"
  83. server_alias="$dom_alias"
  84. alias_string="ServerAlias $server_alias"
  85. else
  86. aliases_idn="$aliases_idn,$dom_alias"
  87. server_alias="$server_alias $dom_alias"
  88. fi
  89. (( ++i))
  90. done
  91. if [ -z "$alias_string" ]; then
  92. alias_string="ServerAlias $server_alias"
  93. else
  94. if [ ! -z "$server_alias" ]; then
  95. alias_string="$alias_string\n ServerAlias $server_alias"
  96. fi
  97. fi
  98. IFS=$OLD_IFS
  99. # Parsing new template
  100. template_data=$(cat $V_WEBTPL/apache_$template.descr | grep -v '#')
  101. for keys in $template_data; do
  102. eval ${keys%%=*}=${keys#*=}
  103. done
  104. # Checking error log
  105. if [ "$ELOG" = 'no' ]; then
  106. elog='#'
  107. else
  108. elog=''
  109. fi
  110. # Adding domain to the httpd.conf
  111. add_web_config
  112. # Running template trigger
  113. if [ -x $V_WEBTPL/apache_$template.sh ]; then
  114. $V_WEBTPL/apache_$template.sh $user $domain $ip $V_HOME $docroot
  115. fi
  116. # Checking ssl
  117. if [ "$SSL" = 'yes' ]; then
  118. # Defining SSL vars
  119. ssl_crt="$V_HOME/$user/conf/ssl.$domain.crt"
  120. ssl_key="$V_HOME/$user/conf/ssl.$domain.key"
  121. ssl_pem="$V_HOME/$user/conf/ssl.$domain.pem"
  122. ssl_ca="$V_HOME/$user/conf/ssl.$domain.ca"
  123. if [ ! -e "$V_USERS/$user/ssl/$domain.ca" ]; then
  124. ssl_ca_str='#'
  125. fi
  126. case $SSL_HOME in
  127. single) docroot="$V_HOME/$user/web/$domain/public_shtml" ;;
  128. same) docroot="$V_HOME/$user/web/$domain/public_html" ;;
  129. esac
  130. conf="$V_HOME/$user/conf/shttpd.conf"
  131. tpl_file="$V_WEBTPL/apache_$template.stpl"
  132. # Adding domain to the httpd.conf
  133. add_web_config
  134. # Running template trigger
  135. if [ -x $V_WEBTPL/apache_$template.sh ]; then
  136. $V_WEBTPL/apache_$template.sh \
  137. "$user" "$domain" "$ip" "$V_HOME" "$docroot"
  138. fi
  139. fi
  140. #----------------------------------------------------------#
  141. # Vesta #
  142. #----------------------------------------------------------#
  143. # Changing tpl in config
  144. update_web_domain_value '$TPL' "$template"
  145. # Updating db keys
  146. for keys in $(cat $V_WEBTPL/apache_$template.descr|grep -v '#'); do
  147. key=$(echo "$keys"| cut -f 1 -d '=' |sed -e "s/^/\$/g")
  148. value=$(echo "$keys" |cut -f 2 -d \')
  149. update_web_domain_value "$key" "$value"
  150. done
  151. # Adding task to the vesta pipe
  152. restart_schedule 'web'
  153. # Logging
  154. log_history "$V_EVENT" "v_change_web_domain_tpl $user $domain $old_tpl"
  155. log_event 'system' "$V_EVENT"
  156. exit