v-update-web-domain-stat 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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=$2
  12. domain_idn=$2
  13. # Includes
  14. source $HESTIA/func/main.sh
  15. source $HESTIA/func/domain.sh
  16. source $HESTIA/conf/hestia.conf
  17. # Additional argument formatting
  18. format_domain
  19. format_domain_idn
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. check_args '2' "$#" 'USER DOMAIN'
  24. is_format_valid 'user' 'domain'
  25. is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
  26. is_object_valid 'user' 'USER' "$user"
  27. is_object_unsuspended 'user' 'USER' "$user"
  28. is_object_valid 'web' 'DOMAIN' "$domain"
  29. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  30. is_object_value_exist 'web' 'DOMAIN' "$domain" '$STATS'
  31. #----------------------------------------------------------#
  32. # Action #
  33. #----------------------------------------------------------#
  34. get_domain_values 'web'
  35. # Checking config
  36. config="$HOMEDIR/$user/conf/web/$domain/$STATS.conf"
  37. if [ ! -e "$config" ]; then
  38. check_result $E_NOTEXISTS "$config doesn't exist"
  39. fi
  40. # Checking statistics directory
  41. dir="$HOMEDIR/$user/web/$domain/stats"
  42. if [ ! -e "$dir" ]; then
  43. mkdir -p $dir
  44. fi
  45. # Defining functions
  46. build_awstats() {
  47. if [ -d "/etc/sysconfig" ]; 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.svg" ]; then
  69. cp -r $HESTIA/web/images/logo.svg $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. awstats) build_awstats ;;
  113. esac
  114. # Chown
  115. chown -R $user:$(groups $user| cut -f 3 -d ' ') $dir
  116. #----------------------------------------------------------#
  117. # Hestia #
  118. #----------------------------------------------------------#
  119. # No Logging
  120. #log_event "$OK" "$ARGUMENTS"
  121. exit