Skip to content

Commit 0a2138f

Browse files
committed
Fix hestiacp#833 Updating single user stats should not truncate global statistics
1 parent 2908dae commit 0a2138f

File tree

1 file changed

+30
-39
lines changed

1 file changed

+30
-39
lines changed

bin/v-update-user-stats

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fi
4040
# Creating user_list
4141
if [ -z "$user" ]; then
4242
user_list=$($HESTIA/bin/v-list-sys-users plain)
43+
update_overall_stats='true'
4344
else
4445
user_list="$user"
4546
fi
@@ -91,22 +92,17 @@ for user in $user_list; do
9192

9293
# Updating user stats log
9394
stats="$USER_DATA/stats.log"
94-
if [ -e "$stats" ]; then
95-
# Checking duplicates
96-
check_month=$(grep -n "DATE='$DATE'" $stats|cut -f 1 -d :)
97-
if [ -z "$check_month" ]; then
98-
# Updating as there no duplicates
99-
echo "$s" >> $stats
100-
chmod 660 $stats
101-
else
102-
# Replacing string with new data
103-
sed -i "$check_month s/.*/$s/" $stats
104-
fi
95+
96+
# Checking duplicates
97+
check_month=$(grep --no-messages -n "DATE='$DATE'" $stats|cut -f 1 -d :)
98+
if [ -z "$check_month" ]; then
99+
# Updating as there no duplicates
100+
echo "$s" >> $stats
105101
else
106-
# Creating stats log
107-
echo "$s" >$stats
108-
chmod 660 $stats
102+
# Replacing string with new data
103+
sed -i "$check_month s/.*/$s/" $stats
109104
fi
105+
chmod 660 $stats
110106

111107
# Increase overall counters
112108
TOTAL_IP_OWNED=$((TOTAL_IP_OWNED + IP_OWNED))
@@ -131,43 +127,38 @@ for user in $user_list; do
131127

132128
done
133129

134-
# Updating overall stats
135-
stats="$HESTIA/data/users/admin/overall_stats.log"
136-
137-
s="DATE='$DATE' TIME='$TIME' PACKAGE='default' IP_OWNED='$TOTAL_IP_OWNED'"
138-
s="$s DISK_QUOTA='0' U_DISK='$TOTAL_U_DISK' U_DISK_DIRS='$TOTAL_U_DISK_DIRS'"
139-
s="$s U_DISK_WEB='$TOTAL_U_DISK_WEB' U_DISK_MAIL='$TOTAL_U_DISK_MAIL'"
140-
s="$s U_DISK_DB='$TOTAL_U_DISK_DB' BANDWIDTH='0'"
141-
s="$s U_BANDWIDTH='$TOTAL_U_BANDWIDTH' U_WEB_DOMAINS='$TOTAL_U_WEB_DOMAINS'"
142-
s="$s U_WEB_SSL='$TOTAL_U_WEB_SSL' U_WEB_ALIASES='$TOTAL_U_WEB_ALIASES'"
143-
s="$s U_DNS_DOMAINS='$TOTAL_U_DNS_DOMAINS'"
144-
s="$s U_DNS_RECORDS='$TOTAL_U_DNS_RECORDS'"
145-
s="$s U_MAIL_DOMAINS='$TOTAL_U_MAIL_DOMAINS'"
146-
s="$s U_MAIL_DKIM='$TOTAL_U_MAIL_DKIM'"
147-
s="$s U_MAIL_ACCOUNTS='$TOTAL_U_MAIL_ACCOUNTS'"
148-
s="$s U_DATABASES='$TOTAL_U_DATABASES'"
149-
s="$s U_CRON_JOBS='$TOTAL_U_CRON_JOBS' U_BACKUPS='$TOTAL_U_BACKUPS'"
150-
s="$s U_USERS='$TOTAL_USERS'"
151-
152-
if [ -e "$stats" ]; then
130+
if [ "$update_overall_stats" = 'yes' ]; then
131+
# Updating overall stats
132+
stats="$HESTIA/data/users/admin/overall_stats.log"
133+
134+
s="DATE='$DATE' TIME='$TIME' PACKAGE='default' IP_OWNED='$TOTAL_IP_OWNED'"
135+
s="$s DISK_QUOTA='0' U_DISK='$TOTAL_U_DISK' U_DISK_DIRS='$TOTAL_U_DISK_DIRS'"
136+
s="$s U_DISK_WEB='$TOTAL_U_DISK_WEB' U_DISK_MAIL='$TOTAL_U_DISK_MAIL'"
137+
s="$s U_DISK_DB='$TOTAL_U_DISK_DB' BANDWIDTH='0'"
138+
s="$s U_BANDWIDTH='$TOTAL_U_BANDWIDTH' U_WEB_DOMAINS='$TOTAL_U_WEB_DOMAINS'"
139+
s="$s U_WEB_SSL='$TOTAL_U_WEB_SSL' U_WEB_ALIASES='$TOTAL_U_WEB_ALIASES'"
140+
s="$s U_DNS_DOMAINS='$TOTAL_U_DNS_DOMAINS'"
141+
s="$s U_DNS_RECORDS='$TOTAL_U_DNS_RECORDS'"
142+
s="$s U_MAIL_DOMAINS='$TOTAL_U_MAIL_DOMAINS'"
143+
s="$s U_MAIL_DKIM='$TOTAL_U_MAIL_DKIM'"
144+
s="$s U_MAIL_ACCOUNTS='$TOTAL_U_MAIL_ACCOUNTS'"
145+
s="$s U_DATABASES='$TOTAL_U_DATABASES'"
146+
s="$s U_CRON_JOBS='$TOTAL_U_CRON_JOBS' U_BACKUPS='$TOTAL_U_BACKUPS'"
147+
s="$s U_USERS='$TOTAL_USERS'"
148+
153149
# Checking duplicates
154-
check_month=$(grep -n "DATE='$DATE'" $stats|cut -f 1 -d :)
150+
check_month=$(grep --no-messages -n "DATE='$DATE'" $stats|cut -f 1 -d :)
155151
if [ -z "$check_month" ]; then
156152
# Updating as there no duplicates
157153
echo "$s" >> $stats
158-
chmod 660 $stats
159154
else
160155
# Replacing string with new data
161156
sed -i "$check_month s/.*/$s/" $stats
162157
fi
163-
else
164-
# Creating stats log
165-
echo "$s" >$stats
166158
chmod 660 $stats
167159
fi
168160

169161

170-
171162
#----------------------------------------------------------#
172163
# Hestia #
173164
#----------------------------------------------------------#

0 commit comments

Comments
 (0)