From c53f890a8c275e4dd196e1fdd4c4e829606cf003 Mon Sep 17 00:00:00 2001 From: leoneleone Date: Fri, 12 Feb 2016 14:58:35 +0000 Subject: [PATCH 1/7] Update hap-nodejs to v0.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cd3f502..63b36c9 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "dependencies": { "chalk": "^1.1.1", "commander": "2.8.1", - "hap-nodejs": "0.1.1", + "hap-nodejs": "0.2.0", "semver": "5.0.3" } } From 386cf34827d7ec4554d877dc920cfa35d06afb3a Mon Sep 17 00:00:00 2001 From: Khaos Tian Date: Mon, 15 Feb 2016 19:23:38 -0800 Subject: [PATCH 2/7] Update hap-nodejs to 0.2.3 so the reachability for existing accessories will be correct. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 63b36c9..e96f1cc 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "dependencies": { "chalk": "^1.1.1", "commander": "2.8.1", - "hap-nodejs": "0.2.0", + "hap-nodejs": "0.2.3", "semver": "5.0.3" } } From aea485c33e9bff22ee754d7c72dd28c3fc9ded4b Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Tue, 16 Feb 2016 13:00:22 -0800 Subject: [PATCH 3/7] Version bump; publish v0.2.17 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e96f1cc..71b8388 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "homebridge", "description": "HomeKit support for the impatient", - "version": "0.2.16", + "version": "0.2.17", "scripts": { "dev": "DEBUG=* ./bin/homebridge -D -P example-plugins/ || true" }, From 1da98bb19fccc4e00630a8deb283e37fc7764eda Mon Sep 17 00:00:00 2001 From: Khaos Tian Date: Wed, 17 Feb 2016 10:37:11 -0800 Subject: [PATCH 4/7] Add the insecure launching option to homebridge cli. --- lib/cli.js | 5 ++++- lib/server.js | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 41ef6af..182fa1c 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -10,15 +10,18 @@ var log = require("./logger")._system; module.exports = function() { + var insecureAccess = false; + program .version(version) .option('-P, --plugin-path [path]', 'look for plugins installed at [path] as well as the default locations ([path] can also point to a single plugin)', function(p) { Plugin.addPluginPath(p); }) .option('-U, --user-storage-path [path]', 'look for homebridge user files at [path] instead of the default location (~/.homebridge)', function(p) { User.setStoragePath(p); }) .option('-D, --debug', 'turn on debug level logging', function() { require('./logger').setDebugEnabled(true) }) + .option('-I, --insecure', 'allow insecure access to homebridge', function() { insecureAccess = true; }) .parse(process.argv); // Initialize HAP-NodeJS with a custom persist directory hap.init(User.persistPath()); - new Server().run(); + new Server(insecureAccess).run(); } diff --git a/lib/server.js b/lib/server.js index eaf4622..bc2c691 100644 --- a/lib/server.js +++ b/lib/server.js @@ -19,11 +19,13 @@ module.exports = { Server: Server } -function Server() { +function Server(insecureAccess) { this._api = new API(); // object we feed to Plugins this._plugins = this._loadPlugins(); // plugins[name] = Plugin instance this._config = this._loadConfig(); this._bridge = this._createBridge(); + + this._allowInsecureAccess = insecureAccess || false; } Server.prototype.run = function() { @@ -52,7 +54,7 @@ Server.prototype._publish = function() { port: bridgeConfig.port || 51826, pincode: bridgeConfig.pin || "031-45-154", category: Accessory.Categories.BRIDGE - }); + }, this._allowInsecureAccess); log.info("Homebridge is running on port %s.", bridgeConfig.port || 51826); } From 287aa6d03427f9b1cb1c56b807af12d49afeac21 Mon Sep 17 00:00:00 2001 From: Khaos Tian Date: Wed, 17 Feb 2016 10:38:08 -0800 Subject: [PATCH 5/7] 0.2.18 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 71b8388..4f33dc4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "homebridge", "description": "HomeKit support for the impatient", - "version": "0.2.17", + "version": "0.2.18", "scripts": { "dev": "DEBUG=* ./bin/homebridge -D -P example-plugins/ || true" }, From 57beabf0b4a9ac8929d23e26cbc385e9e8397d0f Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Wed, 17 Feb 2016 10:43:54 -0800 Subject: [PATCH 6/7] Add comment --- lib/cli.js | 2 +- lib/server.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/cli.js b/lib/cli.js index 182fa1c..be4810a 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -17,7 +17,7 @@ module.exports = function() { .option('-P, --plugin-path [path]', 'look for plugins installed at [path] as well as the default locations ([path] can also point to a single plugin)', function(p) { Plugin.addPluginPath(p); }) .option('-U, --user-storage-path [path]', 'look for homebridge user files at [path] instead of the default location (~/.homebridge)', function(p) { User.setStoragePath(p); }) .option('-D, --debug', 'turn on debug level logging', function() { require('./logger').setDebugEnabled(true) }) - .option('-I, --insecure', 'allow insecure access to homebridge', function() { insecureAccess = true; }) + .option('-I, --insecure', 'allow unauthenticated requests (for easier hacking)', function() { insecureAccess = true }) .parse(process.argv); // Initialize HAP-NodeJS with a custom persist directory diff --git a/lib/server.js b/lib/server.js index bc2c691..d8523c0 100644 --- a/lib/server.js +++ b/lib/server.js @@ -25,6 +25,11 @@ function Server(insecureAccess) { this._config = this._loadConfig(); this._bridge = this._createBridge(); + // Server is "secure by default", meaning it creates a top-level Bridge accessory that + // will not allow unauthenticated requests. This matches the behavior of actual HomeKit + // accessories. However you can set this to true to allow all requests without authentication, + // which can be useful for easy hacking. Note that this will expose all functions of your + // bridged accessories, like changing charactersitics (i.e. flipping your lights on and off). this._allowInsecureAccess = insecureAccess || false; } From cf80e4f2dac2617236eead8bc94fb0d4c2b81eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 18 Feb 2016 00:17:34 +0100 Subject: [PATCH 7/7] Handle SIGINT and SIGTERM to enable clean shutdown of Homebridge For now we terminate the process, but in the future we may tell the server to stop, which may possibly include some teardown logic. Handling these signals also make it easier to put Homebridge inside a docker container, as docker uses SIGTERM to tell a container process to stop, and passes SIGINT when attached to the container and receiving a Ctrl+C. --- lib/cli.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/cli.js b/lib/cli.js index be4810a..68e44f8 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -23,5 +23,17 @@ module.exports = function() { // Initialize HAP-NodeJS with a custom persist directory hap.init(User.persistPath()); - new Server(insecureAccess).run(); + var server = new Server(insecureAccess); + + var signals = { 'SIGINT': 2, 'SIGTERM': 15 }; + Object.keys(signals).forEach(function (signal) { + process.on(signal, function () { + log.info("Got %s, shutting down Homebridge...", signal); + + // FIXME: Shut down server cleanly + process.exit(128 + signals[signal]); + }); + }); + + server.run(); }