From 4ba470d1d7207321e9b4691ec13a0fb6805ba363 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Fri, 17 Dec 2021 12:25:40 +0100
Subject: [PATCH 01/71] =?UTF-8?q?Fix=20f=C3=BCr=20Memory=20Leak?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
UniFi Internet Controller/README.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/UniFi Internet Controller/README.md b/UniFi Internet Controller/README.md
index 838641d..9a9fdd1 100644
--- a/UniFi Internet Controller/README.md
+++ b/UniFi Internet Controller/README.md
@@ -87,3 +87,7 @@ Version 1.0 - 09-09-2021
* Uptime
* UBNT Device Type
* UDM Version
+
+Version 1.1 - 17-12-2021
+* Fix - Memory Leak
+* Fix - HTTP Response Error Message
From ac4c37c7ed65167bc741027f5a41c1efc61f12eb Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Fri, 17 Dec 2021 12:26:24 +0100
Subject: [PATCH 02/71] =?UTF-8?q?fix=20f=C3=BCr=20memory=20leak?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
UniFi Device Blocker/module.php | 6 +++---
UniFi Internet Controller/module.php | 12 ++++++------
UniFi Presence Manager/README.md | 6 +++++-
UniFi Presence Manager/module.php | 4 ++--
library.json | 2 +-
5 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index 61ffaa7..d6fc97d 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -49,7 +49,7 @@ public function ApplyChanges() {
$DeviceName = $Device["varDeviceName"];
$DeviceNameClean = str_replace(array("-",":"," "), "", $DeviceName);
$this->MaintainVariable($DeviceNameClean, $DeviceName, vtBoolean, "~Switch", $vpos++, isset($DevicesJSON));
- SetValue($this->GetIDForIdent($DeviceNameClean),1); // make a device will not a disconnected when the module is initialized
+ $this->SetValue($this->GetIDForIdent($DeviceNameClean),1); // make a device will not a disconnected when the module is initialized
$this->EnableAction($DeviceNameClean);
@@ -112,12 +112,12 @@ public function AuthenticateAndProcessRequest() {
if (isset($results[1])) {
$Cookie = implode(';', $results[1]);
if (!empty($body)) {
- if (($code >= 200) && ($code < 400)) {
+ if ($code == 200) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
//$this->SetBuffer("Cookie",$Cookie);
}
- if ($code === 400 OR $code ) {
+ if ($code == 400) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Failure - We have received an HTTP response status: 400. Probably a controller login failure or no device is configured'),0);
}
diff --git a/UniFi Internet Controller/module.php b/UniFi Internet Controller/module.php
index d641498..ca14eae 100644
--- a/UniFi Internet Controller/module.php
+++ b/UniFi Internet Controller/module.php
@@ -157,13 +157,13 @@ public function AuthenticateAndGetData($UnifiAPI = "") {
if (isset($results[1])) {
$Cookie = implode(';', $results[1]);
if (!empty($body)) {
- if (($code >= 200) && ($code < 400)) {
+ if (($code == 200) && ($code != 400)) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
}
- //if ($code === 400 OR $code ) {
- // $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Failure - We have received an HTTP response status: 400. Probably a controller login failure'),0);
- //}
+ if ($code == 400) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Failure - We have received an HTTP response status: 400. Probably a controller login failure'),0);
+ }
}
}
@@ -185,8 +185,8 @@ public function AuthenticateAndGetData($UnifiAPI = "") {
$RawData = curl_exec($ch);
curl_close($ch);
- $JSON = json_decode($RawData,true);
- $this->SetBuffer("$RawData",$RawData);
+ //$JSON = json_decode($RawData,true);
+ //$this->SetBuffer("RawData",$RawData);
if (isset($RawData) AND $RawData != "Unauthorized") {
$this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Successfully Called"),0);
diff --git a/UniFi Presence Manager/README.md b/UniFi Presence Manager/README.md
index 241f688..d62a0c4 100644
--- a/UniFi Presence Manager/README.md
+++ b/UniFi Presence Manager/README.md
@@ -77,4 +77,8 @@ Version 0.31 (Beta) - 25-08-2021
* Neue Variable die bei jedem Update unabhängig vom Gerät aktualisiert wird
Version 1.0 - 09-09-2021
-* keine weiteren Änderungen
\ No newline at end of file
+* keine weiteren Änderungen
+
+Version 1.1 - 17-12-2021
+* Fix - Memory Leak
+* Fix - HTTP Response Error Message
\ No newline at end of file
diff --git a/UniFi Presence Manager/module.php b/UniFi Presence Manager/module.php
index dbefe87..45b4647 100644
--- a/UniFi Presence Manager/module.php
+++ b/UniFi Presence Manager/module.php
@@ -117,11 +117,11 @@ public function AuthenticateAndGetData() {
if (isset($results[1])) {
$Cookie = implode(';', $results[1]);
if (!empty($body)) {
- if (($code >= 200) && ($code < 400)) {
+ if (($code == 200) && ($code != 400)) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
}
- if ($code === 400 OR $code ) {
+ if ($code == 400) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Failure - We have received an HTTP response status: 400. Probably a controller login failure'),0);
}
diff --git a/library.json b/library.json
index 69e0c53..1324c6a 100644
--- a/library.json
+++ b/library.json
@@ -6,7 +6,7 @@
"compatibility": {
"version": "5.5"
},
- "version": "1.0",
+ "version": "1.1",
"build": 0,
"date": 0
}
From 6d2ad29d5075a2fc79452a1b1b07de8841aa3c20 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sat, 18 Dec 2021 11:26:27 +0100
Subject: [PATCH 03/71] 152 in presence manager - set buffer
---
UniFi Presence Manager/module.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Presence Manager/module.php b/UniFi Presence Manager/module.php
index 45b4647..c906218 100644
--- a/UniFi Presence Manager/module.php
+++ b/UniFi Presence Manager/module.php
@@ -149,8 +149,8 @@ public function AuthenticateAndGetData() {
$RawData = curl_exec($ch);
curl_close($ch);
- $JSON = json_decode($RawData,true);
- $this->SetBuffer("$RawData",$RawData);
+ //$JSON = json_decode($RawData,true);
+ //$this->SetBuffer("$RawData",$RawData);
if (isset($RawData) AND $RawData != "Unauthorized") {
$this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Successfully Called"),0);
From 3b69211ece5d83a189d721e3991408d9ded0f9a6 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sun, 19 Dec 2021 10:35:05 +0100
Subject: [PATCH 04/71] changes in Device Blocker improved handling of
variables
---
UniFi Device Blocker/module.php | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index d6fc97d..1f46364 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -48,15 +48,34 @@ public function ApplyChanges() {
foreach ($DevicesJSON as $Device) {
$DeviceName = $Device["varDeviceName"];
$DeviceNameClean = str_replace(array("-",":"," "), "", $DeviceName);
+
+ if (@IPS_GetObjectIDByIdent($DeviceNameClean, $this->InstanceID) == false) {
+
+ $DeviceNameCleanID = IPS_CreateVariable(0);
+ IPS_SetName($DeviceNameCleanID, $DeviceNameClean);
+ IPS_SetIdent($DeviceNameCleanID, $DeviceNameClean);
+ IPS_SetParent($DeviceNameCleanID, $this->InstanceID);
+
+ SetValue($DeviceNameCleanID,true);
+ $this->EnableAction($DeviceNameClean);
+ $this->RegisterMessage($DeviceNameCleanID, VM_UPDATE);
+
+ }
+
+ /*
+
$this->MaintainVariable($DeviceNameClean, $DeviceName, vtBoolean, "~Switch", $vpos++, isset($DevicesJSON));
- $this->SetValue($this->GetIDForIdent($DeviceNameClean),1); // make a device will not a disconnected when the module is initialized
+ $DeviceNameCleanID = @IPS_GetObjectIDByIdent($DeviceNameClean, $this->InstanceID);
+ SetValue($DeviceNameCleanID,true); // make a device will not a disconnected when the module is initialized
$this->EnableAction($DeviceNameClean);
- $DeviceNameCleanID = @IPS_GetObjectIDByIdent($DeviceNameClean, $this->InstanceID);
+ //$DeviceNameCleanID = @IPS_GetObjectIDByIdent($DeviceNameClean, $this->InstanceID);
if (IPS_GetObject($DeviceNameCleanID)['ObjectType'] == 2) {
$this->RegisterMessage($DeviceNameCleanID, VM_UPDATE);
}
+ */
+
}
}
}
@@ -115,7 +134,6 @@ public function AuthenticateAndProcessRequest() {
if ($code == 200) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
- //$this->SetBuffer("Cookie",$Cookie);
}
if ($code == 400) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Failure - We have received an HTTP response status: 400. Probably a controller login failure or no device is configured'),0);
@@ -137,7 +155,7 @@ public function AuthenticateAndProcessRequest() {
if (isset($DevicesJSON)) {
foreach ($DevicesJSON as $Device) {
if ($SenderName == $Device["varDeviceName"]) {
- $DeviceMacAdress = $Device["varDeviceMAC"];
+ $DeviceMacAdress = strtolower($Device["varDeviceMAC"]);
$this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Device to be blocked ").$Device["varDeviceName"].$this->Translate(" device from Sender ").$SenderName,0);
}
}
From d6fe56b0ee36f665caf5009489c08115595d29a0 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sun, 19 Dec 2021 10:59:27 +0100
Subject: [PATCH 05/71] lower case for presence mgr added
---
UniFi Presence Manager/module.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Presence Manager/module.php b/UniFi Presence Manager/module.php
index c906218..3944717 100644
--- a/UniFi Presence Manager/module.php
+++ b/UniFi Presence Manager/module.php
@@ -179,11 +179,11 @@ public function CheckPresence() {
foreach ($DevicesJSON as $Device) {
//Build a clean array out of the devices mentioned in the config form with : or -
- $DeviceMac = str_replace(array("-",":"), "", $Device["varDeviceMAC"]);
+ $DeviceMac = str_replace(array("-",":"), "", strtolower($Device["varDeviceMAC"]));
//Itterate through all device and check if one of them matches the list in the config form.
foreach ($ActiveDevices["data"] as $Index=>$Device) {
- $DeviceMacClean = str_replace(array("-",":"), "", $Device["mac"]);
+ $DeviceMacClean = strtolower(str_replace(array("-",":"), "", strtolower($Device["mac"])));
$OldPresenceValue = GetValue($this->GetIDForIdent($DeviceMac));
if ($DeviceMac == $DeviceMacClean) {
From 3b796acb53cc254ee2044df10bd9d2649e532fa6 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sun, 19 Dec 2021 11:37:10 +0100
Subject: [PATCH 06/71] removed lower in blocker
---
UniFi Device Blocker/module.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index 1f46364..d2edada 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -155,7 +155,7 @@ public function AuthenticateAndProcessRequest() {
if (isset($DevicesJSON)) {
foreach ($DevicesJSON as $Device) {
if ($SenderName == $Device["varDeviceName"]) {
- $DeviceMacAdress = strtolower($Device["varDeviceMAC"]);
+ $DeviceMacAdress = $Device["varDeviceMAC"];
$this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Device to be blocked ").$Device["varDeviceName"].$this->Translate(" device from Sender ").$SenderName,0);
}
}
From 6489b6e80a8d89c0ecc64d8229667b700976a91d Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sun, 19 Dec 2021 16:12:02 +0100
Subject: [PATCH 07/71] Remove blank removal
---
UniFi Device Blocker/module.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index d2edada..8a269c7 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -47,7 +47,7 @@ public function ApplyChanges() {
if (isset($DevicesJSON)) {
foreach ($DevicesJSON as $Device) {
$DeviceName = $Device["varDeviceName"];
- $DeviceNameClean = str_replace(array("-",":"," "), "", $DeviceName);
+ $DeviceNameClean = str_replace(array("-",":"), "", $DeviceName);
if (@IPS_GetObjectIDByIdent($DeviceNameClean, $this->InstanceID) == false) {
@@ -242,4 +242,4 @@ public function RequestAction($Ident, $Value) {
}
- }
\ No newline at end of file
+ }
From 53d6943b40ce39af6d1586067efb56b066fe4222 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sun, 19 Dec 2021 16:18:53 +0100
Subject: [PATCH 08/71] 50 added " "
---
UniFi Device Blocker/module.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index 8a269c7..9ad5f34 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -47,7 +47,7 @@ public function ApplyChanges() {
if (isset($DevicesJSON)) {
foreach ($DevicesJSON as $Device) {
$DeviceName = $Device["varDeviceName"];
- $DeviceNameClean = str_replace(array("-",":"), "", $DeviceName);
+ $DeviceNameClean = str_replace(array("-",":"," "), "", $DeviceName);
if (@IPS_GetObjectIDByIdent($DeviceNameClean, $this->InstanceID) == false) {
From 0159ea0b22a50e792b0027688c1f462bd5b0573b Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sun, 19 Dec 2021 16:46:32 +0100
Subject: [PATCH 09/71] Added note that no space or allowed in the DevName
---
UniFi Device Blocker/form.json | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/UniFi Device Blocker/form.json b/UniFi Device Blocker/form.json
index 0a9d9b3..862b1ef 100644
--- a/UniFi Device Blocker/form.json
+++ b/UniFi Device Blocker/form.json
@@ -74,6 +74,11 @@
"name": "Password",
"caption": "Password"
},
+ {
+ "type": "Label",
+ "bold": "true",
+ "label": "Device names must not contain a space - please use GardenCam without a space."
+ },
{
"type": "List",
"name": "Devices",
@@ -121,4 +126,4 @@
}
],
"status": []
-}
\ No newline at end of file
+}
From caa50136d8756b8e2af607ec69e17470dadaf43b Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sun, 19 Dec 2021 16:58:02 +0100
Subject: [PATCH 10/71] set profile type
---
UniFi Device Blocker/module.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index 9ad5f34..4044720 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -54,6 +54,7 @@ public function ApplyChanges() {
$DeviceNameCleanID = IPS_CreateVariable(0);
IPS_SetName($DeviceNameCleanID, $DeviceNameClean);
IPS_SetIdent($DeviceNameCleanID, $DeviceNameClean);
+ IPS_SetVariableCustomProfile($DeviceNameCleanID, "~Switch");
IPS_SetParent($DeviceNameCleanID, $this->InstanceID);
SetValue($DeviceNameCleanID,true);
From 53b67b9e087241df621a79a1c7a9c302199e62f7 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sun, 19 Dec 2021 17:00:26 +0100
Subject: [PATCH 11/71] added e.g. in 80
---
UniFi Device Blocker/form.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/UniFi Device Blocker/form.json b/UniFi Device Blocker/form.json
index 862b1ef..df901bf 100644
--- a/UniFi Device Blocker/form.json
+++ b/UniFi Device Blocker/form.json
@@ -77,7 +77,7 @@
{
"type": "Label",
"bold": "true",
- "label": "Device names must not contain a space - please use GardenCam without a space."
+ "label": "Device names must not contain a space - e.g. please use GardenCam without a space."
},
{
"type": "List",
From 1e71f3b49bc8da505a6e7294f02af5b4781eb53a Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sun, 19 Dec 2021 17:02:05 +0100
Subject: [PATCH 12/71] 18 added translation
---
UniFi Device Blocker/locale.json | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/UniFi Device Blocker/locale.json b/UniFi Device Blocker/locale.json
index 98d71e5..d18dc29 100644
--- a/UniFi Device Blocker/locale.json
+++ b/UniFi Device Blocker/locale.json
@@ -15,10 +15,11 @@
"Password": "Passwort",
"Update Frequency": "Aktualisierungsfrequenz",
"sec - 0 is off": "Sek - 0 ist Aus",
+ "Device names must not contain a space - e.g. please use GardenCam without a space.": "Gerätenamen dürfen keine Leerzeichen enthalten, bitte z.B. GartenKamera verwenden",
"Devices": "Geräte",
"Devicename": "Gerätename",
"MAC": "MAC",
"Test Authentication and Blocking": "Teste Anmeldung und Sperre"
}
}
-}
\ No newline at end of file
+}
From 7b843d62579f957885723e737fa69bc91afe618e Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sun, 19 Dec 2021 17:13:29 +0100
Subject: [PATCH 13/71] Added localization
---
UniFi Internet Controller/locale.json | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Internet Controller/locale.json b/UniFi Internet Controller/locale.json
index 2f24d05..18c2e4c 100644
--- a/UniFi Internet Controller/locale.json
+++ b/UniFi Internet Controller/locale.json
@@ -9,7 +9,7 @@
"All data will be stored in variables in the object tree.": "Alle Informationen werden im Objektbaum als Variable zur Verfügung gestellt.",
"Updates will happen on a schedule every xyz seconds.": "Das Module prüft die Anwensenheit alle xyz Sekunden, wie im Module konfiguriert",
"For debugging, please use the Debug function of the module.": "Für das Prüfen der Funktionen, gibt es Modul Meldungen im Debugbereich aus",
- "UniFi Toolbox - Internet Controller Configuration": "UniFi Toolbox - Internet Controller Konfiguration",
+ "UniFi Toolbox - Dream Maschine Internet Controller Configuration": "UniFi Toolbox - Dream Maschine Internet Controller Konfiguration",
"Controller Type": "Art des Controllers",
"Server Address": "Server Adresse",
"User Name": "Anmeldename",
@@ -41,4 +41,4 @@
" milliseconds": " Millisekunden"
}
}
-}
\ No newline at end of file
+}
From 8a927197027f0f567c48b0c282b0c77b63424863 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sun, 19 Dec 2021 21:04:01 +0100
Subject: [PATCH 14/71] add missing message sink at applychanges
---
UniFi Device Blocker/module.php | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index 4044720..ee5cd40 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -63,6 +63,12 @@ public function ApplyChanges() {
}
+ foreach ($DevicesJSON as $Device) {
+ $VarID = @IPS_GetObjectIDByIdent($Device["varDeviceName"], $this->InstanceID);
+ $this->RegisterMessage($VarID, VM_UPDATE);
+ }
+ }
+
/*
$this->MaintainVariable($DeviceNameClean, $DeviceName, vtBoolean, "~Switch", $vpos++, isset($DevicesJSON));
@@ -75,10 +81,9 @@ public function ApplyChanges() {
if (IPS_GetObject($DeviceNameCleanID)['ObjectType'] == 2) {
$this->RegisterMessage($DeviceNameCleanID, VM_UPDATE);
}
- */
-
- }
- }
+ */
+ }
+
}
public function MessageSink($TimeStamp, $SenderID, $Message, $Data) {
@@ -227,8 +232,15 @@ public function AuthenticateAndProcessRequest() {
$RawData = curl_exec($ch);
$HTTP_Code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Feedback from UniFi Controller: ").$RawData." / HTTP Message ".$HTTP_Code ,0);
+
+ $ControllerFeedbackComplete = json_decode($RawData,true);
+ $ControllerFeedbackOK = $ControllerFeedbackComplete["meta"]["rc"];
+ $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Was block executed: ").$ControllerFeedbackOK ,0);
curl_close($ch);
-
+ if ($ControllerFeedbackOK == "ok") {
+ //WFC_SendPopup(12345, "Test", "Eine nette
Meldung");
+ }
+
}
}
From e99a327d928a7d6b1676b8a6e7a688c917ecf6b2 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Wed, 22 Dec 2021 09:26:06 +0100
Subject: [PATCH 15/71] Fix for "Set-Cookie" case insensitive preg_match
---
UniFi Internet Controller/module.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Internet Controller/module.php b/UniFi Internet Controller/module.php
index ca14eae..ec97085 100644
--- a/UniFi Internet Controller/module.php
+++ b/UniFi Internet Controller/module.php
@@ -153,7 +153,7 @@ public function AuthenticateAndGetData($UnifiAPI = "") {
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$code,0);
- preg_match_all('|Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
+ preg_match_all('|(?i)Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
if (isset($results[1])) {
$Cookie = implode(';', $results[1]);
if (!empty($body)) {
@@ -331,4 +331,4 @@ public function GetInternetData() {
}
}
}
-}
\ No newline at end of file
+}
From 92bb4be65dc91d79af2a7029af4922304a995aef Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Wed, 22 Dec 2021 09:31:00 +0100
Subject: [PATCH 16/71] Authentication failure handling improved
---
UniFi Internet Controller/module.php | 29 ++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/UniFi Internet Controller/module.php b/UniFi Internet Controller/module.php
index ec97085..22f09e0 100644
--- a/UniFi Internet Controller/module.php
+++ b/UniFi Internet Controller/module.php
@@ -157,12 +157,15 @@ public function AuthenticateAndGetData($UnifiAPI = "") {
if (isset($results[1])) {
$Cookie = implode(';', $results[1]);
if (!empty($body)) {
- if (($code == 200) && ($code != 400)) {
+ if (200 == $code) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
}
- if ($code == 400) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Failure - We have received an HTTP response status: 400. Probably a controller login failure'),0);
+ else if (400 == $code) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ }
+ else if (401 == $code || 403 == $code) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
}
}
}
@@ -188,7 +191,17 @@ public function AuthenticateAndGetData($UnifiAPI = "") {
//$JSON = json_decode($RawData,true);
//$this->SetBuffer("RawData",$RawData);
- if (isset($RawData) AND $RawData != "Unauthorized") {
+ if (400 == $RawData) {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ $this->SetStatus(201); // login seems to be not successful
+ return false;
+ }
+ else if (401 == $RawData || 403 == $RawData || $RawData == "Unauthorized") {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ $this->SetStatus(201); // login seems to be not successful
+ return false;
+ }
+ else if (isset($RawData)) {
$this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Successfully Called"),0);
$this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Data Provided: ").$RawData,0);
$this->SetBuffer("RawData",$RawData);
@@ -196,9 +209,11 @@ public function AuthenticateAndGetData($UnifiAPI = "") {
else {
$this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("API could not be called - check the login data. Do you see a Cookie?"),0);
$this->SetStatus(201); // login seems to be not successful
+ return false;
}
}
+ return true;
}
public function GetInternetData() {
@@ -212,7 +227,7 @@ public function GetInternetData() {
|| $this->ReadPropertyBoolean("ubnt_device_type")
|| $this->ReadPropertyBoolean("udm_version")) {
// query JSON file for internet data
- $this->AuthenticateAndGetData();
+ if ($this->AuthenticateAndGetData()) {
$RawData = $this->GetBuffer("RawData");
$JSONData = json_decode($RawData, true);
@@ -274,6 +289,7 @@ public function GetInternetData() {
}
}
}
+ }
}
$this->ReadPropertyBoolean("WAN1availability")
@@ -287,7 +303,7 @@ public function GetInternetData() {
{
$Site = $this->ReadPropertyString("Site");
- $this->AuthenticateAndGetData("api/stat/sites");
+ if ($this->AuthenticateAndGetData("api/stat/sites")) {
$RawData = $this->GetBuffer("RawData");
$JSONData = json_decode($RawData, true);
@@ -329,6 +345,7 @@ public function GetInternetData() {
}
}
}
+ }
}
}
}
From 21500d9f02eafbf803f9ec6c3ae9e6173888fad0 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Wed, 22 Dec 2021 09:41:45 +0100
Subject: [PATCH 17/71] Fix for "Set-Cookie" case insensitive preg_match
#13 UnifiOS 1.11.0 - Trying to access array offset on value of type null
---
UniFi Device Blocker/module.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index ee5cd40..0c56e68 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -133,7 +133,7 @@ public function AuthenticateAndProcessRequest() {
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$code,0);
- preg_match_all('|Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
+ preg_match_all('|(?i)Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
if (isset($results[1])) {
$Cookie = implode(';', $results[1]);
if (!empty($body)) {
From cd0ec293c1e89f55bf462b7c62463f7b3ec3844b Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Wed, 22 Dec 2021 09:42:28 +0100
Subject: [PATCH 18/71] Fix for "Set-Cookie" case insensitive preg_match
#13 UnifiOS 1.11.0 - Trying to access array offset on value of type null
---
UniFi Presence Manager/module.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Presence Manager/module.php b/UniFi Presence Manager/module.php
index 3944717..0afb70e 100644
--- a/UniFi Presence Manager/module.php
+++ b/UniFi Presence Manager/module.php
@@ -113,7 +113,7 @@ public function AuthenticateAndGetData() {
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$code,0);
- preg_match_all('|Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
+ preg_match_all('|(?i)Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
if (isset($results[1])) {
$Cookie = implode(';', $results[1]);
if (!empty($body)) {
@@ -218,4 +218,4 @@ public function CheckPresence() {
}
- }
\ No newline at end of file
+ }
From e7fb30cc334f5a146f5f93f1724d9693cd0ee002 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Wed, 22 Dec 2021 13:25:54 +0100
Subject: [PATCH 19/71] Validation + Values added
- Validation of ServerAddress, ServerPort, Update Frequence
- values added: previous_version, wan_ip, gw_version
---
UniFi Internet Controller/form.json | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/UniFi Internet Controller/form.json b/UniFi Internet Controller/form.json
index f2705b5..d3a2939 100644
--- a/UniFi Internet Controller/form.json
+++ b/UniFi Internet Controller/form.json
@@ -38,12 +38,16 @@
{
"type": "ValidationTextBox",
"name": "ServerAdress",
- "caption": "Server Address"
+ "caption": "Server Address",
+ "validate": "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
},
{
"type": "NumberSpinner",
"name": "ServerPort",
- "caption": "Server Port"
+ "caption": "Server Port",
+ "digits": 0,
+ "minimum": 1,
+ "maximum": 65535
},
{
"type": "ValidationTextBox",
@@ -59,7 +63,9 @@
"type": "NumberSpinner",
"name": "Timer",
"caption": "Update Frequency",
- "suffix": "sec - 0 is off"
+ "suffix": "sec - 0 is off",
+ "digits": 0,
+ "minimum": 0
},
{
"type": "Label",
@@ -126,6 +132,10 @@
"type": "CheckBox",
"name": "version",
"caption": "Unifi Network Version"
+ },{
+ "type": "CheckBox",
+ "name": "previous_version",
+ "caption": "Unifi Network Vorgängerversion"
},{
"type": "CheckBox",
"name": "update_available",
@@ -149,6 +159,10 @@
"type": "RowLayout",
"items": [
{
+ "type": "CheckBox",
+ "name": "wan_ip",
+ "caption": "WAN IP active"
+ },{
"type": "CheckBox",
"name": "isp_name",
"caption": "ISP Name"
@@ -164,6 +178,10 @@
"type": "CheckBox",
"name": "udm_version",
"caption": "UDM Version"
+ },{
+ "type": "CheckBox",
+ "name": "gw_version",
+ "caption": "UDM UnifiOS Version"
}
]
}
From c80687992cf9b3edd01823a3c3cd95b234de6fef Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Wed, 22 Dec 2021 13:27:36 +0100
Subject: [PATCH 20/71] Erweiterungen
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- Unifi Vorgängerversion, UDM UnifiOS Version
---
UniFi Internet Controller/locale.json | 2 ++
1 file changed, 2 insertions(+)
diff --git a/UniFi Internet Controller/locale.json b/UniFi Internet Controller/locale.json
index 18c2e4c..8f19fd0 100644
--- a/UniFi Internet Controller/locale.json
+++ b/UniFi Internet Controller/locale.json
@@ -17,11 +17,13 @@
"Update Frequency": "Aktualisierungsfrequenz",
"sec - 0 is off": "Sek - 0 ist Aus",
"Unifi Network Version": "Unifi Network Version",
+ "Unifi Network Vorgängerversion": "Unifi Network Vorgängerversion",
"Update available": "Update verfügbar",
"Update downloaded": "Update heruntergeladen",
"Uptime": "Betriebszeit",
"UBNT Device Type": "UBNT Gerätetyp",
"UDM Version": "UDM Version",
+ "UDM UnifiOS Version": "UDM UnifiOS Version",
"WAN1 External IP Address": "WAN1 Externe IP Adresse",
"WAN2 External IP Address": "WAN2 Externe IP Adresse",
"ISP Name": "ISP Name",
From f625d66ec733320d67cafe83c5a325d7fd931844 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Wed, 22 Dec 2021 13:35:25 +0100
Subject: [PATCH 21/71] values added, if-issue solved, typo fixed
- values added: previous_version, wan_ip, gw_version
- if-issue solved: line 308 (if-case was missing!)
- typo fixed: line 161 (Return-Code instead of Cookie)
---
UniFi Internet Controller/module.php | 32 +++++++++++++++++++++-------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/UniFi Internet Controller/module.php b/UniFi Internet Controller/module.php
index 22f09e0..5fe6f6b 100644
--- a/UniFi Internet Controller/module.php
+++ b/UniFi Internet Controller/module.php
@@ -28,14 +28,17 @@ public function Create() {
$this->RegisterPropertyBoolean("WAN2IP",0);
$this->RegisterPropertyBoolean("version",0);
+ $this->RegisterPropertyBoolean("previous_version",0);
$this->RegisterPropertyBoolean("update_available",0);
$this->RegisterPropertyBoolean("update_downloaded",0);
$this->RegisterPropertyBoolean("uptime",0);
$this->RegisterPropertyBoolean("ubnt_device_type",0);
$this->RegisterPropertyBoolean("udm_version",0);
+ $this->RegisterPropertyBoolean("gw_version",0);
$this->RegisterPropertyBoolean("isp_name",0);
$this->RegisterPropertyBoolean("isp_organization",0);
+ $this->RegisterPropertyBoolean("wan_ip",0);
$this->RegisterPropertyBoolean("WAN1availability",0);
$this->RegisterPropertyBoolean("WAN1latency_average",0);
$this->RegisterPropertyBoolean("WAN1time_period",0);
@@ -74,6 +77,7 @@ public function ApplyChanges() {
parent::ApplyChanges();
$vpos = 100;
+ $this->MaintainVariable("wan_ip", $this->Translate("WAN IP active"), vtString, "", $vpos++, $this->ReadPropertyBoolean("wan_ip"));
$this->MaintainVariable("WAN1IP", $this->Translate("WAN1 External IP Address"), vtString, "", $vpos++, $this->ReadPropertyBoolean("WAN1IP"));
$this->MaintainVariable("WAN1availability", $this->Translate("WAN1 availability"), vtInteger, "~Intensity.100", $vpos++, $this->ReadPropertyBoolean("WAN1availability"));
$this->MaintainVariable("WAN1latency_average", $this->Translate("WAN1 latency-average"), vtInteger, "IC.TimeMS", $vpos++, $this->ReadPropertyBoolean("WAN1latency_average"));
@@ -85,12 +89,14 @@ public function ApplyChanges() {
$this->MaintainVariable("isp_name", $this->Translate("ISP Name"), vtString, "", $vpos++, $this->ReadPropertyBoolean("isp_name"));
$this->MaintainVariable("isp_organization", $this->Translate("ISP Organization"), vtString, "", $vpos++, $this->ReadPropertyBoolean("isp_organization"));
$this->MaintainVariable("version", $this->Translate("Unifi Network Version"), vtString, "", $vpos++, $this->ReadPropertyBoolean("version"));
+ $this->MaintainVariable("previous_version", $this->Translate("Unifi Network Vorg�ngerversion"), vtString, "", $vpos++, $this->ReadPropertyBoolean("previous_version"));
$this->MaintainVariable("update_available", $this->Translate("Update available"), vtBoolean, "", $vpos++, $this->ReadPropertyBoolean("update_available"));
$this->MaintainVariable("update_downloaded", $this->Translate("Update downloaded"), vtBoolean, "", $vpos++, $this->ReadPropertyBoolean("update_downloaded"));
$this->MaintainVariable("uptime", $this->Translate("Uptime"), vtInteger, "~UnixTimestamp", $vpos++, $this->ReadPropertyBoolean("uptime"));
$this->MaintainVariable("ubnt_device_type", $this->Translate("UBNT Device Type"), vtString, "", $vpos++, $this->ReadPropertyBoolean("ubnt_device_type"));
$this->MaintainVariable("udm_version", $this->Translate("UDM Version"), vtString, "", $vpos++, $this->ReadPropertyBoolean("udm_version"));
+ $this->MaintainVariable("gw_version", $this->Translate("UDM UnifiOS Version"), vtString, "", $vpos++, $this->ReadPropertyBoolean("gw_version"));
$TimerMS = $this->ReadPropertyInteger("Timer") * 1000;
$this->SetTimerInterval("Collect Connection Data",$TimerMS);
@@ -152,7 +158,9 @@ public function AuthenticateAndGetData($UnifiAPI = "") {
$body = trim(substr($data, $header_size));
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$code,0);
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Return-Code Provided is: ').$code,0);
+ //$this->SendDebug($this->Translate("Debug"), $data,0);
+
preg_match_all('|(?i)Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
if (isset($results[1])) {
$Cookie = implode(';', $results[1]);
@@ -186,6 +194,8 @@ public function AuthenticateAndGetData($UnifiAPI = "") {
curl_setopt($ch, CURLOPT_HTTPHEADER, array("cookie: ".$Cookie));
curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1');
+ //$this->SendDebug("Debug: ", "https://".$ServerAdress.":".$ServerPort.$MiddlePartURL.$UnifiAPI, 0);
+
$RawData = curl_exec($ch);
curl_close($ch);
//$JSON = json_decode($RawData,true);
@@ -221,11 +231,13 @@ public function GetInternetData() {
if($this->ReadPropertyBoolean("WAN1IP")
|| $this->ReadPropertyBoolean("WAN2IP")
|| $this->ReadPropertyBoolean("version")
+ || $this->ReadPropertyBoolean("previous_version")
|| $this->ReadPropertyBoolean("update_available")
|| $this->ReadPropertyBoolean("update_downloaded")
|| $this->ReadPropertyBoolean("uptime")
|| $this->ReadPropertyBoolean("ubnt_device_type")
- || $this->ReadPropertyBoolean("udm_version")) {
+ || $this->ReadPropertyBoolean("udm_version")
+ ) {
// query JSON file for internet data
if ($this->AuthenticateAndGetData()) {
$RawData = $this->GetBuffer("RawData");
@@ -260,6 +272,7 @@ public function GetInternetData() {
// get everything else (besides IP addresses)
$variableArray = array(
array('ident' => "version", 'localeName' => "Unifi Network Version"),
+ array('ident' => "previous_version", 'localeName' => "Unifi Network Vorgängerversion"),
array('ident' => "update_available", 'localeName' => "Update available"),
array('ident' => "update_downloaded", 'localeName' => "Update downloaded"),
array('ident' => "uptime", 'localeName' => "Uptime", 'valueCorrection' => "\$value = (time() - (time() % 60)) - (\$value - (\$value % 60));"), // value correction to avoid an update for every cycle
@@ -292,24 +305,27 @@ public function GetInternetData() {
}
}
- $this->ReadPropertyBoolean("WAN1availability")
+ if($this->ReadPropertyBoolean("gw_version")
+ || $this->ReadPropertyBoolean("wan_ip")
+ || $this->ReadPropertyBoolean("WAN1availability")
|| $this->ReadPropertyBoolean("WAN1latency_average")
|| $this->ReadPropertyBoolean("WAN1time_period")
|| $this->ReadPropertyBoolean("WAN2availability")
|| $this->ReadPropertyBoolean("WAN2latency_average")
|| $this->ReadPropertyBoolean("WAN2time_period")
|| $this->ReadPropertyBoolean("isp_name")
- || $this->ReadPropertyBoolean("isp_organization");
- {
-
+ || $this->ReadPropertyBoolean("isp_organization")
+ ) {
$Site = $this->ReadPropertyString("Site");
if ($this->AuthenticateAndGetData("api/stat/sites")) {
$RawData = $this->GetBuffer("RawData");
$JSONData = json_decode($RawData, true);
-
+ // $this->SendDebug("JSONData", $JSONData, 0);
$healthArray = $JSONData['data'][0]['health'];
$variableArray = array(
+ array('ident' => "gw_version", 'json' => "return (isset(\$health['gw_version']) ? \$health['gw_version'] : null);", 'localeName' => "UDM UnifiOS Version"),
+ array('ident' => "wan_ip", 'json' => "return (isset(\$health['wan_ip']) ? \$health['wan_ip'] : null);", 'localeName' => "WAN IP active"),
array('ident' => "WAN1availability", 'json' => "return (isset(\$health['uptime_stats']['WAN']['availability']) ? \$health['uptime_stats']['WAN']['availability'] : null);", 'localeName' => "WAN1 availablity"),
array('ident' => "WAN1latency_average", 'json' => "return (isset(\$health['uptime_stats']['WAN']['latency_average']) ? \$health['uptime_stats']['WAN']['latency_average'] : null);", 'localeName' => "WAN1 latency_average"),
array('ident' => "WAN1time_period", 'json' => "return (isset(\$health['uptime_stats']['WAN']['time_period']) ? \$health['uptime_stats']['WAN']['time_period'] : null);", 'localeName' => "WAN1 time_period"),
@@ -345,7 +361,7 @@ public function GetInternetData() {
}
}
}
- }
+ }
}
}
}
From 781d2a2495d6c082b593cd66dc920d802d3fc6db Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Wed, 22 Dec 2021 15:19:43 +0100
Subject: [PATCH 22/71] Sonderzeichenfehler, no update output, rounding
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- Sonderzeichenfehler: Vorgängerversion
- no value update output in module-debug: line 262 + 297 + 354
- round of "availability" added to avoid unrelevant variable-updates
---
UniFi Internet Controller/module.php | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/UniFi Internet Controller/module.php b/UniFi Internet Controller/module.php
index 5fe6f6b..671ee73 100644
--- a/UniFi Internet Controller/module.php
+++ b/UniFi Internet Controller/module.php
@@ -89,7 +89,7 @@ public function ApplyChanges() {
$this->MaintainVariable("isp_name", $this->Translate("ISP Name"), vtString, "", $vpos++, $this->ReadPropertyBoolean("isp_name"));
$this->MaintainVariable("isp_organization", $this->Translate("ISP Organization"), vtString, "", $vpos++, $this->ReadPropertyBoolean("isp_organization"));
$this->MaintainVariable("version", $this->Translate("Unifi Network Version"), vtString, "", $vpos++, $this->ReadPropertyBoolean("version"));
- $this->MaintainVariable("previous_version", $this->Translate("Unifi Network Vorg�ngerversion"), vtString, "", $vpos++, $this->ReadPropertyBoolean("previous_version"));
+ $this->MaintainVariable("previous_version", $this->Translate("Unifi Network Vorgängerversion"), vtString, "", $vpos++, $this->ReadPropertyBoolean("previous_version"));
$this->MaintainVariable("update_available", $this->Translate("Update available"), vtBoolean, "", $vpos++, $this->ReadPropertyBoolean("update_available"));
$this->MaintainVariable("update_downloaded", $this->Translate("Update downloaded"), vtBoolean, "", $vpos++, $this->ReadPropertyBoolean("update_downloaded"));
$this->MaintainVariable("uptime", $this->Translate("Uptime"), vtInteger, "~UnixTimestamp", $vpos++, $this->ReadPropertyBoolean("uptime"));
@@ -255,11 +255,11 @@ public function GetInternetData() {
if (isset($JSONData['data'][0]["ip_addrs"][$variable['index']])) {
$value = $JSONData['data'][0]["ip_addrs"][$variable['index']];
if (isset($value)) {
- if ($value !== GetValue($this->GetIDForIdent($variable['ident']))) {
+ if ($value != GetValue($this->GetIDForIdent($variable['ident']))) {
$this->SendDebug($this->Translate($variable['localeName']), $this->Translate("updated to ").$value, 0);
SetValue($this->GetIDForIdent($variable['ident']), $value);
} else {
- $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("no update received"), 0);
+ $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("no update received")." (".$value.")", 0);
}
}
} else {
@@ -290,11 +290,11 @@ public function GetInternetData() {
eval($variable['valueCorrection']);
}
- if ($value !== GetValue($this->GetIDForIdent($variable['ident']))) {
+ if ($value != GetValue($this->GetIDForIdent($variable['ident']))) {
$this->SendDebug($this->Translate($variable['localeName']), $this->Translate("updated to ").$value, 0);
SetValue($this->GetIDForIdent($variable['ident']), $value);
} else {
- $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("no update received"), 0);
+ $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("no update received")." (".$value.")", 0);
}
}
} else {
@@ -326,10 +326,10 @@ public function GetInternetData() {
$variableArray = array(
array('ident' => "gw_version", 'json' => "return (isset(\$health['gw_version']) ? \$health['gw_version'] : null);", 'localeName' => "UDM UnifiOS Version"),
array('ident' => "wan_ip", 'json' => "return (isset(\$health['wan_ip']) ? \$health['wan_ip'] : null);", 'localeName' => "WAN IP active"),
- array('ident' => "WAN1availability", 'json' => "return (isset(\$health['uptime_stats']['WAN']['availability']) ? \$health['uptime_stats']['WAN']['availability'] : null);", 'localeName' => "WAN1 availablity"),
+ array('ident' => "WAN1availability", 'json' => "return (isset(\$health['uptime_stats']['WAN']['availability']) ? round(\$health['uptime_stats']['WAN']['availability']) : null);", 'localeName' => "WAN1 availablity"),
array('ident' => "WAN1latency_average", 'json' => "return (isset(\$health['uptime_stats']['WAN']['latency_average']) ? \$health['uptime_stats']['WAN']['latency_average'] : null);", 'localeName' => "WAN1 latency_average"),
array('ident' => "WAN1time_period", 'json' => "return (isset(\$health['uptime_stats']['WAN']['time_period']) ? \$health['uptime_stats']['WAN']['time_period'] : null);", 'localeName' => "WAN1 time_period"),
- array('ident' => "WAN2availability", 'json' => "return (isset(\$health['uptime_stats']['WAN2']['availability']) ? \$health['uptime_stats']['WAN2']['availability'] : null);", 'localeName' => "WAN2 availablity"),
+ array('ident' => "WAN2availability", 'json' => "return (isset(\$health['uptime_stats']['WAN2']['availability']) ? round(\$health['uptime_stats']['WAN2']['availability']) : null);", 'localeName' => "WAN2 availablity"),
array('ident' => "WAN2latency_average", 'json' => "return (isset(\$health['uptime_stats']['WAN2']['latency_average']) ? \$health['uptime_stats']['WAN2']['latency_average'] : null);", 'localeName' => "WAN2 latency_average",),
array('ident' => "WAN2time_period", 'json' => "return (isset(\$health['uptime_stats']['WAN2']['time_period']) ? \$health['uptime_stats']['WAN2']['time_period'] : null);", 'localeName' => "WAN2 time_period"),
array('ident' => "isp_name", 'json' => "return (isset(\$health['isp_name']) ? \$health['isp_name'] : null);", 'localeName' => "ISP Name"),
@@ -347,11 +347,11 @@ public function GetInternetData() {
eval($variable['valueCorrection']);
}
- if ($value !== GetValue($this->GetIDForIdent($variable['ident']))) {
+ if ($value != GetValue($this->GetIDForIdent($variable['ident']))) {
$this->SendDebug($this->Translate($variable['localeName']), $this->Translate("updated to ").$value, 0);
SetValue($this->GetIDForIdent($variable['ident']), $value);
} else {
- $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("no update received"), 0);
+ $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("no update received")." (".$value.")", 0);
}
}
} else {
From 70b4332f9073a16a4ce1194d173d833c3b9f0eb1 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Wed, 22 Dec 2021 16:51:17 +0100
Subject: [PATCH 23/71] #32 wan ip active
---
UniFi Internet Controller/locale.json | 1 +
1 file changed, 1 insertion(+)
diff --git a/UniFi Internet Controller/locale.json b/UniFi Internet Controller/locale.json
index 8f19fd0..e60d3f6 100644
--- a/UniFi Internet Controller/locale.json
+++ b/UniFi Internet Controller/locale.json
@@ -29,6 +29,7 @@
"ISP Name": "ISP Name",
"ISP Organization": "ISP Organization",
"WAN1 availability": "WAN1 Verfügbarkeit",
+ "WAN IP active": "WAN IP Aktiv",
"WAN1 latency-average": "WAN1 Latenz-Durchschnitt",
"WAN1 time-period": "WAN1 Betrachtungszeitraum",
"WAN2 availability": "WAN2 Verfügbarkeit",
From 2836ca3ecc175a7ba60bcc9685837cb913929b55 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Wed, 22 Dec 2021 20:51:52 +0100
Subject: [PATCH 24/71] Device Blocker now using MAC for Ident
---
UniFi Device Blocker/module.php | 46 +++++++++++++++++++++------------
1 file changed, 29 insertions(+), 17 deletions(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index 0c56e68..e5b061a 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -48,23 +48,28 @@ public function ApplyChanges() {
foreach ($DevicesJSON as $Device) {
$DeviceName = $Device["varDeviceName"];
$DeviceNameClean = str_replace(array("-",":"," "), "", $DeviceName);
+ $DeviceMacAdress = $Device["varDeviceMAC"];
+ $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAdress);
- if (@IPS_GetObjectIDByIdent($DeviceNameClean, $this->InstanceID) == false) {
+ if (@IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID) == false) {
- $DeviceNameCleanID = IPS_CreateVariable(0);
- IPS_SetName($DeviceNameCleanID, $DeviceNameClean);
- IPS_SetIdent($DeviceNameCleanID, $DeviceNameClean);
- IPS_SetVariableCustomProfile($DeviceNameCleanID, "~Switch");
- IPS_SetParent($DeviceNameCleanID, $this->InstanceID);
+ $DeviceMacCleanID = IPS_CreateVariable(0);
+ IPS_SetName($DeviceMacCleanID, $DeviceName);
+ IPS_SetIdent($DeviceMacCleanID, $DeviceMacClean);
+ IPS_SetVariableCustomProfile($DeviceMacCleanID, "~Switch");
+ IPS_SetParent($DeviceMacCleanID, $this->InstanceID);
- SetValue($DeviceNameCleanID,true);
- $this->EnableAction($DeviceNameClean);
- $this->RegisterMessage($DeviceNameCleanID, VM_UPDATE);
+ SetValue($DeviceMacCleanID,true);
+ IPS_Sleep(1000);
+ $this->EnableAction($DeviceMacClean);
+ $this->RegisterMessage($DeviceMacCleanID, VM_UPDATE);
}
foreach ($DevicesJSON as $Device) {
- $VarID = @IPS_GetObjectIDByIdent($Device["varDeviceName"], $this->InstanceID);
+ $DeviceMacAdress = $Device["varDeviceMAC"];
+ $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAdress);
+ $VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
$this->RegisterMessage($VarID, VM_UPDATE);
}
}
@@ -141,9 +146,11 @@ public function AuthenticateAndProcessRequest() {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
}
- if ($code == 400) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Failure - We have received an HTTP response status: 400. Probably a controller login failure or no device is configured'),0);
-
+ else if ($code == 400) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ }
+ else if ($code == 401 || $code == 403) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
}
}
}
@@ -152,6 +159,7 @@ public function AuthenticateAndProcessRequest() {
if ($SenderID != "") {
$SenderObjectData = IPS_GetObject($SenderID);
$SenderName = ($SenderObjectData["ObjectName"]);
+ $SenderObjectIdent = ($SenderObjectData["ObjectIdent"]);
$SenderStatus = GetValue($SenderID);
//Get MAC Adress from Config form
@@ -160,9 +168,10 @@ public function AuthenticateAndProcessRequest() {
if (isset($DevicesJSON)) {
foreach ($DevicesJSON as $Device) {
- if ($SenderName == $Device["varDeviceName"]) {
+ $DeviceMacClean = str_replace(array(":"," "), "", $Device["varDeviceMAC"]);
+ if ($SenderObjectIdent == $DeviceMacClean) {
$DeviceMacAdress = $Device["varDeviceMAC"];
- $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Device to be blocked ").$Device["varDeviceName"].$this->Translate(" device from Sender ").$SenderName,0);
+ $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Device to be managed: ").$Device["varDeviceName"],0);
}
}
}
@@ -201,7 +210,7 @@ public function AuthenticateAndProcessRequest() {
}
else if ($SenderStatus == 0) {
$Command = "block-sta";
- $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Module will try to block devie ").$SenderName.$this->Translate(" with MAC adress ").$DeviceMacAdress,0);
+ $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Module will try to block device ").$SenderName.$this->Translate(" with MAC adress ").$DeviceMacAdress,0);
}
//$CommandToController = json_encode(array($Command => $DeviceMacAdress));
@@ -235,11 +244,14 @@ public function AuthenticateAndProcessRequest() {
$ControllerFeedbackComplete = json_decode($RawData,true);
$ControllerFeedbackOK = $ControllerFeedbackComplete["meta"]["rc"];
- $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Was block executed: ").$ControllerFeedbackOK ,0);
+ $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Was operation executed: ").$ControllerFeedbackOK ,0);
curl_close($ch);
if ($ControllerFeedbackOK == "ok") {
//WFC_SendPopup(12345, "Test", "Eine nette
Meldung");
}
+ else if ($ControllerFeedbackOK == "error") {
+ //WFC_SendPopup(12345, "Test", "Eine nette
Meldung");
+ }
}
From 1ceaeb2c2dd270563a8702fe802f10fb74932254 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Thu, 23 Dec 2021 10:42:13 +0100
Subject: [PATCH 25/71] fix in blocker and error handling presence
---
UniFi Device Blocker/module.php | 10 ++++++++++
UniFi Presence Manager/module.php | 10 ++++++----
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index e5b061a..874fa48 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -173,9 +173,19 @@ public function AuthenticateAndProcessRequest() {
$DeviceMacAdress = $Device["varDeviceMAC"];
$this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Device to be managed: ").$Device["varDeviceName"],0);
}
+ else {
+ $DeviceMacAdress = "";
+ }
}
}
+ if (!isset($DeviceMacAdress)) {
+ $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("The switched variable did not have an entry in the module configuration - execution stopped"),0);
+ exit;
+ }
+
+
+
$this->SendDebug($this->Translate("Device Blocker"),$Cookie,0);
diff --git a/UniFi Presence Manager/module.php b/UniFi Presence Manager/module.php
index 0afb70e..806271a 100644
--- a/UniFi Presence Manager/module.php
+++ b/UniFi Presence Manager/module.php
@@ -117,13 +117,15 @@ public function AuthenticateAndGetData() {
if (isset($results[1])) {
$Cookie = implode(';', $results[1]);
if (!empty($body)) {
- if (($code == 200) && ($code != 400)) {
+ if ($code == 200) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
}
- if ($code == 400) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Failure - We have received an HTTP response status: 400. Probably a controller login failure'),0);
-
+ else if ($code == 400) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ }
+ else if ($code == 401 || $code == 403) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
}
}
}
From bfb36a0c5bcf0095e181cb94aa3da55ac945c35f Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sat, 25 Dec 2021 19:52:08 +0100
Subject: [PATCH 26/71] fixed error during installation
---
UniFi Internet Controller/module.php | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/UniFi Internet Controller/module.php b/UniFi Internet Controller/module.php
index 671ee73..ab107a3 100644
--- a/UniFi Internet Controller/module.php
+++ b/UniFi Internet Controller/module.php
@@ -113,9 +113,8 @@ public function ApplyChanges() {
}
- public function AuthenticateAndGetData($UnifiAPI = "") {
+ public function AuthenticateAndGetData() {
- //$ControllerType = $this->ReadPropertyInteger("ControllerType");
$ServerAdress = $this->ReadPropertyString("ServerAdress");
$ServerPort = $this->ReadPropertyInteger("ServerPort");
$Username = $this->ReadPropertyString("UserName");
@@ -124,9 +123,9 @@ public function AuthenticateAndGetData($UnifiAPI = "") {
////////////////////////////////////////
//Change the Unifi API to be called here
- if ("" == $UnifiAPI) {
- $UnifiAPI = "api/s/".$Site."/stat/sysinfo";
- }
+
+ $UnifiAPI = "api/s/".$Site."/stat/sysinfo";
+
////////////////////////////////////////
From f84374a59a7324098f8f247948b47a59c05d8148 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sat, 25 Dec 2021 20:13:31 +0100
Subject: [PATCH 27/71] =?UTF-8?q?rollback=20und=20fix=20letzter=20=C3=84nd?=
=?UTF-8?q?erung?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
UniFi Internet Controller/module.php | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/UniFi Internet Controller/module.php b/UniFi Internet Controller/module.php
index ab107a3..d2f0d9a 100644
--- a/UniFi Internet Controller/module.php
+++ b/UniFi Internet Controller/module.php
@@ -113,8 +113,9 @@ public function ApplyChanges() {
}
- public function AuthenticateAndGetData() {
+ public function AuthenticateAndGetData (string $UnifiAPI = "") {
+ //$ControllerType = $this->ReadPropertyInteger("ControllerType");
$ServerAdress = $this->ReadPropertyString("ServerAdress");
$ServerPort = $this->ReadPropertyInteger("ServerPort");
$Username = $this->ReadPropertyString("UserName");
@@ -123,9 +124,9 @@ public function AuthenticateAndGetData() {
////////////////////////////////////////
//Change the Unifi API to be called here
-
- $UnifiAPI = "api/s/".$Site."/stat/sysinfo";
-
+ if ("" == $UnifiAPI) {
+ $UnifiAPI = "api/s/".$Site."/stat/sysinfo";
+ }
////////////////////////////////////////
From 1bb1856548280fd2ed177dc97f4bd1117d4d5e3e Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Sat, 25 Dec 2021 20:19:38 +0100
Subject: [PATCH 28/71] updated readme
---
UniFi Device Blocker/README.md | 7 ++++++-
UniFi Internet Controller/README.md | 2 +-
UniFi Presence Manager/README.md | 2 +-
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/UniFi Device Blocker/README.md b/UniFi Device Blocker/README.md
index ea680dc..bd5a6e2 100644
--- a/UniFi Device Blocker/README.md
+++ b/UniFi Device Blocker/README.md
@@ -75,4 +75,9 @@ Version 0.31 (Beta) - 27-08-2021
* Fix bei der Logik zum blocken
Version 1.0 - 09-09-2021
-* keine weiteren Änderungen
\ No newline at end of file
+* keine weiteren Änderungen
+
+Version 1.1 - 25-12-2021
+* Fix - Memory Leak
+* Fix - HTTP Response Error Message
+* Variablen Management umgestellt - es Ident wird jetzt die MAC verwendet
\ No newline at end of file
diff --git a/UniFi Internet Controller/README.md b/UniFi Internet Controller/README.md
index 9a9fdd1..4f04006 100644
--- a/UniFi Internet Controller/README.md
+++ b/UniFi Internet Controller/README.md
@@ -88,6 +88,6 @@ Version 1.0 - 09-09-2021
* UBNT Device Type
* UDM Version
-Version 1.1 - 17-12-2021
+Version 1.1 - 25-12-2021
* Fix - Memory Leak
* Fix - HTTP Response Error Message
diff --git a/UniFi Presence Manager/README.md b/UniFi Presence Manager/README.md
index d62a0c4..f84d64f 100644
--- a/UniFi Presence Manager/README.md
+++ b/UniFi Presence Manager/README.md
@@ -79,6 +79,6 @@ Version 0.31 (Beta) - 25-08-2021
Version 1.0 - 09-09-2021
* keine weiteren Änderungen
-Version 1.1 - 17-12-2021
+Version 1.1 - 25-12-2021
* Fix - Memory Leak
* Fix - HTTP Response Error Message
\ No newline at end of file
From 0f310113567acc06444165d32bc516e86ff9a8ee Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Tue, 28 Dec 2021 12:10:11 +0100
Subject: [PATCH 29/71] First Commit of Endpoint Monitor and Device Monitor
---
README.md | 8 +
UniFi Device Monitor/README.md | 86 +++++++++
UniFi Device Monitor/form.json | 150 ++++++++++++++++
UniFi Device Monitor/locale.json | 52 ++++++
UniFi Device Monitor/module.json | 12 ++
UniFi Device Monitor/module.php | 261 +++++++++++++++++++++++++++
UniFi Endpoint Monitor/README.md | 82 +++++++++
UniFi Endpoint Monitor/form.json | 154 ++++++++++++++++
UniFi Endpoint Monitor/locale.json | 43 +++++
UniFi Endpoint Monitor/module.json | 12 ++
UniFi Endpoint Monitor/module.php | 274 +++++++++++++++++++++++++++++
UniFi Presence Manager/README.md | 5 +-
library.json | 2 +-
13 files changed, 1139 insertions(+), 2 deletions(-)
create mode 100644 UniFi Device Monitor/README.md
create mode 100644 UniFi Device Monitor/form.json
create mode 100644 UniFi Device Monitor/locale.json
create mode 100644 UniFi Device Monitor/module.json
create mode 100644 UniFi Device Monitor/module.php
create mode 100644 UniFi Endpoint Monitor/README.md
create mode 100644 UniFi Endpoint Monitor/form.json
create mode 100644 UniFi Endpoint Monitor/locale.json
create mode 100644 UniFi Endpoint Monitor/module.json
create mode 100644 UniFi Endpoint Monitor/module.php
diff --git a/README.md b/README.md
index be2471a..1401655 100644
--- a/README.md
+++ b/README.md
@@ -23,4 +23,12 @@ Folgende Module beinhaltet das UniFi Toolbox Repository:
- __UniFi Device Blocker__ ([Dokumentation](UniFi%20Device%20Blocker))
Mit dem Device Blocker können Geräte anhand ihrer MAC Adresse vom Zugang auf das Netzwerk geblockt werden, z.B. um die Nutzung von Geräten im Kinderzimmer nach 20 Uhr zu sperren und am Morgen wieder zu aktivieren.
+- __UniFi Device Monitor__ ([Dokumentation](UniFi%20Device%20Monitor))
+ Mit dem Device Monitor können Geräte von UniFi überwacht werden - es stehen bei Firewalls (UDM/USG) Daten zur Internetverbindung zu Verfügung, bei generischen Geräten Daten zum Status und Hardware.
+
+- __UniFi Endpoint Monitor__ ([Dokumentation](UniFi%20Endpoint%20Monitor))
+ Mit dem Endpoint Monitor können mit den UniFi Netzwerkverbunde Geräte überwacht werden. Hierbei wird zwischen Kabel und WLAN Verbindungen unterschieden, da im WLAN weit mehr Daten zur Verfügung stehen.
+
Für detaillierte Informationen zu den Modulen, wie z.B. zur Version bitte die Hilfeseiten der Module besuchen.
+
+Dieses Modul ist für die nicht kommerzielle Nutzung kostenlos - bei kommerzieller Nutzung bitte den Author kontakieren.
\ No newline at end of file
diff --git a/UniFi Device Monitor/README.md b/UniFi Device Monitor/README.md
new file mode 100644
index 0000000..87b112a
--- /dev/null
+++ b/UniFi Device Monitor/README.md
@@ -0,0 +1,86 @@
+# UniFi Device Monitor
+Dieses Modul ermöglicht es Unifi Geräte im Netz zu überwachen und u.a. Verbindungs und Hardwaredaten abzufragen.
+
+### Inhaltsverzeichnis
+
+1. [Funktionsumfang](#1-funktionsumfang)
+2. [Voraussetzungen](#2-voraussetzungen)
+3. [Software-Installation](#3-software-installation)
+4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon)
+5. [Versionsinformation](#5-versionsinformation)
+
+### 1. Funktionsumfang
+
+* Unterstützung für UniFi Cloudkey 1
+* Unterstützung für UniFi Cloudkey 2 und Dream Maschine
+* Anlegen von zu überwachenden Geräten mit Name und MAC Adresse
+* Erstellt pro Gerät eine Variable welche z.B. für die Automation oder Überwachung genutzt werden kann (Boolean)
+* Abfragen der Controller erfolgt zeitgesteuert alle xx Sekunden
+
+### 2. Vorraussetzungen
+
+- IP-Symcon ab Version 5.5
+
+### 3. Software-Installation
+
+* Über den Module Store das 'UniFi Presence Manager'-Modul installieren.
+* Alternativ über das Module Control folgende URL hinzufügen
+
+### 4. Einrichten der Instanzen in IP-Symcon
+
+ Unter 'Instanz hinzufügen' kann das 'UniFi Presence Manager'-Modul mithilfe des Schnellfilters gefunden werden.
+ - Weitere Informationen zum Hinzufügen von Instanzen in der [Dokumentation der Instanzen](https://www.symcon.de/service/dokumentation/konzepte/instanzen/#Instanz_hinzufügen)
+
+__Konfigurationsseite__:
+
+**Art des Controllers**
+
+Da sich die APIs von CloudKey 1 und CloudKey2/Dreammaschine unterscheiden, kann hier der Controller gewählt werden
+
+**Benutzername & Kennwort**
+
+Account mit dem sich das Modul mit dem Controller verbindet
+
+**Site**
+
+Site die im Controller hinterlegt ist
+
+**IP Adresse und Port**
+
+Bei der Dream Maschine ist der Port 443, bei einem Controller im Standard 8443. IP Addresse des CloudKeys oder der Dream Maschine.
+
+**Aktualisierungsfrequenz**
+
+Da der Controller aktiv abfragt werden muss, kann man hier eine Frequenz hinterlegen wie oft dies geschehen soll.
+
+**MAC Adresse**
+
+Die MAC Adresse des zu überwachenden Geräts. Diese am besten aus dem Controller auslesen.
+
+**Gerätetyp**
+
+Wahl zwischen UDM/USG Geräten welche mit dem Internet verbunden sind und generischen Geräten. Bei generischen Geräten stehen weniger Daten zur Verfügung.
+
+**Basisdaten - Verfügbar für alle Geräte**
+
+Netzwerkdaten umfassen logische Daten wie Gerätemodel, Softwareversion, Zufriedenheit, zuletzt gesehen, Uptime, Name.
+
+**Hardwaredaten - Verfügbar für alle Geräte**
+
+Diese einstellung liest die CPU und Speicherlast aus.
+
+**Verbindungsdaten - nur bei Firewalls wie UDM/USG verfügbar**
+
+Netzwerkdaten wie Public IP, übertragene Daten, Pakete und Fehler
+
+**Übertragungsdaten**
+
+Bei WLAN Geräten werden hier Informationen zu übertragenen Daten und Paketen geliefert.
+
+**Debugging**
+Das Modul gibt diverse Informatioen im Debug Bereich aus.
+
+## 5. Versionsinformation
+
+Version 1.2 - 28-12-2021
+* Neu - Modul verfügbar
\ No newline at end of file
diff --git a/UniFi Device Monitor/form.json b/UniFi Device Monitor/form.json
new file mode 100644
index 0000000..c8891ac
--- /dev/null
+++ b/UniFi Device Monitor/form.json
@@ -0,0 +1,150 @@
+{
+ "elements": [
+ {
+ "type": "ExpansionPanel",
+ "caption": "Module Help",
+ "items": [
+ {
+ "type": "Label",
+ "label": "This Module allows to monitor Unifi equipment connected to a UniFi Network and provide data in variables."
+ },
+ {
+ "type": "Label",
+ "label": "Please select the type of controller you are using, enter its IP Address, Port and a user allowed to log in."
+ },
+ {
+ "type": "Label",
+ "label": "To manage certain devices, please use their MAC adress - easiest method might be to take it from the controller interface."
+ },
+ {
+ "type": "Label",
+ "label": "Please turn on the data points you would like to monitor and variables will be created accordingly."
+ },
+ {
+ "type": "Label",
+ "label": "Updates will happen on a schedule every xyz seconds."
+ },
+ {
+ "type": "Label",
+ "label": "For debugging, please use the Debug function of the module."
+ }
+ ]
+ },
+ {
+ "type": "Label",
+ "label": "UniFi Toolbox - Endpoint Monitor Configuration"
+ },
+ {
+ "type": "Select",
+ "name": "ControllerType",
+ "caption": "Controller Type",
+ "options": [
+ {
+ "caption": "Dream Maschine / Pro / CloudKey V2",
+ "value": 0
+ },
+ {
+ "caption": "CloudKey",
+ "value": 1
+ }
+ ]
+ },
+ {
+ "type": "ValidationTextBox",
+ "name": "Site",
+ "caption": "Site"
+ },
+ {
+ "type": "ValidationTextBox",
+ "name": "ServerAdress",
+ "caption": "Server Address",
+ "validate": "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
+ },
+ {
+ "type": "NumberSpinner",
+ "name": "ServerPort",
+ "caption": "Server Port",
+ "digits": 0,
+ "minimum": 1,
+ "maximum": 65535
+ },
+ {
+ "type": "ValidationTextBox",
+ "name": "UserName",
+ "caption": "User Name"
+ },
+ {
+ "type": "PasswordTextBox",
+ "name": "Password",
+ "caption": "Password"
+ },
+ {
+ "type": "NumberSpinner",
+ "name": "Timer",
+ "caption": "Update Frequency",
+ "suffix": "sec - 0 is off"
+ },
+ {
+ "type": "Label",
+ "label": "Please enter the MAC Address of the device to be monitored."
+ },
+ {
+ "type": "ValidationTextBox",
+ "name": "DeviceMac",
+ "caption": "Device MAC Address",
+ "validate": "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})|([0-9a-fA-F]{4}\\.[0-9a-fA-F]{4}\\.[0-9a-fA-F]{4})$"
+ },
+ {
+ "type": "Label",
+ "label": "Please select how the device to be monitor is connected - this will switch on/off certain variables."
+ },
+ {
+ "type": "Select",
+ "name": "DeviceType",
+ "caption": "Device Type",
+ "options": [
+ {
+ "caption": "UDM or USG",
+ "value": 0
+ },
+ {
+ "caption": "Genric Device",
+ "value": 1
+ }
+ ]
+ },
+ {
+ "type": "CheckBox",
+ "name": "DataPointBasic",
+ "caption": "Basic Data"
+ },
+ {
+ "type": "CheckBox",
+ "name": "DataPointHardware",
+ "caption": "Hardware Data"
+ },
+ {
+ "type": "CheckBox",
+ "name": "DataPointSpecific",
+ "caption": "Network Data"
+ }
+ ],
+ "actions": [
+ {
+ "type": "RowLayout",
+ "items": [
+ {
+ "type": "Button",
+ "label": "Test Authentication",
+ "onClick": "DM_AuthenticateAndGetData($id);"
+ },
+ {
+ "type": "Button",
+ "label": "Get Device Data",
+ "onClick": "DM_DeviceMonitor($id);"
+ }
+ ]
+ }
+ ],
+ "status": []
+}
\ No newline at end of file
diff --git a/UniFi Device Monitor/locale.json b/UniFi Device Monitor/locale.json
new file mode 100644
index 0000000..bf752f4
--- /dev/null
+++ b/UniFi Device Monitor/locale.json
@@ -0,0 +1,52 @@
+{
+ "translations": {
+ "de": {
+ "Module Help": "Modul Hilfe",
+ "This Module allows to monitor devices connected to a UniFi Network and provide data in variables.": "Dieses Modul ermöglicht es Geräte im Netz zu überwachen und Daten in Variablen anzuzeigen.",
+ "Please select the type of controller you are using, enter its IP Adress, Port and a user allowed to log in.": "Bitte wählen sie die Art des Controllers und geben die IP Adresse, Port und einen Anwender ein der auf diesen zugreifen darf.",
+ "To manage certain devices, please use their MAC adress - easiest method might be to take it from the controller interface.": "Um Geräte zu verwalten, geben sie bitte die MAC Addresse ein - diese können am einfachsten aus dem Controller ausgelesen werden.",
+ "Please turn on the data points you would like to monitor and variables will be created accordingly.": "Die gewünschten Datenpunkte können in der Konfiguration ausgewählt werden.",
+ "Updates will happen on a schedule every xyz seconds.": "Das Module prüft die Anwensenheit alle xyz Sekunden, wie im Module konfiguriert",
+ "For debugging, please use the Debug function of the module.": "Für das Prüfen der Funktionen, gibt es Modul Meldungen im Debugbereich aus",
+ "UniFi Toolbox - Endpoint Monitor Configuration": "UniFi Toolbox - Endgeräte Überwachung Konfiguration",
+ "Controller Type": "Art des Controllers",
+ "Server Address": "Server Adresse",
+ "User Name": "Anmeldename",
+ "Password": "Passwort",
+ "Update Frequency": "Aktualisierungsfrequenz",
+ "sec - 0 is off": "Sek - 0 ist Aus",
+ "Please enter the MAC Address of the device to be monitored.": "MAC Adresse die überwacht werden soll.",
+ "Device MAC Address": "Geräte MAC Adresse",
+ "Please select how the device to be monitor is connected - this will switch on/off certain variables.": "Bitte wählen wie das zu überwachende Gerät verbunden ist - dies bestimmt die möglichen Variablen.",
+ "Connection Type": "Art der Verbindung",
+ "Wireless": "WLAN",
+ "Wired": "Kabel",
+ "Basic Data": "Basisdaten",
+ "Hardware Data": "Hardwaredaten",
+ "Device Type": "Geräte Typ",
+ "Config error - device monitored is a wired device. Please select wired in the module configuration.": "Konfigurationsfehler - das überwachte Gerät ist verkabelt. Bitte dies in der Modulkonfiguration einstellen.",
+ "Network Data": "Netzwerkdaten",
+ "Connection Data": "Verbindungsdaten",
+ "Transfer data is only available on wireless devices.": "Übertragungsdaten sind nur bei WLAN Geräten verfügbar.",
+ "Transfer Data": "Übertragungsdaten",
+ "Test Authentication": "Teste Anmeldung am Controller",
+ "Get Device Data": "Hole Gerätedaten",
+ "Device Model": "Geräte Typ",
+ "Device Name": "Geräte Name",
+ "CPU Load": "CPU Auslastung",
+ "Memory Load": "Speicher Auslastung",
+ "WAN 1 TX Packets": "WAN 1 TX Pakete",
+ "WAN 1 RX Packets": "WAN 1 RX Pakete",
+ "WAN 1 TX Errors": "WAN 1 TX Fehler",
+ "WAN 1 RX Errors": "WAN 1 RX Fehler",
+ "IP Address": "IP Adresse",
+ "Satisfaction": "Verbindungsqualität",
+ "Last Seen": "Zuletzt gesehen",
+ "Uptime in hours": "Verbunden seit - in Stunden",
+ "Channel": "Kanal",
+ "Radio": "Funktechnologie",
+ "Noise": "Störung",
+ "Signal Strength": "Signal Stärke"
+ }
+ }
+}
\ No newline at end of file
diff --git a/UniFi Device Monitor/module.json b/UniFi Device Monitor/module.json
new file mode 100644
index 0000000..e1cd04a
--- /dev/null
+++ b/UniFi Device Monitor/module.json
@@ -0,0 +1,12 @@
+{
+ "id": "{26117C51-539E-9E09-F409-AEB2B7896596}",
+ "name": "UniFi Device Monitor",
+ "type": 3,
+ "vendor": "UniFi",
+ "aliases": [],
+ "parentRequirements": [],
+ "childRequirements": [],
+ "implemented": [],
+ "prefix": "DM",
+ "url": "https://github.com/elueckel/Unifi-Toolbox/tree/main/UniFi%20Device%20Monitor"
+}
\ No newline at end of file
diff --git a/UniFi Device Monitor/module.php b/UniFi Device Monitor/module.php
new file mode 100644
index 0000000..8a22392
--- /dev/null
+++ b/UniFi Device Monitor/module.php
@@ -0,0 +1,261 @@
+RegisterPropertyInteger("ControllerType", 0);
+ $this->RegisterPropertyString("ServerAdress","192.168.1.1");
+ $this->RegisterPropertyInteger("ServerPort", "443");
+ $this->RegisterPropertyString("Site","default");
+ $this->RegisterPropertyString("UserName","");
+ $this->RegisterPropertyString("Password","");
+ $this->RegisterPropertyInteger("Timer", "0");
+
+ $this->RegisterPropertyString("DeviceMac", "");
+ $this->RegisterPropertyInteger("DeviceType", 0);
+
+ $this->RegisterPropertyBoolean("DataPointBasic", 1);
+ $this->RegisterPropertyBoolean("DataPointHardware", 0);
+ $this->RegisterPropertyBoolean("DataPointSpecific", 0);
+
+
+ $this->RegisterTimer("Device Monitor",0,"DM_EndpointMonitor(\$_IPS['TARGET']);");
+
+ }
+
+ public function Destroy() {
+ //Never delete this line!
+ parent::Destroy();
+ }
+
+ public function ApplyChanges() {
+ //Never delete this line!
+ parent::ApplyChanges();
+
+ //Basic Data
+ $vpos = 100;
+ $this->MaintainVariable("DeviceModel", $this->Translate("Device Model"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+ $this->MaintainVariable("SoftwareVersion", $this->Translate("Software Version"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+ $this->MaintainVariable("Satisfaction", $this->Translate("Satisfaction"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+ $this->MaintainVariable("LastSeen", $this->Translate("Last Seen"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+ $this->MaintainVariable("Uptime", $this->Translate("Uptime in hours"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+ //$this->MaintainVariable("IPAddress", $this->Translate("IP Address"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+ $this->MaintainVariable("Name", $this->Translate("Device Name"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+
+ //Hardware Data
+ $vpos = 200;
+ $this->MaintainVariable("CPULoad", $this->Translate("CPU Load"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointHardware") == 1);
+ $this->MaintainVariable("MemoryLoad", $this->Translate("Memory Load"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointHardware") == 1);
+
+
+ //Device Specific Data Connection Data UDM/USG
+ $vpos = 300;
+ $this->MaintainVariable("WAN1IP", $this->Translate("WAN1 IP"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
+ $this->MaintainVariable("WAN1TXBytes", $this->Translate("WAN 1 TX Megabytes"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
+ $this->MaintainVariable("WAN1RXBytes", $this->Translate("WAN 1 RX Megabytes"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
+ $this->MaintainVariable("WAN1TXPackets", $this->Translate("WAN 1 TX Packets"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
+ $this->MaintainVariable("WAN1RXPackets", $this->Translate("WAN 1 RX Packets"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
+ $this->MaintainVariable("WAN1TXErrors", $this->Translate("WAN 1 TX Errors"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
+ $this->MaintainVariable("WAN1RXErrors", $this->Translate("WAN 1 RX Errors"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
+
+ $TimerMS = $this->ReadPropertyInteger("Timer") * 1000;
+ $this->SetTimerInterval("Device Monitor",$TimerMS);
+
+ if (0 == $TimerMS) {
+ // instance inactive
+ $this->SetStatus(104);
+ }
+ else {
+ // instance active
+ $this->SetStatus(102);
+ }
+
+ }
+
+
+ public function AuthenticateAndGetData() {
+
+ $ControllerType = $this->ReadPropertyInteger("ControllerType");
+ $ServerAdress = $this->ReadPropertyString("ServerAdress");
+ $ServerPort = $this->ReadPropertyInteger("ServerPort");
+ $Username = $this->ReadPropertyString("UserName");
+ $Password = $this->ReadPropertyString("Password");
+ $Site = $this->ReadPropertyString("Site");
+
+ $DeviceMac = strtolower($this->ReadPropertyString("DeviceMac"));
+
+ ////////////////////////////////////////
+ //Change the Unifi API to be called here
+ $UnifiAPI = "api/s/".$Site."/stat/device";
+ ////////////////////////////////////////
+
+ //Generic Section providing for Authenthication against a Dream Maschine or Classic CloudKey
+
+ $ch = curl_init();
+
+ if ($ControllerType == 0) {
+ $SuffixURL = "/api/auth/login";
+ curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$Username."&password=".$Password);
+ }
+ elseif ($ControllerType == 1) {
+ $SuffixURL = "/api/login";
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['username' => $Username, 'password' => $Password]));
+ }
+ curl_setopt($ch, CURLOPT_POST, TRUE);
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$SuffixURL);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
+ curl_setopt($ch, CURLOPT_HEADER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ $data = curl_exec($ch);
+
+ $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
+ $body = trim(substr($data, $header_size));
+ $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$code,0);
+ preg_match_all('|(?i)Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
+ if (isset($results[1])) {
+ $Cookie = implode(';', $results[1]);
+ if (!empty($body)) {
+ if ($code == 200) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
+ }
+ else if ($code == 400) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ }
+ else if ($code == 401 || $code == 403) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ }
+ }
+ }
+
+ // Section below will collect and store it into a buffer
+
+ if (isset($Cookie)) {
+
+ $ch = curl_init();
+ if ($ControllerType == 0) {
+ $MiddlePartURL = "/proxy/network/";
+ }
+ elseif ($ControllerType == 1) {
+ $MiddlePartURL = "/";
+ }
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$MiddlePartURL.$UnifiAPI."/".$DeviceMac);
+ curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
+ curl_setopt($ch , CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array("cookie: ".$Cookie));
+ curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1');
+
+ $RawData = curl_exec($ch);
+ curl_close($ch);
+
+ if (isset($RawData) AND $RawData != "Unauthorized") {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Successfully Called"),0);
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Data Provided: ").$RawData,0);
+ $this->SetBuffer("RawData",$RawData);
+ }
+ else {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("API could not be called - check the login data. Do you see a Cookie?"),0);
+ }
+ }
+
+ }
+
+ public function DeviceMonitor() {
+
+ $this->AuthenticateAndGetData();
+ $RawData = $this->GetBuffer("RawData");
+
+ if ($RawData !== "") {
+ $JSONData = json_decode($RawData,true);
+ //var_dump($JSONData);
+ $DeviceModel = $JSONData["data"][0]["model"];
+ $UnfiInternetDeviceArray = array("UDM","UGW4","UGW3","UDMPRO");
+
+ if (!in_array($DeviceModel,$UnfiInternetDeviceArray) AND $this->ReadPropertyInteger("DeviceType") == 0) {
+ $DeviceConfigError = true;
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Config error - device type set to UDM, USG etc. but is no such device."),0);
+ }
+ else {
+ $DeviceConfigError = false;
+ }
+
+ if ($this->ReadPropertyBoolean("DataPointBasic") == 1) {
+ $DeviceModel = $JSONData["data"][0]["model"];
+ SetValue($this->GetIDForIdent("DeviceModel"),$DeviceModel);
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Device Model ").$DeviceModel,0);
+ $SoftwareVersion = $JSONData["data"][0]["version"];
+ SetValue($this->GetIDForIdent("SoftwareVersion"),$SoftwareVersion);
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Software Version ").$SoftwareVersion,0);
+ $Satisfaction = $JSONData["data"][0]["satisfaction"];
+ SetValue($this->GetIDForIdent("Satisfaction"),$Satisfaction);
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Device Satisfaction ").$Satisfaction,0);
+ $SLastSeen = $JSONData["data"][0]["last_seen"];
+ SetValue($this->GetIDForIdent("LastSeen"),gmdate("Y-m-d H:i:s", $SLastSeen));
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Connection Data Last Seen ").gmdate("Y-m-d H:i:s", $SLastSeen),0);
+ $Uptime = $JSONData["data"][0]["uptime"];
+ SetValue($this->GetIDForIdent("Uptime"),Round($Uptime/3600,0));
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Connection Data Uptime in hours ").Round($Uptime/3600,0),0);
+ $Name = $JSONData["data"][0]["name"];
+ SetValue($this->GetIDForIdent("Name"),$Name);
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Devicename ").$Name,0);
+ }
+ if ($this->ReadPropertyBoolean("DataPointHardware") == 1) {
+ $CPULoad = $JSONData["data"][0]["system-stats"]["cpu"];
+ SetValue($this->GetIDForIdent("CPULoad"),$CPULoad);
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("CPU Load ").$CPULoad,0);
+ $MemoryLoad = $JSONData["data"][0]["system-stats"]["mem"];
+ SetValue($this->GetIDForIdent("MemoryLoad"),$MemoryLoad);
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Memory Load ").$MemoryLoad,0);
+
+ }
+ if ($this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0 AND $DeviceConfigError == false) {
+ $WAN1IP = $JSONData["data"][0]["wan1"]["ip"];
+ SetValue($this->GetIDForIdent("WAN1IP"),$WAN1IP);
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Connection Data WAN 1 IP ").$WAN1IP,0);
+
+ $WAN1TXBytes = $JSONData["data"][0]["wan1"]["tx_bytes"];
+ SetValue($this->GetIDForIdent("WAN1TXBytes"),$WAN1TXBytes/1000000);
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Transfer Data WAN 1 TX Bytes ").$WAN1TXBytes,0);
+ $WAN1RXBytes = $JSONData["data"][0]["wan1"]["rx_bytes"];
+ SetValue($this->GetIDForIdent("WAN1RXBytes"),$WAN1RXBytes/1000000);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Transfer Data WAN 1 RX Bytes ").$WAN1RXBytes,0);
+ $WAN1TXPackets = $JSONData["data"][0]["wan1"]["tx_packets"];
+ SetValue($this->GetIDForIdent("WAN1TXPackets"),$WAN1TXPackets);
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Transfer Data WAN 1 TX Packets ").$WAN1TXPackets,0);
+ $WAN1RXPackets = $JSONData["data"][0]["wan1"]["tx_packets"];
+ SetValue($this->GetIDForIdent("WAN1RXPackets"),$WAN1RXPackets);
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Transfer Data WAN 1 RXPackets ").$WAN1RXPackets,0);
+ $WAN1TXErrors = $JSONData["data"][0]["wan1"]["tx_errors"];
+ SetValue($this->GetIDForIdent("WAN1TXErrors"),$WAN1TXErrors);
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Transfer Data WAN 1 TX Errors ").$WAN1TXErrors,0);
+ $WAN1RXErrors = $JSONData["data"][0]["wan1"]["rx_errors"];
+ SetValue($this->GetIDForIdent("WAN1RXErrors"),$WAN1RXErrors);
+ $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Transfer Data WAN 1 RX Errors ").$WAN1RXErrors,0);
+ }
+ }
+ else {
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("There does not seem to be any configuration - no data is available from the UniFi"),0);
+ }
+
+ }
+
+ }
diff --git a/UniFi Endpoint Monitor/README.md b/UniFi Endpoint Monitor/README.md
new file mode 100644
index 0000000..f20efb3
--- /dev/null
+++ b/UniFi Endpoint Monitor/README.md
@@ -0,0 +1,82 @@
+# UniFi Endpoint Monitor
+Dieses Modul ermöglicht es Endgeräte im Netz zu überwachen und diverse Daten in Symcon darzustellen.
+
+### Inhaltsverzeichnis
+
+1. [Funktionsumfang](#1-funktionsumfang)
+2. [Voraussetzungen](#2-voraussetzungen)
+3. [Software-Installation](#3-software-installation)
+4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon)
+5. [Versionsinformation](#5-versionsinformation)
+
+### 1. Funktionsumfang
+
+* Unterstützung für UniFi Cloudkey 1
+* Unterstützung für UniFi Cloudkey 2 und Dream Maschine
+* Anlegen von zu überwachenden Geräten mit Name und MAC Adresse
+* Erstellt pro Gerät eine Variable welche z.B. für die Automation oder Überwachung genutzt werden kann (Boolean)
+* Abfragen der Controller erfolgt zeitgesteuert alle xx Sekunden
+
+### 2. Vorraussetzungen
+
+- IP-Symcon ab Version 5.5
+
+### 3. Software-Installation
+
+* Über den Module Store das 'UniFi Presence Manager'-Modul installieren.
+* Alternativ über das Module Control folgende URL hinzufügen
+
+### 4. Einrichten der Instanzen in IP-Symcon
+
+ Unter 'Instanz hinzufügen' kann das 'UniFi Presence Manager'-Modul mithilfe des Schnellfilters gefunden werden.
+ - Weitere Informationen zum Hinzufügen von Instanzen in der [Dokumentation der Instanzen](https://www.symcon.de/service/dokumentation/konzepte/instanzen/#Instanz_hinzufügen)
+
+__Konfigurationsseite__:
+
+**Art des Controllers**
+
+Da sich die APIs von CloudKey 1 und CloudKey2/Dreammaschine unterscheiden, kann hier der Controller gewählt werden
+
+**Benutzername & Kennwort**
+
+Account mit dem sich das Modul mit dem Controller verbindet
+
+**Site**
+
+Site die im Controller hinterlegt ist
+
+**IP Adresse und Port**
+
+Bei der Dream Maschine ist der Port 443, bei einem Controller im Standard 8443. IP Addresse des CloudKeys oder der Dream Maschine.
+
+**Aktualisierungsfrequenz**
+
+Da der Controller aktiv abfragt werden muss, kann man hier eine Frequenz hinterlegen wie oft dies geschehen soll.
+
+**MAC Adresse**
+
+Die MAC Adresse des zu überwachenden Geräts. Diese am besten aus dem Controller auslesen.
+
+**Art der Verbindung**
+
+Basierend auf der Art der Verbindung stehen unterschiedliche Informationen zur Verfügung. Die meisten werden von Geräten im WLAN generiert.
+
+**Netzwerkdaten**
+
+Netzwerkdaten umfassen logische Daten wie IP Adresse oder Hostname.
+
+**Verbindungsdaten**
+
+Hier werden verfügbare physische Daten bereitgestellt. Hierzu zählen bei WLAN Geräten Informationen zu Verbingunsqualität, Zuletzt gesehen, Uptime, Kanal, Art der Technologie, SSID, Dämpfung, Signalstärke.
+
+**Übertragungsdaten**
+
+Bei WLAN Geräten werden hier Informationen zu übertragenen Daten und Paketen geliefert.
+
+**Debugging**
+Das Modul gibt diverse Informatioen im Debug Bereich aus.
+
+## 5. Versionsinformation
+
+Version 1.2 - 27-12-2021
+* Neu - Modul verfügbar
\ No newline at end of file
diff --git a/UniFi Endpoint Monitor/form.json b/UniFi Endpoint Monitor/form.json
new file mode 100644
index 0000000..0da60a1
--- /dev/null
+++ b/UniFi Endpoint Monitor/form.json
@@ -0,0 +1,154 @@
+{
+ "elements": [
+ {
+ "type": "ExpansionPanel",
+ "caption": "Module Help",
+ "items": [
+ {
+ "type": "Label",
+ "label": "This Module allows to monitor devices connected to a UniFi Network and provide data in variables."
+ },
+ {
+ "type": "Label",
+ "label": "Please select the type of controller you are using, enter its IP Adress, Port and a user allowed to log in."
+ },
+ {
+ "type": "Label",
+ "label": "To manage certain devices, please use their MAC adress - easiest method might be to take it from the controller interface."
+ },
+ {
+ "type": "Label",
+ "label": "Please turn on the data points you would like to monitor and variables will be created accordingly."
+ },
+ {
+ "type": "Label",
+ "label": "Updates will happen on a schedule every xyz seconds."
+ },
+ {
+ "type": "Label",
+ "label": "For debugging, please use the Debug function of the module."
+ }
+ ]
+ },
+ {
+ "type": "Label",
+ "label": "UniFi Toolbox - Endpoint Monitor Configuration"
+ },
+ {
+ "type": "Select",
+ "name": "ControllerType",
+ "caption": "Controller Type",
+ "options": [
+ {
+ "caption": "Dream Maschine / Pro / CloudKey V2",
+ "value": 0
+ },
+ {
+ "caption": "CloudKey",
+ "value": 1
+ }
+ ]
+ },
+ {
+ "type": "ValidationTextBox",
+ "name": "Site",
+ "caption": "Site"
+ },
+ {
+ "type": "ValidationTextBox",
+ "name": "ServerAdress",
+ "caption": "Server Address",
+ "validate": "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
+ },
+ {
+ "type": "NumberSpinner",
+ "name": "ServerPort",
+ "caption": "Server Port",
+ "digits": 0,
+ "minimum": 1,
+ "maximum": 65535
+ },
+ {
+ "type": "ValidationTextBox",
+ "name": "UserName",
+ "caption": "User Name"
+ },
+ {
+ "type": "PasswordTextBox",
+ "name": "Password",
+ "caption": "Password"
+ },
+ {
+ "type": "NumberSpinner",
+ "name": "Timer",
+ "caption": "Update Frequency",
+ "suffix": "sec - 0 is off"
+ },
+ {
+ "type": "Label",
+ "label": "Please enter the MAC Address of the device to be monitored."
+ },
+ {
+ "type": "ValidationTextBox",
+ "name": "DeviceMac",
+ "caption": "Device MAC Address",
+ "validate": "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})|([0-9a-fA-F]{4}\\.[0-9a-fA-F]{4}\\.[0-9a-fA-F]{4})$"
+ },
+ {
+ "type": "Label",
+ "label": "Please select how the device to be monitor is connected - this will switch on/off certain variables."
+ },
+ {
+ "type": "Select",
+ "name": "ConnectionType",
+ "caption": "Connection Type",
+ "options": [
+ {
+ "caption": "Wireless",
+ "value": 0
+ },
+ {
+ "caption": "Wired",
+ "value": 1
+ }
+ ]
+ },
+ {
+ "type": "CheckBox",
+ "name": "DataPointNetwork",
+ "caption": "Network Data"
+ },
+ {
+ "type": "CheckBox",
+ "name": "DataPointConnection",
+ "caption": "Connection Data"
+ },
+ {
+ "type": "Label",
+ "label": "Transfer data is only available on wireless devices."
+ },
+ {
+ "type": "CheckBox",
+ "name": "DataPointTransfer",
+ "caption": "Transfer Data"
+ }
+ ],
+ "actions": [
+ {
+ "type": "RowLayout",
+ "items": [
+ {
+ "type": "Button",
+ "label": "Test Authentication",
+ "onClick": "EM_AuthenticateAndGetData($id);"
+ },
+ {
+ "type": "Button",
+ "label": "Get Device Data",
+ "onClick": "EM_EndpointMonitor($id);"
+ }
+ ]
+ }
+ ],
+ "status": []
+}
\ No newline at end of file
diff --git a/UniFi Endpoint Monitor/locale.json b/UniFi Endpoint Monitor/locale.json
new file mode 100644
index 0000000..bc29de7
--- /dev/null
+++ b/UniFi Endpoint Monitor/locale.json
@@ -0,0 +1,43 @@
+{
+ "translations": {
+ "de": {
+ "Module Help": "Modul Hilfe",
+ "This Module allows to monitor devices connected to a UniFi Network and provide data in variables.": "Dieses Modul ermöglicht es Geräte im Netz zu überwachen und Daten in Variablen anzuzeigen.",
+ "Please select the type of controller you are using, enter its IP Adress, Port and a user allowed to log in.": "Bitte wählen sie die Art des Controllers und geben die IP Adresse, Port und einen Anwender ein der auf diesen zugreifen darf.",
+ "To manage certain devices, please use their MAC adress - easiest method might be to take it from the controller interface.": "Um Geräte zu verwalten, geben sie bitte die MAC Addresse ein - diese können am einfachsten aus dem Controller ausgelesen werden.",
+ "Please turn on the data points you would like to monitor and variables will be created accordingly.": "Die gewünschten Datenpunkte können in der Konfiguration ausgewählt werden.",
+ "Updates will happen on a schedule every xyz seconds.": "Das Module prüft die Anwensenheit alle xyz Sekunden, wie im Module konfiguriert",
+ "For debugging, please use the Debug function of the module.": "Für das Prüfen der Funktionen, gibt es Modul Meldungen im Debugbereich aus",
+ "UniFi Toolbox - Endpoint Monitor Configuration": "UniFi Toolbox - Endgeräte Überwachung Konfiguration",
+ "Controller Type": "Art des Controllers",
+ "Server Address": "Server Adresse",
+ "User Name": "Anmeldename",
+ "Password": "Passwort",
+ "Update Frequency": "Aktualisierungsfrequenz",
+ "sec - 0 is off": "Sek - 0 ist Aus",
+ "Please enter the MAC Address of the device to be monitored.": "MAC Adresse die überwacht werden soll.",
+ "Device MAC Address": "Geräte MAC Adresse",
+ "Please select how the device to be monitor is connected - this will switch on/off certain variables.": "Bitte wählen wie das zu überwachende Gerät verbunden ist - dies bestimmt die möglichen Variablen.",
+ "Connection Type": "Art der Verbindung",
+ "Wireless": "WLAN",
+ "Wired": "Kabel",
+ "Config error - device monitored is a wired device. Please select wired in the module configuration.": "Konfigurationsfehler - das überwachte Gerät ist verkabelt. Bitte dies in der Modulkonfiguration einstellen.",
+ "Network Data": "Netzwerkdaten",
+ "Connection Data": "Verbindungsdaten",
+ "Transfer data is only available on wireless devices.": "Übertragungsdaten sind nur bei WLAN Geräten verfügbar.",
+ "Transfer Data": "Übertragungsdaten",
+ "Test Authentication": "Teste Anmeldung am Controller",
+ "Get Device Data": "Hole Gerätedaten",
+ "IP Address": "IP Adresse",
+ "Satisfaction": "Verbindungsqualität",
+ "Last Seen": "Zuletzt gesehen",
+ "Uptime in hours": "Verbunden seit - in Stunden",
+ "Channel": "Kanal",
+ "Radio": "Funktechnologie",
+ "Noise": "Störung",
+ "Signal Strength": "Signal Stärke",
+ "TX Packets": "TX Pakete",
+ "RX Packets": "RX Pakete"
+ }
+ }
+}
\ No newline at end of file
diff --git a/UniFi Endpoint Monitor/module.json b/UniFi Endpoint Monitor/module.json
new file mode 100644
index 0000000..f5c55c1
--- /dev/null
+++ b/UniFi Endpoint Monitor/module.json
@@ -0,0 +1,12 @@
+{
+ "id": "{99B923B9-F641-5787-927E-22F6EBCE1FDE}",
+ "name": "UniFi Endpoint Monitor",
+ "type": 3,
+ "vendor": "UniFi",
+ "aliases": [],
+ "parentRequirements": [],
+ "childRequirements": [],
+ "implemented": [],
+ "prefix": "EM",
+ "url": "https://github.com/elueckel/Unifi-Toolbox/tree/main/UniFi%20Endpoint%20Monitor"
+}
\ No newline at end of file
diff --git a/UniFi Endpoint Monitor/module.php b/UniFi Endpoint Monitor/module.php
new file mode 100644
index 0000000..bc33c43
--- /dev/null
+++ b/UniFi Endpoint Monitor/module.php
@@ -0,0 +1,274 @@
+RegisterPropertyInteger("ControllerType", 0);
+ $this->RegisterPropertyString("ServerAdress","192.168.1.1");
+ $this->RegisterPropertyInteger("ServerPort", "443");
+ $this->RegisterPropertyString("Site","default");
+ $this->RegisterPropertyString("UserName","");
+ $this->RegisterPropertyString("Password","");
+ $this->RegisterPropertyInteger("Timer", "0");
+
+ $this->RegisterPropertyString("DeviceMac", "");
+ $this->RegisterPropertyInteger("ConnectionType", 0);
+
+ $this->RegisterPropertyBoolean("DataPointNetwork", 0);
+ $this->RegisterPropertyBoolean("DataPointConnection", 0);
+ $this->RegisterPropertyBoolean("DataPointTransfer", 0);
+
+ $this->RegisterTimer("Endpoint Monitor",0,"EM_EndpointMonitor(\$_IPS['TARGET']);");
+
+ }
+
+ public function Destroy() {
+ //Never delete this line!
+ parent::Destroy();
+ }
+
+ public function ApplyChanges() {
+ //Never delete this line!
+ parent::ApplyChanges();
+
+ //Network Data
+ $vpos = 100;
+ $this->MaintainVariable("IPAddress", $this->Translate("IP Address"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointNetwork") == 1);
+ $this->MaintainVariable("Hostname", $this->Translate("Hostname"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointNetwork") == 1);
+ //$this->MaintainVariable("Name", $this->Translate("Name"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointNetwork") == 1);
+
+ //Connection Data General
+ $vpos = 200;
+ $this->MaintainVariable("Satisfaction", $this->Translate("Satisfaction"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1);
+ $this->MaintainVariable("LastSeen", $this->Translate("Last Seen"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1);
+ $this->MaintainVariable("Uptime", $this->Translate("Uptime in hours"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1);
+ //Connection Data Wired
+ $vpos = 230;
+ //$this->MaintainVariable("SwitchPort", $this->Translate("Switch Port"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 1);
+ //$this->MaintainVariable("SwitchMAC", $this->Translate("Switch MAC"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 1);
+ //Connection Data Wireless
+ $vpos = 250;
+ $this->MaintainVariable("Accesspoint", $this->Translate("Accesspoint"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("Channel", $this->Translate("Channel"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("Radio", $this->Translate("Radio"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("ESSID", $this->Translate("ESS ID"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("RSSI", $this->Translate("RSSI"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("Noise", $this->Translate("Noise"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("SignalStrength", $this->Translate("Signal Strength"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+
+ //Transfer Data
+ $vpos = 300;
+ $this->MaintainVariable("TXBytes", $this->Translate("TX Megabytes"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointTransfer") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("RXBytes", $this->Translate("RX Megabytes"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointTransfer") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("TXPackets", $this->Translate("TX Packets"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointTransfer") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("RXPackets", $this->Translate("RX Packets"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointTransfer") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+
+
+ $TimerMS = $this->ReadPropertyInteger("Timer") * 1000;
+ $this->SetTimerInterval("Endpoint Monitor",$TimerMS);
+
+ if (0 == $TimerMS) {
+ // instance inactive
+ $this->SetStatus(104);
+ }
+ else {
+ // instance active
+ $this->SetStatus(102);
+ }
+
+ }
+
+
+ public function AuthenticateAndGetData() {
+
+ $ControllerType = $this->ReadPropertyInteger("ControllerType");
+ $ServerAdress = $this->ReadPropertyString("ServerAdress");
+ $ServerPort = $this->ReadPropertyInteger("ServerPort");
+ $Username = $this->ReadPropertyString("UserName");
+ $Password = $this->ReadPropertyString("Password");
+ $Site = $this->ReadPropertyString("Site");
+
+ $DeviceMac = strtolower($this->ReadPropertyString("DeviceMac"));
+
+ ////////////////////////////////////////
+ //Change the Unifi API to be called here
+ $UnifiAPI = "api/s/".$Site."/stat/sta";
+ ////////////////////////////////////////
+
+ //Generic Section providing for Authenthication against a Dream Maschine or Classic CloudKey
+
+
+ $ch = curl_init();
+
+ if ($ControllerType == 0) {
+ $SuffixURL = "/api/auth/login";
+ curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$Username."&password=".$Password);
+ }
+ elseif ($ControllerType == 1) {
+ $SuffixURL = "/api/login";
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['username' => $Username, 'password' => $Password]));
+ }
+ curl_setopt($ch, CURLOPT_POST, TRUE);
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$SuffixURL);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
+ curl_setopt($ch, CURLOPT_HEADER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ $data = curl_exec($ch);
+
+ $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
+ $body = trim(substr($data, $header_size));
+ $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$code,0);
+ preg_match_all('|(?i)Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
+ if (isset($results[1])) {
+ $Cookie = implode(';', $results[1]);
+ if (!empty($body)) {
+ if ($code == 200) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
+ }
+ else if ($code == 400) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ }
+ else if ($code == 401 || $code == 403) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ }
+ }
+ }
+
+ // Section below will collect and store it into a buffer
+
+ if (isset($Cookie)) {
+
+ $ch = curl_init();
+ if ($ControllerType == 0) {
+ $MiddlePartURL = "/proxy/network/";
+ }
+ elseif ($ControllerType == 1) {
+ $MiddlePartURL = "/";
+ }
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$MiddlePartURL.$UnifiAPI."/".$DeviceMac);
+ curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
+ curl_setopt($ch , CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array("cookie: ".$Cookie));
+ curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1');
+
+ $RawData = curl_exec($ch);
+ curl_close($ch);
+ //$JSON = json_decode($RawData,true);
+ //$this->SetBuffer("$RawData",$RawData);
+
+ if (isset($RawData) AND $RawData != "Unauthorized") {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Successfully Called"),0);
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Data Provided: ").$RawData,0);
+ $this->SetBuffer("RawData",$RawData);
+ }
+ else {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("API could not be called - check the login data. Do you see a Cookie?"),0);
+ }
+ }
+
+ }
+
+ public function EndpointMonitor() {
+
+ $this->AuthenticateAndGetData();
+ $RawData = $this->GetBuffer("RawData");
+
+ if ($RawData !== "") {
+ $JSONData = json_decode($RawData,true);
+ $ConnectionMethod = $JSONData["data"][0]["is_wired"];
+
+ if ($ConnectionMethod == true AND $this->ReadPropertyInteger("ConnectionType") == 0) {
+ $ConnectionConfigError = true;
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Config error - device monitored is a wired device. Please select wired in the module configuration."),0);
+ }
+ else {
+ $ConnectionConfigError = false;
+ }
+
+ if ($this->ReadPropertyBoolean("DataPointNetwork") == 1) {
+ $IPAddress = $JSONData["data"][0]["ip"];
+ SetValue($this->GetIDForIdent("IPAddress"),$IPAddress);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Network Data IP ").$IPAddress,0);
+ $Hostname = $JSONData["data"][0]["hostname"];
+ SetValue($this->GetIDForIdent("Hostname"),$Hostname);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Network Data Hostname ").$Hostname,0);
+ //$Name = $JSONData["data"][0]["name"];
+ //SetValue($this->GetIDForIdent("Name"),$Name);
+ //$this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Network Data Name ").$Name,0);
+ }
+ if ($this->ReadPropertyBoolean("DataPointConnection") == 1) {
+ $Satisfaction = $JSONData["data"][0]["satisfaction"];
+ SetValue($this->GetIDForIdent("Satisfaction"),$Satisfaction);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data Satisfaction ").$Satisfaction,0);
+ $SLastSeen = $JSONData["data"][0]["last_seen"];
+ SetValue($this->GetIDForIdent("LastSeen"),gmdate("Y-m-d H:i:s", $SLastSeen));
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data Last Seen ").gmdate("Y-m-d H:i:s", $SLastSeen),0);
+ $Uptime = $JSONData["data"][0]["uptime"];
+ SetValue($this->GetIDForIdent("Uptime"),Round($Uptime/3600,0));
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data Uptime in hours ").Round($Uptime/3600,0),0);
+ }
+ if ($this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0 AND $ConnectionConfigError == false) {
+ $Accesspoint = $JSONData["data"][0]["ap_mac"];
+ SetValue($this->GetIDForIdent("Accesspoint"),$Accesspoint);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data Accesspoint ").$Accesspoint,0);
+ $Channel = $JSONData["data"][0]["channel"];
+ SetValue($this->GetIDForIdent("Channel"),$Channel);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data Channel ").$Channel,0);
+ $Radio = $JSONData["data"][0]["radio"];
+ SetValue($this->GetIDForIdent("Radio"),$Radio);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data Radio ").$Radio,0);
+ $ESSID = $JSONData["data"][0]["essid"];
+ SetValue($this->GetIDForIdent("ESSID"),$ESSID);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data ESSID ").$ESSID,0);
+ $RSSI = $JSONData["data"][0]["rssi"];
+ SetValue($this->GetIDForIdent("RSSI"),$RSSI);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data RSSI ").$RSSI,0);
+ $Noise = $JSONData["data"][0]["noise"];
+ SetValue($this->GetIDForIdent("Noise"),$Noise);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data Noise ").$Noise,0);
+ $SignalStrength = $JSONData["data"][0]["signal"];
+ SetValue($this->GetIDForIdent("SignalStrength"),$SignalStrength);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data SignalStrength ").$SignalStrength,0);
+ }
+ if ($this->ReadPropertyBoolean("DataPointTransfer") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0 AND $ConnectionConfigError == false) {
+ $TXBytes = $JSONData["data"][0]["tx_bytes"];
+ SetValue($this->GetIDForIdent("TXBytes"),$TXBytes/1000000);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Transfer Data TXBytes ").$TXBytes/1000000,0);
+ $RXBytes = $JSONData["data"][0]["rx_bytes"];
+ SetValue($this->GetIDForIdent("RXBytes"),$RXBytes/1000000);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Transfer Data RXBytes ").$RXBytes/1000000,0);
+ $TXPackets = $JSONData["data"][0]["tx_packets"];
+ SetValue($this->GetIDForIdent("TXPackets"),$TXPackets);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Transfer Data TXPackets ").$TXPackets,0);
+ $RXPackets = $JSONData["data"][0]["rx_packets"];
+ SetValue($this->GetIDForIdent("RXPackets"),$RXPackets);
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Transfer Data RXPackets ").$RXPackets,0);
+ }
+ }
+ else {
+ $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("There does not seem to be any configuration - no data is available from the UniFi"),0);
+ }
+
+ }
+
+ }
diff --git a/UniFi Presence Manager/README.md b/UniFi Presence Manager/README.md
index f84d64f..f8ea254 100644
--- a/UniFi Presence Manager/README.md
+++ b/UniFi Presence Manager/README.md
@@ -81,4 +81,7 @@ Version 1.0 - 09-09-2021
Version 1.1 - 25-12-2021
* Fix - Memory Leak
-* Fix - HTTP Response Error Message
\ No newline at end of file
+* Fix - HTTP Response Error Message
+
+Version 1.2 - 27-12-2021
+* Neu - Endpoint Monitor zur Überwachung von Endgeräten
\ No newline at end of file
diff --git a/library.json b/library.json
index 1324c6a..1c50964 100644
--- a/library.json
+++ b/library.json
@@ -6,7 +6,7 @@
"compatibility": {
"version": "5.5"
},
- "version": "1.1",
+ "version": "1.2",
"build": 0,
"date": 0
}
From 3b1ee78554b16f280b6fb376ba55b7ae59fbcb97 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Wed, 29 Dec 2021 08:43:36 +0100
Subject: [PATCH 30/71] =?UTF-8?q?Voraussetzungen=20und=20Ger=C3=A4tebeschr?=
=?UTF-8?q?eibung=20erg=C3=A4nzt?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
UniFi Device Blocker/README.md | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/UniFi Device Blocker/README.md b/UniFi Device Blocker/README.md
index bd5a6e2..dd92ae6 100644
--- a/UniFi Device Blocker/README.md
+++ b/UniFi Device Blocker/README.md
@@ -21,6 +21,8 @@ Dieses Modul ermöglicht es Geräte im Netz zu blockieren, um z.B. den Zugang de
## 2. Vorraussetzungen
- IP-Symcon ab Version 5.5
+- Unifi Benutzer mit Owner oder Super-Admin Rechten (Limited-Admin Rechte sind nicht ausreichend!)
+
## 3. Software-Installation
@@ -56,7 +58,8 @@ Da der Controller aktiv abfragt werden muss, kann man hier eine Frequenz hinterl
**Geräte**
-Geräte die Überwacht werden sollen, werden einfach mit einem Namen und einer MAC Addresse in der Tabelle hinterlegt. Das Modul erstellt dann eine Boolean Variable mit Switch Profil welche in weiter Prozesse eingebunden werden kann um ein Gerät zu blocken oder eine blockade aufzulösen.
+Geräte die Überwacht werden sollen, werden einfach mit einem Namen und einer MAC Addresse in der Tabelle hinterlegt.
+Das Modul erstellt dann eine Boolean-Variable mit Switch-Profil, welche in weiter Prozesse eingebunden werden kann um ein Gerät zu blocken (=false) oder eine blockade aufzulösen (=true).
Das Modul selbst löscht keine Variablen, sollte sich ein Name ändern, dann wird eine neue erstellt und die alte im Objektbaum belassen.
**Debugging**
@@ -80,4 +83,4 @@ Version 1.0 - 09-09-2021
Version 1.1 - 25-12-2021
* Fix - Memory Leak
* Fix - HTTP Response Error Message
-* Variablen Management umgestellt - es Ident wird jetzt die MAC verwendet
\ No newline at end of file
+* Variablen Management umgestellt - es Ident wird jetzt die MAC verwendet
From fab8329b469c1e76b488057554b40d004ef5e82b Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Wed, 29 Dec 2021 10:35:55 +0100
Subject: [PATCH 31/71] changed from INT-value to define
---
UniFi Internet Controller/module.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Internet Controller/module.php b/UniFi Internet Controller/module.php
index d2f0d9a..c384859 100644
--- a/UniFi Internet Controller/module.php
+++ b/UniFi Internet Controller/module.php
@@ -49,7 +49,7 @@ public function Create() {
$this->RegisterTimer("Collect Connection Data",0,"IC_GetInternetData(\$_IPS['TARGET']);");
if (IPS_VariableProfileExists("IC.TimeS") == false){
- IPS_CreateVariableProfile("IC.TimeS", 1);
+ IPS_CreateVariableProfile("IC.TimeS", vtInteger);
IPS_SetVariableProfileValues("IC.TimeS", 0, 0, 1);
IPS_SetVariableProfileDigits("IC.TimeS", 2);
IPS_SetVariableProfileText("IC.TimeS", "", $this->Translate(" seconds"));
@@ -57,7 +57,7 @@ public function Create() {
}
if (IPS_VariableProfileExists("IC.TimeMS") == false){
- IPS_CreateVariableProfile("IC.TimeMS", 1);
+ IPS_CreateVariableProfile("IC.TimeMS", vtInteger);
IPS_SetVariableProfileValues("IC.TimeMS", 0, 0, 1);
IPS_SetVariableProfileDigits("IC.TimeMS", 2);
IPS_SetVariableProfileText("IC.TimeMS", "", $this->Translate(" milliseconds"));
From 5656caf12aae7e59a54949ddda61c0c917431e94 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Wed, 29 Dec 2021 18:51:00 +0100
Subject: [PATCH 32/71] EM timer fix - DM satisfaction removed
---
UniFi Device Monitor/module.php | 8 ++++----
UniFi Endpoint Monitor/module.php | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/UniFi Device Monitor/module.php b/UniFi Device Monitor/module.php
index 8a22392..3bae61f 100644
--- a/UniFi Device Monitor/module.php
+++ b/UniFi Device Monitor/module.php
@@ -49,7 +49,7 @@ public function ApplyChanges() {
$vpos = 100;
$this->MaintainVariable("DeviceModel", $this->Translate("Device Model"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
$this->MaintainVariable("SoftwareVersion", $this->Translate("Software Version"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
- $this->MaintainVariable("Satisfaction", $this->Translate("Satisfaction"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+ //$this->MaintainVariable("Satisfaction", $this->Translate("Satisfaction"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
$this->MaintainVariable("LastSeen", $this->Translate("Last Seen"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
$this->MaintainVariable("Uptime", $this->Translate("Uptime in hours"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
//$this->MaintainVariable("IPAddress", $this->Translate("IP Address"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
@@ -205,9 +205,9 @@ public function DeviceMonitor() {
$SoftwareVersion = $JSONData["data"][0]["version"];
SetValue($this->GetIDForIdent("SoftwareVersion"),$SoftwareVersion);
$this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Software Version ").$SoftwareVersion,0);
- $Satisfaction = $JSONData["data"][0]["satisfaction"];
- SetValue($this->GetIDForIdent("Satisfaction"),$Satisfaction);
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Device Satisfaction ").$Satisfaction,0);
+ //$Satisfaction = $JSONData["data"][0]["satisfaction"];
+ //SetValue($this->GetIDForIdent("Satisfaction"),$Satisfaction);
+ //$this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Device Satisfaction ").$Satisfaction,0);
$SLastSeen = $JSONData["data"][0]["last_seen"];
SetValue($this->GetIDForIdent("LastSeen"),gmdate("Y-m-d H:i:s", $SLastSeen));
$this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Connection Data Last Seen ").gmdate("Y-m-d H:i:s", $SLastSeen),0);
diff --git a/UniFi Endpoint Monitor/module.php b/UniFi Endpoint Monitor/module.php
index bc33c43..fa01e9f 100644
--- a/UniFi Endpoint Monitor/module.php
+++ b/UniFi Endpoint Monitor/module.php
@@ -10,7 +10,7 @@
define('vtArray', 8);
define('vtObject', 9);
}
- class UniFiEndpointMonitor extends IPSModule
+ class UnifiEndpointMonitor extends IPSModule
{
public function Create() {
//Never delete this line!
From 0e23c15a176367c589e3a9275d16923b03f4b7ad Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Wed, 29 Dec 2021 19:24:36 +0100
Subject: [PATCH 33/71] fix timer device monitor
---
UniFi Device Monitor/module.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/UniFi Device Monitor/module.php b/UniFi Device Monitor/module.php
index 3bae61f..34decea 100644
--- a/UniFi Device Monitor/module.php
+++ b/UniFi Device Monitor/module.php
@@ -32,7 +32,7 @@ public function Create() {
$this->RegisterPropertyBoolean("DataPointSpecific", 0);
- $this->RegisterTimer("Device Monitor",0,"DM_EndpointMonitor(\$_IPS['TARGET']);");
+ $this->RegisterTimer("Device Monitor",0,"DM_DeviceMonitor(\$_IPS['TARGET']);");
}
From 55cba151387f06b47e02305127fd0da9a558191f Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 10:30:06 +0100
Subject: [PATCH 34/71] bugfix for #20
#20 Only last Device in list can be blocked
---
UniFi Device Blocker/module.php | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index 874fa48..98d0722 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -167,25 +167,23 @@ public function AuthenticateAndProcessRequest() {
$DevicesJSON = json_decode($DevicesList,true);
if (isset($DevicesJSON)) {
+ $DeviceMacAdress = "";
+
foreach ($DevicesJSON as $Device) {
$DeviceMacClean = str_replace(array(":"," "), "", $Device["varDeviceMAC"]);
if ($SenderObjectIdent == $DeviceMacClean) {
$DeviceMacAdress = $Device["varDeviceMAC"];
$this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Device to be managed: ").$Device["varDeviceName"],0);
- }
- else {
- $DeviceMacAdress = "";
+ break;
}
}
}
- if (!isset($DeviceMacAdress)) {
+ if (!isset($DeviceMacAdress) || "" == $DeviceMacAdress) {
$this->SendDebug($this->Translate("Device Blocker"),$this->Translate("The switched variable did not have an entry in the module configuration - execution stopped"),0);
exit;
}
-
-
$this->SendDebug($this->Translate("Device Blocker"),$Cookie,0);
From e94f72d2e53e6642d7b772c0dd79b352d071e5a3 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 10:50:08 +0100
Subject: [PATCH 35/71] address typo fixed
---
UniFi Device Blocker/form.json | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Device Blocker/form.json b/UniFi Device Blocker/form.json
index df901bf..ceff838 100644
--- a/UniFi Device Blocker/form.json
+++ b/UniFi Device Blocker/form.json
@@ -10,11 +10,11 @@
},
{
"type": "Label",
- "label": "Please select the type of controller you are using, enter its IP Adress, Port and a user allowed to log in."
+ "label": "Please select the type of controller you are using, enter its IP address, port and a user allowed to log in."
},
{
"type": "Label",
- "label": "To manage devices, please use their MAC adress and a clear text name, which will be used to create a variable in the object tree."
+ "label": "To manage devices, please use their MAC address and a clear text name, which will be used to create a variable in the object tree."
},
{
"type": "Label",
From 449978472c134909d09f2c32fbf62a70a108b2e1 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 10:50:54 +0100
Subject: [PATCH 36/71] address typo fixed
---
UniFi Device Blocker/locale.json | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Device Blocker/locale.json b/UniFi Device Blocker/locale.json
index d18dc29..c58a415 100644
--- a/UniFi Device Blocker/locale.json
+++ b/UniFi Device Blocker/locale.json
@@ -3,8 +3,8 @@
"de": {
"Module Help": "Modul Hilfe",
"This Module allows to block devices from accessing the network - e.g. block internet access of children post 20:00.": "Dieses Modul ermöglicht es Geräte im Netz zu blockieren, um z.B. den Zugang der Kinder zu Internet nach 20 Uhr zu blockieren.",
- "Please select the type of controller you are using, enter its IP Adress, Port and a user allowed to log in.": "Bitte wählen sie die Art des Controllers und geben die IP Adresse, Port und einen Anwender ein der auf diesen zugreifen darf.",
- "To manage certain devices, please use their MAC adress and a clear text name, which will be used to create a variable in the object tree.": "Um Geräte zu verwalten, geben sie bitte die MAC Addresse und einen Namen in der Form unten ein - anhand des Namens wird eine Boolean Variable im Objektbaum erstellt.",
+ "Please select the type of controller you are using, enter its IP address, port and a user allowed to log in.": "Bitte wählen sie die Art des Controllers und geben die IP Adresse, Port und einen Anwender ein der auf diesen zugreifen darf.",
+ "To manage certain devices, please use their MAC address and a clear text name, which will be used to create a variable in the object tree.": "Um Geräte zu verwalten, geben sie bitte die MAC Addresse und einen Namen in der Form unten ein - anhand des Namens wird eine Boolean Variable im Objektbaum erstellt.",
"This variable can than be turn on or off resulting in a block or unblock e.g. via the mobile app, webfront or other automation.": "Die Variable im Objektbaum kann im Webfront, der Mobile-App oder einer Automation genutzt werden um Geräte ein oder aus zu schalten.",
"Updates will happen on a schedule every xyz seconds.": "Das Module prüft die Anwensenheit alle xyz Sekunden, wie im Module konfiguriert",
"For debugging, please use the Debug function of the module.": "Für das Prüfen der Funktionen, gibt es Modul Meldungen im Debugbereich aus",
From 57d93c6f0d53b5e96f44a1db69d3310ead6903e8 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 10:53:51 +0100
Subject: [PATCH 37/71] address typo fixed
---
UniFi Device Blocker/module.php | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index 98d0722..af905f9 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -17,7 +17,7 @@ public function Create() {
parent::Create();
$this->RegisterPropertyInteger("ControllerType", 0);
- $this->RegisterPropertyString("ServerAdress","192.168.1.1");
+ $this->RegisterPropertyString("ServerAddress","192.168.1.1");
$this->RegisterPropertyInteger("ServerPort", "443");
$this->RegisterPropertyString("Site","default");
$this->RegisterPropertyString("UserName","");
@@ -48,8 +48,8 @@ public function ApplyChanges() {
foreach ($DevicesJSON as $Device) {
$DeviceName = $Device["varDeviceName"];
$DeviceNameClean = str_replace(array("-",":"," "), "", $DeviceName);
- $DeviceMacAdress = $Device["varDeviceMAC"];
- $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAdress);
+ $DeviceMacAddress = $Device["varDeviceMAC"];
+ $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAddress);
if (@IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID) == false) {
@@ -67,8 +67,8 @@ public function ApplyChanges() {
}
foreach ($DevicesJSON as $Device) {
- $DeviceMacAdress = $Device["varDeviceMAC"];
- $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAdress);
+ $DeviceMacAddress = $Device["varDeviceMAC"];
+ $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAddress);
$VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
$this->RegisterMessage($VarID, VM_UPDATE);
}
@@ -103,7 +103,7 @@ public function MessageSink($TimeStamp, $SenderID, $Message, $Data) {
public function AuthenticateAndProcessRequest() {
$ControllerType = $this->ReadPropertyInteger("ControllerType");
- $ServerAdress = $this->ReadPropertyString("ServerAdress");
+ $ServerAddress = $this->ReadPropertyString("ServerAddress");
$ServerPort = $this->ReadPropertyInteger("ServerPort");
$Username = $this->ReadPropertyString("UserName");
$Password = $this->ReadPropertyString("Password");
@@ -125,7 +125,7 @@ public function AuthenticateAndProcessRequest() {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['username' => $Username, 'password' => $Password]));
}
curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$SuffixURL);
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$SuffixURL);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
@@ -162,24 +162,24 @@ public function AuthenticateAndProcessRequest() {
$SenderObjectIdent = ($SenderObjectData["ObjectIdent"]);
$SenderStatus = GetValue($SenderID);
- //Get MAC Adress from Config form
+ //Get MAC Address from Config form
$DevicesList = $this->ReadPropertyString("Devices");
$DevicesJSON = json_decode($DevicesList,true);
if (isset($DevicesJSON)) {
- $DeviceMacAdress = "";
+ $DeviceMacAddress = "";
foreach ($DevicesJSON as $Device) {
$DeviceMacClean = str_replace(array(":"," "), "", $Device["varDeviceMAC"]);
if ($SenderObjectIdent == $DeviceMacClean) {
- $DeviceMacAdress = $Device["varDeviceMAC"];
+ $DeviceMacAddress = $Device["varDeviceMAC"];
$this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Device to be managed: ").$Device["varDeviceName"],0);
break;
}
}
}
- if (!isset($DeviceMacAdress) || "" == $DeviceMacAdress) {
+ if (!isset($DeviceMacAddress) || "" == $DeviceMacAddress) {
$this->SendDebug($this->Translate("Device Blocker"),$this->Translate("The switched variable did not have an entry in the module configuration - execution stopped"),0);
exit;
}
@@ -214,18 +214,18 @@ public function AuthenticateAndProcessRequest() {
if ($SenderStatus == 1) {
$Command = "unblock-sta";
- $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Module will try to unblock device ").$SenderName.$this->Translate(" with MAC adress ").$DeviceMacAdress,0);
+ $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Module will try to unblock device ").$SenderName.$this->Translate(" with MAC address ").$DeviceMacAddress,0);
}
else if ($SenderStatus == 0) {
$Command = "block-sta";
- $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Module will try to block device ").$SenderName.$this->Translate(" with MAC adress ").$DeviceMacAdress,0);
+ $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Module will try to block device ").$SenderName.$this->Translate(" with MAC address ").$DeviceMacAddress,0);
}
- //$CommandToController = json_encode(array($Command => $DeviceMacAdress));
+ //$CommandToController = json_encode(array($Command => $DeviceMacAddress));
$CommandToController = json_encode(array(
"cmd" => $Command,
- "mac" => $DeviceMacAdress
+ "mac" => $DeviceMacAddress
), JSON_UNESCAPED_SLASHES);
//var_dump($CommandToController);
@@ -239,7 +239,7 @@ public function AuthenticateAndProcessRequest() {
$MiddlePartURL = "/";
}
curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$MiddlePartURL.$UnifiAPI);
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$MiddlePartURL.$UnifiAPI);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Cookie:'.$Cookie,$X_CSRF_Token,'Content-Type:application/json', 'Expect:'/*,'data='.$CommandToController*/));
curl_setopt($ch, CURLOPT_POSTFIELDS, $CommandToController);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
From 910f38d1c306540bccf9f6d106edd505c572616a Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Thu, 30 Dec 2021 11:04:26 +0100
Subject: [PATCH 38/71] error feedback when using wrong login data
---
UniFi Device Blocker/locale.json | 2 ++
UniFi Device Blocker/module.php | 4 ++++
UniFi Device Monitor/locale.json | 2 ++
UniFi Device Monitor/module.php | 10 +++++++---
UniFi Endpoint Monitor/locale.json | 2 ++
UniFi Endpoint Monitor/module.php | 17 +++++++++++------
UniFi Internet Controller/locale.json | 2 ++
UniFi Internet Controller/module.php | 6 +++++-
UniFi Presence Manager/locale.json | 2 ++
UniFi Presence Manager/module.php | 4 ++++
10 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/UniFi Device Blocker/locale.json b/UniFi Device Blocker/locale.json
index d18dc29..8cc95fc 100644
--- a/UniFi Device Blocker/locale.json
+++ b/UniFi Device Blocker/locale.json
@@ -8,6 +8,8 @@
"This variable can than be turn on or off resulting in a block or unblock e.g. via the mobile app, webfront or other automation.": "Die Variable im Objektbaum kann im Webfront, der Mobile-App oder einer Automation genutzt werden um Geräte ein oder aus zu schalten.",
"Updates will happen on a schedule every xyz seconds.": "Das Module prüft die Anwensenheit alle xyz Sekunden, wie im Module konfiguriert",
"For debugging, please use the Debug function of the module.": "Für das Prüfen der Funktionen, gibt es Modul Meldungen im Debugbereich aus",
+ "400 Bad Request - The server cannot or will not process the request due to an apparent client error.": "400 Bad Request - Die Anfrage wird vom Controller nicht verarbeitet (falsche IP?) - Client Fehler.",
+ "401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?": "401 Unauthorized / 403 Forbidden - Die Anfrage ging an den richtigen Server, allerdings konnte sich Symcon nicht anmelden. Bitte Login Daten prüfen.",
"UniFi Toolbox - Presence Manager Configuration": "UniFi Toolbox - Anwesenheits Manager Konfiguration",
"Controller Type": "Art des Controllers",
"Server Address": "Server Adresse",
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index 874fa48..80a1ae4 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -148,9 +148,13 @@ public function AuthenticateAndProcessRequest() {
}
else if ($code == 400) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
+ exit();
}
else if ($code == 401 || $code == 403) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
+ exit();
}
}
}
diff --git a/UniFi Device Monitor/locale.json b/UniFi Device Monitor/locale.json
index bf752f4..1bad1aa 100644
--- a/UniFi Device Monitor/locale.json
+++ b/UniFi Device Monitor/locale.json
@@ -18,6 +18,8 @@
"Please enter the MAC Address of the device to be monitored.": "MAC Adresse die überwacht werden soll.",
"Device MAC Address": "Geräte MAC Adresse",
"Please select how the device to be monitor is connected - this will switch on/off certain variables.": "Bitte wählen wie das zu überwachende Gerät verbunden ist - dies bestimmt die möglichen Variablen.",
+ "400 Bad Request - The server cannot or will not process the request due to an apparent client error.": "400 Bad Request - Die Anfrage wird vom Controller nicht verarbeitet (falsche IP?) - Client Fehler.",
+ "401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?": "401 Unauthorized / 403 Forbidden - Die Anfrage ging an den richtigen Server, allerdings konnte sich Symcon nicht anmelden. Bitte Login Daten prüfen.",
"Connection Type": "Art der Verbindung",
"Wireless": "WLAN",
"Wired": "Kabel",
diff --git a/UniFi Device Monitor/module.php b/UniFi Device Monitor/module.php
index 34decea..e9f46ee 100644
--- a/UniFi Device Monitor/module.php
+++ b/UniFi Device Monitor/module.php
@@ -51,14 +51,14 @@ public function ApplyChanges() {
$this->MaintainVariable("SoftwareVersion", $this->Translate("Software Version"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
//$this->MaintainVariable("Satisfaction", $this->Translate("Satisfaction"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
$this->MaintainVariable("LastSeen", $this->Translate("Last Seen"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
- $this->MaintainVariable("Uptime", $this->Translate("Uptime in hours"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+ $this->MaintainVariable("Uptime", $this->Translate("Uptime in hours"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
//$this->MaintainVariable("IPAddress", $this->Translate("IP Address"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
$this->MaintainVariable("Name", $this->Translate("Device Name"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
//Hardware Data
$vpos = 200;
- $this->MaintainVariable("CPULoad", $this->Translate("CPU Load"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointHardware") == 1);
- $this->MaintainVariable("MemoryLoad", $this->Translate("Memory Load"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointHardware") == 1);
+ $this->MaintainVariable("CPULoad", $this->Translate("CPU Load"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointHardware") == 1);
+ $this->MaintainVariable("MemoryLoad", $this->Translate("Memory Load"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointHardware") == 1);
//Device Specific Data Connection Data UDM/USG
@@ -138,9 +138,13 @@ public function AuthenticateAndGetData() {
}
else if ($code == 400) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
+ exit();
}
else if ($code == 401 || $code == 403) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
+ exit();
}
}
}
diff --git a/UniFi Endpoint Monitor/locale.json b/UniFi Endpoint Monitor/locale.json
index bc29de7..11db47c 100644
--- a/UniFi Endpoint Monitor/locale.json
+++ b/UniFi Endpoint Monitor/locale.json
@@ -18,6 +18,8 @@
"Please enter the MAC Address of the device to be monitored.": "MAC Adresse die überwacht werden soll.",
"Device MAC Address": "Geräte MAC Adresse",
"Please select how the device to be monitor is connected - this will switch on/off certain variables.": "Bitte wählen wie das zu überwachende Gerät verbunden ist - dies bestimmt die möglichen Variablen.",
+ "400 Bad Request - The server cannot or will not process the request due to an apparent client error.": "400 Bad Request - Die Anfrage wird vom Controller nicht verarbeitet (falsche IP?) - Client Fehler.",
+ "401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?": "401 Unauthorized / 403 Forbidden - Die Anfrage ging an den richtigen Server, allerdings konnte sich Symcon nicht anmelden. Bitte Login Daten prüfen.",
"Connection Type": "Art der Verbindung",
"Wireless": "WLAN",
"Wired": "Kabel",
diff --git a/UniFi Endpoint Monitor/module.php b/UniFi Endpoint Monitor/module.php
index fa01e9f..5e72a67 100644
--- a/UniFi Endpoint Monitor/module.php
+++ b/UniFi Endpoint Monitor/module.php
@@ -52,9 +52,9 @@ public function ApplyChanges() {
//Connection Data General
$vpos = 200;
- $this->MaintainVariable("Satisfaction", $this->Translate("Satisfaction"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1);
+ $this->MaintainVariable("Satisfaction", $this->Translate("Satisfaction"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1);
$this->MaintainVariable("LastSeen", $this->Translate("Last Seen"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1);
- $this->MaintainVariable("Uptime", $this->Translate("Uptime in hours"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1);
+ $this->MaintainVariable("Uptime", $this->Translate("Uptime in hours"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1);
//Connection Data Wired
$vpos = 230;
//$this->MaintainVariable("SwitchPort", $this->Translate("Switch Port"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 1);
@@ -62,12 +62,12 @@ public function ApplyChanges() {
//Connection Data Wireless
$vpos = 250;
$this->MaintainVariable("Accesspoint", $this->Translate("Accesspoint"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
- $this->MaintainVariable("Channel", $this->Translate("Channel"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("Channel", $this->Translate("Channel"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
$this->MaintainVariable("Radio", $this->Translate("Radio"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
$this->MaintainVariable("ESSID", $this->Translate("ESS ID"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
- $this->MaintainVariable("RSSI", $this->Translate("RSSI"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
- $this->MaintainVariable("Noise", $this->Translate("Noise"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
- $this->MaintainVariable("SignalStrength", $this->Translate("Signal Strength"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("RSSI", $this->Translate("RSSI"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("Noise", $this->Translate("Noise"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("SignalStrength", $this->Translate("Signal Strength"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
//Transfer Data
$vpos = 300;
@@ -145,9 +145,13 @@ public function AuthenticateAndGetData() {
}
else if ($code == 400) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
+ exit();
}
else if ($code == 401 || $code == 403) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
+ exit();
}
}
}
@@ -191,6 +195,7 @@ public function AuthenticateAndGetData() {
public function EndpointMonitor() {
$this->AuthenticateAndGetData();
+
$RawData = $this->GetBuffer("RawData");
if ($RawData !== "") {
diff --git a/UniFi Internet Controller/locale.json b/UniFi Internet Controller/locale.json
index e60d3f6..1cb1247 100644
--- a/UniFi Internet Controller/locale.json
+++ b/UniFi Internet Controller/locale.json
@@ -10,6 +10,8 @@
"Updates will happen on a schedule every xyz seconds.": "Das Module prüft die Anwensenheit alle xyz Sekunden, wie im Module konfiguriert",
"For debugging, please use the Debug function of the module.": "Für das Prüfen der Funktionen, gibt es Modul Meldungen im Debugbereich aus",
"UniFi Toolbox - Dream Maschine Internet Controller Configuration": "UniFi Toolbox - Dream Maschine Internet Controller Konfiguration",
+ "400 Bad Request - The server cannot or will not process the request due to an apparent client error.": "400 Bad Request - Die Anfrage wird vom Controller nicht verarbeitet (falsche IP?) - Client Fehler.",
+ "401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?": "401 Unauthorized / 403 Forbidden - Die Anfrage ging an den richtigen Server, allerdings konnte sich Symcon nicht anmelden. Bitte Login Daten prüfen.",
"Controller Type": "Art des Controllers",
"Server Address": "Server Adresse",
"User Name": "Anmeldename",
diff --git a/UniFi Internet Controller/module.php b/UniFi Internet Controller/module.php
index d2f0d9a..2845a2b 100644
--- a/UniFi Internet Controller/module.php
+++ b/UniFi Internet Controller/module.php
@@ -170,10 +170,14 @@ public function AuthenticateAndGetData (string $UnifiAPI = "") {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
}
else if (400 == $code) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
+ exit();
}
else if (401 == $code || 403 == $code) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
+ exit();
}
}
}
diff --git a/UniFi Presence Manager/locale.json b/UniFi Presence Manager/locale.json
index 21b6f93..a02cfae 100644
--- a/UniFi Presence Manager/locale.json
+++ b/UniFi Presence Manager/locale.json
@@ -16,6 +16,8 @@
"Update Frequency": "Aktualisierungsfrequenz",
"sec - 0 is off": "Sek - 0 ist Aus",
"The General Presence Updated variable will always be updated and can be used to trigger general updates independent of the sender.": "Die Allgemeine Anwesenheit Aktualisiert Variable wird immer unabhängig vom Gerät aktualisiert und kann somit eine generische Aktion auslösen.",
+ "400 Bad Request - The server cannot or will not process the request due to an apparent client error.": "400 Bad Request - Die Anfrage wird vom Controller nicht verarbeitet (falsche IP?) - Client Fehler.",
+ "401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?": "401 Unauthorized / 403 Forbidden - Die Anfrage ging an den richtigen Server, allerdings konnte sich Symcon nicht anmelden. Bitte Login Daten prüfen.",
"General Presence Updated": "Allgemeine Anwesenheit Aktualisiert",
"Devices": "Geräte",
"Devicename": "Gerätename",
diff --git a/UniFi Presence Manager/module.php b/UniFi Presence Manager/module.php
index 806271a..ab15346 100644
--- a/UniFi Presence Manager/module.php
+++ b/UniFi Presence Manager/module.php
@@ -123,9 +123,13 @@ public function AuthenticateAndGetData() {
}
else if ($code == 400) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
+ exit();
}
else if ($code == 401 || $code == 403) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
+ exit();
}
}
}
From f21cd2f7936b99dfa2d52bf5dd82d121d6e5e670 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 11:15:34 +0100
Subject: [PATCH 39/71] public functions for blocking / unblocking devices
#21 Feature Request DeviceBlocker - public functions for blocking / unblocking devices
---
UniFi Device Blocker/module.php | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index af905f9..d8547a0 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -275,4 +275,30 @@ public function RequestAction($Ident, $Value) {
}
+ // public function, which is blocking a device with MAC $DeviceMacAddress
+ public function block($DeviceMacAddress) {
+ $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAddress);
+ $VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
+
+ if(false !== $VarID) {
+ $this->SetValue($VarID, false);
+ }
+ else {
+ $this->SendDebug($this->Translate("Device Blocker"), "block(".$DeviceMacAddress.")", 0);
+ }
+ }
+
+ // public function, which is unblocking/allowing a device with MAC $DeviceMacAddress
+ public function unblock($DeviceMacAddress) {
+ $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAddress);
+ $VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
+
+ if(false !== $VarID) {
+ $this->SetValue($VarID, true);
+ }
+ else {
+ $this->SendDebug($this->Translate("Device Blocker"), "unblock(".$DeviceMacAddress.")", 0);
+ }
+ }
+
}
From 3eb8431e2693ca786a120db01db4e6f981553d07 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 11:25:14 +0100
Subject: [PATCH 40/71] fix for public functions for blocking / unblocking
devices
#21 public functions for blocking / unblocking devices
---
UniFi Device Blocker/module.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index d8547a0..966dbeb 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -281,7 +281,7 @@ public function block($DeviceMacAddress) {
$VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
if(false !== $VarID) {
- $this->SetValue($VarID, false);
+ $this->SetValue($DeviceMacClean, false);
}
else {
$this->SendDebug($this->Translate("Device Blocker"), "block(".$DeviceMacAddress.")", 0);
@@ -294,7 +294,7 @@ public function unblock($DeviceMacAddress) {
$VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
if(false !== $VarID) {
- $this->SetValue($VarID, true);
+ $this->SetValue($DeviceMacClean, true);
}
else {
$this->SendDebug($this->Translate("Device Blocker"), "unblock(".$DeviceMacAddress.")", 0);
From 79ac989ff6fe4407807a3cda382a2c6875bb1058 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 11:28:21 +0100
Subject: [PATCH 41/71] parameter type added to public functions block +
unblock
#21
---
UniFi Device Blocker/module.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index 966dbeb..671edf6 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -276,7 +276,7 @@ public function RequestAction($Ident, $Value) {
}
// public function, which is blocking a device with MAC $DeviceMacAddress
- public function block($DeviceMacAddress) {
+ public function block(string $DeviceMacAddress) {
$DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAddress);
$VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
@@ -289,7 +289,7 @@ public function block($DeviceMacAddress) {
}
// public function, which is unblocking/allowing a device with MAC $DeviceMacAddress
- public function unblock($DeviceMacAddress) {
+ public function unblock(string $DeviceMacAddress) {
$DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAddress);
$VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
From cdb053c75d87754d189455cc2158cf1a56810fd7 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Thu, 30 Dec 2021 12:03:24 +0100
Subject: [PATCH 42/71] CPU Load jetzt float
---
UniFi Device Monitor/module.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Device Monitor/module.php b/UniFi Device Monitor/module.php
index e9f46ee..b82f740 100644
--- a/UniFi Device Monitor/module.php
+++ b/UniFi Device Monitor/module.php
@@ -57,8 +57,8 @@ public function ApplyChanges() {
//Hardware Data
$vpos = 200;
- $this->MaintainVariable("CPULoad", $this->Translate("CPU Load"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointHardware") == 1);
- $this->MaintainVariable("MemoryLoad", $this->Translate("Memory Load"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointHardware") == 1);
+ $this->MaintainVariable("CPULoad", $this->Translate("CPU Load"), vtFloat, "", $vpos++, $this->ReadPropertyBoolean("DataPointHardware") == 1);
+ $this->MaintainVariable("MemoryLoad", $this->Translate("Memory Load"), vtFloat, "", $vpos++, $this->ReadPropertyBoolean("DataPointHardware") == 1);
//Device Specific Data Connection Data UDM/USG
From f329b254f96b8bc7b9e6ae1bc8b7db8c7d4c4f6f Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 12:21:44 +0100
Subject: [PATCH 43/71] public functions added
---
UniFi Device Blocker/README.md | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/UniFi Device Blocker/README.md b/UniFi Device Blocker/README.md
index dd92ae6..c668782 100644
--- a/UniFi Device Blocker/README.md
+++ b/UniFi Device Blocker/README.md
@@ -7,7 +7,8 @@ Dieses Modul ermöglicht es Geräte im Netz zu blockieren, um z.B. den Zugang de
2. [Voraussetzungen](#2-voraussetzungen)
3. [Software-Installation](#3-software-installation)
4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon)
-5. [Versionsinformation](#5-versionsinformation)
+5. [PHP-Befehlsreferenz](#5-php-befehlsreferenz)
+6. [Versionsinformation](#6-versionsinformation)
## 1. Funktionsumfang
@@ -18,7 +19,7 @@ Dieses Modul ermöglicht es Geräte im Netz zu blockieren, um z.B. den Zugang de
* Erstellt pro Gerät eine Variable welche z.B. für die Automation oder Überwachung genutzt werden kann (Boolean)
* Das Modul reagiert auf die Änderung einer Variable
-## 2. Vorraussetzungen
+## 2. Voraussetzungen
- IP-Symcon ab Version 5.5
- Unifi Benutzer mit Owner oder Super-Admin Rechten (Limited-Admin Rechte sind nicht ausreichend!)
@@ -65,7 +66,26 @@ Das Modul selbst löscht keine Variablen, sollte sich ein Name ändern, dann wir
**Debugging**
Das Modul gibt diverse Informatioen im Debug Bereich aus.
-## 5. Versionsinformation
+### 5. PHP-Befehlsreferenz
+
+#### Empfehlung
+Sofern nur eine Instanz des Unifi Device Blockers im Einsatz ist, sollte die $InstanzID wie folgt dynamisch ermittelt werden und nicht statisch gesetzt werden, da somit ein Löschen und Neuinstallieren der Unifi Device Blocker Instanz keine Auswirkung auf andere Skripte hat:
+
+`$InstanzID = IPS_GetInstanceListByModuleID("{FC3E71F1-BF95-D45D-0676-BA3D10D02CB8}")[0];`
+
+
+#### Funktionen
+
+`int DB_block(int $InstanzID, string $DeviceMacAddress)`
+
+Blockiert das Gerät mit der MAC Adresse $DeviceMacAddress, welche in der DeviceBlocker Instanz $InstanzID konfiguriert wurde.
+
+`int DB_unblock(int $InstanzID, string $DeviceMacAddress)`
+
+Erlaubt das Gerät mit der MAC Adresse $DeviceMacAddress, welche in der DeviceBlocker Instanz $InstanzID konfiguriert wurde.
+
+
+## 6. Versionsinformation
Version 0.3 (Beta) - 23-08-2021
* Unterstützung für UniFi Cloudkey 1
From 8bbd31631acdf608cfe91a1651b34d752100e37a Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 12:23:47 +0100
Subject: [PATCH 44/71] public functions return value
---
UniFi Device Blocker/README.md | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/UniFi Device Blocker/README.md b/UniFi Device Blocker/README.md
index c668782..f72da03 100644
--- a/UniFi Device Blocker/README.md
+++ b/UniFi Device Blocker/README.md
@@ -76,13 +76,15 @@ Sofern nur eine Instanz des Unifi Device Blockers im Einsatz ist, sollte die $In
#### Funktionen
-`int DB_block(int $InstanzID, string $DeviceMacAddress)`
+`bool DB_block(int $InstanzID, string $DeviceMacAddress)`
Blockiert das Gerät mit der MAC Adresse $DeviceMacAddress, welche in der DeviceBlocker Instanz $InstanzID konfiguriert wurde.
+Gibt false zurück, wenn Gerät in DeviceBlocker Instanz nicht gefunden wurde, ansonsten true.
-`int DB_unblock(int $InstanzID, string $DeviceMacAddress)`
+`bool DB_unblock(int $InstanzID, string $DeviceMacAddress)`
Erlaubt das Gerät mit der MAC Adresse $DeviceMacAddress, welche in der DeviceBlocker Instanz $InstanzID konfiguriert wurde.
+Gibt false zurück, wenn Gerät in DeviceBlocker Instanz nicht gefunden wurde, ansonsten true.
## 6. Versionsinformation
From 768cccdd5c47df4587f0a1471c78cd03e321fbd0 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 12:25:09 +0100
Subject: [PATCH 45/71] return value for block() and unblock() added
#21
---
UniFi Device Blocker/module.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index 671edf6..26d7ccf 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -282,9 +282,11 @@ public function block(string $DeviceMacAddress) {
if(false !== $VarID) {
$this->SetValue($DeviceMacClean, false);
+ return true;
}
else {
$this->SendDebug($this->Translate("Device Blocker"), "block(".$DeviceMacAddress.")", 0);
+ return false;
}
}
@@ -295,9 +297,11 @@ public function unblock(string $DeviceMacAddress) {
if(false !== $VarID) {
$this->SetValue($DeviceMacClean, true);
+ return true;
}
else {
$this->SendDebug($this->Translate("Device Blocker"), "unblock(".$DeviceMacAddress.")", 0);
+ return false;
}
}
From a1bde831f9a8bff385c48e146d43a8c382a62ff1 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 12:29:08 +0100
Subject: [PATCH 46/71] debug output
#21
---
UniFi Device Blocker/module.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index 26d7ccf..cdade1b 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -285,7 +285,7 @@ public function block(string $DeviceMacAddress) {
return true;
}
else {
- $this->SendDebug($this->Translate("Device Blocker"), "block(".$DeviceMacAddress.")", 0);
+ $this->SendDebug($this->Translate("Device Blocker"), "Error: block(".$DeviceMacAddress.")", 0);
return false;
}
}
@@ -300,7 +300,7 @@ public function unblock(string $DeviceMacAddress) {
return true;
}
else {
- $this->SendDebug($this->Translate("Device Blocker"), "unblock(".$DeviceMacAddress.")", 0);
+ $this->SendDebug($this->Translate("Device Blocker"), "Error: unblock(".$DeviceMacAddress.")", 0);
return false;
}
}
From 38502dbe528868bb19c431c2770112e8c4982254 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:11:30 +0100
Subject: [PATCH 47/71] Ident creation - blank space intercepted
---
UniFi Presence Manager/module.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Presence Manager/module.php b/UniFi Presence Manager/module.php
index ab15346..b09161c 100644
--- a/UniFi Presence Manager/module.php
+++ b/UniFi Presence Manager/module.php
@@ -50,7 +50,7 @@ public function ApplyChanges() {
if (isset($DevicesJSON)) {
foreach ($DevicesJSON as $Device) {
$DeviceName = $Device["varDeviceName"];
- $DeviceMac = str_replace(array("-",":"), "", $Device["varDeviceMAC"]);
+ $DeviceMac = str_replace(array("-",":"," "), "", $Device["varDeviceMAC"]);
$this->MaintainVariable($DeviceMac, $DeviceName, vtBoolean, "~Presence", $vpos++, isset($DevicesJSON));
}
}
@@ -185,7 +185,7 @@ public function CheckPresence() {
foreach ($DevicesJSON as $Device) {
//Build a clean array out of the devices mentioned in the config form with : or -
- $DeviceMac = str_replace(array("-",":"), "", strtolower($Device["varDeviceMAC"]));
+ $DeviceMac = str_replace(array("-",":"," "), "", strtolower($Device["varDeviceMAC"]));
//Itterate through all device and check if one of them matches the list in the config form.
foreach ($ActiveDevices["data"] as $Index=>$Device) {
From 12f02fb4dcc2f24f5fc8713d4ffc1d7c90ae8d5f Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:20:28 +0100
Subject: [PATCH 48/71] Removed old code which was commented out
---
UniFi Device Blocker/module.php | 16 +---------------
1 file changed, 1 insertion(+), 15 deletions(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index 9ba5135..c4ea68c 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -72,21 +72,7 @@ public function ApplyChanges() {
$VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
$this->RegisterMessage($VarID, VM_UPDATE);
}
- }
-
- /*
-
- $this->MaintainVariable($DeviceNameClean, $DeviceName, vtBoolean, "~Switch", $vpos++, isset($DevicesJSON));
- $DeviceNameCleanID = @IPS_GetObjectIDByIdent($DeviceNameClean, $this->InstanceID);
- SetValue($DeviceNameCleanID,true); // make a device will not a disconnected when the module is initialized
-
- $this->EnableAction($DeviceNameClean);
-
- //$DeviceNameCleanID = @IPS_GetObjectIDByIdent($DeviceNameClean, $this->InstanceID);
- if (IPS_GetObject($DeviceNameCleanID)['ObjectType'] == 2) {
- $this->RegisterMessage($DeviceNameCleanID, VM_UPDATE);
- }
- */
+ }
}
}
From 317fa3236a176c04fee5cbbd9d31dd02604caa09 Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:21:49 +0100
Subject: [PATCH 49/71] update 1.2
---
UniFi Device Blocker/README.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/UniFi Device Blocker/README.md b/UniFi Device Blocker/README.md
index f72da03..4902195 100644
--- a/UniFi Device Blocker/README.md
+++ b/UniFi Device Blocker/README.md
@@ -106,3 +106,7 @@ Version 1.1 - 25-12-2021
* Fix - Memory Leak
* Fix - HTTP Response Error Message
* Variablen Management umgestellt - es Ident wird jetzt die MAC verwendet
+
+Version 1.2 - 30-12-2021
+* Neu - Verbessertes Fehlerhandling vor allem bei falschen Logins
+* Neu - Block kann jetzt als Funktion aufgerufen werden
From 4555494fc190237f3b7ff9ac04279c018cf5cd0c Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:23:01 +0100
Subject: [PATCH 50/71] Update 1.2
---
UniFi Presence Manager/README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Presence Manager/README.md b/UniFi Presence Manager/README.md
index f8ea254..95b7b8b 100644
--- a/UniFi Presence Manager/README.md
+++ b/UniFi Presence Manager/README.md
@@ -83,5 +83,5 @@ Version 1.1 - 25-12-2021
* Fix - Memory Leak
* Fix - HTTP Response Error Message
-Version 1.2 - 27-12-2021
-* Neu - Endpoint Monitor zur Überwachung von Endgeräten
\ No newline at end of file
+Version 1.2 - 30-12-2021
+* Neu - Verbessertes Fehlerhandling vor allem bei falschen Logins
From 8039800073ef94ad8b3fef0a0e069d85e61eecfd Mon Sep 17 00:00:00 2001
From: elueckel <30531515+elueckel@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:23:35 +0100
Subject: [PATCH 51/71] update 1.2
---
UniFi Internet Controller/README.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/UniFi Internet Controller/README.md b/UniFi Internet Controller/README.md
index 4f04006..66cf7a6 100644
--- a/UniFi Internet Controller/README.md
+++ b/UniFi Internet Controller/README.md
@@ -91,3 +91,6 @@ Version 1.0 - 09-09-2021
Version 1.1 - 25-12-2021
* Fix - Memory Leak
* Fix - HTTP Response Error Message
+
+Version 1.2 - 30-12-2021
+* Neu - Verbessertes Fehlerhandling vor allem bei falschen Logins
From 403f4c208dc8459d1b7320880217fbaf4b5b4127 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:24:48 +0100
Subject: [PATCH 52/71] typos
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 1401655..fbc399c 100644
--- a/README.md
+++ b/README.md
@@ -24,11 +24,11 @@ Folgende Module beinhaltet das UniFi Toolbox Repository:
Mit dem Device Blocker können Geräte anhand ihrer MAC Adresse vom Zugang auf das Netzwerk geblockt werden, z.B. um die Nutzung von Geräten im Kinderzimmer nach 20 Uhr zu sperren und am Morgen wieder zu aktivieren.
- __UniFi Device Monitor__ ([Dokumentation](UniFi%20Device%20Monitor))
- Mit dem Device Monitor können Geräte von UniFi überwacht werden - es stehen bei Firewalls (UDM/USG) Daten zur Internetverbindung zu Verfügung, bei generischen Geräten Daten zum Status und Hardware.
+ Mit dem Device Monitor können Geräte von UniFi überwacht werden - es stehen bei Firewalls (UDM/USG) Daten zur Internetverbindung zur Verfügung, bei generischen Geräten Daten zum Status und Hardware.
- __UniFi Endpoint Monitor__ ([Dokumentation](UniFi%20Endpoint%20Monitor))
Mit dem Endpoint Monitor können mit den UniFi Netzwerkverbunde Geräte überwacht werden. Hierbei wird zwischen Kabel und WLAN Verbindungen unterschieden, da im WLAN weit mehr Daten zur Verfügung stehen.
Für detaillierte Informationen zu den Modulen, wie z.B. zur Version bitte die Hilfeseiten der Module besuchen.
-Dieses Modul ist für die nicht kommerzielle Nutzung kostenlos - bei kommerzieller Nutzung bitte den Author kontakieren.
\ No newline at end of file
+Dieses Modul ist für die nicht kommerzielle Nutzung kostenlos - bei kommerzieller Nutzung bitte den Author kontaktieren.
From 4fb41bfad6cca97467e2613466475ca9a0c33797 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:33:05 +0100
Subject: [PATCH 53/71] typos
---
UniFi Device Monitor/README.md | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/UniFi Device Monitor/README.md b/UniFi Device Monitor/README.md
index 87b112a..ca29d69 100644
--- a/UniFi Device Monitor/README.md
+++ b/UniFi Device Monitor/README.md
@@ -1,5 +1,5 @@
# UniFi Device Monitor
-Dieses Modul ermöglicht es Unifi Geräte im Netz zu überwachen und u.a. Verbindungs und Hardwaredaten abzufragen.
+Dieses Modul ermöglicht es Unifi Geräte im Netz zu überwachen und u.a. Verbindungs- und Hardwaredaten abzufragen.
### Inhaltsverzeichnis
@@ -17,7 +17,7 @@ Dieses Modul ermöglicht es Unifi Geräte im Netz zu überwachen und u.a. Verbin
* Erstellt pro Gerät eine Variable welche z.B. für die Automation oder Überwachung genutzt werden kann (Boolean)
* Abfragen der Controller erfolgt zeitgesteuert alle xx Sekunden
-### 2. Vorraussetzungen
+### 2. Voraussetzungen
- IP-Symcon ab Version 5.5
@@ -35,7 +35,7 @@ __Konfigurationsseite__:
**Art des Controllers**
-Da sich die APIs von CloudKey 1 und CloudKey2/Dreammaschine unterscheiden, kann hier der Controller gewählt werden
+Da sich die APIs von CloudKey 1 und CloudKey2/Dreammachine unterscheiden, kann hier der Controller gewählt werden
**Benutzername & Kennwort**
@@ -47,7 +47,7 @@ Site die im Controller hinterlegt ist
**IP Adresse und Port**
-Bei der Dream Maschine ist der Port 443, bei einem Controller im Standard 8443. IP Addresse des CloudKeys oder der Dream Maschine.
+Bei der Dream Maschine ist der Port 443, bei einem Controller im Standard 8443. IP-Adresse des CloudKeys oder der Dream Maschine.
**Aktualisierungsfrequenz**
@@ -67,7 +67,7 @@ Netzwerkdaten umfassen logische Daten wie Gerätemodel, Softwareversion, Zufried
**Hardwaredaten - Verfügbar für alle Geräte**
-Diese einstellung liest die CPU und Speicherlast aus.
+Diese Einstellung liest die CPU und Speicherlast aus.
**Verbindungsdaten - nur bei Firewalls wie UDM/USG verfügbar**
@@ -75,12 +75,12 @@ Netzwerkdaten wie Public IP, übertragene Daten, Pakete und Fehler
**Übertragungsdaten**
-Bei WLAN Geräten werden hier Informationen zu übertragenen Daten und Paketen geliefert.
+Bei WLAN-Geräten werden hier Informationen zu übertragenen Daten und Paketen geliefert.
**Debugging**
-Das Modul gibt diverse Informatioen im Debug Bereich aus.
+Das Modul gibt diverse Informationen im Debug Bereich aus.
## 5. Versionsinformation
Version 1.2 - 28-12-2021
-* Neu - Modul verfügbar
\ No newline at end of file
+* Neu - Modul verfügbar
From 413cb05eecf0c19a5a48001a9336452036227309 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:34:32 +0100
Subject: [PATCH 54/71] typos
---
UniFi Device Monitor/locale.json | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/UniFi Device Monitor/locale.json b/UniFi Device Monitor/locale.json
index 1bad1aa..6cdb1da 100644
--- a/UniFi Device Monitor/locale.json
+++ b/UniFi Device Monitor/locale.json
@@ -3,8 +3,8 @@
"de": {
"Module Help": "Modul Hilfe",
"This Module allows to monitor devices connected to a UniFi Network and provide data in variables.": "Dieses Modul ermöglicht es Geräte im Netz zu überwachen und Daten in Variablen anzuzeigen.",
- "Please select the type of controller you are using, enter its IP Adress, Port and a user allowed to log in.": "Bitte wählen sie die Art des Controllers und geben die IP Adresse, Port und einen Anwender ein der auf diesen zugreifen darf.",
- "To manage certain devices, please use their MAC adress - easiest method might be to take it from the controller interface.": "Um Geräte zu verwalten, geben sie bitte die MAC Addresse ein - diese können am einfachsten aus dem Controller ausgelesen werden.",
+ "Please select the type of controller you are using, enter its IP Address, Port and a user allowed to log in.": "Bitte wählen sie die Art des Controllers und geben die IP Adresse, Port und einen Anwender ein der auf diesen zugreifen darf.",
+ "To manage certain devices, please use their MAC address - easiest method might be to take it from the controller interface.": "Um Geräte zu verwalten, geben sie bitte die MAC Addresse ein - diese können am einfachsten aus dem Controller ausgelesen werden.",
"Please turn on the data points you would like to monitor and variables will be created accordingly.": "Die gewünschten Datenpunkte können in der Konfiguration ausgewählt werden.",
"Updates will happen on a schedule every xyz seconds.": "Das Module prüft die Anwensenheit alle xyz Sekunden, wie im Module konfiguriert",
"For debugging, please use the Debug function of the module.": "Für das Prüfen der Funktionen, gibt es Modul Meldungen im Debugbereich aus",
@@ -51,4 +51,4 @@
"Signal Strength": "Signal Stärke"
}
}
-}
\ No newline at end of file
+}
From 595b6d05d60aed3aacc70660322cb8adbd3c4cdc Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:35:01 +0100
Subject: [PATCH 55/71] typo
---
UniFi Device Monitor/form.json | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Device Monitor/form.json b/UniFi Device Monitor/form.json
index c8891ac..e73658b 100644
--- a/UniFi Device Monitor/form.json
+++ b/UniFi Device Monitor/form.json
@@ -14,7 +14,7 @@
},
{
"type": "Label",
- "label": "To manage certain devices, please use their MAC adress - easiest method might be to take it from the controller interface."
+ "label": "To manage certain devices, please use their MAC address - easiest method might be to take it from the controller interface."
},
{
"type": "Label",
@@ -147,4 +147,4 @@
}
],
"status": []
-}
\ No newline at end of file
+}
From 250447016689f1a8ed3c97ae5c7b8abdf13f56de Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:35:58 +0100
Subject: [PATCH 56/71] typo
---
UniFi Device Monitor/form.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/UniFi Device Monitor/form.json b/UniFi Device Monitor/form.json
index e73658b..a574837 100644
--- a/UniFi Device Monitor/form.json
+++ b/UniFi Device Monitor/form.json
@@ -56,7 +56,7 @@
},
{
"type": "ValidationTextBox",
- "name": "ServerAdress",
+ "name": "ServerAddress",
"caption": "Server Address",
"validate": "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
},
From bd13a8254959d56f9df07ddf89581607eb613e49 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:36:06 +0100
Subject: [PATCH 57/71] typo
From df42850a0f429d24d0187ffcfa7eefceed9ecf08 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:37:01 +0100
Subject: [PATCH 58/71] typos
---
UniFi Device Monitor/module.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/UniFi Device Monitor/module.php b/UniFi Device Monitor/module.php
index b82f740..4b2cc48 100644
--- a/UniFi Device Monitor/module.php
+++ b/UniFi Device Monitor/module.php
@@ -17,7 +17,7 @@ public function Create() {
parent::Create();
$this->RegisterPropertyInteger("ControllerType", 0);
- $this->RegisterPropertyString("ServerAdress","192.168.1.1");
+ $this->RegisterPropertyString("ServerAddress","192.168.1.1");
$this->RegisterPropertyInteger("ServerPort", "443");
$this->RegisterPropertyString("Site","default");
$this->RegisterPropertyString("UserName","");
@@ -89,7 +89,7 @@ public function ApplyChanges() {
public function AuthenticateAndGetData() {
$ControllerType = $this->ReadPropertyInteger("ControllerType");
- $ServerAdress = $this->ReadPropertyString("ServerAdress");
+ $ServerAddress = $this->ReadPropertyString("ServerAddress");
$ServerPort = $this->ReadPropertyInteger("ServerPort");
$Username = $this->ReadPropertyString("UserName");
$Password = $this->ReadPropertyString("Password");
@@ -115,7 +115,7 @@ public function AuthenticateAndGetData() {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['username' => $Username, 'password' => $Password]));
}
curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$SuffixURL);
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$SuffixURL);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
@@ -160,7 +160,7 @@ public function AuthenticateAndGetData() {
elseif ($ControllerType == 1) {
$MiddlePartURL = "/";
}
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$MiddlePartURL.$UnifiAPI."/".$DeviceMac);
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$MiddlePartURL.$UnifiAPI."/".$DeviceMac);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
From 07165e5d4d6659b2a843f76dfa515b43926adccc Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:40:30 +0100
Subject: [PATCH 59/71] typos
---
UniFi Endpoint Monitor/README.md | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/UniFi Endpoint Monitor/README.md b/UniFi Endpoint Monitor/README.md
index f20efb3..9f957bf 100644
--- a/UniFi Endpoint Monitor/README.md
+++ b/UniFi Endpoint Monitor/README.md
@@ -17,7 +17,7 @@ Dieses Modul ermöglicht es Endgeräte im Netz zu überwachen und diverse Daten
* Erstellt pro Gerät eine Variable welche z.B. für die Automation oder Überwachung genutzt werden kann (Boolean)
* Abfragen der Controller erfolgt zeitgesteuert alle xx Sekunden
-### 2. Vorraussetzungen
+### 2. Voraussetzungen
- IP-Symcon ab Version 5.5
@@ -35,7 +35,7 @@ __Konfigurationsseite__:
**Art des Controllers**
-Da sich die APIs von CloudKey 1 und CloudKey2/Dreammaschine unterscheiden, kann hier der Controller gewählt werden
+Da sich die APIs von CloudKey 1 und CloudKey2/Dreammachine unterscheiden, kann hier der Controller gewählt werden
**Benutzername & Kennwort**
@@ -47,7 +47,7 @@ Site die im Controller hinterlegt ist
**IP Adresse und Port**
-Bei der Dream Maschine ist der Port 443, bei einem Controller im Standard 8443. IP Addresse des CloudKeys oder der Dream Maschine.
+Bei der Dream Maschine ist der Port 443, bei einem Controller im Standard 8443. IP-Adresse des CloudKeys oder der Dream Maschine.
**Aktualisierungsfrequenz**
@@ -63,20 +63,20 @@ Basierend auf der Art der Verbindung stehen unterschiedliche Informationen zur V
**Netzwerkdaten**
-Netzwerkdaten umfassen logische Daten wie IP Adresse oder Hostname.
+Netzwerkdaten umfassen logische Daten wie IP-Adresse oder Hostname.
**Verbindungsdaten**
-Hier werden verfügbare physische Daten bereitgestellt. Hierzu zählen bei WLAN Geräten Informationen zu Verbingunsqualität, Zuletzt gesehen, Uptime, Kanal, Art der Technologie, SSID, Dämpfung, Signalstärke.
+Hier werden verfügbare physische Daten bereitgestellt. Hierzu zählen bei WLAN-Geräten Informationen zu Verbindungsqualität, Zuletzt gesehen, Uptime, Kanal, Art der Technologie, SSID, Dämpfung, Signalstärke.
**Übertragungsdaten**
-Bei WLAN Geräten werden hier Informationen zu übertragenen Daten und Paketen geliefert.
+Bei WLAN-Geräten werden hier Informationen zu übertragenen Daten und Paketen geliefert.
**Debugging**
-Das Modul gibt diverse Informatioen im Debug Bereich aus.
+Das Modul gibt diverse Informationen im Debug Bereich aus.
## 5. Versionsinformation
Version 1.2 - 27-12-2021
-* Neu - Modul verfügbar
\ No newline at end of file
+* Neu - Modul verfügbar
From 17a1b49e1554eaf0f4e0fa8a693225ef917cc224 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:41:39 +0100
Subject: [PATCH 60/71] typos
---
UniFi Endpoint Monitor/form.json | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/UniFi Endpoint Monitor/form.json b/UniFi Endpoint Monitor/form.json
index 0da60a1..2414090 100644
--- a/UniFi Endpoint Monitor/form.json
+++ b/UniFi Endpoint Monitor/form.json
@@ -10,11 +10,11 @@
},
{
"type": "Label",
- "label": "Please select the type of controller you are using, enter its IP Adress, Port and a user allowed to log in."
+ "label": "Please select the type of controller you are using, enter its IP Address, Port and a user allowed to log in."
},
{
"type": "Label",
- "label": "To manage certain devices, please use their MAC adress - easiest method might be to take it from the controller interface."
+ "label": "To manage certain devices, please use their MAC address - easiest method might be to take it from the controller interface."
},
{
"type": "Label",
@@ -56,7 +56,7 @@
},
{
"type": "ValidationTextBox",
- "name": "ServerAdress",
+ "name": "ServerAddress",
"caption": "Server Address",
"validate": "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
},
@@ -151,4 +151,4 @@
}
],
"status": []
-}
\ No newline at end of file
+}
From 673892bad1dbd0862038d2b10596374ada730aec Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:42:20 +0100
Subject: [PATCH 61/71] typos
---
UniFi Endpoint Monitor/locale.json | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/UniFi Endpoint Monitor/locale.json b/UniFi Endpoint Monitor/locale.json
index 11db47c..34b3aa0 100644
--- a/UniFi Endpoint Monitor/locale.json
+++ b/UniFi Endpoint Monitor/locale.json
@@ -3,8 +3,8 @@
"de": {
"Module Help": "Modul Hilfe",
"This Module allows to monitor devices connected to a UniFi Network and provide data in variables.": "Dieses Modul ermöglicht es Geräte im Netz zu überwachen und Daten in Variablen anzuzeigen.",
- "Please select the type of controller you are using, enter its IP Adress, Port and a user allowed to log in.": "Bitte wählen sie die Art des Controllers und geben die IP Adresse, Port und einen Anwender ein der auf diesen zugreifen darf.",
- "To manage certain devices, please use their MAC adress - easiest method might be to take it from the controller interface.": "Um Geräte zu verwalten, geben sie bitte die MAC Addresse ein - diese können am einfachsten aus dem Controller ausgelesen werden.",
+ "Please select the type of controller you are using, enter its IP Address, Port and a user allowed to log in.": "Bitte wählen sie die Art des Controllers und geben die IP Adresse, Port und einen Anwender ein der auf diesen zugreifen darf.",
+ "To manage certain devices, please use their MAC address - easiest method might be to take it from the controller interface.": "Um Geräte zu verwalten, geben sie bitte die MAC Addresse ein - diese können am einfachsten aus dem Controller ausgelesen werden.",
"Please turn on the data points you would like to monitor and variables will be created accordingly.": "Die gewünschten Datenpunkte können in der Konfiguration ausgewählt werden.",
"Updates will happen on a schedule every xyz seconds.": "Das Module prüft die Anwensenheit alle xyz Sekunden, wie im Module konfiguriert",
"For debugging, please use the Debug function of the module.": "Für das Prüfen der Funktionen, gibt es Modul Meldungen im Debugbereich aus",
@@ -42,4 +42,4 @@
"RX Packets": "RX Pakete"
}
}
-}
\ No newline at end of file
+}
From 9ee8db81f897f1a1dc907b6e9cd3bd9415afb052 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:43:20 +0100
Subject: [PATCH 62/71] typos
---
UniFi Endpoint Monitor/module.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/UniFi Endpoint Monitor/module.php b/UniFi Endpoint Monitor/module.php
index 5e72a67..87089f1 100644
--- a/UniFi Endpoint Monitor/module.php
+++ b/UniFi Endpoint Monitor/module.php
@@ -17,7 +17,7 @@ public function Create() {
parent::Create();
$this->RegisterPropertyInteger("ControllerType", 0);
- $this->RegisterPropertyString("ServerAdress","192.168.1.1");
+ $this->RegisterPropertyString("ServerAddress","192.168.1.1");
$this->RegisterPropertyInteger("ServerPort", "443");
$this->RegisterPropertyString("Site","default");
$this->RegisterPropertyString("UserName","");
@@ -95,7 +95,7 @@ public function ApplyChanges() {
public function AuthenticateAndGetData() {
$ControllerType = $this->ReadPropertyInteger("ControllerType");
- $ServerAdress = $this->ReadPropertyString("ServerAdress");
+ $ServerAddress = $this->ReadPropertyString("ServerAddress");
$ServerPort = $this->ReadPropertyInteger("ServerPort");
$Username = $this->ReadPropertyString("UserName");
$Password = $this->ReadPropertyString("Password");
@@ -122,7 +122,7 @@ public function AuthenticateAndGetData() {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['username' => $Username, 'password' => $Password]));
}
curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$SuffixURL);
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$SuffixURL);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
@@ -167,7 +167,7 @@ public function AuthenticateAndGetData() {
elseif ($ControllerType == 1) {
$MiddlePartURL = "/";
}
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$MiddlePartURL.$UnifiAPI."/".$DeviceMac);
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$MiddlePartURL.$UnifiAPI."/".$DeviceMac);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
From f75f09e31635b5468e7e5e5a088ac9c575aa4fb7 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:48:15 +0100
Subject: [PATCH 63/71] exit removed, return added
---
UniFi Device Blocker/module.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index c4ea68c..d576f68 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -135,12 +135,12 @@ public function AuthenticateAndProcessRequest() {
else if ($code == 400) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
- exit();
+ return false;
}
else if ($code == 401 || $code == 403) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
- exit();
+ return false;
}
}
}
@@ -171,7 +171,7 @@ public function AuthenticateAndProcessRequest() {
if (!isset($DeviceMacAddress) || "" == $DeviceMacAddress) {
$this->SendDebug($this->Translate("Device Blocker"),$this->Translate("The switched variable did not have an entry in the module configuration - execution stopped"),0);
- exit;
+ return false;
}
@@ -255,7 +255,7 @@ public function AuthenticateAndProcessRequest() {
}
-
+ return true;
}
From 903cdf994d037848c689145fcd68f1e60a34a754 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:48:52 +0100
Subject: [PATCH 64/71] exit removed, return added
---
UniFi Device Monitor/module.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/UniFi Device Monitor/module.php b/UniFi Device Monitor/module.php
index 4b2cc48..cb82c8c 100644
--- a/UniFi Device Monitor/module.php
+++ b/UniFi Device Monitor/module.php
@@ -139,12 +139,12 @@ public function AuthenticateAndGetData() {
else if ($code == 400) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
- exit();
+ return false;
}
else if ($code == 401 || $code == 403) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
- exit();
+ return false;
}
}
}
@@ -181,6 +181,7 @@ public function AuthenticateAndGetData() {
}
}
+ return true;
}
public function DeviceMonitor() {
From 17ee6b1bc009adb61ff947a983ecf0b8f5cd8069 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:49:25 +0100
Subject: [PATCH 65/71] exit removed, return added
---
UniFi Endpoint Monitor/module.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/UniFi Endpoint Monitor/module.php b/UniFi Endpoint Monitor/module.php
index 87089f1..3f30fc2 100644
--- a/UniFi Endpoint Monitor/module.php
+++ b/UniFi Endpoint Monitor/module.php
@@ -146,12 +146,12 @@ public function AuthenticateAndGetData() {
else if ($code == 400) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
- exit();
+ return false;
}
else if ($code == 401 || $code == 403) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
- exit();
+ return false;
}
}
}
@@ -190,6 +190,7 @@ public function AuthenticateAndGetData() {
}
}
+ return true;
}
public function EndpointMonitor() {
From f983885de431d0a40c8e1a4180d06c6c8ed67009 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:49:59 +0100
Subject: [PATCH 66/71] exit removed, return added
---
UniFi Internet Controller/module.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/UniFi Internet Controller/module.php b/UniFi Internet Controller/module.php
index 1826b7d..90be610 100644
--- a/UniFi Internet Controller/module.php
+++ b/UniFi Internet Controller/module.php
@@ -172,12 +172,12 @@ public function AuthenticateAndGetData (string $UnifiAPI = "") {
else if (400 == $code) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
- exit();
+ return false;
}
else if (401 == $code || 403 == $code) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
- exit();
+ return false;
}
}
}
From 8e4f8dd03baf91726ea804617610b2a539b9f6d4 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Thu, 30 Dec 2021 19:50:29 +0100
Subject: [PATCH 67/71] exit removed, return added
---
UniFi Presence Manager/module.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/UniFi Presence Manager/module.php b/UniFi Presence Manager/module.php
index b09161c..fd78552 100644
--- a/UniFi Presence Manager/module.php
+++ b/UniFi Presence Manager/module.php
@@ -124,12 +124,12 @@ public function AuthenticateAndGetData() {
else if ($code == 400) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
- exit();
+ return false;
}
else if ($code == 401 || $code == 403) {
$this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
- exit();
+ return false;
}
}
}
@@ -168,6 +168,7 @@ public function AuthenticateAndGetData() {
}
}
+ return true;
}
public function CheckPresence() {
From 5ca5a77e2fb59c97c92909681a5e275d0c8f37ba Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Fri, 31 Dec 2021 09:22:48 +0100
Subject: [PATCH 68/71] #23 code cleanup
#23 code cleanup
---
UniFi Device Blocker/README.md | 18 +-
UniFi Device Blocker/form.json | 15 +-
UniFi Device Blocker/module.php | 469 ++++++++++++------------
UniFi Device Monitor/README.md | 21 +-
UniFi Device Monitor/form.json | 11 +-
UniFi Device Monitor/locale.json | 4 +-
UniFi Device Monitor/module.php | 459 ++++++++++++------------
UniFi Endpoint Monitor/README.md | 21 +-
UniFi Endpoint Monitor/form.json | 11 +-
UniFi Endpoint Monitor/locale.json | 4 +-
UniFi Endpoint Monitor/module.php | 492 ++++++++++++++------------
UniFi Internet Controller/README.md | 10 +-
UniFi Internet Controller/form.json | 14 +-
UniFi Internet Controller/locale.json | 9 +-
UniFi Internet Controller/module.php | 228 ++++++------
UniFi Presence Manager/README.md | 28 +-
UniFi Presence Manager/form.json | 27 +-
UniFi Presence Manager/locale.json | 8 +-
UniFi Presence Manager/module.php | 381 ++++++++++----------
19 files changed, 1166 insertions(+), 1064 deletions(-)
diff --git a/UniFi Device Blocker/README.md b/UniFi Device Blocker/README.md
index 4902195..55b446d 100644
--- a/UniFi Device Blocker/README.md
+++ b/UniFi Device Blocker/README.md
@@ -13,8 +13,8 @@ Dieses Modul ermöglicht es Geräte im Netz zu blockieren, um z.B. den Zugang de
## 1. Funktionsumfang
-* Unterstützung für UniFi Cloudkey 1
-* Unterstützung für UniFi Cloudkey 2 und Dream Maschine
+* Unterstützung für UniFi CloudKey 1 (UC-CK)
+* Unterstützung für UniFi CloudKey 2 (UCK-G2) und DreamMachine (UDM)
* Anlegen von zu überwachenden Geräten mit Name und MAC Adresse
* Erstellt pro Gerät eine Variable welche z.B. für die Automation oder Überwachung genutzt werden kann (Boolean)
* Das Modul reagiert auf die Änderung einer Variable
@@ -24,7 +24,6 @@ Dieses Modul ermöglicht es Geräte im Netz zu blockieren, um z.B. den Zugang de
- IP-Symcon ab Version 5.5
- Unifi Benutzer mit Owner oder Super-Admin Rechten (Limited-Admin Rechte sind nicht ausreichend!)
-
## 3. Software-Installation
* Über den Module Store das 'UniFi Device Blocker'-Modul installieren.
@@ -39,7 +38,7 @@ __Konfigurationsseite__:
**Art des Controllers**
-Da sich die APIs von CloudKey 1 und CloudKey2/Dreammaschine unterscheiden, kann hier der Controller gewählt werden
+Da sich die APIs von CloudKey 1 und CloudKey2/DreamMachine unterscheiden, kann hier der Controller gewählt werden
**Benutzername & Kennwort**
@@ -49,9 +48,9 @@ Account mit dem sich das Modul mit dem Controller verbindet
Site die im Controller hinterlegt ist
-**IP Adresse und Port**
+**IP-Adresse und Port**
-Bei der Dream Maschine ist der Port 443, bei einem Controller im Standard 8443. IP Addresse des CloudKeys oder der Dream Maschine.
+Bei der DreamMachine ist der Port 443, bei einem Controller im Standard 8443. IP-Adresse des CloudKeys oder der DreamMachine.
**Aktualisierungsfrequenz**
@@ -64,7 +63,8 @@ Das Modul erstellt dann eine Boolean-Variable mit Switch-Profil, welche in weite
Das Modul selbst löscht keine Variablen, sollte sich ein Name ändern, dann wird eine neue erstellt und die alte im Objektbaum belassen.
**Debugging**
-Das Modul gibt diverse Informatioen im Debug Bereich aus.
+
+Das Modul gibt diverse Informationen im Debug Bereich aus.
### 5. PHP-Befehlsreferenz
@@ -90,8 +90,8 @@ Gibt false zurück, wenn Gerät in DeviceBlocker Instanz nicht gefunden wurde, a
## 6. Versionsinformation
Version 0.3 (Beta) - 23-08-2021
-* Unterstützung für UniFi Cloudkey 1
-* Unterstützung für UniFi Cloudkey 2 und Dream Maschine
+* Unterstützung für UniFi CloudKey 1
+* Unterstützung für UniFi CloudKey 2 und DreamMachine
* Anlegen von zu überwachenden Geräten mit Name und MAC Adresse
* Erstellt pro Gerät eine Variable welche z.B. für die Automation oder Überwachung genutzt werden kann (Boolean)
* Abfragen der Controller erfolgt zeitgesteuert alle xx Sekunden
diff --git a/UniFi Device Blocker/form.json b/UniFi Device Blocker/form.json
index ceff838..20a3991 100644
--- a/UniFi Device Blocker/form.json
+++ b/UniFi Device Blocker/form.json
@@ -40,7 +40,7 @@
"caption": "Controller Type",
"options": [
{
- "caption": "Dream Maschine / Pro / CloudKey V2",
+ "caption": "DreamMachine / Pro / CloudKey V2",
"value": 0
},
{
@@ -56,13 +56,17 @@
},
{
"type": "ValidationTextBox",
- "name": "ServerAdress",
- "caption": "Server Address"
+ "name": "ServerAddress",
+ "caption": "Server Address",
+ "validate": "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
},
{
"type": "NumberSpinner",
"name": "ServerPort",
- "caption": "Server Port"
+ "caption": "Server Port",
+ "digits": 0,
+ "minimum": 1,
+ "maximum": 65535
},
{
"type": "ValidationTextBox",
@@ -124,6 +128,5 @@
}
]
}
- ],
- "status": []
+ ]
}
diff --git a/UniFi Device Blocker/module.php b/UniFi Device Blocker/module.php
index d576f68..c49963f 100644
--- a/UniFi Device Blocker/module.php
+++ b/UniFi Device Blocker/module.php
@@ -10,289 +10,306 @@
define('vtArray', 8);
define('vtObject', 9);
}
- class UniFiDeviceBlocker extends IPSModule
- {
- public function Create() {
- //Never delete this line!
- parent::Create();
-
- $this->RegisterPropertyInteger("ControllerType", 0);
- $this->RegisterPropertyString("ServerAddress","192.168.1.1");
- $this->RegisterPropertyInteger("ServerPort", "443");
- $this->RegisterPropertyString("Site","default");
- $this->RegisterPropertyString("UserName","");
- $this->RegisterPropertyString("Password","");
- //$this->RegisterPropertyInteger("Timer", "0");
-
- $this->RegisterPropertyString("Devices", "");
- }
+class UniFiDeviceBlocker extends IPSModule {
- public function Destroy() {
- //Never delete this line!
- parent::Destroy();
- }
+ public function Create() {
+ //Never delete this line!
+ parent::Create();
- public function ApplyChanges() {
- //Never delete this line!
- parent::ApplyChanges();
+ $this->RegisterPropertyInteger("ControllerType", 0);
+ $this->RegisterPropertyString("ServerAddress","192.168.1.1");
+ $this->RegisterPropertyInteger("ServerPort", "443");
+ $this->RegisterPropertyString("Site","default");
+ $this->RegisterPropertyString("UserName","");
+ $this->RegisterPropertyString("Password","");
+ //$this->RegisterPropertyInteger("Timer", "0");
- $vpos = 100;
+ $this->RegisterPropertyString("Devices", "");
- //Create Devices mentioned in configuration
- $DevicesList = $this->ReadPropertyString("Devices");
- $DevicesJSON = json_decode($DevicesList,true);
- //var_dump($DevicesJSON);
+ }
- if (isset($DevicesJSON)) {
- foreach ($DevicesJSON as $Device) {
- $DeviceName = $Device["varDeviceName"];
- $DeviceNameClean = str_replace(array("-",":"," "), "", $DeviceName);
- $DeviceMacAddress = $Device["varDeviceMAC"];
- $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAddress);
+ public function Destroy() {
+ //Never delete this line!
+ parent::Destroy();
+ }
+
+ public function ApplyChanges() {
+ //Never delete this line!
+ parent::ApplyChanges();
+
+ $vpos = 100;
- if (@IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID) == false) {
+ //Create Devices mentioned in configuration
+ $DevicesList = $this->ReadPropertyString("Devices");
+ $DevicesJSON = json_decode($DevicesList,true);
+ //var_dump($DevicesJSON);
- $DeviceMacCleanID = IPS_CreateVariable(0);
- IPS_SetName($DeviceMacCleanID, $DeviceName);
- IPS_SetIdent($DeviceMacCleanID, $DeviceMacClean);
- IPS_SetVariableCustomProfile($DeviceMacCleanID, "~Switch");
- IPS_SetParent($DeviceMacCleanID, $this->InstanceID);
+ if (isset($DevicesJSON)) {
+ foreach ($DevicesJSON as $Device) {
+ $DeviceName = $Device["varDeviceName"];
+ $DeviceNameClean = str_replace(array("-",":"," "), "", $DeviceName);
+ $DeviceMacAddress = $Device["varDeviceMAC"];
+ $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAddress);
+
+ if (@IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID) == false) {
+
+ $DeviceMacCleanID = IPS_CreateVariable(0);
+ IPS_SetName($DeviceMacCleanID, $DeviceName);
+ IPS_SetIdent($DeviceMacCleanID, $DeviceMacClean);
+ IPS_SetVariableCustomProfile($DeviceMacCleanID, "~Switch");
+ IPS_SetParent($DeviceMacCleanID, $this->InstanceID);
- SetValue($DeviceMacCleanID,true);
- IPS_Sleep(1000);
- $this->EnableAction($DeviceMacClean);
- $this->RegisterMessage($DeviceMacCleanID, VM_UPDATE);
+ SetValue($DeviceMacCleanID,true);
+ IPS_Sleep(1000);
+ $this->EnableAction($DeviceMacClean);
+ $this->RegisterMessage($DeviceMacCleanID, VM_UPDATE);
- }
+ }
- foreach ($DevicesJSON as $Device) {
- $DeviceMacAddress = $Device["varDeviceMAC"];
- $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAddress);
- $VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
- $this->RegisterMessage($VarID, VM_UPDATE);
- }
- }
- }
+ foreach ($DevicesJSON as $Device) {
+ $DeviceMacAddress = $Device["varDeviceMAC"];
+ $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAddress);
+ $VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
+ $this->RegisterMessage($VarID, VM_UPDATE);
+ }
+ }
+ }
- }
+ }
- public function MessageSink($TimeStamp, $SenderID, $Message, $Data) {
+ public function MessageSink($TimeStamp, $SenderID, $Message, $Data) {
- $this->SendDebug($this->Translate("Sender"),$SenderID, 0);
- $this->SetBuffer("SenderID",$SenderID);
- $this->AuthenticateAndProcessRequest();
+ $this->SendDebug($this->Translate("Sender"),$SenderID, 0);
+ $this->SetBuffer("SenderID",$SenderID);
- }
+ $Site = $this->ReadPropertyString("Site");
+ $this->AuthenticateAndProcessRequest("api/s/".$Site."/cmd/sta");
+
+ }
- public function AuthenticateAndProcessRequest() {
+ public function AuthenticateAndProcessRequest(string $UnifiAPI = "") {
- $ControllerType = $this->ReadPropertyInteger("ControllerType");
- $ServerAddress = $this->ReadPropertyString("ServerAddress");
- $ServerPort = $this->ReadPropertyInteger("ServerPort");
- $Username = $this->ReadPropertyString("UserName");
- $Password = $this->ReadPropertyString("Password");
+ $ControllerType = $this->ReadPropertyInteger("ControllerType");
+ $ServerAddress = $this->ReadPropertyString("ServerAddress");
+ $ServerPort = $this->ReadPropertyInteger("ServerPort");
+ $Username = $this->ReadPropertyString("UserName");
+ $Password = $this->ReadPropertyString("Password");
+
+ //Change the Unifi API to be called here
+ if ("" == $UnifiAPI) {
$Site = $this->ReadPropertyString("Site");
-
- ////////////////////////////////////////
- //Change the Unifi API to be called here
$UnifiAPI = "api/s/".$Site."/cmd/sta";
- ////////////////////////////////////////
+ }
- $ch = curl_init();
+ //Generic Section providing for Authenthication against a DreamMachine or Classic CloudKey
+ $ch = curl_init();
- if ($ControllerType == 0) {
- $SuffixURL = "/api/auth/login";
- curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$Username."&password=".$Password);
- }
- elseif ($ControllerType == 1) {
- $SuffixURL = "/api/login";
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['username' => $Username, 'password' => $Password]));
- }
- curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$SuffixURL);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $data = curl_exec($ch);
-
- $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
- $body = trim(substr($data, $header_size));
- $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$code,0);
- preg_match_all('|(?i)Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
- if (isset($results[1])) {
- $Cookie = implode(';', $results[1]);
- if (!empty($body)) {
- if ($code == 200) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
- }
- else if ($code == 400) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
- echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
- return false;
- }
- else if ($code == 401 || $code == 403) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
- echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
- return false;
- }
+ if(!isset($ControllerType) || $ControllerType == 0) {
+ $SuffixURL = "/api/auth/login";
+ curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$Username."&password=".$Password);
+ }
+ elseif ($ControllerType == 1) {
+ $SuffixURL = "/api/login";
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['username' => $Username, 'password' => $Password]));
+ }
+ curl_setopt($ch, CURLOPT_POST, TRUE);
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$SuffixURL);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
+ curl_setopt($ch, CURLOPT_HEADER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ $data = curl_exec($ch);
+
+ if(false === $data)
+ {
+ $this->SendDebug($this->Translate("Authentication"), $this->Translate('Error: Not reachable / No response!'),0);
+
+ // IP or Port not reachable / no response
+ $this->SetStatus(200);
+
+ return false;
+ }
+
+ $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
+ $body = trim(substr($data, $header_size));
+ $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Return-Code Provided is: ').$code,0);
+ //$this->SendDebug($this->Translate("Debug"), $data,0);
+
+ preg_match_all('|(?i)Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
+ if (isset($results[1])) {
+ $Cookie = implode(';', $results[1]);
+ if (!empty($body)) {
+ if (200 == $code) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
+ }
+ else if (400 == $code) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
+ return false;
+ }
+ else if (401 == $code || 403 == $code) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
+ return false;
}
}
+ }
- $SenderID = $this->GetBuffer("SenderID");
- if ($SenderID != "") {
- $SenderObjectData = IPS_GetObject($SenderID);
- $SenderName = ($SenderObjectData["ObjectName"]);
- $SenderObjectIdent = ($SenderObjectData["ObjectIdent"]);
- $SenderStatus = GetValue($SenderID);
+ $SenderID = $this->GetBuffer("SenderID");
+ if ($SenderID != "") {
+ $SenderObjectData = IPS_GetObject($SenderID);
+ $SenderName = ($SenderObjectData["ObjectName"]);
+ $SenderObjectIdent = ($SenderObjectData["ObjectIdent"]);
+ $SenderStatus = GetValue($SenderID);
- //Get MAC Address from Config form
- $DevicesList = $this->ReadPropertyString("Devices");
- $DevicesJSON = json_decode($DevicesList,true);
+ //Get MAC Address from Config form
+ $DevicesList = $this->ReadPropertyString("Devices");
+ $DevicesJSON = json_decode($DevicesList,true);
- if (isset($DevicesJSON)) {
- $DeviceMacAddress = "";
-
- foreach ($DevicesJSON as $Device) {
- $DeviceMacClean = str_replace(array(":"," "), "", $Device["varDeviceMAC"]);
- if ($SenderObjectIdent == $DeviceMacClean) {
- $DeviceMacAddress = $Device["varDeviceMAC"];
- $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Device to be managed: ").$Device["varDeviceName"],0);
- break;
- }
+ if (isset($DevicesJSON)) {
+ $DeviceMacAddress = "";
+
+ foreach ($DevicesJSON as $Device) {
+ $DeviceMacClean = str_replace(array(":"," "), "", $Device["varDeviceMAC"]);
+ if ($SenderObjectIdent == $DeviceMacClean) {
+ $DeviceMacAddress = $Device["varDeviceMAC"];
+ $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Device to be managed: ").$Device["varDeviceName"],0);
+ break;
}
}
+ }
- if (!isset($DeviceMacAddress) || "" == $DeviceMacAddress) {
- $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("The switched variable did not have an entry in the module configuration - execution stopped"),0);
- return false;
- }
+ if (!isset($DeviceMacAddress) || "" == $DeviceMacAddress) {
+ $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("The switched variable did not have an entry in the module configuration - execution stopped"),0);
+ return false;
+ }
- $this->SendDebug($this->Translate("Device Blocker"),$Cookie,0);
+ $this->SendDebug($this->Translate("Device Blocker"),$Cookie,0);
- //////////////////////////////////////////
- //Change the Unifi API to be called here
- $UnifiAPI = "api/s/".$Site."/cmd/stamgr";
- //////////////////////////////////////////
+ //////////////////////////////////////////
+ //Change the Unifi API to be called here
+ $Site = $this->ReadPropertyString("Site");
+ $UnifiAPI = "api/s/".$Site."/cmd/stamgr";
+ //////////////////////////////////////////
- //create XSRF Token
-
- if (($Cookie) && strpos($Cookie, 'TOKEN') !== false) {
- $cookie_bits = explode('=', $Cookie);
- if (empty($cookie_bits) || !array_key_exists(1, $cookie_bits)) {
- return;
- }
+ //create XSRF Token
- $jwt_components = explode('.', $cookie_bits[1]);
- if (empty($jwt_components) || !array_key_exists(1, $jwt_components)) {
- return;
- }
+ if (($Cookie) && strpos($Cookie, 'TOKEN') !== false) {
+ $cookie_bits = explode('=', $Cookie);
+ if (empty($cookie_bits) || !array_key_exists(1, $cookie_bits)) {
+ return;
+ }
- $X_CSRF_Token = 'x-csrf-token: ' . json_decode(base64_decode($jwt_components[1]))->csrfToken;
+ $jwt_components = explode('.', $cookie_bits[1]);
+ if (empty($jwt_components) || !array_key_exists(1, $jwt_components)) {
+ return;
}
- if (isset($Cookie)) {
+ $X_CSRF_Token = 'x-csrf-token: ' . json_decode(base64_decode($jwt_components[1]))->csrfToken;
+ }
+
+ if (isset($Cookie)) {
- $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Module is authenticated and will try to manage device"),0);
+ $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Module is authenticated and will try to manage device"),0);
- if ($SenderStatus == 1) {
- $Command = "unblock-sta";
- $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Module will try to unblock device ").$SenderName.$this->Translate(" with MAC address ").$DeviceMacAddress,0);
- }
- else if ($SenderStatus == 0) {
- $Command = "block-sta";
- $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Module will try to block device ").$SenderName.$this->Translate(" with MAC address ").$DeviceMacAddress,0);
- }
+ if ($SenderStatus == 1) {
+ $Command = "unblock-sta";
+ $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Module will try to unblock device ").$SenderName.$this->Translate(" with MAC address ").$DeviceMacAddress,0);
+ }
+ else if ($SenderStatus == 0) {
+ $Command = "block-sta";
+ $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Module will try to block device ").$SenderName.$this->Translate(" with MAC address ").$DeviceMacAddress,0);
+ }
- //$CommandToController = json_encode(array($Command => $DeviceMacAddress));
+ //$CommandToController = json_encode(array($Command => $DeviceMacAddress));
- $CommandToController = json_encode(array(
- "cmd" => $Command,
- "mac" => $DeviceMacAddress
+ $CommandToController = json_encode(array(
+ "cmd" => $Command,
+ "mac" => $DeviceMacAddress
- ), JSON_UNESCAPED_SLASHES);
- //var_dump($CommandToController);
+ ), JSON_UNESCAPED_SLASHES);
+ //var_dump($CommandToController);
- $ch = curl_init();
- if ($ControllerType == 0) {
- $MiddlePartURL = "/proxy/network/";
- }
- elseif ($ControllerType == 1) {
- $MiddlePartURL = "/";
- }
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$MiddlePartURL.$UnifiAPI);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Cookie:'.$Cookie,$X_CSRF_Token,'Content-Type:application/json', 'Expect:'/*,'data='.$CommandToController*/));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $CommandToController);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $RawData = curl_exec($ch);
- $HTTP_Code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Feedback from UniFi Controller: ").$RawData." / HTTP Message ".$HTTP_Code ,0);
+ $ch = curl_init();
+ if ($ControllerType == 0) {
+ $MiddlePartURL = "/proxy/network/";
+ }
+ elseif ($ControllerType == 1) {
+ $MiddlePartURL = "/";
+ }
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$MiddlePartURL.$UnifiAPI);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Cookie:'.$Cookie,$X_CSRF_Token,'Content-Type:application/json', 'Expect:'/*,'data='.$CommandToController*/));
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $CommandToController);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+ curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1');
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ $RawData = curl_exec($ch);
+ $HTTP_Code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Feedback from UniFi Controller: ").$RawData." / HTTP Message ".$HTTP_Code ,0);
- $ControllerFeedbackComplete = json_decode($RawData,true);
- $ControllerFeedbackOK = $ControllerFeedbackComplete["meta"]["rc"];
- $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Was operation executed: ").$ControllerFeedbackOK ,0);
- curl_close($ch);
- if ($ControllerFeedbackOK == "ok") {
- //WFC_SendPopup(12345, "Test", "Eine nette
Meldung");
- }
- else if ($ControllerFeedbackOK == "error") {
- //WFC_SendPopup(12345, "Test", "Eine nette
Meldung");
- }
-
+ $ControllerFeedbackComplete = json_decode($RawData,true);
+ $ControllerFeedbackOK = $ControllerFeedbackComplete["meta"]["rc"];
+ $this->SendDebug($this->Translate("Device Blocker"),$this->Translate("Was operation executed: ").$ControllerFeedbackOK ,0);
+ curl_close($ch);
+ if ($ControllerFeedbackOK == "ok") {
+ //WFC_SendPopup(12345, "Test", "Eine nette
Meldung");
}
-
+ else if ($ControllerFeedbackOK == "error") {
+ //WFC_SendPopup(12345, "Test", "Eine nette
Meldung");
+ }
+
}
- return true;
-
}
+
+ return true;
+
+ }
- public function RequestAction($Ident, $Value) {
+ public function RequestAction($Ident, $Value) {
- $this->SetValue($Ident, $Value);
+ $this->SetValue($Ident, $Value);
- }
+ }
- // public function, which is blocking a device with MAC $DeviceMacAddress
- public function block(string $DeviceMacAddress) {
- $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAddress);
- $VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
+ // public function, which is blocking a device with MAC $DeviceMacAddress
+ public function block(string $DeviceMacAddress) {
+ $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAddress);
+ $VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
- if(false !== $VarID) {
- $this->SetValue($DeviceMacClean, false);
- return true;
- }
- else {
- $this->SendDebug($this->Translate("Device Blocker"), "Error: block(".$DeviceMacAddress.")", 0);
- return false;
- }
+ if(false !== $VarID) {
+ $this->SetValue($DeviceMacClean, false);
+ return true;
+ }
+ else {
+ $this->SendDebug($this->Translate("Device Blocker"), "Error: block(".$DeviceMacAddress.")", 0);
+ return false;
}
+ }
- // public function, which is unblocking/allowing a device with MAC $DeviceMacAddress
- public function unblock(string $DeviceMacAddress) {
- $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAddress);
- $VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
+ // public function, which is unblocking/allowing a device with MAC $DeviceMacAddress
+ public function unblock(string $DeviceMacAddress) {
+ $DeviceMacClean = str_replace(array(":"," "), "", $DeviceMacAddress);
+ $VarID = @IPS_GetObjectIDByIdent($DeviceMacClean, $this->InstanceID);
- if(false !== $VarID) {
- $this->SetValue($DeviceMacClean, true);
- return true;
- }
- else {
- $this->SendDebug($this->Translate("Device Blocker"), "Error: unblock(".$DeviceMacAddress.")", 0);
- return false;
- }
+ if(false !== $VarID) {
+ $this->SetValue($DeviceMacClean, true);
+ return true;
+ }
+ else {
+ $this->SendDebug($this->Translate("Device Blocker"), "Error: unblock(".$DeviceMacAddress.")", 0);
+ return false;
}
-
}
+
+}
diff --git a/UniFi Device Monitor/README.md b/UniFi Device Monitor/README.md
index ca29d69..6e086c7 100644
--- a/UniFi Device Monitor/README.md
+++ b/UniFi Device Monitor/README.md
@@ -1,7 +1,7 @@
# UniFi Device Monitor
Dieses Modul ermöglicht es Unifi Geräte im Netz zu überwachen und u.a. Verbindungs- und Hardwaredaten abzufragen.
-### Inhaltsverzeichnis
+## Inhaltsverzeichnis
1. [Funktionsumfang](#1-funktionsumfang)
2. [Voraussetzungen](#2-voraussetzungen)
@@ -9,24 +9,24 @@ Dieses Modul ermöglicht es Unifi Geräte im Netz zu überwachen und u.a. Verbin
4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon)
5. [Versionsinformation](#5-versionsinformation)
-### 1. Funktionsumfang
+## 1. Funktionsumfang
-* Unterstützung für UniFi Cloudkey 1
-* Unterstützung für UniFi Cloudkey 2 und Dream Maschine
+* Unterstützung für UniFi CloudKey 1 (UC-CK)
+* Unterstützung für UniFi CloudKey 2 (UCK-G2) und DreamMachine (UDM)
* Anlegen von zu überwachenden Geräten mit Name und MAC Adresse
* Erstellt pro Gerät eine Variable welche z.B. für die Automation oder Überwachung genutzt werden kann (Boolean)
* Abfragen der Controller erfolgt zeitgesteuert alle xx Sekunden
-### 2. Voraussetzungen
+## 2. Voraussetzungen
- IP-Symcon ab Version 5.5
-### 3. Software-Installation
+## 3. Software-Installation
* Über den Module Store das 'UniFi Presence Manager'-Modul installieren.
* Alternativ über das Module Control folgende URL hinzufügen
-### 4. Einrichten der Instanzen in IP-Symcon
+## 4. Einrichten der Instanzen in IP-Symcon
Unter 'Instanz hinzufügen' kann das 'UniFi Presence Manager'-Modul mithilfe des Schnellfilters gefunden werden.
- Weitere Informationen zum Hinzufügen von Instanzen in der [Dokumentation der Instanzen](https://www.symcon.de/service/dokumentation/konzepte/instanzen/#Instanz_hinzufügen)
@@ -35,7 +35,7 @@ __Konfigurationsseite__:
**Art des Controllers**
-Da sich die APIs von CloudKey 1 und CloudKey2/Dreammachine unterscheiden, kann hier der Controller gewählt werden
+Da sich die APIs von CloudKey 1 und CloudKey2/DreamMachine unterscheiden, kann hier der Controller gewählt werden
**Benutzername & Kennwort**
@@ -45,9 +45,9 @@ Account mit dem sich das Modul mit dem Controller verbindet
Site die im Controller hinterlegt ist
-**IP Adresse und Port**
+**IP-Adresse und Port**
-Bei der Dream Maschine ist der Port 443, bei einem Controller im Standard 8443. IP-Adresse des CloudKeys oder der Dream Maschine.
+Bei der DreamMachine ist der Port 443, bei einem Controller im Standard 8443. IP-Adresse des CloudKeys oder der DreamMachine.
**Aktualisierungsfrequenz**
@@ -78,6 +78,7 @@ Netzwerkdaten wie Public IP, übertragene Daten, Pakete und Fehler
Bei WLAN-Geräten werden hier Informationen zu übertragenen Daten und Paketen geliefert.
**Debugging**
+
Das Modul gibt diverse Informationen im Debug Bereich aus.
## 5. Versionsinformation
diff --git a/UniFi Device Monitor/form.json b/UniFi Device Monitor/form.json
index a574837..8284b94 100644
--- a/UniFi Device Monitor/form.json
+++ b/UniFi Device Monitor/form.json
@@ -40,7 +40,7 @@
"caption": "Controller Type",
"options": [
{
- "caption": "Dream Maschine / Pro / CloudKey V2",
+ "caption": "DreamMachine / Pro / CloudKey V2",
"value": 0
},
{
@@ -82,7 +82,9 @@
"type": "NumberSpinner",
"name": "Timer",
"caption": "Update Frequency",
- "suffix": "sec - 0 is off"
+ "suffix": "sec - 0 is off",
+ "digits": 0,
+ "minimum": 0
},
{
"type": "Label",
@@ -136,7 +138,7 @@
{
"type": "Button",
"label": "Test Authentication",
- "onClick": "DM_AuthenticateAndGetData($id);"
+ "onClick": "DM_AuthenticateAndGetData($id, '');"
},
{
"type": "Button",
@@ -145,6 +147,5 @@
}
]
}
- ],
- "status": []
+ ]
}
diff --git a/UniFi Device Monitor/locale.json b/UniFi Device Monitor/locale.json
index 6cdb1da..473acf5 100644
--- a/UniFi Device Monitor/locale.json
+++ b/UniFi Device Monitor/locale.json
@@ -9,6 +9,8 @@
"Updates will happen on a schedule every xyz seconds.": "Das Module prüft die Anwensenheit alle xyz Sekunden, wie im Module konfiguriert",
"For debugging, please use the Debug function of the module.": "Für das Prüfen der Funktionen, gibt es Modul Meldungen im Debugbereich aus",
"UniFi Toolbox - Endpoint Monitor Configuration": "UniFi Toolbox - Endgeräte Überwachung Konfiguration",
+ "400 Bad Request - The server cannot or will not process the request due to an apparent client error.": "400 Bad Request - Die Anfrage wird vom Controller nicht verarbeitet (falsche IP?) - Client Fehler.",
+ "401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?": "401 Unauthorized / 403 Forbidden - Die Anfrage ging an den richtigen Server, allerdings konnte sich Symcon nicht anmelden. Bitte Login Daten prüfen.",
"Controller Type": "Art des Controllers",
"Server Address": "Server Adresse",
"User Name": "Anmeldename",
@@ -18,8 +20,6 @@
"Please enter the MAC Address of the device to be monitored.": "MAC Adresse die überwacht werden soll.",
"Device MAC Address": "Geräte MAC Adresse",
"Please select how the device to be monitor is connected - this will switch on/off certain variables.": "Bitte wählen wie das zu überwachende Gerät verbunden ist - dies bestimmt die möglichen Variablen.",
- "400 Bad Request - The server cannot or will not process the request due to an apparent client error.": "400 Bad Request - Die Anfrage wird vom Controller nicht verarbeitet (falsche IP?) - Client Fehler.",
- "401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?": "401 Unauthorized / 403 Forbidden - Die Anfrage ging an den richtigen Server, allerdings konnte sich Symcon nicht anmelden. Bitte Login Daten prüfen.",
"Connection Type": "Art der Verbindung",
"Wireless": "WLAN",
"Wired": "Kabel",
diff --git a/UniFi Device Monitor/module.php b/UniFi Device Monitor/module.php
index cb82c8c..a54c020 100644
--- a/UniFi Device Monitor/module.php
+++ b/UniFi Device Monitor/module.php
@@ -10,257 +10,280 @@
define('vtArray', 8);
define('vtObject', 9);
}
- class UniFiDeviceMonitor extends IPSModule
- {
- public function Create() {
- //Never delete this line!
- parent::Create();
-
- $this->RegisterPropertyInteger("ControllerType", 0);
- $this->RegisterPropertyString("ServerAddress","192.168.1.1");
- $this->RegisterPropertyInteger("ServerPort", "443");
- $this->RegisterPropertyString("Site","default");
- $this->RegisterPropertyString("UserName","");
- $this->RegisterPropertyString("Password","");
- $this->RegisterPropertyInteger("Timer", "0");
+class UniFiDeviceMonitor extends IPSModule {
+ public function Create() {
+ //Never delete this line!
+ parent::Create();
+
+ $this->RegisterPropertyInteger("ControllerType", 0);
+ $this->RegisterPropertyString("ServerAddress","192.168.1.1");
+ $this->RegisterPropertyInteger("ServerPort", "443");
+ $this->RegisterPropertyString("Site","default");
+ $this->RegisterPropertyString("UserName","");
+ $this->RegisterPropertyString("Password","");
+ $this->RegisterPropertyInteger("Timer", "0");
- $this->RegisterPropertyString("DeviceMac", "");
- $this->RegisterPropertyInteger("DeviceType", 0);
+ $this->RegisterPropertyString("DeviceMac", "");
+ $this->RegisterPropertyInteger("DeviceType", 0);
- $this->RegisterPropertyBoolean("DataPointBasic", 1);
- $this->RegisterPropertyBoolean("DataPointHardware", 0);
- $this->RegisterPropertyBoolean("DataPointSpecific", 0);
+ $this->RegisterPropertyBoolean("DataPointBasic", 1);
+ $this->RegisterPropertyBoolean("DataPointHardware", 0);
+ $this->RegisterPropertyBoolean("DataPointSpecific", 0);
- $this->RegisterTimer("Device Monitor",0,"DM_DeviceMonitor(\$_IPS['TARGET']);");
+ $this->RegisterTimer("Device Monitor",0,"DM_DeviceMonitor(\$_IPS['TARGET']);");
- }
+ }
- public function Destroy() {
- //Never delete this line!
- parent::Destroy();
- }
+ public function Destroy() {
+ //Never delete this line!
+ parent::Destroy();
+ }
- public function ApplyChanges() {
- //Never delete this line!
- parent::ApplyChanges();
+ public function ApplyChanges() {
+ //Never delete this line!
+ parent::ApplyChanges();
- //Basic Data
- $vpos = 100;
- $this->MaintainVariable("DeviceModel", $this->Translate("Device Model"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
- $this->MaintainVariable("SoftwareVersion", $this->Translate("Software Version"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
- //$this->MaintainVariable("Satisfaction", $this->Translate("Satisfaction"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
- $this->MaintainVariable("LastSeen", $this->Translate("Last Seen"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
- $this->MaintainVariable("Uptime", $this->Translate("Uptime in hours"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
- //$this->MaintainVariable("IPAddress", $this->Translate("IP Address"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
- $this->MaintainVariable("Name", $this->Translate("Device Name"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
-
- //Hardware Data
- $vpos = 200;
- $this->MaintainVariable("CPULoad", $this->Translate("CPU Load"), vtFloat, "", $vpos++, $this->ReadPropertyBoolean("DataPointHardware") == 1);
- $this->MaintainVariable("MemoryLoad", $this->Translate("Memory Load"), vtFloat, "", $vpos++, $this->ReadPropertyBoolean("DataPointHardware") == 1);
+ //Basic Data
+ $vpos = 100;
+ $this->MaintainVariable("DeviceModel", $this->Translate("Device Model"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+ $this->MaintainVariable("SoftwareVersion", $this->Translate("Software Version"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+ //$this->MaintainVariable("Satisfaction", $this->Translate("Satisfaction"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+ $this->MaintainVariable("LastSeen", $this->Translate("Last Seen"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+ $this->MaintainVariable("Uptime", $this->Translate("Uptime in hours"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+ //$this->MaintainVariable("IPAddress", $this->Translate("IP Address"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+ $this->MaintainVariable("Name", $this->Translate("Device Name"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointBasic") == 1);
+
+ //Hardware Data
+ $vpos = 200;
+ $this->MaintainVariable("CPULoad", $this->Translate("CPU Load"), vtFloat, "", $vpos++, $this->ReadPropertyBoolean("DataPointHardware") == 1);
+ $this->MaintainVariable("MemoryLoad", $this->Translate("Memory Load"), vtFloat, "", $vpos++, $this->ReadPropertyBoolean("DataPointHardware") == 1);
- //Device Specific Data Connection Data UDM/USG
- $vpos = 300;
- $this->MaintainVariable("WAN1IP", $this->Translate("WAN1 IP"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
- $this->MaintainVariable("WAN1TXBytes", $this->Translate("WAN 1 TX Megabytes"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
- $this->MaintainVariable("WAN1RXBytes", $this->Translate("WAN 1 RX Megabytes"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
- $this->MaintainVariable("WAN1TXPackets", $this->Translate("WAN 1 TX Packets"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
- $this->MaintainVariable("WAN1RXPackets", $this->Translate("WAN 1 RX Packets"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
- $this->MaintainVariable("WAN1TXErrors", $this->Translate("WAN 1 TX Errors"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
- $this->MaintainVariable("WAN1RXErrors", $this->Translate("WAN 1 RX Errors"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
-
- $TimerMS = $this->ReadPropertyInteger("Timer") * 1000;
- $this->SetTimerInterval("Device Monitor",$TimerMS);
-
- if (0 == $TimerMS) {
- // instance inactive
- $this->SetStatus(104);
- }
- else {
- // instance active
- $this->SetStatus(102);
- }
+ //Device Specific Data Connection Data UDM/USG
+ $vpos = 300;
+ $this->MaintainVariable("WAN1IP", $this->Translate("WAN1 IP"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
+ $this->MaintainVariable("WAN1TXBytes", $this->Translate("WAN 1 TX Megabytes"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
+ $this->MaintainVariable("WAN1RXBytes", $this->Translate("WAN 1 RX Megabytes"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
+ $this->MaintainVariable("WAN1TXPackets", $this->Translate("WAN 1 TX Packets"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
+ $this->MaintainVariable("WAN1RXPackets", $this->Translate("WAN 1 RX Packets"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
+ $this->MaintainVariable("WAN1TXErrors", $this->Translate("WAN 1 TX Errors"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
+ $this->MaintainVariable("WAN1RXErrors", $this->Translate("WAN 1 RX Errors"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0);
+ $TimerMS = $this->ReadPropertyInteger("Timer") * 1000;
+ $this->SetTimerInterval("Device Monitor",$TimerMS);
+
+ if (0 == $TimerMS) {
+ // instance inactive
+ $this->SetStatus(104);
+ }
+ else {
+ // instance active
+ $this->SetStatus(102);
}
+ }
+
- public function AuthenticateAndGetData() {
+ public function AuthenticateAndGetData(string $UnifiAPI = "") {
- $ControllerType = $this->ReadPropertyInteger("ControllerType");
- $ServerAddress = $this->ReadPropertyString("ServerAddress");
- $ServerPort = $this->ReadPropertyInteger("ServerPort");
- $Username = $this->ReadPropertyString("UserName");
- $Password = $this->ReadPropertyString("Password");
+ $ControllerType = $this->ReadPropertyInteger("ControllerType");
+ $ServerAddress = $this->ReadPropertyString("ServerAddress");
+ $ServerPort = $this->ReadPropertyInteger("ServerPort");
+ $Username = $this->ReadPropertyString("UserName");
+ $Password = $this->ReadPropertyString("Password");
+ $DeviceMac = strtolower($this->ReadPropertyString("DeviceMac"));
+
+ //Change the Unifi API to be called here
+ if ("" == $UnifiAPI) {
$Site = $this->ReadPropertyString("Site");
+ $UnifiAPI = "api/s/".$Site."/stat/device";
+ }
- $DeviceMac = strtolower($this->ReadPropertyString("DeviceMac"));
+ //Generic Section providing for Authenthication against a DreamMachine or Classic CloudKey
+ $ch = curl_init();
- ////////////////////////////////////////
- //Change the Unifi API to be called here
- $UnifiAPI = "api/s/".$Site."/stat/device";
- ////////////////////////////////////////
+ if(!isset($ControllerType) || $ControllerType == 0) {
+ $SuffixURL = "/api/auth/login";
+ curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$Username."&password=".$Password);
+ }
+ elseif ($ControllerType == 1) {
+ $SuffixURL = "/api/login";
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['username' => $Username, 'password' => $Password]));
+ }
+ curl_setopt($ch, CURLOPT_POST, TRUE);
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$SuffixURL);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
+ curl_setopt($ch, CURLOPT_HEADER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ $data = curl_exec($ch);
- //Generic Section providing for Authenthication against a Dream Maschine or Classic CloudKey
+ if(false === $data)
+ {
+ $this->SendDebug($this->Translate("Authentication"), $this->Translate('Error: Not reachable / No response!'),0);
- $ch = curl_init();
+ // IP or Port not reachable / no response
+ $this->SetStatus(200);
- if ($ControllerType == 0) {
- $SuffixURL = "/api/auth/login";
- curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$Username."&password=".$Password);
- }
- elseif ($ControllerType == 1) {
- $SuffixURL = "/api/login";
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['username' => $Username, 'password' => $Password]));
- }
- curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$SuffixURL);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $data = curl_exec($ch);
-
- $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
- $body = trim(substr($data, $header_size));
- $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$code,0);
- preg_match_all('|(?i)Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
- if (isset($results[1])) {
- $Cookie = implode(';', $results[1]);
- if (!empty($body)) {
- if ($code == 200) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
- }
- else if ($code == 400) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
- echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
- return false;
- }
- else if ($code == 401 || $code == 403) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
- echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
- return false;
- }
- }
- }
+ return false;
+ }
- // Section below will collect and store it into a buffer
-
- if (isset($Cookie)) {
+ $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
+ $body = trim(substr($data, $header_size));
+ $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Return-Code Provided is: ').$code,0);
+ //$this->SendDebug($this->Translate("Debug"), $data,0);
- $ch = curl_init();
- if ($ControllerType == 0) {
- $MiddlePartURL = "/proxy/network/";
+ preg_match_all('|(?i)Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
+ if (isset($results[1])) {
+ $Cookie = implode(';', $results[1]);
+ if (!empty($body)) {
+ if (200 == $code) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
}
- elseif ($ControllerType == 1) {
- $MiddlePartURL = "/";
- }
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$MiddlePartURL.$UnifiAPI."/".$DeviceMac);
- curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
- curl_setopt($ch , CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("cookie: ".$Cookie));
- curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1');
-
- $RawData = curl_exec($ch);
- curl_close($ch);
-
- if (isset($RawData) AND $RawData != "Unauthorized") {
- $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Successfully Called"),0);
- $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Data Provided: ").$RawData,0);
- $this->SetBuffer("RawData",$RawData);
+ else if (400 == $code) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
+ return false;
}
- else {
- $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("API could not be called - check the login data. Do you see a Cookie?"),0);
+ else if (401 == $code || 403 == $code) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
+ return false;
}
}
-
- return true;
}
- public function DeviceMonitor() {
-
- $this->AuthenticateAndGetData();
- $RawData = $this->GetBuffer("RawData");
+ // Section below will collect and store it into a buffer
- if ($RawData !== "") {
- $JSONData = json_decode($RawData,true);
- //var_dump($JSONData);
- $DeviceModel = $JSONData["data"][0]["model"];
- $UnfiInternetDeviceArray = array("UDM","UGW4","UGW3","UDMPRO");
-
- if (!in_array($DeviceModel,$UnfiInternetDeviceArray) AND $this->ReadPropertyInteger("DeviceType") == 0) {
- $DeviceConfigError = true;
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Config error - device type set to UDM, USG etc. but is no such device."),0);
- }
- else {
- $DeviceConfigError = false;
- }
+ if (isset($Cookie)) {
- if ($this->ReadPropertyBoolean("DataPointBasic") == 1) {
- $DeviceModel = $JSONData["data"][0]["model"];
- SetValue($this->GetIDForIdent("DeviceModel"),$DeviceModel);
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Device Model ").$DeviceModel,0);
- $SoftwareVersion = $JSONData["data"][0]["version"];
- SetValue($this->GetIDForIdent("SoftwareVersion"),$SoftwareVersion);
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Software Version ").$SoftwareVersion,0);
- //$Satisfaction = $JSONData["data"][0]["satisfaction"];
- //SetValue($this->GetIDForIdent("Satisfaction"),$Satisfaction);
- //$this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Device Satisfaction ").$Satisfaction,0);
- $SLastSeen = $JSONData["data"][0]["last_seen"];
- SetValue($this->GetIDForIdent("LastSeen"),gmdate("Y-m-d H:i:s", $SLastSeen));
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Connection Data Last Seen ").gmdate("Y-m-d H:i:s", $SLastSeen),0);
- $Uptime = $JSONData["data"][0]["uptime"];
- SetValue($this->GetIDForIdent("Uptime"),Round($Uptime/3600,0));
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Connection Data Uptime in hours ").Round($Uptime/3600,0),0);
- $Name = $JSONData["data"][0]["name"];
- SetValue($this->GetIDForIdent("Name"),$Name);
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Devicename ").$Name,0);
- }
- if ($this->ReadPropertyBoolean("DataPointHardware") == 1) {
- $CPULoad = $JSONData["data"][0]["system-stats"]["cpu"];
- SetValue($this->GetIDForIdent("CPULoad"),$CPULoad);
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("CPU Load ").$CPULoad,0);
- $MemoryLoad = $JSONData["data"][0]["system-stats"]["mem"];
- SetValue($this->GetIDForIdent("MemoryLoad"),$MemoryLoad);
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Memory Load ").$MemoryLoad,0);
-
- }
- if ($this->ReadPropertyBoolean("DataPointSpecific") == 1 AND $this->ReadPropertyInteger("DeviceType") == 0 AND $DeviceConfigError == false) {
- $WAN1IP = $JSONData["data"][0]["wan1"]["ip"];
- SetValue($this->GetIDForIdent("WAN1IP"),$WAN1IP);
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Connection Data WAN 1 IP ").$WAN1IP,0);
-
- $WAN1TXBytes = $JSONData["data"][0]["wan1"]["tx_bytes"];
- SetValue($this->GetIDForIdent("WAN1TXBytes"),$WAN1TXBytes/1000000);
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Transfer Data WAN 1 TX Bytes ").$WAN1TXBytes,0);
- $WAN1RXBytes = $JSONData["data"][0]["wan1"]["rx_bytes"];
- SetValue($this->GetIDForIdent("WAN1RXBytes"),$WAN1RXBytes/1000000);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Transfer Data WAN 1 RX Bytes ").$WAN1RXBytes,0);
- $WAN1TXPackets = $JSONData["data"][0]["wan1"]["tx_packets"];
- SetValue($this->GetIDForIdent("WAN1TXPackets"),$WAN1TXPackets);
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Transfer Data WAN 1 TX Packets ").$WAN1TXPackets,0);
- $WAN1RXPackets = $JSONData["data"][0]["wan1"]["tx_packets"];
- SetValue($this->GetIDForIdent("WAN1RXPackets"),$WAN1RXPackets);
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Transfer Data WAN 1 RXPackets ").$WAN1RXPackets,0);
- $WAN1TXErrors = $JSONData["data"][0]["wan1"]["tx_errors"];
- SetValue($this->GetIDForIdent("WAN1TXErrors"),$WAN1TXErrors);
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Transfer Data WAN 1 TX Errors ").$WAN1TXErrors,0);
- $WAN1RXErrors = $JSONData["data"][0]["wan1"]["rx_errors"];
- SetValue($this->GetIDForIdent("WAN1RXErrors"),$WAN1RXErrors);
- $this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Transfer Data WAN 1 RX Errors ").$WAN1RXErrors,0);
- }
+ $ch = curl_init();
+ if (!isset($ControllerType) || $ControllerType == 0) {
+ $MiddlePartURL = "/proxy/network/";
}
- else {
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("There does not seem to be any configuration - no data is available from the UniFi"),0);
- }
+ elseif ($ControllerType == 1) {
+ $MiddlePartURL = "/";
+ }
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$MiddlePartURL.$UnifiAPI."/".$DeviceMac);
+ curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
+ curl_setopt($ch , CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array("cookie: ".$Cookie));
+ curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1');
+
+ //$this->SendDebug("Debug: ", "https://".$ServerAddress.":".$ServerPort.$MiddlePartURL.$UnifiAPI, 0);
+ $RawData = curl_exec($ch);
+ curl_close($ch);
+ //$JSON = json_decode($RawData,true);
+ //$this->SetBuffer("RawData",$RawData);
+
+ if (isset($RawData) && 400 == $RawData) {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ $this->SetStatus(201); // login seems to be not successful
+ return false;
+ }
+ else if (isset($RawData) && (401 == $RawData || 403 == $RawData || $RawData == "Unauthorized")) {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ $this->SetStatus(201); // login seems to be not successful
+ return false;
+ }
+ else if (isset($RawData)) {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Successfully Called"),0);
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Data Provided: ").$RawData,0);
+ $this->SetBuffer("RawData",$RawData);
+ }
+ else {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("API could not be called - check the login data. Do you see a Cookie?"),0);
+ $this->SetStatus(201); // login seems to be not successful
+ return false;
+ }
}
+ return true;
}
+
+ public function DeviceMonitor() {
+ $Site = $this->ReadPropertyString("Site");
+
+ // query JSON file for internet data
+ if ($this->AuthenticateAndGetData("api/s/".$Site."/stat/device")) {
+ $RawData = $this->GetBuffer("RawData");
+
+ if ($RawData !== "") {
+ $JSONData = json_decode($RawData, true);
+ //var_dump($JSONData);
+ $DeviceModel = $JSONData["data"][0]["model"];
+ $UnfiInternetDeviceArray = array("UDM","UGW4","UGW3","UDMPRO");
+
+ if (!in_array($DeviceModel, $UnfiInternetDeviceArray) and $this->ReadPropertyInteger("DeviceType") == 0) {
+ $DeviceConfigError = true;
+ $this->SendDebug($this->Translate("Device Monitor"), $this->Translate("Config error - device type set to UDM, USG etc. but is no such device."), 0);
+ } else {
+ $DeviceConfigError = false;
+ }
+
+ if ($this->ReadPropertyBoolean("DataPointBasic") == 1) {
+ $DeviceModel = $JSONData["data"][0]["model"];
+ SetValue($this->GetIDForIdent("DeviceModel"), $DeviceModel);
+ $this->SendDebug($this->Translate("Device Monitor"), $this->Translate("Device Model ").$DeviceModel, 0);
+ $SoftwareVersion = $JSONData["data"][0]["version"];
+ SetValue($this->GetIDForIdent("SoftwareVersion"), $SoftwareVersion);
+ $this->SendDebug($this->Translate("Device Monitor"), $this->Translate("Software Version ").$SoftwareVersion, 0);
+ //$Satisfaction = $JSONData["data"][0]["satisfaction"];
+ //SetValue($this->GetIDForIdent("Satisfaction"),$Satisfaction);
+ //$this->SendDebug($this->Translate("Device Monitor"),$this->Translate("Device Satisfaction ").$Satisfaction,0);
+ $SLastSeen = $JSONData["data"][0]["last_seen"];
+ SetValue($this->GetIDForIdent("LastSeen"), gmdate("Y-m-d H:i:s", $SLastSeen));
+ $this->SendDebug($this->Translate("Device Monitor"), $this->Translate("Connection Data Last Seen ").gmdate("Y-m-d H:i:s", $SLastSeen), 0);
+ $Uptime = $JSONData["data"][0]["uptime"];
+ SetValue($this->GetIDForIdent("Uptime"), Round($Uptime/3600, 0));
+ $this->SendDebug($this->Translate("Device Monitor"), $this->Translate("Connection Data Uptime in hours ").Round($Uptime/3600, 0), 0);
+ $Name = $JSONData["data"][0]["name"];
+ SetValue($this->GetIDForIdent("Name"), $Name);
+ $this->SendDebug($this->Translate("Device Monitor"), $this->Translate("Devicename ").$Name, 0);
+ }
+ if ($this->ReadPropertyBoolean("DataPointHardware") == 1) {
+ $CPULoad = $JSONData["data"][0]["system-stats"]["cpu"];
+ SetValue($this->GetIDForIdent("CPULoad"), $CPULoad);
+ $this->SendDebug($this->Translate("Device Monitor"), $this->Translate("CPU Load ").$CPULoad, 0);
+ $MemoryLoad = $JSONData["data"][0]["system-stats"]["mem"];
+ SetValue($this->GetIDForIdent("MemoryLoad"), $MemoryLoad);
+ $this->SendDebug($this->Translate("Device Monitor"), $this->Translate("Memory Load ").$MemoryLoad, 0);
+ }
+ if ($this->ReadPropertyBoolean("DataPointSpecific") == 1 and $this->ReadPropertyInteger("DeviceType") == 0 and $DeviceConfigError == false) {
+ $WAN1IP = $JSONData["data"][0]["wan1"]["ip"];
+ SetValue($this->GetIDForIdent("WAN1IP"), $WAN1IP);
+ $this->SendDebug($this->Translate("Device Monitor"), $this->Translate("Connection Data WAN 1 IP ").$WAN1IP, 0);
+
+ $WAN1TXBytes = $JSONData["data"][0]["wan1"]["tx_bytes"];
+ SetValue($this->GetIDForIdent("WAN1TXBytes"), $WAN1TXBytes/1000000);
+ $this->SendDebug($this->Translate("Device Monitor"), $this->Translate("Transfer Data WAN 1 TX Bytes ").$WAN1TXBytes, 0);
+ $WAN1RXBytes = $JSONData["data"][0]["wan1"]["rx_bytes"];
+ SetValue($this->GetIDForIdent("WAN1RXBytes"), $WAN1RXBytes/1000000);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Transfer Data WAN 1 RX Bytes ").$WAN1RXBytes, 0);
+ $WAN1TXPackets = $JSONData["data"][0]["wan1"]["tx_packets"];
+ SetValue($this->GetIDForIdent("WAN1TXPackets"), $WAN1TXPackets);
+ $this->SendDebug($this->Translate("Device Monitor"), $this->Translate("Transfer Data WAN 1 TX Packets ").$WAN1TXPackets, 0);
+ $WAN1RXPackets = $JSONData["data"][0]["wan1"]["tx_packets"];
+ SetValue($this->GetIDForIdent("WAN1RXPackets"), $WAN1RXPackets);
+ $this->SendDebug($this->Translate("Device Monitor"), $this->Translate("Transfer Data WAN 1 RXPackets ").$WAN1RXPackets, 0);
+ $WAN1TXErrors = $JSONData["data"][0]["wan1"]["tx_errors"];
+ SetValue($this->GetIDForIdent("WAN1TXErrors"), $WAN1TXErrors);
+ $this->SendDebug($this->Translate("Device Monitor"), $this->Translate("Transfer Data WAN 1 TX Errors ").$WAN1TXErrors, 0);
+ $WAN1RXErrors = $JSONData["data"][0]["wan1"]["rx_errors"];
+ SetValue($this->GetIDForIdent("WAN1RXErrors"), $WAN1RXErrors);
+ $this->SendDebug($this->Translate("Device Monitor"), $this->Translate("Transfer Data WAN 1 RX Errors ").$WAN1RXErrors, 0);
+ }
+ } else {
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("There does not seem to be any configuration - no data is available from the UniFi"), 0);
+ }
+ }
+ }
+}
diff --git a/UniFi Endpoint Monitor/README.md b/UniFi Endpoint Monitor/README.md
index 9f957bf..968ffe2 100644
--- a/UniFi Endpoint Monitor/README.md
+++ b/UniFi Endpoint Monitor/README.md
@@ -1,7 +1,7 @@
# UniFi Endpoint Monitor
Dieses Modul ermöglicht es Endgeräte im Netz zu überwachen und diverse Daten in Symcon darzustellen.
-### Inhaltsverzeichnis
+## Inhaltsverzeichnis
1. [Funktionsumfang](#1-funktionsumfang)
2. [Voraussetzungen](#2-voraussetzungen)
@@ -9,24 +9,24 @@ Dieses Modul ermöglicht es Endgeräte im Netz zu überwachen und diverse Daten
4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon)
5. [Versionsinformation](#5-versionsinformation)
-### 1. Funktionsumfang
+## 1. Funktionsumfang
-* Unterstützung für UniFi Cloudkey 1
-* Unterstützung für UniFi Cloudkey 2 und Dream Maschine
+* Unterstützung für UniFi CloudKey 1 (UC-CK)
+* Unterstützung für UniFi CloudKey 2 (UCK-G2) und DreamMachine (UDM)
* Anlegen von zu überwachenden Geräten mit Name und MAC Adresse
* Erstellt pro Gerät eine Variable welche z.B. für die Automation oder Überwachung genutzt werden kann (Boolean)
* Abfragen der Controller erfolgt zeitgesteuert alle xx Sekunden
-### 2. Voraussetzungen
+## 2. Voraussetzungen
- IP-Symcon ab Version 5.5
-### 3. Software-Installation
+## 3. Software-Installation
* Über den Module Store das 'UniFi Presence Manager'-Modul installieren.
* Alternativ über das Module Control folgende URL hinzufügen
-### 4. Einrichten der Instanzen in IP-Symcon
+## 4. Einrichten der Instanzen in IP-Symcon
Unter 'Instanz hinzufügen' kann das 'UniFi Presence Manager'-Modul mithilfe des Schnellfilters gefunden werden.
- Weitere Informationen zum Hinzufügen von Instanzen in der [Dokumentation der Instanzen](https://www.symcon.de/service/dokumentation/konzepte/instanzen/#Instanz_hinzufügen)
@@ -35,7 +35,7 @@ __Konfigurationsseite__:
**Art des Controllers**
-Da sich die APIs von CloudKey 1 und CloudKey2/Dreammachine unterscheiden, kann hier der Controller gewählt werden
+Da sich die APIs von CloudKey 1 und CloudKey2/DreamMachine unterscheiden, kann hier der Controller gewählt werden
**Benutzername & Kennwort**
@@ -45,9 +45,9 @@ Account mit dem sich das Modul mit dem Controller verbindet
Site die im Controller hinterlegt ist
-**IP Adresse und Port**
+**IP-Adresse und Port**
-Bei der Dream Maschine ist der Port 443, bei einem Controller im Standard 8443. IP-Adresse des CloudKeys oder der Dream Maschine.
+Bei der DreamMachine ist der Port 443, bei einem Controller im Standard 8443. IP-Adresse des CloudKeys oder der DreamMachine.
**Aktualisierungsfrequenz**
@@ -74,6 +74,7 @@ Hier werden verfügbare physische Daten bereitgestellt. Hierzu zählen bei WLAN-
Bei WLAN-Geräten werden hier Informationen zu übertragenen Daten und Paketen geliefert.
**Debugging**
+
Das Modul gibt diverse Informationen im Debug Bereich aus.
## 5. Versionsinformation
diff --git a/UniFi Endpoint Monitor/form.json b/UniFi Endpoint Monitor/form.json
index 2414090..cce3f1e 100644
--- a/UniFi Endpoint Monitor/form.json
+++ b/UniFi Endpoint Monitor/form.json
@@ -40,7 +40,7 @@
"caption": "Controller Type",
"options": [
{
- "caption": "Dream Maschine / Pro / CloudKey V2",
+ "caption": "DreamMachine / Pro / CloudKey V2",
"value": 0
},
{
@@ -82,7 +82,9 @@
"type": "NumberSpinner",
"name": "Timer",
"caption": "Update Frequency",
- "suffix": "sec - 0 is off"
+ "suffix": "sec - 0 is off",
+ "digits": 0,
+ "minimum": 0
},
{
"type": "Label",
@@ -140,7 +142,7 @@
{
"type": "Button",
"label": "Test Authentication",
- "onClick": "EM_AuthenticateAndGetData($id);"
+ "onClick": "EM_AuthenticateAndGetData($id, '');"
},
{
"type": "Button",
@@ -149,6 +151,5 @@
}
]
}
- ],
- "status": []
+ ]
}
diff --git a/UniFi Endpoint Monitor/locale.json b/UniFi Endpoint Monitor/locale.json
index 34b3aa0..f90d185 100644
--- a/UniFi Endpoint Monitor/locale.json
+++ b/UniFi Endpoint Monitor/locale.json
@@ -9,6 +9,8 @@
"Updates will happen on a schedule every xyz seconds.": "Das Module prüft die Anwensenheit alle xyz Sekunden, wie im Module konfiguriert",
"For debugging, please use the Debug function of the module.": "Für das Prüfen der Funktionen, gibt es Modul Meldungen im Debugbereich aus",
"UniFi Toolbox - Endpoint Monitor Configuration": "UniFi Toolbox - Endgeräte Überwachung Konfiguration",
+ "400 Bad Request - The server cannot or will not process the request due to an apparent client error.": "400 Bad Request - Die Anfrage wird vom Controller nicht verarbeitet (falsche IP?) - Client Fehler.",
+ "401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?": "401 Unauthorized / 403 Forbidden - Die Anfrage ging an den richtigen Server, allerdings konnte sich Symcon nicht anmelden. Bitte Login Daten prüfen.",
"Controller Type": "Art des Controllers",
"Server Address": "Server Adresse",
"User Name": "Anmeldename",
@@ -18,8 +20,6 @@
"Please enter the MAC Address of the device to be monitored.": "MAC Adresse die überwacht werden soll.",
"Device MAC Address": "Geräte MAC Adresse",
"Please select how the device to be monitor is connected - this will switch on/off certain variables.": "Bitte wählen wie das zu überwachende Gerät verbunden ist - dies bestimmt die möglichen Variablen.",
- "400 Bad Request - The server cannot or will not process the request due to an apparent client error.": "400 Bad Request - Die Anfrage wird vom Controller nicht verarbeitet (falsche IP?) - Client Fehler.",
- "401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?": "401 Unauthorized / 403 Forbidden - Die Anfrage ging an den richtigen Server, allerdings konnte sich Symcon nicht anmelden. Bitte Login Daten prüfen.",
"Connection Type": "Art der Verbindung",
"Wireless": "WLAN",
"Wired": "Kabel",
diff --git a/UniFi Endpoint Monitor/module.php b/UniFi Endpoint Monitor/module.php
index 3f30fc2..e9d11b3 100644
--- a/UniFi Endpoint Monitor/module.php
+++ b/UniFi Endpoint Monitor/module.php
@@ -10,271 +10,291 @@
define('vtArray', 8);
define('vtObject', 9);
}
- class UnifiEndpointMonitor extends IPSModule
- {
- public function Create() {
- //Never delete this line!
- parent::Create();
-
- $this->RegisterPropertyInteger("ControllerType", 0);
- $this->RegisterPropertyString("ServerAddress","192.168.1.1");
- $this->RegisterPropertyInteger("ServerPort", "443");
- $this->RegisterPropertyString("Site","default");
- $this->RegisterPropertyString("UserName","");
- $this->RegisterPropertyString("Password","");
- $this->RegisterPropertyInteger("Timer", "0");
+class UnifiEndpointMonitor extends IPSModule {
+
+ public function Create() {
+ //Never delete this line!
+ parent::Create();
+
+ $this->RegisterPropertyInteger("ControllerType", 0);
+ $this->RegisterPropertyString("ServerAddress","192.168.1.1");
+ $this->RegisterPropertyInteger("ServerPort", "443");
+ $this->RegisterPropertyString("Site","default");
+ $this->RegisterPropertyString("UserName","");
+ $this->RegisterPropertyString("Password","");
+ $this->RegisterPropertyInteger("Timer", "0");
- $this->RegisterPropertyString("DeviceMac", "");
- $this->RegisterPropertyInteger("ConnectionType", 0);
+ $this->RegisterPropertyString("DeviceMac", "");
+ $this->RegisterPropertyInteger("ConnectionType", 0);
- $this->RegisterPropertyBoolean("DataPointNetwork", 0);
- $this->RegisterPropertyBoolean("DataPointConnection", 0);
- $this->RegisterPropertyBoolean("DataPointTransfer", 0);
+ $this->RegisterPropertyBoolean("DataPointNetwork", 0);
+ $this->RegisterPropertyBoolean("DataPointConnection", 0);
+ $this->RegisterPropertyBoolean("DataPointTransfer", 0);
- $this->RegisterTimer("Endpoint Monitor",0,"EM_EndpointMonitor(\$_IPS['TARGET']);");
+ $this->RegisterTimer("Endpoint Monitor",0,"EM_EndpointMonitor(\$_IPS['TARGET']);");
- }
+ }
- public function Destroy() {
- //Never delete this line!
- parent::Destroy();
- }
+ public function Destroy() {
+ //Never delete this line!
+ parent::Destroy();
+ }
- public function ApplyChanges() {
- //Never delete this line!
- parent::ApplyChanges();
+ public function ApplyChanges() {
+ //Never delete this line!
+ parent::ApplyChanges();
- //Network Data
- $vpos = 100;
- $this->MaintainVariable("IPAddress", $this->Translate("IP Address"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointNetwork") == 1);
- $this->MaintainVariable("Hostname", $this->Translate("Hostname"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointNetwork") == 1);
- //$this->MaintainVariable("Name", $this->Translate("Name"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointNetwork") == 1);
-
- //Connection Data General
- $vpos = 200;
- $this->MaintainVariable("Satisfaction", $this->Translate("Satisfaction"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1);
- $this->MaintainVariable("LastSeen", $this->Translate("Last Seen"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1);
- $this->MaintainVariable("Uptime", $this->Translate("Uptime in hours"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1);
- //Connection Data Wired
- $vpos = 230;
- //$this->MaintainVariable("SwitchPort", $this->Translate("Switch Port"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 1);
- //$this->MaintainVariable("SwitchMAC", $this->Translate("Switch MAC"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 1);
- //Connection Data Wireless
- $vpos = 250;
- $this->MaintainVariable("Accesspoint", $this->Translate("Accesspoint"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
- $this->MaintainVariable("Channel", $this->Translate("Channel"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
- $this->MaintainVariable("Radio", $this->Translate("Radio"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
- $this->MaintainVariable("ESSID", $this->Translate("ESS ID"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
- $this->MaintainVariable("RSSI", $this->Translate("RSSI"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
- $this->MaintainVariable("Noise", $this->Translate("Noise"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
- $this->MaintainVariable("SignalStrength", $this->Translate("Signal Strength"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
-
- //Transfer Data
- $vpos = 300;
- $this->MaintainVariable("TXBytes", $this->Translate("TX Megabytes"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointTransfer") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
- $this->MaintainVariable("RXBytes", $this->Translate("RX Megabytes"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointTransfer") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
- $this->MaintainVariable("TXPackets", $this->Translate("TX Packets"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointTransfer") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
- $this->MaintainVariable("RXPackets", $this->Translate("RX Packets"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointTransfer") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
-
-
- $TimerMS = $this->ReadPropertyInteger("Timer") * 1000;
- $this->SetTimerInterval("Endpoint Monitor",$TimerMS);
-
- if (0 == $TimerMS) {
- // instance inactive
- $this->SetStatus(104);
- }
- else {
- // instance active
- $this->SetStatus(102);
- }
-
+ //Network Data
+ $vpos = 100;
+ $this->MaintainVariable("IPAddress", $this->Translate("IP Address"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointNetwork") == 1);
+ $this->MaintainVariable("Hostname", $this->Translate("Hostname"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointNetwork") == 1);
+ //$this->MaintainVariable("Name", $this->Translate("Name"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointNetwork") == 1);
+
+ //Connection Data General
+ $vpos = 200;
+ $this->MaintainVariable("Satisfaction", $this->Translate("Satisfaction"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1);
+ $this->MaintainVariable("LastSeen", $this->Translate("Last Seen"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1);
+ $this->MaintainVariable("Uptime", $this->Translate("Uptime in hours"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1);
+ //Connection Data Wired
+ $vpos = 230;
+ //$this->MaintainVariable("SwitchPort", $this->Translate("Switch Port"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 1);
+ //$this->MaintainVariable("SwitchMAC", $this->Translate("Switch MAC"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 1);
+ //Connection Data Wireless
+ $vpos = 250;
+ $this->MaintainVariable("Accesspoint", $this->Translate("Accesspoint"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("Channel", $this->Translate("Channel"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("Radio", $this->Translate("Radio"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("ESSID", $this->Translate("ESS ID"), vtString, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("RSSI", $this->Translate("RSSI"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("Noise", $this->Translate("Noise"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("SignalStrength", $this->Translate("Signal Strength"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+
+ //Transfer Data
+ $vpos = 300;
+ $this->MaintainVariable("TXBytes", $this->Translate("TX Megabytes"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointTransfer") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("RXBytes", $this->Translate("RX Megabytes"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointTransfer") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("TXPackets", $this->Translate("TX Packets"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointTransfer") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+ $this->MaintainVariable("RXPackets", $this->Translate("RX Packets"), vtInteger, "", $vpos++, $this->ReadPropertyBoolean("DataPointTransfer") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0);
+
+
+ $TimerMS = $this->ReadPropertyInteger("Timer") * 1000;
+ $this->SetTimerInterval("Endpoint Monitor",$TimerMS);
+
+ if (0 == $TimerMS) {
+ // instance inactive
+ $this->SetStatus(104);
+ }
+ else {
+ // instance active
+ $this->SetStatus(102);
}
+ }
+
- public function AuthenticateAndGetData() {
+ public function AuthenticateAndGetData(string $UnifiAPI = "") {
- $ControllerType = $this->ReadPropertyInteger("ControllerType");
- $ServerAddress = $this->ReadPropertyString("ServerAddress");
- $ServerPort = $this->ReadPropertyInteger("ServerPort");
- $Username = $this->ReadPropertyString("UserName");
- $Password = $this->ReadPropertyString("Password");
- $Site = $this->ReadPropertyString("Site");
+ $ControllerType = $this->ReadPropertyInteger("ControllerType");
+ $ServerAddress = $this->ReadPropertyString("ServerAddress");
+ $ServerPort = $this->ReadPropertyInteger("ServerPort");
+ $Username = $this->ReadPropertyString("UserName");
+ $Password = $this->ReadPropertyString("Password");
+ $Site = $this->ReadPropertyString("Site");
- $DeviceMac = strtolower($this->ReadPropertyString("DeviceMac"));
+ $DeviceMac = strtolower($this->ReadPropertyString("DeviceMac"));
- ////////////////////////////////////////
- //Change the Unifi API to be called here
+ //Change the Unifi API to be called here
+ if ("" == $UnifiAPI) {
+ $Site = $this->ReadPropertyString("Site");
$UnifiAPI = "api/s/".$Site."/stat/sta";
- ////////////////////////////////////////
-
- //Generic Section providing for Authenthication against a Dream Maschine or Classic CloudKey
+ }
+ //Generic Section providing for Authenthication against a DreamMachine or Classic CloudKey
+ $ch = curl_init();
- $ch = curl_init();
+ if(!isset($ControllerType) || $ControllerType == 0) {
+ $SuffixURL = "/api/auth/login";
+ curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$Username."&password=".$Password);
+ }
+ elseif ($ControllerType == 1) {
+ $SuffixURL = "/api/login";
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['username' => $Username, 'password' => $Password]));
+ }
+ curl_setopt($ch, CURLOPT_POST, TRUE);
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$SuffixURL);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
+ curl_setopt($ch, CURLOPT_HEADER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ $data = curl_exec($ch);
+
+ if(false === $data)
+ {
+ $this->SendDebug($this->Translate("Authentication"), $this->Translate('Error: Not reachable / No response!'),0);
+
+ // IP or Port not reachable / no response
+ $this->SetStatus(200);
+
+ return false;
+ }
- if ($ControllerType == 0) {
- $SuffixURL = "/api/auth/login";
- curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$Username."&password=".$Password);
- }
- elseif ($ControllerType == 1) {
- $SuffixURL = "/api/login";
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['username' => $Username, 'password' => $Password]));
- }
- curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$SuffixURL);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $data = curl_exec($ch);
-
- $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
- $body = trim(substr($data, $header_size));
- $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$code,0);
- preg_match_all('|(?i)Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
- if (isset($results[1])) {
- $Cookie = implode(';', $results[1]);
- if (!empty($body)) {
- if ($code == 200) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
- }
- else if ($code == 400) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
- echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
- return false;
- }
- else if ($code == 401 || $code == 403) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
- echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
- return false;
- }
- }
- }
+ $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
+ $body = trim(substr($data, $header_size));
+ $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- // Section below will collect and store it into a buffer
-
- if (isset($Cookie)) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Return-Code Provided is: ').$code,0);
+ //$this->SendDebug($this->Translate("Debug"), $data,0);
- $ch = curl_init();
- if ($ControllerType == 0) {
- $MiddlePartURL = "/proxy/network/";
+ preg_match_all('|(?i)Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
+ if (isset($results[1])) {
+ $Cookie = implode(';', $results[1]);
+ if (!empty($body)) {
+ if (200 == $code) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
}
- elseif ($ControllerType == 1) {
- $MiddlePartURL = "/";
- }
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$MiddlePartURL.$UnifiAPI."/".$DeviceMac);
- curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
- curl_setopt($ch , CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("cookie: ".$Cookie));
- curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1');
-
- $RawData = curl_exec($ch);
- curl_close($ch);
- //$JSON = json_decode($RawData,true);
- //$this->SetBuffer("$RawData",$RawData);
-
- if (isset($RawData) AND $RawData != "Unauthorized") {
- $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Successfully Called"),0);
- $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Data Provided: ").$RawData,0);
- $this->SetBuffer("RawData",$RawData);
+ else if (400 == $code) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
+ return false;
}
- else {
- $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("API could not be called - check the login data. Do you see a Cookie?"),0);
+ else if (401 == $code || 403 == $code) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
+ return false;
}
}
-
- return true;
}
- public function EndpointMonitor() {
-
- $this->AuthenticateAndGetData();
-
- $RawData = $this->GetBuffer("RawData");
+ // Section below will collect and store it into a buffer
- if ($RawData !== "") {
- $JSONData = json_decode($RawData,true);
- $ConnectionMethod = $JSONData["data"][0]["is_wired"];
+ if (isset($Cookie)) {
- if ($ConnectionMethod == true AND $this->ReadPropertyInteger("ConnectionType") == 0) {
- $ConnectionConfigError = true;
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Config error - device monitored is a wired device. Please select wired in the module configuration."),0);
- }
- else {
- $ConnectionConfigError = false;
- }
-
- if ($this->ReadPropertyBoolean("DataPointNetwork") == 1) {
- $IPAddress = $JSONData["data"][0]["ip"];
- SetValue($this->GetIDForIdent("IPAddress"),$IPAddress);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Network Data IP ").$IPAddress,0);
- $Hostname = $JSONData["data"][0]["hostname"];
- SetValue($this->GetIDForIdent("Hostname"),$Hostname);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Network Data Hostname ").$Hostname,0);
- //$Name = $JSONData["data"][0]["name"];
- //SetValue($this->GetIDForIdent("Name"),$Name);
- //$this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Network Data Name ").$Name,0);
- }
- if ($this->ReadPropertyBoolean("DataPointConnection") == 1) {
- $Satisfaction = $JSONData["data"][0]["satisfaction"];
- SetValue($this->GetIDForIdent("Satisfaction"),$Satisfaction);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data Satisfaction ").$Satisfaction,0);
- $SLastSeen = $JSONData["data"][0]["last_seen"];
- SetValue($this->GetIDForIdent("LastSeen"),gmdate("Y-m-d H:i:s", $SLastSeen));
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data Last Seen ").gmdate("Y-m-d H:i:s", $SLastSeen),0);
- $Uptime = $JSONData["data"][0]["uptime"];
- SetValue($this->GetIDForIdent("Uptime"),Round($Uptime/3600,0));
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data Uptime in hours ").Round($Uptime/3600,0),0);
- }
- if ($this->ReadPropertyBoolean("DataPointConnection") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0 AND $ConnectionConfigError == false) {
- $Accesspoint = $JSONData["data"][0]["ap_mac"];
- SetValue($this->GetIDForIdent("Accesspoint"),$Accesspoint);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data Accesspoint ").$Accesspoint,0);
- $Channel = $JSONData["data"][0]["channel"];
- SetValue($this->GetIDForIdent("Channel"),$Channel);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data Channel ").$Channel,0);
- $Radio = $JSONData["data"][0]["radio"];
- SetValue($this->GetIDForIdent("Radio"),$Radio);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data Radio ").$Radio,0);
- $ESSID = $JSONData["data"][0]["essid"];
- SetValue($this->GetIDForIdent("ESSID"),$ESSID);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data ESSID ").$ESSID,0);
- $RSSI = $JSONData["data"][0]["rssi"];
- SetValue($this->GetIDForIdent("RSSI"),$RSSI);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data RSSI ").$RSSI,0);
- $Noise = $JSONData["data"][0]["noise"];
- SetValue($this->GetIDForIdent("Noise"),$Noise);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data Noise ").$Noise,0);
- $SignalStrength = $JSONData["data"][0]["signal"];
- SetValue($this->GetIDForIdent("SignalStrength"),$SignalStrength);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Connection Data SignalStrength ").$SignalStrength,0);
- }
- if ($this->ReadPropertyBoolean("DataPointTransfer") == 1 AND $this->ReadPropertyInteger("ConnectionType") == 0 AND $ConnectionConfigError == false) {
- $TXBytes = $JSONData["data"][0]["tx_bytes"];
- SetValue($this->GetIDForIdent("TXBytes"),$TXBytes/1000000);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Transfer Data TXBytes ").$TXBytes/1000000,0);
- $RXBytes = $JSONData["data"][0]["rx_bytes"];
- SetValue($this->GetIDForIdent("RXBytes"),$RXBytes/1000000);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Transfer Data RXBytes ").$RXBytes/1000000,0);
- $TXPackets = $JSONData["data"][0]["tx_packets"];
- SetValue($this->GetIDForIdent("TXPackets"),$TXPackets);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Transfer Data TXPackets ").$TXPackets,0);
- $RXPackets = $JSONData["data"][0]["rx_packets"];
- SetValue($this->GetIDForIdent("RXPackets"),$RXPackets);
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Transfer Data RXPackets ").$RXPackets,0);
- }
+ $ch = curl_init();
+ if (!isset($ControllerType) || $ControllerType == 0) {
+ $MiddlePartURL = "/proxy/network/";
+ }
+ elseif ($ControllerType == 1) {
+ $MiddlePartURL = "/";
+ }
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$MiddlePartURL.$UnifiAPI."/".$DeviceMac);
+ curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
+ curl_setopt($ch , CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array("cookie: ".$Cookie));
+ curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1');
+
+ $RawData = curl_exec($ch);
+ curl_close($ch);
+ //$JSON = json_decode($RawData,true);
+ //$this->SetBuffer("RawData",$RawData);
+
+ if (isset($RawData) && 400 == $RawData) {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ $this->SetStatus(201); // login seems to be not successful
+ return false;
+ }
+ else if (isset($RawData) && (401 == $RawData || 403 == $RawData || $RawData == "Unauthorized")) {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ $this->SetStatus(201); // login seems to be not successful
+ return false;
+ }
+ else if (isset($RawData)) {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Successfully Called"),0);
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Data Provided: ").$RawData,0);
+ $this->SetBuffer("RawData",$RawData);
}
else {
- $this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("There does not seem to be any configuration - no data is available from the UniFi"),0);
- }
-
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("API could not be called - check the login data. Do you see a Cookie?"),0);
+ $this->SetStatus(201); // login seems to be not successful
+ return false;
+ }
}
+ return true;
}
+
+ public function EndpointMonitor() {
+ $Site = $this->ReadPropertyString("Site");
+
+ if ($this->AuthenticateAndGetData("api/s/".$Site."/stat/sta")) {
+ $RawData = $this->GetBuffer("RawData");
+
+ if ($RawData !== "") {
+ $JSONData = json_decode($RawData, true);
+ $ConnectionMethod = $JSONData["data"][0]["is_wired"];
+
+ if ($ConnectionMethod == true and $this->ReadPropertyInteger("ConnectionType") == 0) {
+ $ConnectionConfigError = true;
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Config error - device monitored is a wired device. Please select wired in the module configuration."), 0);
+ } else {
+ $ConnectionConfigError = false;
+ }
+
+ if ($this->ReadPropertyBoolean("DataPointNetwork") == 1) {
+ $IPAddress = $JSONData["data"][0]["ip"];
+ SetValue($this->GetIDForIdent("IPAddress"), $IPAddress);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Network Data IP ").$IPAddress, 0);
+ $Hostname = $JSONData["data"][0]["hostname"];
+ SetValue($this->GetIDForIdent("Hostname"), $Hostname);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Network Data Hostname ").$Hostname, 0);
+ //$Name = $JSONData["data"][0]["name"];
+ //SetValue($this->GetIDForIdent("Name"),$Name);
+ //$this->SendDebug($this->Translate("Endpoint Monitor"),$this->Translate("Network Data Name ").$Name,0);
+ }
+ if ($this->ReadPropertyBoolean("DataPointConnection") == 1) {
+ $Satisfaction = $JSONData["data"][0]["satisfaction"];
+ SetValue($this->GetIDForIdent("Satisfaction"), $Satisfaction);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Connection Data Satisfaction ").$Satisfaction, 0);
+ $SLastSeen = $JSONData["data"][0]["last_seen"];
+ SetValue($this->GetIDForIdent("LastSeen"), gmdate("Y-m-d H:i:s", $SLastSeen));
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Connection Data Last Seen ").gmdate("Y-m-d H:i:s", $SLastSeen), 0);
+ $Uptime = $JSONData["data"][0]["uptime"];
+ SetValue($this->GetIDForIdent("Uptime"), Round($Uptime/3600, 0));
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Connection Data Uptime in hours ").Round($Uptime/3600, 0), 0);
+ }
+ if ($this->ReadPropertyBoolean("DataPointConnection") == 1 and $this->ReadPropertyInteger("ConnectionType") == 0 and $ConnectionConfigError == false) {
+ $Accesspoint = $JSONData["data"][0]["ap_mac"];
+ SetValue($this->GetIDForIdent("Accesspoint"), $Accesspoint);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Connection Data Accesspoint ").$Accesspoint, 0);
+ $Channel = $JSONData["data"][0]["channel"];
+ SetValue($this->GetIDForIdent("Channel"), $Channel);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Connection Data Channel ").$Channel, 0);
+ $Radio = $JSONData["data"][0]["radio"];
+ SetValue($this->GetIDForIdent("Radio"), $Radio);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Connection Data Radio ").$Radio, 0);
+ $ESSID = $JSONData["data"][0]["essid"];
+ SetValue($this->GetIDForIdent("ESSID"), $ESSID);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Connection Data ESSID ").$ESSID, 0);
+ $RSSI = $JSONData["data"][0]["rssi"];
+ SetValue($this->GetIDForIdent("RSSI"), $RSSI);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Connection Data RSSI ").$RSSI, 0);
+ $Noise = $JSONData["data"][0]["noise"];
+ SetValue($this->GetIDForIdent("Noise"), $Noise);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Connection Data Noise ").$Noise, 0);
+ $SignalStrength = $JSONData["data"][0]["signal"];
+ SetValue($this->GetIDForIdent("SignalStrength"), $SignalStrength);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Connection Data SignalStrength ").$SignalStrength, 0);
+ }
+ if ($this->ReadPropertyBoolean("DataPointTransfer") == 1 and $this->ReadPropertyInteger("ConnectionType") == 0 and $ConnectionConfigError == false) {
+ $TXBytes = $JSONData["data"][0]["tx_bytes"];
+ SetValue($this->GetIDForIdent("TXBytes"), $TXBytes/1000000);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Transfer Data TXBytes ").$TXBytes/1000000, 0);
+ $RXBytes = $JSONData["data"][0]["rx_bytes"];
+ SetValue($this->GetIDForIdent("RXBytes"), $RXBytes/1000000);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Transfer Data RXBytes ").$RXBytes/1000000, 0);
+ $TXPackets = $JSONData["data"][0]["tx_packets"];
+ SetValue($this->GetIDForIdent("TXPackets"), $TXPackets);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Transfer Data TXPackets ").$TXPackets, 0);
+ $RXPackets = $JSONData["data"][0]["rx_packets"];
+ SetValue($this->GetIDForIdent("RXPackets"), $RXPackets);
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("Transfer Data RXPackets ").$RXPackets, 0);
+ }
+ } else {
+ $this->SendDebug($this->Translate("Endpoint Monitor"), $this->Translate("There does not seem to be any configuration - no data is available from the UniFi"), 0);
+ }
+ }
+ }
+}
diff --git a/UniFi Internet Controller/README.md b/UniFi Internet Controller/README.md
index 66cf7a6..4165298 100644
--- a/UniFi Internet Controller/README.md
+++ b/UniFi Internet Controller/README.md
@@ -1,5 +1,5 @@
# UniFi Internet Controller
-Dieses Modul ermöglicht es Informationen über die Internetverbindung durch eine USG oder DreamMaschine, wie z.B. die öffentliche IP-Adresse abzurufen.
+Dieses Modul ermöglicht es Informationen über die Internetverbindung durch eine USG oder DreamMachine, wie z.B. die öffentliche IP-Adresse abzurufen.
## Inhaltsverzeichnis
@@ -12,7 +12,7 @@ Dieses Modul ermöglicht es Informationen über die Internetverbindung durch ein
## 1. Funktionsumfang
* Unterstützung für UniFi CloudKey 1 (UC-CK)
-* Unterstützung für UniFi CloudKey 2 (UCK-G2) und DreamMaschine (UDM)
+* Unterstützung für UniFi CloudKey 2 (UCK-G2) und DreamMachine (UDM)
* Abfragen der Controller erfolgt zeitgesteuert alle xx Sekunden
* Aktuelle Datenpunkte: Externe IP-Adresse
@@ -34,7 +34,7 @@ __Konfigurationsseite__:
**Art des Controllers**
-Da sich die APIs von CloudKey 1 und CloudKey2/DreamMaschine unterscheiden, kann hier der Controller gewählt werden
+Da sich die APIs von CloudKey 1 und CloudKey2/DreamMachine unterscheiden, kann hier der Controller gewählt werden
**Benutzername & Kennwort**
@@ -46,7 +46,7 @@ Site die im Controller hinterlegt ist
**IP-Adresse und Port**
-Bei der DreamMaschine ist der Port 443, bei einem Controller im Standard 8443. IP-Adresse des CloudKeys oder der DreamMaschine.
+Bei der DreamMachine ist der Port 443, bei einem Controller im Standard 8443. IP-Adresse des CloudKeys oder der DreamMachine.
**Aktualisierungsfrequenz**
@@ -64,7 +64,7 @@ Das Modul gibt diverse Informationen im Debug Bereich aus.
Version 0.3 (Beta) - 23-08-2021
* Unterstützung für UniFi CloudKey 1
-* Unterstützung für UniFi CloudKey 2 und DreamMaschine
+* Unterstützung für UniFi CloudKey 2 und DreamMachine
* Abfrage der externen IP-Adresse (WAN01)
Version 0.4 (Beta) - 26-08-2021
diff --git a/UniFi Internet Controller/form.json b/UniFi Internet Controller/form.json
index d3a2939..3ed8a97 100644
--- a/UniFi Internet Controller/form.json
+++ b/UniFi Internet Controller/form.json
@@ -6,11 +6,11 @@
"items": [
{
"type": "Label",
- "label": "This Module allows to gather information converning the internet connection like the current public IP adress in conjunction with a Dream Machine."
+ "label": "This Module allows to gather information converning the internet connection like the current public IP address in conjunction with a Dream Machine."
},
{
"type": "Label",
- "label": "Please select the type of controller you are using, enter its IP Adress, Port and a user allowed to log in."
+ "label": "Please select the type of controller you are using, enter its IP Address, Port and a user allowed to log in."
},
{
"type": "Label",
@@ -28,7 +28,7 @@
},
{
"type": "Label",
- "label": "UniFi Toolbox - Dream Maschine Internet Controller Configuration"
+ "label": "UniFi Toolbox - DreamMachine Internet Controller Configuration"
},
{
"type": "ValidationTextBox",
@@ -37,7 +37,7 @@
},
{
"type": "ValidationTextBox",
- "name": "ServerAdress",
+ "name": "ServerAddress",
"caption": "Server Address",
"validate": "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
},
@@ -71,7 +71,7 @@
"type": "Label",
"label": ""
},
- {
+ {
"type": "RowLayout",
"items": [
{
@@ -98,7 +98,7 @@
"type": "Label",
"label": ""
},
- {
+ {
"type": "RowLayout",
"items": [
{
@@ -125,7 +125,7 @@
"type": "Label",
"label": ""
},
- {
+ {
"type": "RowLayout",
"items": [
{
diff --git a/UniFi Internet Controller/locale.json b/UniFi Internet Controller/locale.json
index 1cb1247..77bbe15 100644
--- a/UniFi Internet Controller/locale.json
+++ b/UniFi Internet Controller/locale.json
@@ -1,15 +1,14 @@
{
"translations": {
"de": {
- "active": "Aktiviert",
"Module Help": "Modul Hilfe",
- "This Module allows to gather information converning the internet connection like the current public IP adress in conjunction with a USG or Dream Machine.": "Dieses Modul ermöglicht es Informationen über die Internetverbindung durch eine USG oder Dream Maschine, wie z.B. die öffentliche IP Adresse abzurufen.",
- "Please select the type of controller you are using, enter its IP Adress, Port and a user allowed to log in.": "Bitte wählen sie die Art des Controllers und geben die IP Adresse, Port und einen Anwender ein der auf diesen zugreifen darf.",
- "To manage certain devices, please use their MAC adress and a clear text name, which will be used to create a variable in the object tree.": "Um Geräte zu verwalten, geben sie bitte die MAC Addresse und einen Namen in der Form unten ein - anhand des Namens wird eine Boolean Variable im Objektbaum erstellt.",
+ "This Module allows to gather information converning the internet connection like the current public IP address in conjunction with a USG or Dream Machine.": "Dieses Modul ermöglicht es Informationen über die Internetverbindung durch eine USG oder DreamMachine, wie z.B. die öffentliche IP Adresse abzurufen.",
+ "Please select the type of controller you are using, enter its IP Address, Port and a user allowed to log in.": "Bitte wählen sie die Art des Controllers und geben die IP Adresse, Port und einen Anwender ein der auf diesen zugreifen darf.",
+ "To manage certain devices, please use their MAC address and a clear text name, which will be used to create a variable in the object tree.": "Um Geräte zu verwalten, geben sie bitte die MAC Addresse und einen Namen in der Form unten ein - anhand des Namens wird eine Boolean Variable im Objektbaum erstellt.",
"All data will be stored in variables in the object tree.": "Alle Informationen werden im Objektbaum als Variable zur Verfügung gestellt.",
"Updates will happen on a schedule every xyz seconds.": "Das Module prüft die Anwensenheit alle xyz Sekunden, wie im Module konfiguriert",
"For debugging, please use the Debug function of the module.": "Für das Prüfen der Funktionen, gibt es Modul Meldungen im Debugbereich aus",
- "UniFi Toolbox - Dream Maschine Internet Controller Configuration": "UniFi Toolbox - Dream Maschine Internet Controller Konfiguration",
+ "UniFi Toolbox - DreamMachine Internet Controller Configuration": "UniFi Toolbox - DreamMachine Internet Controller Konfiguration",
"400 Bad Request - The server cannot or will not process the request due to an apparent client error.": "400 Bad Request - Die Anfrage wird vom Controller nicht verarbeitet (falsche IP?) - Client Fehler.",
"401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?": "401 Unauthorized / 403 Forbidden - Die Anfrage ging an den richtigen Server, allerdings konnte sich Symcon nicht anmelden. Bitte Login Daten prüfen.",
"Controller Type": "Art des Controllers",
diff --git a/UniFi Internet Controller/module.php b/UniFi Internet Controller/module.php
index 90be610..3a65b44 100644
--- a/UniFi Internet Controller/module.php
+++ b/UniFi Internet Controller/module.php
@@ -10,6 +10,7 @@
define('vtArray', 8);
define('vtObject', 9);
}
+
class UniFiDMInternetController extends IPSModule {
public function Create() {
@@ -17,7 +18,7 @@ public function Create() {
parent::Create();
//$this->RegisterPropertyInteger("ControllerType", 0);
- $this->RegisterPropertyString("ServerAdress","192.168.1.1");
+ $this->RegisterPropertyString("ServerAddress","192.168.1.1");
$this->RegisterPropertyInteger("ServerPort", "443");
$this->RegisterPropertyString("Site","default");
$this->RegisterPropertyString("UserName","");
@@ -113,30 +114,33 @@ public function ApplyChanges() {
}
- public function AuthenticateAndGetData (string $UnifiAPI = "") {
+ public function AuthenticateAndGetData(string $UnifiAPI = "") {
//$ControllerType = $this->ReadPropertyInteger("ControllerType");
- $ServerAdress = $this->ReadPropertyString("ServerAdress");
+ $ServerAddress = $this->ReadPropertyString("ServerAddress");
$ServerPort = $this->ReadPropertyInteger("ServerPort");
$Username = $this->ReadPropertyString("UserName");
$Password = $this->ReadPropertyString("Password");
- $Site = $this->ReadPropertyString("Site");
- ////////////////////////////////////////
//Change the Unifi API to be called here
if ("" == $UnifiAPI) {
+ $Site = $this->ReadPropertyString("Site");
$UnifiAPI = "api/s/".$Site."/stat/sysinfo";
}
- ////////////////////////////////////////
-
-
- //Generic Section providing for Authenthication against a Dream Maschine or Classic CloudKey
+ //Generic Section providing for Authenthication against a DreamMachine or Classic CloudKey
$ch = curl_init();
- $SuffixURL = "/api/auth/login";
- curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$Username."&password=".$Password);
+
+ if(!isset($ControllerType) || $ControllerType == 0) {
+ $SuffixURL = "/api/auth/login";
+ curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$Username."&password=".$Password);
+ }
+ elseif ($ControllerType == 1) {
+ $SuffixURL = "/api/login";
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['username' => $Username, 'password' => $Password]));
+ }
curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$SuffixURL);
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$SuffixURL);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
@@ -182,15 +186,18 @@ public function AuthenticateAndGetData (string $UnifiAPI = "") {
}
}
-
// Section below will collect and store it into a buffer
-
+
if (isset($Cookie)) {
$ch = curl_init();
-
- $MiddlePartURL = "/proxy/network/";
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$MiddlePartURL.$UnifiAPI);
+ if (!isset($ControllerType) || $ControllerType == 0) {
+ $MiddlePartURL = "/proxy/network/";
+ }
+ elseif ($ControllerType == 1) {
+ $MiddlePartURL = "/";
+ }
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$MiddlePartURL.$UnifiAPI);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
@@ -198,19 +205,19 @@ public function AuthenticateAndGetData (string $UnifiAPI = "") {
curl_setopt($ch, CURLOPT_HTTPHEADER, array("cookie: ".$Cookie));
curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1');
- //$this->SendDebug("Debug: ", "https://".$ServerAdress.":".$ServerPort.$MiddlePartURL.$UnifiAPI, 0);
+ //$this->SendDebug("Debug: ", "https://".$ServerAddress.":".$ServerPort.$MiddlePartURL.$UnifiAPI, 0);
$RawData = curl_exec($ch);
curl_close($ch);
//$JSON = json_decode($RawData,true);
//$this->SetBuffer("RawData",$RawData);
- if (400 == $RawData) {
+ if (isset($RawData) && 400 == $RawData) {
$this->SendDebug($this->Translate("UniFi API Call"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
$this->SetStatus(201); // login seems to be not successful
return false;
}
- else if (401 == $RawData || 403 == $RawData || $RawData == "Unauthorized") {
+ else if (isset($RawData) && (401 == $RawData || 403 == $RawData || $RawData == "Unauthorized")) {
$this->SendDebug($this->Translate("UniFi API Call"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
$this->SetStatus(201); // login seems to be not successful
return false;
@@ -231,6 +238,7 @@ public function AuthenticateAndGetData (string $UnifiAPI = "") {
}
public function GetInternetData() {
+ $Site = $this->ReadPropertyString("Site");
if($this->ReadPropertyBoolean("WAN1IP")
|| $this->ReadPropertyBoolean("WAN2IP")
@@ -242,70 +250,71 @@ public function GetInternetData() {
|| $this->ReadPropertyBoolean("ubnt_device_type")
|| $this->ReadPropertyBoolean("udm_version")
) {
+
// query JSON file for internet data
- if ($this->AuthenticateAndGetData()) {
- $RawData = $this->GetBuffer("RawData");
- $JSONData = json_decode($RawData, true);
-
-
- // get IP addresses
- $variableArray = array(
- array('ident' => "WAN1IP", 'localeName' => "WAN1 External IP Address", 'index' => 0),
- array('ident' => "WAN2IP", 'localeName' => "WAN2 External IP Address", 'index' => 1),
- );
-
- foreach ($variableArray as $variable) {
- if ($this->ReadPropertyBoolean($variable['ident'])) {
- if (isset($JSONData['data'][0]["ip_addrs"][$variable['index']])) {
- $value = $JSONData['data'][0]["ip_addrs"][$variable['index']];
- if (isset($value)) {
- if ($value != GetValue($this->GetIDForIdent($variable['ident']))) {
- $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("updated to ").$value, 0);
- SetValue($this->GetIDForIdent($variable['ident']), $value);
- } else {
- $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("no update received")." (".$value.")", 0);
+ if ($this->AuthenticateAndGetData("api/s/".$Site."/stat/sysinfo")) {
+ $RawData = $this->GetBuffer("RawData");
+ $JSONData = json_decode($RawData, true);
+
+
+ // get IP addresses
+ $variableArray = array(
+ array('ident' => "WAN1IP", 'localeName' => "WAN1 External IP Address", 'index' => 0),
+ array('ident' => "WAN2IP", 'localeName' => "WAN2 External IP Address", 'index' => 1),
+ );
+
+ foreach ($variableArray as $variable) {
+ if ($this->ReadPropertyBoolean($variable['ident'])) {
+ if (isset($JSONData['data'][0]["ip_addrs"][$variable['index']])) {
+ $value = $JSONData['data'][0]["ip_addrs"][$variable['index']];
+ if (isset($value)) {
+ if ($value != GetValue($this->GetIDForIdent($variable['ident']))) {
+ $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("updated to ").$value, 0);
+ SetValue($this->GetIDForIdent($variable['ident']), $value);
+ } else {
+ $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("no update received")." (".$value.")", 0);
+ }
}
+ } else {
+ $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("No data"), 0);
}
- } else {
- $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("No data"), 0);
}
}
- }
- // get everything else (besides IP addresses)
- $variableArray = array(
- array('ident' => "version", 'localeName' => "Unifi Network Version"),
- array('ident' => "previous_version", 'localeName' => "Unifi Network Vorgängerversion"),
- array('ident' => "update_available", 'localeName' => "Update available"),
- array('ident' => "update_downloaded", 'localeName' => "Update downloaded"),
- array('ident' => "uptime", 'localeName' => "Uptime", 'valueCorrection' => "\$value = (time() - (time() % 60)) - (\$value - (\$value % 60));"), // value correction to avoid an update for every cycle
- );
-
- $variableArray[] = array('ident' => "ubnt_device_type", 'localeName' => "UBNT Device Type");
- $variableArray[] = array('ident' => "udm_version", 'localeName' => "UDM Version");
-
- foreach ($variableArray as $variable) {
- if ($this->ReadPropertyBoolean($variable['ident'])) {
- if (isset($JSONData['data'][0][$variable['ident']])) {
- $value = $JSONData['data'][0][$variable['ident']];
- if (isset($value)) {
- if (isset($variable['valueCorrection'])) {
- eval($variable['valueCorrection']);
- }
+ // get everything else (besides IP addresses)
+ $variableArray = array(
+ array('ident' => "version", 'localeName' => "Unifi Network Version"),
+ array('ident' => "previous_version", 'localeName' => "Unifi Network Vorgängerversion"),
+ array('ident' => "update_available", 'localeName' => "Update available"),
+ array('ident' => "update_downloaded", 'localeName' => "Update downloaded"),
+ array('ident' => "uptime", 'localeName' => "Uptime", 'valueCorrection' => "\$value = (time() - (time() % 60)) - (\$value - (\$value % 60));"), // value correction to avoid an update for every cycle
+ );
+
+ $variableArray[] = array('ident' => "ubnt_device_type", 'localeName' => "UBNT Device Type");
+ $variableArray[] = array('ident' => "udm_version", 'localeName' => "UDM Version");
+
+ foreach ($variableArray as $variable) {
+ if ($this->ReadPropertyBoolean($variable['ident'])) {
+ if (isset($JSONData['data'][0][$variable['ident']])) {
+ $value = $JSONData['data'][0][$variable['ident']];
+ if (isset($value)) {
+ if (isset($variable['valueCorrection'])) {
+ eval($variable['valueCorrection']);
+ }
- if ($value != GetValue($this->GetIDForIdent($variable['ident']))) {
- $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("updated to ").$value, 0);
- SetValue($this->GetIDForIdent($variable['ident']), $value);
- } else {
- $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("no update received")." (".$value.")", 0);
+ if ($value != GetValue($this->GetIDForIdent($variable['ident']))) {
+ $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("updated to ").$value, 0);
+ SetValue($this->GetIDForIdent($variable['ident']), $value);
+ } else {
+ $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("no update received")." (".$value.")", 0);
+ }
}
+ } else {
+ $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("No data"), 0);
}
- } else {
- $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("No data"), 0);
}
}
- }
}
}
@@ -320,52 +329,51 @@ public function GetInternetData() {
|| $this->ReadPropertyBoolean("isp_name")
|| $this->ReadPropertyBoolean("isp_organization")
) {
- $Site = $this->ReadPropertyString("Site");
if ($this->AuthenticateAndGetData("api/stat/sites")) {
- $RawData = $this->GetBuffer("RawData");
- $JSONData = json_decode($RawData, true);
- // $this->SendDebug("JSONData", $JSONData, 0);
- $healthArray = $JSONData['data'][0]['health'];
-
- $variableArray = array(
- array('ident' => "gw_version", 'json' => "return (isset(\$health['gw_version']) ? \$health['gw_version'] : null);", 'localeName' => "UDM UnifiOS Version"),
- array('ident' => "wan_ip", 'json' => "return (isset(\$health['wan_ip']) ? \$health['wan_ip'] : null);", 'localeName' => "WAN IP active"),
- array('ident' => "WAN1availability", 'json' => "return (isset(\$health['uptime_stats']['WAN']['availability']) ? round(\$health['uptime_stats']['WAN']['availability']) : null);", 'localeName' => "WAN1 availablity"),
- array('ident' => "WAN1latency_average", 'json' => "return (isset(\$health['uptime_stats']['WAN']['latency_average']) ? \$health['uptime_stats']['WAN']['latency_average'] : null);", 'localeName' => "WAN1 latency_average"),
- array('ident' => "WAN1time_period", 'json' => "return (isset(\$health['uptime_stats']['WAN']['time_period']) ? \$health['uptime_stats']['WAN']['time_period'] : null);", 'localeName' => "WAN1 time_period"),
- array('ident' => "WAN2availability", 'json' => "return (isset(\$health['uptime_stats']['WAN2']['availability']) ? round(\$health['uptime_stats']['WAN2']['availability']) : null);", 'localeName' => "WAN2 availablity"),
- array('ident' => "WAN2latency_average", 'json' => "return (isset(\$health['uptime_stats']['WAN2']['latency_average']) ? \$health['uptime_stats']['WAN2']['latency_average'] : null);", 'localeName' => "WAN2 latency_average",),
- array('ident' => "WAN2time_period", 'json' => "return (isset(\$health['uptime_stats']['WAN2']['time_period']) ? \$health['uptime_stats']['WAN2']['time_period'] : null);", 'localeName' => "WAN2 time_period"),
- array('ident' => "isp_name", 'json' => "return (isset(\$health['isp_name']) ? \$health['isp_name'] : null);", 'localeName' => "ISP Name"),
- array('ident' => "isp_organization", 'json' => "return (isset(\$health['isp_organization']) ? \$health['isp_organization'] : null);", 'localeName' => "ISP Organization"),
- );
-
- foreach ($healthArray as $health) {
- if (isset($health['subsystem']) && 'wan' == $health['subsystem']) {
- foreach ($variableArray as $variable) {
- if ($this->ReadPropertyBoolean($variable['ident'])) {
- if (null !== eval($variable['json'])) {
- $value = eval($variable['json']);
- if (isset($value)) {
- if (isset($variable['valueCorrection'])) {
- eval($variable['valueCorrection']);
- }
-
- if ($value != GetValue($this->GetIDForIdent($variable['ident']))) {
- $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("updated to ").$value, 0);
- SetValue($this->GetIDForIdent($variable['ident']), $value);
- } else {
- $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("no update received")." (".$value.")", 0);
+ $RawData = $this->GetBuffer("RawData");
+ $JSONData = json_decode($RawData, true);
+ // $this->SendDebug("JSONData", $JSONData, 0);
+ $healthArray = $JSONData['data'][0]['health'];
+
+ $variableArray = array(
+ array('ident' => "gw_version", 'json' => "return (isset(\$health['gw_version']) ? \$health['gw_version'] : null);", 'localeName' => "UDM UnifiOS Version"),
+ array('ident' => "wan_ip", 'json' => "return (isset(\$health['wan_ip']) ? \$health['wan_ip'] : null);", 'localeName' => "WAN IP active"),
+ array('ident' => "WAN1availability", 'json' => "return (isset(\$health['uptime_stats']['WAN']['availability']) ? round(\$health['uptime_stats']['WAN']['availability']) : null);", 'localeName' => "WAN1 availablity"),
+ array('ident' => "WAN1latency_average", 'json' => "return (isset(\$health['uptime_stats']['WAN']['latency_average']) ? \$health['uptime_stats']['WAN']['latency_average'] : null);", 'localeName' => "WAN1 latency_average"),
+ array('ident' => "WAN1time_period", 'json' => "return (isset(\$health['uptime_stats']['WAN']['time_period']) ? \$health['uptime_stats']['WAN']['time_period'] : null);", 'localeName' => "WAN1 time_period"),
+ array('ident' => "WAN2availability", 'json' => "return (isset(\$health['uptime_stats']['WAN2']['availability']) ? round(\$health['uptime_stats']['WAN2']['availability']) : null);", 'localeName' => "WAN2 availablity"),
+ array('ident' => "WAN2latency_average", 'json' => "return (isset(\$health['uptime_stats']['WAN2']['latency_average']) ? \$health['uptime_stats']['WAN2']['latency_average'] : null);", 'localeName' => "WAN2 latency_average",),
+ array('ident' => "WAN2time_period", 'json' => "return (isset(\$health['uptime_stats']['WAN2']['time_period']) ? \$health['uptime_stats']['WAN2']['time_period'] : null);", 'localeName' => "WAN2 time_period"),
+ array('ident' => "isp_name", 'json' => "return (isset(\$health['isp_name']) ? \$health['isp_name'] : null);", 'localeName' => "ISP Name"),
+ array('ident' => "isp_organization", 'json' => "return (isset(\$health['isp_organization']) ? \$health['isp_organization'] : null);", 'localeName' => "ISP Organization"),
+ );
+
+ foreach ($healthArray as $health) {
+ if (isset($health['subsystem']) && 'wan' == $health['subsystem']) {
+ foreach ($variableArray as $variable) {
+ if ($this->ReadPropertyBoolean($variable['ident'])) {
+ if (null !== eval($variable['json'])) {
+ $value = eval($variable['json']);
+ if (isset($value)) {
+ if (isset($variable['valueCorrection'])) {
+ eval($variable['valueCorrection']);
+ }
+
+ if ($value != GetValue($this->GetIDForIdent($variable['ident']))) {
+ $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("updated to ").$value, 0);
+ SetValue($this->GetIDForIdent($variable['ident']), $value);
+ } else {
+ $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("no update received")." (".$value.")", 0);
+ }
}
+ } else {
+ $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("No data"), 0);
}
- } else {
- $this->SendDebug($this->Translate($variable['localeName']), $this->Translate("No data"), 0);
}
}
}
}
}
- }
}
}
}
diff --git a/UniFi Presence Manager/README.md b/UniFi Presence Manager/README.md
index 95b7b8b..bd6bc7a 100644
--- a/UniFi Presence Manager/README.md
+++ b/UniFi Presence Manager/README.md
@@ -1,7 +1,7 @@
# UniFi Presence Manager
Dieses Modul ermöglicht es Geräte im Netz zu überwachen, um z.B. eine Anwsenheitskontrolle zu ermöglichen.
-### Inhaltsverzeichnis
+## Inhaltsverzeichnis
1. [Funktionsumfang](#1-funktionsumfang)
2. [Voraussetzungen](#2-voraussetzungen)
@@ -9,24 +9,24 @@ Dieses Modul ermöglicht es Geräte im Netz zu überwachen, um z.B. eine Anwsenh
4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon)
5. [Versionsinformation](#5-versionsinformation)
-### 1. Funktionsumfang
+## 1. Funktionsumfang
-* Unterstützung für UniFi Cloudkey 1
-* Unterstützung für UniFi Cloudkey 2 und Dream Maschine
+* Unterstützung für UniFi CloudKey 1 (UC-CK)
+* Unterstützung für UniFi CloudKey 2 (UCK-G2) und DreamMachine (UDM)
* Anlegen von zu überwachenden Geräten mit Name und MAC Adresse
* Erstellt pro Gerät eine Variable welche z.B. für die Automation oder Überwachung genutzt werden kann (Boolean)
* Abfragen der Controller erfolgt zeitgesteuert alle xx Sekunden
-### 2. Vorraussetzungen
+## 2. Voraussetzungen
- IP-Symcon ab Version 5.5
-### 3. Software-Installation
+## 3. Software-Installation
* Über den Module Store das 'UniFi Presence Manager'-Modul installieren.
* Alternativ über das Module Control folgende URL hinzufügen
-### 4. Einrichten der Instanzen in IP-Symcon
+## 4. Einrichten der Instanzen in IP-Symcon
Unter 'Instanz hinzufügen' kann das 'UniFi Presence Manager'-Modul mithilfe des Schnellfilters gefunden werden.
- Weitere Informationen zum Hinzufügen von Instanzen in der [Dokumentation der Instanzen](https://www.symcon.de/service/dokumentation/konzepte/instanzen/#Instanz_hinzufügen)
@@ -35,7 +35,7 @@ __Konfigurationsseite__:
**Art des Controllers**
-Da sich die APIs von CloudKey 1 und CloudKey2/Dreammaschine unterscheiden, kann hier der Controller gewählt werden
+Da sich die APIs von CloudKey 1 und CloudKey2/DreamMachine unterscheiden, kann hier der Controller gewählt werden
**Benutzername & Kennwort**
@@ -45,9 +45,9 @@ Account mit dem sich das Modul mit dem Controller verbindet
Site die im Controller hinterlegt ist
-**IP Adresse und Port**
+**IP-Adresse und Port**
-Bei der Dream Maschine ist der Port 443, bei einem Controller im Standard 8443. IP Addresse des CloudKeys oder der Dream Maschine.
+Bei der DreamMachine ist der Port 443, bei einem Controller im Standard 8443. IP-Adresse des CloudKeys oder der DreamMachine.
**Aktualisierungsfrequenz**
@@ -63,12 +63,14 @@ Geräte die Überwacht werden sollen, werden einfach mit einem Namen und einer M
Das Modul selbst löscht keine Variablen, sollte sich ein Name ändern, dann wird eine neue erstellt und die alte im Objektbaum belassen.
**Debugging**
-Das Modul gibt diverse Informatioen im Debug Bereich aus.
+
+Das Modul gibt diverse Informationen im Debug Bereich aus.
+
## 5. Versionsinformation
Version 0.3 (Beta) - 23-08-2021
-* Unterstützung für UniFi Cloudkey 1
-* Unterstützung für UniFi Cloudkey 2 und Dream Maschine
+* Unterstützung für UniFi CloudKey 1
+* Unterstützung für UniFi CloudKey 2 und DreamMachine
* Anlegen von zu überwachenden Geräten mit Name und MAC Adresse
* Erstellt pro Gerät eine Variable welche z.B. für die Automation oder Überwachung genutzt werden kann (Boolean)
* Abfragen der Controller erfolgt zeitgesteuert alle xx Sekunden
diff --git a/UniFi Presence Manager/form.json b/UniFi Presence Manager/form.json
index 2961239..fa59891 100644
--- a/UniFi Presence Manager/form.json
+++ b/UniFi Presence Manager/form.json
@@ -10,11 +10,11 @@
},
{
"type": "Label",
- "label": "Please select the type of controller you are using, enter its IP Adress, Port and a user allowed to log in."
+ "label": "Please select the type of controller you are using, enter its IP Address, Port and a user allowed to log in."
},
{
"type": "Label",
- "label": "To manage certain devices, please use their MAC adress and a clear text name, which will be used to create a variable in the object tree."
+ "label": "To manage certain devices, please use their MAC address and a clear text name, which will be used to create a variable in the object tree."
},
{
"type": "Label",
@@ -40,7 +40,7 @@
"caption": "Controller Type",
"options": [
{
- "caption": "Dream Maschine / Pro / CloudKey V2",
+ "caption": "DreamMachine / Pro / CloudKey V2",
"value": 0
},
{
@@ -56,13 +56,17 @@
},
{
"type": "ValidationTextBox",
- "name": "ServerAdress",
- "caption": "Server Address"
+ "name": "ServerAddress",
+ "caption": "Server Address",
+ "validate": "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
},
{
"type": "NumberSpinner",
"name": "ServerPort",
- "caption": "Server Port"
+ "caption": "Server Port",
+ "digits": 0,
+ "minimum": 1,
+ "maximum": 65535
},
{
"type": "ValidationTextBox",
@@ -78,7 +82,9 @@
"type": "NumberSpinner",
"name": "Timer",
"caption": "Update Frequency",
- "suffix": "sec - 0 is off"
+ "suffix": "sec - 0 is off",
+ "digits": 0,
+ "minimum": 0
},
{
"type": "Label",
@@ -130,7 +136,7 @@
{
"type": "Button",
"label": "Test Authentication",
- "onClick": "PM_AuthenticateAndGetData($id);"
+ "onClick": "PM_AuthenticateAndGetData($id, '');"
},
{
"type": "Button",
@@ -139,6 +145,5 @@
}
]
}
- ],
- "status": []
-}
\ No newline at end of file
+ ]
+}
diff --git a/UniFi Presence Manager/locale.json b/UniFi Presence Manager/locale.json
index a02cfae..2cf834b 100644
--- a/UniFi Presence Manager/locale.json
+++ b/UniFi Presence Manager/locale.json
@@ -3,12 +3,14 @@
"de": {
"Module Help": "Modul Hilfe",
"This Module allows to identify if a certain device is connected to the network to e.g. provide for presence management.": "Dieses Modul ermöglicht es Geräte im Netz zu überwachen, um z.B. eine Anwsenheitskontrolle zu ermöglichen.",
- "Please select the type of controller you are using, enter its IP Adress, Port and a user allowed to log in.": "Bitte wählen sie die Art des Controllers und geben die IP Adresse, Port und einen Anwender ein der auf diesen zugreifen darf.",
- "To manage certain devices, please use their MAC adress and a clear text name, which will be used to create a variable in the object tree.": "Um Geräte zu verwalten, geben sie bitte die MAC Addresse und einen Namen in der Form unten ein - anhand des Namens wird eine Boolean Variable im Objektbaum erstellt.",
+ "Please select the type of controller you are using, enter its IP Address, Port and a user allowed to log in.": "Bitte wählen sie die Art des Controllers und geben die IP Adresse, Port und einen Anwender ein der auf diesen zugreifen darf.",
+ "To manage certain devices, please use their MAC address and a clear text name, which will be used to create a variable in the object tree.": "Um Geräte zu verwalten, geben sie bitte die MAC Addresse und einen Namen in der Form unten ein - anhand des Namens wird eine Boolean Variable im Objektbaum erstellt.",
"The variable in the Object Tree can be used to see if a device is online or offline e.g. a mobile app, webfront or other automation.": "Die Variable im Objektbaum kann dann im Webfront, der Mobile-App oder einer Automation genutzt werden wenn Geräte Online oder Offline sind",
"Updates will happen on a schedule every xyz seconds.": "Das Module prüft die Anwensenheit alle xyz Sekunden, wie im Module konfiguriert",
"For debugging, please use the Debug function of the module.": "Für das Prüfen der Funktionen, gibt es Modul Meldungen im Debugbereich aus",
"UniFi Toolbox - Presence Manager Configuration": "UniFi Toolbox - Anwesenheits Manager Konfiguration",
+ "400 Bad Request - The server cannot or will not process the request due to an apparent client error.": "400 Bad Request - Die Anfrage wird vom Controller nicht verarbeitet (falsche IP?) - Client Fehler.",
+ "401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?": "401 Unauthorized / 403 Forbidden - Die Anfrage ging an den richtigen Server, allerdings konnte sich Symcon nicht anmelden. Bitte Login Daten prüfen.",
"Controller Type": "Art des Controllers",
"Server Address": "Server Adresse",
"User Name": "Anmeldename",
@@ -16,8 +18,6 @@
"Update Frequency": "Aktualisierungsfrequenz",
"sec - 0 is off": "Sek - 0 ist Aus",
"The General Presence Updated variable will always be updated and can be used to trigger general updates independent of the sender.": "Die Allgemeine Anwesenheit Aktualisiert Variable wird immer unabhängig vom Gerät aktualisiert und kann somit eine generische Aktion auslösen.",
- "400 Bad Request - The server cannot or will not process the request due to an apparent client error.": "400 Bad Request - Die Anfrage wird vom Controller nicht verarbeitet (falsche IP?) - Client Fehler.",
- "401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?": "401 Unauthorized / 403 Forbidden - Die Anfrage ging an den richtigen Server, allerdings konnte sich Symcon nicht anmelden. Bitte Login Daten prüfen.",
"General Presence Updated": "Allgemeine Anwesenheit Aktualisiert",
"Devices": "Geräte",
"Devicename": "Gerätename",
diff --git a/UniFi Presence Manager/module.php b/UniFi Presence Manager/module.php
index fd78552..eeeac93 100644
--- a/UniFi Presence Manager/module.php
+++ b/UniFi Presence Manager/module.php
@@ -10,219 +10,240 @@
define('vtArray', 8);
define('vtObject', 9);
}
- class UniFiPresenceManager extends IPSModule
- {
- public function Create() {
- //Never delete this line!
- parent::Create();
- $this->RegisterPropertyInteger("ControllerType", 0);
- $this->RegisterPropertyString("ServerAdress","192.168.1.1");
- $this->RegisterPropertyInteger("ServerPort", "443");
- $this->RegisterPropertyString("Site","default");
- $this->RegisterPropertyString("UserName","");
- $this->RegisterPropertyString("Password","");
- $this->RegisterPropertyInteger("Timer", "0");
- $this->RegisterPropertyBoolean("GeneralPresenceUpdatedVariable","0");
+class UniFiPresenceManager extends IPSModule {
+ public function Create() {
+ //Never delete this line!
+ parent::Create();
- $this->RegisterPropertyString("Devices", "");
+ $this->RegisterPropertyInteger("ControllerType", 0);
+ $this->RegisterPropertyString("ServerAddress","192.168.1.1");
+ $this->RegisterPropertyInteger("ServerPort", "443");
+ $this->RegisterPropertyString("Site","default");
+ $this->RegisterPropertyString("UserName","");
+ $this->RegisterPropertyString("Password","");
+ $this->RegisterPropertyInteger("Timer", "0");
+ $this->RegisterPropertyBoolean("GeneralPresenceUpdatedVariable","0");
- $this->RegisterTimer("Check Presence",0,"PM_CheckPresence(\$_IPS['TARGET']);");
+ $this->RegisterPropertyString("Devices", "");
- }
+ $this->RegisterTimer("Check Presence",0,"PM_CheckPresence(\$_IPS['TARGET']);");
- public function Destroy() {
- //Never delete this line!
- parent::Destroy();
- }
+ }
- public function ApplyChanges() {
- //Never delete this line!
- parent::ApplyChanges();
+ public function Destroy() {
+ //Never delete this line!
+ parent::Destroy();
+ }
- $vpos = 100;
+ public function ApplyChanges() {
+ //Never delete this line!
+ parent::ApplyChanges();
- //Create Devices mentioned in configuration
- $DevicesList = $this->ReadPropertyString("Devices");
- $DevicesJSON = json_decode($DevicesList,true);
- //var_dump($DevicesJSON);
+ $vpos = 100;
- if (isset($DevicesJSON)) {
- foreach ($DevicesJSON as $Device) {
- $DeviceName = $Device["varDeviceName"];
- $DeviceMac = str_replace(array("-",":"," "), "", $Device["varDeviceMAC"]);
- $this->MaintainVariable($DeviceMac, $DeviceName, vtBoolean, "~Presence", $vpos++, isset($DevicesJSON));
- }
- }
+ //Create Devices mentioned in configuration
+ $DevicesList = $this->ReadPropertyString("Devices");
+ $DevicesJSON = json_decode($DevicesList,true);
+ //var_dump($DevicesJSON);
- $this->MaintainVariable("GeneralPresenceUpdatedVariable", $this->Translate("Presence Updated"), vtBoolean, "~Switch", 10, $this->ReadPropertyBoolean("GeneralPresenceUpdatedVariable") == 1);
+ if (isset($DevicesJSON)) {
+ foreach ($DevicesJSON as $Device) {
+ $DeviceName = $Device["varDeviceName"];
+ $DeviceMac = str_replace(array("-",":"," "), "", $Device["varDeviceMAC"]);
+ $this->MaintainVariable($DeviceMac, $DeviceName, vtBoolean, "~Presence", $vpos++, isset($DevicesJSON));
+ }
+ }
- $TimerMS = $this->ReadPropertyInteger("Timer") * 1000;
- $this->SetTimerInterval("Check Presence",$TimerMS);
+ $this->MaintainVariable("GeneralPresenceUpdatedVariable", $this->Translate("Presence Updated"), vtBoolean, "~Switch", 10, $this->ReadPropertyBoolean("GeneralPresenceUpdatedVariable") == 1);
- if (0 == $TimerMS) {
- // instance inactive
- $this->SetStatus(104);
- }
- else {
- // instance active
- $this->SetStatus(102);
- }
+ $TimerMS = $this->ReadPropertyInteger("Timer") * 1000;
+ $this->SetTimerInterval("Check Presence",$TimerMS);
+ if (0 == $TimerMS) {
+ // instance inactive
+ $this->SetStatus(104);
+ }
+ else {
+ // instance active
+ $this->SetStatus(102);
}
+ }
- public function AuthenticateAndGetData() {
-
- $ControllerType = $this->ReadPropertyInteger("ControllerType");
- $ServerAdress = $this->ReadPropertyString("ServerAdress");
- $ServerPort = $this->ReadPropertyInteger("ServerPort");
- $Username = $this->ReadPropertyString("UserName");
- $Password = $this->ReadPropertyString("Password");
- $Site = $this->ReadPropertyString("Site");
- ////////////////////////////////////////
- //Change the Unifi API to be called here
- $UnifiAPI = "api/s/".$Site."/stat/sta";
- ////////////////////////////////////////
+ public function AuthenticateAndGetData(string $UnifiAPI = "") {
+
+ $ControllerType = $this->ReadPropertyInteger("ControllerType");
+ $ServerAddress = $this->ReadPropertyString("ServerAddress");
+ $ServerPort = $this->ReadPropertyInteger("ServerPort");
+ $Username = $this->ReadPropertyString("UserName");
+ $Password = $this->ReadPropertyString("Password");
- //Generic Section providing for Authenthication against a Dream Maschine or Classic CloudKey
+ //Change the Unifi API to be called here
+ if ("" == $UnifiAPI) {
+ $Site = $this->ReadPropertyString("Site");
+ $UnifiAPI = "api/s/".$Site."/stat/sysinfo";
+ }
+ //Generic Section providing for Authenthication against a DreamMachine or Classic CloudKey
+ $ch = curl_init();
- $ch = curl_init();
+ if(!isset($ControllerType) || $ControllerType == 0) {
+ $SuffixURL = "/api/auth/login";
+ curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$Username."&password=".$Password);
+ }
+ elseif ($ControllerType == 1) {
+ $SuffixURL = "/api/login";
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['username' => $Username, 'password' => $Password]));
+ }
+ curl_setopt($ch, CURLOPT_POST, TRUE);
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$SuffixURL);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
+ curl_setopt($ch, CURLOPT_HEADER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ $data = curl_exec($ch);
+
+ if(false === $data)
+ {
+ $this->SendDebug($this->Translate("Authentication"), $this->Translate('Error: Not reachable / No response!'),0);
+
+ // IP or Port not reachable / no response
+ $this->SetStatus(200);
+
+ return false;
+ }
- if ($ControllerType == 0) {
- $SuffixURL = "/api/auth/login";
- curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$Username."&password=".$Password);
- }
- elseif ($ControllerType == 1) {
- $SuffixURL = "/api/login";
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['username' => $Username, 'password' => $Password]));
- }
- curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$SuffixURL);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $data = curl_exec($ch);
-
- $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
- $body = trim(substr($data, $header_size));
- $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$code,0);
- preg_match_all('|(?i)Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
- if (isset($results[1])) {
- $Cookie = implode(';', $results[1]);
- if (!empty($body)) {
- if ($code == 200) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
- }
- else if ($code == 400) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
- echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
- return false;
- }
- else if ($code == 401 || $code == 403) {
- $this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
- echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
- return false;
- }
- }
- }
+ $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
+ $body = trim(substr($data, $header_size));
+ $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- // Section below will collect and store it into a buffer
-
- if (isset($Cookie)) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Return-Code Provided is: ').$code,0);
+ //$this->SendDebug($this->Translate("Debug"), $data,0);
- $ch = curl_init();
- if ($ControllerType == 0) {
- $MiddlePartURL = "/proxy/network/";
+ preg_match_all('|(?i)Set-Cookie: (.*);|U', substr($data, 0, $header_size), $results);
+ if (isset($results[1])) {
+ $Cookie = implode(';', $results[1]);
+ if (!empty($body)) {
+ if (200 == $code) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Login Successful'),0);
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('Cookie Provided is: ').$Cookie,0);
}
- elseif ($ControllerType == 1) {
- $MiddlePartURL = "/";
- }
- curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$MiddlePartURL.$UnifiAPI);
- curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
- curl_setopt($ch , CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("cookie: ".$Cookie));
- curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1');
-
- $RawData = curl_exec($ch);
- curl_close($ch);
- //$JSON = json_decode($RawData,true);
- //$this->SetBuffer("$RawData",$RawData);
-
- if (isset($RawData) AND $RawData != "Unauthorized") {
- $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Successfully Called"),0);
- $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Data Provided: ").$RawData,0);
- $this->SetBuffer("RawData",$RawData);
+ else if (400 == $code) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ echo $this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.');
+ return false;
}
- else {
- $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("API could not be called - check the login data. Do you see a Cookie?"),0);
+ else if (401 == $code || 403 == $code) {
+ $this->SendDebug($this->Translate("Authentication"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ echo $this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?');
+ return false;
}
}
-
- return true;
}
- public function CheckPresence() {
+ // Section below will collect and store it into a buffer
+
+ if (isset($Cookie)) {
- $this->AuthenticateAndGetData();
- $RawData = $this->GetBuffer("RawData");
+ $ch = curl_init();
+ if (!isset($ControllerType) || $ControllerType == 0) {
+ $MiddlePartURL = "/proxy/network/";
+ }
+ elseif ($ControllerType == 1) {
+ $MiddlePartURL = "/";
+ }
+ curl_setopt($ch, CURLOPT_URL, "https://".$ServerAddress.":".$ServerPort.$MiddlePartURL.$UnifiAPI);
+ curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
+ curl_setopt($ch , CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array("cookie: ".$Cookie));
+ curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1');
+
+ //$this->SendDebug("Debug: ", "https://".$ServerAddress.":".$ServerPort.$MiddlePartURL.$UnifiAPI, 0);
+
+ $RawData = curl_exec($ch);
+ curl_close($ch);
+ //$JSON = json_decode($RawData,true);
+ //$this->SetBuffer("RawData",$RawData);
- if ($RawData !== "") {
- $JSONData = json_decode($RawData,true);
- $ActiveDevices = $JSONData;
-
- //Load devices from config form
- $DevicesList = $this->ReadPropertyString("Devices");
- $DevicesJSON = json_decode($DevicesList,true);
-
- foreach ($DevicesJSON as $Device) {
- //Build a clean array out of the devices mentioned in the config form with : or -
- $DeviceMac = str_replace(array("-",":"," "), "", strtolower($Device["varDeviceMAC"]));
-
- //Itterate through all device and check if one of them matches the list in the config form.
- foreach ($ActiveDevices["data"] as $Index=>$Device) {
- $DeviceMacClean = strtolower(str_replace(array("-",":"), "", strtolower($Device["mac"])));
-
- $OldPresenceValue = GetValue($this->GetIDForIdent($DeviceMac));
- if ($DeviceMac == $DeviceMacClean) {
- if ($OldPresenceValue == 0) { //check if new value is different and only than trigger a replacement
- SetValue($this->GetIDForIdent($DeviceMac),1);
- if ($this->ReadPropertyBoolean("GeneralPresenceUpdatedVariable") == 1) {
- SetValue($this->GetIDForIdent("GeneralPresenceUpdatedVariable"),1);
- }
- $this->SendDebug($this->Translate("Presence Manager"),$this->Translate("Device ACTIVE with MAC: ".$DeviceMac),0);
- }
- break;
- }
- else {
- if ($Index === array_key_last($ActiveDevices["data"])) {
- if ($OldPresenceValue == 1) {
- SetValue($this->GetIDForIdent($DeviceMac),0);
- if ($this->ReadPropertyBoolean("GeneralPresenceUpdatedVariable") == 1) {
- SetValue($this->GetIDForIdent("GeneralPresenceUpdatedVariable"),1);
- }
- $this->SendDebug($this->Translate("Presence Manager"),$this->Translate("Device NOT active with MAC: ".$DeviceMac),0);
- }
- }
-
- }
-
- }
- }
+ if (isset($RawData) && 400 == $RawData) {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate('400 Bad Request - The server cannot or will not process the request due to an apparent client error.'),0);
+ $this->SetStatus(201); // login seems to be not successful
+ return false;
+ }
+ else if (isset($RawData) && (401 == $RawData || 403 == $RawData || $RawData == "Unauthorized")) {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate('401 Unauthorized / 403 Forbidden - The request contained valid data and was understood by the server, but the server is refusing action. Missing user permission?'),0);
+ $this->SetStatus(201); // login seems to be not successful
+ return false;
+ }
+ else if (isset($RawData)) {
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Successfully Called"),0);
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("Data Provided: ").$RawData,0);
+ $this->SetBuffer("RawData",$RawData);
}
else {
- $this->SendDebug($this->Translate("Presence Manager"),$this->Translate("There does not seem to be any configuration - no data is available from the UniFi"),0);
- }
-
+ $this->SendDebug($this->Translate("UniFi API Call"),$this->Translate("API could not be called - check the login data. Do you see a Cookie?"),0);
+ $this->SetStatus(201); // login seems to be not successful
+ return false;
+ }
}
+ return true;
+ }
+
+ public function CheckPresence() {
+ $Site = $this->ReadPropertyString("Site");
+
+ if ($this->AuthenticateAndGetData("api/s/".$Site."/stat/sta")) {
+ $RawData = $this->GetBuffer("RawData");
+
+ if ($RawData !== "") {
+ $JSONData = json_decode($RawData, true);
+ $ActiveDevices = $JSONData;
+
+ //Load devices from config form
+ $DevicesList = $this->ReadPropertyString("Devices");
+ $DevicesJSON = json_decode($DevicesList, true);
+
+ foreach ($DevicesJSON as $Device) {
+ //Build a clean array out of the devices mentioned in the config form with : or -
+ $DeviceMac = str_replace(array("-",":"," "), "", strtolower($Device["varDeviceMAC"]));
+
+ //Itterate through all device and check if one of them matches the list in the config form.
+ foreach ($ActiveDevices["data"] as $Index=>$Device) {
+ $DeviceMacClean = strtolower(str_replace(array("-",":"), "", strtolower($Device["mac"])));
+
+ $OldPresenceValue = GetValue($this->GetIDForIdent($DeviceMac));
+ if ($DeviceMac == $DeviceMacClean) {
+ if ($OldPresenceValue == 0) { //check if new value is different and only than trigger a replacement
+ SetValue($this->GetIDForIdent($DeviceMac), 1);
+ if ($this->ReadPropertyBoolean("GeneralPresenceUpdatedVariable") == 1) {
+ SetValue($this->GetIDForIdent("GeneralPresenceUpdatedVariable"), 1);
+ }
+ $this->SendDebug($this->Translate("Presence Manager"), $this->Translate("Device ACTIVE with MAC: ".$DeviceMac), 0);
+ }
+ break;
+ } else {
+ if ($Index === array_key_last($ActiveDevices["data"])) {
+ if ($OldPresenceValue == 1) {
+ SetValue($this->GetIDForIdent($DeviceMac), 0);
+ if ($this->ReadPropertyBoolean("GeneralPresenceUpdatedVariable") == 1) {
+ SetValue($this->GetIDForIdent("GeneralPresenceUpdatedVariable"), 1);
+ }
+ $this->SendDebug($this->Translate("Presence Manager"), $this->Translate("Device NOT active with MAC: ".$DeviceMac), 0);
+ }
+ }
+ }
+ }
+ }
+ } else {
+ $this->SendDebug($this->Translate("Presence Manager"), $this->Translate("There does not seem to be any configuration - no data is available from the UniFi"), 0);
+ }
+ }
}
+
+}
From 0665dd47aa91f102c8b8359165e2ce54ee985057 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Fri, 31 Dec 2021 10:16:02 +0100
Subject: [PATCH 69/71] #23 code cleanup
#23
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index fbc399c..9f8f993 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Die UniFi Toolbox ist eine Sammlung von Modulen, welche verschiedene Aktionen in
## Voraussetzungen:
* Symcon 5.5 oder höher
-* UniFi Dream Machine
+* UniFi DreamMachine
* UniFi Controller
## Installation:
@@ -18,7 +18,7 @@ Folgende Module beinhaltet das UniFi Toolbox Repository:
Mit dem Presence oder Anwesenheitsmanager ist es möglich Geräte die mit dem Netzwerk verbunden sind zu überwachen, z.B. um die Anwesenheit zu bestimmen.
- __UniFi Internet Controller__ ([Dokumentation](UniFi%20Internet%20Controller))
- Der Internet Controller ermöglich die Erfassung von Informationen zur Internetverbindung, wenn eine USG oder Dream Machine eingesetzt wird.
+ Der Internet Controller ermöglich die Erfassung von Informationen zur Internetverbindung, wenn eine USG oder DreamMachine eingesetzt wird.
- __UniFi Device Blocker__ ([Dokumentation](UniFi%20Device%20Blocker))
Mit dem Device Blocker können Geräte anhand ihrer MAC Adresse vom Zugang auf das Netzwerk geblockt werden, z.B. um die Nutzung von Geräten im Kinderzimmer nach 20 Uhr zu sperren und am Morgen wieder zu aktivieren.
From 586f6a4c8d7ba5c8030b671a0a25a771177a84de Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Fri, 31 Dec 2021 10:34:13 +0100
Subject: [PATCH 70/71] #23 cleanup
#23
---
UniFi Device Blocker/form.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/UniFi Device Blocker/form.json b/UniFi Device Blocker/form.json
index 20a3991..6537ed9 100644
--- a/UniFi Device Blocker/form.json
+++ b/UniFi Device Blocker/form.json
@@ -124,7 +124,7 @@
{
"type": "Button",
"label": "Test Authentication and Blocking",
- "onClick": "DB_AuthenticateAndProcessRequest($id);"
+ "onClick": "DB_AuthenticateAndProcessRequest($id, '');"
}
]
}
From 14fc21bf7558fc1bac19c7ae8ac7a32864d1fb32 Mon Sep 17 00:00:00 2001
From: Brovning <39644775+Brovning@users.noreply.github.com>
Date: Fri, 31 Dec 2021 10:43:47 +0100
Subject: [PATCH 71/71] Schreibweise vereinheitlicht
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index fbc399c..9f8f993 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Die UniFi Toolbox ist eine Sammlung von Modulen, welche verschiedene Aktionen in
## Voraussetzungen:
* Symcon 5.5 oder höher
-* UniFi Dream Machine
+* UniFi DreamMachine
* UniFi Controller
## Installation:
@@ -18,7 +18,7 @@ Folgende Module beinhaltet das UniFi Toolbox Repository:
Mit dem Presence oder Anwesenheitsmanager ist es möglich Geräte die mit dem Netzwerk verbunden sind zu überwachen, z.B. um die Anwesenheit zu bestimmen.
- __UniFi Internet Controller__ ([Dokumentation](UniFi%20Internet%20Controller))
- Der Internet Controller ermöglich die Erfassung von Informationen zur Internetverbindung, wenn eine USG oder Dream Machine eingesetzt wird.
+ Der Internet Controller ermöglich die Erfassung von Informationen zur Internetverbindung, wenn eine USG oder DreamMachine eingesetzt wird.
- __UniFi Device Blocker__ ([Dokumentation](UniFi%20Device%20Blocker))
Mit dem Device Blocker können Geräte anhand ihrer MAC Adresse vom Zugang auf das Netzwerk geblockt werden, z.B. um die Nutzung von Geräten im Kinderzimmer nach 20 Uhr zu sperren und am Morgen wieder zu aktivieren.