v-update-web-domain-stat 4.1 KB

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