From 12a31e14eed368994ac59d6113389075ed917d61 Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Wed, 7 Dec 2016 07:56:18 +0100 Subject: [PATCH] Optionally disable SSL cert verification. Fixes #44 --- README.md | 15 +++++++++++++- config/config.example.json | 12 ++++++++++++ lib/dasher.js | 40 +++++++++++++++++++++++++++++--------- 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3d7651f..70182fc 100755 --- a/README.md +++ b/README.md @@ -51,12 +51,24 @@ Here's an example. "var2":" val2" } }, + { + "name": "Start Party Time from anywhere", + "address": "d8:02:dc:98:63:49", + "interface": "en0", + "timeout": "60000", + "url": "https://home.example.com/api/services/scene/turn_on", + "insecure": true, + "method": "POST", + "headers": {"x-ha-access": "your_password"}, + "json": true, + "body": {"entity_id": "scene.party_time"} + }, { "name": "Start Cooking Playlist", "address": "66:a0:dc:98:d2:63", "url": "http://192.168.1.55:8181/playlists/cooking/play", "method": "PUT" - }, + } ]} ``` @@ -67,6 +79,7 @@ Buttons take up to 7 options. * `interface` - Optionally listen for the button on a specific network interface. (`enX` on OS X and `ethX` on Linux) * `timeout` - Optionally set the time required between button press detections (if multiple pressese are detected) in milliseconds * `url` - The URL that will be requested. +* `insecure` - Optionally skip SSL certificate verification. Default is `false`. * `method` - The HTTP method of the request. * `headers` - Optional headers to use in the request. * `json` - Optionally declare the content body as being JSON in the request. diff --git a/config/config.example.json b/config/config.example.json index 6d6be70..54e459c 100644 --- a/config/config.example.json +++ b/config/config.example.json @@ -10,6 +10,18 @@ "json": true, "body": {"entity_id": "scene.party_time"} }, + { + "name": "Start Party Time from anywhere", + "address": "d8:02:dc:98:63:49", + "interface": "en0", + "timeout": "60000", + "url": "https://home.example.com/api/services/scene/turn_on", + "insecure": true, + "method": "POST", + "headers": {"x-ha-access": "your_password"}, + "json": true, + "body": {"entity_id": "scene.party_time"} + }, { "name": "Start Cooking Playlist", "address": "66:a0:dc:98:d2:63", diff --git a/lib/dasher.js b/lib/dasher.js index e3958ff..024ce50 100644 --- a/lib/dasher.js +++ b/lib/dasher.js @@ -7,7 +7,13 @@ function doLog(message) { } function DasherButton(button) { - var options = {headers: button.headers, body: button.body, json: button.json, formData: button.formData} + var options = { + headers: button.headers, + body: button.body, + json: button.json, + insecure: button.insecure, + formData: button.formData + } this.dashButton = dashButton(button.address, button.interface, button.timeout) @@ -24,15 +30,31 @@ function doRequest(requestUrl, method, options, callback) { options.query = options.query || {} options.json = options.json || false options.headers = options.headers || {} + options.insecure = options.insecure || false - var reqOpts = { - url: url.parse(requestUrl), - method: method || 'GET', - qs: options.query, - body: options.body, - json: options.json, - headers: options.headers, - formData: options.formData + if (options.insecure) { + var reqOpts = { + url: url.parse(requestUrl), + method: method || 'GET', + qs: options.query, + body: options.body, + json: options.json, + headers: options.headers, + formData: options.formData, + rejectUnauthorized: false, + requestCert: true, + agent: false + } + } else { + var reqOpts = { + url: url.parse(requestUrl), + method: method || 'GET', + qs: options.query, + body: options.body, + json: options.json, + headers: options.headers, + formData: options.formData, + } } request(reqOpts, function onResponse(error, response, body) {