v-add-web-domain-stats 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #----------------------------------------------------------#
  56. # Vesta #
  57. #----------------------------------------------------------#
  58. # Schedule statistic processing
  59. echo "$BIN/v-update-web-domain-stat $user $domain" >> \
  60. $VESTA/data/queue/webstats.pipe
  61. # Update config
  62. update_object_value 'web' 'DOMAIN' "$domain" '$STATS' "$type"
  63. # Logging
  64. log_history "enabled web log analyzer for $domain"
  65. log_event "$OK" "$EVENT"
  66. # Build stats
  67. exec $BIN/v-update-web-domain-stat $user $domain
  68. exit