mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
TCP add tls option to inbound nodes
This commit is contained in:
parent
0937837b7f
commit
6692b1992c
@ -93,10 +93,8 @@
|
|||||||
var sockettype = $("#node-input-server").val();
|
var sockettype = $("#node-input-server").val();
|
||||||
if (sockettype == "client") {
|
if (sockettype == "client") {
|
||||||
$("#node-input-host-row").show();
|
$("#node-input-host-row").show();
|
||||||
$("#node-input-tls-enable").show();
|
|
||||||
} else {
|
} else {
|
||||||
$("#node-input-host-row").hide();
|
$("#node-input-host-row").hide();
|
||||||
$("#node-input-tls-enable").hide();
|
|
||||||
}
|
}
|
||||||
var datamode = $("#node-input-datamode").val();
|
var datamode = $("#node-input-datamode").val();
|
||||||
var datatype = $("#node-input-datatype").val();
|
var datatype = $("#node-input-datatype").val();
|
||||||
@ -222,7 +220,7 @@
|
|||||||
$("#node-input-port-row").show();
|
$("#node-input-port-row").show();
|
||||||
$("#node-input-host-row").hide();
|
$("#node-input-host-row").hide();
|
||||||
$("#node-input-end-row").show();
|
$("#node-input-end-row").show();
|
||||||
$("#node-input-tls-enable").hide();
|
$("#node-input-tls-enable").show();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
updateOptions();
|
updateOptions();
|
||||||
@ -269,7 +267,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-out"><i class="fa fa-sign-out"></i> <span data-i18n="tcpin.label.return"></span></label>
|
<label for="node-input-ret"><i class="fa fa-sign-out"></i> <span data-i18n="tcpin.label.return"></span></label>
|
||||||
<select type="text" id="node-input-ret" style="width:54%;">
|
<select type="text" id="node-input-ret" style="width:54%;">
|
||||||
<option value="buffer" data-i18n="tcpin.output.buffer"></option>
|
<option value="buffer" data-i18n="tcpin.output.buffer"></option>
|
||||||
<option value="string" data-i18n="tcpin.output.string"></option>
|
<option value="string" data-i18n="tcpin.output.string"></option>
|
||||||
|
@ -93,7 +93,6 @@ module.exports = function(RED) {
|
|||||||
this.connected = false;
|
this.connected = false;
|
||||||
var node = this;
|
var node = this;
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var nlstr = (this.newline && !this.newline.trim()) ? false : true;
|
|
||||||
if (n.tls) { var tlsNode = RED.nodes.getNode(n.tls); }
|
if (n.tls) { var tlsNode = RED.nodes.getNode(n.tls); }
|
||||||
|
|
||||||
if (!node.server) {
|
if (!node.server) {
|
||||||
@ -105,8 +104,7 @@ module.exports = function(RED) {
|
|||||||
node.log(RED._("tcpin.status.connecting",{host:node.host,port:node.port}));
|
node.log(RED._("tcpin.status.connecting",{host:node.host,port:node.port}));
|
||||||
node.status({fill:"grey",shape:"dot",text:"common.status.connecting"});
|
node.status({fill:"grey",shape:"dot",text:"common.status.connecting"});
|
||||||
var id = RED.util.generateId();
|
var id = RED.util.generateId();
|
||||||
var connOpts = {host: node.host
|
var connOpts = {host: node.host};
|
||||||
};
|
|
||||||
if (n.tls) {
|
if (n.tls) {
|
||||||
var connOpts = tlsNode.addTLSOptions({host: node.host});
|
var connOpts = tlsNode.addTLSOptions({host: node.host});
|
||||||
client = tls.connect(node.port, connOpts, function() {
|
client = tls.connect(node.port, connOpts, function() {
|
||||||
@ -137,8 +135,7 @@ module.exports = function(RED) {
|
|||||||
buffer = buffer+data;
|
buffer = buffer+data;
|
||||||
var parts = buffer.split(node.newline);
|
var parts = buffer.split(node.newline);
|
||||||
for (var i = 0; i<parts.length-1; i+=1) {
|
for (var i = 0; i<parts.length-1; i+=1) {
|
||||||
if (nlstr) { parts[i] += node.newline; }
|
msg = {topic:node.topic, payload:parts[i] + node.newline.trimEnd()};
|
||||||
msg = {topic:node.topic, payload:parts[i]};
|
|
||||||
msg._session = {type:"tcp",id:id};
|
msg._session = {type:"tcp",id:id};
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
@ -199,7 +196,13 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var server = net.createServer(function (socket) {
|
let srv = net;
|
||||||
|
let connOpts;
|
||||||
|
if (n.tls) {
|
||||||
|
srv = tls;
|
||||||
|
connOpts = tlsNode.addTLSOptions({});
|
||||||
|
}
|
||||||
|
var server = srv.createServer(connOpts, function (socket) {
|
||||||
socket.setKeepAlive(true,120000);
|
socket.setKeepAlive(true,120000);
|
||||||
if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
|
if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
|
||||||
var id = RED.util.generateId();
|
var id = RED.util.generateId();
|
||||||
@ -431,7 +434,13 @@ module.exports = function(RED) {
|
|||||||
else {
|
else {
|
||||||
var connectedSockets = [];
|
var connectedSockets = [];
|
||||||
node.status({text:RED._("tcpin.status.connections",{count:0})});
|
node.status({text:RED._("tcpin.status.connections",{count:0})});
|
||||||
var server = net.createServer(function (socket) {
|
let srv = net;
|
||||||
|
let connOpts;
|
||||||
|
if (n.tls) {
|
||||||
|
srv = tls;
|
||||||
|
connOpts = tlsNode.addTLSOptions({});
|
||||||
|
}
|
||||||
|
var server = srv.createServer(connOpts, function (socket) {
|
||||||
socket.setKeepAlive(true,120000);
|
socket.setKeepAlive(true,120000);
|
||||||
if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
|
if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
|
||||||
node.log(RED._("tcpin.status.connection-from",{host:socket.remoteAddress, port:socket.remotePort}));
|
node.log(RED._("tcpin.status.connection-from",{host:socket.remoteAddress, port:socket.remotePort}));
|
||||||
|
Loading…
Reference in New Issue
Block a user