v-add-web-domain-stats 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. # info: add log analyzer to generate domain statitics
  3. # options: USER DOMAIN TYPE
  4. #
  5. # The call is used for enabling log analyzer system to a domain. At this time
  6. # two types of these system is supported - awstats and webalizer. For viewing
  7. # the domain statistics use http://domain.tld/vstats/ link. Access this page
  8. # is not protected by default. If you want to secure it with passwords you
  9. # should use v-add-web-domain_stat_auth script.
  10. #----------------------------------------------------------#
  11. # Variable&Function #
  12. #----------------------------------------------------------#
  13. # Argument definition
  14. user=$1
  15. domain=$2
  16. type=$3
  17. # Includes
  18. source $VESTA/func/main.sh
  19. source $VESTA/func/domain.sh
  20. source $VESTA/conf/vesta.conf
  21. # Additional argument formatting
  22. format_domain
  23. format_domain_idn
  24. #----------------------------------------------------------#
  25. # Verifications #
  26. #----------------------------------------------------------#
  27. check_args '3' "$#" 'USER DOMAIN TYPE'
  28. is_format_valid 'user' 'domain'
  29. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  30. is_type_valid "$STATS_SYSTEM" "$type"
  31. is_object_valid 'user' 'USER' "$user" "$user"
  32. is_object_unsuspended 'user' 'USER' "$user"
  33. is_object_valid 'web' 'DOMAIN' "$domain"
  34. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  35. is_object_value_empty 'web' 'DOMAIN' "$domain" '$STATS'
  36. #----------------------------------------------------------#
  37. # Action #
  38. #----------------------------------------------------------#
  39. # Parse aliases
  40. get_domain_values 'web'
  41. # Adding statistic config
  42. prepare_web_domain_values
  43. cat $WEBTPL/$type/$type.tpl |\
  44. sed -e "s|%ip%|$ip|g" \
  45. -e "s|%web_port%|$WEB_PORT|g" \
  46. -e "s|%web_system%|$WEB_SYSTEM|g" \
  47. -e "s|%web_ssl_port%|$WEB_SSL_PORT|g" \
  48. -e "s|%rgroups%|$WEB_RGROUPs|g" \
  49. -e "s|%proxy_system%|$PROXY_SYSTEM|g" \
  50. -e "s|%proxy_port%|$PROXY_PORT|g" \
  51. -e "s|%proxy_ssl_port%|$PROXY_SSL_PORT|g" \
  52. -e "s|%domain_idn%|$domain_idn|g" \
  53. -e "s|%domain%|$domain|g" \
  54. -e "s|%user%|$user|g" \
  55. -e "s|%home%|$HOMEDIR|g" \
  56. -e "s|%alias%|${aliases//,/ }|g" \
  57. -e "s|%alias_idn%|${aliases_idn//,/ }|g" \
  58. > $HOMEDIR/$user/conf/web/$type.$domain.conf
  59. if [ "$type" == 'awstats' ]; then
  60. rm -f /etc/awstats/$type.$domain_idn.conf
  61. ln -s $HOMEDIR/$user/conf/web/$type.$domain.conf \
  62. /etc/awstats/$type.$domain_idn.conf
  63. else
  64. mkdir -p /var/lib/webalizer
  65. fi
  66. #----------------------------------------------------------#
  67. # Vesta #
  68. #----------------------------------------------------------#
  69. # Schedule statistic processing
  70. echo "$BIN/v-update-web-domain-stat $user $domain" >> \
  71. $VESTA/data/queue/webstats.pipe
  72. # Update config
  73. update_object_value 'web' 'DOMAIN' "$domain" '$STATS' "$type"
  74. # Logging
  75. log_history "enabled web log analyzer for $domain"
  76. log_event "$OK" "$ARGUMENTS"
  77. # Build stats
  78. exec $BIN/v-update-web-domain-stat $user $domain
  79. exit