v_upd_web_domain_stat 3.4 KB

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