mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-02-05 01:23:11 -08:00
75 lines
2.4 KiB
Bash
Executable File
75 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# info: add password protection to web domain statistics
|
|
# options: USER DOMAIN STATS_USER STATS_PASSWORD
|
|
#
|
|
# The call is used for securing the web statistics page.
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Variable&Function #
|
|
#----------------------------------------------------------#
|
|
|
|
# Argument definition
|
|
user=$1
|
|
domain=$2
|
|
stats_user=$3
|
|
password=$4; HIDE=4
|
|
|
|
# Includes
|
|
source $VESTA/func/main.sh
|
|
source $VESTA/func/domain.sh
|
|
source $VESTA/conf/vesta.conf
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Verifications #
|
|
#----------------------------------------------------------#
|
|
|
|
check_args '4' "$#" 'USER DOMAIN STATS_USER STATS_PASS'
|
|
is_format_valid 'user' 'domain' 'stats_user'
|
|
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_password_valid
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Action #
|
|
#----------------------------------------------------------#
|
|
|
|
# Defining statistic dir
|
|
stats_dir="$HOMEDIR/$user/web/$domain/stats"
|
|
|
|
# Adding htaccess file
|
|
if [ "$WEB_SYSTEM" = 'nginx' ]; then
|
|
echo "auth_basic \"Web Statistics\";" > $stats_dir/auth.conf
|
|
echo "auth_basic_user_file $stats_dir/.htpasswd;" >> $stats_dir/auth.conf
|
|
else
|
|
echo "AuthUserFile $stats_dir/.htpasswd" > $stats_dir/.htaccess
|
|
echo "AuthName \"Web Statistics\"" >> $stats_dir/.htaccess
|
|
echo "AuthType Basic" >> $stats_dir/.htaccess
|
|
echo "Require valid-user" >> $stats_dir/.htaccess
|
|
fi
|
|
|
|
# Generating htaccess user and password
|
|
salt=$(generate_password "$PW_MATRIX" "8")
|
|
stats_pass=$($BIN/v-generate-password-hash md5 $salt $password)
|
|
echo "$stats_user:$stats_pass" > $stats_dir/.htpasswd
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Vesta #
|
|
#----------------------------------------------------------#
|
|
|
|
# Adding stats user in config
|
|
update_object_value 'web' 'DOMAIN' "$domain" '$STATS_USER' "$stats_user"
|
|
update_object_value 'web' 'DOMAIN' "$domain" '$STATS_CRYPT' "$stats_pass"
|
|
|
|
# Logging
|
|
log_history "added password protection for web stats on $domain"
|
|
log_event "$OK" "$ARGUMENTS"
|
|
|
|
exit
|