v_update_web_domain_stat 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/bash
  2. # info: updating domain web statistics
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user=$1
  8. domain=$(idn -t --quiet -u "$2" )
  9. domain_idn=$(idn -t --quiet -a "$domain")
  10. # Importing variables
  11. source $VESTA/conf/vars.conf
  12. source $V_CONF/vesta.conf
  13. source $V_FUNC/shared.func
  14. source $V_FUNC/domain.func
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. # Checking arg number
  19. check_args '2' "$#" 'user domain'
  20. # Checking argument format
  21. format_validation 'user' 'domain'
  22. # Checking web system is enabled
  23. is_system_enabled 'web'
  24. # Checking user
  25. is_user_valid
  26. # Checking domain exist
  27. is_web_domain_valid
  28. # Checking domain is not suspened
  29. is_domain_suspended 'web'
  30. # Checking stats enabled
  31. is_web_domain_value_exist '$STATS'
  32. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. stats=$(get_web_domain_value '$STATS')
  36. # Checking config
  37. config="$V_HOME/$user/conf/$stats.$domain.conf"
  38. if [ ! -e "$config" ]; then
  39. echo "Error: Parsing error"
  40. log_event 'debug' "$E_PARSING $V_EVENT"
  41. exit $E_PARSING
  42. fi
  43. # Checking statistics directory
  44. dir="$V_HOME/$user/web/$domain/stats"
  45. if [ ! -e "$dir" ]; then
  46. mkdir -p $dir
  47. fi
  48. # Defining functions
  49. build_webalizer() {
  50. /usr/bin/webalizer -c $config
  51. }
  52. build_awstats() {
  53. awstats="/var/www/awstats"
  54. awstats_options="-config=$config -staticlinks -update -output"
  55. month=$(date "+%Y-%m")
  56. output='alldomains allhosts lasthosts unknownip allrobots lastrobots
  57. session urldetail urlentry urlexit osdetail unknownos
  58. browserdetail unknownbrowser refererse refererpages keyphrases
  59. keywords errors404'
  60. # Checking statistics directory
  61. if [ ! -e "$dir/$month" ]; then
  62. mkdir -p $dir/$month
  63. fi
  64. # Icon directory check
  65. if [ ! -e "$dir/icon" ]; then
  66. cp -r $awstats/icon $dir/
  67. fi
  68. # Creating main awstats page
  69. $awstats/awstats.pl $awstats_options |\
  70. sed -e "s%awstats.$config.%%g" > $dir/$month/index.html
  71. # Creating suplemental awstats pages
  72. for format in $output; do
  73. $awstats/awstats.pl $awstats_options=$format |\
  74. sed -e "s%awstats.$config.%%g" > $dir/$month/$format.html
  75. done
  76. # Creating index page
  77. cat $V_WEBTPL/awstats_index.tpl | sed -e "s/%month%/$month/g" \
  78. > $dir/index.html
  79. # Creating navigation page
  80. months=$(find $dir -type d | sed -e "s%$dir/%%g" -e "s%$dir%%g" |\
  81. grep -v icon | sort -r )
  82. for link in $months; do
  83. select_m="$select_m\t <option value=\"$link\">$link<\/option>\n"
  84. done
  85. cat $V_WEBTPL/awstats_nav.tpl | sed -e "s/%select_month%/$select_m/" \
  86. > $dir/nav.html
  87. }
  88. # Switching on statistics type
  89. case $stats in
  90. webalizer) build_webalizer ;;
  91. awstats) build_awstats ;;
  92. esac
  93. # Chown
  94. chown -R $user:$(groups $user| cut -f 3 -d ' ') $dir
  95. #----------------------------------------------------------#
  96. # Vesta #
  97. #----------------------------------------------------------#
  98. # Logging
  99. log_event 'system' "$V_EVENT"
  100. exit