diff --git a/Inventory/Z_data_aix.php b/Inventory/Z_data_aix.php index ba0cb5d..3c845fd 100644 --- a/Inventory/Z_data_aix.php +++ b/Inventory/Z_data_aix.php @@ -1,5 +1,48 @@ ['pipe','r'], // stdin (unused) + 1 => ['pipe','w'], // stdout -> texte déchiffré + 2 => ['pipe','w'], // stderr -> erreurs OpenSSL + ]; + $proc = proc_open($cmd, $spec, $pipes); + if (!is_resource($proc)) { error_log('proc_open failed'); return null; } + fclose($pipes[0]); // rien à envoyer en stdin + + $stdout = stream_get_contents($pipes[1]); fclose($pipes[1]); + $stderr = stream_get_contents($pipes[2]); fclose($pipes[2]); + $code = proc_close($proc); + + if ($code !== 0) { + error_log("OpenSSL failed (code $code): $stderr"); + return null; + } + return $stdout; + } + function DB_ZABBIX() + { + $host = 'aztprdzabbix52.armony.net'; + $dbname = 'zabbix'; + $user = 'patrick'; + $pass = decypher( 'zabbix'); + $pdo = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); + return $pdo; + } $pdo = DB_ZABBIX(); diff --git a/Inventory/Z_data_linux.php b/Inventory/Z_data_linux.php index b5e4c83..18a79c1 100644 --- a/Inventory/Z_data_linux.php +++ b/Inventory/Z_data_linux.php @@ -1,5 +1,48 @@ ['pipe','r'], // stdin (unused) + 1 => ['pipe','w'], // stdout -> texte déchiffré + 2 => ['pipe','w'], // stderr -> erreurs OpenSSL + ]; + $proc = proc_open($cmd, $spec, $pipes); + if (!is_resource($proc)) { error_log('proc_open failed'); return null; } + fclose($pipes[0]); // rien à envoyer en stdin + + $stdout = stream_get_contents($pipes[1]); fclose($pipes[1]); + $stderr = stream_get_contents($pipes[2]); fclose($pipes[2]); + $code = proc_close($proc); + + if ($code !== 0) { + error_log("OpenSSL failed (code $code): $stderr"); + return null; + } + return $stdout; + } + function DB_ZABBIX() + { + $host = 'aztprdzabbix52.armony.net'; + $dbname = 'zabbix'; + $user = 'patrick'; + $pass = decypher( 'zabbix'); + $pdo = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); + return $pdo; + } $pdo = DB_ZABBIX(); diff --git a/Inventory/Z_data_windows.php b/Inventory/Z_data_windows.php index c99a1c5..4815e37 100644 --- a/Inventory/Z_data_windows.php +++ b/Inventory/Z_data_windows.php @@ -1,5 +1,48 @@ ['pipe','r'], // stdin (unused) + 1 => ['pipe','w'], // stdout -> texte déchiffré + 2 => ['pipe','w'], // stderr -> erreurs OpenSSL + ]; + $proc = proc_open($cmd, $spec, $pipes); + if (!is_resource($proc)) { error_log('proc_open failed'); return null; } + fclose($pipes[0]); // rien à envoyer en stdin + + $stdout = stream_get_contents($pipes[1]); fclose($pipes[1]); + $stderr = stream_get_contents($pipes[2]); fclose($pipes[2]); + $code = proc_close($proc); + + if ($code !== 0) { + error_log("OpenSSL failed (code $code): $stderr"); + return null; + } + return $stdout; + } +function DB_ZABBIX() + { + $host = 'aztprdzabbix52.armony.net'; + $dbname = 'zabbix'; + $user = 'patrick'; + $pass = decypher( 'zabbix'); + $pdo = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); + return $pdo; + } $pdo = DB_ZABBIX(); $server = strtoupper($_GET['c']); diff --git a/Inventory/search_servers.php b/Inventory/search_servers.php index c848974..2fb68a4 100644 --- a/Inventory/search_servers.php +++ b/Inventory/search_servers.php @@ -1,6 +1,48 @@ ['pipe','r'], // stdin (unused) + 1 => ['pipe','w'], // stdout -> texte déchiffré + 2 => ['pipe','w'], // stderr -> erreurs OpenSSL + ]; + $proc = proc_open($cmd, $spec, $pipes); + if (!is_resource($proc)) { error_log('proc_open failed'); return null; } + fclose($pipes[0]); // rien à envoyer en stdin + + $stdout = stream_get_contents($pipes[1]); fclose($pipes[1]); + $stderr = stream_get_contents($pipes[2]); fclose($pipes[2]); + $code = proc_close($proc); + + if ($code !== 0) { + error_log("OpenSSL failed (code $code): $stderr"); + return null; + } + return $stdout; + } + function DB_INFRA() { + $user="INFRA_dbo"; + $pwd=decypher("infra"); + $server="DUN-PRD-R1MSSQL.armony.net\PRD"; + $database="INFRA"; + $conn = odbc_connect("Driver={SQL Server};Server=$server;Database=$database;", $user, $pwd); + return $conn ; + } if (isset($_GET['term'])) { $term = $_GET['term']; $query = "SELECT hostname AS serv FROM cmdb_srvall WHERE hostname LIKE '%$term%' UNION SELECT hostname AS serv FROM x_SRVALL WHERE hostname LIKE '%$term%'"; diff --git a/X/Inventory.php b/X/Inventory.php index b7e9ce9..c83f66b 100644 --- a/X/Inventory.php +++ b/X/Inventory.php @@ -2,22 +2,18 @@ - + - Web Infra Reports - - - @@ -28,212 +24,331 @@ - - + -
-
- -
- -
- -
- -

AIX / Linux inventory

+ // NOUVEAU : Gérer les filtres + // Par défaut, tout est coché (true) + // On vérifie si un paramètre est passé dans l'URL pour décocher une case + $show_aix = isset($_GET['show_aix']) ? $_GET['show_aix'] === '1' : true; + $show_linux = isset($_GET['show_linux']) ? $_GET['show_linux'] === '1' : true; - -
- -
+ // Construction de la requête SQL + $base_sql = "SELECT * FROM x_inventory WHERE type IS NOT NULL and hostname not in ('DUNAPPDNIM51','DUNAPPDNIM52') "; + $conditions = []; + + if ($show_aix) { + // La condition pour AIX est simple + $conditions[] = "type = 'AIX'"; + } + if ($show_linux) { + // D'après votre code, tout ce qui n'est pas 'AIX' est considéré comme Linux + $conditions[] = "type <> 'AIX'"; + } + + if (!empty($conditions)) { + // On ajoute les conditions à la requête de base + $sql = $base_sql . " AND (" . implode(' OR ', $conditions) . ")"; + } else { + // Si rien n'est coché, on ne retourne aucun résultat + $sql = $base_sql . " AND 1=0"; + } + + + // DATA + $servers = Invoke_Infra($sql); // On utilise la nouvelle requête + $UTDS1 = (Invoke_Infra("select max(Ver) as utd from X_cmdb_Product where Name = 's1'"))[0]['utd']; + $UTDNessus = (Invoke_Infra("select max(Ver) as utd from X_cmdb_Product where Name = 'nessus'"))[0]['utd']; + $UTDZabbix = (Invoke_Infra("select max(Ver) as utd from X_cmdb_Product where Name = 'zabbix'"))[0]['utd']; + $rows = Invoke_Infra("SELECT DISTINCT(Ver) FROM X_cmdb_Product WHERE Name='bes'"); + $versions = array_map(fn ($r) => $r['Ver'] ?? null, $rows); + $versions = array_values(array_filter($versions)); + usort($versions, 'version_compare'); + $UTDBES = end($versions); + $UTDFI = (Invoke_Infra("select max(Ver) as utd from X_cmdb_Product where Name = 'fi'"))[0]['utd']; +?> + + +
+
+
+ +
+
+

AIX / Linux inventory

+ +
+
+
+
+ > + +
+
+ > + +
+
+
+ +
- - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - "; - //name - $name = $s['hostname']; $heartbeat = $s['Heartbeat']; $statusClass = ''; - $heartbeatDate = new DateTime($heartbeat); - $now = new DateTime(); - $interval = $now->diff($heartbeatDate); - $diffInMinutes = ($interval->days * 24 * 60) + ($interval->h * 60) + $interval->i; - if ($diffInMinutes < 10) { - $statusClass = 'table-success'; - } elseif ($diffInMinutes <= 30) { - $statusClass = 'table-warning'; - } else { - $statusClass = 'table-danger'; - } - echo ""; + + "; + //name + $name = $s['hostname']; + $heartbeat = $s['Heartbeat']; + $statusClass = ''; + $heartbeatDate = new DateTime($heartbeat); + $now = new DateTime(); + $interval = $now->diff($heartbeatDate); + $diffInMinutes = ($interval->days * 24 * 60) + ($interval->h * 60) + $interval->i; + if ($diffInMinutes < 10) { + $statusClass = 'table-success'; + } elseif ($diffInMinutes <= 30) { + $statusClass = 'table-warning'; + } else { + $statusClass = 'table-danger'; + } + echo ""; - //heartbeat - echo ""; + //heartbeat + echo ""; - //Host - echo ""; - //OS Type - $typ = match ($s['type'] ?? null) { - 'AIX' => 'AIX', - null, '' => '', - default => 'LINUX', - }; - echo ""; + //Host + echo ""; + //OS Type + $typ = match ($s['type'] ?? null) { + 'AIX' => 'AIX', + null, '' => '', + default => 'LINUX', + }; + echo ""; - //Distrib - $Distrib = ""; - if($typ == "AIX"){ - $Distrib = $s['osversion']; - } - if($typ == "LINUX"){ - $Distrib = $s['osversion']." (".str_replace(".x86_64","",$s['kernel']).")"; - } - echo ""; + //Distrib + $Distrib = ""; + if ($typ == "AIX") { + $Distrib = $s['osversion']; + } + if ($typ == "LINUX") { + $Distrib = $s['osversion'] . " (" . str_replace(".x86_64", "", $s['kernel']) . ")"; + } + echo ""; - //LastReboot - $lr = $s['lastboot'] ?? ""; $lrDate=""; - try { - $lrDate = new DateTime($lr); - } catch (DateMalformedStringException $e) {} - $interval = (new DateTime())->diff($lrDate); - if($interval->days > 60){ - echo ""; - }else{ - if($interval->days > 1){ - echo ""; - }else{ - echo ""; - } - } - - //LastBackup - $lr = explode(".",$s['backuplast'] ?? "")[0]; - $size = 0; - if($s['backuplog'] != "") { - if (str_contains($s['backuplog'],"Length")) { - $size = explode(" ", $s['backuplog'])[1]; - } else { - $size = explode(" ", $s['backuplog'])[3]; - } - $size = floor($size / 1024 / 1024 / 1024); - } - if($size >= 15){ - $size = "$size GB"; - }else{ - $size = "$size GB"; - } - try { - $lrDate = new DateTime($lr); - } catch (DateMalformedStringException $e) {} - $interval = (new DateTime())->diff($lrDate); - if($interval->days > 7 || $s['backuplast'] == ""){ - echo ""; - }else{ - if($interval->days > 1){ - echo ""; - }else{ - echo ""; - } - } - - //Auth - echo ""; - - //SentinelOne - $s1s = $s['S1State']; $s1v = $s['S1Version']; - if($typ == "LINUX"){ - if($s1s == "YY"){ - if($s1v == $UTDS1) { - echo ""; - }else{ - echo ""; - } - }else{ - if($s1v == "") { - echo ""; - }else{ - echo ""; - } - } - }else{ - echo ""; - } - - //Nessus - $s1s = $s['NessusState']; $s1v = $s['NessusVersion']; - if($typ == "LINUX"){ - if($s1s == "YYY_YYY"){ - if($s1v == $UTDNessus) { - echo ""; - }else{ - echo ""; - } - }else { - if ($s1v == "") { - echo ""; - } else { - echo ""; - } - } - }else{ - echo ""; + //LastReboot + $lr = $s['lastboot'] ?? ""; + $lrDate = ""; + try { + $lrDate = new DateTime($lr); + } catch (DateMalformedStringException $e) { + } + $interval = (new DateTime())->diff($lrDate); + if ($interval->days > 60) { + echo ""; + } else { + if ($interval->days > 1) { + echo ""; + } else { + echo ""; } - - //Zabbix - $s1s = $s['ZabbixState']; $s1v = $s['ZabbixVersion']; - if($s1s == "Y"){ - if($s1v == $UTDZabbix) { - echo ""; - }else{ - echo ""; - } - }else{ - if($s1v == "") { - echo ""; - }else{ - echo ""; - } - } - - echo ""; } - ?> - -
NameHeartbeatHostOS TypeDistribLast rebootLast backupAuthSentinelOneNessusZabbix
NameHeartbeatHostOS TypeDistribLast rebootLast backupAuthSentinelOneNessusZabbixBESFusion Inv.
"; - echo " {$name}"; - echo "
"; + echo " {$name}"; + echo "".$s["Heartbeat"]."" . $s["Heartbeat"] . "".$s['Owner']."".$s['type']."" . $s['Owner'] . "" . $s['type'] . "$Distrib$Distrib$lr$lr$lr$lr"." ".$size."".date_format($lrDate,"Y-m-d H:i:s")." - ".$size."$lr"." - ".$size."".$s['auth']."$s1v $s1s$s1v $s1sMISSING$s1v $s1s$s1v $s1s$s1v $s1sMISSING$s1v $s1s$lr$lr$lr$s1v $s1s$s1v $s1sMISSING$s1v $s1s

-
servers
-
+ //LastBackup + $lr = explode(".", $s['backuplast'] ?? "")[0]; + $size = 0; + if ($s['backuplog'] != "") { + if (str_contains($s['backuplog'], "Length")) { + $size = explode(" ", $s['backuplog'])[1]; + } else { + $size = explode(" ", $s['backuplog'])[3]; + } + $size = floor($size / 1024 / 1024 / 1024); + } + if ($size >= 15) { + $size = "$size GB"; + } else { + $size = "$size GB"; + } + try { + $lrDate = new DateTime($lr); + } catch (DateMalformedStringException $e) { + } + $interval = (new DateTime())->diff($lrDate); + if ($interval->days > 7 || $s['backuplast'] == "") { + echo "$lr" . " " . $size . ""; + } else { + if ($interval->days > 1) { + echo "" . date_format($lrDate, "Y-m-d H:i:s") . " - " . $size . ""; + } else { + echo "$lr" . " - " . $size . ""; + } + } + + //Auth + echo "" . $s['auth'] . ""; + + //SentinelOne + $s1s = $s['S1State']; + $s1v = $s['S1Version']; + if ($typ == "LINUX") { + if ($s1s == "YY") { + if ($s1v == $UTDS1) { + echo "$s1v $s1s"; + } else { + echo "$s1v $s1s"; + } + } else { + if ($s1v == "") { + echo "MISSING"; + } else { + echo "$s1v $s1s"; + } + } + } else { + echo ""; + } + + //Nessus + $s1s = $s['NessusState']; + $s1v = $s['NessusVersion']; + if ($typ == "LINUX") { + if ($s1s == "YYY_YYY") { + if ($s1v == $UTDNessus) { + echo "$s1v $s1s"; + } else { + echo "$s1v $s1s"; + } + } else { + if ($s1v == "") { + echo "MISSING"; + } else { + echo "$s1v $s1s"; + } + } + } else { + echo ""; + } + + //Zabbix + $s1s = $s['ZabbixState']; + $s1v = $s['ZabbixVersion']; + if ($typ == "AIX" && str_starts_with($s['osversion'], '6')) { + echo ""; + } else { + if ($s1s == "Y") { + if ($s1v == $UTDZabbix) { + echo "$s1v $s1s"; + } else { + echo "$s1v $s1s"; + } + } else { + if ($s1v == "") { + echo "MISSING"; + } else { + echo "$s1v $s1s"; + } + } + } + + //BES + $s1s = $s['BESState']; + $s1v = $s['BESVersion']; + if ($s1s == "Y") { + if ($s1v == $UTDBES) { + echo "$s1v $s1s"; + } else { + echo "$s1v $s1s"; + } + } else { + if ($s1v == "") { + echo "MISSING"; + } else { + echo "$s1v $s1s"; + } + } + + //FI + $s1s = $s['FIState']; + $s1v = $s['FIVersion']; + if ($typ == "LINUX") { + if ($s1s == "Y") { + if ($s1v == $UTDFI) { + echo "$s1v $s1s"; + } else { + echo "$s1v $s1s"; + } + } else { + if ($s1v == "") { + echo "MISSING"; + } else { + echo "$s1v $s1s"; + } + } + } else { + echo ""; + } + + echo ""; + } + + ?> + +
+
servers
-
+
+ + + \ No newline at end of file diff --git a/X/StdOut-detail.php b/X/StdOut-detail.php index 0a8c6b5..4f92291 100644 --- a/X/StdOut-detail.php +++ b/X/StdOut-detail.php @@ -69,26 +69,14 @@
Host OS + Distrib TimeStamp RC StdOut @@ -186,7 +176,8 @@ $host"; echo "$os"; + echo "$osver"; echo "" . $ts . ""; if ($rc == 0 && (string)$rc <> "") { echo "" . $rc . ""; diff --git a/crossover/GlobalCrossover.php b/crossover/GlobalCrossover.php index ace6efe..076cfad 100644 --- a/crossover/GlobalCrossover.php +++ b/crossover/GlobalCrossover.php @@ -30,7 +30,6 @@ -
diff --git a/include/all.php b/include/all.php index 151587f..1d64a32 100644 --- a/include/all.php +++ b/include/all.php @@ -259,27 +259,78 @@ return $pdo; } + //Cookie// + function Set_Cookie() { + // --- paramètres --- + $cookieName = 'UserInfo'; + $cookieLife = 86400 * 365; // 1 an + $cookieDomain = '.appliarmony.net'; + $secureFlag = true; + $httpOnly = true; + $sameSite = 'Lax'; + // --- helpers --- + $now = date('Y-m-d H:i:s'); - //Set Cookies - $secretKey = 'impossibleatrouvercommeca'; - $remoteUser = $_SERVER['REMOTE_USER'] ?? null; - if ($remoteUser) { - $expiration = time() + 3600; // Token is valid for 1 hour - $payload = base64_encode($remoteUser . '|' . $expiration); // Combine user and expiration - $signature = hash_hmac('sha256', $payload, $secretKey); - $cookieValue = $payload . '.' . $signature; + // IP client: XFF (première IP) -> fallback REMOTE_ADDR + $ip = ''; + if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $parts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); + $cand = trim($parts[0]); + if (filter_var($cand, FILTER_VALIDATE_IP)) $ip = $cand; + } + if (!$ip && !empty($_SERVER['REMOTE_ADDR'])) $ip = $_SERVER['REMOTE_ADDR']; - // Set the cookie - setcookie('AuthToken', $cookieValue, [ - 'expires' => time() + 3600, - 'path' => '/', - 'domain' => '.appliarmony.net', - 'secure' => false, // true quand HTTPS - 'httponly' => true, - 'samesite' => 'Lax' - ]); + // User Windows (SSO) + $user = $_SERVER['REMOTE_USER'] ?? null; + $hasUser = !empty($user); + + // --- lecture éventuelle du cookie existant --- + $cookie = []; + if (!empty($_COOKIE[$cookieName])) { + $decoded = json_decode($_COOKIE[$cookieName], true); + if (is_array($decoded)) $cookie = $decoded; + } + + // --- écriture/MAJ SEULEMENT si on a un REMOTE_USER --- + if ($hasUser) { + if (empty($cookie) || ($cookie['user'] ?? null) !== $user) { + // Nouveau cookie ou changement d’utilisateur → reset + $cookie = [ + 'user' => $user, + 'ip' => $ip, + 'created' => $now, + 'last' => $now + ]; + } else { + // Même user → on rafraîchit last + IP + $cookie['ip'] = $ip ?: ($cookie['ip'] ?? ''); + $cookie['last'] = $now; + } + + // Écrire le cookie (évite d’écrire si headers déjà envoyés) + if (!headers_sent()) { + setcookie($cookieName, json_encode($cookie), [ + 'expires' => time() + $cookieLife, + 'path' => '/', + 'domain' => $cookieDomain, + 'secure' => $secureFlag, + 'httponly' => $httpOnly, + 'samesite' => $sameSite + ]); + } + } + + // --- exposer des constantes pour le reste du code --- + // Priorité: si on a REMOTE_USER on l’utilise; sinon on retombe sur le cookie existant; sinon vide/anonyme. + $currentUser = $hasUser ? $user : ($cookie['user'] ?? 'Anonymous'); + $currentIp = $hasUser ? $ip : ($cookie['ip'] ?? ($_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'] ?? '')); + + if (!defined('CURRENT_USER')) define('CURRENT_USER', $currentUser); + if (!defined('CURRENT_IP')) define('CURRENT_IP', $currentIp); + if (!defined('COOKIE_INFO')) define('COOKIE_INFO', $cookie); } + Set_Cookie(); ?>