Fix get_plesk_user_domains() to have fallback when MySQL fails
Issue: get_plesk_user_domains() only tried MySQL query with no fallback. When MySQL query failed, it returned nothing, causing 0 domains detected. Fix: Added fallbacks: 1. Try MySQL query (primary) 2. Use Plesk CLI 'plesk bin site --list' + grep for username 3. Check if /var/www/vhosts/$username directory exists This should now detect domains for Plesk users even when MySQL query fails. Testing: Will verify on Plesk server
This commit is contained in:
+16
-1
@@ -272,8 +272,23 @@ get_plesk_user_domains() {
|
||||
[ -z "$1" ] && return 1
|
||||
local username="$1"
|
||||
|
||||
# Try MySQL query first
|
||||
if command_exists mysql && [ -f /etc/psa/.psa.shadow ]; then
|
||||
mysql -Ns psa -e "SELECT d.name FROM domains d JOIN sys_users u ON d.id=u.domain_id WHERE u.login='$username'" 2>/dev/null
|
||||
local domains=$(mysql -Ns psa -e "SELECT d.name FROM domains d JOIN sys_users u ON d.id=u.domain_id WHERE u.login='$username'" 2>/dev/null)
|
||||
if [ -n "$domains" ]; then
|
||||
echo "$domains"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Fallback: Use Plesk CLI if available
|
||||
if [ -x "/usr/local/psa/bin/plesk" ]; then
|
||||
/usr/local/psa/bin/plesk bin site --list 2>/dev/null | grep -i "$username" || true
|
||||
fi
|
||||
|
||||
# Last resort: Check if vhosts directory exists for this user
|
||||
if [ -d "/var/www/vhosts/$username" ]; then
|
||||
echo "$username"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user