v_change_web_domain_tpl 3.5 KB

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