You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							110 lines
						
					
					
						
							3.3 KiB
						
					
					
				
			
		
		
	
	
							110 lines
						
					
					
						
							3.3 KiB
						
					
					
				#!/bin/bash
 | 
						|
# info: add log analyser to generate domain statistics
 | 
						|
# options: USER DOMAIN TYPE
 | 
						|
#
 | 
						|
# example: v-add-web-domain-stats admin example.com awstats
 | 
						|
#
 | 
						|
# This function is used for enabling log analyser system to a domain. For viewing
 | 
						|
# the domain statistics use <http://domain.tld/vstats/> link. Access this page
 | 
						|
# is not protected by default. If you want to secure it with passwords you
 | 
						|
# should use v-add-web-domain_stat_auth script.
 | 
						|
 | 
						|
#----------------------------------------------------------#
 | 
						|
#                Variables & Functions                     #
 | 
						|
#----------------------------------------------------------#
 | 
						|
 | 
						|
# Argument definition
 | 
						|
user=$1
 | 
						|
domain=$2
 | 
						|
domain_idn=$2
 | 
						|
type=$3
 | 
						|
 | 
						|
# Includes
 | 
						|
# shellcheck source=/etc/hestiacp/hestia.conf
 | 
						|
source /etc/hestiacp/hestia.conf
 | 
						|
# shellcheck source=/usr/local/hestia/func/main.sh
 | 
						|
source $HESTIA/func/main.sh
 | 
						|
# shellcheck source=/usr/local/hestia/func/domain.sh
 | 
						|
source $HESTIA/func/domain.sh
 | 
						|
# load config file
 | 
						|
source_conf "$HESTIA/conf/hestia.conf"
 | 
						|
 | 
						|
# Additional argument formatting
 | 
						|
format_domain
 | 
						|
format_domain_idn
 | 
						|
 | 
						|
#----------------------------------------------------------#
 | 
						|
#                    Verifications                         #
 | 
						|
#----------------------------------------------------------#
 | 
						|
 | 
						|
check_args '3' "$#" 'USER DOMAIN TYPE'
 | 
						|
is_format_valid 'user' 'domain'
 | 
						|
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
 | 
						|
is_type_valid "$STATS_SYSTEM" "$type"
 | 
						|
is_object_valid 'user' 'USER' "$user" "$user"
 | 
						|
is_object_unsuspended 'user' 'USER' "$user"
 | 
						|
is_object_valid 'web' 'DOMAIN' "$domain"
 | 
						|
is_object_unsuspended 'web' 'DOMAIN' "$domain"
 | 
						|
is_object_value_empty 'web' 'DOMAIN' "$domain" '$STATS'
 | 
						|
 | 
						|
# Perform verification if read-only mode is enabled
 | 
						|
check_hestia_demo_mode
 | 
						|
 | 
						|
#----------------------------------------------------------#
 | 
						|
#                       Action                             #
 | 
						|
#----------------------------------------------------------#
 | 
						|
 | 
						|
# Parse aliases
 | 
						|
get_domain_values 'web'
 | 
						|
 | 
						|
# Adding statistic config
 | 
						|
prepare_web_domain_values
 | 
						|
 | 
						|
if [ -z "${aliases//,/ }" ]; then
 | 
						|
	stats_alias="localhost"
 | 
						|
else
 | 
						|
	stats_alias=${aliases_idn//,/ }
 | 
						|
fi
 | 
						|
 | 
						|
cat $WEBTPL/$type/$type.tpl \
 | 
						|
	| sed -e "s|%ip%|$ip|g" \
 | 
						|
		-e "s|%web_port%|$WEB_PORT|g" \
 | 
						|
		-e "s|%web_system%|$WEB_SYSTEM|g" \
 | 
						|
		-e "s|%web_ssl_port%|$WEB_SSL_PORT|g" \
 | 
						|
		-e "s|%rgroups%|$WEB_RGROUPs|g" \
 | 
						|
		-e "s|%proxy_system%|$PROXY_SYSTEM|g" \
 | 
						|
		-e "s|%proxy_port%|$PROXY_PORT|g" \
 | 
						|
		-e "s|%proxy_ssl_port%|$PROXY_SSL_PORT|g" \
 | 
						|
		-e "s|%domain_idn%|$domain_idn|g" \
 | 
						|
		-e "s|%domain%|$domain|g" \
 | 
						|
		-e "s|%user%|$user|g" \
 | 
						|
		-e "s|%home%|$HOMEDIR|g" \
 | 
						|
		-e "s|%alias%|$stats_alias|g" \
 | 
						|
		-e "s|%alias_idn%|$stats_alias|g" \
 | 
						|
		> $HOMEDIR/$user/conf/web/$domain/$type.conf
 | 
						|
 | 
						|
if [ "$type" == 'awstats' ]; then
 | 
						|
	rm -f /etc/awstats/$type.$domain_idn.conf
 | 
						|
	ln -s $HOMEDIR/$user/conf/web/$domain/$type.conf \
 | 
						|
		/etc/awstats/$type.$domain_idn.conf
 | 
						|
fi
 | 
						|
 | 
						|
#----------------------------------------------------------#
 | 
						|
#                       Hestia                             #
 | 
						|
#----------------------------------------------------------#
 | 
						|
 | 
						|
# Schedule statistic processing
 | 
						|
echo "$BIN/v-update-web-domain-stat $user $domain" >> $HESTIA/data/queue/webstats.pipe
 | 
						|
 | 
						|
# Update config
 | 
						|
update_object_value 'web' 'DOMAIN' "$domain" '$STATS' "$type"
 | 
						|
 | 
						|
# Logging
 | 
						|
$BIN/v-log-action "$user" "Info" "Web" "Web traffic analyzer enabled (Domain: $domain)."
 | 
						|
log_event "$OK" "$ARGUMENTS"
 | 
						|
 | 
						|
# Build stats
 | 
						|
exec $BIN/v-update-web-domain-stat "$user" "$domain"
 | 
						|
 | 
						|
exit
 |