v_update_web_domain_stat 3.5 KB

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