diff --git a/pom.xml b/pom.xml index 927d11e..88f10e2 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 4.5.0a + 4.5.0b jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/BridgeSecurity.java b/src/main/java/com/bwssystems/HABridge/BridgeSecurity.java index 08a4496..0f2c917 100644 --- a/src/main/java/com/bwssystems/HABridge/BridgeSecurity.java +++ b/src/main/java/com/bwssystems/HABridge/BridgeSecurity.java @@ -212,26 +212,26 @@ public class BridgeSecurity { Iterator userIterator = theUserIds.iterator(); while (userIterator.hasNext()) { validUser = userIterator.next(); - if (validUser.equals(aUser)) + if (validUser.equals(aUser)) { found = true; + log.debug("validateWhitelistUser: found a user <" + aUser + ">"); + } } } } if(!found && !strict) { + log.debug("validateWhitelistUser: a user was not found and it is not strict rules <" + aUser + "> being created"); newWhitelistUser(aUser, userDescription); found = true; } if (!found) { - return HueErrorResponse.createResponse("1", "/api/" + aUser, "unauthorized user", null, null, null).getTheErrors(); + log.debug("validateWhitelistUser: a user was not found and it is strict rules <" + aUser + ">"); + return HueErrorResponse.createResponse("1", "/api/" + aUser == null ? "" : aUser, "unauthorized user", null, null, null).getTheErrors(); } - Object anUser = securityDescriptor.getWhitelist().remove(DEPRACATED_INTERNAL_USER); - if(anUser != null) - setSettingsChanged(true); - return null; } diff --git a/src/main/java/com/bwssystems/HABridge/HABridge.java b/src/main/java/com/bwssystems/HABridge/HABridge.java index 8a0f9fb..087354e 100644 --- a/src/main/java/com/bwssystems/HABridge/HABridge.java +++ b/src/main/java/com/bwssystems/HABridge/HABridge.java @@ -49,6 +49,7 @@ public class HABridge { staticFileLocation("/public"); while(!bridgeSettings.getBridgeControl().isStop()) { bridgeSettings.buildSettings(); + bridgeSettings.getBridgeSecurity().removeTestUsers(); log.info("HA Bridge initializing...."); // sparkjava config directive to set ip address for the web server to listen on ipAddress(bridgeSettings.getBridgeSettingsDescriptor().getWebaddress()); diff --git a/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java b/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java index f715ef8..f6247c8 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java +++ b/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java @@ -2,6 +2,7 @@ package com.bwssystems.HABridge.hue; import java.math.BigDecimal; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import org.apache.commons.lang3.Conversion; @@ -83,7 +84,7 @@ public class BrightnessDecode { replaceTarget = INTENSITY_PERCENT_HEX; notDone = true; } else if (request.contains(INTENSITY_DECIMAL_PERCENT)) { - replaceValue = String.format("%1.2f", decimalBrightness); + replaceValue = String.format(Locale.ROOT, "%1.2f", decimalBrightness); replaceTarget = INTENSITY_DECIMAL_PERCENT; notDone = true; } else if (request.contains(INTENSITY_MATH_CLOSE)) { diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index a1dfc1c..09d29f8 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -69,6 +69,7 @@ public class HueMulator { public void setupServer() { log.info("Hue emulator service started...."); before(HUE_CONTEXT + "/*", (request, response) -> { + log.debug("HueMulator GET called on api/* with request <" + request.pathInfo() + ">"); if(bridgeSettingMaster.getBridgeSecurity().isSecure()) { String pathInfo = request.pathInfo(); if(pathInfo != null && pathInfo.contains(HUE_CONTEXT + "/devices")) { diff --git a/src/main/java/com/bwssystems/HABridge/plugins/hal/HalDevice.java b/src/main/java/com/bwssystems/HABridge/plugins/hal/HalDevice.java index 55714fd..2b38314 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/hal/HalDevice.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/hal/HalDevice.java @@ -5,6 +5,7 @@ public class HalDevice { private String haldevicename; private String haladdress; private String halname; + private Boolean secure; private DeviceElements buttons; public String getHaldevicetype() { return haldevicetype; @@ -30,6 +31,12 @@ public class HalDevice { public void setHalname(String halname) { this.halname = halname; } + public Boolean getSecure() { + return secure; + } + public void setSecure(Boolean secure) { + this.secure = secure; + } public DeviceElements getButtons() { return buttons; } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/hal/HalHome.java b/src/main/java/com/bwssystems/HABridge/plugins/hal/HalHome.java index 05f0c0a..234803b 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/hal/HalHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/hal/HalHome.java @@ -13,7 +13,6 @@ import com.bwssystems.HABridge.BridgeSettings; import com.bwssystems.HABridge.Home; import com.bwssystems.HABridge.NamedIP; import com.bwssystems.HABridge.api.CallItem; -import com.bwssystems.HABridge.api.NameValue; import com.bwssystems.HABridge.api.hue.HueError; import com.bwssystems.HABridge.api.hue.HueErrorResponse; import com.bwssystems.HABridge.dao.DeviceDescriptor; diff --git a/src/main/java/com/bwssystems/HABridge/plugins/hal/HalInfo.java b/src/main/java/com/bwssystems/HABridge/plugins/hal/HalInfo.java index 4da5514..89189ed 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/hal/HalInfo.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/hal/HalInfo.java @@ -8,8 +8,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.bwssystems.HABridge.NamedIP; -import com.bwssystems.HABridge.api.hue.HueError; -import com.bwssystems.HABridge.api.hue.HueErrorResponse; import com.bwssystems.HABridge.plugins.http.HTTPHandler; import com.bwssystems.HABridge.util.TextStringFormatter; import com.google.gson.Gson; @@ -100,7 +98,11 @@ public class HalInfo { String theUrl = null; String theData; - theUrl = "http://" + halAddress.getIp() + apiType + theToken; + if(halAddress.getSecure()) + theUrl = "https://"; + else + theUrl = "http://"; + theUrl = theUrl + halAddress.getIp() + apiType + theToken; theData = httpClient.doHttpRequest(theUrl, null, null, null, null); if(theData != null) { log.debug("GET " + deviceType + " HalApiResponse - data: " + theData); @@ -125,6 +127,7 @@ public class HalInfo { aNewHalDevice.setHaldevicename(theDevice.getDeviceName()); aNewHalDevice.setHaladdress(halAddress.getIp()); aNewHalDevice.setHalname(halAddress.getName()); + aNewHalDevice.setSecure(halAddress.getSecure()); deviceList.add(aNewHalDevice); } @@ -147,7 +150,11 @@ public class HalInfo { deviceList = new ArrayList(); while (theHalDevices.hasNext()) { HalDevice theHalDevice = theHalDevices.next(); - theUrl = "http://" + halAddress.getIp() + IRBUTTON_REQUEST + TextStringFormatter.forQuerySpaceUrl(theHalDevice.getHaldevicename()) + TOKEN_REQUEST + theToken; + if(halAddress.getSecure()) + theUrl = "https://"; + else + theUrl = "http://"; + theUrl = theUrl + halAddress.getIp() + IRBUTTON_REQUEST + TextStringFormatter.forQuerySpaceUrl(theHalDevice.getHaldevicename()) + TOKEN_REQUEST + theToken; theData = httpClient.doHttpRequest(theUrl, null, null, null, null); if (theData != null) { log.debug("GET IrData for IR Device " + theHalDevice.getHaldevicename() + " HalApiResponse - data: " + theData); diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index b6f387e..d4e9969 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -1317,14 +1317,15 @@ app.controller ('SystemController', function ($scope, $location, bridgeService, } } }; - $scope.addHaltoSettings = function (newhalname, newhalip) { + $scope.addHaltoSettings = function (newhalname, newhalip, newhasssecure) { if($scope.bridge.settings.haladdress === undefined || $scope.bridge.settings.haladdress === null) { $scope.bridge.settings.haladdress = { devices: [] }; } - var newhal = {name: newhalname, ip: newhalip } + var newhal = {name: newhalname, ip: newhalip, secure: newhasssecure} $scope.bridge.settings.haladdress.devices.push(newhal); $scope.newhalname = null; $scope.newhalip = null; + $scope.newhasssecure = false; }; $scope.removeHaltoSettings = function (halname, halip) { for(var i = $scope.bridge.settings.haladdress.devices.length - 1; i >= 0; i--) { @@ -2202,6 +2203,10 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi var preOffCmd = ""; var nameCmd = ""; var aDeviceType; + var httpType = "http://"; + if(haldevice.secure) + httpType = "https://"; + var postCmd = "?Token=" + $scope.bridge.settings.haltoken; if(haldevice.haldevicetype === "Group") { aDeviceType = "group"; @@ -2227,24 +2232,24 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi nameCmd = "!DeviceName="; } if((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) && aDeviceType === "switch") - dimpayload = "http://" + haldevice.haladdress + dimpayload = httpType + haldevice.haladdress + preDimCmd + dim_control + nameCmd + haldevice.haldevicename.replaceAll(" ", "%20") + postCmd; else - dimpayload = "http://" + haldevice.haladdress + dimpayload = httpType + haldevice.haladdress + preOnCmd + nameCmd + haldevice.haldevicename.replaceAll(" ", "%20") + postCmd; - onpayload = "http://" + haldevice.haladdress + onpayload = httpType + haldevice.haladdress + preOnCmd + nameCmd + haldevice.haldevicename.replaceAll(" ", "%20") + postCmd; - offpayload = "http://" + haldevice.haladdress + offpayload = httpType + haldevice.haladdress + preOffCmd + nameCmd + haldevice.haldevicename.replaceAll(" ", "%20") @@ -2260,8 +2265,11 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi $scope.buildButtonUrls = function (haldevice, onbutton, offbutton, buildonly) { var actionOn = angular.fromJson(onbutton); var actionOff = angular.fromJson(offbutton); - onpayload = "http://" + haldevice.haladdress + "/IrService!IrCmd=Set!IrDevice=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!IrButton=" + actionOn.DeviceName.replaceAll(" ", "%20") + "?Token=" + $scope.bridge.settings.haltoken; - offpayload = "http://" + haldevice.haladdress + "/IrService!IrCmd=Set!IrDevice=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!IrButton=" + actionOff.DeviceName.replaceAll(" ", "%20") + "?Token=" + $scope.bridge.settings.haltoken; + var httpType = "http://"; + if(haldevice.secure) + httpType = "https://"; + onpayload = httpType + haldevice.haladdress + "/IrService!IrCmd=Set!IrDevice=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!IrButton=" + actionOn.DeviceName.replaceAll(" ", "%20") + "?Token=" + $scope.bridge.settings.haltoken; + offpayload = httpType + haldevice.haladdress + "/IrService!IrCmd=Set!IrDevice=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!IrButton=" + actionOff.DeviceName.replaceAll(" ", "%20") + "?Token=" + $scope.bridge.settings.haltoken; bridgeService.buildUrls(onpayload, null, offpayload, false, haldevice.haldevicename + "-" + haldevice.halname + "-" + actionOn.DeviceName, haldevice.haldevicename, haldevice.halname, "button", "halButton", null, null); $scope.device = bridgeService.state.device; @@ -2272,8 +2280,11 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi }; $scope.buildHALHomeUrls = function (haldevice, buildonly) { - onpayload = "http://" + haldevice.haladdress + "/ModeService!ModeCmd=Set!ModeName=Home?Token=" + $scope.bridge.settings.haltoken; - offpayload = "http://" + haldevice.haladdress + "/ModeService!ModeCmd=Set!ModeName=Away?Token=" + $scope.bridge.settings.haltoken; + var httpType = "http://"; + if(haldevice.secure) + httpType = "https://"; + onpayload = httpType + haldevice.haladdress + "/ModeService!ModeCmd=Set!ModeName=Home?Token=" + $scope.bridge.settings.haltoken; + offpayload = httpType + haldevice.haladdress + "/ModeService!ModeCmd=Set!ModeName=Away?Token=" + $scope.bridge.settings.haltoken; bridgeService.buildUrls(onpayload, null, offpayload, false, haldevice.haldevicename + "-" + haldevice.halname + "-HomeAway", haldevice.haldevicename, haldevice.halname, "home", "halHome", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { @@ -2283,17 +2294,20 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi }; $scope.buildHALHeatUrls = function (haldevice, buildonly) { - onpayload = "http://" + haldevice.haladdress + var httpType = "http://"; + if(haldevice.secure) + httpType = "https://"; + onpayload = httpType + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Heat?Token=" + $scope.bridge.settings.haltoken; - dimpayload = "http://" + haldevice.haladdress + dimpayload = httpType + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Heat!HeatSpValue=${intensity.percent}?Token=" + $scope.bridge.settings.haltoken; - offpayload = "http://" + haldevice.haladdress + offpayload = httpType + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Off?Token=" @@ -2307,17 +2321,20 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi }; $scope.buildHALCoolUrls = function (haldevice, buildonly) { - onpayload = "http://" + haldevice.haladdress + var httpType = "http://"; + if(haldevice.secure) + httpType = "https://"; + onpayload = httpType + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Cool?Token=" + $scope.bridge.settings.haltoken; - dimpayload = "http://" + haldevice.haladdress + dimpayload = httpType + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Cool!CoolSpValue=${intensity.percent}?Token=" + $scope.bridge.settings.haltoken; - offpayload = "http://" + haldevice.haladdress + offpayload = httpType + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Off?Token=" @@ -2331,12 +2348,15 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi }; $scope.buildHALAutoUrls = function (haldevice, buildonly) { - onpayload = "http://" + haldevice.haladdress + var httpType = "http://"; + if(haldevice.secure) + httpType = "https://"; + onpayload = httpType + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Auto?Token=" + $scope.bridge.settings.haltoken; - offpayload = "http://" + haldevice.haladdress + offpayload = httpType + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Off?Token=" @@ -2349,16 +2369,18 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi }; $scope.buildHALOffUrls = function (haldevice, buildonly) { - onpayload = "http://" + haldevice.haladdress + var httpType = "http://"; + if(haldevice.secure) + httpType = "https://"; + onpayload = httpType + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Auto?Token=" + $scope.bridge.settings.haltoken; - offpayload = "http://" + haldevice.haladdress + offpayload = httpType + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Off?Token=" - $scope.device.offUrl = "http://" + haldevice.haladdress bridgeService.buildUrls(onpayload, null, offpayload, false, haldevice.haldevicename + "-" + haldevice.halname + "-TurnOff", haldevice.haldevicename + " Thermostat", haldevice.halname, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { @@ -2368,12 +2390,15 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi }; $scope.buildHALFanUrls = function (haldevice, buildonly) { - onpayload = "http://" + haldevice.haladdress + var httpType = "http://"; + if(haldevice.secure) + httpType = "https://"; + onpayload = httpType + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!FanMode=On?Token=" + $scope.bridge.settings.haltoken; - offpayload = "http://" + haldevice.haladdress + offpayload = httpType + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!FanMode=Auto?Token=" diff --git a/src/main/resources/public/views/system.html b/src/main/resources/public/views/system.html index f5f5bdd..eb87c31 100644 --- a/src/main/resources/public/views/system.html +++ b/src/main/resources/public/views/system.html @@ -201,12 +201,14 @@ Name IP + Use SSL Manage {{hal.name}} {{hal.ip}} + {{hal.secure}} @@ -217,8 +219,11 @@ + + ng-click="addHaltoSettings(newhalname, newhalip, newhalsecure)">Add