v-change-web-domain-stats 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. # info: change web domain statistics
  3. # options: USER DOMAIN TYPE
  4. #
  5. # The function of deleting site's system of statistics. Its type is
  6. # automatically chooses from client's configuration file.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument definition
  11. user=$1
  12. domain=$(idn -t --quiet -u "$2" )
  13. domain_idn=$(idn -t --quiet -a "$domain")
  14. type=$3
  15. # Includes
  16. source $VESTA/func/main.sh
  17. source $VESTA/func/domain.sh
  18. source $VESTA/conf/vesta.conf
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. check_args '3' "$#" 'USER DOMAIN TYPE'
  23. is_format_valid 'user' 'domain'
  24. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  25. is_type_valid "$STATS_SYSTEM" "$type"
  26. is_object_valid 'user' 'USER' "$user"
  27. is_object_unsuspended 'user' 'USER' "$user"
  28. is_object_valid 'web' 'DOMAIN' "$domain"
  29. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  30. is_object_value_exist 'web' 'DOMAIN' "$domain" '$STATS'
  31. #----------------------------------------------------------#
  32. # Action #
  33. #----------------------------------------------------------#
  34. # Defining statistic type
  35. get_domain_values 'web'
  36. # Comparing stats types
  37. if [ "$STATS" == $type ]; then
  38. log_event "$OK" "$ARGUMENTS"
  39. exit 0
  40. fi
  41. # Defining statistic dir
  42. stats_dir="$HOMEDIR/$user/web/$domain/stats"
  43. # Deleting dir content
  44. rm -rf $stats_dir/*
  45. # Deleting config
  46. rm -f $HOMEDIR/$user/conf/web/$STATS.$domain.conf
  47. # Adding statistic config
  48. prepare_web_domain_values
  49. cat $WEBTPL/$type/$type.tpl |\
  50. sed -e "s/%ip%/$ip/g" \
  51. -e "s/%web_port%/$WEB_PORT/g" \
  52. -e "s/%web_system%/$WEB_SYSTEM/g" \
  53. -e "s/%web_ssl_port%/$WEB_SSL_PORT/g" \
  54. -e "s/%rgroups%/$WEB_RGROUPS/g" \
  55. -e "s/%proxy_system%/$PROXY_SYSTEM/g" \
  56. -e "s/%proxy_port%/$PROXY_PORT/g" \
  57. -e "s/%proxy_ssl_port%/$PROXY_SSL_PORT/g" \
  58. -e "s/%domain_idn%/$domain_idn/g" \
  59. -e "s/%domain%/$domain/g" \
  60. -e "s/%user%/$user/g" \
  61. -e "s/%home%/${HOMEDIR////\/}/g" \
  62. -e "s/%alias%/${aliases//,/ }/g" \
  63. -e "s/%alias_idn%/${aliases_idn//,/ }/g" \
  64. > $HOMEDIR/$user/conf/web/$type.$domain.conf
  65. if [ "$type" == 'awstats' ]; then
  66. rm -f /etc/awstats/$type.$domain_idn.conf
  67. ln -s $HOMEDIR/$user/conf/web/$type.$domain.conf \
  68. /etc/awstats/$type.$domain_idn.conf
  69. else
  70. mkdir -p /var/lib/webalizer
  71. fi
  72. #----------------------------------------------------------#
  73. # Vesta #
  74. #----------------------------------------------------------#
  75. # Update config
  76. update_object_value 'web' 'DOMAIN' "$domain" '$STATS' "$type"
  77. # Logging
  78. log_history "changed web log stats for $domain to $type"
  79. log_event "$OK" "$ARGUMENTS"
  80. # Build stats
  81. exec $BIN/v-update-web-domain-stat $user $domain
  82. exit