From 5d01e6da14852878ab76746c27818f44d1955bae Mon Sep 17 00:00:00 2001 From: sva-e025532 Date: Wed, 13 Aug 2025 09:38:16 +0200 Subject: [PATCH] Replace deprecated `instr` function with `str_contains` and add `include/global.php` for central configurations. --- Hyper-V/clusters.php | 4 +- Inventory/Server-Detail.php | 6 +- Shared-Folders/HomeDirectories.php | 141 +------------- X/Inventory.php | 4 +- include/function.inc.php | 8 - include/global.php | 290 +++++++++++++++++++++++++++++ include/modal_wait.html | 2 +- reports/HomeDirectories.php | 2 +- 8 files changed, 301 insertions(+), 156 deletions(-) create mode 100644 include/global.php diff --git a/Hyper-V/clusters.php b/Hyper-V/clusters.php index 81479c7..bc0fe29 100644 --- a/Hyper-V/clusters.php +++ b/Hyper-V/clusters.php @@ -72,7 +72,7 @@ $vm_mem += $d['vm_memory']; $node_mem = (int) $d['node_ram']; foreach (explode("|", $d['csvs']) as $csv) { - if (instr($csv, ';')) { + if (str_contains($csv, ';')) { $free += intval(explode(";", $csv)[1]) - intval(explode(";", $csv)[2]); $disk = max($disk, $free); $capacity += (int) explode(";", $csv)[1]; @@ -112,7 +112,7 @@ $Repart = Invoke_Infra("select Owner, count(owner) as nbvm from cmdb_vms where Cluster ='".$cluster['cluster']."' and decomtime is null group by Owner order by Owner"); $vmCountNode1 = $vmCountNode2 = 0; $node1_name = $node2_name = ""; - if(count($Repart) == 1 ){ + if(isset($Repart) && count($Repart) == 1 ){ $node1_name = $Repart[0]['Owner']; $vmCountNode1 = $Repart[0]['nbvm']; }else{ $node1_name = 'DUN'; $vmCountNode1 = $Repart[0]['nbvm']; diff --git a/Inventory/Server-Detail.php b/Inventory/Server-Detail.php index cef4df1..88d1701 100644 --- a/Inventory/Server-Detail.php +++ b/Inventory/Server-Detail.php @@ -66,7 +66,7 @@ if($OSType == "AIX"){ $memory = round(str_replace(" Mo","",$Qx[0]['Memory'])/1024,2)." GB"; }else{ - $memory = $Qvm[0]['Memory']; + $memory = $Qvm[0]['Memory'] ?? $Qx[0]['Memory'] ; } } echo ""; @@ -198,8 +198,8 @@ foreach($drives as $drive){ echo "
"; $data = explode(",",$drive); - echo "
".$data[0]." : ".round($data[2])."/".$data[1]." GB
"; - $pcent = ($data[1] - $data[2])/$data[1]*100; + echo "
".$data[0]." : ".round(intval($data[2]))."/".$data[1]." GB
"; + $pcent = (intval($data[1]) - intval($data[2]))/intval($data[1])*100; $pcent_restant = 100 - $pcent; if($pcent <= 5){ $color = "bg-danger"; $border = "red"; diff --git a/Shared-Folders/HomeDirectories.php b/Shared-Folders/HomeDirectories.php index c6b8d1a..50d6aee 100644 --- a/Shared-Folders/HomeDirectories.php +++ b/Shared-Folders/HomeDirectories.php @@ -31,6 +31,7 @@ ?";}else{$acl="".$answer['acl']."";} + if(str_contains($answer['acl'],"S-1-5")){$acl="?";}else{$acl="".$answer['acl']."";} if($answer['enabled'] != 'True'){$enabled="N";}else{$enabled="Y";} if($answer['cn'] == ''){$inAD="N";}else{$inAD="Y";} if($answer['o365'] != 'N'){$o365="".$answer['o365']."";}else{$o365="N";} @@ -118,141 +119,3 @@ - - - - - - - - - - - Web Infra Reports IT - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- -
- -
- -
- -

Project and Team folders ( entries)

Updated every day at 07:00:00
- - -
- - - -
- - - - - - - - - - - - - - - "; - }else{ - echo ""; - } - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - } - ?> - -
ServerFolderTypeACLQuotaSizeEffective Users
".$answer['server']."".$answer['folder']."".$answer['typ']."".$answer['acl']."".$answer['quota']."".$answer['size']."".$answer['users']."
-
-
-
- -
-
-
- - - - - \ No newline at end of file diff --git a/X/Inventory.php b/X/Inventory.php index 9fc0052..a2b181a 100644 --- a/X/Inventory.php +++ b/X/Inventory.php @@ -28,7 +28,7 @@ - + = 20){ + if($size >= 15){ $size = "$size GB"; }else{ $size = "$size GB"; diff --git a/include/function.inc.php b/include/function.inc.php index b3460fd..7d55488 100644 --- a/include/function.inc.php +++ b/include/function.inc.php @@ -1,13 +1,5 @@ ['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 PostJson($url, $content){ + $curl = curl_init($url); + curl_setopt($curl, CURLOPT_HEADER, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json")); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $content); + $retour = curl_exec($curl); + curl_close($curl); + return $retour; + } + + //invoke// + function Invoke_WebSelfInfra($request) + { + $user = "Scom-Write"; + $pwd = decypher("web-self-infra"); + $server = "DUN-PRD-R1SCOM.armony.net\OPS"; + $database = "web-self-infra"; + $conn = odbc_connect("Driver={SQL Server};Server=$server;Database=$database;", $user, $pwd); + if (!($conn)) { + echo "Pas de connexion"; + } + $rs = odbc_exec($conn, $request); + if (str_contains(strtoupper($request), "SELECT")) { + while ($row = odbc_fetch_array($rs)) { + $answer[] = $row; + } + } + return $answer ?? null; + } + function Invoke_SCOMInfra($request) + { + $user = "Scom-Write"; + $pwd = decypher("ScomInfra"); + $server = "DUN-PRD-R1SCOM.armony.net\OPS"; + $database = "infra"; + $conn = odbc_connect("Driver={SQL Server};Server=$server;Database=$database;", $user, $pwd); + if (!($conn)) { + echo "Pas de connexion"; + } + $rs = odbc_exec($conn, $request); + if (str_contains(strtoupper($request), "SELECT")) { + while ($row = odbc_fetch_array($rs)) { + $answer[] = $row; + } + } + return $answer ?? null; + } + function Invoke_Entry01($request) + { + $user = "infra"; + $pwd = decypher("entry01"); + $server = "dun-sup-entry01:3306"; + $database = "infra"; + $conn = new mysqli($server, $user, $pwd, $database); + $rs = $conn->query($request); + while ($row = mysqli_fetch_array($rs)) { + $answer[] = $row; + } + return $answer ?? null; + } + function Invoke_WebInfraTools($request) + { + $user = "admin"; + $pwd = decypher("web-infra-tools"); + $server = "dun-sup-s2entry.armony.net:3306"; + $database = "webinfratools"; + $conn = new mysqli($server, $user, $pwd, $database); + $rs = $conn->query($request); + while ($row = mysqli_fetch_array($rs)) { + $answer[] = $row; + } + return $answer ?? null; + } + function Invoke_WebInfraReports($request) + { + $user = "admin"; + $pwd = decypher("web-infra-reports"); + $server = "dun-sup-s2entry.armony.net:3306"; + $database = "web-infra-reports"; + $conn = new mysqli($server, $user, $pwd, $database); + $rs = $conn->query($request); + while ($row = mysqli_fetch_array($rs)) { + $answer[] = $row; + } + return $answer ?? null; + + } + + function Invoke_Infra($request) + { + error_reporting(E_ALL ^ E_WARNING); + $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); + if (!($conn)) { + echo "Pas de connexion"; + } + $rs = odbc_exec($conn, $request); + if (str_contains(strtoupper($request), "SELECT")) { + while ($row = odbc_fetch_array($rs)) { + $answer[] = $row; + } + } + if (isset($answer)) { + return $answer; + } else { + if ($rs) { + return "OK"; + } else { + error_reporting(E_ALL); + return "ERROR : " . odbc_errormsg($conn); + } + } + + } + function Invoke_aixcmdb($request) + { + $conn_string = "DRIVER={IBM DB2 ODBC DRIVER - F_DB2_clidriver};" . + "DATABASE=AIXCMDB; " . + "HOSTNAME=db2_aixcmdb.appliarmony.net;" . + "PORT=50000; " . + "PROTOCOL=TCPIP; " . + "UID=aixcmdb;" . + "AUTHENTICATION=SERVER;" . + "PWD=".decypher('aixcmdb').";"; + + $conn = odbc_connect($conn_string, "", ""); + if (!$conn) { + $error_message = "ODBC Connect Error: " . odbc_errormsg() . " (" . odbc_error() . ")"; + echo "Pas de connexion : " . $error_message . "
"; + return "ERROR: Could not connect to DB2. Check connection string and ODBC setup."; + } + $rs = odbc_exec($conn, $request); + if (str_contains(strtoupper($request), "SELECT")) { + $answer = []; + while ($row = odbc_fetch_array($rs)) { + $answer[] = $row; + } + } + if (isset($answer)) { + return $answer; + } else { + if ($rs) { + return "OK"; + } else { + error_reporting(E_ALL); + return "ERROR : " . odbc_errormsg($conn); + } + } + } + function Invoke_GLPI($request) + { + $user="glpi_lect_seule"; + $pwd=decypher("glpi"); + $server="srvv-n4glpi-aim.process.dkm"; + $server="mys_glpi_prod.appliarmony.net"; + $database="glpi"; + $conn = new mysqli($server, $user, $pwd, $database); + if (!($conn)) { + echo "Pas de connexion"; + } + $rs = $conn->query($request); + while ($row = mysqli_fetch_array($rs)) { + $answer[] = $row; + } + if (isset($answer)) { + return $answer; + } + } + + //DB Conn// + function DB_SCCM(){ + $user = "infra"; + $pwd = decypher("SCCM"); + $conn = odbc_connect("Driver={SQL Server};Server=DUN-SMS-SRV01;Database=CM_SV1;", $user, $pwd); + return $conn; + } + function DB_GLPI() { + $username="glpi_lect_seule"; + $password=decypher( "glpi"); + $dbserver="mys_glpi_prod.appliarmony.net"; + $database="glpi"; + $conn = new mysqli($dbserver,$username,$password,$database); + return $conn; + } + function DB_ENTRY01() { + $username="infra"; + $password=decypher("entry01"); + $dbserver="dun-sup-entry01.armony.net"; + $database="infra"; + $conn = new mysqli($dbserver,$username,$password,$database); + return $conn; + } + function DB_ENTRY02() { + $username="admin"; + $password=decypher("web-infra-reports"); + $dbserver="dun-sup-s2entry.armony.net"; + $database="web-infra-reports"; + $conn = new mysqli($dbserver,$username,$password,$database); + return $conn ; + } + 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 ; + } + 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; + } + +?> + +//HTML// + + \ No newline at end of file diff --git a/include/modal_wait.html b/include/modal_wait.html index 03be9f7..e1d96f4 100644 --- a/include/modal_wait.html +++ b/include/modal_wait.html @@ -5,7 +5,7 @@