1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

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

@ -231,7 +231,7 @@ module.exports = function(RED) {
} }
RED.nodes.registerType("rpi-pibrella out",PibrellaOut); RED.nodes.registerType("rpi-pibrella out",PibrellaOut);
RED.httpAdmin.get('/rpi-pibpins/:id',function(req,res) { RED.httpAdmin.get('/rpi-pibpins/:id',RED.auth.needsPermission('rpi-pibrella.read'),function(req,res) {
res.send( JSON.stringify(pinsInUse) ); res.json(pinsInUse);
}); });
} }

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-pibrella", "name" : "node-red-node-pibrella",
"version" : "0.0.5", "version" : "0.0.6",
"description" : "A Node-RED node to read from and write to a Pibrella Raspberry Pi add-on board", "description" : "A Node-RED node to read from and write to a Pibrella Raspberry Pi add-on board",
"dependencies" : { "dependencies" : {
}, },

View File

@ -248,11 +248,9 @@ module.exports = function(RED) {
RED.nodes.registerType("blinkstick",BlinkStick); RED.nodes.registerType("blinkstick",BlinkStick);
RED.httpAdmin.get("/blinksticklist",function(req,res) { RED.httpAdmin.get("/blinksticklist", RED.auth.needsPermission("blinkstick.read"), function(req,res) {
blinkstick.findAllSerials(function(serials) { blinkstick.findAllSerials(function(serials) {
res.writeHead(200, {'Content-Type': 'application/json'}); res.json(serials);
res.write(JSON.stringify(serials));
res.end();
}); });
}); });
}; };

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-blinkstick", "name" : "node-red-node-blinkstick",
"version" : "0.1.1", "version" : "0.1.2",
"description" : "A Node-RED node to control a Blinkstick", "description" : "A Node-RED node to control a Blinkstick",
"dependencies" : { "dependencies" : {
"blinkstick" : "1.1.*" "blinkstick" : "1.1.*"

View File

@ -82,33 +82,11 @@
server: {value:"http://localhost",required:true}, server: {value:"http://localhost",required:true},
name: {value:""} name: {value:""}
}, },
credentials: {
apikey: {type:"text"}
},
label: function() { label: function() {
return this.name||this.server; return this.name||this.server;
},
oneditprepare: function() {
$.getJSON('emoncms-server/'+this.id,function(data) {
if (data.apikey) {
$('#node-config-input-apikey').val(data.apikey);
}
});
},
oneditsave: function() {
var newApikey = $('#node-config-input-apikey').val();
var credentials = {};
credentials.apikey = newApikey;
$.ajax({
url: 'emoncms-server/'+this.id,
type: 'POST',
data: credentials,
success:function(result){}
});
},
ondelete: function() {
$.ajax({
url: 'emoncms-server/'+this.id,
type: 'DELETE',
success: function(result) {}
});
} }
}); });
</script> </script>

View File

@ -20,56 +20,20 @@ function EmoncmsServerNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.server = n.server; this.server = n.server;
this.name = n.name; this.name = n.name;
var credentials = RED.nodes.getCredentials(n.id);
if (credentials) {
this.apikey = credentials.apikey;
}
} }
RED.nodes.registerType("emoncms-server",EmoncmsServerNode); RED.nodes.registerType("emoncms-server",EmoncmsServerNode,{
credentials: {
var querystring = require('querystring'); apikey: {type:"text"}
RED.httpAdmin.get('/emoncms-server/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({apikey:credentials.apikey}));
} else {
res.send(JSON.stringify({}));
} }
}); });
RED.httpAdmin.delete('/emoncms-server/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
RED.httpAdmin.post('/emoncms-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.apikey == null || newCreds.apikey == "") {
delete credentials.apikey;
} else {
credentials.apikey = newCreds.apikey;
}
RED.nodes.addCredentials(req.params.id,credentials);
res.send(200);
});
});
function Emoncms(n) { function Emoncms(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.emonServer = n.emonServer; this.emonServer = n.emonServer;
var sc = RED.nodes.getNode(this.emonServer); var sc = RED.nodes.getNode(this.emonServer);
this.baseurl = sc.server; this.baseurl = sc.server;
this.apikey = sc.apikey; this.apikey = sc.credentials.apikey;
this.nodegroup = n.nodegroup || ""; this.nodegroup = n.nodegroup || "";
var node = this; var node = this;

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-emoncms", "name" : "node-red-node-emoncms",
"version" : "0.0.1", "version" : "0.0.2",
"description" : "A Node-RED node to send energy data to emoncms.org.", "description" : "A Node-RED node to send energy data to emoncms.org.",
"dependencies" : { "dependencies" : {
}, },

View File

@ -110,7 +110,7 @@
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-config-input-pass"><i class="fa fa-lock"></i> Password</label> <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>
<div class="form-row"> <div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label> <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
@ -126,44 +126,12 @@
port: {value:61618,required:true,validate:RED.validators.number()}, port: {value:61618,required:true,validate:RED.validators.number()},
name: {} name: {}
}, },
credentials: {
user: {type:"text"},
password: {type: "password"}
},
label: function() { label: function() {
return (this.name?this.name:this.server+":"+this.port); return (this.name?this.name:this.server+":"+this.port);
},
oneditprepare: function() {
$.getJSON('stomp-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: 'stomp-server/'+this.id,
type: 'POST',
data: credentials,
success: function(result){}
});
},
ondelete: function() {
$.ajax({
url: 'stomp-server/'+this.id,
type: 'DELETE',
success: function(result) {}
});
} }
}); });
</script> </script>

View File

@ -24,52 +24,16 @@ module.exports = function(RED) {
this.server = n.server; this.server = n.server;
this.port = n.port; this.port = n.port;
this.name = n.name; this.name = n.name;
var credentials = RED.nodes.getCredentials(n.id); this.username = this.credentials.user;
if (credentials) { this.password = this.credentials.password;
this.username = credentials.user;
this.password = credentials.password;
}
} }
RED.nodes.registerType("stomp-server",StompServerNode); RED.nodes.registerType("stomp-server",StompServerNode,{
credentials: {
RED.httpAdmin.get('/stomp-server/:id',function(req,res) { user: {type:"text"},
var credentials = RED.nodes.getCredentials(req.params.id); password: {type: "password"}
if (credentials) {
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!=="")}));
} else {
res.send(JSON.stringify({}));
} }
}); });
RED.httpAdmin.delete('/stomp-server/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
RED.httpAdmin.post('/stomp-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 StompInNode(n) { function StompInNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.server = n.server; this.server = n.server;

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-stomp", "name" : "node-red-node-stomp",
"version" : "0.0.1", "version" : "0.0.2",
"description" : "A Node-RED node to publish and subscribe to/from a Stomp server", "description" : "A Node-RED node to publish and subscribe to/from a Stomp server",
"dependencies" : { "dependencies" : {
"stomp-client" : "0.5.0" "stomp-client" : "0.5.0"

View File

@ -44,6 +44,9 @@
title: {value:""}, title: {value:""},
name: {value:""} name: {value:""}
}, },
credentials: {
pushkey: {type: "password"}
},
color:"#a7c9a0", color:"#a7c9a0",
inputs:1, inputs:1,
outputs:0, outputs:0,
@ -54,35 +57,6 @@
}, },
labelStyle: function() { labelStyle: function() {
return this.name?"node_label_italic":""; 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> </script>

View File

@ -21,7 +21,7 @@ module.exports = function(RED) {
function NMANode(n) { function NMANode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.title = n.title; this.title = n.title;
var credentials = RED.nodes.getCredentials(n.id); var credentials = this.credentials;
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; } if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
else { this.error("No NMA API key set"); } else { this.error("No NMA API key set"); }
var node = this; var node = this;
@ -50,39 +50,9 @@ module.exports = function(RED) {
}); });
} }
RED.nodes.registerType("nma",NMANode); RED.nodes.registerType("nma",NMANode, {
credentials: {
var querystring = require('querystring'); pushkey: {type: "password"}
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.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", "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", "description" : "A Node-RED node to send alerts via Notify-My-Android",
"dependencies" : { "dependencies" : {
"nma" : "0.2.2" "nma" : "0.2.2"

View File

@ -32,7 +32,6 @@
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name"> <input type="text" id="node-input-name" placeholder="Name">
</div> </div>
<div class="form-tips" id="node-tip"><b>Note:</b> Using credentials from global pushkey.js file.</div>
</script> </script>
<script type="text/x-red" data-help-name="prowl"> <script type="text/x-red" data-help-name="prowl">
@ -52,6 +51,9 @@
priority: {value:0,required:true,validate:RED.validators.number()}, priority: {value:0,required:true,validate:RED.validators.number()},
name: {value:""} name: {value:""}
}, },
credentials: {
pushkey: {type: "password"}
}
color:"#a7c9a0", color:"#a7c9a0",
inputs:1, inputs:1,
outputs:0, outputs:0,
@ -62,37 +64,6 @@
}, },
labelStyle: function() { labelStyle: function() {
return this.name?"node_label_italic":""; 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> </script>

View File

@ -18,11 +18,6 @@ module.exports = function(RED) {
"use strict"; "use strict";
var Prowl = require('node-prowl'); 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 { try {
var pushkeys = RED.settings.prowl || require(process.env.NODE_RED_HOME+"/../pushkey.js"); 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); this.priority = parseInt(n.priority);
if (this.priority > 2) { this.priority = 2; } if (this.priority > 2) { this.priority = 2; }
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; } if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
else { else {
if (pushkeys) { this.pushkey = pushkeys.prowlkey; } if (pushkeys) { this.pushkey = pushkeys.prowlkey; }
@ -67,45 +62,9 @@ module.exports = function(RED) {
} }
}); });
} }
RED.nodes.registerType("prowl",ProwlNode); RED.nodes.registerType("prowl",ProwlNode,{
credentials: {
var querystring = require('querystring'); pushkey: {type: "password"}
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!=="")}));
} }
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", "name" : "node-red-node-prowl",
"version" : "0.0.1", "version" : "0.0.2",
"description" : "A Node-RED node to send alerts via Prowl", "description" : "A Node-RED node to send alerts via Prowl",
"dependencies" : { "dependencies" : {
"node-prowl" : "0.1.7" "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"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -27,7 +27,7 @@
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-appkey_sub"><i class="fa fa-lock"></i> App Key</label> <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>
<div class="form-row"> <div class="form-row">
@ -51,6 +51,9 @@
channel: {value:"", required:true}, channel: {value:"", required:true},
eventname: {value:"", required:true} eventname: {value:"", required:true}
}, },
credentials: {
pusherappkey_sub: "text"
},
inputs:0, // set the number of inputs - only 0 or 1 inputs:0, // set the number of inputs - only 0 or 1
outputs:1, // set the number of outputs - 0 to n outputs:1, // set the number of outputs - 0 to n
icon: "pusher.png", // set the icon (held in public/icons) icon: "pusher.png", // set the icon (held in public/icons)
@ -59,31 +62,6 @@
}, },
labelStyle: function() { // sets the class to apply to the label labelStyle: function() { // sets the class to apply to the label
return this.name?"node_label_italic":""; 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> </script>
@ -101,17 +79,17 @@
<div class="form-row"> <div class="form-row">
<label for="node-input-appid"><i class="fa fa-tag"></i> App ID</label> <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>
<div class="form-row"> <div class="form-row">
<label for="node-input-appkey"><i class="fa fa-lock"></i> App Key</label> <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>
<div class="form-row"> <div class="form-row">
<label for="node-input-topic"><i class="fa fa-asterisk"></i> App Secret</label> <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>
<div class="form-row"> <div class="form-row">
@ -135,6 +113,11 @@
channel: {value:"", required:true}, channel: {value:"", required:true},
eventname: {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 inputs:1, // set the number of inputs - only 0 or 1
outputs:0, // set the number of outputs - 0 to n outputs:0, // set the number of outputs - 0 to n
icon: "pusher.png", // set the icon (held in public/icons) icon: "pusher.png", // set the icon (held in public/icons)
@ -144,41 +127,6 @@
}, },
labelStyle: function() { // sets the class to apply to the label labelStyle: function() { // sets the class to apply to the label
return this.name?"node_label_italic":""; 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> </script>

View File

@ -3,7 +3,7 @@
* Subscription module for the Pusher service (www.pusher.com) * Subscription module for the Pusher service (www.pusher.com)
* Requires 'pusher' and 'pusher-client' modules. * 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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); RED.nodes.createNode(this,n);
var node = this; 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; } if ((credentials) && (credentials.hasOwnProperty("pusherappkey_sub"))) { this.appkey = credentials.pusherappkey_sub; }
else { this.error("No Pusher app key set for input node"); } else { this.error("No Pusher app key set for input node"); }
@ -61,7 +61,7 @@ module.exports = function(RED) {
var node = this; var node = this;
var credentials = RED.nodes.getCredentials(n.id); var credentials = this.credentials;
if ((credentials) && (credentials.hasOwnProperty("pusherappid"))) { this.appid = credentials.pusherappid; } if ((credentials) && (credentials.hasOwnProperty("pusherappid"))) { this.appid = credentials.pusherappid; }
else { this.error("No Pusher api token set"); } else { this.error("No Pusher api token set"); }
@ -99,59 +99,16 @@ module.exports = function(RED) {
node.log("Error: "+err); node.log("Error: "+err);
}; };
RED.nodes.registerType("pusher in",PusherNode); RED.nodes.registerType("pusher in",PusherNode,{
RED.nodes.registerType("pusher out",PusherNodeSend); credentials: {
pusherappkey_sub: "text"
var querystring = require('querystring'); }
});
RED.httpAdmin.get('/pusher/:id',function(req,res) { RED.nodes.registerType("pusher out",PusherNodeSend,{
var credentials = RED.nodes.getCredentials(req.params.id); credentials: {
if (credentials) { pusherappid: {type:"text"},
res.send(JSON.stringify({pusherappid:credentials.pusherappid,pusherappsecret:credentials.pusherappsecret, pusherappkey:credentials.pusherappkey, pusherappkey_sub:credentials.pusherappkey_sub})); pusherappkey: {type:"text"},
} else { pusherappsecret: {type:"password"}
res.send(JSON.stringify({}));
} }
}); });
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:""}, name: {value:""},
priority: {value:0} priority: {value:0}
}, },
credentials: {
deviceid: {type:"text"},
pushkey: {type: "password"}
},
color:"#a7c9a0", color:"#a7c9a0",
inputs:1, inputs:1,
outputs:0, outputs:0,
@ -71,39 +75,6 @@
min:-1, min:-1,
max:2 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> </script>

View File

@ -23,7 +23,7 @@ module.exports = function(RED) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.title = n.title; this.title = n.title;
this.priority = n.priority; this.priority = n.priority;
var credentials = RED.nodes.getCredentials(n.id); var credentials = this.credentials;
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; } if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
else { this.error("No Pushover api token set"); } else { this.error("No Pushover api token set"); }
if ((credentials) && (credentials.hasOwnProperty("deviceid"))) { this.deviceid = credentials.deviceid; } if ((credentials) && (credentials.hasOwnProperty("deviceid"))) { this.deviceid = credentials.deviceid; }
@ -69,44 +69,10 @@ module.exports = function(RED) {
} }
}); });
} }
RED.nodes.registerType("pushover",PushoverNode); RED.nodes.registerType("pushover",PushoverNode,{
credentials: {
var querystring = require('querystring'); deviceid: {type:"text"},
pushkey: {type: "password"}
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);
});
}); });
} }

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-pushover", "name" : "node-red-node-pushover",
"version" : "0.0.1", "version" : "0.0.2",
"description" : "A Node-RED node to send alerts via Pushover", "description" : "A Node-RED node to send alerts via Pushover",
"dependencies" : { "dependencies" : {
"pushover-notifications" : "0.2.0" "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 http://blog.thiseldo.co.uk
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
@ -102,38 +102,11 @@
// token -> credentials // token -> credentials
name: { value: ""} name: { value: ""}
}, },
credentials: {
token: "password"
},
label: function() { label: function() {
return this.name||this.from; 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 * http://blog.thiseldo.co.uk
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -25,41 +25,8 @@ module.exports = function(RED) {
catch(err) { catch(err) {
} }
var querystring = require('querystring'); RED.httpAdmin.get('/twilio-api/global', RED.auth.needsPermission("twilio.read"), function(req,res) {
res.json({hasToken:!(twiliokey && twiliokey.account && twiliokey.authtoken)});
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);
});
}); });
function TwilioAPINode(n) { function TwilioAPINode(n) {
@ -67,12 +34,16 @@ module.exports = function(RED) {
this.sid = n.sid; this.sid = n.sid;
this.from = n.from; this.from = n.from;
this.name = n.name; this.name = n.name;
var credentials = RED.nodes.getCredentials(n.id); var credentials = this.credentials;
if (credentials) { if (credentials) {
this.token = credentials.token; this.token = credentials.token;
} }
} }
RED.nodes.registerType("twilio-api",TwilioAPINode); RED.nodes.registerType("twilio-api",TwilioAPINode,{
credentials: {
token: "password"
}
});
function TwilioOutNode(n) { function TwilioOutNode(n) {

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-twilio", "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.", "description" : "A Node-RED node to send SMS messages via the Twilio service.",
"dependencies" : { "dependencies" : {
"twilio" : "1.6.0" "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"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -138,9 +138,8 @@
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-config-input-pass"><i class="fa fa-lock"></i> Password</label> <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>
<div class="form-tips" id="node-config-cred-tip"><b>Note:</b> Using credentials from global xmppkey.js file.</div>
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
@ -151,44 +150,12 @@
port: {value:5222,required:true,validate:RED.validators.number()}, port: {value:5222,required:true,validate:RED.validators.number()},
nickname: {} nickname: {}
}, },
credentials: {
user: {type:"text"},
password: {type: "password"}
},
label: function() { label: function() {
return (this.nickname?this.nickname+"@":"")+this.server+":"+this.port; 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> </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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.server = n.server;
this.port = n.port; this.port = n.port;
this.nickname = n.nickname; this.nickname = n.nickname;
var credentials = RED.nodes.getCredentials(n.id); var credentials = this.credentials;
if (credentials) { if (credentials) {
this.username = credentials.user; this.username = credentials.user;
this.password = credentials.password; this.password = credentials.password;
} }
} }
RED.nodes.registerType("xmpp-server",XMPPServerNode); RED.nodes.registerType("xmpp-server",XMPPServerNode,{
credentials: {
var querystring = require('querystring'); user: {type:"text"},
password: {type: "password"}
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.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) { function XmppInNode(n) {

View File

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

View File

@ -42,44 +42,12 @@
port: { value: 5432,required:true}, port: { value: 5432,required:true},
db: { value:"postgres",required:true} db: { value:"postgres",required:true}
}, },
credentials: {
user: {type:"text"},
password: {type: "password"}
},
label: function() { label: function() {
return this.name||this.hostname+":"+this.port+"/"+this.db; return this.name||this.hostname+":"+this.port+"/"+this.db;
},
oneditprepare: function() {
$.getJSON('postgresdb/'+this.id,function(data) {
if (data.user) {
$('#node-config-input-user').val(data.user);
}
if (data.hasPassword) {
$('#node-config-input-password').val('__PWRD__');
} else {
$('#node-config-input-password').val('');
}
});
},
oneditsave: function() {
var newUser = $('#node-config-input-user').val();
var newPass = $('#node-config-input-password').val();
var credentials = {};
credentials.user = newUser;
if (newPass != '__PWRD__') {
credentials.password = newPass;
}
$.ajax({
url: 'postgresdb/'+this.id,
type: 'POST',
data: credentials,
success:function(result){}
});
},
ondelete: function() {
$.ajax({
url: 'postgresdb/'+this.id,
type: 'DELETE',
success: function(result) {}
});
} }
}); });
</script> </script>

View File

@ -1,5 +1,5 @@
/** /**
* Copyright 2013 Kris Daniels. * Copyright 2013, 2015 Kris Daniels, IBM Corp.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -14,110 +14,74 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var pg=require('pg'); var pg=require('pg');
var named=require('node-postgres-named'); var named=require('node-postgres-named');
var querystring = require('querystring'); var querystring = require('querystring');
RED.httpAdmin.get('/postgresdb/: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 {
res.send(JSON.stringify({}));
}
});
RED.httpAdmin.delete('/postgresdb/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
RED.httpAdmin.post('/postgresdb/: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 PostgresDatabaseNode(n) {
RED.nodes.createNode(this,n);
this.hostname = n.hostname;
this.port = n.port;
this.db = n.db;
var credentials = RED.nodes.getCredentials(n.id); function PostgresDatabaseNode(n) {
if (credentials) { RED.nodes.createNode(this,n);
this.user = credentials.user; this.hostname = n.hostname;
this.password = credentials.password; this.port = n.port;
} this.db = n.db;
} this.user = this.credentials.user;
this.password = this.credentials.password;
RED.nodes.registerType("postgresdb",PostgresDatabaseNode);
function PostgresNode(n) {
RED.nodes.createNode(this,n);
this.topic = n.topic;
this.postgresdb = n.postgresdb;
this.postgresConfig = RED.nodes.getNode(this.postgresdb);
this.sqlquery = n.sqlquery;
this.output = n.output;
var node = this;
if(this.postgresConfig)
{
var conString = 'postgres://'+this.postgresConfig.user +':' + this.postgresConfig.password + '@' + this.postgresConfig.hostname + ':' + this.postgresConfig.port + '/' + this.postgresConfig.db;
node.clientdb = new pg.Client(conString);
named.patch(node.clientdb);
node.clientdb.connect(function(err){
if(err) { node.error(err); }
else {
node.on('input',
function(msg){
if(!msg.queryParameters) msg.queryParameters={};
node.clientdb.query(msg.payload,
msg.queryParameters,
function (err, results) {
if(err) { node.error(err); }
else {
if(node.output)
{
msg.payload = results.rows;
node.send(msg);
}
}
});
});
}
});
} else {
this.error("missing postgres configuration");
} }
this.on("close", function() { RED.nodes.registerType("postgresdb",PostgresDatabaseNode,{
if(node.clientdb) node.clientdb.end(); credentials: {
user: {type:"text"},
password: {type: "password"}
}
}); });
function PostgresNode(n) {
RED.nodes.createNode(this,n);
this.topic = n.topic;
this.postgresdb = n.postgresdb;
this.postgresConfig = RED.nodes.getNode(this.postgresdb);
this.sqlquery = n.sqlquery;
this.output = n.output;
var node = this;
if(this.postgresConfig)
{
var conString = 'postgres://'+this.postgresConfig.user +':' + this.postgresConfig.password + '@' + this.postgresConfig.hostname + ':' + this.postgresConfig.port + '/' + this.postgresConfig.db;
node.clientdb = new pg.Client(conString);
named.patch(node.clientdb);
node.clientdb.connect(function(err){
if(err) { node.error(err); }
else {
node.on('input',
function(msg){
if(!msg.queryParameters) msg.queryParameters={};
node.clientdb.query(msg.payload,
msg.queryParameters,
function (err, results) {
if(err) { node.error(err); }
else {
if(node.output)
{
msg.payload = results.rows;
node.send(msg);
}
}
});
});
}
});
} else {
this.error("missing postgres configuration");
}
this.on("close", function() {
if(node.clientdb) node.clientdb.end();
});
}
RED.nodes.registerType("postgres",PostgresNode);
} }
RED.nodes.registerType("postgres",PostgresNode);