mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge branch 'dev' into adding-timeout-to-functio-node
This commit is contained in:
@@ -117,14 +117,21 @@ module.exports = function(RED) {
|
||||
if (p.v) {
|
||||
try {
|
||||
var exp = RED.util.prepareJSONataExpression(p.v, node);
|
||||
var val = RED.util.evaluateJSONataExpression(exp, msg);
|
||||
RED.util.setMessageProperty(msg, property, val, true);
|
||||
}
|
||||
catch (err) {
|
||||
RED.util.evaluateJSONataExpression(exp, msg, (err, newValue) => {
|
||||
if (err) {
|
||||
errors.push(err.toString())
|
||||
} else {
|
||||
RED.util.setMessageProperty(msg,property,newValue,true);
|
||||
}
|
||||
evaluateProperty(doneEvaluating)
|
||||
});
|
||||
} catch (err) {
|
||||
errors.push(err.message);
|
||||
evaluateProperty(doneEvaluating)
|
||||
}
|
||||
} else {
|
||||
evaluateProperty(doneEvaluating)
|
||||
}
|
||||
evaluateProperty(doneEvaluating)
|
||||
} else {
|
||||
try {
|
||||
RED.util.evaluateNodeProperty(value, valueType, node, msg, (err, newValue) => {
|
||||
|
@@ -4,6 +4,7 @@
|
||||
<label style="width: auto" for="node-input-scope" data-i18n="catch.label.source"></label>
|
||||
<select id="node-input-scope-select">
|
||||
<option value="all" data-i18n="catch.scope.all"></option>
|
||||
<option value="group" data-i18n="catch.scope.group"></option>
|
||||
<option value="target" data-i18n="catch.scope.selected"></option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -170,6 +171,8 @@
|
||||
});
|
||||
if (this.scope === null) {
|
||||
$("#node-input-scope-select").val("all");
|
||||
} else if(this.scope === "group"){
|
||||
$("#node-input-scope-select").val("group");
|
||||
} else {
|
||||
$("#node-input-scope-select").val("target");
|
||||
}
|
||||
@@ -179,6 +182,8 @@
|
||||
var scope = $("#node-input-scope-select").val();
|
||||
if (scope === 'all') {
|
||||
this.scope = null;
|
||||
} else if(scope === 'group') {
|
||||
this.scope = "group";
|
||||
} else {
|
||||
$("#node-input-uncaught").prop("checked",false);
|
||||
this.scope = $("#node-input-catch-target-container-div").treeList('selected').map(function(i) { return i.node.id})
|
||||
|
@@ -4,6 +4,7 @@
|
||||
<label style="width: auto" for="node-input-scope" data-i18n="status.label.source"></label>
|
||||
<select id="node-input-scope-select">
|
||||
<option value="all" data-i18n="status.scope.all"></option>
|
||||
<option value="group" data-i18n="status.scope.group"></option>
|
||||
<option value="target" data-i18n="status.scope.selected"></option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -157,6 +158,8 @@
|
||||
});
|
||||
if (this.scope === null) {
|
||||
$("#node-input-scope-select").val("all");
|
||||
} else if(this.scope === "group"){
|
||||
$("#node-input-scope-select").val("group");
|
||||
} else {
|
||||
$("#node-input-scope-select").val("target");
|
||||
}
|
||||
@@ -166,6 +169,8 @@
|
||||
var scope = $("#node-input-scope-select").val();
|
||||
if (scope === 'all') {
|
||||
this.scope = null;
|
||||
} else if(scope === 'group') {
|
||||
this.scope = "group";
|
||||
} else {
|
||||
this.scope = $("#node-input-status-target-container-div").treeList('selected').map(function(i) { return i.node.id})
|
||||
}
|
||||
|
@@ -248,6 +248,14 @@ module.exports = function(RED) {
|
||||
}
|
||||
});
|
||||
|
||||
this.on("close", function () {
|
||||
for (const event of Object.values(messageEvents)) {
|
||||
if (event.ts) {
|
||||
clearTimeout(event.ts)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.returnLinkMessage = function(eventId, msg) {
|
||||
if (Array.isArray(msg._linkSource) && msg._linkSource.length === 0) {
|
||||
delete msg._linkSource;
|
||||
|
27
packages/node_modules/@node-red/nodes/core/common/91-global-config.html
vendored
Normal file
27
packages/node_modules/@node-red/nodes/core/common/91-global-config.html
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<script type="text/html" data-template-name="global-config">
|
||||
<div class="form-row">
|
||||
<label style="width: 100%"><span data-i18n="global-config.label.open-conf"></span>:</label>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<button class="red-ui-button" type="button" id="node-input-edit-env-var" data-i18n="editor:env-var.header" style="margin-left: 20px"></button>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('global-config',{
|
||||
category: 'config',
|
||||
defaults: {
|
||||
name: { value: "" },
|
||||
env: { value: [] },
|
||||
},
|
||||
credentials: {
|
||||
map: { type: "map" }
|
||||
},
|
||||
oneditprepare: function() {
|
||||
$('#node-input-edit-env-var').on('click', function(evt) {
|
||||
RED.actions.invoke('core:show-user-settings', 'envvar')
|
||||
});
|
||||
},
|
||||
hasUsers: false
|
||||
});
|
||||
</script>
|
7
packages/node_modules/@node-red/nodes/core/common/91-global-config.js
vendored
Normal file
7
packages/node_modules/@node-red/nodes/core/common/91-global-config.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
function GlobalConfigNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
}
|
||||
RED.nodes.registerType("global-config", GlobalConfigNode);
|
||||
}
|
@@ -10,6 +10,7 @@
|
||||
<option value="scale" data-i18n="range.scale.payload"></option>
|
||||
<option value="clamp" data-i18n="range.scale.limit"></option>
|
||||
<option value="roll" data-i18n="range.scale.wrap"></option>
|
||||
<option value="drop" data-i18n="range.scale.drop"></option>
|
||||
</select>
|
||||
</div>
|
||||
<br/>
|
||||
|
@@ -32,11 +32,15 @@ module.exports = function(RED) {
|
||||
if (value !== undefined) {
|
||||
var n = Number(value);
|
||||
if (!isNaN(n)) {
|
||||
if (node.action == "clamp") {
|
||||
if (node.action === "drop") {
|
||||
if (n < node.minin) { done(); return; }
|
||||
if (n > node.maxin) { done(); return; }
|
||||
}
|
||||
if (node.action === "clamp") {
|
||||
if (n < node.minin) { n = node.minin; }
|
||||
if (n > node.maxin) { n = node.maxin; }
|
||||
}
|
||||
if (node.action == "roll") {
|
||||
if (node.action === "roll") {
|
||||
var divisor = node.maxin - node.minin;
|
||||
n = ((n - node.minin) % divisor + divisor) % divisor + node.minin;
|
||||
}
|
||||
|
@@ -201,6 +201,7 @@ module.exports = function(RED) {
|
||||
});
|
||||
node.on("close", function() { clearDelayList(); });
|
||||
}
|
||||
|
||||
else if (node.pauseType === "random") {
|
||||
node.on("input", function(msg, send, done) {
|
||||
var wait = node.randomFirst + (node.diff * Math.random());
|
||||
@@ -226,34 +227,19 @@ module.exports = function(RED) {
|
||||
// The rate limit/queue type modes
|
||||
else if (node.pauseType === "rate") {
|
||||
node.on("input", function(msg, send, done) {
|
||||
if (msg.hasOwnProperty("reset")) {
|
||||
if (node.intervalID !== -1 ) {
|
||||
clearInterval(node.intervalID);
|
||||
node.intervalID = -1;
|
||||
}
|
||||
delete node.lastSent;
|
||||
node.buffer = [];
|
||||
node.rate = node.fixedrate;
|
||||
node.status({fill:"blue",shape:"ring",text:0});
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!node.drop) {
|
||||
var m = RED.util.cloneMessage(msg);
|
||||
delete m.flush;
|
||||
delete m.lifo;
|
||||
if (Object.keys(m).length > 1) {
|
||||
if (node.intervalID !== -1) {
|
||||
if (node.allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate)) && node.rate !== msg.rate) {
|
||||
node.rate = msg.rate;
|
||||
if (node.allowrate && m.hasOwnProperty("rate") && !isNaN(parseFloat(m.rate)) && node.rate !== m.rate) {
|
||||
node.rate = m.rate;
|
||||
clearInterval(node.intervalID);
|
||||
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
|
||||
}
|
||||
var max_msgs = maxKeptMsgsCount(node);
|
||||
if ((max_msgs > 0) && (node.buffer.length >= max_msgs)) {
|
||||
node.buffer = [];
|
||||
node.error(RED._("delay.errors.too-many"), msg);
|
||||
node.error(RED._("delay.errors.too-many"), m);
|
||||
} else if (msg.toFront === true) {
|
||||
node.buffer.unshift({msg: m, send: send, done: done});
|
||||
node.reportDepth();
|
||||
@@ -263,8 +249,8 @@ module.exports = function(RED) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (node.allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
|
||||
node.rate = msg.rate;
|
||||
if (node.allowrate && m.hasOwnProperty("rate") && !isNaN(parseFloat(m.rate))) {
|
||||
node.rate = m.rate;
|
||||
}
|
||||
send(m);
|
||||
node.reportDepth();
|
||||
@@ -282,6 +268,8 @@ module.exports = function(RED) {
|
||||
else {
|
||||
while (len > 0) {
|
||||
const msgInfo = node.buffer.shift();
|
||||
delete msgInfo.msg.flush;
|
||||
delete msgInfo.msg.reset;
|
||||
if (Object.keys(msgInfo.msg).length > 1) {
|
||||
node.send(msgInfo.msg);
|
||||
msgInfo.done();
|
||||
@@ -335,6 +323,21 @@ module.exports = function(RED) {
|
||||
}
|
||||
done();
|
||||
}
|
||||
|
||||
if (msg.hasOwnProperty("reset")) {
|
||||
if (msg.flush === undefined) {
|
||||
if (node.intervalID !== -1 ) {
|
||||
clearInterval(node.intervalID);
|
||||
node.intervalID = -1;
|
||||
}
|
||||
delete node.lastSent;
|
||||
}
|
||||
node.buffer = [];
|
||||
node.rate = node.fixedrate;
|
||||
node.status({fill:"blue",shape:"ring",text:0});
|
||||
done();
|
||||
return;
|
||||
}
|
||||
});
|
||||
node.on("close", function() {
|
||||
clearInterval(node.intervalID);
|
||||
@@ -387,6 +390,22 @@ module.exports = function(RED) {
|
||||
node.buffer.push({msg, send, done}); // if not add to end of queue
|
||||
node.reportDepth();
|
||||
}
|
||||
if (msg.hasOwnProperty("flush")) {
|
||||
var len = node.buffer.length;
|
||||
if (typeof(msg.flush) == 'number') { len = Math.min(Math.floor(msg.flush,len)); }
|
||||
while (len > 0) {
|
||||
const msgInfo = node.buffer.shift();
|
||||
delete msgInfo.msg.flush;
|
||||
delete msgInfo.msg.reset;
|
||||
if (Object.keys(msgInfo.msg).length > 2) {
|
||||
node.send(msgInfo.msg);
|
||||
msgInfo.done();
|
||||
}
|
||||
len = len - 1;
|
||||
}
|
||||
node.status({});
|
||||
done();
|
||||
}
|
||||
if (msg.hasOwnProperty("reset")) {
|
||||
while (node.buffer.length > 0) {
|
||||
const msgInfo = node.buffer.shift();
|
||||
@@ -397,21 +416,6 @@ module.exports = function(RED) {
|
||||
node.status({text:"reset"});
|
||||
done();
|
||||
}
|
||||
if (msg.hasOwnProperty("flush")) {
|
||||
var len = node.buffer.length;
|
||||
if (typeof(msg.flush) == 'number') { len = Math.min(Math.floor(msg.flush,len)); }
|
||||
while (len > 0) {
|
||||
const msgInfo = node.buffer.shift();
|
||||
delete msgInfo.msg.flush;
|
||||
if (Object.keys(msgInfo.msg).length > 2) {
|
||||
node.send(msgInfo.msg);
|
||||
msgInfo.done();
|
||||
}
|
||||
len = len - 1;
|
||||
}
|
||||
node.status({});
|
||||
done();
|
||||
}
|
||||
});
|
||||
node.on("close", function() {
|
||||
clearInterval(node.intervalID);
|
||||
|
@@ -25,7 +25,7 @@
|
||||
<select id="node-then-type" style="width:70%;">
|
||||
<option value="block" data-i18n="trigger.wait-reset"></option>
|
||||
<option value="wait" data-i18n="trigger.wait-for"></option>
|
||||
<option value="loop" data-i18n="trigger.wait-loop"></option>
|
||||
<option id="node-trigger-wait-loop" value="loop" data-i18n="trigger.wait-loop"></option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row node-type-duration">
|
||||
@@ -181,6 +181,13 @@
|
||||
$("#node-input-op2type").val('str');
|
||||
}
|
||||
|
||||
$("#node-input-op1").on("change", function() {
|
||||
if ($("#node-input-op1type").val() === "nul") {
|
||||
$("#node-trigger-wait-loop").hide();
|
||||
}
|
||||
else { $("#node-trigger-wait-loop").show(); }
|
||||
});
|
||||
|
||||
var optionNothing = {value:"nul",label:this._("trigger.output.nothing"),hasValue:false};
|
||||
var optionPayload = {value:"pay",label:this._("trigger.output.existing"),hasValue:false};
|
||||
var optionOriginalPayload = {value:"pay",label:this._("trigger.output.original"),hasValue:false};
|
||||
|
@@ -249,6 +249,12 @@
|
||||
<span id="node-config-input-cleansession-label" data-i18n="mqtt.label.cleansession"></span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-row mqtt-persistence">
|
||||
<label for="node-config-input-autoUnsubscribe" style="width: auto;">
|
||||
<input type="checkbox" id="node-config-input-autoUnsubscribe" style="position: relative;vertical-align: bottom; top: -2px; width: 15px;height: 15px;">
|
||||
<span id="node-config-input-autoUnsubscribe-label" data-i18n="mqtt.label.autoUnsubscribe"></span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-row mqtt5">
|
||||
<label style="width:auto" for="node-config-input-sessionExpiry"><span data-i18n="mqtt.label.sessionExpiry"></span></label>
|
||||
<input type="number" min="0" id="node-config-input-sessionExpiry" style="width: 100px" >
|
||||
@@ -483,17 +489,23 @@
|
||||
tls: {type:"tls-config",required: false,
|
||||
label:RED._("node-red:mqtt.label.use-tls") },
|
||||
clientid: {value:"", validate: function(v, opt) {
|
||||
var ok = false;
|
||||
let ok = true;
|
||||
if ($("#node-config-input-clientid").length) {
|
||||
// Currently editing the node
|
||||
ok = $("#node-config-input-cleansession").is(":checked") || (v||"").length > 0;
|
||||
let needClientId = !$("#node-config-input-cleansession").is(":checked") || !$("#node-config-input-autoUnsubscribe").is(":checked")
|
||||
if (needClientId) {
|
||||
ok = (v||"").length > 0;
|
||||
}
|
||||
} else {
|
||||
ok = (this.cleansession===undefined || this.cleansession) || (v||"").length > 0;
|
||||
let needClientId = !(this.cleansession===undefined || this.cleansession) || this.autoUnsubscribe;
|
||||
if (needClientId) {
|
||||
ok = (v||"").length > 0;
|
||||
}
|
||||
}
|
||||
if (ok) {
|
||||
return ok;
|
||||
if (!ok) {
|
||||
return RED._("node-red:mqtt.errors.invalid-client-id");
|
||||
}
|
||||
return RED._("node-red:mqtt.errors.invalid-client-id");
|
||||
return true;
|
||||
}},
|
||||
autoConnect: {value: true},
|
||||
usetls: {value: false},
|
||||
@@ -505,6 +517,7 @@
|
||||
label: RED._("node-red:mqtt.label.keepalive"),
|
||||
validate:RED.validators.number(false)},
|
||||
cleansession: {value: true},
|
||||
autoUnsubscribe: {value: true},
|
||||
birthTopic: {value:"", validate:validateMQTTPublishTopic},
|
||||
birthQos: {value:"0"},
|
||||
birthRetain: {value:"false"},
|
||||
@@ -620,6 +633,10 @@
|
||||
this.cleansession = true;
|
||||
$("#node-config-input-cleansession").prop("checked",true);
|
||||
}
|
||||
if (typeof this.autoUnsubscribe === 'undefined') {
|
||||
this.autoUnsubscribe = true;
|
||||
$("#node-config-input-autoUnsubscribe").prop("checked",true);
|
||||
}
|
||||
if (typeof this.usetls === 'undefined') {
|
||||
this.usetls = false;
|
||||
$("#node-config-input-usetls").prop("checked",false);
|
||||
@@ -635,6 +652,14 @@
|
||||
if (typeof this.protocolVersion === 'undefined') {
|
||||
this.protocolVersion = 4;
|
||||
}
|
||||
$("#node-config-input-cleansession").on("change", function() {
|
||||
const useCleanSession = $("#node-config-input-cleansession").is(':checked');
|
||||
if(useCleanSession) {
|
||||
$("div.form-row.mqtt-persistence").hide();
|
||||
} else {
|
||||
$("div.form-row.mqtt-persistence").show();
|
||||
}
|
||||
});
|
||||
$("#node-config-input-protocolVersion").on("change", function() {
|
||||
var v5 = $("#node-config-input-protocolVersion").val() == "5";
|
||||
if(v5) {
|
||||
|
@@ -482,6 +482,7 @@ module.exports = function(RED) {
|
||||
setIfHasProperty(opts, node, "protocolVersion", init);
|
||||
setIfHasProperty(opts, node, "keepalive", init);
|
||||
setIfHasProperty(opts, node, "cleansession", init);
|
||||
setIfHasProperty(opts, node, "autoUnsubscribe", init);
|
||||
setIfHasProperty(opts, node, "topicAliasMaximum", init);
|
||||
setIfHasProperty(opts, node, "maximumPacketSize", init);
|
||||
setIfHasProperty(opts, node, "receiveMaximum", init);
|
||||
@@ -590,6 +591,9 @@ module.exports = function(RED) {
|
||||
if (typeof node.cleansession === 'undefined') {
|
||||
node.cleansession = true;
|
||||
}
|
||||
if (typeof node.autoUnsubscribe === 'undefined') {
|
||||
node.autoUnsubscribe = true;
|
||||
}
|
||||
|
||||
//use url or build a url from usetls://broker:port
|
||||
if (node.url && node.brokerurl !== node.url) {
|
||||
@@ -660,6 +664,7 @@ module.exports = function(RED) {
|
||||
node.options.password = node.password;
|
||||
node.options.keepalive = node.keepalive;
|
||||
node.options.clean = node.cleansession;
|
||||
node.options.autoUnsubscribe = node.autoUnsubscribe;
|
||||
node.options.clientId = node.clientid || 'nodered_' + RED.util.generateId();
|
||||
node.options.reconnectPeriod = RED.settings.mqttReconnectTime||5000;
|
||||
delete node.options.protocolId; //V4+ default
|
||||
@@ -1234,12 +1239,16 @@ module.exports = function(RED) {
|
||||
node.on('close', function(removed, done) {
|
||||
if (node.brokerConn) {
|
||||
if(node.isDynamic) {
|
||||
Object.keys(node.dynamicSubs).forEach(function (topic) {
|
||||
node.brokerConn.unsubscribe(topic, node.id, removed);
|
||||
});
|
||||
node.dynamicSubs = {};
|
||||
if (node.brokerConn.options.autoUnsubscribe) {
|
||||
Object.keys(node.dynamicSubs).forEach(function (topic) {
|
||||
node.brokerConn.unsubscribe(topic, node.id, removed);
|
||||
});
|
||||
node.dynamicSubs = {};
|
||||
}
|
||||
} else {
|
||||
node.brokerConn.unsubscribe(node.topic,node.id, removed);
|
||||
if (node.brokerConn.options.autoUnsubscribe) {
|
||||
node.brokerConn.unsubscribe(node.topic, node.id, removed);
|
||||
}
|
||||
}
|
||||
node.brokerConn.deregister(node, done, removed);
|
||||
node.brokerConn = null;
|
||||
|
@@ -14,9 +14,9 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
module.exports = function(RED) {
|
||||
module.exports = async function(RED) {
|
||||
"use strict";
|
||||
const got = require("got");
|
||||
const { got } = await import('got')
|
||||
const {CookieJar} = require("tough-cookie");
|
||||
const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent');
|
||||
const FormData = require('form-data');
|
||||
@@ -210,24 +210,24 @@ in your Node-RED user directory (${RED.settings.userDir}).
|
||||
// set defaultport, else when using HttpsProxyAgent, it's defaultPort of 443 will be used :(.
|
||||
// Had to remove this to get http->https redirect to work
|
||||
// opts.defaultPort = isHttps?443:80;
|
||||
opts.timeout = node.reqTimeout;
|
||||
opts.timeout = { request: node.reqTimeout || 5000 };
|
||||
opts.throwHttpErrors = false;
|
||||
// TODO: add UI option to auto decompress. Setting to false for 1.x compatibility
|
||||
opts.decompress = false;
|
||||
opts.method = method;
|
||||
opts.retry = 0;
|
||||
opts.retry = { limit: 0 };
|
||||
opts.responseType = 'buffer';
|
||||
opts.maxRedirects = 21;
|
||||
opts.cookieJar = new CookieJar();
|
||||
opts.ignoreInvalidCookies = true;
|
||||
opts.forever = nodeHTTPPersistent;
|
||||
// opts.forever = nodeHTTPPersistent;
|
||||
if (msg.requestTimeout !== undefined) {
|
||||
if (isNaN(msg.requestTimeout)) {
|
||||
node.warn(RED._("httpin.errors.timeout-isnan"));
|
||||
} else if (msg.requestTimeout < 1) {
|
||||
node.warn(RED._("httpin.errors.timeout-isnegative"));
|
||||
} else {
|
||||
opts.timeout = msg.requestTimeout;
|
||||
opts.timeout = { request: msg.requestTimeout };
|
||||
}
|
||||
}
|
||||
const originalHeaderMap = {};
|
||||
@@ -245,9 +245,12 @@ in your Node-RED user directory (${RED.settings.userDir}).
|
||||
delete options.headers[h];
|
||||
}
|
||||
})
|
||||
|
||||
if (node.insecureHTTPParser) {
|
||||
options.insecureHTTPParser = true
|
||||
// Setting the property under _unixOptions as pretty
|
||||
// much the only hack available to get got to apply
|
||||
// a core http option it doesn't think we should be
|
||||
// allowed to set
|
||||
options._unixOptions = { ...options.unixOptions, insecureHTTPParser: true }
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -403,15 +406,16 @@ in your Node-RED user directory (${RED.settings.userDir}).
|
||||
return response
|
||||
}
|
||||
const requestUrl = new URL(response.request.requestUrl);
|
||||
const options = response.request.options;
|
||||
const options = { headers: {} }
|
||||
const normalisedHeaders = {};
|
||||
Object.keys(response.headers).forEach(k => {
|
||||
normalisedHeaders[k.toLowerCase()] = response.headers[k]
|
||||
})
|
||||
if (normalisedHeaders['www-authenticate']) {
|
||||
let authHeader = buildDigestHeader(digestCreds.user,digestCreds.password, options.method, requestUrl.pathname, normalisedHeaders['www-authenticate'])
|
||||
let authHeader = buildDigestHeader(digestCreds.user,digestCreds.password, response.request.options.method, requestUrl.pathname, normalisedHeaders['www-authenticate'])
|
||||
options.headers.Authorization = authHeader;
|
||||
}
|
||||
// response.request.options.merge(options)
|
||||
sentCreds = true;
|
||||
return retry(options);
|
||||
}
|
||||
@@ -699,25 +703,43 @@ in your Node-RED user directory (${RED.settings.userDir}).
|
||||
});
|
||||
|
||||
const md5 = (value) => { return crypto.createHash('md5').update(value).digest('hex') }
|
||||
const sha256 = (value) => { return crypto.createHash('sha256').update(value).digest('hex') }
|
||||
const sha512 = (value) => { return crypto.createHash('sha512').update(value).digest('hex') }
|
||||
|
||||
function digestCompute(algorithm, value) {
|
||||
var lowercaseAlgorithm = ""
|
||||
if (algorithm) {
|
||||
lowercaseAlgorithm = algorithm.toLowerCase().replace(/-sess$/, '')
|
||||
}
|
||||
|
||||
if (lowercaseAlgorithm === "sha-256") {
|
||||
return sha256(value)
|
||||
} else if (lowercaseAlgorithm === "sha-512-256") {
|
||||
var hash = sha512(value)
|
||||
return hash.slice(0, 64) // Only use the first 256 bits
|
||||
} else {
|
||||
return md5(value)
|
||||
}
|
||||
}
|
||||
|
||||
function ha1Compute(algorithm, user, realm, pass, nonce, cnonce) {
|
||||
/**
|
||||
* RFC 2617: handle both MD5 and MD5-sess algorithms.
|
||||
* RFC 2617: handle both standard and -sess algorithms.
|
||||
*
|
||||
* If the algorithm directive's value is "MD5" or unspecified, then HA1 is
|
||||
* HA1=MD5(username:realm:password)
|
||||
* If the algorithm directive's value is "MD5-sess", then HA1 is
|
||||
* HA1=MD5(MD5(username:realm:password):nonce:cnonce)
|
||||
* If the algorithm directive's value ends with "-sess", then HA1 is
|
||||
* HA1=digestCompute(digestCompute(username:realm:password):nonce:cnonce)
|
||||
*
|
||||
* If the algorithm directive's value does not end with "-sess", then HA1 is
|
||||
* HA1=digestCompute(username:realm:password)
|
||||
*/
|
||||
var ha1 = md5(user + ':' + realm + ':' + pass)
|
||||
if (algorithm && algorithm.toLowerCase() === 'md5-sess') {
|
||||
return md5(ha1 + ':' + nonce + ':' + cnonce)
|
||||
var ha1 = digestCompute(algorithm, user + ':' + realm + ':' + pass)
|
||||
if (algorithm && /-sess$/i.test(algorithm)) {
|
||||
return digestCompute(algorithm, ha1 + ':' + nonce + ':' + cnonce)
|
||||
} else {
|
||||
return ha1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function buildDigestHeader(user, pass, method, path, authHeader) {
|
||||
var challenge = {}
|
||||
var re = /([a-z0-9_-]+)=(?:"([^"]+)"|([a-z0-9_-]+))/gi
|
||||
@@ -732,10 +754,10 @@ in your Node-RED user directory (${RED.settings.userDir}).
|
||||
var nc = qop && '00000001'
|
||||
var cnonce = qop && uuid().replace(/-/g, '')
|
||||
var ha1 = ha1Compute(challenge.algorithm, user, challenge.realm, pass, challenge.nonce, cnonce)
|
||||
var ha2 = md5(method + ':' + path)
|
||||
var ha2 = digestCompute(challenge.algorithm, method + ':' + path)
|
||||
var digestResponse = qop
|
||||
? md5(ha1 + ':' + challenge.nonce + ':' + nc + ':' + cnonce + ':' + qop + ':' + ha2)
|
||||
: md5(ha1 + ':' + challenge.nonce + ':' + ha2)
|
||||
? digestCompute(challenge.algorithm, ha1 + ':' + challenge.nonce + ':' + nc + ':' + cnonce + ':' + qop + ':' + ha2)
|
||||
: digestCompute(challenge.algorithm, ha1 + ':' + challenge.nonce + ':' + ha2)
|
||||
var authValues = {
|
||||
username: user,
|
||||
realm: challenge.realm,
|
||||
|
@@ -86,7 +86,7 @@ module.exports = function(RED) {
|
||||
this.topic = n.topic;
|
||||
this.stream = (!n.datamode||n.datamode=='stream'); /* stream,single*/
|
||||
this.datatype = n.datatype||'buffer'; /* buffer,utf8,base64 */
|
||||
this.newline = (n.newline||"").replace("\\n","\n").replace("\\r","\r").replace("\\t","\t");
|
||||
this.newline = (n.newline||"").replace(/\\n/g,"\n").replace(/\\r/g,"\r").replace(/\\t/g,"\t");
|
||||
this.base64 = n.base64;
|
||||
this.trim = n.trim || false;
|
||||
this.server = (typeof n.server == 'boolean')?n.server:(n.server == "server");
|
||||
|
@@ -19,9 +19,9 @@ module.exports = function(RED) {
|
||||
function CSVNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.template = (n.temp || "");
|
||||
this.sep = (n.sep || ',').replace("\\t","\t").replace("\\n","\n").replace("\\r","\r");
|
||||
this.sep = (n.sep || ',').replace(/\\t/g,"\t").replace(/\\n/g,"\n").replace(/\\r/g,"\r");
|
||||
this.quo = '"';
|
||||
this.ret = (n.ret || "\n").replace("\\n","\n").replace("\\r","\r");
|
||||
this.ret = (n.ret || "\n").replace(/\\n/g,"\n").replace(/\\r/g,"\r");
|
||||
this.winflag = (this.ret === "\r\n");
|
||||
this.lineend = "\n";
|
||||
this.multi = n.multi || "one";
|
||||
|
@@ -33,7 +33,13 @@ module.exports = function(RED) {
|
||||
parseString(value, options, function (err, result) {
|
||||
if (err) { done(err); }
|
||||
else {
|
||||
value = result;
|
||||
// TODO: With xml2js@0.5.0, they return an object with
|
||||
// a null prototype. This could cause unexpected
|
||||
// issues. So for now, we have to reconstruct
|
||||
// the object with a proper prototype.
|
||||
// Once https://github.com/Leonidas-from-XIV/node-xml2js/pull/674
|
||||
// is merged, we can revisit and hopefully remove this hack
|
||||
value = fixObj(result)
|
||||
RED.util.setMessageProperty(msg,node.property,value);
|
||||
send(msg);
|
||||
done();
|
||||
@@ -46,4 +52,18 @@ module.exports = function(RED) {
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("xml",XMLNode);
|
||||
|
||||
|
||||
function fixObj(obj) {
|
||||
const res = {}
|
||||
const keys = Object.keys(obj)
|
||||
keys.forEach(k => {
|
||||
if (typeof obj[k] === 'object' && obj[k]) {
|
||||
res[k] = fixObj(obj[k])
|
||||
} else {
|
||||
res[k] = obj[k]
|
||||
}
|
||||
})
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
@@ -224,7 +224,12 @@
|
||||
outputs:1,
|
||||
icon: "join.svg",
|
||||
label: function() {
|
||||
return this.name||this._("join.join");
|
||||
var nam = this.name||this._("join.join");
|
||||
if (this.mode === "custom" && !isNaN(Number(this.count))) {
|
||||
nam += " "+this.count;
|
||||
if (this.accumulate === true) { nam+= "+"; }
|
||||
}
|
||||
return nam;
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
|
@@ -478,7 +478,7 @@ module.exports = function(RED) {
|
||||
var completeSend = function(partId) {
|
||||
var group = inflight[partId];
|
||||
if (group.timeout) { clearTimeout(group.timeout); }
|
||||
if ((node.accumulate !== true) || group.msg.hasOwnProperty("complete")) { delete inflight[partId]; }
|
||||
if (node.mode === 'auto' || node.accumulate !== true || group.msg.hasOwnProperty("complete")) { delete inflight[partId]; }
|
||||
if (group.type === 'array' && group.arrayLen > 1) {
|
||||
var newArray = [];
|
||||
group.payload.forEach(function(n) {
|
||||
|
@@ -107,7 +107,14 @@
|
||||
outputs:1,
|
||||
icon: "batch.svg",
|
||||
label: function() {
|
||||
return this.name||this._("batch.batch");;
|
||||
var nam = this.name||this._("batch.batch");
|
||||
if (this.mode === "count" && !isNaN(Number(this.count))) {
|
||||
nam += " "+this.count;
|
||||
}
|
||||
if (this.mode === "interval" && !isNaN(Number(this.interval))) {
|
||||
nam += " "+this.interval+"s";
|
||||
}
|
||||
return nam;
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name ? "node_label_italic" : "";
|
||||
|
Reference in New Issue
Block a user