From 5c2d30e24bf00540dea58d2c8aedfda3c2ec9b99 Mon Sep 17 00:00:00 2001 From: BWS Systems Date: Wed, 24 Jul 2019 16:10:59 -0500 Subject: [PATCH] a few fixes and trying to handle secure https fail on start --- pom.xml | 2 +- .../com/bwssystems/HABridge/HABridge.java | 16 ++++++-- .../HABridge/dao/GroupRepository.java | 8 +++- src/main/resources/public/scripts/app.js | 39 +++++++++++++------ src/main/resources/public/views/system.html | 2 +- 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index a73585a..fea398a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 5.3.0RC12 + 5.3.0RC13 jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/HABridge.java b/src/main/java/com/bwssystems/HABridge/HABridge.java index 7280566..f8db8d8 100644 --- a/src/main/java/com/bwssystems/HABridge/HABridge.java +++ b/src/main/java/com/bwssystems/HABridge/HABridge.java @@ -15,6 +15,8 @@ import com.bwssystems.HABridge.upnp.UpnpSettingsResource; import com.bwssystems.HABridge.util.UDPDatagramSender; public class HABridge { + private static SystemControl theSystem; + private static boolean secureFailed; /* * This program is based on the work of armzilla from this github repository: @@ -39,13 +41,13 @@ public class HABridge { UDPDatagramSender udpSender; UpnpSettingsResource theSettingResponder; UpnpListener theUpnpListener; - SystemControl theSystem; BridgeSettings bridgeSettings; Version theVersion; @SuppressWarnings("unused") HttpClientPool thePool; ShutdownHook shutdownHook = null; + secureFailed = false; log.info("HA Bridge startup sequence..."); theVersion = new Version(); // Singleton initialization @@ -56,7 +58,7 @@ public class HABridge { while(!bridgeSettings.getBridgeControl().isStop()) { log.info("HA Bridge (v{}) initializing....", theVersion.getVersion() ); bridgeSettings.buildSettings(); - if(bridgeSettings.getBridgeSecurity().isUseHttps()) { + if(bridgeSettings.getBridgeSecurity().isUseHttps() && !secureFailed) { secure(bridgeSettings.getBridgeSecurity().getKeyfilePath(), bridgeSettings.getBridgeSecurity().getKeyfilePassword(), null, null); log.info("Using https for web and api calls"); } @@ -153,8 +155,14 @@ public class HABridge { } private static void theExceptionHandler(Exception e, Integer thePort) { - Logger log = LoggerFactory.getLogger(HABridge.class); + Logger log = LoggerFactory.getLogger(HABridge.class); + if(e.getMessage().equals("no valid keystore")) { + log.error("Could not start ha-bridge using https webservice on port [{}] due to: {}", thePort, e.getMessage()); + secureFailed = true; + theSystem.reinit(); + return; + } log.error("Could not start ha-bridge webservice on port [{}] due to: {}", thePort, e.getMessage()); System.exit(0); - } + } } diff --git a/src/main/java/com/bwssystems/HABridge/dao/GroupRepository.java b/src/main/java/com/bwssystems/HABridge/dao/GroupRepository.java index 96a9c5c..5cf77d3 100644 --- a/src/main/java/com/bwssystems/HABridge/dao/GroupRepository.java +++ b/src/main/java/com/bwssystems/HABridge/dao/GroupRepository.java @@ -201,11 +201,15 @@ public class GroupRepository extends BackupHandler { private String repositoryReader(Path filePath) { String content = null; - if(Files.notExists(filePath) || !Files.isReadable(filePath)){ - log.warn("Error reading the file: " + filePath + " - Does not exist or is not readable. continuing..."); + if(Files.notExists(filePath)){ + log.debug("Error, the file: " + filePath + " - does not exist. continuing..."); return null; } + if(!Files.isReadable(filePath)){ + log.warn("Error, the file: " + filePath + " - is not readable. continuing..."); + return null; + } try { content = new String(Files.readAllBytes(filePath)); diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index 0afe010..8cee1e9 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -367,6 +367,18 @@ app.service('bridgeService', function ($rootScope, $http, $base64, $location, ng }; this.changeSecuritySettings = function (useLinkButton, secureHueApi, execGarden, useHttps, keyfilePath, keyfilePassword) { + if(useHttps) { + if(!keyfilePassword || keyfilePassword.length == 0 || !keyfilePassword.trim()) { + self.displayErrorMessage("Use HTTPS - ", "Key File Password cannot be empty."); + return; + } + + if(!keyfilePath || keyfilePath.length == 0 || !keyfilePath.trim()) { + self.displayErrorMessage("Use HTTPS - ", "Key File Path cannot be empty."); + return; + } + } + var newSecurityInfo = {}; newSecurityInfo = { useLinkButton: useLinkButton, @@ -376,6 +388,7 @@ app.service('bridgeService', function ($rootScope, $http, $base64, $location, ng keyfilePath: keyfilePath, keyfilePassword: keyfilePassword }; + return $http.post(this.state.systemsbase + "/changesecurityinfo", newSecurityInfo).then( function (response) { self.state.securityInfo = response.data; @@ -2082,21 +2095,25 @@ app.controller('SystemController', function ($scope, $location, bridgeService, n } var othertypes = []; - othertypes = newhomegenieothertypes.split(","); - var theModuleTypes = []; var count = 0; - if (othertypes.length > 0) { - for (var i = 0; i < othertypes.length; i++) { - var aType = othertypes[i].trim(); - if (aType.length > 0) { - var moduleType = { - moduleType: aType - }; - theModuleTypes.push(moduleType); - count++; + var theModuleTypes = []; + + if(newhomegenieothertypes && newhomegenieothertypes.trim() && newhomegenieothertypes.length > 0) { + othertypes = newhomegenieothertypes.split(","); + if (othertypes.length > 0) { + for (var i = 0; i < othertypes.length; i++) { + var aType = othertypes[i].trim(); + if (aType.length > 0) { + var moduleType = { + moduleType: aType + }; + theModuleTypes.push(moduleType); + count++; + } } } } + var theExtension; if (count == 0) { theExtension = undefined; diff --git a/src/main/resources/public/views/system.html b/src/main/resources/public/views/system.html index 06d5a35..e0397a9 100644 --- a/src/main/resources/public/views/system.html +++ b/src/main/resources/public/views/system.html @@ -761,7 +761,7 @@ + ng-click="addHomeGenietoSettings(newhomegeniename, newhomegenieip, newhomegenieport, newhomegenieusername, newhomegeniepassword, newhomegeniewebhook, newhomegeniesecure, newhomegenieothertypes)">Add