forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv_add_web_domain_stat_auth
More file actions
executable file
·103 lines (77 loc) · 2.79 KB
/
Copy pathv_add_web_domain_stat_auth
File metadata and controls
executable file
·103 lines (77 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
# info: add password protection to web domain statistics
# options: user domain auth_user auth_password
#
# The call is used for securing the web statistics page.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
domain=$(idn -t --quiet -u "$2" )
auth_user=$3
auth_pass=$4
# Importing variables
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
source $VESTA/func/domain.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '4' "$#" 'user domain auth_user auth_password'
# Checking argument format
validate_format 'user' 'domain' 'auth_user' 'auth_pass'
# Checking web system is enabled
is_system_enabled 'WEB_SYSTEM'
# Checking user
is_object_valid 'user' 'USER' "$user"
# Checking user is active
is_object_unsuspended 'user' 'USER' "$user"
# Checking domain exist
is_domain_valid 'web'
# Checking domain is not suspened
is_domain_suspended 'web'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Definining statistic dir
stat_dir="$HOMEDIR/$user/web/$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
else
htpasswd -b $stat_dir/.htpasswd "$auth_user" "$auth_pass" &>/dev/null
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Get current value
curr_val=$(get_domain_value 'web' '$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_domain_value 'web' '$STATS_AUTH' "$a_users"
# Hiding password
EVENT="$DATE $SCRIPT $user $domain $auth_user *****"
# Logging
log_history "$EVENT" "v_delete_web_domain_stat_auth $user $domain $auth_user"
log_event "$OK" "$EVENT"
exit