v-update-web-domain-stat 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/bin/bash
  2. # info: update domain statistics
  3. # options: USER DOMAIN
  4. #
  5. # The function runs log analyzer for specific webdomain.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  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. is_format_valid '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. check_result $E_NOTEXISTS "$config doesn't exist"
  36. fi
  37. # Checking statistics directory
  38. dir="$HOMEDIR/$user/web/$domain/stats"
  39. if [ ! -e "$dir" ]; then
  40. mkdir -p $dir
  41. fi
  42. # Defining functions
  43. build_webalizer() {
  44. /usr/bin/webalizer -c $config
  45. }
  46. build_awstats() {
  47. if [ -e "/etc/redhat-release" ]; then
  48. awstats="/usr/share/awstats/wwwroot/cgi-bin/awstats.pl"
  49. wwwroot="/usr/share/awstats/wwwroot"
  50. if [ ! -e "$awstats" ]; then
  51. awstats="/var/www/awstats/awstats.pl"
  52. wwwroot="/var/www/awstats"
  53. fi
  54. else
  55. awstats="/usr/lib/cgi-bin/awstats.pl"
  56. wwwroot="/usr/share/awstats"
  57. fi
  58. opts="-config=$domain_idn -staticlinks -update -output"
  59. month=$(date "+%Y-%m")
  60. output='alldomains allhosts lasthosts unknownip allrobots lastrobots
  61. urldetail urlentry urlexit osdetail browserdetail unknownbrowser
  62. unknownos refererse refererpages keyphrases keywords errors404'
  63. # Checking statistics directory
  64. if [ ! -e "$dir/$month" ]; then
  65. mkdir -p $dir/$month
  66. fi
  67. # Logo check
  68. if [ ! -e "$dir/logo.png" ]; then
  69. cp -r $VESTA/web/images/logo.png $dir/
  70. fi
  71. # Icon directory check
  72. if [ ! -e "$dir/icon" ]; then
  73. cp -r $wwwroot/icon $dir/
  74. fi
  75. # Creating main awstats page
  76. $awstats $opts | sed "s%awstats.$domain.%%g" > $dir/$month/index.html
  77. # Creating suplemental awstats pages
  78. for format in $output; do
  79. $awstats $opts=$format |\
  80. sed "s%awstats.$domain.%%g" > $dir/$month/$format.html
  81. done
  82. # Creating index page
  83. cat $WEBTPL/awstats/index.tpl | sed "s/%month%/$month/g" >\
  84. $dir/index.html
  85. # Creating navigation page
  86. months=$(find $dir -type d | sed -e "s%$dir/%%g" -e "s%$dir%%g" |\
  87. grep -v icon | sort -r )
  88. for link in $months; do
  89. year=$(echo $link |cut -f 1 -d \-)
  90. month=$(echo $link |cut -f 2 -d \-| sed -e "s/^0//")
  91. case "$month" in
  92. 1) month='January';;
  93. 2) month='February';;
  94. 3) month='March';;
  95. 4) month='April';;
  96. 5) month='May';;
  97. 6) month='June';;
  98. 7) month='July';;
  99. 8) month='August';;
  100. 9) month='September';;
  101. 10) month='October';;
  102. 11) month='November';;
  103. 12) month='December';;
  104. esac
  105. select_m="$select_m<option value=$link>$month $year<\/option>\n"
  106. done
  107. cat $WEBTPL/awstats/nav.tpl | sed "s/%select_month%/$select_m/" >\
  108. $dir/nav.html
  109. }
  110. # Switching on statistics type
  111. case $STATS in
  112. webalizer) build_webalizer ;;
  113. awstats) build_awstats ;;
  114. esac
  115. # Chown
  116. chown -R $user:$(groups $user| cut -f 3 -d ' ') $dir
  117. #----------------------------------------------------------#
  118. # Vesta #
  119. #----------------------------------------------------------#
  120. # No Logging
  121. #log_event "$OK" "$ARGUMENTS"
  122. exit