From 889f0e15694a4cb86860305ed309aed71b685764 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Thu, 21 Apr 2022 11:40:12 +0100 Subject: [PATCH 1/9] Don't start if user has no home directory If the user doesn't have a defined home dir (env var `HOME`, `USERPROFILE` or `HOMEPATH`) and the `userDir` is not passed on the command line then we shouldn't start as we don't know where to copy the default `settings.js` file to or where to store flows fixes #3539 --- packages/node_modules/node-red/red.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/node_modules/node-red/red.js b/packages/node_modules/node-red/red.js index 2af02e2d5..421189118 100755 --- a/packages/node_modules/node-red/red.js +++ b/packages/node_modules/node-red/red.js @@ -112,6 +112,10 @@ if (parsedArgs.settings) { // Consider compatibility for older versions settingsFile = path.join(process.env.HOMEPATH,".node-red","settings.js"); } else { + if (!parsedArgs.userDir && !(process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH)) { + console.log("User has no Home Directory and no userDir set") + process.exit() + } var userDir = parsedArgs.userDir || path.join(process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH,".node-red"); var userSettingsFile = path.join(userDir,"settings.js"); if (fs.existsSync(userSettingsFile)) { From 812efde3424a012066d835ef6c28daa531c7a24c Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Thu, 21 Apr 2022 12:00:10 +0100 Subject: [PATCH 2/9] Also check if there is a useDir defined --- packages/node_modules/node-red/red.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/node-red/red.js b/packages/node_modules/node-red/red.js index 421189118..786f86a2b 100755 --- a/packages/node_modules/node-red/red.js +++ b/packages/node_modules/node-red/red.js @@ -114,7 +114,7 @@ if (parsedArgs.settings) { } else { if (!parsedArgs.userDir && !(process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH)) { console.log("User has no Home Directory and no userDir set") - process.exit() + process.exit(1) } var userDir = parsedArgs.userDir || path.join(process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH,".node-red"); var userSettingsFile = path.join(userDir,"settings.js"); @@ -321,6 +321,11 @@ httpsPromise.then(function(startupHttps) { settings.userDir = parsedArgs.userDir; } + if (!settings.userDir) { + console.log("No Node-RED userDir set, exiting") + process.exit(1) + } + try { RED.init(server,settings); } catch(err) { From 0014fec63f43842b47e61ac4d17ddce5f922ef3f Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Thu, 21 Apr 2022 13:52:38 +0100 Subject: [PATCH 3/9] Remove test that exits if no userDir defined With the storage plugins it is possible to not need a userDir, just a settings.js --- packages/node_modules/node-red/red.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/node_modules/node-red/red.js b/packages/node_modules/node-red/red.js index 786f86a2b..f6f019054 100755 --- a/packages/node_modules/node-red/red.js +++ b/packages/node_modules/node-red/red.js @@ -321,11 +321,6 @@ httpsPromise.then(function(startupHttps) { settings.userDir = parsedArgs.userDir; } - if (!settings.userDir) { - console.log("No Node-RED userDir set, exiting") - process.exit(1) - } - try { RED.init(server,settings); } catch(err) { From cdcc8cc59a295e7a36311bf14f6d277ebcb42411 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Thu, 21 Apr 2022 15:47:40 +0100 Subject: [PATCH 4/9] Update packages/node_modules/node-red/red.js Co-authored-by: Nick O'Leary --- packages/node_modules/node-red/red.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node_modules/node-red/red.js b/packages/node_modules/node-red/red.js index f6f019054..38a51f434 100755 --- a/packages/node_modules/node-red/red.js +++ b/packages/node_modules/node-red/red.js @@ -113,7 +113,7 @@ if (parsedArgs.settings) { settingsFile = path.join(process.env.HOMEPATH,".node-red","settings.js"); } else { if (!parsedArgs.userDir && !(process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH)) { - console.log("User has no Home Directory and no userDir set") + console.log("Could not find user directory. Ensure $HOME is set for the current user, or use --userDir option") process.exit(1) } var userDir = parsedArgs.userDir || path.join(process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH,".node-red"); From 020eaef5baf82340388eda6692982f169579d4c3 Mon Sep 17 00:00:00 2001 From: Stephen McLaughlin <44235289+Steve-Mcl@users.noreply.github.com> Date: Tue, 26 Apr 2022 16:12:54 +0100 Subject: [PATCH 5/9] Fix incorrect MQTT status fixes #3550 --- .../@node-red/nodes/core/network/10-mqtt.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js index 1ea5445ce..a026fdc29 100644 --- a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js +++ b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js @@ -362,7 +362,7 @@ module.exports = function(RED) { node.brokerConn.connect(function () { done(); }); - }) + }, true) } else { // Without force flag, we will refuse to cycle an active connection done(new Error(RED._('mqtt.errors.invalid-action-alreadyconnected'))); @@ -750,32 +750,35 @@ module.exports = function(RED) { } } }; - node.disconnect = function (callback) { - const _callback = function (resetNodeConnectedState) { + node.disconnect = function (callback, force) { + const _callback = function (resetNodeConnectedState, _force) { setStatusDisconnected(node, true); - if(resetNodeConnectedState) { + if(resetNodeConnectedState || _force) { + node.client.removeAllListeners(); node.closing = true; node.connecting = false; node.connected = false; } callback && typeof callback == "function" && callback(); }; - if(node.closing) { - return _callback(false); + return _callback(false, force); } var endCallBack = function endCallBack() { } if(node.connected && node.closeMessage) { node.publish(node.closeMessage, function (err) { node.client.end(endCallBack); - _callback(true); + _callback(true, force); }); } else if(node.connected) { node.client.end(endCallBack); - _callback(true); + _callback(true, force); + } else if(node.connecting) { + node.client.end(); + _callback(true, true); } else { - _callback(false); + _callback(false, force); } } node.subscriptionIds = {}; From 205dbc1a259f6f8c386bf390042b4a210e713651 Mon Sep 17 00:00:00 2001 From: Mauricio Bonani Date: Wed, 27 Apr 2022 15:00:29 -0400 Subject: [PATCH 6/9] Increase typedInput container border-radius Fixes #3548 --- .../@node-red/editor-client/src/sass/ui/common/typedInput.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/editor-client/src/sass/ui/common/typedInput.scss b/packages/node_modules/@node-red/editor-client/src/sass/ui/common/typedInput.scss index a084fcff3..194ae68df 100644 --- a/packages/node_modules/@node-red/editor-client/src/sass/ui/common/typedInput.scss +++ b/packages/node_modules/@node-red/editor-client/src/sass/ui/common/typedInput.scss @@ -16,7 +16,7 @@ .red-ui-typedInput-container { border: 1px solid $form-input-border-color; - border-radius: 4px; + border-radius: 5px; height: 34px; line-height: 14px; display: inline-flex; From 662a44fccf26c19d0552756963ea276eef028d00 Mon Sep 17 00:00:00 2001 From: Stephen McLaughlin <44235289+Steve-Mcl@users.noreply.github.com> Date: Fri, 29 Apr 2022 10:44:19 +0100 Subject: [PATCH 7/9] save and restore v5 config user props --- .../node_modules/@node-red/nodes/core/network/10-mqtt.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html index 747281ad0..cf4015f2e 100644 --- a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html +++ b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html @@ -609,6 +609,7 @@ default: !this.userProps ? 'none':'json', types: [typedInputNoneOpt, 'json'] }); + $("#node-config-input-userProps").typedInput('value',this.userProps); if (typeof this.keepalive === 'undefined') { this.keepalive = 15; $("#node-config-input-keepalive").val(this.keepalive); @@ -718,6 +719,10 @@ } if (v5) { + const userProps = $("#node-config-input-userProps").val().trim(); + if (userProps) { + this.userProps = userProps; + } this.birthMsg = saveV5Message("birth"); this.closeMsg = saveV5Message("close"); this.willMsg = saveV5Message("will"); From 294fc6b62f8ff986ec1331f542155f44e7bf9f52 Mon Sep 17 00:00:00 2001 From: Stephen McLaughlin <44235289+Steve-Mcl@users.noreply.github.com> Date: Fri, 29 Apr 2022 11:25:19 +0100 Subject: [PATCH 8/9] Ensure userProps makes it through to runtime --- .../@node-red/nodes/core/network/10-mqtt.html | 11 ++++++++--- .../@node-red/nodes/core/network/10-mqtt.js | 8 ++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html index cf4015f2e..ecef71366 100644 --- a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html +++ b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html @@ -480,6 +480,7 @@ willRetain: {value:false}, willPayload: {value:""}, willMsg: { value: {}}, + userProps: { value: ""}, sessionExpiry: {value:0} }, credentials: { @@ -719,9 +720,13 @@ } if (v5) { - const userProps = $("#node-config-input-userProps").val().trim(); - if (userProps) { - this.userProps = userProps; + this.userProps = ""; + const userPropsType = $("#node-config-input-userProps").typedInput("type"); + if(userPropsType == "json") { + const userProps = $("#node-config-input-userProps").val(); + if (userProps && typeof userProps === "string") { + this.userProps = userProps.trim(); + } } this.birthMsg = saveV5Message("birth"); this.closeMsg = saveV5Message("close"); diff --git a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js index a026fdc29..1e8f8ce9c 100644 --- a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js +++ b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js @@ -415,8 +415,12 @@ module.exports = function(RED) { setIfHasProperty(opts, node, "topicAliasMaximum", init); setIfHasProperty(opts, node, "maximumPacketSize", init); setIfHasProperty(opts, node, "receiveMaximum", init); - setIfHasProperty(opts, node, "userProperties", init);//https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901116 - setIfHasProperty(opts, node, "userPropertiesType", init); + //https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901116 + if (hasProperty(opts, "userProperties")) { + node.userProperties = opts.userProperties; + } else if (hasProperty(opts, "userProps")) { + node.userProperties = opts.userProps; + } function createLWT(topic, payload, qos, retain, v5opts, v5SubPropName) { let message = undefined; From b51eb7326f6990dd8920282f792b068ffe62a163 Mon Sep 17 00:00:00 2001 From: Mauricio Bonani Date: Fri, 29 Apr 2022 18:40:34 -0400 Subject: [PATCH 9/9] Change node config SASS variables --- .../@node-red/editor-client/src/sass/colors.scss | 1 + .../@node-red/editor-client/src/sass/tab-config.scss | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/sass/colors.scss b/packages/node_modules/@node-red/editor-client/src/sass/colors.scss index 88498b355..a09aace5e 100644 --- a/packages/node_modules/@node-red/editor-client/src/sass/colors.scss +++ b/packages/node_modules/@node-red/editor-client/src/sass/colors.scss @@ -212,6 +212,7 @@ $node-icon-background-color-opacity: 0.05; $node-icon-border-color: #000; $node-icon-border-color-opacity: 0.1; +$node-config-background: #f3f3f3; $node-link-port-background: #eee; diff --git a/packages/node_modules/@node-red/editor-client/src/sass/tab-config.scss b/packages/node_modules/@node-red/editor-client/src/sass/tab-config.scss index 787669fd7..fbfa8eb29 100644 --- a/packages/node_modules/@node-red/editor-client/src/sass/tab-config.scss +++ b/packages/node_modules/@node-red/editor-client/src/sass/tab-config.scss @@ -54,7 +54,7 @@ ul.red-ui-sidebar-node-config-list { .red-ui-palette-icon-container { font-size: 12px; line-height: 30px; - background-color: $secondary-background-selected; + background-color: $node-icon-background-color; border-top-right-radius: 4px; border-bottom-right-radius: 4px; a { @@ -63,10 +63,10 @@ ul.red-ui-sidebar-node-config-list { bottom: 0; left: 0; right: 0; - color: $secondary-text-color; + color: $node-port-label-color; &:hover { text-decoration: none; - background: $secondary-background-hover; + background: $node-port-background-hover; } } } @@ -74,7 +74,7 @@ ul.red-ui-sidebar-node-config-list { .red-ui-palette-node-config { width: 160px; height: 30px; - background: $primary-background; + background: $node-config-background; color: $primary-text-color; cursor: pointer; }