Using 1.9.3 and I’ve just noticed that the overall statistics (/list/stats/) have stopped working since February. Single user statistics are fine, all the way up to May.
My cronjob seem to be OK:
*/5 * * * * sudo /usr/local/hestia/bin/v-update-sys-queue letsencrypt
*/5 * * * * sudo /usr/local/hestia/bin/v-update-sys-queue backup
*/5 * * * * sudo /usr/local/hestia/bin/v-update-sys-rrd
10 00 * * * sudo /usr/local/hestia/bin/v-update-sys-queue traffic
20 00 * * * sudo /usr/local/hestia/bin/v-update-user-stats
30 00 * * * sudo /usr/local/hestia/bin/v-backup-user
15 02 * * * sudo /usr/local/hestia/bin/v-update-sys-queue disk
50 02 * * * sudo /usr/local/hestia/bin/v-update-letsencrypt-ssl
55 02 * * * sudo /usr/local/hestia/bin/v-update-sys-hestia-all
30 03 * * * sudo /usr/local/hestia/bin/v-update-sys-queue webstats
10 05 * * * sudo /usr/local/hestia/bin/v-backup-users
A second server has the same problem. What am I missing ?
It’s a bug.
opened 02:47AM - 02 Apr 25 UTC
closed 08:17AM - 03 Apr 25 UTC
bug
### Describe the bug
Hi,
I was testing Hestia 1.9.3 and noticed that the overa… ll stats page was blank. After debugging, I found an issue in four scripts that handle cases where the `user` variable is empty.
I'll explain what I mean using `v-update-user-stats` as an example:
You can run the command with a user as an argument or without any arguments. The problem occurs when no user is specified. In this case, the script checks whether the `user` variable is empty. If it is, the script lists all users and sets the variable `update_overall_stats`, ensuring that the `overall_stats.log` file is updated and the overall stats are displayed in the Web UI.
```
#!/bin/bash
# info: update user statistics
# options: USER
#
# example: v-update-user-stats admin
#
# Function logs user parameters into statistics database.
#----------------------------------------------------------#
# Variables & Functions #
#----------------------------------------------------------#
# Argument definition
user=$1
# Importing system environment as we run this script
# mostly by cron wich not read it by itself
source /etc/profile.d/hestia.sh
# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# shellcheck source=/usr/local/hestia/func/domain.sh
source $HESTIA/func/domain.sh
# load config file
source_conf "$HESTIA/conf/hestia.conf"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '0' "$#" 'USER'
if [ ! -z "$user" ]; then
is_format_valid 'user'
is_object_valid 'user' 'USER' "$user"
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
if [ -z "$user" ]; then
user_list=$("$BIN/v-list-users" list)
update_overall_stats='yes'
else
user_list="$user"
fi
```
The problem is that `func/main.sh` contains the following code:
```
if [ -z "$user" ]; then
if [ -z "$ROOT_USER" ]; then
if [ -z "$HESTIA" ]; then
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
fi
source_conf "$HESTIA/conf/hestia.conf" # load config file
fi
user="$ROOT_USER"
fi
```
If the script is run without any arguments, the `user` variable is empty. When sourcing the `func/main.sh` file, it checks whether the `user` variable is empty, and if so, it assigns `$ROOT_USER` to it. As a result, in the main script, the `user` variable will never be empty because it will always be set to `$ROOT_USER`, preventing the overall stats from being updated.
Before creating a PR, I’d like to discuss the best approach to fix this. The simplest solution might be to move the assignment of the `user` variable to after sourcing `func/main.sh`, something like this:
```
#----------------------------------------------------------#
# Variables & Functions #
#----------------------------------------------------------#
# Importing system environment as we run this script
# mostly by cron wich not read it by itself
source /etc/profile.d/hestia.sh
# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# shellcheck source=/usr/local/hestia/func/domain.sh
source $HESTIA/func/domain.sh
# load config file
source_conf "$HESTIA/conf/hestia.conf"
# Argument definition
user=$1
```
I've been checking which scripts might have the same issue (attempting to perform an action when the `user` variable is empty) and have found four.
```
❯ grep -rl 'if.*-[zn].*\$user[\"\ ] ' $HESTIA/bin
/usr/local/hestia/bin/v-update-user-stats
/usr/local/hestia/bin/v-check-access-key
/usr/local/hestia/bin/v-list-access-keys
/usr/local/hestia/bin/v-update-user-counters
```
**Edit:** I've been testing it and seems `v-check-access-key` is not affected.
If you agree, I'll create a PR to move the `user` variable assignment after sourcing `main.sh`. If you have a better approach, let me know.
### Tell us how to replicate the bug
There is no need to do anything to replicate it.
### Which components are affected by this bug?
Control Panel Command Line Interface
### Hestia Control Panel Version
1.9.3
### Operating system
Ubuntu 24.04 and Debian 12
### Log capture
```shell
```
main
← sahsanu:fix-user-variable-empty
opened 12:23AM - 03 Apr 25 UTC
If you want to fix the stats now, execute this as root:
cd /usr/local/hestia/bin/
mv v-update-user-stats v-update-user-stats.original
wget https://raw.githubusercontent.com/hestiacp/hestiacp/refs/heads/main/bin/v-update-user-stats
chmod +x v-update-user-stats
1 Like