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