diff --git a/nodes/core/hardware/35-arduino.html b/nodes/core/hardware/35-arduino.html deleted file mode 100644 index 982cfe095..000000000 --- a/nodes/core/hardware/35-arduino.html +++ /dev/null @@ -1,171 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/nodes/core/hardware/35-arduino.js b/nodes/core/hardware/35-arduino.js deleted file mode 100644 index fd44ae934..000000000 --- a/nodes/core/hardware/35-arduino.js +++ /dev/null @@ -1,167 +0,0 @@ -/** - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function(RED) { - "use strict"; - var ArduinoFirmata = require('arduino-firmata'); - - // The Board Definition - this opens (and closes) the connection - function ArduinoNode(n) { - RED.nodes.createNode(this,n); - this.device = n.device || null; - this.repeat = n.repeat||25; - //node.log("opening connection "+this.device); - var node = this; - node.board = new ArduinoFirmata(); - ArduinoFirmata.list(function (err, ports) { - if (!node.device) { - node.log("connecting to first board found."); - node.board.connect(); - } - else { - if (ports.indexOf(node.device) === -1) { - node.warn(node.device + " not found. Trying to find board."); - node.board.connect(); - } - else { - node.log("connecting to "+node.device); - node.board.connect(node.device); - } - } - - node.board.on('boardReady', function() { - node.log("connected to "+node.board.serialport_name); - if (RED.settings.verbose) { node.log("version "+node.board.boardVersion); } - }); - }); - - node.on('close', function(done) { - if (node.board) { - try { - node.board.close(function() { - done(); - if (RED.settings.verbose) { node.log("port closed"); } - }); - } catch(e) { done(); } - } else { done(); } - }); - } - RED.nodes.registerType("arduino-board",ArduinoNode); - - - // The Input Node - function DuinoNodeIn(n) { - RED.nodes.createNode(this,n); - this.buttonState = -1; - this.pin = n.pin; - this.state = n.state; - this.arduino = n.arduino; - this.serverConfig = RED.nodes.getNode(this.arduino); - if (typeof this.serverConfig === "object") { - this.board = this.serverConfig.board; - var node = this; - node.status({fill:"red",shape:"ring",text:"connecting"}); - node.board.on('connect', function() { - node.status({fill:"green",shape:"dot",text:"connected"}); - //console.log("i",node.state,node.pin); - if (node.state == "ANALOG") { - node.board.on('analogChange', function(e) { - if (e.pin == node.pin) { - var msg = {payload:e.value, topic:"A"+e.pin}; - node.send(msg); - } - }); - } - if (node.state == "INPUT") { - node.board.pinMode(node.pin, ArduinoFirmata.INPUT); - node.board.on('digitalChange', function(e) { - if (e.pin == node.pin) { - var msg = {payload:e.value, topic:e.pin}; - node.send(msg); - } - }); - } - if (node.state == "SYSEX") { - node.board.on('sysex', function(e) { - var msg = {payload:e, topic:"sysex"}; - node.send(msg); - }); - } - }); - } - else { - this.warn("port not configured"); - } - } - RED.nodes.registerType("arduino in",DuinoNodeIn); - - - // The Output Node - function DuinoNodeOut(n) { - RED.nodes.createNode(this,n); - this.buttonState = -1; - this.pin = n.pin; - this.state = n.state; - this.arduino = n.arduino; - this.serverConfig = RED.nodes.getNode(this.arduino); - if (typeof this.serverConfig === "object") { - this.board = this.serverConfig.board; - var node = this; - node.status({fill:"red",shape:"ring",text:"connecting"}); - - node.board.on('connect', function() { - node.status({fill:"green",shape:"dot",text:"connected"}); - //console.log("o",node.state,node.pin); - node.board.pinMode(node.pin, node.state); - node.on("input", function(msg) { - if (node.state === "OUTPUT") { - if ((msg.payload === true)||(msg.payload.toString() == "1")||(msg.payload.toString().toLowerCase() == "on")) { - node.board.digitalWrite(node.pin, true); - } - if ((msg.payload === false)||(msg.payload.toString() == "0")||(msg.payload.toString().toLowerCase() == "off")) { - node.board.digitalWrite(node.pin, false); - } - } - if (node.state === "PWM") { - msg.payload = msg.payload * 1; - if ((msg.payload >= 0) && (msg.payload <= 255)) { - node.board.analogWrite(node.pin, msg.payload); - } - } - if (node.state === "SERVO") { - msg.payload = msg.payload * 1; - if ((msg.payload >= 0) && (msg.payload <= 180)) { - node.board.servoWrite(node.pin, msg.payload); - } - } - if (node.state === "SYSEX") { - node.board.sysex(msg.payload); - } - }); - }); - } - else { - this.warn("port not configured"); - } - } - RED.nodes.registerType("arduino out",DuinoNodeOut); - - RED.httpAdmin.get("/arduinoports", RED.auth.needsPermission("arduino.read"), function(req,res) { - ArduinoFirmata.list(function (err, ports) { - res.json(ports); - }); - }); -} diff --git a/nodes/core/io/25-serial.html b/nodes/core/io/25-serial.html deleted file mode 100644 index 7bbace6ac..000000000 --- a/nodes/core/io/25-serial.html +++ /dev/null @@ -1,266 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/nodes/core/io/25-serial.js b/nodes/core/io/25-serial.js deleted file mode 100644 index b4c08af26..000000000 --- a/nodes/core/io/25-serial.js +++ /dev/null @@ -1,309 +0,0 @@ -/** -* 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. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -**/ - -module.exports = function(RED) { - "use strict"; - var settings = RED.settings; - var events = require("events"); - var serialp = require("serialport"); - var bufMaxSize = 32768; // Max serial buffer size, for inputs... - - // TODO: 'serialPool' should be encapsulated in SerialPortNode - - function SerialPortNode(n) { - RED.nodes.createNode(this,n); - this.serialport = n.serialport; - this.newline = n.newline; - this.addchar = n.addchar || "false"; - this.serialbaud = parseInt(n.serialbaud) || 57600; - this.databits = parseInt(n.databits) || 8; - this.parity = n.parity || "none"; - this.stopbits = parseInt(n.stopbits) || 1; - this.bin = n.bin || "false"; - this.out = n.out || "char"; - } - RED.nodes.registerType("serial-port",SerialPortNode); - - function SerialOutNode(n) { - RED.nodes.createNode(this,n); - this.serial = n.serial; - this.serialConfig = RED.nodes.getNode(this.serial); - - if (this.serialConfig) { - var node = this; - node.port = serialPool.get(this.serialConfig.serialport, - this.serialConfig.serialbaud, - this.serialConfig.databits, - this.serialConfig.parity, - this.serialConfig.stopbits, - this.serialConfig.newline); - node.addCh = ""; - if (node.serialConfig.addchar == "true" || node.serialConfig.addchar === true) { - node.addCh = this.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0"); - } - node.on("input",function(msg) { - if (msg.hasOwnProperty("payload")) { - var payload = msg.payload; - if (!Buffer.isBuffer(payload)) { - if (typeof payload === "object") { - payload = JSON.stringify(payload); - } else { - payload = payload.toString(); - } - payload += node.addCh; - } else if (node.addCh !== "") { - payload = Buffer.concat([payload,new Buffer(node.addCh)]); - } - node.port.write(payload,function(err,res) { - if (err) { - var errmsg = err.toString().replace("Serialport","Serialport "+node.port.serial.path); - node.error(errmsg,msg); - } - }); - } - }); - node.port.on('ready', function() { - node.status({fill:"green",shape:"dot",text:"connected"}); - }); - node.port.on('closed', function() { - node.status({fill:"red",shape:"ring",text:"not connected"}); - }); - } else { - this.error("missing serial config"); - } - - this.on("close", function(done) { - if (this.serialConfig) { - serialPool.close(this.serialConfig.serialport,done); - } else { - done(); - } - }); - } - RED.nodes.registerType("serial out",SerialOutNode); - - - function SerialInNode(n) { - RED.nodes.createNode(this,n); - this.serial = n.serial; - this.serialConfig = RED.nodes.getNode(this.serial); - - if (this.serialConfig) { - var node = this; - node.tout = null; - var buf; - if (node.serialConfig.out != "count") { buf = new Buffer(bufMaxSize); } - else { buf = new Buffer(Number(node.serialConfig.newline)); } - var i = 0; - node.status({fill:"grey",shape:"dot",text:"unknown"}); - node.port = serialPool.get(this.serialConfig.serialport, - this.serialConfig.serialbaud, - this.serialConfig.databits, - this.serialConfig.parity, - this.serialConfig.stopbits, - this.serialConfig.newline - ); - - var splitc; - if (node.serialConfig.newline.substr(0,2) == "0x") { - splitc = new Buffer([parseInt(node.serialConfig.newline)]); - } else { - splitc = new Buffer(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0")); - } - - this.port.on('data', function(msg) { - // single char buffer - if ((node.serialConfig.newline === 0)||(node.serialConfig.newline === "")) { - if (node.serialConfig.bin !== "bin") { node.send({"payload": String.fromCharCode(msg)}); } - else { node.send({"payload": new Buffer([msg])}); } - } - else { - // do the timer thing - if (node.serialConfig.out === "time") { - if (node.tout) { - i += 1; - buf[i] = msg; - } - else { - node.tout = setTimeout(function () { - node.tout = null; - var m = new Buffer(i+1); - buf.copy(m,0,0,i+1); - if (node.serialConfig.bin !== "bin") { m = m.toString(); } - node.send({"payload": m}); - m = null; - }, node.serialConfig.newline); - i = 0; - buf[0] = msg; - } - } - // count bytes into a buffer... - else if (node.serialConfig.out === "count") { - buf[i] = msg; - i += 1; - if ( i >= parseInt(node.serialConfig.newline)) { - var m = new Buffer(i); - buf.copy(m,0,0,i); - if (node.serialConfig.bin !== "bin") { m = m.toString(); } - node.send({"payload":m}); - m = null; - i = 0; - } - } - // look to match char... - else if (node.serialConfig.out === "char") { - buf[i] = msg; - i += 1; - if ((msg === splitc[0]) || (i === bufMaxSize)) { - var m = new Buffer(i); - buf.copy(m,0,0,i); - if (node.serialConfig.bin !== "bin") { m = m.toString(); } - node.send({"payload":m}); - m = null; - i = 0; - } - } - else { node.log("should never get here"); } - } - }); - this.port.on('ready', function() { - node.status({fill:"green",shape:"dot",text:"connected"}); - }); - this.port.on('closed', function() { - node.status({fill:"red",shape:"ring",text:"not connected"}); - }); - } else { - this.error("missing serial config"); - } - - this.on("close", function(done) { - if (this.serialConfig) { - serialPool.close(this.serialConfig.serialport,done); - } else { - done(); - } - }); - } - RED.nodes.registerType("serial in",SerialInNode); - - - var serialPool = function() { - var connections = {}; - return { - get:function(port,baud,databits,parity,stopbits,newline,callback) { - var id = port; - if (!connections[id]) { - connections[id] = function() { - var obj = { - _emitter: new events.EventEmitter(), - serial: null, - _closing: false, - tout: null, - on: function(a,b) { this._emitter.on(a,b); }, - close: function(cb) { this.serial.close(cb); }, - write: function(m,cb) { this.serial.write(m,cb); }, - } - //newline = newline.replace("\\n","\n").replace("\\r","\r"); - var setupSerial = function() { - //if (newline == "") { - obj.serial = new serialp.SerialPort(port,{ - baudrate: baud, - databits: databits, - parity: parity, - stopbits: stopbits, - parser: serialp.parsers.raw - },true, function(err, results) { if (err) { obj.serial.emit('error',err); } }); - //} - //else { - // obj.serial = new serialp.SerialPort(port,{ - // baudrate: baud, - // databits: databits, - // parity: parity, - // stopbits: stopbits, - // parser: serialp.parsers.readline(newline) - // },true, function(err, results) { if (err) obj.serial.emit('error',err); }); - //} - obj.serial.on('error', function(err) { - RED.log.error("serial port "+port+" error "+err); - obj._emitter.emit('closed'); - obj.tout = setTimeout(function() { - setupSerial(); - }, settings.serialReconnectTime); - }); - obj.serial.on('close', function() { - if (!obj._closing) { - RED.log.error("serial port "+port+" closed unexpectedly"); - obj._emitter.emit('closed'); - obj.tout = setTimeout(function() { - setupSerial(); - }, settings.serialReconnectTime); - } - }); - obj.serial.on('open',function() { - RED.log.info("serial port "+port+" opened at "+baud+" baud "+databits+""+parity.charAt(0).toUpperCase()+stopbits); - if (obj.tout) { clearTimeout(obj.tout); } - //obj.serial.flush(); - obj._emitter.emit('ready'); - }); - obj.serial.on('data',function(d) { - //console.log(Buffer.isBuffer(d),d.length,d); - //if (typeof d !== "string") { - // //d = d.toString(); - for (var z=0; z - - - - - - - - - - - - - - - - - diff --git a/nodes/core/social/27-twitter.js b/nodes/core/social/27-twitter.js deleted file mode 100644 index c0a20d528..000000000 --- a/nodes/core/social/27-twitter.js +++ /dev/null @@ -1,386 +0,0 @@ -/** - * Copyright 2013 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function(RED) { - "use strict"; - var ntwitter = require('twitter-ng'); - var OAuth= require('oauth').OAuth; - var request = require('request'); - - function TwitterNode(n) { - RED.nodes.createNode(this,n); - this.screen_name = n.screen_name; - } - RED.nodes.registerType("twitter-credentials",TwitterNode,{ - credentials: { - screen_name: {type:"text"}, - access_token: {type: "password"}, - access_token_secret: {type:"password"} - } - }); - - - /** - * Populate msg.location based on data found in msg.tweet. - */ - function addLocationToTweet(msg) { - if(msg.tweet) { - if(msg.tweet.geo) { // if geo is set, always set location from geo - if(msg.tweet.geo.coordinates && msg.tweet.geo.coordinates.length === 2) { - if (!msg.location) { msg.location = {}; } - // coordinates[0] is lat, coordinates[1] is lon - msg.location.lat = msg.tweet.geo.coordinates[0]; - msg.location.lon = msg.tweet.geo.coordinates[1]; - msg.location.icon = "twitter"; - } - } else if(msg.tweet.coordinates) { // otherwise attempt go get it from coordinates - if(msg.tweet.coordinates.coordinates && msg.tweet.coordinates.coordinates.length === 2) { - if (!msg.location) { msg.location = {}; } - // WARNING! coordinates[1] is lat, coordinates[0] is lon!!! - msg.location.lat = msg.tweet.coordinates.coordinates[1]; - msg.location.lon = msg.tweet.coordinates.coordinates[0]; - msg.location.icon = "twitter"; - } - } // if none of these found then just do nothing - } // if no msg.tweet then just do nothing - } - - function TwitterInNode(n) { - RED.nodes.createNode(this,n); - this.active = true; - this.user = n.user; - //this.tags = n.tags.replace(/ /g,''); - this.tags = n.tags; - this.twitter = n.twitter; - this.topic = n.topic||"tweets"; - this.twitterConfig = RED.nodes.getNode(this.twitter); - var credentials = RED.nodes.getCredentials(this.twitter); - - if (credentials && credentials.screen_name == this.twitterConfig.screen_name) { - var twit = new ntwitter({ - consumer_key: "OKjYEd1ef2bfFolV25G5nQ", - consumer_secret: "meRsltCktVMUI8gmggpXett7WBLd1k0qidYazoML6g", - access_token_key: credentials.access_token, - access_token_secret: credentials.access_token_secret - }); - - //setInterval(function() { - // twit.get("/application/rate_limit_status.json",null,function(err,cb) { - // console.log("direct_messages:",cb["resources"]["direct_messages"]); - // }); - // - //},10000); - - var node = this; - if (this.user === "user") { - node.poll_ids = []; - node.since_ids = {}; - var users = node.tags.split(","); - for (var i=0;i=0;t-=1) { - var tweet = cb[t]; - var where = tweet.user.location; - var la = tweet.lang || tweet.user.lang; - var msg = { topic:node.topic+"/"+tweet.user.screen_name, payload:tweet.text, lang:la, tweet:tweet }; - if (where) { - msg.location = {place:where}; - addLocationToTweet(msg); - } - node.send(msg); - if (t == 0) { - node.since_ids[u] = tweet.id_str; - } - } - } - if (err) { - node.error(err); - } - }); - },60000)); - } - }()); - } - } else if (this.user === "dm") { - node.poll_ids = []; - twit.getDirectMessages({ - screen_name:node.twitterConfig.screen_name, - trim_user:0, - count:1 - },function(err,cb) { - if (err) { - node.error(err); - return; - } - if (cb[0]) { - node.since_id = cb[0].id_str; - } else { - node.since_id = '0'; - } - node.poll_ids.push(setInterval(function() { - twit.getDirectMessages({ - screen_name:node.twitterConfig.screen_name, - trim_user:0, - since_id:node.since_id - },function(err,cb) { - if (cb) { - for (var t=cb.length-1;t>=0;t-=1) { - var tweet = cb[t]; - var where = tweet.sender.location; - var la = tweet.lang || tweet.sender.lang; - var msg = { topic:node.topic+"/"+tweet.sender.screen_name, payload:tweet.text, lang:la, tweet:tweet }; - if (where) { - msg.location = {place:where}; - addLocationToTweet(msg); - } - node.send(msg); - if (t == 0) { - node.since_id = tweet.id_str; - } - } - } - if (err) { - node.error(err); - } - }); - },120000)); - }); - - } else if (this.tags !== "") { - try { - var thing = 'statuses/filter'; - if (this.user === "true") { thing = 'user'; } - var st = { track: [node.tags] }; - var bits = node.tags.split(","); - if (bits.length == 4) { - if ((Number(bits[0]) < Number(bits[2])) && (Number(bits[1]) < Number(bits[3]))) { - st = { locations: node.tags }; - } - else { - node.log("possible bad geo area format. Should be lower-left lon, lat, upper-right lon, lat"); - } - } - - var setupStream = function() { - if (node.active) { - twit.stream(thing, st, function(stream) { - //console.log(st); - //twit.stream('user', { track: [node.tags] }, function(stream) { - //twit.stream('site', { track: [node.tags] }, function(stream) { - //twit.stream('statuses/filter', { track: [node.tags] }, function(stream) { - node.stream = stream; - stream.on('data', function(tweet) { - if (tweet.user !== undefined) { - var where = tweet.user.location; - var la = tweet.lang || tweet.user.lang; - var msg = { topic:node.topic+"/"+tweet.user.screen_name, payload:tweet.text, lang:la, tweet:tweet }; - if (where) { - msg.location = {place:where}; - addLocationToTweet(msg); - } - node.send(msg); - } - }); - stream.on('limit', function(tweet) { - node.warn("tweet rate limit hit"); - }); - stream.on('error', function(tweet,rc) { - if (rc == 420) { - node.warn("Twitter rate limit hit"); - } else { - node.warn("Stream error:"+tweet.toString()+" ("+rc+")"); - } - setTimeout(setupStream,10000); - }); - stream.on('destroy', function (response) { - if (this.active) { - node.warn("twitter ended unexpectedly"); - setTimeout(setupStream,10000); - } - }); - }); - } - } - setupStream(); - } - catch (err) { - node.error(err); - } - } else { - this.error("Invalid tag property"); - } - } else { - this.error("missing twitter credentials"); - } - - this.on('close', function() { - if (this.stream) { - this.active = false; - this.stream.destroy(); - } - if (this.poll_ids) { - for (var i=0;i 140) { - msg.payload = msg.payload.slice(0,139); - node.warn("Tweet greater than 140 : truncated"); - } - - if (msg.media && Buffer.isBuffer(msg.media)) { - var apiUrl = "https://api.twitter.com/1.1/statuses/update_with_media.json"; - var signedUrl = oa.signUrl(apiUrl, - credentials.access_token, - credentials.access_token_secret, - "POST"); - - var r = request.post(signedUrl,function(err,httpResponse,body) { - if (err) { - node.error(err,msg); - node.status({fill:"red",shape:"ring",text:"failed"}); - } else { - var response = JSON.parse(body); - if (response.errors) { - var errorList = response.errors.map(function(er) { return er.code+": "+er.message }).join(", "); - node.error("Send tweet failed: "+errorList,msg); - node.status({fill:"red",shape:"ring",text:"failed"}); - } else { - node.status({}); - } - } - }); - var form = r.form(); - form.append("status",msg.payload); - form.append("media[]",msg.media,{filename:"image"}); - - } else { - twit.updateStatus(msg.payload, function (err, data) { - if (err) { - node.status({fill:"red",shape:"ring",text:"failed"}); - node.error(err,msg); - } - node.status({}); - }); - } - } - else { node.warn("No payload to tweet"); } - }); - } - } - RED.nodes.registerType("twitter out",TwitterOutNode); - - var oa = new OAuth( - "https://api.twitter.com/oauth/request_token", - "https://api.twitter.com/oauth/access_token", - "OKjYEd1ef2bfFolV25G5nQ", - "meRsltCktVMUI8gmggpXett7WBLd1k0qidYazoML6g", - "1.0", - null, - "HMAC-SHA1" - ); - - RED.httpAdmin.get('/twitter-credentials/:id/auth', function(req, res){ - var credentials = {}; - oa.getOAuthRequestToken({ - oauth_callback: req.query.callback - },function(error, oauth_token, oauth_token_secret, results){ - if (error) { - var resp = '

Oh no!

'+ - '

Something went wrong with the authentication process. The following error was returned:

'+ - '

'+error.statusCode+': '+error.data+'

'+ - '

One known cause of this type of failure is if the clock is wrong on system running Node-RED.'; - res.send(resp) - } else { - credentials.oauth_token = oauth_token; - credentials.oauth_token_secret = oauth_token_secret; - res.redirect('https://twitter.com/oauth/authorize?oauth_token='+oauth_token) - RED.nodes.addCredentials(req.params.id,credentials); - } - }); - }); - - RED.httpAdmin.get('/twitter-credentials/:id/auth/callback', function(req, res, next){ - var credentials = RED.nodes.getCredentials(req.params.id); - credentials.oauth_verifier = req.query.oauth_verifier; - - oa.getOAuthAccessToken( - credentials.oauth_token, - credentials.token_secret, - credentials.oauth_verifier, - function(error, oauth_access_token, oauth_access_token_secret, results){ - if (error){ - RED.log.error(error); - res.send("something in twitter oauth broke."); - } else { - credentials = {}; - credentials.access_token = oauth_access_token; - credentials.access_token_secret = oauth_access_token_secret; - credentials.screen_name = "@"+results.screen_name; - RED.nodes.addCredentials(req.params.id,credentials); - res.send("Authorised - you can close this window and return to Node-RED"); - } - } - ); - }); -} diff --git a/nodes/core/social/32-feedparse.html b/nodes/core/social/32-feedparse.html deleted file mode 100644 index 4e2925c87..000000000 --- a/nodes/core/social/32-feedparse.html +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - diff --git a/nodes/core/social/32-feedparse.js b/nodes/core/social/32-feedparse.js deleted file mode 100644 index 49ffe83f6..000000000 --- a/nodes/core/social/32-feedparse.js +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Copyright 2013,2014 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function(RED) { - "use strict"; - var FeedParser = require("feedparser"); - var request = require("request"); - - function FeedParseNode(n) { - RED.nodes.createNode(this,n); - this.url = n.url; - this.interval = (parseInt(n.interval)||15) * 60000; - var node = this; - this.interval_id = null; - this.seen = {}; - if (this.url !== "") { - var getFeed = function() { - var req = request(node.url, {timeout: 10000, pool: false}); - //req.setMaxListeners(50); - //req.setHeader('user-agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36'); - req.setHeader('accept', 'text/html,application/xhtml+xml'); - - var feedparser = new FeedParser(); - - req.on('error', function(err) { node.error(err); }); - - req.on('response', function(res) { - if (res.statusCode != 200) { node.warn('error - Bad status code'); } - else { res.pipe(feedparser); } - }); - - feedparser.on('error', function(error) { node.error(error); }); - - feedparser.on('readable', function () { - var stream = this, article; - while (article = stream.read()) { - if (!(article.guid in node.seen) || ( node.seen[article.guid] !== 0 && node.seen[article.guid] != article.date.getTime())) { - node.seen[article.guid] = article.date?article.date.getTime():0; - var msg = { - topic: article.origlink || article.link, - payload: article.description, - article: article - }; - node.send(msg); - } - } - }); - - feedparser.on('meta', function (meta) {}); - feedparser.on('end', function () {}); - }; - this.interval_id = setInterval(function() { getFeed(); }, node.interval); - getFeed(); - } else { - this.error("Invalid url"); - } - - this.on("close", function() { - if (this.interval_id != null) { - clearInterval(this.interval_id); - } - }); - } - - RED.nodes.registerType("feedparse",FeedParseNode); -} diff --git a/nodes/core/social/61-email.html b/nodes/core/social/61-email.html deleted file mode 100644 index d2e70219c..000000000 --- a/nodes/core/social/61-email.html +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - - - - - diff --git a/nodes/core/social/61-email.js b/nodes/core/social/61-email.js deleted file mode 100644 index 6d2145bf8..000000000 --- a/nodes/core/social/61-email.js +++ /dev/null @@ -1,283 +0,0 @@ -/** - * Copyright 2013,2014 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function(RED) { - "use strict"; - var nodemailer = require("nodemailer"); - var Imap = require('imap'); - - //console.log(nodemailer.Transport.transports.SMTP.wellKnownHosts); - - try { - var globalkeys = RED.settings.email || require(process.env.NODE_RED_HOME+"/../emailkeys.js"); - } catch(err) { - } - - function EmailNode(n) { - RED.nodes.createNode(this,n); - this.topic = n.topic; - this.name = n.name; - this.outserver = n.server; - this.outport = n.port; - var flag = false; - if (this.credentials && this.credentials.hasOwnProperty("userid")) { - this.userid = this.credentials.userid; - } else { - if (globalkeys) { - this.userid = globalkeys.user; - flag = true; - } else { - this.error("No e-mail userid set"); - } - } - if (this.credentials && this.credentials.hasOwnProperty("password")) { - this.password = this.credentials.password; - } else { - if (globalkeys) { - this.password = globalkeys.pass; - flag = true; - } else { - this.error("No e-mail password set"); - } - } - if (flag) { - RED.nodes.addCredentials(n.id,{userid:this.userid, password:this.password, global:true}); - } - var node = this; - - var smtpTransport = nodemailer.createTransport({ - host: node.outserver, - port: node.outport, - secure: true, - auth: { - user: node.userid, - pass: node.password - } - }); - - this.on("input", function(msg) { - if (msg.hasOwnProperty("payload")) { - if (smtpTransport) { - node.status({fill:"blue",shape:"dot",text:"sending"}); - if (msg.to && node.name && (msg.to !== node.name)) { - node.warn("Warning: msg properties can no longer override set node properties. See bit.ly/nr-override-msg-props"); - } - var sendopts = { from: node.userid }; // sender address - sendopts.to = node.name || msg.to; // comma separated list of addressees - sendopts.subject = msg.topic || msg.title || "Message from Node-RED"; // subject line - if (Buffer.isBuffer(msg.payload)) { // if it's a buffer in the payload then auto create an attachment instead - if (!msg.filename) { - var fe = "bin"; - if ((msg.payload[0] === 0xFF)&&(msg.payload[1] === 0xD8)) { fe = "jpg"; } - if ((msg.payload[0] === 0x47)&&(msg.payload[1] === 0x49)) { fe = "gif"; } //46 - if ((msg.payload[0] === 0x42)&&(msg.payload[1] === 0x4D)) { fe = "bmp"; } - if ((msg.payload[0] === 0x89)&&(msg.payload[1] === 0x50)) { fe = "png"; } //4E - msg.filename = "attachment."+fe; - } - sendopts.attachments = [ { content: msg.payload, filename:(msg.filename.replace(/^.*[\\\/]/, '') || "file.bin") } ]; - if (msg.hasOwnProperty("headers") && msg.headers.hasOwnProperty("content-type")) { - sendopts.attachments[0].contentType = msg.headers["content-type"]; - } - // Create some body text.. - sendopts.text = "Your file from Node-RED is attached : "+(msg.filename.replace(/^.*[\\\/]/, '') || "file.bin")+ (msg.hasOwnProperty("description") ? "\n\n"+msg.description : ""); - } - else { - var payload = RED.util.ensureString(msg.payload); - sendopts.text = payload; // plaintext body - if (/<[a-z][\s\S]*>/i.test(payload)) { sendopts.html = payload; } // html body - if (msg.attachments) { sendopts.attachments = msg.attachments; } // add attachments - } - smtpTransport.sendMail(sendopts, function(error, info) { - if (error) { - node.error(error,msg); - node.status({fill:"red",shape:"ring",text:"send failed"}); - } else { - node.log("Message sent: " + info.response); - node.status({}); - } - }); - } - else { node.warn("No Email credentials found. See info panel."); } - } - else { node.warn("No payload to send"); } - }); - } - RED.nodes.registerType("e-mail",EmailNode,{ - credentials: { - userid: {type:"text"}, - password: {type: "password"}, - global: { type:"boolean"} - } - }); - - function EmailInNode(n) { - RED.nodes.createNode(this,n); - this.name = n.name; - this.repeat = n.repeat * 1000 || 300000; - this.inserver = n.server || globalkeys.server || "imap.gmail.com"; - this.inport = n.port || globalkeys.port || "993"; - this.box = n.box || "INBOX"; - var flag = false; - - if (this.credentials && this.credentials.hasOwnProperty("userid")) { - this.userid = this.credentials.userid; - } else { - if (globalkeys) { - this.userid = globalkeys.user; - flag = true; - } else { - this.error("No e-mail userid set"); - } - } - if (this.credentials && this.credentials.hasOwnProperty("password")) { - this.password = this.credentials.password; - } else { - if (globalkeys) { - this.password = globalkeys.pass; - flag = true; - } else { - this.error("No e-mail password set"); - } - } - if (flag) { - RED.nodes.addCredentials(n.id,{userid:this.userid, password:this.password, global:true}); - } - - var node = this; - this.interval_id = null; - var oldmail = {}; - - var imap = new Imap({ - user: node.userid, - password: node.password, - host: node.inserver, - port: node.inport, - tls: true, - tlsOptions: { rejectUnauthorized: false }, - connTimeout: node.repeat, - authTimeout: node.repeat - }); - - if (!isNaN(this.repeat) && this.repeat > 0) { - node.log("repeat = "+this.repeat); - this.interval_id = setInterval( function() { - node.emit("input",{}); - }, this.repeat ); - } - - this.on("input", function(msg) { - imap.once('ready', function() { - node.status({fill:"blue",shape:"dot",text:"fetching"}); - var pay = {}; - imap.openBox(node.box, false, function(err, box) { - if (err) { - node.status({fill:"red",shape:"ring",text:"fetch folder error"}); - node.error("Failed to fetch folder "+node.box,err); - } - else { - if (box.messages.total > 0) { - //var f = imap.seq.fetch(box.messages.total + ':*', { markSeen:true, bodies: ['HEADER.FIELDS (FROM SUBJECT DATE TO CC BCC)','TEXT'] }); - var f = imap.seq.fetch(box.messages.total + ':*', { markSeen:true, bodies: ['HEADER','TEXT'] }); - f.on('message', function(msg, seqno) { - node.log('message: #'+ seqno); - var prefix = '(#' + seqno + ') '; - msg.on('body', function(stream, info) { - var buffer = ''; - stream.on('data', function(chunk) { - buffer += chunk.toString('utf8'); - }); - stream.on('end', function() { - if (info.which !== 'TEXT') { - var head = Imap.parseHeader(buffer); - pay.from = head.from[0]; - pay.topic = head.subject[0]; - pay.date = head.date[0]; - pay.header = head; - } else { - var parts = buffer.split("Content-Type"); - for (var p = 0; p < parts.length; p++) { - if (parts[p].indexOf("text/plain") >= 0) { - pay.payload = parts[p].split("\n").slice(1,-2).join("\n").trim(); - } - else if (parts[p].indexOf("text/html") >= 0) { - pay.html = parts[p].split("\n").slice(1,-2).join("\n").trim(); - } else { - pay.payload = parts[0]; - } - } - //pay.body = buffer; - } - }); - }); - msg.on('end', function() { - //node.log('Finished: '+prefix); - }); - }); - f.on('error', function(err) { - node.warn('fetch message error: ' + err); - node.status({fill:"red",shape:"ring",text:"fetch message error"}); - }); - f.on('end', function() { - delete(pay._msgid); - if (JSON.stringify(pay) !== oldmail) { - oldmail = JSON.stringify(pay); - node.send(pay); - node.log('received new email: '+pay.topic); - } - else { node.log('duplicate not sent: '+pay.topic); } - //node.status({fill:"green",shape:"dot",text:"ok"}); - node.status({}); - }); - } - else { - node.log("you have achieved inbox zero"); - //node.status({fill:"green",shape:"dot",text:"ok"}); - node.status({}); - } - } - imap.end(); - }); - }); - node.status({fill:"grey",shape:"dot",text:"connecting"}); - imap.connect(); - }); - - imap.on('error', function(err) { - node.log(err); - node.status({fill:"red",shape:"ring",text:"connect error"}); - }); - - this.on("error", function(err) { - node.log("error: ",err); - }); - - this.on("close", function() { - if (this.interval_id != null) { - clearInterval(this.interval_id); - } - if (imap) { imap.destroy(); } - }); - - node.emit("input",{}); - } - RED.nodes.registerType("e-mail in",EmailInNode,{ - credentials: { - userid: {type:"text"}, - password: {type: "password"}, - global: { type:"boolean"} - } - }); -}; diff --git a/nodes/core/social/91-irc.html b/nodes/core/social/91-irc.html deleted file mode 100644 index 61ced52aa..000000000 --- a/nodes/core/social/91-irc.html +++ /dev/null @@ -1,235 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/nodes/core/social/91-irc.js b/nodes/core/social/91-irc.js deleted file mode 100644 index ffc1bc28b..000000000 --- a/nodes/core/social/91-irc.js +++ /dev/null @@ -1,282 +0,0 @@ -/** - * Copyright 2013,2014 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -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); - this.server = n.server; - this.port = n.port || 6667; - this.ssl = n.ssl || false; - this.cert = n.cert || false; - this.channel = n.channel; - this.nickname = n.nickname; - this.lastseen = 0; - this.ircclient = null; - this.on("close", function() { - if (this.ircclient != null) { - this.ircclient.removeAllListeners(); - this.ircclient.disconnect(); - } - }); - } - RED.nodes.registerType("irc-server",IRCServerNode); - - - // The Input Node - function IrcInNode(n) { - RED.nodes.createNode(this,n); - this.ircserver = n.ircserver; - this.serverConfig = RED.nodes.getNode(this.ircserver); - this.channel = n.channel || this.serverConfig.channel; - var node = this; - if (node.serverConfig.ircclient === null) { - node.log("CONNECT: "+node.serverConfig.server); - node.status({fill:"grey",shape:"dot",text:"connecting"}); - var options = {autoConnect:true,autoRejoin:false,floodProtection:true,secure:node.serverConfig.ssl,selfSigned:node.serverConfig.cert,port:node.serverConfig.port,retryDelay:20000}; - 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) { - if (RED.settings.verbose) { node.log("ERR: "+JSON.stringify(message)); } - }); - node.serverConfig.ircclient.addListener('netError', function(message) { - node.serverConfig.lastseen = Date.now(); - if (RED.settings.verbose) { node.log("NET: "+JSON.stringify(message)); } - node.status({fill:"red",shape:"ring",text:"net error"}); - }); - node.serverConfig.ircclient.addListener('connect', function() { - node.serverConfig.lastseen = Date.now(); - if (RED.settings.verbose) { node.log("CONNECTED "); } - }); - node.serverConfig.ircclient.addListener('registered', function(message) { - node.serverConfig.lastseen = Date.now(); - node.log(node.serverConfig.ircclient.nick+" ONLINE: "+message.server); - node.status({fill:"yellow",shape:"dot",text:"connected"}); - node.serverConfig.ircclient.join( node.channel, function(data) { - node.log(data+" JOINED: "+node.channel); - node.status({fill:"green",shape:"dot",text:"joined"}); - }); - }); - node.serverConfig.ircclient.addListener('ping', function(server) { - node.serverConfig.lastseen = Date.now(); - if (RED.settings.verbose) { node.log("PING from "+JSON.stringify(server)); } - node.status({fill:"green",shape:"dot",text:"ok"}); - }); - node.serverConfig.ircclient.addListener('quit', function(nick, reason, channels, message) { - node.serverConfig.lastseen = Date.now(); - if (RED.settings.verbose) { node.log("QUIT: "+nick+" "+reason+" "+channels+" "+JSON.stringify(message)); } - node.status({fill:"grey",shape:"ring",text:"quit"}); - //node.serverConfig.ircclient.disconnect( function() { - // node.serverConfig.ircclient.connect(); - //}); - //if (RED.settings.verbose) { node.log("restart"); } // then retry - }); - node.serverConfig.ircclient.addListener('raw', function (message) { // any message received means we are alive - //console.log("RAW:"+JSON.stringify(message)); - if (message.commandType === "reply") { - //console.log("RAW:"+JSON.stringify(message)); - node.serverConfig.lastseen = Date.now(); - } - }); - node.recon = setInterval( function() { - //console.log("CHK ",(Date.now()-node.serverConfig.lastseen)/1000); - if ((Date.now()-node.serverConfig.lastseen) > 240000) { // if more than 4 mins since last seen - node.serverConfig.ircclient.send.apply(node.serverConfig.ircclient,["TIME"]); // request time to check link - } - if ((Date.now()-node.serverConfig.lastseen) > 300000) { // If more than 5 mins - //node.serverConfig.ircclient.disconnect(); - //node.serverConfig.ircclient.connect(); - node.status({fill:"grey",shape:"ring",text:"no connection"}); - if (RED.settings.verbose) { node.log("CONNECTION LOST ?"); } - } - //node.serverConfig.ircclient.send.apply(node.serverConfig.ircclient,["TIME"]); // request time to check link - }, 60000); // check every 1 min - //node.serverConfig.ircclient.connect(); - } - else { node.status({text:""}); } - node.ircclient = node.serverConfig.ircclient; - - node.ircclient.addListener('registered', function(message) { - //node.log(node.ircclient.nick+" ONLINE"); - node.status({fill:"yellow",shape:"dot",text:"connected"}); - node.ircclient.join( node.channel, function(data) { - // node.log(data+" JOINED "+node.channel); - node.status({fill:"green",shape:"dot",text:"joined"}); - }); - }); - node.ircclient.addListener('message', function (from, to, message) { - //node.log(from + ' => ' + to + ' : ' + message); - if (~node.channel.toLowerCase().indexOf(to.toLowerCase())) { - var msg = { "topic":from, "from":from, "to":to, "payload":message }; - node.send([msg,null]); - } - //else { console.log(node.channel,to); } - }); - node.ircclient.addListener('pm', function(from, message) { - //node.log("PM => "+from + ': ' + message); - var msg = { "topic":from, "from":from, "to":"PRIV", "payload":message }; - node.send([msg,null]); - }); - node.ircclient.addListener('join', function(channel, who) { - var msg = { "payload": { "type":"join", "who":who, "channel":channel } }; - node.send([null,msg]); - //node.log(who+' has joined '+channel); - }); - node.ircclient.addListener('invite', function(channel, from, message) { - var msg = { "payload": { "type":"invite", "who":from, "channel":channel, "message":message } }; - node.send([null,msg]); - //node.log(from+' sent invite to '+channel+': '+message); - }); - node.ircclient.addListener('part', function(channel, who, reason) { - var msg = { "payload": { "type":"part", "who":who, "channel":channel, "reason":reason } }; - node.send([null,msg]); - //node.log(who+' has left '+channel+': '+reason); - }); - node.ircclient.addListener('quit', function(nick, reason, channels, message) { - var msg = { "payload": { "type":"quit", "who":nick, "channel":channels, "reason":reason } }; - node.send([null,msg]); - //node.log(nick+' has quit '+channels+': '+reason); - }); - node.ircclient.addListener('kick', function(channel, who, by, reason) { - var msg = { "payload": { "type":"kick", "who":who, "channel":channel, "by":by, "reason":reason } }; - node.send([null,msg]); - //node.log(who+' was kicked from '+channel+' by '+by+': '+reason); - }); - node.ircclient.addListener('names', function (channel, nicks) { - var msg = { "payload": { "type": "names", "channel": channel, "names": nicks} }; - node.send([null, msg]); - }); - node.ircclient.addListener('raw', function (message) { // any message means we are alive - node.serverConfig.lastseen = Date.now(); - }); - node.on("close", function() { - node.ircclient.removeAllListeners(); - if (node.recon) { clearInterval(node.recon); } - }); - } - RED.nodes.registerType("irc in",IrcInNode); - - - // The Output Node - function IrcOutNode(n) { - RED.nodes.createNode(this,n); - this.sendFlag = n.sendObject; - this.ircserver = n.ircserver; - this.serverConfig = RED.nodes.getNode(this.ircserver); - this.channel = n.channel || this.serverConfig.channel; - var node = this; - if (node.serverConfig.ircclient === null) { - node.log("CONNECT: "+node.serverConfig.server); - node.status({fill:"grey",shape:"dot",text:"connecting"}); - var options = {autoConnect:true,autoRejoin:false,floodProtection:true,secure:node.serverConfig.ssl,selfSigned:node.serverConfig.cert,port:node.serverConfig.port,retryDelay:20000}; - 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) { - if (RED.settings.verbose) { node.log("ERR: "+JSON.stringify(message)); } - }); - node.serverConfig.ircclient.addListener('netError', function(message) { - node.serverConfig.lastseen = Date.now(); - if (RED.settings.verbose) { node.log("NET: "+JSON.stringify(message)); } - node.status({fill:"red",shape:"ring",text:"net error"}); - }); - node.serverConfig.ircclient.addListener('connect', function() { - node.serverConfig.lastseen = Date.now(); - if (RED.settings.verbose) { node.log("CONNECTED "); } - }); - node.serverConfig.ircclient.addListener('registered', function(message) { - node.serverConfig.lastseen = Date.now(); - node.log(node.serverConfig.ircclient.nick+" ONLINE: "+message.server); - node.status({fill:"yellow",shape:"dot",text:"connected"}); - node.serverConfig.ircclient.join( node.channel, function(data) { - node.log(data+" JOINED: "+node.channel); - node.status({fill:"green",shape:"dot",text:"joined"}); - }); - }); - node.serverConfig.ircclient.addListener('ping', function(server) { - node.serverConfig.lastseen = Date.now(); - if (RED.settings.verbose) { node.log("PING from "+JSON.stringify(server)); } - node.status({fill:"green",shape:"dot",text:"ok"}); - }); - node.serverConfig.ircclient.addListener('quit', function(nick, reason, channels, message) { - node.serverConfig.lastseen = Date.now(); - if (RED.settings.verbose) { node.log("QUIT: "+nick+" "+reason+" "+channels+" "+JSON.stringify(message)); } - node.status({fill:"grey",shape:"ring",text:"quit"}); - //node.serverConfig.ircclient.disconnect( function() { - // node.serverConfig.ircclient.connect(); - //}); - //if (RED.settings.verbose) { node.log("restart"); } // then retry - }); - node.serverConfig.ircclient.addListener('raw', function (message) { // any message received means we are alive - //console.log("RAW:"+JSON.stringify(message)); - if (message.commandType === "reply") { - //console.log("RAW:"+JSON.stringify(message)); - node.serverConfig.lastseen = Date.now(); - } - }); - node.recon = setInterval( function() { - //console.log("CHK ",(Date.now()-node.serverConfig.lastseen)/1000); - if ((Date.now()-node.serverConfig.lastseen) > 240000) { // if more than 4 mins since last seen - node.serverConfig.ircclient.send.apply(node.serverConfig.ircclient,["TIME"]); // request time to check link - } - if ((Date.now()-node.serverConfig.lastseen) > 300000) { // If more than 5 mins - //node.serverConfig.ircclient.disconnect(); - //node.serverConfig.ircclient.connect(); - node.status({fill:"grey",shape:"ring",text:"no connection"}); - if (RED.settings.verbose) { node.log("CONNECTION LOST ?"); } - } - //node.serverConfig.ircclient.send.apply(node.serverConfig.ircclient,["TIME"]); // request time to check link - }, 60000); // check every 1 min - //node.serverConfig.ircclient.connect(); - } - else { node.status({text:""}); } - node.ircclient = node.serverConfig.ircclient; - - node.on("input", function(msg) { - if (Object.prototype.toString.call( msg.raw ) === '[object Array]') { - if (RED.settings.verbose) { node.log("RAW command:"+msg.raw); } - node.ircclient.send.apply(node.ircclient,msg.raw); - } - else { - if (msg._topic) { delete msg._topic; } - var ch = node.channel.split(","); // split on , so we can send to multiple - if (node.sendFlag == "true") { // override channels with msg.topic - if ((msg.hasOwnProperty('topic'))&&(typeof msg.topic === "string")) { - ch = msg.topic.split(","); // split on , so we can send to multiple - } - else { node.warn("msg.topic not set"); } - } - for (var c = 0; c < ch.length; c++) { - if (node.sendFlag == "false") { // send whole message object to each channel - node.ircclient.say(ch[c], JSON.stringify(msg)); - } - else { // send just the payload to each channel - if (typeof msg.payload === "object") { msg.payload = JSON.stringify(msg.payload); } - node.ircclient.say(ch[c], msg.payload); - } - } - } - }); - - node.on("close", function() { - node.ircclient.removeAllListeners(); - if (node.recon) { clearInterval(node.recon); } - }); - } - RED.nodes.registerType("irc out",IrcOutNode); -} diff --git a/nodes/core/storage/65-redisout.html b/nodes/core/storage/65-redisout.html deleted file mode 100644 index dc1f7b838..000000000 --- a/nodes/core/storage/65-redisout.html +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - - diff --git a/nodes/core/storage/65-redisout.js b/nodes/core/storage/65-redisout.js deleted file mode 100644 index 18a5f2b4a..000000000 --- a/nodes/core/storage/65-redisout.js +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Copyright 2013 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function(RED) { - "use strict"; - var redis = require("redis"); - - var hashFieldRE = /^([^=]+)=(.*)$/; - - var redisConnectionPool = function() { - var connections = {}; - var obj = { - get: function(host,port) { - var id = host+":"+port; - if (!connections[id]) { - connections[id] = redis.createClient(port,host); - connections[id].on("error",function(err) { - RED.log.error(err); - }); - connections[id].on("connect",function() { - if (RED.settings.verbose) { RED.log.info("connected to "+host+":"+port); } - }); - connections[id]._id = id; - connections[id]._nodeCount = 0; - } - connections[id]._nodeCount += 1; - return connections[id]; - }, - close: function(connection) { - connection._nodeCount -= 1; - if (connection._nodeCount === 0) { - if (connection) { - clearTimeout(connection.retry_timer); - connection.end(); - } - delete connections[connection._id]; - } - } - }; - return obj; - }(); - - - function RedisOutNode(n) { - RED.nodes.createNode(this,n); - this.port = n.port||"6379"; - this.hostname = n.hostname||"127.0.0.1"; - this.key = n.key; - this.structtype = n.structtype; - - this.client = redisConnectionPool.get(this.hostname,this.port); - - if (this.client.connected) { - this.status({fill:"green",shape:"dot",text:"connected"}); - } else { - this.status({fill:"red",shape:"ring",text:"disconnected"},true); - } - - var node = this; - this.client.on("end", function() { - node.status({fill:"red",shape:"ring",text:"disconnected"}); - }); - this.client.on("connect", function() { - node.status({fill:"green",shape:"dot",text:"connected"}); - }); - - this.on("input", function(msg) { - var k = this.key || msg.topic; - if (k) { - if (this.structtype == "string") { - this.client.set(k,RED.util.ensureString(msg.payload)); - } else if (this.structtype == "hash") { - if (typeof msg.payload == "object") { - this.client.hmset(k,msg.payload); - } else { - var r = hashFieldRE.exec(msg.payload); - if (r) { - this.client.hset(k,r[1],r[2]); - } else { - this.warn("Invalid payload for redis hash"); - } - } - } else if (this.structtype == "set") { - this.client.sadd(k,msg.payload); - } else if (this.structtype == "list") { - this.client.rpush(k,msg.payload); - } - } else { - this.warn("No key or topic set"); - } - }); - this.on("close", function() { - redisConnectionPool.close(node.client); - }); - } - RED.nodes.registerType("redis out",RedisOutNode); -} diff --git a/nodes/core/storage/66-mongodb.html b/nodes/core/storage/66-mongodb.html deleted file mode 100644 index 1b448de95..000000000 --- a/nodes/core/storage/66-mongodb.html +++ /dev/null @@ -1,231 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/nodes/core/storage/66-mongodb.js b/nodes/core/storage/66-mongodb.js deleted file mode 100644 index 0e67fd291..000000000 --- a/nodes/core/storage/66-mongodb.js +++ /dev/null @@ -1,244 +0,0 @@ -/** - * Copyright 2013,2014 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -module.exports = function(RED) { - "use strict"; - var mongo = require('mongodb'); - var MongoClient = mongo.MongoClient; - - function MongoNode(n) { - RED.nodes.createNode(this,n); - this.hostname = n.hostname; - this.port = n.port; - this.db = n.db; - this.name = n.name; - - var url = "mongodb://"; - if (this.credentials && this.credentials.user && this.credentials.password) { - url += this.credentials.user+":"+this.credentials.password+"@"; - } - url += this.hostname+":"+this.port+"/"+this.db; - - this.url = url; - } - - RED.nodes.registerType("mongodb",MongoNode,{ - credentials: { - user: {type:"text"}, - password: {type: "password"} - } - }); - - function ensureValidSelectorObject(selector) { - if (selector != null && (typeof selector != 'object' || Buffer.isBuffer(selector))) { - return {}; - } - return selector; - } - - - function MongoOutNode(n) { - RED.nodes.createNode(this,n); - this.collection = n.collection; - this.mongodb = n.mongodb; - this.payonly = n.payonly || false; - this.upsert = n.upsert || false; - this.multi = n.multi || false; - this.operation = n.operation; - this.mongoConfig = RED.nodes.getNode(this.mongodb); - - if (this.mongoConfig) { - var node = this; - MongoClient.connect(this.mongoConfig.url, function(err, db) { - if (err) { - node.error(err); - } else { - node.clientDb = db; - var coll; - if (node.collection) { - coll = db.collection(node.collection); - } - node.on("input",function(msg) { - if (!node.collection) { - if (msg.collection) { - coll = db.collection(msg.collection); - } else { - node.error("No collection defined",msg); - return; - } - } - delete msg._topic; - delete msg.collection; - if (node.operation === "store") { - if (node.payonly) { - if (typeof msg.payload !== "object") { - msg.payload = {"payload": msg.payload}; - } - coll.save(msg.payload,function(err, item) { - if (err) { - node.error(err,msg); - } - }); - } else { - coll.save(msg,function(err, item) { - if (err) { - node.error(err,msg); - } - }); - } - } else if (node.operation === "insert") { - if (node.payonly) { - if (typeof msg.payload !== "object") { - msg.payload = {"payload": msg.payload}; - } - coll.insert(msg.payload, function(err, item) { - if (err) { - node.error(err,msg); - } - }); - } else { - coll.insert(msg, function(err,item) { - if (err) { - node.error(err,msg); - } - }); - } - } else if (node.operation === "update") { - if (typeof msg.payload !== "object") { - msg.payload = {"payload": msg.payload}; - } - var query = msg.query || {}; - var payload = msg.payload || {}; - var options = { - upsert: node.upsert, - multi: node.multi - }; - - coll.update(query, payload, options, function(err, item) { - if (err) { - node.error(err,msg); - } - }); - } else if (node.operation === "delete") { - coll.remove(msg.payload, function(err, items) { - if (err) { - node.error(err,msg); - } - }); - } - }); - } - }); - } else { - this.error("missing mongodb configuration"); - } - - this.on("close", function() { - if (this.clientDb) { - this.clientDb.close(); - } - }); - } - RED.nodes.registerType("mongodb out",MongoOutNode); - - function MongoInNode(n) { - RED.nodes.createNode(this,n); - this.collection = n.collection; - this.mongodb = n.mongodb; - this.operation = n.operation || "find"; - this.mongoConfig = RED.nodes.getNode(this.mongodb); - - if (this.mongoConfig) { - var node = this; - var selector; - MongoClient.connect(this.mongoConfig.url, function(err,db) { - if (err) { - node.error(err); - } else { - node.clientDb = db; - var coll; - if (node.collection) { - coll = db.collection(node.collection); - } - node.on("input", function(msg) { - if (!node.collection) { - if (msg.collection) { - coll = db.collection(msg.collection); - } else { - node.error("No collection defined"); - return; - } - } - if (node.operation === "find") { - msg.projection = msg.projection || {}; - selector = ensureValidSelectorObject(msg.payload); - var limit = msg.limit; - if (typeof limit === "string" && !isNaN(limit)) { - limit = Number(limit); - } - var skip = msg.skip; - if (typeof skip === "string" && !isNaN(skip)) { - skip = Number(skip); - } - - coll.find(selector,msg.projection).sort(msg.sort).limit(limit).skip(skip).toArray(function(err, items) { - if (err) { - node.error(err); - } else { - msg.payload = items; - delete msg.projection; - delete msg.sort; - delete msg.limit; - delete msg.skip; - node.send(msg); - } - }); - } else if (node.operation === "count") { - selector = ensureValidSelectorObject(msg.payload); - coll.count(selector, function(err, count) { - if (err) { - node.error(err); - } else { - msg.payload = count; - node.send(msg); - } - }); - } else if (node.operation === "aggregate") { - msg.payload = (Array.isArray(msg.payload)) ? msg.payload : []; - coll.aggregate(msg.payload, function(err, result) { - if (err) { - node.error(err); - } else { - msg.payload = result; - node.send(msg); - } - }); - } - }); - } - }); - } else { - this.error("missing mongodb configuration"); - } - - this.on("close", function() { - if (this.clientDb) { - this.clientDb.close(); - } - }); - } - RED.nodes.registerType("mongodb in",MongoInNode); -} diff --git a/package.json b/package.json index 9a30c9107..8e0d63e56 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version" : "0.10.7", "description" : "A visual tool for wiring the Internet of Things", "homepage" : "http://nodered.org", - "license" : "Apache", + "license" : "Apache-2.0", "repository" : { "type":"git", "url":"https://github.com/node-red/node-red.git" @@ -30,35 +30,31 @@ "bcryptjs": "2.1.0", "nopt": "3.0.1", "mqtt": "0.3.x", - "ws": "0.7.1", + "ws": "0.7.2", "fs-extra": "0.16.3", "clone": "0.2.0", "mustache": "1.0.0", "cron":"1.0.6", "raw-body":"1.3.2", - "twitter-ng":"0.6.2", - "oauth":"0.9.12", "xml2js":"0.4.4", "sentiment":"0.2.3", "follow-redirects":"0.0.3", "cors":"2.5.3", - "cheerio":"0.18.0", + "cheerio":"0.19.0", "uglify-js":"2.4.16", - "nodemailer":"1.3.0", - "imap":"0.8.14", - "request":"2.42.0", "on-headers":"1.0.0", "is-utf8":"0.2.0", - "feedparser":"0.19.2", "fs.notify":"0.0.4", "passport":"0.2.1", "passport-http-bearer":"1.0.1", "passport-oauth2-client-password":"0.1.2", - "oauth2orize":"1.0.1" + "oauth2orize":"1.0.1", + "node-red-node-feedparser":"0.0.2", + "node-red-node-email":"0.0.1", + "node-red-node-twitter":"0.0.4" }, "optionalDependencies": { - "irc":"0.3.9", - "serialport":"1.4.10", + "node-red-node-serialport":"0.0.1", "bcrypt":"0.8.1" }, "devDependencies": {