| SYSTEM INFORMATION | |
|---|---|
| OS type and version | Ubuntu 26.04.1 LTS |
| Webmin version | 2.660 |
| Virtualmin version | 8.1.0 GPL |
| Usermin version | 2.560 |
I’ve created a bash script for users that updates the list of databases for that user when they have created or deleted them within a 3rd party app (Phpmyadmin). Everything works fine when the user triggers the script except Webmin always reverts the user access to “Custom Commands” as disabled after using it once.
Furthermore, if I (as root admin) go into Webmin to adjust user permission and allow them to use Custom Commands again, the file permissions for all sites get misconfigured somehow because FTP stops allowing file access. This forces me to have to go into Virtualmin as root and fix file permissions for all sites.
This repeats anytime that user initiates the script.
Here is the script ( with confidential data changed ) :
# Sync databases with the username prefix created by a 3rd party script for username @ domain_name
# files must be run solely as root to work properly therefore the predefined variables are not working and must be manually adjusted to specifics
#username=$USER;
#dbpassword=$PASS;
#domain_name=$IDNDOM;
username="USERNAME";
dbpassword="DBPASSWORD";
domain_name="DOMAINNAME";
db_pattern="$username%"
count=0
declare -A db_array=()
for db in $(mysql -u "$username" -p"$dbpassword" -e "SHOW DATABASES LIKE '$db_pattern';" -s --skip-column-names | grep -Ev "information_schema|performance_schema|sys|mysql"); do
virtualmin list-databases --domain "$domain_name" --name-only 2>/dev/null | grep -xFq "$db"
if [ $? -eq 0 ]; then
echo "'$username' has access to '$db' via domain '$domain_name'."
else
((count++))
echo -e "\n"
virtualmin import-database --domain "$domain_name" --type mysql --name "$db"
echo -e "\n"
fi
db_array["$db"]="db_exists_flag"
done
if [ "$count" -eq 0 ]; then
echo -e "\nNo additional databases were found for '$username' @ '$domain_name'\n"
elif [ "$count" -eq 1 ]; then
echo -e "\nAn additional database was added to '$username' @ '$domain_name'\n"
else
echo -e "\nAn additional '$count' databases were added to '$username' @ '$domain_name'\n"
fi
virtualmin list-databases --domain "$domain_name" --type mysql --name-only 2>/dev/null | while read -r db; do
if [[ ! -v db_array[$db] ]]; then
echo -e "\n⚠️ Found orphaned database '$db' on domain '$domain_name'. Disconnecting..."
virtualmin disconnect-database --domain "$domain_name" --type mysql --name "$db"
echo "✅ Successfully disconnected '$db' from '$domain_name'."
else
echo "Detected DB: '$db'"
fi
done
The script is executed with a button via: bash /path/to/file/file.sh
Within the script itself, if I comment out the lines containing the commands: “virtualmin disconnect-database” & “virtualmin import-database” then the script will not affect any permissions. However, I would like those commands to work without changing other unintended settings.
If I set it up so that a user can use a custom command that I create, then why is it changing other settings including that very permission itself?
To clarify… these things happen in order.
When the script is executed, it changes the user permission to use/view the custom command to false/disabled. At that point the website file permissions are fine and not affected.
When I then use Webmin to give the user back that permission to use the custom commands module, it ends up altering “all” website file permissions on the server.
What is happening here?