mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-01-08 20:13:01 -08:00
100 lines
2.6 KiB
Bash
Executable File
100 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# info: adding web domain
|
|
|
|
#----------------------------------------------------------#
|
|
# Variable&Function #
|
|
#----------------------------------------------------------#
|
|
|
|
# Argument defenition
|
|
user="$1"
|
|
domain=$(idn -t --quiet -u "$2" )
|
|
auth_user="$3"
|
|
auth_pass="$4"
|
|
|
|
# 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 '4' "$#" 'user domain auth_user auth_password'
|
|
|
|
# Checking argument format
|
|
format_validation 'user' 'domain' 'auth_user' 'auth_pass'
|
|
|
|
# Checking web system is enabled
|
|
is_system_enabled 'web'
|
|
|
|
# Checking user
|
|
is_user_valid
|
|
|
|
# Checking user is active
|
|
is_user_suspended
|
|
|
|
# Checking domain exist
|
|
is_web_domain_valid
|
|
|
|
# Checking domain is not suspened
|
|
is_domain_suspended 'web_domains'
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Action #
|
|
#----------------------------------------------------------#
|
|
|
|
# Definining statistic dir
|
|
stat_dir="$V_HOME/$user/domains/$domain/stats"
|
|
|
|
# Adding htaccess file
|
|
if [ ! -e "$stat_dir/.htaccess" ]; then
|
|
echo "AuthUserFile $stat_dir/.htpasswd" > $stat_dir/.htaccess
|
|
echo "AuthName \"Only for admins\"" >> $stat_dir/.htaccess
|
|
echo "AuthType Basic" >> $stat_dir/.htaccess
|
|
echo "Require valid-user" >> $stat_dir/.htaccess
|
|
echo "" >> $stat_dir/.htaccess
|
|
fi
|
|
|
|
# Generating htaccess user and password
|
|
if [ ! -e "$stat_dir/.htpasswd" ]; then
|
|
htpasswd -bc $stat_dir/.htpasswd "$auth_user" "$auth_pass" >/dev/null 2>&1
|
|
else
|
|
htpasswd -b $stat_dir/.htpasswd "$auth_user" "$auth_pass" >/dev/null 2>&1
|
|
fi
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Vesta #
|
|
#----------------------------------------------------------#
|
|
|
|
# Get current value
|
|
curr_val=$(get_web_domain_value '$STATS_AUTH')
|
|
check_uniq=$(echo "$curr_val" | grep -w "$auth_user")
|
|
|
|
# Checking current users
|
|
if [ -z "$curr_val" ] || [ "$curr_val" = 'no' ]; then
|
|
a_users="$auth_user"
|
|
else
|
|
if [ -z "$check_uniq" ]; then
|
|
a_users="$curr_val,$auth_user"
|
|
else
|
|
a_users="$curr_val"
|
|
fi
|
|
fi
|
|
|
|
# Adding stats user in config
|
|
update_web_domain_value '$STATS_AUTH' "$a_users"
|
|
|
|
# Hiding password
|
|
V_EVENT=$(echo $V_EVENT | sed -e "s/$auth_pass/xxxxxx/g")
|
|
|
|
# Logging
|
|
log_history "$V_EVENT" "v_del_web_domain_stat_auth $user $domain $auth_user"
|
|
log_event 'system' "$V_EVENT"
|
|
|
|
exit $OK
|