diff --git a/lib/reference-db.sh b/lib/reference-db.sh index 87c4163..780046e 100644 --- a/lib/reference-db.sh +++ b/lib/reference-db.sh @@ -279,24 +279,46 @@ build_wordpress_section() { for wp_config in $wp_configs; do local wp_dir=$(dirname "$wp_config") - # Extract username from path (/home/username/...) - local username=$(echo "$wp_dir" | cut -d'/' -f3) - - # Try to get domain from path - check if it's in a subdomain or addon domain folder - local path_after_home=$(echo "$wp_dir" | sed "s|^/home/$username/||") + # Extract username/domain from path (panel-agnostic) + local username="" local domain="" - # Check for common domain folder patterns - if [[ "$path_after_home" == public_html ]]; then - # This is the primary domain - get it from user info - domain=$(grep "USER|${username}|" "$SYSREF_DB" 2>/dev/null | cut -d'|' -f3 || true) - elif [[ "$path_after_home" =~ ^public_html/(.+) ]]; then - # Could be subdomain or subdirectory - extract folder name - local folder=$(echo "$path_after_home" | cut -d'/' -f2) - domain="${folder}" - else - # Might be addon/parked domain with own directory - domain=$(echo "$path_after_home" | cut -d'/' -f1) + case "$SYS_CONTROL_PANEL" in + cpanel) + # cPanel: /home/username/... + username=$(echo "$wp_dir" | cut -d'/' -f3) + ;; + plesk) + # Plesk: /var/www/vhosts/domain.com/... + domain=$(echo "$wp_dir" | cut -d'/' -f5) + username=$(get_domain_owner "$domain" 2>/dev/null || echo "unknown") + ;; + interworx) + # InterWorx: /chroot/home/user/var/domain.com/... + username=$(echo "$wp_dir" | cut -d'/' -f4) + ;; + *) + # Standalone: try to extract from path + username=$(stat -c "%U" "$wp_dir" 2>/dev/null || echo "unknown") + ;; + esac + + # If domain not set yet (cPanel/InterWorx/Standalone), try to infer from path + if [ -z "$domain" ] && [ "$SYS_CONTROL_PANEL" = "cpanel" ]; then + # cPanel: check if this is primary domain or addon/subdomain + local path_after_home=$(echo "$wp_dir" | sed "s|^/home/$username/||") + + if [[ "$path_after_home" == public_html ]]; then + # This is the primary domain - get it from user info + domain=$(grep "USER|${username}|" "$SYSREF_DB" 2>/dev/null | cut -d'|' -f3 || true) + elif [[ "$path_after_home" =~ ^public_html/(.+) ]]; then + # Could be subdomain or subdirectory - extract folder name + local folder=$(echo "$path_after_home" | cut -d'/' -f2) + domain="${folder}" + else + # Might be addon/parked domain with own directory + domain=$(echo "$path_after_home" | cut -d'/' -f1) + fi fi # Try to get actual domain from WP database options (more reliable)