Improve inventory handling and cookie management:

- Replace old cookie logic with `Set_Cookie()` for enhanced security (SameSite, Secure, HttpOnly).
- Add dynamic AIX/Linux filtering on `/X/Inventory.php` with checkbox-driven UI and adjusted SQL queries.
- Expand `/X/Inventory.php` table with additional columns (`BES`, `FI`) and enhance data validation/styling.
- Add `decypher()` function in `Z_data_linux.php` to support OpenSSL-based file decryption with error handling.
This commit is contained in:
2025-10-14 11:08:42 +02:00
parent dcfe098f35
commit ea46ba5c8f
8 changed files with 569 additions and 241 deletions

View File

@@ -1,5 +1,48 @@
<?php <?php
include $_SERVER['DOCUMENT_ROOT']."/include/all.php" ; function decypher(string $name): ?string {
$openssl = 'C:\Program Files\FireDaemon OpenSSL 3\bin\openssl.exe';
$cmsFile = "F:\\Include\\dat\\$name.p7m";
$certPem = "F:\\Include\\certs\\cert_only.pem";
$keyPem = "F:\\Include\\certs\\key_only.pem";
foreach ([$openssl,$cmsFile,$certPem,$keyPem] as $p) {
if (!is_file($p)) { error_log("Missing file: $p"); return null; }
}
$cmd = '"' . $openssl . '" cms -decrypt -inform PEM'
. ' -in ' . escapeshellarg($cmsFile)
. ' -recip ' . escapeshellarg($certPem)
. ' -inkey ' . escapeshellarg($keyPem)
. ' -out -';
$spec = [
0 => ['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(); $pdo = DB_ZABBIX();

View File

@@ -1,5 +1,48 @@
<?php <?php
include $_SERVER['DOCUMENT_ROOT']."/include/all.php" ; function decypher(string $name): ?string {
$openssl = 'C:\Program Files\FireDaemon OpenSSL 3\bin\openssl.exe';
$cmsFile = "F:\\Include\\dat\\$name.p7m";
$certPem = "F:\\Include\\certs\\cert_only.pem";
$keyPem = "F:\\Include\\certs\\key_only.pem";
foreach ([$openssl,$cmsFile,$certPem,$keyPem] as $p) {
if (!is_file($p)) { error_log("Missing file: $p"); return null; }
}
$cmd = '"' . $openssl . '" cms -decrypt -inform PEM'
. ' -in ' . escapeshellarg($cmsFile)
. ' -recip ' . escapeshellarg($certPem)
. ' -inkey ' . escapeshellarg($keyPem)
. ' -out -';
$spec = [
0 => ['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(); $pdo = DB_ZABBIX();

View File

@@ -1,5 +1,48 @@
<?php <?php
include $_SERVER['DOCUMENT_ROOT']."/include/all.php" ; function decypher(string $name): ?string {
$openssl = 'C:\Program Files\FireDaemon OpenSSL 3\bin\openssl.exe';
$cmsFile = "F:\\Include\\dat\\$name.p7m";
$certPem = "F:\\Include\\certs\\cert_only.pem";
$keyPem = "F:\\Include\\certs\\key_only.pem";
foreach ([$openssl,$cmsFile,$certPem,$keyPem] as $p) {
if (!is_file($p)) { error_log("Missing file: $p"); return null; }
}
$cmd = '"' . $openssl . '" cms -decrypt -inform PEM'
. ' -in ' . escapeshellarg($cmsFile)
. ' -recip ' . escapeshellarg($certPem)
. ' -inkey ' . escapeshellarg($keyPem)
. ' -out -';
$spec = [
0 => ['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(); $pdo = DB_ZABBIX();
$server = strtoupper($_GET['c']); $server = strtoupper($_GET['c']);

View File

@@ -1,6 +1,48 @@
<?php <?php
header('Content-Type: application/json'); header('Content-Type: application/json');
include $_SERVER['DOCUMENT_ROOT'] . "/include/all.php"; function decypher(string $name): ?string {
$openssl = 'C:\Program Files\FireDaemon OpenSSL 3\bin\openssl.exe';
$cmsFile = "F:\\Include\\dat\\$name.p7m";
$certPem = "F:\\Include\\certs\\cert_only.pem";
$keyPem = "F:\\Include\\certs\\key_only.pem";
foreach ([$openssl,$cmsFile,$certPem,$keyPem] as $p) {
if (!is_file($p)) { error_log("Missing file: $p"); return null; }
}
$cmd = '"' . $openssl . '" cms -decrypt -inform PEM'
. ' -in ' . escapeshellarg($cmsFile)
. ' -recip ' . escapeshellarg($certPem)
. ' -inkey ' . escapeshellarg($keyPem)
. ' -out -';
$spec = [
0 => ['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'])) { if (isset($_GET['term'])) {
$term = $_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%'"; $query = "SELECT hostname AS serv FROM cmdb_srvall WHERE hostname LIKE '%$term%' UNION SELECT hostname AS serv FROM x_SRVALL WHERE hostname LIKE '%$term%'";

View File

@@ -2,22 +2,18 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-t">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Page Title -->
<title>Web Infra Reports</title> <title>Web Infra Reports</title>
<link rel="shortcut icon" type="image/png" href="/include/favicon-32x32.png"> <link rel="shortcut icon" type="image/png" href="/include/favicon-32x32.png">
<!-- JQuery -->
<script src="/js/jquery-3.6.1.min.js"></script> <script src="/js/jquery-3.6.1.min.js"></script>
<!-- Bootstrap -->
<link rel="stylesheet" href="/css/bootstrap.min.css"> <link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/bootstrap-icons/bootstrap-icons.css"> <link rel="stylesheet" href="/css/bootstrap-icons/bootstrap-icons.css">
<link rel="stylesheet" href="/css/preloader.css"> <link rel="stylesheet" href="/css/preloader.css">
<script src="/js/bootstrap.bundle.min.js"></script> <script src="/js/bootstrap.bundle.min.js"></script>
<!-- Bootstrap-tables -->
<link rel="stylesheet" href="/css/bootstrap-table.min.css"> <link rel="stylesheet" href="/css/bootstrap-table.min.css">
<script src="/js/bootstrap-table.min.js"></script> <script src="/js/bootstrap-table.min.js"></script>
<script src="/js/bootstrap-table-fr-FR.min.js"></script> <script src="/js/bootstrap-table-fr-FR.min.js"></script>
@@ -28,32 +24,76 @@
</head> </head>
<body class="bg-light text-dark"> <body class="bg-light text-dark">
<?php include $_SERVER['DOCUMENT_ROOT'] . "/include/global.php"; ?> <?php
<?php // DATA include $_SERVER['DOCUMENT_ROOT'] . "/include/global.php";
$servers = Invoke_Infra("select * from x_inventory where type is not null");
// 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']; $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']; $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']; $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'];
?> ?>
<!-- HTML -->
<div class="container-fluid" id="content"> <div class="container-fluid" id="content">
<div class="row flex-nowrap"> <div class="row flex-nowrap">
<!-- Left NAVBAR -->
<div class="col-auto col-md-2 col-xl-2 px-sm-2 px-0 bg-dark vh-100 position-sticky top-0" style="-ms-flex: 0 0 230px;flex: 0 0 230px;"> <div class="col-auto col-md-2 col-xl-2 px-sm-2 px-0 bg-dark vh-100 position-sticky top-0" style="-ms-flex: 0 0 230px;flex: 0 0 230px;">
<?php include $_SERVER['DOCUMENT_ROOT'] . "/navbar.html"; ?> <?php include $_SERVER['DOCUMENT_ROOT'] . "/navbar.html"; ?>
</div> </div>
<!-- Display -->
<div class="col py-3"> <div class="col py-3">
<!-- Page Title -->
<h1><span class="badge text-bg-secondary font-weight-bold" style="width:100%;">AIX / Linux inventory</span></h1> <h1><span class="badge text-bg-secondary font-weight-bold" style="width:100%;">AIX / Linux inventory</span></h1>
<!-- Main content -->
<div class="container-fluid"> <div class="container-fluid">
<!-- TABLE --> <div class="d-flex justify-content-start align-items-center mb-2 p-2 rounded bg-secondary-subtle">
<form class="form-inline d-flex gap-4">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="showAix" <?php echo $show_aix ? 'checked' : ''; ?>>
<label class="form-check-label" for="showAix"><strong>AIX</strong></label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="showLinux" <?php echo $show_linux ? 'checked' : ''; ?>>
<label class="form-check-label" for="showLinux"><strong>Linux</strong></label>
</div>
</form>
</div>
<div> <div>
<table class='table table-bordered table-hover table-sm' id='t1' data-height="620" data-toggle="table" data-search="true" data-show-columns="true" data-export-types="['xlsx','csv','json']" data-show-export="true" data-sortable="true" data-sort-name="VM"> <table class='table table-bordered table-hover table-sm' id='t1' data-height="620" data-toggle="table" data-search="true" data-show-columns="true" data-export-types="['xlsx','csv','json']" data-show-export="true" data-sortable="true" data-sort-name="VM">
<thead> <!-- Header --> <thead>
<tr> <tr>
<th data-field="Name" data-sortable="true">Name</th> <th data-field="Name" data-sortable="true">Name</th>
<th data-field="Heartbeat" data-sortable="true" data-visible="false">Heartbeat</th> <th data-field="Heartbeat" data-sortable="true" data-visible="false">Heartbeat</th>
@@ -66,17 +106,21 @@
<th data-field="SentinelOne" data-sortable="true">SentinelOne</th> <th data-field="SentinelOne" data-sortable="true">SentinelOne</th>
<th data-field="Nessus" data-sortable="true">Nessus</th> <th data-field="Nessus" data-sortable="true">Nessus</th>
<th data-field="Zabbix" data-sortable="true">Zabbix</th> <th data-field="Zabbix" data-sortable="true">Zabbix</th>
<th data-field="BES" data-sortable="true" data-visible="false">BES</th>
<th data-field="FI" data-sortable="true" data-visible="false">Fusion Inv.</th>
</tr> </tr>
</thead> </thead>
<tbody> <!-- Body --> <tbody>
<?php <?php
$total = 0; $total = 0;
foreach ($servers as $s) { foreach ($servers as $s) {
$total++; $total++;
echo "<tr>"; echo "<tr>";
//name //name
$name = $s['hostname']; $heartbeat = $s['Heartbeat']; $statusClass = ''; $name = $s['hostname'];
$heartbeat = $s['Heartbeat'];
$statusClass = '';
$heartbeatDate = new DateTime($heartbeat); $heartbeatDate = new DateTime($heartbeat);
$now = new DateTime(); $now = new DateTime();
$interval = $now->diff($heartbeatDate); $interval = $now->diff($heartbeatDate);
@@ -88,7 +132,7 @@
} else { } else {
$statusClass = 'table-danger'; $statusClass = 'table-danger';
} }
echo "<td class='{$statusClass}'>"; echo "<td class='$statusClass'>";
echo " <a href='/inventory/server-detail.php?s={$name}' target='_blank'>{$name}</a>"; echo " <a href='/inventory/server-detail.php?s={$name}' target='_blank'>{$name}</a>";
echo "</td>"; echo "</td>";
@@ -116,10 +160,12 @@
echo "<td>$Distrib</td>"; echo "<td>$Distrib</td>";
//LastReboot //LastReboot
$lr = $s['lastboot'] ?? ""; $lrDate=""; $lr = $s['lastboot'] ?? "";
$lrDate = "";
try { try {
$lrDate = new DateTime($lr); $lrDate = new DateTime($lr);
} catch (DateMalformedStringException $e) {} } catch (DateMalformedStringException $e) {
}
$interval = (new DateTime())->diff($lrDate); $interval = (new DateTime())->diff($lrDate);
if ($interval->days > 60) { if ($interval->days > 60) {
echo "<td class='table-danger'>$lr</td>"; echo "<td class='table-danger'>$lr</td>";
@@ -149,7 +195,8 @@
} }
try { try {
$lrDate = new DateTime($lr); $lrDate = new DateTime($lr);
} catch (DateMalformedStringException $e) {} } catch (DateMalformedStringException $e) {
}
$interval = (new DateTime())->diff($lrDate); $interval = (new DateTime())->diff($lrDate);
if ($interval->days > 7 || $s['backuplast'] == "") { if ($interval->days > 7 || $s['backuplast'] == "") {
echo "<td class='table-danger'>$lr" . " " . $size . "</td>"; echo "<td class='table-danger'>$lr" . " " . $size . "</td>";
@@ -165,7 +212,8 @@
echo "<td>" . $s['auth'] . "</td>"; echo "<td>" . $s['auth'] . "</td>";
//SentinelOne //SentinelOne
$s1s = $s['S1State']; $s1v = $s['S1Version']; $s1s = $s['S1State'];
$s1v = $s['S1Version'];
if ($typ == "LINUX") { if ($typ == "LINUX") {
if ($s1s == "YY") { if ($s1s == "YY") {
if ($s1v == $UTDS1) { if ($s1v == $UTDS1) {
@@ -185,7 +233,8 @@
} }
//Nessus //Nessus
$s1s = $s['NessusState']; $s1v = $s['NessusVersion']; $s1s = $s['NessusState'];
$s1v = $s['NessusVersion'];
if ($typ == "LINUX") { if ($typ == "LINUX") {
if ($s1s == "YYY_YYY") { if ($s1s == "YYY_YYY") {
if ($s1v == $UTDNessus) { if ($s1v == $UTDNessus) {
@@ -205,7 +254,11 @@
} }
//Zabbix //Zabbix
$s1s = $s['ZabbixState']; $s1v = $s['ZabbixVersion']; $s1s = $s['ZabbixState'];
$s1v = $s['ZabbixVersion'];
if ($typ == "AIX" && str_starts_with($s['osversion'], '6')) {
echo "<td></td>";
} else {
if ($s1s == "Y") { if ($s1s == "Y") {
if ($s1v == $UTDZabbix) { if ($s1v == $UTDZabbix) {
echo "<td class='table-success'>$s1v $s1s</td>"; echo "<td class='table-success'>$s1v $s1s</td>";
@@ -219,6 +272,45 @@
echo "<td class='table-danger'>$s1v <b>$s1s</b></td>"; echo "<td class='table-danger'>$s1v <b>$s1s</b></td>";
} }
} }
}
//BES
$s1s = $s['BESState'];
$s1v = $s['BESVersion'];
if ($s1s == "Y") {
if ($s1v == $UTDBES) {
echo "<td class='table-success'>$s1v $s1s</td>";
} else {
echo "<td class='table-warning'><b>$s1v</b> $s1s</td>";
}
} else {
if ($s1v == "") {
echo "<td class='table-danger text-center'>MISSING</td>";
} else {
echo "<td class='table-danger'>$s1v <b>$s1s</b></td>";
}
}
//FI
$s1s = $s['FIState'];
$s1v = $s['FIVersion'];
if ($typ == "LINUX") {
if ($s1s == "Y") {
if ($s1v == $UTDFI) {
echo "<td class='table-success'>$s1v $s1s</td>";
} else {
echo "<td class='table-warning'><b>$s1v</b> $s1s</td>";
}
} else {
if ($s1v == "") {
echo "<td class='table-danger text-center'>MISSING</td>";
} else {
echo "<td class='table-danger'>$s1v <b>$s1s</b></td>";
}
}
} else {
echo "<td></td>";
}
echo "</tr>"; echo "</tr>";
} }
@@ -229,11 +321,34 @@
<h5 class="text-center"><?php echo $total; ?> servers</h5> <h5 class="text-center"><?php echo $total; ?> servers</h5>
</div> </div>
</div> </div>
<!-- End of main content -->
</div> </div>
</div> </div>
</div> </div>
</body> </body>
<script src="/js/switch.js"></script> <script src="/js/switch.js"></script>
<script>
// This function will be executed when the document is ready
$(function() {
// Add an event listener to both checkboxes
$('#showAix, #showLinux').on('change', function() {
// Get the current state of the checkboxes (checked or not)
// '1' for checked, '0' for unchecked
const showAix = $('#showAix').is(':checked') ? '1' : '0';
const showLinux = $('#showLinux').is(':checked') ? '1' : '0';
// Create a URL object to easily manipulate query parameters
const url = new URL(window.location.href);
// Set the parameters based on checkbox states
url.searchParams.set('show_aix', showAix);
url.searchParams.set('show_linux', showLinux);
// Reload the page with the new URL
window.location.href = url.toString();
});
});
</script>
</HTML> </HTML>
<script src="/js/tableResize.js"></script> <script src="/js/tableResize.js"></script>

View File

@@ -69,26 +69,14 @@
<div> <div>
<?php <?php
$aix = $linux = $dun = $azt = $other = "Checked"; $aix = $linux = $dun = $azt = $other = "Checked";
$where = " and OS_TYPE IN ("; $where = "";
if (isset($_GET['AIX'])) { if (!isset($_GET['AIX'])){$aix = "Unchecked";}
if ($_GET['AIX'] == 1) { if (!isset($_GET['linux'])){$linux = "Unchecked";}
$where .= "'AIX',";
} else { if($linux=="Unchecked" && $aix=="Unchecked"){ $where = " and 1=2 ";}
$aix = "Unchecked"; if($linux=="Unchecked" && $aix=="Checked"){ $where = " and Type ='AIX' ";}
} if($linux=="Checked" && $aix=="Unchecked"){ $where = " and not Type ='AIX' ";}
} else {
$aix = "Unchecked";
}
if (isset($_GET['linux'])) {
if ($_GET['linux'] == 1) {
$where .= "'LINUX',";
} else {
$linux = "Unchecked";
}
} else {
$linux = "Unchecked";
}
$where = rtrim($where, ',') . ")";
$site = ""; $site = "";
if (isset($_GET['DUN'])) { if (isset($_GET['DUN'])) {
if ($_GET['DUN'] == 1) { if ($_GET['DUN'] == 1) {
@@ -120,8 +108,9 @@
$site = " and (" . ltrim($site, ' or') . ") "; $site = " and (" . ltrim($site, ' or') . ") ";
$where .= $site; $where .= $site;
$sql = "select hostname, os_type from srvall where decomtime is null and (ucase(filter) not like 'X_%' or filter is null) $where order by hostname"; $sql = "select HOSTNAME, Type, OSVersion from x_srvall where Decom is null $where order by hostname";
$hosts = Invoke_aixcmdb($sql); $hosts = Invoke_Infra($sql);
//print_r($hosts);exit;
$taix = $aixok = $aixko = $tlinux = $linuxok = $linuxko = 0; $taix = $aixok = $aixko = $tlinux = $linuxok = $linuxko = 0;
$resultsByHost = []; $resultsByHost = [];
@@ -178,6 +167,7 @@
<thead> <tr> <thead> <tr>
<th data-field='host' data-sortable='true'>Host</th> <th data-field='host' data-sortable='true'>Host</th>
<th data-field='OS' data-sortable='true'>OS</th> <th data-field='OS' data-sortable='true'>OS</th>
<th data-field='OSVer' data-sortable='true'>Distrib</th>
<th data-field='TimeStamp' data-sortable='true'>TimeStamp</th> <th data-field='TimeStamp' data-sortable='true'>TimeStamp</th>
<th data-field='RC' data-sortable='true'>RC</th> <th data-field='RC' data-sortable='true'>RC</th>
<th data-field='Result' data-sortable='true'>StdOut</th> <th data-field='Result' data-sortable='true'>StdOut</th>
@@ -186,7 +176,8 @@
<tbody> <?php <tbody> <?php
foreach ($hosts as $h) { foreach ($hosts as $h) {
$host = strtoupper($h['HOSTNAME']); $host = strtoupper($h['HOSTNAME']);
$os = strtoupper($h['OS_TYPE']); $os = strtoupper($h['Type']);
$osver = strtoupper($h['OSVersion']);
if ($os == "AIX") { if ($os == "AIX") {
$taix++; $taix++;
@@ -220,6 +211,7 @@
echo "<tr><td><b>$host</b></td>"; echo "<tr><td><b>$host</b></td>";
echo "<td>$os</td>"; echo "<td>$os</td>";
echo "<td>$osver</td>";
echo "<td>" . $ts . "</td>"; echo "<td>" . $ts . "</td>";
if ($rc == 0 && (string)$rc <> "") { if ($rc == 0 && (string)$rc <> "") {
echo "<td class='table-success'>" . $rc . "</td>"; echo "<td class='table-success'>" . $rc . "</td>";

View File

@@ -30,7 +30,6 @@
<body class="bg-light text-dark"> <body class="bg-light text-dark">
<?php include $_SERVER['DOCUMENT_ROOT'] . "/include/all.php"; ?> <!-- Include All --> <?php include $_SERVER['DOCUMENT_ROOT'] . "/include/all.php"; ?> <!-- Include All -->
<?php include $_SERVER['DOCUMENT_ROOT'] . "/include/all.php"; ?> <!-- Database connexion -->
<div class="container-fluid"> <div class="container-fluid">
<div class="row flex-nowrap"> <div class="row flex-nowrap">
<!-- Left NAVBAR --> <!-- Left NAVBAR -->

View File

@@ -259,27 +259,78 @@
return $pdo; 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 // IP client: XFF (première IP) -> fallback REMOTE_ADDR
$secretKey = 'impossibleatrouvercommeca'; $ip = '';
$remoteUser = $_SERVER['REMOTE_USER'] ?? null; if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
if ($remoteUser) { $parts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$expiration = time() + 3600; // Token is valid for 1 hour $cand = trim($parts[0]);
$payload = base64_encode($remoteUser . '|' . $expiration); // Combine user and expiration if (filter_var($cand, FILTER_VALIDATE_IP)) $ip = $cand;
$signature = hash_hmac('sha256', $payload, $secretKey); }
$cookieValue = $payload . '.' . $signature; if (!$ip && !empty($_SERVER['REMOTE_ADDR'])) $ip = $_SERVER['REMOTE_ADDR'];
// Set the cookie // User Windows (SSO)
setcookie('AuthToken', $cookieValue, [ $user = $_SERVER['REMOTE_USER'] ?? null;
'expires' => time() + 3600, $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 dutilisateur → 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' => '/', 'path' => '/',
'domain' => '.appliarmony.net', 'domain' => $cookieDomain,
'secure' => false, // true quand HTTPS 'secure' => $secureFlag,
'httponly' => true, 'httponly' => $httpOnly,
'samesite' => 'Lax' 'samesite' => $sameSite
]); ]);
} }
}
// --- exposer des constantes pour le reste du code ---
// Priorité: si on a REMOTE_USER on lutilise; 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();
?> ?>