v-add-web-domain-stats 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 defenition
  14. user=$1
  15. domain=$(idn -t --quiet -u "$2" )
  16. domain_idn=$(idn -t --quiet -a "$domain")
  17. type=$3
  18. # Includes
  19. source $VESTA/conf/vesta.conf
  20. source $VESTA/func/main.sh
  21. source $VESTA/func/domain.sh
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. check_args '3' "$#" 'user domain type'
  26. validate_format 'user' 'domain'
  27. is_system_enabled "$WEB_SYSTEM"
  28. is_type_valid "$STATS_SYSTEM" "$type"
  29. is_object_valid 'user' 'USER' "$user" "$user"
  30. is_object_unsuspended 'user' 'USER' "$user"
  31. is_object_valid 'web' 'DOMAIN' "$domain"
  32. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  33. is_object_value_empty 'web' 'DOMAIN' "$domain" '$STATS'
  34. #----------------------------------------------------------#
  35. # Action #
  36. #----------------------------------------------------------#
  37. # Parse aliases
  38. get_domain_values 'web'
  39. # Preparing domain values for the template substitution
  40. upd_web_domain_values
  41. # Adding statistic config
  42. cat $WEBTPL/$type.tpl |\
  43. sed -e "s/%ip%/$ip/g" \
  44. -e "s/%web_port%/$WEB_PORT/g" \
  45. -e "s/%web_ssl_port%/$WEB_SSL_PORT/g" \
  46. -e "s/%proxy_port%/$PROXY_PORT/g" \
  47. -e "s/%proxy_ssl_port%/$PROXY_SSL_PORT/g" \
  48. -e "s/%domain_idn%/$domain_idn/g" \
  49. -e "s/%domain%/$domain/g" \
  50. -e "s/%user%/$user/g" \
  51. -e "s/%home%/${HOMEDIR////\/}/g" \
  52. -e "s/%alias%/${aliases//,/ }/g" \
  53. -e "s/%alias_idn%/${aliases_idn//,/ }/g" \
  54. > $HOMEDIR/$user/conf/web/$type.$domain.conf
  55. if [ "$type" == 'awstats' ]; then
  56. ln -s $HOMEDIR/$user/conf/web/$type.$domain.conf /etc/awstats/
  57. fi
  58. #----------------------------------------------------------#
  59. # Vesta #
  60. #----------------------------------------------------------#
  61. # Schedule statistic processing
  62. echo "$BIN/v-update-web-domain-stat $user $domain" >> \
  63. $VESTA/data/queue/webstats.pipe
  64. # Update config
  65. update_object_value 'web' 'DOMAIN' "$domain" '$STATS' "$type"
  66. # Logging
  67. log_history "enabled web log analyzer for $domain"
  68. log_event "$OK" "$EVENT"
  69. # Build stats
  70. exec $BIN/v-update-web-domain-stat $user $domain
  71. exit