From 6d36af04486e365bb131a17c12238703e000890d Mon Sep 17 00:00:00 2001 From: jhartworks Date: Thu, 19 Mar 2026 14:24:12 +0100 Subject: [PATCH] Refactor SQL ID checks in MonitoringServer class to improve validation logic and ensure proper database connection handling --- Monitoring Server Influx V1/module.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Monitoring Server Influx V1/module.php b/Monitoring Server Influx V1/module.php index 27f8952..96ebd18 100644 --- a/Monitoring Server Influx V1/module.php +++ b/Monitoring Server Influx V1/module.php @@ -429,17 +429,18 @@ class MonitoringServer extends IPSModule { $tdOld = $this->ReadAttributeString("AtAlarmtable"); $td = $tdOld; - if ($idSql > 1 && $idSql != 12345){ - MySQL_Open($idSql); + if ($idSql > 0 && IPS_InstanceExists($idSql)){ + MySQL_Open($idSql); - // === Helfer: Escaping für Strings === - if (function_exists('MySQL_RealEscapeString')) { - $esc = fn(string $s) => MySQL_RealEscapeString($idSql, $s); - } else { - // Fallback, falls Modul-Funktion nicht verfügbar ist - $esc = fn(string $s) => addslashes($s); - } + // === Helfer: Escaping für Strings === + if (function_exists('MySQL_RealEscapeString')) { + $esc = fn(string $s) => MySQL_RealEscapeString($idSql, $s); + } else { + // Fallback, falls Modul-Funktion nicht verfügbar ist + $esc = fn(string $s) => addslashes($s); + } + } $time = date("Y-m-d H:i:s"); @@ -538,7 +539,7 @@ class MonitoringServer extends IPSModule { )", $esc($smname), $esc($phonenumber) ); - if ($idSql > 1 && $idSql != 12345){ + if ($idSql > 0 && IPS_InstanceExists($idSql)){ // === Ausführen === @@ -615,7 +616,7 @@ class MonitoringServer extends IPSModule { (int)$mail, $esc($email_address), (int)$mailed, (int)$push ); - if ($idSql > 1 && $idSql != 12345){ + if ($idSql > 0 && IPS_InstanceExists($idSql)){ // === Ausführen === $ok = MySQL_ExecuteSimple($idSql, $sql); if (!$ok) {