From c25fd964e1d5a604d9b6bebfb701abe8dae4090c Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Fri, 23 Sep 2011 14:14:09 +0300 Subject: [PATCH] awstats support --- bin/v_add_web_domain_stat | 29 ++++--- bin/v_upd_web_domain_stat | 131 +++++++++++++++++++++++++++++++ data/templates/awstats.tpl | 40 +++++----- data/templates/awstats_index.tpl | 10 +++ data/templates/awstats_nav.tpl | 23 ++++++ data/templates/webalizer.tpl | 2 +- 6 files changed, 200 insertions(+), 35 deletions(-) create mode 100755 bin/v_upd_web_domain_stat create mode 100644 data/templates/awstats_index.tpl create mode 100644 data/templates/awstats_nav.tpl diff --git a/bin/v_add_web_domain_stat b/bin/v_add_web_domain_stat index 3572fd00..73e39024 100755 --- a/bin/v_add_web_domain_stat +++ b/bin/v_add_web_domain_stat @@ -54,30 +54,29 @@ is_web_domain_key_empty '$STATS' # Action # #----------------------------------------------------------# +# Parse aliases +aliases=$(get_web_domain_value '$ALIAS') +aliases_idn=$(idn -t --quiet -a "$aliases") + # Adding statistic config cat $V_WEBTPL/$type.tpl |\ - sed -e "s/%ip%/$ip/g" | \ - sed -e "s/%port%/$port/g" | \ - sed -e "s/%domain_idn%/$domain_idn/g" | \ - sed -e "s/%domain%/$domain/g" | \ - sed -e "s/%user%/$user/g" | \ - sed -e "s/%home%/${V_HOME////\/}/g" | \ - sed -e "s/%alias%/$domain_aliases/g" \ ->$V_HOME/$user/conf/$type.$domain.conf + sed -e "s/%ip%/$ip/g" \ + -e "s/%port%/$port/g" \ + -e "s/%domain_idn%/$domain_idn/g" \ + -e "s/%domain%/$domain/g" \ + -e "s/%user%/$user/g" \ + -e "s/%home%/${V_HOME////\/}/g" \ + -e "s/%alias%/${aliases//,/ }/g" \ + -e "s/%alias_idn%/${aliases_idn//,/ }/g" \ + > $V_HOME/$user/conf/$type.$domain.conf #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# -# Switching on command string for pipe -case $type in - webalizer) command="webalizer -c $V_HOME/$user/conf/$type.$domain.conf";; - awstats ) command="" # FIXME awstats command;; -esac - # Adding command to pipe -echo "$command" >> $V_QUEUE/stats.pipe +echo "$V_BIN/v_upd_web_domain_stat $user $domain" >> $V_QUEUE/stats.pipe # Adding stats in config update_web_domain_value '$STATS' "$type" diff --git a/bin/v_upd_web_domain_stat b/bin/v_upd_web_domain_stat new file mode 100755 index 00000000..e336d980 --- /dev/null +++ b/bin/v_upd_web_domain_stat @@ -0,0 +1,131 @@ +#!/bin/bash +# info: updating domain web statistics + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user="$1" +domain=$(idn -t --quiet -u "$2" ) +domain_idn=$(idn -t --quiet -a "$domain") + +# Importing variables +source $VESTA/conf/vars.conf +source $V_FUNC/shared_func.sh +source $V_FUNC/domain_func.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +# Checking arg number +check_args '2' "$#" 'user domain' + +# Checking argument format +format_validation 'user' 'domain' + +# Checking web system is enabled +is_system_enabled 'web' + +# Checking user +is_user_valid + +# Checking domain exist +is_web_domain_valid + +# Checking domain is not suspened +is_domain_suspended 'web' + +# Checking stats enabled +is_web_domain_value_exist '$STATS' + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +stats=$(get_web_domain_value '$STATS') + +# Checking config +config="$V_HOME/$user/conf/$stats.$domain.conf" +if [ ! -e "$config" ]; then + echo "Error: Parsing error" + log_event 'debug' "$E_PARSE_ERROR $V_EVENT" + exit $E_PARSE_ERROR +fi + +# Checking statistics directory +dir="$V_HOME/$user/web/$domain/stats" +if [ ! -e "$dir" ]; then + mkdir -p $dir +fi + +# Defining functions +build_webalizer() { + /usr/bin/webalizer -c $config +} + +build_awstats() { + awstats="/var/www/awstats" + awstats_options="-config=$config -staticlinks -update -output" + month=$(date "+%Y-%m") + output='alldomains allhosts lasthosts unknownip allrobots lastrobots + session urldetail urlentry urlexit osdetail unknownos + browserdetail unknownbrowser refererse refererpages keyphrases + keywords errors404' + + # Checking statistics directory + if [ ! -e "$dir/$month" ]; then + mkdir -p $dir/$month + fi + + # Icon directory check + if [ ! -e "$dir/icon" ]; then + cp -r $awstats/icon $dir/ + fi + + # Creating main awstats page + $awstats/awstats.pl $awstats_options |\ + sed -e "s%awstats.$config.%%g" > $dir/$month/index.html + + # Creating suplemental awstats pages + for format in $output; do + $awstats/awstats.pl $awstats_options=$format |\ + sed -e "s%awstats.$config.%%g" > $dir/$month/$format.html + done + + # Creating index page + cat $V_WEBTPL/awstats_index.tpl | sed -e "s/%month%/$month/g" \ + > $dir/index.html + + # Creating navigation page + months=$(find $dir -type d | sed -e "s%$dir/%%g" -e "s%$dir%%g" |\ + grep -v icon | sort -r ) + for link in $months; do + select_m="$select_m\t