v-add-web-domain-stats 2.9 KB

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