mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Merge pull request #138 from d4rr3ll/master
Username and password server credentials. Thanks @d4rr3ll
This commit is contained in:
commit
a0ff123673
@ -92,6 +92,10 @@
|
||||
ircserver: {type:"irc-server", required:true},
|
||||
channel: {value:"",required:true,validate:RED.validators.regex(/^#/)}
|
||||
},
|
||||
credentials: {
|
||||
username: {type:"text"},
|
||||
password: {type:"password"}
|
||||
},
|
||||
color:"Silver",
|
||||
inputs:0,
|
||||
outputs:2,
|
||||
@ -200,6 +204,14 @@
|
||||
<label for="node-config-input-nickname"><i class="fa fa-user"></i> <span data-i18n="irc.label.nickname"></span></label>
|
||||
<input type="text" id="node-config-input-nickname">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-username"><i class="fa fa-user"></i> <span data-i18n="irc.label.username"></span></label>
|
||||
<input type="text" id="node-config-input-username">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-password"><i class="fa fa-lock"></i> <span data-i18n="irc.label.password"></span></label>
|
||||
<input type="text" id="node-config-input-password">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -212,6 +224,10 @@
|
||||
cert: {value:false},
|
||||
nickname: {value:"",required:true}
|
||||
},
|
||||
credentials: {
|
||||
username: {type:"text"},
|
||||
password: {type:"password"}
|
||||
},
|
||||
label: function() {
|
||||
return this.server;
|
||||
},
|
||||
|
@ -18,6 +18,7 @@ module.exports = function(RED) {
|
||||
"use strict";
|
||||
var irc = require("irc");
|
||||
|
||||
|
||||
// The Server Definition - this opens (and closes) the connection
|
||||
function IRCServerNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
@ -35,8 +36,23 @@ module.exports = function(RED) {
|
||||
this.ircclient.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
this.username = null;
|
||||
this.password = null;
|
||||
if (this.credentials && this.credentials.hasOwnProperty("username")) {
|
||||
this.username = this.credentials.username;
|
||||
}
|
||||
if (this.credentials && this.credentials.hasOwnProperty("password")) {
|
||||
this.password = this.credentials.password;
|
||||
}
|
||||
|
||||
}
|
||||
RED.nodes.registerType("irc-server",IRCServerNode);
|
||||
RED.nodes.registerType("irc-server",IRCServerNode, {
|
||||
credentials: {
|
||||
username: {type:"text"},
|
||||
password: {type:"password"}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// The Input Node
|
||||
@ -47,9 +63,11 @@ module.exports = function(RED) {
|
||||
this.channel = n.channel || this.serverConfig.channel;
|
||||
var node = this;
|
||||
if (node.serverConfig.ircclient === null) {
|
||||
node.log(RED._("irc.errors.connect")+": "+node.serverConfig.server);
|
||||
node.log(RED._("irc.errors.connect")+": "+node.serverConfig.server+" "+node.serverConfig.username+" "+node.serverConfig.ssl);
|
||||
node.status({fill:"grey",shape:"dot",text:"node-red:common.status.connecting"});
|
||||
var options = {autoConnect:true,autoRejoin:false,floodProtection:true,secure:node.serverConfig.ssl,selfSigned:node.serverConfig.cert,port:node.serverConfig.port,retryDelay:20000};
|
||||
if (node.serverConfig.username !== null) { options["userName"] = node.serverConfig.username }
|
||||
if (node.serverConfig.password !== null) { options["password"] = node.serverConfig.password }
|
||||
node.serverConfig.ircclient = new irc.Client(node.serverConfig.server, node.serverConfig.nickname, options);
|
||||
node.serverConfig.ircclient.setMaxListeners(0);
|
||||
node.serverConfig.ircclient.addListener('error', function(message) {
|
||||
@ -185,6 +203,8 @@ module.exports = function(RED) {
|
||||
node.log(RED._("irc.errors.connect")+": "+node.serverConfig.server);
|
||||
node.status({fill:"grey",shape:"dot",text:"node-red:common.status.connecting"});
|
||||
var options = {autoConnect:true,autoRejoin:false,floodProtection:true,secure:node.serverConfig.ssl,selfSigned:node.serverConfig.cert,port:node.serverConfig.port,retryDelay:20000};
|
||||
if (node.serverConfig.username !== null) { options['userName'] = node.serverConfig.username }
|
||||
if (node.serverConfig.password !== null) { options['password'] = node.serverConfig.password }
|
||||
node.serverConfig.ircclient = new irc.Client(node.serverConfig.server, node.serverConfig.nickname, options);
|
||||
node.serverConfig.ircclient.setMaxListeners(0);
|
||||
node.serverConfig.ircclient.addListener('error', function(message) {
|
||||
|
@ -7,7 +7,9 @@
|
||||
"port": "Port",
|
||||
"ssl": "Use Secure SSL connection?",
|
||||
"self": "Allow self-signed certificates?",
|
||||
"nickname": "Nickname"
|
||||
"nickname": "Nickname",
|
||||
"username": "Server username",
|
||||
"password": "Server password"
|
||||
},
|
||||
"payload": "Send payload to channel(s)",
|
||||
"topic": "Use msg.topic to set nickname or channel(s)",
|
||||
@ -36,4 +38,4 @@
|
||||
"topicnotset": "msg.topic not set"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
{
|
||||
"name" : "node-red-node-irc",
|
||||
"version" : "0.0.3",
|
||||
"version" : "0.0.4",
|
||||
"description" : "A Node-RED node to talk to an IRC server",
|
||||
"dependencies" : {
|
||||
"irc" : "0.3.11"
|
||||
"irc" : "~0.4.0"
|
||||
},
|
||||
"repository" : {
|
||||
"type":"git",
|
||||
|
Loading…
Reference in New Issue
Block a user