Global Crossover (Updated every 15mn)

45)"; break; case "OS": $whereClauses[] = "OS LIKE '%2003%' OR OS LIKE '%2008%'"; break; case "GLPI": $whereClauses[] = "GLPI IS NULL OR GLPIlu IS NULL OR DATEDIFF(now(), GLPIlu) > 7"; break; case "SCCM": $whereClauses[] = "SCCM IS NULL OR (SCCMlu IS NOT NULL AND DATEDIFF(now(), SCCMlu) > 7)"; break; case "NESSUS": $whereClauses[] = "EPO IS NULL"; break; case "NBU": $whereClauses[] = "NBU IS NULL OR (NBUlu IS NOT NULL AND DATEDIFF(now(), NBUlu) > 30)"; break; case "SCOM": $whereClauses[] = "SCOM IS NULL"; break; case "zabbix": $whereClauses[] = "zabbix IS NULL"; break; case "S1": $whereClauses[] = "S1 IS NULL OR (S1lu IS NOT NULL AND DATEDIFF(now(), S1lu) > 7)"; break; default: $filterTitle = null; // No valid filter break; } if ($filterTitle) { echo "

$filterTitle

"; } } // Combine all WHERE clauses if (!empty($whereClauses)) { $sql .= " WHERE " . implode(' AND ', $whereClauses); } $sql .= " ORDER BY server"; // Prepare and execute the query $stmt = $conn->prepare($sql); // Note: If you had parameters, you would bind them here, e.g., $stmt->bind_param($types, ...$params); $stmt->execute(); $result = $stmt->get_result(); // --- PART 2: HELPER FUNCTIONS FOR RENDERING --- /** * Renders a standard status cell based on a value and its last update date. * @param string|null $status The status value (e.g., 'Y', 'N'). * @param string|null $lastUpdate The date of the last update. * @param int $daysThreshold The number of days to be considered "out of date". * @param string $okText Text to display for OK status (e.g., "OK", "OK (NBU)"). * @return string The generated HTML for two " . ""; } try { $diff = date_diff(date_create($lastUpdate), date_create()); $days = (int) $diff->format("%R%a"); if ($days > $daysThreshold) { // Out of date return "" . ""; } else { // Compliant return "" . ""; } } catch (Exception) { // Handle invalid date format gracefully return ""; } } if ($status !== '') { // Not applicable, non-supported, etc. return ""; } // Missing return ""; } // --- PART 3: CLEAN DATA DISPLAY LOOP --- // Initialize counters $counters = [ 'total' => 0, 'ok' => 0, 'nOS' => 0, 'nAD' => 0, 'nSCCM' => 0, 'nGLPI' => 0, 'nFI' => 0, 'nNESSUS' => 0, 'nNBU' => 0, 'nDPM' => 0, 'nS1' => 0 ]; while ($row = $result->fetch_assoc()) { $counters['total']++; // Sanitize server name for URL and display $serverName = htmlspecialchars($row['Server'], ENT_QUOTES, 'UTF-8'); $serverUrl = urlencode($row['Server']); // Determine overall row status $isCompliant = isset($row['AD'], $row['GLPI'], $row['SCCM'], $row['EPO']) && (isset($row['NBU']) || isset($row['DPM'])) && isset($row['SCOM']); if ($isCompliant) { $counters['ok']++; $serverCell = ""; } else { $serverCell = ""; } // OS Cell $osCell = ""; if (!empty($row['OS'])) { $os = htmlspecialchars($row['OS']); if (preg_match('(XP|2003|2000|2008|Windows 7|2012)', $row['OS'])) { $osCell = ""; } else { $counters['nOS']++; $osCell = ""; } } echo ""; echo $serverCell; echo $osCell; echo ""; echo ""; // Use helper function for status columns echo renderStatusCellWithDate($row['AD'], $row['ADlu'], 45); echo renderStatusCellWithDate($row['GLPI'], $row['GLPIlu'], 7); echo renderStatusCellWithDate($row['SCCM'], $row['SCCMlu'], 7); // NESSUS (EPO) Cell - Custom logic if (str_contains($row['EPO'] ?? '', '.')) { echo ""; } elseif (isset($row['EPO']) && !in_array($row['EPO'], ['Y', 'N'])) { echo ""; } else { echo ""; $counters['nNESSUS']++; } // BACKUP Cell - Custom logic for NBU/DPM if ($row['NBU'] === 'Y') { echo renderStatusCellWithDate($row['NBU'], $row['NBUlu'], 30, 'OK (NBU)'); } elseif ($row['DPM'] === 'Y') { echo renderStatusCellWithDate($row['DPM'], $row['DPMlu'], 30, 'OK (DPM)'); } else { // Handle non-Y cases for NBU or DPM, or missing $backupStatus = $row['NBU'] ?? $row['DPM'] ?? null; echo renderStatusCellWithDate($backupStatus, null, 30); } // SCOM Cell - Simple logic if ($row['SCOM'] === 'Y') { echo ""; } elseif (isset($row['SCOM'])) { echo ""; } else { echo ""; } // Zabbix Cell - Simple logic $zabbixStatus = $row['zabbix'] ?? ''; if ($zabbixStatus === 'Y' || str_contains($zabbixStatus, '.')) { echo ""; } elseif (isset($row['zabbix'])) { echo ""; } else { echo ""; } // S1 Cell $s1Status = $row['S1'] ?? ''; $s1Text = ($s1Status === 'Y' || str_contains($s1Status, '.')) ? str_replace('Y', 'OK', $s1Status) : 'OK'; echo renderStatusCellWithDate($s1Status, $row['S1lu'], 7, $s1Text); echo ""; } // You can now use the $counters array to pass data to your JS for the KPIs // For example: echo ""; $stmt->close(); $conn->close(); ?>
Name Operating System Criticity Departement AD AD Last Logon GLPI Last FI Inventory SCCM
SCCM Last Heartbeat NESSUS Backup Last Backup SCOM Zabbix SentinelOne S1 Last Update
cells. */ function renderStatusCellWithDate(?string $status, ?string $lastUpdate, int $daysThreshold, string $okText = 'OK'): string { // Sanitize output to prevent XSS $status = htmlspecialchars($status ?? '', ENT_QUOTES, 'UTF-8'); $lastUpdate = htmlspecialchars($lastUpdate ?? '', ENT_QUOTES, 'UTF-8'); $okText = htmlspecialchars($okText, ENT_QUOTES, 'UTF-8'); if ($status === 'Y') { if (empty($lastUpdate)) { // Status is OK, but date is missing return "$okTextMissing$okText$lastUpdate ($days days)$okText$lastUpdateInvalid Date$lastUpdate$status Missing $serverName$serverName $os$os
" . htmlspecialchars($row['crit'] ?? '') . "" . htmlspecialchars($row['dpt'] ?? '') . "" . htmlspecialchars($row['EPO']) . "" . htmlspecialchars($row['EPO']) . "MissingOK" . htmlspecialchars($row['SCOM']) . "Missing" . htmlspecialchars(str_replace('Y', 'OK', $zabbixStatus)) . "" . htmlspecialchars($zabbixStatus) . "Missing
All Devices

Supported OS

AD

GLPI/FI

SCCM

NESSUS

Backup

SCOM

Zabbix

SentinelOne