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,6 +1,48 @@
<?php
header('Content-Type: application/json');
include $_SERVER['DOCUMENT_ROOT'] . "/include/all.php";
header('Content-Type: application/json');
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'])) {
$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%'";