Refactor and enhance code readability across multiple components

- Updated SQL query in `VMs-Backups.php` to include `policy` condition.
- Improved formatting and indentation in `StdOut-detail.php`, `StdOut.php`, and `Server-Detail.php`.
- Simplified conditional checks and removed redundant spaces for better clarity.
- Modified `.idea/sqldialects.xml` file to add new SQL dialect mappings.
This commit is contained in:
e025532
2025-06-26 09:44:43 +02:00
parent f1aebef05b
commit b19795f421
5 changed files with 204 additions and 141 deletions

2
.idea/sqldialects.xml generated
View File

@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="SqlDialectMappings"> <component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/X/StdOut.php" dialect="GenericSQL" />
<file url="file://$PROJECT_DIR$/crossover/GlobalCrossover2.php" dialect="GenericSQL" /> <file url="file://$PROJECT_DIR$/crossover/GlobalCrossover2.php" dialect="GenericSQL" />
<file url="PROJECT" dialect="GenericSQL" />
</component> </component>
</project> </project>

View File

@@ -83,7 +83,7 @@
<?php <?php
// NO Backup or Backup with Errors // NO Backup or Backup with Errors
$er = 0; $er = 0;
$answers = Invoke_infra("SELECT * FROM VMs_Backup where ( Owner like 'DUN-VMH%' or Owner like 'MDK-VMH%' ) and name not like 'WS%' and owner not like '%WKG%' and owner not like '%VMH-WM%' and Exclusion ='' and (LastResult <> 'OK' or lastresult is null) order by lastresult,name"); $answers = Invoke_infra("SELECT * FROM VMs_Backup where ( Owner like 'DUN-VMH%' or Owner like 'MDK-VMH%' ) and name not like 'WS%' and owner not like '%WKG%' and owner not like '%VMH-WM%' and Exclusion ='' and (LastResult <> 'OK' or lastresult is null) and policy is not null order by lastresult,name");
foreach ($answers as $row) { foreach ($answers as $row) {
$er++; $er++;
$date1 = date_create($row['LastKnownGood']); $diff = date_diff($date1, date_create(date("Y-m-d"))); $date1 = date_create($row['LastKnownGood']); $diff = date_diff($date1, date_create(date("Y-m-d")));

View File

@@ -95,7 +95,7 @@
echo "</div></div></body></HTML>"; echo "</div></div></body></HTML>";
exit; exit;
} }
if(strpos($Qw[0]['DECOM'],'-') != false || strpos($Qx[0]['Decom'],'-') != false){ if(strpos($Qw[0]['DECOM'], '-') || strpos($Qx[0]['Decom'], '-')){
echo '<h1><span class="badge text-bg-danger font-weight-bold blinking" style="width:100%;">'. strtoupper($server) .' : DECOMMISSIONED !</span></h1>'; echo '<h1><span class="badge text-bg-danger font-weight-bold blinking" style="width:100%;">'. strtoupper($server) .' : DECOMMISSIONED !</span></h1>';
echo '<script src="/js/switch.js"></script>'; echo '<script src="/js/switch.js"></script>';
echo "</div></div></body></HTML>"; echo "</div></div></body></HTML>";
@@ -124,6 +124,7 @@
$site = substr($Qx[0]['Owner'],0,3); $site = substr($Qx[0]['Owner'],0,3);
}else{ }else{
echo "&nbsp;<span class='badge rounded-pill bg-success text-light'>Physical</span>"; echo "&nbsp;<span class='badge rounded-pill bg-success text-light'>Physical</span>";
echo "&nbsp;<span class='badge rounded-pill bg-success text-light'>".Invoke_GLPI("select a.name from glpi_computermodels a left join glpi_computers b on a.id = b.computermodels_id where b.name = '$server'")[0]['name']."</span>";
} }
} }
?> ?>
@@ -242,17 +243,17 @@
<!-- Last boot, last rollup, next rollup --> <!-- Last boot, last rollup, next rollup -->
<?php <?php
if(is_array($Qw)){ if(is_array($Qw)){
if(strpos($Qw[0]['zabbix'],'.') != false){ if(strpos($Qw[0]['zabbix'], '.')){
echo "<span class='badge rounded-pill bg-secondary text-light fs-5'>Zabbix : ".$Qw[0]['zabbix']."</span>"; echo "<span class='badge rounded-pill bg-secondary text-light fs-5'>Zabbix : ".$Qw[0]['zabbix']."</span>";
}else{ }else{
echo "<span class='badge rounded-pill bg-warning text-dark fs-5'>Zabbix : Not Installed</span>"; echo "<span class='badge rounded-pill bg-warning text-dark fs-5'>Zabbix : Not Installed</span>";
} }
if(strpos($Qw[0]['sentinel'],'.') != false){ if(strpos($Qw[0]['sentinel'], '.')){
echo "&nbsp;<span class='badge rounded-pill bg-secondary text-light fs-5'>SentinelOne : ".$Qw[0]['sentinel']."</span>"; echo "&nbsp;<span class='badge rounded-pill bg-secondary text-light fs-5'>SentinelOne : ".$Qw[0]['sentinel']."</span>";
}else{ }else{
echo "&nbsp;<span class='badge rounded-pill bg-warning text-dark fs-5'>SentinelOne : Not Installed</span>"; echo "&nbsp;<span class='badge rounded-pill bg-warning text-dark fs-5'>SentinelOne : Not Installed</span>";
} }
if(strpos($Qw[0]['zabbix'],'.') != false){ if(strpos($Qw[0]['zabbix'], '.')){
echo "&nbsp;<span class='badge rounded-pill bg-secondary text-light fs-5'>Nessus : ".$Qw[0]['nessus']."</span>"; echo "&nbsp;<span class='badge rounded-pill bg-secondary text-light fs-5'>Nessus : ".$Qw[0]['nessus']."</span>";
}else{ }else{
echo "&nbsp;<span class='badge rounded-pill bg-warning text-dark fs-5'>Nessus : Not Installed</span>"; echo "&nbsp;<span class='badge rounded-pill bg-warning text-dark fs-5'>Nessus : Not Installed</span>";
@@ -260,19 +261,19 @@
} }
if(is_array($Qx)){ if(is_array($Qx)){
$a = Invoke_Infra("select * from X_cmdb_Product where HOSTNAME='$server' and Name ='zabbix'"); $a = Invoke_Infra("select * from X_cmdb_Product where HOSTNAME='$server' and Name ='zabbix'");
if(is_array($a) && strpos($a[0]['Ver'],'.') != false){ if(is_array($a) && strpos($a[0]['Ver'], '.')){
echo "<span class='badge rounded-pill bg-secondary text-light fs-5'>Zabbix : ".$a[0]['Ver']." - ".$a[0]['State']."</span>"; echo "<span class='badge rounded-pill bg-secondary text-light fs-5'>Zabbix : ".$a[0]['Ver']." - ".$a[0]['State']."</span>";
}else{ }else{
echo "<span class='badge rounded-pill bg-warning text-dark fs-5'>Zabbix : Not Installed</span>"; echo "<span class='badge rounded-pill bg-warning text-dark fs-5'>Zabbix : Not Installed</span>";
} }
$a = Invoke_Infra("select * from X_cmdb_Product where HOSTNAME='$server' and Name ='s1'"); $a = Invoke_Infra("select * from X_cmdb_Product where HOSTNAME='$server' and Name ='s1'");
if(is_array($a) && strpos($a[0]['Ver'],'.') != false){ if(is_array($a) && strpos($a[0]['Ver'], '.')){
echo "&nbsp;<span class='badge rounded-pill bg-secondary text-light fs-5'>SentinelOne : ".$a[0]['Ver']." - ".$a[0]['State']."</span>"; echo "&nbsp;<span class='badge rounded-pill bg-secondary text-light fs-5'>SentinelOne : ".$a[0]['Ver']." - ".$a[0]['State']."</span>";
}else{ }else{
echo "&nbsp;<span class='badge rounded-pill bg-warning text-dark fs-5'>SentinelOne : Not Installed</span>"; echo "&nbsp;<span class='badge rounded-pill bg-warning text-dark fs-5'>SentinelOne : Not Installed</span>";
} }
$a = Invoke_Infra("select * from X_cmdb_Product where HOSTNAME='$server' and Name ='nessus'"); $a = Invoke_Infra("select * from X_cmdb_Product where HOSTNAME='$server' and Name ='nessus'");
if(is_array($a) && strpos($a[0]['Ver'],'.') != false){ if(is_array($a) && strpos($a[0]['Ver'], '.')){
echo "&nbsp;<span class='badge rounded-pill bg-secondary text-light fs-5'>Nessus : ".$a[0]['Ver']." - ".$a[0]['State']."</span>"; echo "&nbsp;<span class='badge rounded-pill bg-secondary text-light fs-5'>Nessus : ".$a[0]['Ver']." - ".$a[0]['State']."</span>";
}else{ }else{
echo "&nbsp;<span class='badge rounded-pill bg-warning text-dark fs-5'>Nessus : Not Installed</span>"; echo "&nbsp;<span class='badge rounded-pill bg-warning text-dark fs-5'>Nessus : Not Installed</span>";

View File

@@ -41,22 +41,25 @@
<!-- Display --> <!-- Display -->
<div class="col py-3"> <div class="col py-3">
<!-- Page Title --> <!-- Page Title -->
<h1><span class="badge text-bg-secondary font-weight-bold" style="width:100%;">Script <b><?php echo $script; ?></b> Details</span></h1> <h1><span class="badge text-bg-secondary font-weight-bold"
style="width:100%;">Script <b><?php echo $script; ?></b> Details</span></h1>
<!-- Main content --> <!-- Main content -->
<div class="container-fluid"> <div class="container-fluid">
<!-- MODAL WAIT --> <!-- MODAL WAIT -->
<div class="modal fade bs-example-modal-sm" id="wait" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" style="padding-top: 15%;"> <div class="modal fade bs-example-modal-sm" id="wait" tabindex="-1" role="dialog" aria-hidden="true"
data-backdrop="static" style="padding-top: 15%;">
<div class="modal-dialog modal-sm"> <div class="modal-dialog modal-sm">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h4 class="modal-title mb-1 text-dark text-uppercase"> <h4 class="modal-title mb-1 text-dark text-uppercase text-center" style="font-size: 1.2rem;">
<center><i class="bi bi-hourglass-split"></i><br> Work in progress ...</center> <i class="bi bi-hourglass-split"></i><br> Work in progress ...
</h4> </h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="progress"> <div class="progress">
<div class="progress-bar progress-bar-secondary progress-bar-striped progress-bar-animated" style="width: 100%"></div> <div class="progress-bar progress-bar-secondary progress-bar-striped progress-bar-animated"
style="width: 100%"></div>
</div> </div>
</div> </div>
</div> </div>
@@ -67,13 +70,53 @@
<?php // DATA <?php // DATA
$aix = $linux = $dun = $azt = $other = "Checked"; $aix = $linux = $dun = $azt = $other = "Checked";
$where = " and OS_TYPE IN ("; $where = " and OS_TYPE IN (";
if (isset($_GET['AIX'])) {if ($_GET['AIX'] == 1) {$aix = "Checked"; $where .= "'AIX',";} else {$aix = "Unchecked";}} else {$aix = "Unchecked";} if (isset($_GET['AIX'])) {
if (isset($_GET['linux'])) {if ($_GET['linux'] == 1) {$linux = "Checked"; $where .= "'LINUX',";} else {$linux = "Unchecked";}} else {$linux = "Unchecked";} if ($_GET['AIX'] == 1) {
$where .= "'AIX',";
} else {
$aix = "Unchecked";
}
} else {
$aix = "Unchecked";
}
if (isset($_GET['linux'])) {
if ($_GET['linux'] == 1) {
$where .= "'LINUX',";
} else {
$linux = "Unchecked";
}
} else {
$linux = "Unchecked";
}
$where = rtrim($where, ',') . ")"; $where = rtrim($where, ',') . ")";
$site = ""; $site = "";
if (isset($_GET['DUN'])) {if ($_GET['DUN'] == 1) {$dun = "Checked"; $site .= " or UPPER(HOSTNAME) like 'DUN%' or UPPER(HOSTNAME) like 'DMV%' or UPPER(HOSTNAME) like 'MDK%' or UPPER(HOSTNAME) like 'APPQPC%'";} else {$dun = "Unchecked";}} else {$dun = "Unchecked";} if (isset($_GET['DUN'])) {
if (isset($_GET['AZT'])) {if ($_GET['AZT'] == 1) {$azt = "Checked"; $site .=" or UPPER(HOSTNAME) like 'AZT%'";} else {$azt = "Unchecked";}} else {$azt = "Unchecked";} if ($_GET['DUN'] == 1) {
if (isset($_GET['other'])) {if ($_GET['other'] == 1) {$other = "Checked"; $site .=" or UPPER(HOSTNAME) like 'BAD%' or UPPER(HOSTNAME) like 'FLO%' or UPPER(HOSTNAME) like 'MON%'";} else {$other = "Unchecked";}} else {$other = "Unchecked";} $site .= " or UPPER(HOSTNAME) like 'DUN%' or UPPER(HOSTNAME) like 'DMV%' or UPPER(HOSTNAME) like 'MDK%' or UPPER(HOSTNAME) like 'APPQPC%'";
} else {
$dun = "Unchecked";
}
} else {
$dun = "Unchecked";
}
if (isset($_GET['AZT'])) {
if ($_GET['AZT'] == 1) {
$site .= " or UPPER(HOSTNAME) like 'AZT%'";
} else {
$azt = "Unchecked";
}
} else {
$azt = "Unchecked";
}
if (isset($_GET['other'])) {
if ($_GET['other'] == 1) {
$site .= " or UPPER(HOSTNAME) like 'BAD%' or UPPER(HOSTNAME) like 'FLO%' or UPPER(HOSTNAME) like 'MON%'";
} else {
$other = "Unchecked";
}
} else {
$other = "Unchecked";
}
$site = " and (" . ltrim($site, ' or') . ") "; $site = " and (" . ltrim($site, ' or') . ") ";
$where .= $site; $where .= $site;
@@ -89,31 +132,31 @@
<div class="form-check form-check-inline form-switch"> <div class="form-check form-check-inline form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="AIX" <?php echo $aix; ?> <input class="form-check-input" type="checkbox" role="switch" id="AIX" <?php echo $aix; ?>
name="AIX" value="1"> name="AIX" value="1">
<label class="form-check-label" for="None">AIX</label> <label class="form-check-label" for="AIX">AIX</label>
</div> </div>
&nbsp; &nbsp;
<div class="form-check form-check-inline form-switch"> <div class="form-check form-check-inline form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="linux" <?php echo $linux; ?> <input class="form-check-input" type="checkbox" role="switch" id="linux" <?php echo $linux; ?>
name="linux" value="1"> name="linux" value="1">
<label class="form-check-label" for="Manu">Linux</label> <label class="form-check-label" for="linux">Linux</label>
</div> </div>
&nbsp; | &nbsp; &nbsp; | &nbsp;
<div class="form-check form-check-inline form-switch"> <div class="form-check form-check-inline form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="DUN" <?php echo $dun; ?> <input class="form-check-input" type="checkbox" role="switch" id="DUN" <?php echo $dun; ?>
name="DUN" value="1"> name="DUN" value="1">
<label class="form-check-label" for="Done">DMV/DUN/MDK</label> <label class="form-check-label" for="DUN">DMV/DUN/MDK</label>
</div> </div>
&nbsp; &nbsp;
<div class="form-check form-check-inline form-switch"> <div class="form-check form-check-inline form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="AZT" <?php echo $azt; ?> <input class="form-check-input" type="checkbox" role="switch" id="AZT" <?php echo $azt; ?>
name="AZT" value="1"> name="AZT" value="1">
<label class="form-check-label" for="Done">Azure</label> <label class="form-check-label" for="AZT">Azure</label>
</div> </div>
&nbsp; &nbsp;
<div class="form-check form-check-inline form-switch"> <div class="form-check form-check-inline form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="other" <?php echo $other; ?> <input class="form-check-input" type="checkbox" role="switch" id="other" <?php echo $other; ?>
name="other" value="1"> name="other" value="1">
<label class="form-check-label" for="Done">Other</label> <label class="form-check-label" for="other">Other</label>
</div> </div>
<input type="hidden" name="s" value="<?php echo $script; ?>"> <input type="hidden" name="s" value="<?php echo $script; ?>">
<button type="submit" class="btn btn-success btn-small mb-2 mt-2">Apply</button> <button type="submit" class="btn btn-success btn-small mb-2 mt-2">Apply</button>
@@ -121,9 +164,9 @@
</form> </form>
<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']"
<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"> data-show-export="true" data-sortable="true" data-sort-name="vm">
<thead> <!-- Header --> <thead> <!-- Header -->
<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>
@@ -137,16 +180,32 @@
foreach ($hosts as $h) { foreach ($hosts as $h) {
$host = strtoupper($h['HOSTNAME']); $host = strtoupper($h['HOSTNAME']);
$os = strtoupper($h['OS_TYPE']); $os = strtoupper($h['OS_TYPE']);
if(strtoupper($h['OS_TYPE']) == "AIX"){$taix++;}else{$tlinux++;} if (strtoupper($h['OS_TYPE']) == "AIX") {
$taix++;
} else {
$tlinux++;
}
$answer = Invoke_infra("SELECT * FROM x_stdout where cmd ='$script' and host ='$host'"); $answer = Invoke_infra("SELECT * FROM x_stdout where cmd ='$script' and host ='$host'");
if (is_array($answer)) { if (is_array($answer)) {
$rc = $answer[0]['rc']; $rc = $answer[0]['rc'];
$stdout = $answer[0]['stdout']; $stdout = $answer[0]['stdout'];
$ts = $answer[0]['ts']; $ts = $answer[0]['ts'];
if (strtoupper($h['OS_TYPE']) == "AIX") { if (strtoupper($h['OS_TYPE']) == "AIX") {
if($rc == 0 && (string)$rc <> ""){$aixok++;}else{if((string)$rc <> ""){$aixko++;}} if ($rc == 0 && (string)$rc <> "") {
$aixok++;
} else { } else {
if($rc == 0 && (string)$rc <> ""){$linuxok++;}else{if((string)$rc <> ""){$linuxko++;}} if ((string)$rc <> "") {
$aixko++;
}
}
} else {
if ($rc == 0 && (string)$rc <> "") {
$linuxok++;
} else {
if ((string)$rc <> "") {
$linuxko++;
}
}
} }
} else { } else {
$rc = $stdout = $ts = ""; $rc = $stdout = $ts = "";
@@ -158,7 +217,7 @@
echo "<td class='table-success'>" . $rc . "</td>"; echo "<td class='table-success'>" . $rc . "</td>";
} else { } else {
if ((string)$rc <> "") { if ((string)$rc <> "") {
echo "<td class='table-danger'>".(string)$rc."</td>"; echo "<td class='table-danger'>" . $rc . "</td>";
} else { } else {
echo "<td></td>"; echo "<td></td>";
} }
@@ -169,7 +228,8 @@
</tbody> </tbody>
<br> <br>
<?php <?php
$aixNO = $taix-$aixok-$aixko; $linuxNO=$tlinux-$linuxok-$linuxko; $aixNO = $taix - $aixok - $aixko;
$linuxNO = $tlinux - $linuxok - $linuxko;
echo "<div class='row'><div class='col text-center h4'><b>$taix AIX : </b>"; echo "<div class='row'><div class='col text-center h4'><b>$taix AIX : </b>";
echo "<span class='badge bg-success'>$aixok</span>&nbsp;<span class='badge bg-danger'>$aixko</span>&nbsp;<span class='badge bg-secondary'>$aixNO</span></div>"; echo "<span class='badge bg-success'>$aixok</span>&nbsp;<span class='badge bg-danger'>$aixko</span>&nbsp;<span class='badge bg-secondary'>$aixNO</span></div>";
echo "<div class='col text-center h4'><b>$tlinux Linux : </b>"; echo "<div class='col text-center h4'><b>$tlinux Linux : </b>";

View File

@@ -49,8 +49,8 @@
<div class="modal-dialog modal-sm"> <div class="modal-dialog modal-sm">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h4 class="modal-title mb-1 text-dark text-uppercase"> <h4 class="modal-title mb-1 text-dark text-uppercase text-center" style="font-size: 1.5rem;">
<center><i class="bi bi-hourglass-split"></i><br> Work in progress ...</center> <i class="bi bi-hourglass-split"></i><br> Work in progress ...
</h4> </h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">