v-update-web-domain-stat 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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/func/main.sh
  15. source $VESTA/func/domain.sh
  16. source $VESTA/conf/vesta.conf
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. check_args '2' "$#" 'USER DOMAIN'
  21. validate_format 'user' 'domain'
  22. is_system_enabled "$WEB_SYSTEM" '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. if [ -e "/etc/redhat-release" ]; then
  50. awstats="/usr/share/awstats/wwwroot/cgi-bin/awstats.pl"
  51. wwwroot="/usr/share/awstats/wwwroot"
  52. if [ ! -e "$awstats" ]; then
  53. awstats="/var/www/awstats/awstats.pl"
  54. wwwroot="/var/www/awstats"
  55. fi
  56. else
  57. awstats="/usr/lib/cgi-bin/awstats.pl"
  58. wwwroot="/usr/share/awstats"
  59. fi
  60. opts="-config=$domain_idn -staticlinks -update -output"
  61. month=$(date "+%Y-%m")
  62. output='alldomains allhosts lasthosts unknownip allrobots lastrobots
  63. urldetail urlentry urlexit osdetail browserdetail unknownbrowser
  64. unknownos refererse refererpages keyphrases keywords errors404'
  65. # Checking statistics directory
  66. if [ ! -e "$dir/$month" ]; then
  67. mkdir -p $dir/$month
  68. fi
  69. # Logo check
  70. if [ ! -e "$dir/logo.png" ]; then
  71. cp -r $VESTA/web/images/logo.png $dir/
  72. fi
  73. # Icon directory check
  74. if [ ! -e "$dir/icon" ]; then
  75. cp -r $wwwroot/icon $dir/
  76. fi
  77. # Creating main awstats page
  78. $awstats $opts | sed "s%awstats.$domain.%%g" > $dir/$month/index.html
  79. # Creating suplemental awstats pages
  80. for format in $output; do
  81. $awstats $opts=$format |\
  82. sed "s%awstats.$domain.%%g" > $dir/$month/$format.html
  83. done
  84. # Creating index page
  85. cat $WEBTPL/awstats/index.tpl | sed "s/%month%/$month/g" >\
  86. $dir/index.html
  87. # Creating navigation page
  88. months=$(find $dir -type d | sed -e "s%$dir/%%g" -e "s%$dir%%g" |\
  89. grep -v icon | sort -r )
  90. for link in $months; do
  91. year=$(echo $link |cut -f 1 -d \-)
  92. month=$(echo $link |cut -f 2 -d \-| sed -e "s/^0//")
  93. case "$month" in
  94. 1) month='January';;
  95. 2) month='February';;
  96. 3) month='March';;
  97. 4) month='April';;
  98. 5) month='May';;
  99. 6) month='June';;
  100. 7) month='July';;
  101. 8) month='August';;
  102. 9) month='September';;
  103. 10) month='October';;
  104. 11) month='November';;
  105. 12) month='December';;
  106. esac
  107. select_m="$select_m<option value=$link>$month $year<\/option>\n"
  108. done
  109. cat $WEBTPL/awstats/nav.tpl | sed "s/%select_month%/$select_m/" >\
  110. $dir/nav.html
  111. }
  112. # Switching on statistics type
  113. case $STATS in
  114. webalizer) build_webalizer ;;
  115. awstats) build_awstats ;;
  116. esac
  117. # Chown
  118. chown -R $user:$(groups $user| cut -f 3 -d ' ') $dir
  119. #----------------------------------------------------------#
  120. # Vesta #
  121. #----------------------------------------------------------#
  122. # No Logging
  123. #log_event "$OK" "$EVENT"
  124. exit