#!/bin/bash
# info: disable webdomain stats  authentication support
# options: USER DOMAIN
#
# The function removes authentication of statistics system. If the script is
# called without naming a certain user, all users will be removed. After
# deleting all of them statistics will be accessible for view without an
# authentication.


#----------------------------------------------------------#
#                    Variable&Function                     #
#----------------------------------------------------------#

# Argument defenition
user=$1
domain=$(idn -t --quiet -u "$2" )

# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf


#----------------------------------------------------------#
#                    Verifications                         #
#----------------------------------------------------------#

check_args '2' "$#" 'USER DOMAIN'
validate_format 'user' 'domain'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
is_object_value_exist 'web' 'DOMAIN' "$domain" '$STATS_USER'


#----------------------------------------------------------#
#                       Action                             #
#----------------------------------------------------------#

# Definining statistic dir
rm -f $HOMEDIR/$user/web/$domain/stats/.htpasswd
rm -f $HOMEDIR/$user/web/$domain/stats/.htaccess


#----------------------------------------------------------#
#                       Vesta                              #
#----------------------------------------------------------#

# Update config
update_object_value 'web' 'DOMAIN' "$domain" '$STATS_USER' ''
update_object_value 'web' 'DOMAIN' "$domain" '$STATS_CRYPT' ''


# Logging
log_history "disabled web stats password protection for $domain"
log_event "$OK" "$EVENT"

exit
