v-update-web-domain-stat 4.0 KB

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