Update all nodes to credentials system and auth middleware

This commit is contained in:
Nick O'Leary
2015-02-06 21:10:14 +00:00
parent f4fdebfba5
commit 08791f1914
29 changed files with 177 additions and 783 deletions

View File

@@ -44,6 +44,9 @@
title: {value:""},
name: {value:""}
},
credentials: {
pushkey: {type: "password"}
},
color:"#a7c9a0",
inputs:1,
outputs:0,
@@ -54,35 +57,6 @@
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
$.getJSON('nma/'+this.id,function(data) {
if (data.hasPassword) {
$('#node-config-input-pushkey').val('__PWRD__');
} else {
$('#node-config-input-pushkey').val('');
}
});
},
oneditsave: function() {
var credentials = {};
var newPass = $('#node-config-input-pushkey').val();
if (newPass != '__PWRD__') {
credentials.pushkey = newPass;
$.ajax({
url: 'nma/'+this.id,
type: 'POST',
data: credentials,
success: function(result){}
});
}
},
ondelete: function() {
$.ajax({
url: 'nma/'+this.id,
type: 'DELETE',
success: function(result) {}
});
}
});
</script>

View File

@@ -21,7 +21,7 @@ module.exports = function(RED) {
function NMANode(n) {
RED.nodes.createNode(this,n);
this.title = n.title;
var credentials = RED.nodes.getCredentials(n.id);
var credentials = this.credentials;
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
else { this.error("No NMA API key set"); }
var node = this;
@@ -50,39 +50,9 @@ module.exports = function(RED) {
});
}
RED.nodes.registerType("nma",NMANode);
var querystring = require('querystring');
RED.httpAdmin.get('/nma/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
} else {
res.send(JSON.stringify({}));
RED.nodes.registerType("nma",NMANode, {
credentials: {
pushkey: {type: "password"}
}
});
RED.httpAdmin.delete('/nma/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
RED.httpAdmin.post('/nma/:id',function(req,res) {
var body = "";
req.on('data', function(chunk) {
body+=chunk;
});
req.on('end', function(){
var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.pushkey === "") {
delete credentials.pushkey;
} else {
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
}
RED.nodes.addCredentials(req.params.id,credentials);
res.send(200);
});
});
}

View File

@@ -1,6 +1,6 @@
{
"name" : "node-red-node-nma",
"version" : "0.0.2",
"version" : "0.0.3",
"description" : "A Node-RED node to send alerts via Notify-My-Android",
"dependencies" : {
"nma" : "0.2.2"

View File

@@ -32,7 +32,6 @@
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-tips" id="node-tip"><b>Note:</b> Using credentials from global pushkey.js file.</div>
</script>
<script type="text/x-red" data-help-name="prowl">
@@ -52,6 +51,9 @@
priority: {value:0,required:true,validate:RED.validators.number()},
name: {value:""}
},
credentials: {
pushkey: {type: "password"}
}
color:"#a7c9a0",
inputs:1,
outputs:0,
@@ -62,37 +64,6 @@
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
$.getJSON('prowl/'+this.id,function(data) {
if (data.hasPassword) {
$('#node-config-input-pushkey').val('__PWRD__');
} else {
$('#node-config-input-pushkey').val('');
}
if (data.global) $('#node-tip').show();
else $('#node-tip').hide();
});
},
oneditsave: function() {
var credentials = {};
var newPass = $('#node-config-input-pushkey').val();
if (newPass != '__PWRD__') {
credentials.pushkey = newPass;
$.ajax({
url: 'prowl/'+this.id,
type: 'POST',
data: credentials,
success: function(result){}
});
}
},
ondelete: function() {
$.ajax({
url: 'prowl/'+this.id,
type: 'DELETE',
success: function(result) {}
});
}
});
</script>

View File

@@ -18,11 +18,6 @@ module.exports = function(RED) {
"use strict";
var Prowl = require('node-prowl');
// Either add a line like this to settings.js
// prowl: {prowlkey:'My-API-KEY'},
// or create pushkey.js in dir ABOVE node-red, it just needs to be like
// module.exports = {prowlkey:'My-API-KEY'}
try {
var pushkeys = RED.settings.prowl || require(process.env.NODE_RED_HOME+"/../pushkey.js");
}
@@ -34,7 +29,7 @@ module.exports = function(RED) {
this.priority = parseInt(n.priority);
if (this.priority > 2) { this.priority = 2; }
if (this.priority < -2) { this.priority = -2; }
var credentials = RED.nodes.getCredentials(n.id);
var credentials = this.credentials;
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
else {
if (pushkeys) { this.pushkey = pushkeys.prowlkey; }
@@ -67,45 +62,9 @@ module.exports = function(RED) {
}
});
}
RED.nodes.registerType("prowl",ProwlNode);
var querystring = require('querystring');
RED.httpAdmin.get('/prowl/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
RED.nodes.registerType("prowl",ProwlNode,{
credentials: {
pushkey: {type: "password"}
}
else if (pushkeys && pushkeys.prowlkey) {
RED.nodes.addCredentials(req.params.id,{pushkey:pushkeys.prowlkey,global:true});
credentials = RED.nodes.getCredentials(req.params.id);
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!==""),global:credentials.global}));
}
else {
res.send(JSON.stringify({}));
}
});
RED.httpAdmin.delete('/prowl/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
RED.httpAdmin.post('/prowl/:id',function(req,res) {
var body = "";
req.on('data', function(chunk) {
body+=chunk;
});
req.on('end', function(){
var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.pushkey === "") {
delete credentials.pushkey;
} else {
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
}
RED.nodes.addCredentials(req.params.id,credentials);
res.send(200);
});
});
}

View File

@@ -1,6 +1,6 @@
{
"name" : "node-red-node-prowl",
"version" : "0.0.1",
"version" : "0.0.2",
"description" : "A Node-RED node to send alerts via Prowl",
"dependencies" : {
"node-prowl" : "0.1.7"

View File

@@ -1,6 +1,6 @@
<!--
Copyright 2014 Charalampos Doukas, @BuildingIoT
Copyright 2014, 2015 Charalampos Doukas, @BuildingIoT
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
</div>
<div class="form-row">
<label for="node-input-appkey_sub"><i class="fa fa-lock"></i> App Key</label>
<input type="text" id="node-input-appkey_sub" placeholder="key">
<input type="text" id="node-input-pusherappkey_sub" placeholder="key">
</div>
<div class="form-row">
@@ -51,6 +51,9 @@
channel: {value:"", required:true},
eventname: {value:"", required:true}
},
credentials: {
pusherappkey_sub: "text"
},
inputs:0, // set the number of inputs - only 0 or 1
outputs:1, // set the number of outputs - 0 to n
icon: "pusher.png", // set the icon (held in public/icons)
@@ -59,31 +62,6 @@
},
labelStyle: function() { // sets the class to apply to the label
return this.name?"node_label_italic":"";
},
oneditsave: function() {
var credentials = {};
var newAppKey_sub = $('#node-input-appkey_sub').val();
credentials.pusherappkey_sub = newAppKey_sub;
$.ajax({
url: 'pusher/'+this.id,
type: 'POST',
data: credentials,
success: function(result){}
});
},
oneditprepare: function() {
$.getJSON('pusher/'+this.id,function(data) {
if (data.pusherappkey_sub) {
$('#node-input-appkey_sub').val(data.pusherappkey_sub);
}
});
},
ondelete: function() {
$.ajax({
url: 'pusher/'+this.id,
type: 'DELETE',
success: function(result) {}
});
}
});
</script>
@@ -101,17 +79,17 @@
<div class="form-row">
<label for="node-input-appid"><i class="fa fa-tag"></i> App ID</label>
<input type="text" id="node-input-appid" placeholder="app_id">
<input type="text" id="node-input-pusherappid" placeholder="app_id">
</div>
<div class="form-row">
<label for="node-input-appkey"><i class="fa fa-lock"></i> App Key</label>
<input type="text" id="node-input-appkey" placeholder="key">
<input type="text" id="node-input-pusherappkey" placeholder="key">
</div>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-asterisk"></i> App Secret</label>
<input type="password" id="node-input-appsecret" placeholder="secret">
<input type="password" id="node-input-pusherappsecret" placeholder="secret">
</div>
<div class="form-row">
@@ -135,6 +113,11 @@
channel: {value:"", required:true},
eventname: {value:"", required:true}
},
credentials: {
pusherappid: {type:"text"},
pusherappkey: {type:"text"},
pusherappsecret: {type:"password"}
},
inputs:1, // set the number of inputs - only 0 or 1
outputs:0, // set the number of outputs - 0 to n
icon: "pusher.png", // set the icon (held in public/icons)
@@ -144,41 +127,6 @@
},
labelStyle: function() { // sets the class to apply to the label
return this.name?"node_label_italic":"";
},
oneditsave: function() {
var credentials = {};
var newAppID = $('#node-input-appid').val();
var newAppKey = $('#node-input-appkey').val();
var newAppSecret = $('#node-input-appsecret').val();
credentials.pusherappid = newAppID;
credentials.pusherappkey = newAppKey;
credentials.pusherappsecret = newAppSecret;
$.ajax({
url: 'pusher/'+this.id,
type: 'POST',
data: credentials,
success: function(result){}
});
},
oneditprepare: function() {
$.getJSON('pusher/'+this.id,function(data) {
if (data.pusherappid) {
$('#node-input-appid').val(data.pusherappid);
}
if (data.pusherappkey) {
$('#node-input-appkey').val(data.pusherappkey);
}
if (data.pusherappsecret) {
$('#node-input-appsecret').val(data.pusherappsecret);
}
});
},
ondelete: function() {
$.ajax({
url: 'pusher/'+this.id,
type: 'DELETE',
success: function(result) {}
});
}
});
</script>

View File

@@ -3,7 +3,7 @@
* Subscription module for the Pusher service (www.pusher.com)
* Requires 'pusher' and 'pusher-client' modules.
*
* Copyright 2014 Charalampos Doukas, @BuildingIoT
* Copyright 2014, 2015 Charalampos Doukas, @BuildingIoT
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ module.exports = function(RED) {
RED.nodes.createNode(this,n);
var node = this;
var credentials = RED.nodes.getCredentials(n.id);
var credentials = this.credentials;
if ((credentials) && (credentials.hasOwnProperty("pusherappkey_sub"))) { this.appkey = credentials.pusherappkey_sub; }
else { this.error("No Pusher app key set for input node"); }
@@ -61,7 +61,7 @@ module.exports = function(RED) {
var node = this;
var credentials = RED.nodes.getCredentials(n.id);
var credentials = this.credentials;
if ((credentials) && (credentials.hasOwnProperty("pusherappid"))) { this.appid = credentials.pusherappid; }
else { this.error("No Pusher api token set"); }
@@ -99,59 +99,16 @@ module.exports = function(RED) {
node.log("Error: "+err);
};
RED.nodes.registerType("pusher in",PusherNode);
RED.nodes.registerType("pusher out",PusherNodeSend);
var querystring = require('querystring');
RED.httpAdmin.get('/pusher/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({pusherappid:credentials.pusherappid,pusherappsecret:credentials.pusherappsecret, pusherappkey:credentials.pusherappkey, pusherappkey_sub:credentials.pusherappkey_sub}));
} else {
res.send(JSON.stringify({}));
RED.nodes.registerType("pusher in",PusherNode,{
credentials: {
pusherappkey_sub: "text"
}
});
RED.nodes.registerType("pusher out",PusherNodeSend,{
credentials: {
pusherappid: {type:"text"},
pusherappkey: {type:"text"},
pusherappsecret: {type:"password"}
}
});
RED.httpAdmin.delete('/pusher/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
RED.httpAdmin.post('/pusher/:id',function(req,res) {
var body = "";
req.on('data', function(chunk) {
body+=chunk;
});
req.on('end', function(){
var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.pusherappid === null || newCreds.pusherappid === "") {
delete credentials.pusherappid;
} else {
credentials.pusherappid = newCreds.pusherappid;
}
if (newCreds.pusherappkey === "") {
delete credentials.pusherappkey;
} else {
credentials.pusherappkey = newCreds.pusherappkey||credentials.pusherappkey;
}
if (newCreds.pusherappsecret === "") {
delete credentials.pusherappsecret;
} else {
credentials.pusherappsecret = newCreds.pusherappsecret||credentials.pusherappsecret;
}
if (newCreds.pusherappkey_sub === "") {
delete credentials.pusherappkey_sub;
} else {
credentials.pusherappkey_sub = newCreds.pusherappkey_sub||credentials.pusherappkey_sub;
}
RED.nodes.addCredentials(req.params.id,credentials);
res.send(200);
});
});
}

View File

@@ -55,6 +55,10 @@
name: {value:""},
priority: {value:0}
},
credentials: {
deviceid: {type:"text"},
pushkey: {type: "password"}
},
color:"#a7c9a0",
inputs:1,
outputs:0,
@@ -71,39 +75,6 @@
min:-1,
max:2
});
$.getJSON('pushover/'+this.id,function(data) {
if (data.deviceid) {
$('#node-config-input-deviceid').val(data.deviceid);
}
if (data.hasPassword) {
$('#node-config-input-pushkey').val('__PWRD__');
} else {
$('#node-config-input-pushkey').val('');
}
});
},
oneditsave: function() {
var credentials = {};
var newUser = $('#node-config-input-deviceid').val();
var newPass = $('#node-config-input-pushkey').val();
credentials.deviceid = newUser;
if (newPass != '__PWRD__') {
credentials.pushkey = newPass;
}
$.ajax({
url: 'pushover/'+this.id,
type: 'POST',
data: credentials,
success: function(result){}
});
},
ondelete: function() {
$.ajax({
url: 'pushover/'+this.id,
type: 'DELETE',
success: function(result) {}
});
}
});
</script>

View File

@@ -23,7 +23,7 @@ module.exports = function(RED) {
RED.nodes.createNode(this,n);
this.title = n.title;
this.priority = n.priority;
var credentials = RED.nodes.getCredentials(n.id);
var credentials = this.credentials;
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
else { this.error("No Pushover api token set"); }
if ((credentials) && (credentials.hasOwnProperty("deviceid"))) { this.deviceid = credentials.deviceid; }
@@ -69,44 +69,10 @@ module.exports = function(RED) {
}
});
}
RED.nodes.registerType("pushover",PushoverNode);
var querystring = require('querystring');
RED.httpAdmin.get('/pushover/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({deviceid:credentials.deviceid,hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
} else {
res.send(JSON.stringify({}));
}
});
RED.httpAdmin.delete('/pushover/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
RED.httpAdmin.post('/pushover/:id',function(req,res) {
var body = "";
req.on('data', function(chunk) {
body+=chunk;
});
req.on('end', function(){
var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.deviceid === null || newCreds.deviceid === "") {
delete credentials.deviceid;
} else {
credentials.deviceid = newCreds.deviceid;
}
if (newCreds.pushkey === "") {
delete credentials.pushkey;
} else {
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
}
RED.nodes.addCredentials(req.params.id,credentials);
res.send(200);
});
RED.nodes.registerType("pushover",PushoverNode,{
credentials: {
deviceid: {type:"text"},
pushkey: {type: "password"}
}
});
}

View File

@@ -1,6 +1,6 @@
{
"name" : "node-red-node-pushover",
"version" : "0.0.1",
"version" : "0.0.2",
"description" : "A Node-RED node to send alerts via Pushover",
"dependencies" : {
"pushover-notifications" : "0.2.0"

View File

@@ -1,5 +1,5 @@
<!--
Copyright 2014 Andrew D Lindsay @AndrewDLindsay
Copyright 2014, 2015 Andrew D Lindsay @AndrewDLindsay
http://blog.thiseldo.co.uk
Licensed under the Apache License, Version 2.0 (the "License");
@@ -102,38 +102,11 @@
// token -> credentials
name: { value: ""}
},
credentials: {
token: "password"
},
label: function() {
return this.name||this.from;
},
oneditprepare: function() {
$.getJSON('twilio-api/'+this.id,function(data) {
if (data.hasToken) {
$('#node-config-input-token').val('__PWRD__');
} else {
$('#node-config-input-token').val('');
}
});
},
oneditsave: function() {
var newToken = $('#node-config-input-token').val();
if (newToken != '__PWRD__') {
var credentials = {};
credentials.token = newToken;
$.ajax({
url: 'twilio-api/'+this.id,
type: 'POST',
data: credentials,
success:function(result){}
});
}
},
ondelete: function() {
$.ajax({
url: 'twilio-api/'+this.id,
type: 'DELETE',
success: function(result) {}
});
}
});

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2014 Andrew D Lindsay @AndrewDLindsay
* Copyright 2014, 2015 Andrew D Lindsay @AndrewDLindsay
* http://blog.thiseldo.co.uk
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,41 +25,8 @@ module.exports = function(RED) {
catch(err) {
}
var querystring = require('querystring');
RED.httpAdmin.get('/twilio-api/global',function(req,res) {
res.send(JSON.stringify({hasToken:!(twiliokey && twiliokey.account && twiliokey.authtoken)}));
});
RED.httpAdmin.get('/twilio-api/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({hasToken:(credentials.token&&credentials.token!=="")}));
} else {
res.send(JSON.stringify({}));
}
});
RED.httpAdmin.delete('/twilio-api/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
RED.httpAdmin.post('/twilio-api/:id',function(req,res) {
var body = "";
req.on('data', function(chunk) {
body+=chunk;
});
req.on('end', function(){
var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.token == "") {
delete credentials.token;
} else {
credentials.token = newCreds.token;
}
RED.nodes.addCredentials(req.params.id,credentials);
res.send(200);
});
RED.httpAdmin.get('/twilio-api/global', RED.auth.needsPermission("twilio.read"), function(req,res) {
res.json({hasToken:!(twiliokey && twiliokey.account && twiliokey.authtoken)});
});
function TwilioAPINode(n) {
@@ -67,12 +34,16 @@ module.exports = function(RED) {
this.sid = n.sid;
this.from = n.from;
this.name = n.name;
var credentials = RED.nodes.getCredentials(n.id);
var credentials = this.credentials;
if (credentials) {
this.token = credentials.token;
}
}
RED.nodes.registerType("twilio-api",TwilioAPINode);
RED.nodes.registerType("twilio-api",TwilioAPINode,{
credentials: {
token: "password"
}
});
function TwilioOutNode(n) {

View File

@@ -1,6 +1,6 @@
{
"name" : "node-red-node-twilio",
"version" : "0.0.4",
"version" : "0.0.6",
"description" : "A Node-RED node to send SMS messages via the Twilio service.",
"dependencies" : {
"twilio" : "1.6.0"

View File

@@ -1,5 +1,5 @@
<!--
Copyright 2013,2014 IBM Corp.
Copyright 2013,2015 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -138,9 +138,8 @@
</div>
<div class="form-row">
<label for="node-config-input-pass"><i class="fa fa-lock"></i> Password</label>
<input type="password" id="node-config-input-pass">
<input type="password" id="node-config-input-password">
</div>
<div class="form-tips" id="node-config-cred-tip"><b>Note:</b> Using credentials from global xmppkey.js file.</div>
</script>
<script type="text/javascript">
@@ -151,44 +150,12 @@
port: {value:5222,required:true,validate:RED.validators.number()},
nickname: {}
},
credentials: {
user: {type:"text"},
password: {type: "password"}
},
label: function() {
return (this.nickname?this.nickname+"@":"")+this.server+":"+this.port;
},
oneditprepare: function() {
$.getJSON('xmpp-server/'+this.id,function(data) {
if (data.user) {
$('#node-config-input-user').val(data.user);
}
if (data.hasPassword) {
$('#node-config-input-pass').val('__PWRD__');
} else {
$('#node-config-input-pass').val('');
}
if (data.global) $('#node-config-cred-tip').show();
else $('#node-config-cred-tip').hide();
});
},
oneditsave: function() {
var credentials = {};
var newUser = $('#node-config-input-user').val();
var newPass = $('#node-config-input-pass').val();
credentials.user = newUser;
if (newPass != '__PWRD__') {
credentials.password = newPass;
}
$.ajax({
url: 'xmpp-server/'+this.id,
type: 'POST',
data: credentials,
success: function(result){}
});
},
ondelete: function() {
$.ajax({
url: 'xmpp-server/'+this.id,
type: 'DELETE',
success: function(result) {}
});
}
});
</script>

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2013,2014 IBM Corp.
* Copyright 2013,2015 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,56 +26,19 @@ function XMPPServerNode(n) {
this.server = n.server;
this.port = n.port;
this.nickname = n.nickname;
var credentials = RED.nodes.getCredentials(n.id);
var credentials = this.credentials;
if (credentials) {
this.username = credentials.user;
this.password = credentials.password;
}
}
RED.nodes.registerType("xmpp-server",XMPPServerNode);
var querystring = require('querystring');
RED.httpAdmin.get('/xmpp-server/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
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, global:true});
credentials = RED.nodes.getCredentials(req.params.id);
res.send(JSON.stringify({user:credentials.user,global:credentials.global,hasPassword:(credentials.password&&credentials.password!=="")}));
} else {
res.send(JSON.stringify({}));
RED.nodes.registerType("xmpp-server",XMPPServerNode,{
credentials: {
user: {type:"text"},
password: {type: "password"}
}
});
RED.httpAdmin.delete('/xmpp-server/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
RED.httpAdmin.post('/xmpp-server/:id',function(req,res) {
var body = "";
req.on('data', function(chunk) {
body+=chunk;
});
req.on('end', function(){
var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.user == null || newCreds.user === "") {
delete credentials.user;
} else {
credentials.user = newCreds.user;
}
if (newCreds.password === "") {
delete credentials.password;
} else {
credentials.password = newCreds.password||credentials.password;
}
RED.nodes.addCredentials(req.params.id,credentials);
res.send(200);
});
});
function XmppInNode(n) {

View File

@@ -1,6 +1,6 @@
{
"name" : "node-red-node-xmpp",
"version" : "0.0.2",
"version" : "0.0.3",
"description" : "A Node-RED node to talk to an XMPP server",
"dependencies" : {
"simple-xmpp" : "0.1.19"