v_update_web_domain_stat 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. # info: update domain statistics
  3. # options: user domain
  4. #
  5. # The function runs log analyzer for speciefic webdomain.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. domain=$(idn -t --quiet -u "$2" )
  12. domain_idn=$(idn -t --quiet -a "$domain")
  13. # Includes
  14. source $VESTA/conf/vesta.conf
  15. source $VESTA/func/main.sh
  16. source $VESTA/func/domain.sh
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. check_args '2' "$#" 'user domain'
  21. validate_format 'user' 'domain'
  22. is_system_enabled "$WEB_SYSTEM"
  23. is_object_valid 'user' 'USER' "$user"
  24. is_object_unsuspended 'user' 'USER' "$user"
  25. is_object_valid 'web' 'DOMAIN' "$domain"
  26. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  27. is_object_value_exist 'web' 'DOMAIN' "$domain" '$STATS'
  28. #----------------------------------------------------------#
  29. # Action #
  30. #----------------------------------------------------------#
  31. get_domain_values 'web'
  32. # Checking config
  33. config="$HOMEDIR/$user/conf/web/$STATS.$domain.conf"
  34. if [ ! -e "$config" ]; then
  35. echo "Error: Parsing error"
  36. log_event "$E_PARSING" "$EVENT"
  37. exit $E_PARSING
  38. fi
  39. # Checking statistics directory
  40. dir="$HOMEDIR/$user/web/$domain/stats"
  41. if [ ! -e "$dir" ]; then
  42. mkdir -p $dir
  43. fi
  44. # Defining functions
  45. build_webalizer() {
  46. /usr/bin/webalizer -c $config
  47. }
  48. build_awstats() {
  49. awstats="/var/www/awstats"
  50. awstats_options="-config=$config -staticlinks -update -output"
  51. month=$(date "+%Y-%m")
  52. output='alldomains allhosts lasthosts unknownip allrobots lastrobots
  53. session urldetail urlentry urlexit osdetail unknownos
  54. browserdetail unknownbrowser refererse refererpages keyphrases
  55. keywords errors404'
  56. # Checking statistics directory
  57. if [ ! -e "$dir/$month" ]; then
  58. mkdir -p $dir/$month
  59. fi
  60. # Icon directory check
  61. if [ ! -e "$dir/icon" ]; then
  62. cp -r $awstats/icon $dir/
  63. fi
  64. # Creating main awstats page
  65. $awstats/awstats.pl $awstats_options |\
  66. sed -e "s%awstats.$config.%%g" > $dir/$month/index.html
  67. # Creating suplemental awstats pages
  68. for format in $output; do
  69. $awstats/awstats.pl $awstats_options=$format |\
  70. sed -e "s%awstats.$config.%%g" > $dir/$month/$format.html
  71. done
  72. # Creating index page
  73. cat $WEBTPL/awstats_index.tpl | sed -e "s/%month%/$month/g" \
  74. > $dir/index.html
  75. # Creating navigation page
  76. months=$(find $dir -type d | sed -e "s%$dir/%%g" -e "s%$dir%%g" |\
  77. grep -v icon | sort -r )
  78. for link in $months; do
  79. select_m="$select_m\t <option value=\"$link\">$link<\/option>\n"
  80. done
  81. cat $WEBTPL/awstats_nav.tpl | sed -e "s/%select_month%/$select_m/" \
  82. > $dir/nav.html
  83. }
  84. # Switching on statistics type
  85. case $stats in
  86. webalizer) build_webalizer ;;
  87. awstats) build_awstats ;;
  88. esac
  89. # Chown
  90. chown -R $user:$(groups $user| cut -f 3 -d ' ') $dir
  91. #----------------------------------------------------------#
  92. # Vesta #
  93. #----------------------------------------------------------#
  94. # Logging
  95. log_event "$OK" "$EVENT"
  96. exit