a few fixes and trying to handle secure https fail on start

This commit is contained in:
BWS Systems
2019-07-24 16:10:59 -05:00
parent 28d84f667a
commit 5c2d30e24b
5 changed files with 48 additions and 19 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId> <groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId> <artifactId>ha-bridge</artifactId>
<version>5.3.0RC12</version> <version>5.3.0RC13</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HA Bridge</name> <name>HA Bridge</name>

View File

@@ -15,6 +15,8 @@ import com.bwssystems.HABridge.upnp.UpnpSettingsResource;
import com.bwssystems.HABridge.util.UDPDatagramSender; import com.bwssystems.HABridge.util.UDPDatagramSender;
public class HABridge { public class HABridge {
private static SystemControl theSystem;
private static boolean secureFailed;
/* /*
* This program is based on the work of armzilla from this github repository: * This program is based on the work of armzilla from this github repository:
@@ -39,13 +41,13 @@ public class HABridge {
UDPDatagramSender udpSender; UDPDatagramSender udpSender;
UpnpSettingsResource theSettingResponder; UpnpSettingsResource theSettingResponder;
UpnpListener theUpnpListener; UpnpListener theUpnpListener;
SystemControl theSystem;
BridgeSettings bridgeSettings; BridgeSettings bridgeSettings;
Version theVersion; Version theVersion;
@SuppressWarnings("unused") @SuppressWarnings("unused")
HttpClientPool thePool; HttpClientPool thePool;
ShutdownHook shutdownHook = null; ShutdownHook shutdownHook = null;
secureFailed = false;
log.info("HA Bridge startup sequence..."); log.info("HA Bridge startup sequence...");
theVersion = new Version(); theVersion = new Version();
// Singleton initialization // Singleton initialization
@@ -56,7 +58,7 @@ public class HABridge {
while(!bridgeSettings.getBridgeControl().isStop()) { while(!bridgeSettings.getBridgeControl().isStop()) {
log.info("HA Bridge (v{}) initializing....", theVersion.getVersion() ); log.info("HA Bridge (v{}) initializing....", theVersion.getVersion() );
bridgeSettings.buildSettings(); bridgeSettings.buildSettings();
if(bridgeSettings.getBridgeSecurity().isUseHttps()) { if(bridgeSettings.getBridgeSecurity().isUseHttps() && !secureFailed) {
secure(bridgeSettings.getBridgeSecurity().getKeyfilePath(), bridgeSettings.getBridgeSecurity().getKeyfilePassword(), null, null); secure(bridgeSettings.getBridgeSecurity().getKeyfilePath(), bridgeSettings.getBridgeSecurity().getKeyfilePassword(), null, null);
log.info("Using https for web and api calls"); log.info("Using https for web and api calls");
} }
@@ -153,8 +155,14 @@ public class HABridge {
} }
private static void theExceptionHandler(Exception e, Integer thePort) { 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()); log.error("Could not start ha-bridge webservice on port [{}] due to: {}", thePort, e.getMessage());
System.exit(0); System.exit(0);
} }
} }

View File

@@ -201,11 +201,15 @@ public class GroupRepository extends BackupHandler {
private String repositoryReader(Path filePath) { private String repositoryReader(Path filePath) {
String content = null; String content = null;
if(Files.notExists(filePath) || !Files.isReadable(filePath)){ if(Files.notExists(filePath)){
log.warn("Error reading the file: " + filePath + " - Does not exist or is not readable. continuing..."); log.debug("Error, the file: " + filePath + " - does not exist. continuing...");
return null; return null;
} }
if(!Files.isReadable(filePath)){
log.warn("Error, the file: " + filePath + " - is not readable. continuing...");
return null;
}
try { try {
content = new String(Files.readAllBytes(filePath)); content = new String(Files.readAllBytes(filePath));

View File

@@ -367,6 +367,18 @@ app.service('bridgeService', function ($rootScope, $http, $base64, $location, ng
}; };
this.changeSecuritySettings = function (useLinkButton, secureHueApi, execGarden, useHttps, keyfilePath, keyfilePassword) { 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 = {}; var newSecurityInfo = {};
newSecurityInfo = { newSecurityInfo = {
useLinkButton: useLinkButton, useLinkButton: useLinkButton,
@@ -376,6 +388,7 @@ app.service('bridgeService', function ($rootScope, $http, $base64, $location, ng
keyfilePath: keyfilePath, keyfilePath: keyfilePath,
keyfilePassword: keyfilePassword keyfilePassword: keyfilePassword
}; };
return $http.post(this.state.systemsbase + "/changesecurityinfo", newSecurityInfo).then( return $http.post(this.state.systemsbase + "/changesecurityinfo", newSecurityInfo).then(
function (response) { function (response) {
self.state.securityInfo = response.data; self.state.securityInfo = response.data;
@@ -2082,21 +2095,25 @@ app.controller('SystemController', function ($scope, $location, bridgeService, n
} }
var othertypes = []; var othertypes = [];
othertypes = newhomegenieothertypes.split(",");
var theModuleTypes = [];
var count = 0; var count = 0;
if (othertypes.length > 0) { var theModuleTypes = [];
for (var i = 0; i < othertypes.length; i++) {
var aType = othertypes[i].trim(); if(newhomegenieothertypes && newhomegenieothertypes.trim() && newhomegenieothertypes.length > 0) {
if (aType.length > 0) { othertypes = newhomegenieothertypes.split(",");
var moduleType = { if (othertypes.length > 0) {
moduleType: aType for (var i = 0; i < othertypes.length; i++) {
}; var aType = othertypes[i].trim();
theModuleTypes.push(moduleType); if (aType.length > 0) {
count++; var moduleType = {
moduleType: aType
};
theModuleTypes.push(moduleType);
count++;
}
} }
} }
} }
var theExtension; var theExtension;
if (count == 0) { if (count == 0) {
theExtension = undefined; theExtension = undefined;

View File

@@ -761,7 +761,7 @@
<td><input type="checkbox" ng-model="newhomegeniesecure" ng-true-value=true <td><input type="checkbox" ng-model="newhomegeniesecure" ng-true-value=true
ng-false-value=false></td> ng-false-value=false></td>
<td><button class="btn btn-success" type="submit" <td><button class="btn btn-success" type="submit"
ng-click="addHomeGenietoSettings(newhomegeniename, newhomegenieip, newhomegenieport, newshomegenieusername, newhomegeniepassword, newhomegeniewebhook, newhomegeniesecure, newhomegenieothertypes)">Add</button> ng-click="addHomeGenietoSettings(newhomegeniename, newhomegenieip, newhomegenieport, newhomegenieusername, newhomegeniepassword, newhomegeniewebhook, newhomegeniesecure, newhomegenieothertypes)">Add</button>
</td> </td>
</tr> </tr>
</table> </table>