Refactor SQL ID checks in MonitoringServer class to improve validation logic and ensure proper database connection handling

This commit is contained in:
jhartworks
2026-03-19 14:24:12 +01:00
parent 4fcaeb2010
commit 6d36af0448
+12 -11
View File
@@ -429,17 +429,18 @@ class MonitoringServer extends IPSModule {
$tdOld = $this->ReadAttributeString("AtAlarmtable"); $tdOld = $this->ReadAttributeString("AtAlarmtable");
$td = $tdOld; $td = $tdOld;
if ($idSql > 1 && $idSql != 12345){ if ($idSql > 0 && IPS_InstanceExists($idSql)){
MySQL_Open($idSql); MySQL_Open($idSql);
// === Helfer: Escaping für Strings === // === Helfer: Escaping für Strings ===
if (function_exists('MySQL_RealEscapeString')) { if (function_exists('MySQL_RealEscapeString')) {
$esc = fn(string $s) => MySQL_RealEscapeString($idSql, $s); $esc = fn(string $s) => MySQL_RealEscapeString($idSql, $s);
} else { } else {
// Fallback, falls Modul-Funktion nicht verfügbar ist // Fallback, falls Modul-Funktion nicht verfügbar ist
$esc = fn(string $s) => addslashes($s); $esc = fn(string $s) => addslashes($s);
} }
} }
$time = date("Y-m-d H:i:s"); $time = date("Y-m-d H:i:s");
@@ -538,7 +539,7 @@ class MonitoringServer extends IPSModule {
)", )",
$esc($smname), $esc($phonenumber) $esc($smname), $esc($phonenumber)
); );
if ($idSql > 1 && $idSql != 12345){ if ($idSql > 0 && IPS_InstanceExists($idSql)){
// === Ausführen === // === Ausführen ===
@@ -615,7 +616,7 @@ class MonitoringServer extends IPSModule {
(int)$mail, $esc($email_address), (int)$mailed, (int)$mail, $esc($email_address), (int)$mailed,
(int)$push (int)$push
); );
if ($idSql > 1 && $idSql != 12345){ if ($idSql > 0 && IPS_InstanceExists($idSql)){
// === Ausführen === // === Ausführen ===
$ok = MySQL_ExecuteSimple($idSql, $sql); $ok = MySQL_ExecuteSimple($idSql, $sql);
if (!$ok) { if (!$ok) {