mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Updated xmpp node to use config node instead of additional creds file.
This commit is contained in:
parent
2f83f71ace
commit
eddf21af74
@ -74,7 +74,7 @@
|
|||||||
outputs:2,
|
outputs:2,
|
||||||
icon: "xmpp.png",
|
icon: "xmpp.png",
|
||||||
label: function() {
|
label: function() {
|
||||||
return this.name||this.server||"xmpp";
|
return this.name||"xmpp";
|
||||||
},
|
},
|
||||||
labelStyle: function() {
|
labelStyle: function() {
|
||||||
return (this.name||!this.server)?"node_label_italic":"";
|
return (this.name||!this.server)?"node_label_italic":"";
|
||||||
@ -85,7 +85,7 @@
|
|||||||
<script type="text/x-red" data-template-name="xmpp-server">
|
<script type="text/x-red" data-template-name="xmpp-server">
|
||||||
<div class="form-row node-input-server">
|
<div class="form-row node-input-server">
|
||||||
<label for="node-config-input-server"><i class="icon-bookmark"></i> Server</label>
|
<label for="node-config-input-server"><i class="icon-bookmark"></i> Server</label>
|
||||||
<input class="input-append-left" type="text" id="node-config-input-server" placeholder="Server" style="width: 40%;" >
|
<input class="input-append-left" type="text" id="node-config-input-server" placeholder="localhost" style="width: 40%;" >
|
||||||
<label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
|
<label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
|
||||||
<input type="text" id="node-config-input-port" placeholder="Port" style="width:45px">
|
<input type="text" id="node-config-input-port" placeholder="Port" style="width:45px">
|
||||||
</div>
|
</div>
|
||||||
@ -103,12 +103,10 @@
|
|||||||
RED.nodes.registerType('xmpp-server',{
|
RED.nodes.registerType('xmpp-server',{
|
||||||
category: 'config',
|
category: 'config',
|
||||||
defaults: {
|
defaults: {
|
||||||
server: {value:"localhost",required:true},
|
server: {required:true},
|
||||||
port: {value:5222,required:true,validate:RED.validators.number()},
|
port: {value:5222,required:true,validate:RED.validators.number()},
|
||||||
user: {required:true},
|
user: {required:true},
|
||||||
pass: {required:true}
|
pass: {required:true}
|
||||||
//user -> credentials
|
|
||||||
//pass -> credentials
|
|
||||||
|
|
||||||
},
|
},
|
||||||
label: function() {
|
label: function() {
|
||||||
@ -119,6 +117,12 @@
|
|||||||
if (data.user) {
|
if (data.user) {
|
||||||
$('#node-config-input-user').val(data.user);
|
$('#node-config-input-user').val(data.user);
|
||||||
}
|
}
|
||||||
|
if (data.server) {
|
||||||
|
$('#node-config-input-server').val(data.server);
|
||||||
|
}
|
||||||
|
if (data.port) {
|
||||||
|
$('#node-config-input-port').val(data.port);
|
||||||
|
}
|
||||||
if (data.hasPassword) {
|
if (data.hasPassword) {
|
||||||
$('#node-config-input-pass').val('__PWRD__');
|
$('#node-config-input-pass').val('__PWRD__');
|
||||||
} else {
|
} else {
|
||||||
@ -130,11 +134,15 @@
|
|||||||
oneditsave: function() {
|
oneditsave: function() {
|
||||||
var newUser = $('#node-config-input-user').val();
|
var newUser = $('#node-config-input-user').val();
|
||||||
var newPass = $('#node-config-input-pass').val();
|
var newPass = $('#node-config-input-pass').val();
|
||||||
|
//var newServer = $('#node-config-input-server').val();
|
||||||
|
//var newPort = $('#node-config-input-port').val();
|
||||||
var credentials = {};
|
var credentials = {};
|
||||||
credentials.user = newUser;
|
credentials.user = newUser;
|
||||||
if (newPass != '__PWRD__') {
|
if (newPass != '__PWRD__') {
|
||||||
credentials.password = newPass;
|
credentials.password = newPass;
|
||||||
}
|
}
|
||||||
|
//credentials.server = newServer;
|
||||||
|
//credentials.port = newPort;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'xmpp-server/'+this.id,
|
url: 'xmpp-server/'+this.id,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
|
@ -22,16 +22,16 @@ console.warn=(function() { // suppress warning from stringprep when not needed)
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||||
|
var xmpp = require('simple-xmpp');
|
||||||
|
console.warn = orig;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var xmppkey = RED.settings.xmpp || require(process.env.NODE_RED_HOME+"/../xmppkeys.js");
|
var xmppkey = RED.settings.xmpp || require(process.env.NODE_RED_HOME+"/../xmppkeys.js");
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
// throw new Error("Failed to load XMPP credentials");
|
// throw new Error("Failed to load XMPP credentials");
|
||||||
}
|
}
|
||||||
|
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
|
||||||
var xmpp = require('simple-xmpp');
|
|
||||||
console.warn = orig;
|
|
||||||
|
|
||||||
function XMPPServerNode(n) {
|
function XMPPServerNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.server = n.server;
|
this.server = n.server;
|
||||||
@ -50,6 +50,10 @@ RED.httpAdmin.get('/xmpp-server/:id',function(req,res) {
|
|||||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||||
if (credentials) {
|
if (credentials) {
|
||||||
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")}));
|
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")}));
|
||||||
|
} else if (xmppkey && xmppkey.jid && xmppkey.password) {
|
||||||
|
RED.nodes.addCredentials(req.params.id,{user:xmppkey.jid,password:xmppkey.password});
|
||||||
|
credentials = RED.nodes.getCredentials(req.params.id);
|
||||||
|
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")}));
|
||||||
} else {
|
} else {
|
||||||
res.send(JSON.stringify({}));
|
res.send(JSON.stringify({}));
|
||||||
}
|
}
|
||||||
@ -87,14 +91,21 @@ RED.httpAdmin.post('/xmpp-server/:id',function(req,res) {
|
|||||||
function XmppNode(n) {
|
function XmppNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.server = n.server;
|
this.server = n.server;
|
||||||
this.serverConfig = RED.nodes.getNode(this.server);
|
try {
|
||||||
|
this.serverConfig = RED.nodes.getNode(this.server);
|
||||||
|
} catch (err) {
|
||||||
|
}
|
||||||
if (this.serverConfig){
|
if (this.serverConfig){
|
||||||
this.host = this.serverConfig.server;
|
this.host = this.serverConfig.server;
|
||||||
this.port = this.serverConfig.port;
|
this.port = this.serverConfig.port;
|
||||||
this.jid = this.serverConfig.username;
|
this.jid = this.serverConfig.username;
|
||||||
this.password = this.serverConfig.password;
|
this.password = this.serverConfig.password;
|
||||||
} else {
|
} else if (xmppkey) {
|
||||||
console.log("no serverConfig found");
|
console.warn("no serverConfig found, trying old creds file");
|
||||||
|
this.host = n.server;
|
||||||
|
this.port = n.port;
|
||||||
|
this.jid = xmppkey.jid;
|
||||||
|
this.password = xmppkey.password;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.join = n.join || false;
|
this.join = n.join || false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user