node-red-contrib-remote 1.5.2 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,8 +36,14 @@ You will find more information on [www.remote-red-com](https://www.remote-red.co
36
36
 
37
37
  ## Version History
38
38
 
39
+ Version 1.6.0
40
+ - Compatibility to 'node-red-contrib-remote-cli' version 1.1.0.
41
+
42
+ Version 1.5.3
43
+ - Improved error logging while the instance registration process.
44
+
39
45
  Version 1.5.2
40
- - Compatibility to 'node-red-contrib-remote-cli'
46
+ - Compatibility to 'node-red-contrib-remote-cli'.
41
47
 
42
48
  Version 1.5.1
43
49
  - Added support for running Node-RED with a self signed https certificate.
@@ -21,6 +21,7 @@
21
21
  "actions" : {
22
22
  "register_app": "Remote-RED App verbinden",
23
23
  "register_app_next": "Weitere Remote-RED App verbinden",
24
+ "test_network": "Netzwerk testen",
24
25
  "support_mail": "Mail an Support öffnen"
25
26
  },
26
27
  "legal": {
@@ -21,6 +21,7 @@
21
21
  "actions" : {
22
22
  "register_app": "Connect Remote-RED App",
23
23
  "register_app_next": "Connect another Remote-RED App",
24
+ "test_network": "Test network",
24
25
  "support_mail": "Open mail to support"
25
26
  },
26
27
  "legal": {
@@ -10,7 +10,9 @@
10
10
  baseurl: {value:""},
11
11
  instancehash: {value:""},
12
12
  server: {value:""},
13
- region: {value:"de"}
13
+ region: {value:"de"},
14
+ customerhash: {value:""},
15
+ customerkey: {value:""}
14
16
  },
15
17
  credentials: {
16
18
  instanceauth: {type:"text"}
@@ -91,7 +93,7 @@
91
93
  function registerInstance() {
92
94
  // Request InstanceHash when empty
93
95
  const region = document.getElementById('node-config-input-region').value;
94
- $.getJSON('contrib-remote/requestInstanceHash/' + region, function(data) {
96
+ $.getJSON('contrib-remote/requestInstanceHash/' + region + '/0/0', function(data) {
95
97
  if ( data.error == undefined ) {
96
98
  // Fill UI
97
99
  document.getElementById('node-config-input-instancehash').value = data.instancehash;
@@ -166,6 +168,23 @@
166
168
  }
167
169
  }
168
170
 
171
+ function testNetworkButtonClicked() {
172
+ // Disable Button
173
+ document.getElementById('testNetworkButton').disabled = true;
174
+
175
+ $.get(`contrib-remote/testNetwork`, function(data) {
176
+ if ( data.error == undefined ) {
177
+ alert(data);
178
+ } else {
179
+ // Show error
180
+ alert('Error while registering app: ' + data.error);
181
+ }
182
+
183
+ // Enable button
184
+ document.getElementById('testNetworkButton').disabled = false;
185
+ });
186
+ }
187
+
169
188
  function openSupportMailButtonClicked() {
170
189
  // Get InstanceHash and Server from UI
171
190
  const instanceHash = document.getElementById('node-config-input-instancehash').value;
@@ -243,7 +262,7 @@
243
262
  <span id='terms_url_template' data-i18n="remote-config.legal.termsurl" style="display: none;"></span>
244
263
 
245
264
  <div id="registerRemoteAppQRCodeContainer" style="visibility: collapse; height: 0px;">
246
- <img id="registerRemoteAppQRCode" src=""></img>
265
+ <img id="registerRemoteAppQRCode" src="">
247
266
  <div id="apphelp" style="max-width: 460px; border-width: 1px; border-style: dashed; border-color: #666; padding: 10px; margin-top: 6px; margin-bottom: 20px;">
248
267
  <label data-i18n="remote-config.apphelp.title" style="font-weight: bold;"></label>
249
268
  <label data-i18n="remote-config.apphelp.para1"></label>
@@ -270,6 +289,12 @@
270
289
  </div>
271
290
  </div>
272
291
 
292
+ <!--
293
+ <button id="testNetworkButton" type="button" class="red-ui-button" onclick="testNetworkButtonClicked()">
294
+ <span id="testNetworkButtonText" data-i18n="remote-config.actions.test_network">
295
+ </button>
296
+ -->
297
+
273
298
  <div id="help" style="max-width: 460px; border-width: 1px; border-style: dashed; border-color: #666; padding: 10px; margin-top: 40px; margin-bottom: 20px;">
274
299
  <label data-i18n="remote-config.help.title" style="font-weight: bold;"></label>
275
300
  <label data-i18n="remote-config.help.para1"></label>
@@ -1,6 +1,9 @@
1
1
  module.exports = function(RED) {
2
2
  const commons = require('./remote-commons');
3
3
  const internalIp = require('internal-ip');
4
+ const ping = require('ping');
5
+ const dns = require('dns');
6
+ const dnsPromises = dns.promises;
4
7
  const fs = require('fs');
5
8
  var QRCode = require('qrcode');
6
9
 
@@ -23,6 +26,74 @@ module.exports = function(RED) {
23
26
  }
24
27
  });
25
28
 
29
+ function getErrorMessage(error) {
30
+ let errorMessage = error.message;
31
+ if ( error.response && error.response.data && error.response.data.message ) {
32
+ errorMessage = errorMessage + " / " + error.response.data.message;
33
+ }
34
+ if ( commons.getNetworkErrorCustomString(error) !== undefined) {
35
+ errorMessage = commons.getNetworkErrorCustomString(error);
36
+ }
37
+ return errorMessage;
38
+ }
39
+
40
+ RED.httpAdmin.get("/contrib-remote/testNetwork", RED.auth.needsPermission('remote-config.read'), async function(req,res) {
41
+ // Test the network conditions
42
+
43
+ const testResults = [];
44
+
45
+ const axiosInstance = commons.createAxiosInstance();
46
+
47
+ // All servers to check
48
+ const serversToCheck = ['contact-dev.remote-red.comx', 'contact-de.remote-red.com'];
49
+
50
+ // DNS probe
51
+ const promisesDns = serversToCheck.map(host => {
52
+ return dnsPromises.lookup(host, {all: true})
53
+ .then(res => {
54
+ const v4 = res.some(e => e.family === 4);
55
+ const v6 = res.some(e => e.family === 6);
56
+ testResults.push({type: 'DNS', test: `DNS lookup ${host}`, result: getErrorMessage(error)});
57
+ console.log(res);
58
+ // testResults.push({test: `DNS lookup ${host}`, result: res.alive ? `${res.time}ms` : 'Error'});
59
+ })
60
+ .catch(error => {
61
+ console.log(error);
62
+ console.log(`dns resolve ${host}: ${getErrorMessage(error)}`);
63
+ // console.log(error);
64
+ testResults.push({type: 'DNS', test: `DNS lookup ${host}`, result: getErrorMessage(error)});
65
+ });
66
+ });
67
+ await Promise.all(promisesDns);
68
+
69
+ // Ping hosts
70
+ const additionalPingHosts = ['google.com', '173.212.245.41', '2a02:c207:3006:3079::1'];
71
+ const promisesPings = [...serversToCheck, ...additionalPingHosts].map(host => {
72
+ return ping.promise.probe(host)
73
+ .then(res => {
74
+ testResults.push({type: 'PING', test: `ping ${host}`, result: res.alive ? `${res.time}ms` : 'Error'});
75
+ });
76
+ });
77
+ await Promise.all(promisesPings);
78
+
79
+ // Make https test call
80
+ const promisesHttpsCalls = serversToCheck.map(url => {
81
+ return axiosInstance.get(`https://${url}/testNetwork`)
82
+ .then(response => {
83
+ testResults.push({test: `https call to ${url}`, result: 'OK'});
84
+ })
85
+ .catch(error => {
86
+ console.log(`https call to ${url}: ${getErrorMessage(error)}`);
87
+ // console.log(error);
88
+ testResults.push({type: 'HTTPS', test: `https call to ${url}`, result: getErrorMessage(error)});
89
+ });
90
+ });
91
+ await Promise.all(promisesHttpsCalls);
92
+
93
+ console.log(testResults);
94
+ res.json(testResults);
95
+ });
96
+
26
97
  RED.httpAdmin.get("/contrib-remote/connectionData", RED.auth.needsPermission('remote-config.read'), function(req,res) {
27
98
  // Return the internal IP and the mountpath
28
99
  const ipData = {
@@ -34,7 +105,7 @@ module.exports = function(RED) {
34
105
  res.json(ipData);
35
106
  });
36
107
 
37
- RED.httpAdmin.get("/contrib-remote/requestInstanceHash/:regionorserver", RED.auth.needsPermission('remote-config.read'), function(req,res) {
108
+ RED.httpAdmin.get("/contrib-remote/requestInstanceHash/:regionorserver/:customerhash/:customerkey", RED.auth.needsPermission('remote-config.read'), function(req,res) {
38
109
  // Call API for a instacehash and a instanceauth
39
110
  const axiosInstance = commons.createAxiosInstance();
40
111
 
@@ -49,12 +120,17 @@ module.exports = function(RED) {
49
120
  }
50
121
 
51
122
  // Call API
52
- axiosInstance.post(url, {})
123
+ axiosInstance.post(url, {
124
+ 'customerhash': req.params.customerhash,
125
+ 'customerkey': req.params.customerkey,
126
+ 'version': commons.getNodeVersion()
127
+ })
53
128
  .then(response => {
54
129
  res.json(response.data);
55
130
  })
56
131
  .catch((error) => {
57
132
  console.log("ERROR: requestInstanceHash: " + error);
133
+ console.error(error);
58
134
  let errorMessage = error.message;
59
135
  if ( error.response && error.response.data && error.response.data.message ) {
60
136
  errorMessage = errorMessage + " / " + error.response.data.message;
@@ -72,7 +148,7 @@ module.exports = function(RED) {
72
148
  axiosInstance.post(`https://api-${req.body.server}/registerApp`, {
73
149
  'instancehash': req.body.instancehash,
74
150
  'instanceauth': req.body.instanceauth,
75
- 'customerhash': req.body.customerhash
151
+ 'version': commons.getNodeVersion()
76
152
  })
77
153
  .then(response => {
78
154
  var localip = req.body.host;
@@ -92,12 +168,13 @@ module.exports = function(RED) {
92
168
  'instancehash': response.data.instancehash,
93
169
  'apphash': response.data.apphash,
94
170
  'password': response.data.password,
95
- 'nodeversion': 1.0
171
+ 'customerhash': response.data.customerhash,
172
+ 'nodeversion': commons.getNodeVersion()
96
173
  };
97
174
  const qrCodeString = JSON.stringify(qrCodeData);
98
175
  const qrCodeStringBuffer = Buffer.from(qrCodeString);
99
176
  const qrCodeStringBase64 = qrCodeStringBuffer.toString('base64');
100
- const link = 'remotered://add?data=' + qrCodeStringBase64;
177
+ const link = response.data.appurl + '://add?data=' + qrCodeStringBase64;
101
178
  QRCode.toDataURL(qrCodeStringBase64, function (err, url) {
102
179
  const responseData = {
103
180
  'qrcode': url,
@@ -108,6 +185,7 @@ module.exports = function(RED) {
108
185
  })
109
186
  .catch((error) => {
110
187
  console.log("ERROR: registerApp: " + error);
188
+ console.error(error);
111
189
  let errorMessage = error.message;
112
190
  if ( error.response && error.response.data && error.response.data.message ) {
113
191
  errorMessage = errorMessage + " / " + error.response.data.message;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-remote",
3
- "version": "1.5.2",
3
+ "version": "1.6.0",
4
4
  "description": "Remote-RED is an ecosystem to bring remote access, push notification and geofencing to Node-RED. There are also additional functions like directly answer on a notification and homescreen widgets.",
5
5
  "author": "Thorsten Heilmann",
6
6
  "license": "GPL-3.0",
@@ -17,10 +17,10 @@
17
17
  "internal-ip": "^6.1.0",
18
18
  "limiter": "^1.1.5",
19
19
  "path": "^0.12.7",
20
+ "ping": "^0.4.4",
20
21
  "qrcode": "^1.4.4"
21
22
  },
22
23
  "main": "remote-config.js",
23
- "devDependencies": {},
24
24
  "scripts": {
25
25
  "test": "echo \"Error: no test specified\" && exit 1"
26
26
  },