diff --git a/UniFi Internet Controller/form.json b/UniFi Internet Controller/form.json index 4c0b333..f2705b5 100644 --- a/UniFi Internet Controller/form.json +++ b/UniFi Internet Controller/form.json @@ -6,7 +6,7 @@ "items": [ { "type": "Label", - "label": "This Module allows to gather information converning the internet connection like the current public IP adress in conjunction with a USG or Dream Machine." + "label": "This Module allows to gather information converning the internet connection like the current public IP adress in conjunction with a Dream Machine." }, { "type": "Label", @@ -28,22 +28,7 @@ }, { "type": "Label", - "label": "UniFi Toolbox - Internet Controller Configuration" - }, - { - "type": "Select", - "name": "ControllerType", - "caption": "Controller Type", - "options": [ - { - "caption": "Dream Maschine / Pro / CloudKey V2", - "value": 0 - }, - { - "caption": "CloudKey", - "value": 1 - } - ] + "label": "UniFi Toolbox - Dream Maschine Internet Controller Configuration" }, { "type": "ValidationTextBox", @@ -76,89 +61,111 @@ "caption": "Update Frequency", "suffix": "sec - 0 is off" }, - { - "type": "CheckBox", - "name": "WAN1IP", - "caption": "WAN1 External IP Address" - }, - { - "type": "CheckBox", - "name": "WAN2IP", - "caption": "WAN2 External IP Address" - }, - { - "type": "CheckBox", - "name": "version", - "caption": "Unifi Network Version" - }, - { - "type": "CheckBox", - "name": "update_available", - "caption": "Update available" - }, - { - "type": "CheckBox", - "name": "update_downloaded", - "caption": "Update downloaded" - }, - { - "type": "CheckBox", - "name": "uptime", - "caption": "Uptime" - }, { "type": "Label", - "label": "Nachfolgende Werte sind nur mit DreamMachine verfügbar:" - }, - { - "type": "CheckBox", - "name": "WAN1availability", - "caption": "WAN1 availability" + "label": "" }, - { - "type": "CheckBox", - "name": "WAN1latency_average", - "caption": "WAN1 latency-average" - }, - { - "type": "CheckBox", - "name": "WAN1time_period", - "caption": "WAN1 time-period" - }, - { - "type": "CheckBox", - "name": "WAN2availability", - "caption": "WAN2 availability" + { + "type": "RowLayout", + "items": [ + { + "type": "CheckBox", + "name": "WAN1IP", + "caption": "WAN1 External IP Address" + },{ + "type": "CheckBox", + "name": "WAN1availability", + "caption": "WAN1 availability" + },{ + "type": "CheckBox", + "name": "WAN1latency_average", + "caption": "WAN1 latency-average" + }, + { + "type": "CheckBox", + "name": "WAN1time_period", + "caption": "WAN1 time-period" + } + ] }, { - "type": "CheckBox", - "name": "WAN2latency_average", - "caption": "WAN2 latency-average" + "type": "Label", + "label": "" }, - { - "type": "CheckBox", - "name": "WAN2time_period", - "caption": "WAN2 time-period" + { + "type": "RowLayout", + "items": [ + { + "type": "CheckBox", + "name": "WAN2IP", + "caption": "WAN2 External IP Address" + },{ + "type": "CheckBox", + "name": "WAN2availability", + "caption": "WAN2 availability" + },{ + "type": "CheckBox", + "name": "WAN2latency_average", + "caption": "WAN2 latency-average" + }, + { + "type": "CheckBox", + "name": "WAN2time_period", + "caption": "WAN2 time-period" + } + ] }, { - "type": "CheckBox", - "name": "isp_name", - "caption": "ISP Name" + "type": "Label", + "label": "" }, - { - "type": "CheckBox", - "name": "isp_organization", - "caption": "ISP Organization" + { + "type": "RowLayout", + "items": [ + { + "type": "CheckBox", + "name": "version", + "caption": "Unifi Network Version" + },{ + "type": "CheckBox", + "name": "update_available", + "caption": "Update available" + },{ + "type": "CheckBox", + "name": "update_downloaded", + "caption": "Update downloaded" + },{ + "type": "CheckBox", + "name": "uptime", + "caption": "Uptime" + } + ] }, { - "type": "CheckBox", - "name": "ubnt_device_type", - "caption": "UBNT Device Type" + "type": "Label", + "label": "" }, - { - "type": "CheckBox", - "name": "udm_version", - "caption": "UDM Version" + { + "type": "RowLayout", + "items": [ + { + "type": "CheckBox", + "name": "isp_name", + "caption": "ISP Name" + },{ + "type": "CheckBox", + "name": "isp_organization", + "caption": "ISP Organization" + },{ + "type": "CheckBox", + "name": "ubnt_device_type", + "caption": "UBNT Device Type" + },{ + "type": "CheckBox", + "name": "udm_version", + "caption": "UDM Version" + } + ] } ], "actions": [ diff --git a/UniFi Internet Controller/module.json b/UniFi Internet Controller/module.json index fe88979..04f2f12 100644 --- a/UniFi Internet Controller/module.json +++ b/UniFi Internet Controller/module.json @@ -1,6 +1,6 @@ { "id": "{D1D2F76B-AAA2-A2F8-82CD-0A482654FA49}", - "name": "UniFi Internet Controller", + "name": "UniFi DM Internet Controller", "type": 3, "vendor": "UniFi", "aliases": [], diff --git a/UniFi Internet Controller/module.php b/UniFi Internet Controller/module.php index 9eba797..d641498 100644 --- a/UniFi Internet Controller/module.php +++ b/UniFi Internet Controller/module.php @@ -10,13 +10,13 @@ define('vtArray', 8); define('vtObject', 9); } -class UniFiInternetController extends IPSModule -{ +class UniFiDMInternetController extends IPSModule { + public function Create() { //Never delete this line! parent::Create(); - $this->RegisterPropertyInteger("ControllerType", 0); + //$this->RegisterPropertyInteger("ControllerType", 0); $this->RegisterPropertyString("ServerAdress","192.168.1.1"); $this->RegisterPropertyInteger("ServerPort", "443"); $this->RegisterPropertyString("Site","default"); @@ -75,26 +75,22 @@ public function ApplyChanges() { $vpos = 100; $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") && 0 == $this->ReadPropertyInteger("ControllerType")); - $this->MaintainVariable("WAN1latency_average", $this->Translate("WAN1 latency-average"), vtInteger, "IC.TimeMS", $vpos++, $this->ReadPropertyBoolean("WAN1latency_average") && 0 == $this->ReadPropertyInteger("ControllerType")); - $this->MaintainVariable("WAN1time_period", $this->Translate("WAN1 time-period"), vtInteger, "IC.TimeS", $vpos++, $this->ReadPropertyBoolean("WAN1time_period") && 0 == $this->ReadPropertyInteger("ControllerType")); - + $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")); + $this->MaintainVariable("WAN1time_period", $this->Translate("WAN1 time-period"), vtInteger, "IC.TimeS", $vpos++, $this->ReadPropertyBoolean("WAN1time_period")); $this->MaintainVariable("WAN2IP", $this->Translate("WAN2 External IP Address"), vtString, "", $vpos++, $this->ReadPropertyBoolean("WAN2IP")); - - $this->MaintainVariable("WAN2availability", $this->Translate("WAN2 availability"), vtInteger, "~Intensity.100", $vpos++, $this->ReadPropertyBoolean("WAN2availability") && 0 == $this->ReadPropertyInteger("ControllerType")); - $this->MaintainVariable("WAN2latency_average", $this->Translate("WAN2 latency-average"), vtInteger, "IC.TimeMS", $vpos++, $this->ReadPropertyBoolean("WAN2latency_average") && 0 == $this->ReadPropertyInteger("ControllerType")); - $this->MaintainVariable("WAN2time_period", $this->Translate("WAN2 time-period"), vtInteger, "IC.TimeS", $vpos++, $this->ReadPropertyBoolean("WAN2time_period") && 0 == $this->ReadPropertyInteger("ControllerType")); - - $this->MaintainVariable("isp_name", $this->Translate("ISP Name"), vtString, "", $vpos++, $this->ReadPropertyBoolean("isp_name") && 0 == $this->ReadPropertyInteger("ControllerType")); - $this->MaintainVariable("isp_organization", $this->Translate("ISP Organization"), vtString, "", $vpos++, $this->ReadPropertyBoolean("isp_organization") && 0 == $this->ReadPropertyInteger("ControllerType")); + $this->MaintainVariable("WAN2availability", $this->Translate("WAN2 availability"), vtInteger, "~Intensity.100", $vpos++, $this->ReadPropertyBoolean("WAN2availability")); + $this->MaintainVariable("WAN2latency_average", $this->Translate("WAN2 latency-average"), vtInteger, "IC.TimeMS", $vpos++, $this->ReadPropertyBoolean("WAN2latency_average")); + $this->MaintainVariable("WAN2time_period", $this->Translate("WAN2 time-period"), vtInteger, "IC.TimeS", $vpos++, $this->ReadPropertyBoolean("WAN2time_period")); + $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("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") && 0 == $this->ReadPropertyInteger("ControllerType")); - $this->MaintainVariable("udm_version", $this->Translate("UDM Version"), vtString, "", $vpos++, $this->ReadPropertyBoolean("udm_version") && 0 == $this->ReadPropertyInteger("ControllerType")); + $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")); $TimerMS = $this->ReadPropertyInteger("Timer") * 1000; $this->SetTimerInterval("Collect Connection Data",$TimerMS); @@ -113,7 +109,7 @@ public function ApplyChanges() { public function AuthenticateAndGetData($UnifiAPI = "") { - $ControllerType = $this->ReadPropertyInteger("ControllerType"); + //$ControllerType = $this->ReadPropertyInteger("ControllerType"); $ServerAdress = $this->ReadPropertyString("ServerAdress"); $ServerPort = $this->ReadPropertyInteger("ServerPort"); $Username = $this->ReadPropertyString("UserName"); @@ -131,15 +127,8 @@ public function AuthenticateAndGetData($UnifiAPI = "") { //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])); - } + $SuffixURL = "/api/auth/login"; + curl_setopt($ch, CURLOPT_POSTFIELDS, "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); @@ -184,12 +173,8 @@ public function AuthenticateAndGetData($UnifiAPI = "") { if (isset($Cookie)) { $ch = curl_init(); - if ($ControllerType == 0) { - $MiddlePartURL = "/proxy/network/"; - } - elseif ($ControllerType == 1) { - $MiddlePartURL = "/"; - } + + $MiddlePartURL = "/proxy/network/"; curl_setopt($ch, CURLOPT_URL, "https://".$ServerAdress.":".$ServerPort.$MiddlePartURL.$UnifiAPI); curl_setopt($ch, CURLOPT_HTTPGET, TRUE); curl_setopt($ch , CURLOPT_RETURNTRANSFER, true); @@ -210,9 +195,7 @@ 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); - - // login seems to be not successful - $this->SetStatus(201); + $this->SetStatus(201); // login seems to be not successful } } @@ -227,9 +210,7 @@ public function GetInternetData() { || $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 $this->AuthenticateAndGetData(); $RawData = $this->GetBuffer("RawData"); @@ -244,8 +225,6 @@ public function GetInternetData() { foreach ($variableArray as $variable) { if ($this->ReadPropertyBoolean($variable['ident'])) { -// $this->SendDebug("GetInternetData", print_r($JSONData), 0); - if (isset($JSONData['data'][0]["ip_addrs"][$variable['index']])) { $value = $JSONData['data'][0]["ip_addrs"][$variable['index']]; if (isset($value)) { @@ -265,17 +244,14 @@ public function GetInternetData() { // get everything else (besides IP addresses) $variableArray = array( - array('ident' => "version", 'localeName' => "Unifi Network Version"), - 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 - ); + array('ident' => "version", 'localeName' => "Unifi Network Version"), + 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 + ); - if($this->ReadPropertyInteger("ControllerType") == 0) - { - $variableArray[] = array('ident' => "ubnt_device_type", 'localeName' => "UBNT Device Type"); - $variableArray[] = array('ident' => "udm_version", 'localeName' => "UDM Version"); - } + $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'])) { @@ -300,40 +276,33 @@ public function GetInternetData() { } } - - // special properties of Unifi DreamMachine - if($this->ReadPropertyInteger("ControllerType") == 0 - && ($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("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"); { - // query JSON file for internet data + $Site = $this->ReadPropertyString("Site"); $this->AuthenticateAndGetData("api/stat/sites"); $RawData = $this->GetBuffer("RawData"); $JSONData = json_decode($RawData, true); -// $this->SendDebug("GetInternetData2", print_r($JSONData), 0); - - // get everything else + $healthArray = $JSONData['data'][0]['health']; $variableArray = array( - 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"), - array('ident' => "WAN2availability", 'json' => "return (isset(\$health['uptime_stats']['WAN2']['availability']) ? \$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"), - ); + 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"), + array('ident' => "WAN2availability", 'json' => "return (isset(\$health['uptime_stats']['WAN2']['availability']) ? \$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']) { @@ -361,7 +330,5 @@ public function GetInternetData() { } } } - } - } \ No newline at end of file