freifunk-bot

Modular parser for the hackerspace door status with handlers for multiple services
git clone git://archive.git.mtrnord.blog/MTRNord/freifunk-bot.git
Log | Files | Refs | README | LICENSE

commit 669022bda92225c6fdadf13f9927bb701967b809
parent 607d859cbe8e7d2eb21ef1c7a2fa3baf5586e789
Author: Marcel Radzio <mtrnord1@gmail.com>
Date:   Tue,  5 Jan 2016 12:12:49 +0100

Update dependencies

Diffstat:
M.gitignore | 54+++++++++++++++++++++++++++---------------------------
MLICENSE.md | 4++--
MREADME.md | 62+++++++++++++++++++++++++++++++-------------------------------
Mconfigs/commands.json | 192++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mconfigs/params.json | 28++++++++++++++--------------
Mhandlers/irc.js | 476++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mhandlers/pushbullet.js | 21++++++++++-----------
Mhandlers/ssh_server.js | 110++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mmain.js | 176++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mpackage.json | 14++++++--------
10 files changed, 567 insertions(+), 570 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,27 +1,27 @@ -# Logs -logs -*.log - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directory -# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git -node_modules +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git +node_modules diff --git a/LICENSE.md b/LICENSE.md @@ -1,3 +1,3 @@ -This Project is under the [DBAD PUBLIC LICENSE](https://github.com/philsturgeon/dbad/blob/master/LICENSE-en.md "DON'T BE A DICK PUBLIC LICENSE") and the [DBADJ PUBLIC LICENSE](https://github.com/philsturgeon/dbad/blob/master/LICENSE-en.md "Don't Be a Jerk: The Open Source Software License"). - +This Project is under the [DBAD PUBLIC LICENSE](https://github.com/philsturgeon/dbad/blob/master/LICENSE-en.md "DON'T BE A DICK PUBLIC LICENSE") and the [DBADJ PUBLIC LICENSE](https://github.com/philsturgeon/dbad/blob/master/LICENSE-en.md "Don't Be a Jerk: The Open Source Software License"). + Other §2 in this project than in the DBAD §2: "If you become rich through modifications, related works/services, or supporting the original work, share the love. Only a dick would make loads off this work and not buy the original work's creator(s) a Club Mate." :) (PIzza is also ok) \ No newline at end of file diff --git a/README.md b/README.md @@ -1,31 +1,31 @@ -Nordlab Bot -=========== -Modular parser for the hackerspace door status with handlers for multiple services and IRC Bot for the Nordlab e.V. - -How to install -============== -1. npm install -2. npm start - -Commandline options -=================== -When using commandline arguments use ```node main.js``` to start.<br> -```--noupdate``` - stops bot from getting updates <br> - -Commands -======== -```!help | !hilfe``` - Lists all commands in a PM<br> -```!doorstatus``` - Send an PM with the actual Door Status<br> -```!doorstatus [arg]``` - If the arg is <b>"this"</b> it sends in the actual channel the Door Status or is there an <b>existing channel as argument</b> it sends to the channel which is the argument<br> -```!where``` - Send an PM with the address of the Hackerspace<br> -```!who``` - Send an PM with information about who can go to the Hackerspace<br> -```!when``` - Send an PM with information about when the Hackerspace usually is open<br> -```!source``` - Send an PM with the link of this repo. If you add <b>"this"</b> after it you can post it in the actual channel<br> -```!license``` - Send an PM with the link of the bot license<br> -```!afk``` - Send in the actual channel that you are A(way) F(rom) K(eyboard)<br> -```!alone``` - Send in the actual channel that you are alone in the channel<br> -```!freifunk``` - Send in the actual channel a link with an meme about Freifunk<br> - -Updates -======= -The Bot pulls the repo every day at 2am (if not deativated) and restarts the bot. So it is always UpTo-Date :)<br> +Nordlab Bot +=========== +Modular parser for the hackerspace door status with handlers for multiple services and IRC Bot for the Nordlab e.V. + +How to install +============== +1. npm install +2. npm start + +Commandline options +=================== +When using commandline arguments use ```node main.js``` to start.<br> +```--noupdate``` - stops bot from getting updates <br> + +Commands +======== +```!help | !hilfe``` - Lists all commands in a PM<br> +```!doorstatus``` - Send an PM with the actual Door Status<br> +```!doorstatus [arg]``` - If the arg is <b>"this"</b> it sends in the actual channel the Door Status or is there an <b>existing channel as argument</b> it sends to the channel which is the argument<br> +```!where``` - Send an PM with the address of the Hackerspace<br> +```!who``` - Send an PM with information about who can go to the Hackerspace<br> +```!when``` - Send an PM with information about when the Hackerspace usually is open<br> +```!source``` - Send an PM with the link of this repo. If you add <b>"this"</b> after it you can post it in the actual channel<br> +```!license``` - Send an PM with the link of the bot license<br> +```!afk``` - Send in the actual channel that you are A(way) F(rom) K(eyboard)<br> +```!alone``` - Send in the actual channel that you are alone in the channel<br> +```!freifunk``` - Send in the actual channel a link with an meme about Freifunk<br> + +Updates +======= +The Bot pulls the repo every day at 2am (if not deativated) and restarts the bot. So it is always UpTo-Date :)<br> diff --git a/configs/commands.json b/configs/commands.json @@ -1,96 +1,96 @@ -{ - "commands": [ - { - "keyword": "help", - "message": "Here is your Help!\nCommand List:\n- !help - Shows this page.\n- !DoorStatus - Shows the actual Door Status in an PM\n- !DoorStatus channel - Shows the actual Door Status in the channel from where it was run\n- !where - Shows the address of the Nordlab e.V.\n- !who - Shows who is allowed to come to the Nordlab e.V.\n- !when - Shows who the Nordlab e.V. Hackerspace usually is open\n- !source - Shows where the source of this bot is.\n- !license - What is the license of the bot?????????", - "argument": "1", - "target": "from" - }, - { - "keyword": "hilfe", - "message": "Hier ist die Hilfe!\nBefehl-Liste:\n- !hilfe - Zeigt diese Seite an.\n- !DoorStatus - Sendet eine PM mit dem aktuellen Status\n- !DoorStatus channel - Sendet in den Channel wo der Befehl ausgeführt wurde den aktuellen Status\n- !where - Zeigt die Addresse vom Nordlab e.V.\n- !who - Zeigt wer alles in den Nordlab e.V. kommen darf\n- !when - Zeigt wann der Nordlab e.V. Hackerspace geöffnet hat\n- !source - Zeigt wo die Sourcen des Bot's sind.\n- !license - HILFE! Welche Lizenz hat der Bot?????????", - "argument": "1", - "target": "from" - }, - { - "keyword": "where", - "message": "You can find the Hackerspace in:\nOffener Kanal Flensburg\nSt.-Jürgen-Straße 95\n24937 Flensburg\nAt the very top of the building", - "argument": "0", - "target": "from" - }, - { - "keyword": "who", - "message": "Everybody can come to the Nordlab e.V.", - "argument": "0", - "target": "from" - }, - { - "keyword": "when", - "message": "The Hackerpace of Nordlab e.V. is usually opened every Monday at 6pm o'clock.", - "argument": "0", - "target": "from" - }, - { - "keyword": "source", - "message": "You can find the source of this bot at https://github.com/MTRNord/nordlab-hackerspace-door", - "argument": "0", - "target": "from" - }, - { - "keyword": "license", - "message": "You can find the license of this bot at https://github.com/MTRNord/nordlab-hackerspace-door/blob/master/LICENSE.md", - "argument": "0", - "target": "from" - }, - { - "keyword": "bug", - "message": "You have found an bug? :O Send it right now to https://github.com/MTRNord/nordlab-hackerspace-door/issues", - "argument": "0", - "target": "from" - }, - { - "keyword": "klassiker", - "message": "Für mehr oder weniger hilfreiche Kommentare den klassiker fragen und wenn er mal nicht reagiert ist er damit beschäftigt dem MTRNord damit zu queälen seinen realnamen nicht zu sagen. :( <-- sad MTRNord face.", - "argument": "0", - "target": "to" - }, - { - "keyword": "stina", - "message": "Stina liebt unzielgerichteten Unsinn *lach*", - "argument": "0", - "target": "to" - }, - { - "keyword": "afk", - "before": "from", - "message": " is now afk.", - "argument": "0", - "target": "to" - }, - { - "keyword": "alone", - "before": "from", - "message": " is now alone.", - "argument": "0", - "target": "to" - }, - { - "keyword": "freifunk", - "message": "http://memegen.link/buzz/freifunk/everywhere.-the-dream.jpg", - "argument": "0", - "target": "to" - }, - { - "keyword": "todo", - "message": "- Add ability to do multiple server connections\n- Add SSH Admin Control Server for editing the bot easily", - "argument": "0", - "target": "from" - }, - { - "keyword": "xmas", - "message": "Der NordlabBot wünscht euch allen eine frohe und besinliche Weihnachtszeit :)", - "argument": "0", - "target": "to" - } - ] -} +{ + "commands": [ + { + "keyword": "help", + "message": "Here is your Help!\nCommand List:\n- !help - Shows this page.\n- !DoorStatus - Shows the actual Door Status in an PM\n- !DoorStatus channel - Shows the actual Door Status in the channel from where it was run\n- !where - Shows the address of the Nordlab e.V.\n- !who - Shows who is allowed to come to the Nordlab e.V.\n- !when - Shows who the Nordlab e.V. Hackerspace usually is open\n- !source - Shows where the source of this bot is.\n- !license - What is the license of the bot?????????", + "argument": "1", + "target": "from" + }, + { + "keyword": "hilfe", + "message": "Hier ist die Hilfe!\nBefehl-Liste:\n- !hilfe - Zeigt diese Seite an.\n- !DoorStatus - Sendet eine PM mit dem aktuellen Status\n- !DoorStatus channel - Sendet in den Channel wo der Befehl ausgeführt wurde den aktuellen Status\n- !where - Zeigt die Addresse vom Nordlab e.V.\n- !who - Zeigt wer alles in den Nordlab e.V. kommen darf\n- !when - Zeigt wann der Nordlab e.V. Hackerspace geöffnet hat\n- !source - Zeigt wo die Sourcen des Bot's sind.\n- !license - HILFE! Welche Lizenz hat der Bot?????????", + "argument": "1", + "target": "from" + }, + { + "keyword": "where", + "message": "You can find the Hackerspace in:\nOffener Kanal Flensburg\nSt.-Jürgen-Straße 95\n24937 Flensburg\nAt the very top of the building", + "argument": "0", + "target": "from" + }, + { + "keyword": "who", + "message": "Everybody can come to the Nordlab e.V.", + "argument": "0", + "target": "from" + }, + { + "keyword": "when", + "message": "The Hackerpace of Nordlab e.V. is usually opened every Monday at 6pm o'clock.", + "argument": "0", + "target": "from" + }, + { + "keyword": "source", + "message": "You can find the source of this bot at https://github.com/MTRNord/nordlab-hackerspace-door", + "argument": "0", + "target": "from" + }, + { + "keyword": "license", + "message": "You can find the license of this bot at https://github.com/MTRNord/nordlab-hackerspace-door/blob/master/LICENSE.md", + "argument": "0", + "target": "from" + }, + { + "keyword": "bug", + "message": "You have found an bug? :O Send it right now to https://github.com/MTRNord/nordlab-hackerspace-door/issues", + "argument": "0", + "target": "from" + }, + { + "keyword": "klassiker", + "message": "Für mehr oder weniger hilfreiche Kommentare den klassiker fragen und wenn er mal nicht reagiert ist er damit beschäftigt dem MTRNord damit zu queälen seinen realnamen nicht zu sagen. :( <-- sad MTRNord face.", + "argument": "0", + "target": "to" + }, + { + "keyword": "stina", + "message": "Stina liebt unzielgerichteten Unsinn *lach*", + "argument": "0", + "target": "to" + }, + { + "keyword": "afk", + "before": "from", + "message": " is now afk.", + "argument": "0", + "target": "to" + }, + { + "keyword": "alone", + "before": "from", + "message": " is now alone.", + "argument": "0", + "target": "to" + }, + { + "keyword": "freifunk", + "message": "http://memegen.link/buzz/freifunk/everywhere.-the-dream.jpg", + "argument": "0", + "target": "to" + }, + { + "keyword": "todo", + "message": "- Add ability to do multiple server connections\n- Add SSH Admin Control Server for editing the bot easily", + "argument": "0", + "target": "from" + }, + { + "keyword": "xmas", + "message": "Der NordlabBot wünscht euch allen eine frohe und besinliche Weihnachtszeit :)", + "argument": "0", + "target": "to" + } + ] +} diff --git a/configs/params.json b/configs/params.json @@ -1,15 +1,15 @@ -{ - "botname": "NordlabBot", - "autoupdate": 1, - "disconnect_meassage": "Bot was stopped!", - "servers": [ - { - "servername": "Lugfl", - "serveraddress": "irc.lugfl.de", - "main_channel": "#hackerspace", - "nickserv_pass": "NordlabBotPass", - "active": 1, - "debug": 0 - } - ] +{ + "botname": "NordlabBot", + "autoupdate": 1, + "disconnect_meassage": "Bot was stopped!", + "servers": [ + { + "servername": "Lugfl", + "serveraddress": "irc.lugfl.de", + "main_channel": "#hackerspace", + "nickserv_pass": "NordlabBotPass", + "active": 1, + "debug": 0 + } + ] } \ No newline at end of file diff --git a/handlers/irc.js b/handlers/irc.js @@ -1,238 +1,238 @@ -var irc = require('irc'); -var request = require('request'); -var command_config = require("../configs/commands.json"); -var params_config = require("../configs/params.json"); - -//Set Params -var botname = params_config["botname"]; -var autoupdate = params_config["autoupdate"]; -var disconnect_meassage = params_config["disconnect_meassage"]; -/* // TEMPLATE // -for (var key in params_config["servers"]) { - if (params_config["servers"].hasOwnProperty(key)) { - var servername = params_config["servers"][key]["servername"]; - var serveraddress = params_config["servers"][key]["serveraddress"]; - var main_channel = params_config["servers"][key]["main_channel"]; - var nickserv_pass = params_config["servers"][key]["nickserv_pass"]; - var active = params_config["servers"][key]["active"]; - var debug = params_config["servers"][key]["debug"]; - if (debug == 1) { - var debug = true; - }else{ - var debug = false; - } - } -} -*/ - - -for (var key in params_config["servers"]) { - if (params_config["servers"].hasOwnProperty(key)) { - var serveraddress = params_config["servers"][key]["serveraddress"]; - var main_channel = params_config["servers"][key]["main_channel"]; - var active = params_config["servers"][key]["active"]; - var debug = params_config["servers"][key]["debug"]; - if (debug == 1) { - var debug = true; - }else{ - var debug = false; - } - if (debug == false) { - console = console || {}; - console.log = function(){}; - } - if (active == 1) { - var bot = new irc.Client(serveraddress, botname, { - debug: debug, - channels: [main_channel, "#freifunk-flensburg"], - autoRejoin: true, - autoConnect: false, - messageSplit: 1000000 - }); - } - } -} - -module.exports = { - ircEndCustom: function (meassage) { - bot.disconnect(meassage); - }, - ircPreload: function () { - bot.addListener('error', function(message) { - setTimeout(function() { - console.log("wait 7sek"); - }, 7000); - - bot.send('nick', botname); - for (var key in params_config["servers"]) { - if (params_config["servers"].hasOwnProperty(key)) { - var nickserv_pass = params_config["servers"][key]["nickserv_pass"]; - bot.say('NickServ', 'identify ' + nickserv_pass); - } - } - }); - setTimeout(function() { - console.log("wait 7sek"); - }, 7000); - bot.connect(10, function() { - bot.send('nick', botname); - for (var key in params_config["servers"]) { - if (params_config["servers"].hasOwnProperty(key)) { - var nickserv_pass = params_config["servers"][key]["nickserv_pass"]; - var main_channel = params_config["servers"][key]["main_channel"]; - bot.say('NickServ', 'identify ' + nickserv_pass); - bot.join(main_channel); - } - } - bot.say('#hackerspace', 'Door Bot is starting to watch on the Door Status'); - }) - }, - ircSend: function (door_status) { - for (var key in params_config["servers"]) { - if (params_config["servers"].hasOwnProperty(key)) { - var main_channel = params_config["servers"][key]["main_channel"]; - bot.say(main_channel, 'Door Status changed to: ' + door_status); - bot.say("#freifunk-flensburg", 'Door Status changed to: ' + door_status); - } - } - bot.send('topic','#hackerspace "Hackerspace Flensburg - Treffen jeden Montag 18:00 Uhr im Offenen Kanal Flensburg! - Tür Status"' + door_status); - console.log("IRC Door Status Chnaged"); - }, - ircStopp: function() { - bot.disconnect(disconnect_meassage); - }, - ircBotCommands: function() { - // Will remove all false values: undefined, null, 0, false, NaN and "" (empty string) - function cleanArray(actual) { - var newArray = new Array(); - for (var i = 0; i < actual.length; i++) { - if (actual[i]) { - newArray.push(actual[i]); - } - } - return newArray; - } - - bot.addListener('message', function (from, to, message) { - message = message.toLowerCase(); - for (var key in command_config["commands"]) { - if (command_config["commands"].hasOwnProperty(key)) { - console.log("!" + JSON.stringify(command_config["commands"][key]["keyword"])); - if (message == ("!" + command_config["commands"][key]["keyword"])) { - if (command_config["commands"][key]["before"] == "from") { - if (command_config["commands"][key]["target"] == "from") { - bot.say(from, from + command_config["commands"][key]["message"]); - } else { - bot.say(to, from + command_config["commands"][key]["message"]); - } - } else { - if (!command_config["commands"][key]["before"]) { - if (command_config["commands"][key]["target"] == "from") { - bot.say(from, command_config["commands"][key]["message"]); - } else { - bot.say(to, command_config["commands"][key]["message"]); - } - } else { - if (command_config["commands"][key]["target"] == "from") { - bot.say(from, to + command_config["commands"][key]["message"]); - } else { - bot.say(to, to + command_config["commands"][key]["message"]); - } - } - } - } - } - } - var channel = message.split(" "); - channel = cleanArray(channel); - if (channel[0] + " " + channel[1] == "!source this") { - console.log("!source " + channel[1]); - if (channel[1] == "this") { - bot.join(to); - bot.say(to, "You can find the Source of this bot at https://github.com/MTRNord/nordlab-hackerspace-door"); - } - } - if (message == "!doorstatus") { - request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { - if (!error && response.statusCode == 200) { - door_status = body; - console.log(body); - } else { - door_status = error; - console.log(error); - } - if (!error && response.statusCode == 200) { - if (door_status == "geschlossen") { - door_status = "closed"; - } else { - door_status = "open"; - } - console.log(from + ' => ' + to + ': ' + message); - bot.say(from, "DoorStatus is: " + door_status); - }else{ - bot.say(from, "DoorStatus is not availible at this time"); - } - }).setMaxListeners(0); - } - if (channel[0] + " " + channel[1] == "!doorstatus this") { - request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { - if (!error && response.statusCode == 200) { - door_status = body; - console.log(body); - } else { - door_status = error; - console.log(error); - } - if (!error && response.statusCode == 200) { - if (door_status == "geschlossen") { - door_status = "closed"; - } else { - door_status = "open"; - } - console.log(message); - bot.list(); - console.log(channel[(channel.length-(channel.length-1))+1]); - console.log(channel.length); - if (channel[1] !== "this") { - if (channel[1] !== " ") { - bot.addListener('channellist', function (channel_list) { - for (var key in channel_list) { - if (channel_list.hasOwnProperty(key)) { - if (channel_list[key]["name"] == channel[1]) { - bot.join(channel[1]); - bot.say(channel[1], "DoorStatus is: " + door_status); - } - } - } - }); - } else { - bot.say(from, "DoorStatus is: " + door_status); - } - } else { - bot.join(to); - bot.say(to, "DoorStatus is: " + door_status); - } - }else{ - bot.say(from, "DoorStatus is not availible at this time"); - } - }).setMaxListeners(0); - } - if (message == "!kill") { - if ((from == "DasNordlicht") || (from == "MTRNord")) { - console.log(from + ' => ' + to + ': ' + message); - if (process.platform === "win32") { - var rl = require("readline").createInterface({ - input: process.stdin, - output: process.stdout - }); - bot.disconnect(disconnect_meassage); - process.exit(); - } - } - } - }) - }, - ircNick: function() { - bot.send('nick', botname); - } -}; +var irc = require('irc'); +var request = require('request'); +var command_config = require("../configs/commands.json"); +var params_config = require("../configs/params.json"); + +//Set Params +var botname = params_config["botname"]; +var autoupdate = params_config["autoupdate"]; +var disconnect_meassage = params_config["disconnect_meassage"]; +/* // TEMPLATE // +for (var key in params_config["servers"]) { + if (params_config["servers"].hasOwnProperty(key)) { + var servername = params_config["servers"][key]["servername"]; + var serveraddress = params_config["servers"][key]["serveraddress"]; + var main_channel = params_config["servers"][key]["main_channel"]; + var nickserv_pass = params_config["servers"][key]["nickserv_pass"]; + var active = params_config["servers"][key]["active"]; + var debug = params_config["servers"][key]["debug"]; + if (debug == 1) { + var debug = true; + }else{ + var debug = false; + } + } +} +*/ + + +for (var key in params_config["servers"]) { + if (params_config["servers"].hasOwnProperty(key)) { + var serveraddress = params_config["servers"][key]["serveraddress"]; + var main_channel = params_config["servers"][key]["main_channel"]; + var active = params_config["servers"][key]["active"]; + var debug = params_config["servers"][key]["debug"]; + if (debug == 1) { + var debug = true; + }else{ + var debug = false; + } + if (debug == false) { + console = console || {}; + console.log = function(){}; + } + if (active == 1) { + var bot = new irc.Client(serveraddress, botname, { + debug: debug, + channels: [main_channel, "#freifunk-flensburg"], + autoRejoin: true, + autoConnect: false, + messageSplit: 1000000 + }); + } + } +} + +module.exports = { + ircEndCustom: function (meassage) { + bot.disconnect(meassage); + }, + ircPreload: function () { + bot.addListener('error', function(message) { + setTimeout(function() { + console.log("wait 7sek"); + }, 7000); + + bot.send('nick', botname); + for (var key in params_config["servers"]) { + if (params_config["servers"].hasOwnProperty(key)) { + var nickserv_pass = params_config["servers"][key]["nickserv_pass"]; + bot.say('NickServ', 'identify ' + nickserv_pass); + } + } + }); + setTimeout(function() { + console.log("wait 7sek"); + }, 7000); + bot.connect(10, function() { + bot.send('nick', botname); + for (var key in params_config["servers"]) { + if (params_config["servers"].hasOwnProperty(key)) { + var nickserv_pass = params_config["servers"][key]["nickserv_pass"]; + var main_channel = params_config["servers"][key]["main_channel"]; + bot.say('NickServ', 'identify ' + nickserv_pass); + bot.join(main_channel); + } + } + bot.say('#hackerspace', 'Door Bot is starting to watch on the Door Status'); + }) + }, + ircSend: function (door_status) { + for (var key in params_config["servers"]) { + if (params_config["servers"].hasOwnProperty(key)) { + var main_channel = params_config["servers"][key]["main_channel"]; + bot.say(main_channel, 'Door Status changed to: ' + door_status); + bot.say("#freifunk-flensburg", 'Door Status changed to: ' + door_status); + } + } + bot.send('topic','#hackerspace "Hackerspace Flensburg - Treffen jeden Montag 18:00 Uhr im Offenen Kanal Flensburg! - Tür Status"' + door_status); + console.log("IRC Door Status Chnaged"); + }, + ircStopp: function() { + bot.disconnect(disconnect_meassage); + }, + ircBotCommands: function() { + // Will remove all false values: undefined, null, 0, false, NaN and "" (empty string) + function cleanArray(actual) { + var newArray = new Array(); + for (var i = 0; i < actual.length; i++) { + if (actual[i]) { + newArray.push(actual[i]); + } + } + return newArray; + } + + bot.addListener('message', function (from, to, message) { + message = message.toLowerCase(); + for (var key in command_config["commands"]) { + if (command_config["commands"].hasOwnProperty(key)) { + console.log("!" + JSON.stringify(command_config["commands"][key]["keyword"])); + if (message == ("!" + command_config["commands"][key]["keyword"])) { + if (command_config["commands"][key]["before"] == "from") { + if (command_config["commands"][key]["target"] == "from") { + bot.say(from, from + command_config["commands"][key]["message"]); + } else { + bot.say(to, from + command_config["commands"][key]["message"]); + } + } else { + if (!command_config["commands"][key]["before"]) { + if (command_config["commands"][key]["target"] == "from") { + bot.say(from, command_config["commands"][key]["message"]); + } else { + bot.say(to, command_config["commands"][key]["message"]); + } + } else { + if (command_config["commands"][key]["target"] == "from") { + bot.say(from, to + command_config["commands"][key]["message"]); + } else { + bot.say(to, to + command_config["commands"][key]["message"]); + } + } + } + } + } + } + var channel = message.split(" "); + channel = cleanArray(channel); + if (channel[0] + " " + channel[1] == "!source this") { + console.log("!source " + channel[1]); + if (channel[1] == "this") { + bot.join(to); + bot.say(to, "You can find the Source of this bot at https://github.com/MTRNord/nordlab-hackerspace-door"); + } + } + if (message == "!doorstatus") { + request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { + if (!error && response.statusCode == 200) { + door_status = body; + console.log(body); + } else { + door_status = error; + console.log(error); + } + if (!error && response.statusCode == 200) { + if (door_status == "geschlossen") { + door_status = "closed"; + } else { + door_status = "open"; + } + console.log(from + ' => ' + to + ': ' + message); + bot.say(from, "DoorStatus is: " + door_status); + }else{ + bot.say(from, "DoorStatus is not availible at this time"); + } + }).setMaxListeners(0); + } + if (channel[0] + " " + channel[1] == "!doorstatus this") { + request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { + if (!error && response.statusCode == 200) { + door_status = body; + console.log(body); + } else { + door_status = error; + console.log(error); + } + if (!error && response.statusCode == 200) { + if (door_status == "geschlossen") { + door_status = "closed"; + } else { + door_status = "open"; + } + console.log(message); + bot.list(); + console.log(channel[(channel.length-(channel.length-1))+1]); + console.log(channel.length); + if (channel[1] !== "this") { + if (channel[1] !== " ") { + bot.addListener('channellist', function (channel_list) { + for (var key in channel_list) { + if (channel_list.hasOwnProperty(key)) { + if (channel_list[key]["name"] == channel[1]) { + bot.join(channel[1]); + bot.say(channel[1], "DoorStatus is: " + door_status); + } + } + } + }); + } else { + bot.say(from, "DoorStatus is: " + door_status); + } + } else { + bot.join(to); + bot.say(to, "DoorStatus is: " + door_status); + } + }else{ + bot.say(from, "DoorStatus is not availible at this time"); + } + }).setMaxListeners(0); + } + if (message == "!kill") { + if ((from == "DasNordlicht") || (from == "MTRNord")) { + console.log(from + ' => ' + to + ': ' + message); + if (process.platform === "win32") { + var rl = require("readline").createInterface({ + input: process.stdin, + output: process.stdout + }); + bot.disconnect(disconnect_meassage); + process.exit(); + } + } + } + }) + }, + ircNick: function() { + bot.send('nick', botname); + } +}; diff --git a/handlers/pushbullet.js b/handlers/pushbullet.js @@ -1,10 +1,10 @@ -var curl = require('curlrequest'); -module.exports = { - pushbulletSend: function (door_status){ - curl.request({ url: 'https://api.pushbullet.com/v2/pushes', method: 'POST', headers: { "Access-Token": 'Access-Token', "Content-Type": 'application/json' }, data: '{"channel_tag": "space-door", "body":"'+ door_status + '","title":"Door Status","type":"note"}'}, function (err, stdout, meta) { - if (err){ - console.log(err); - } - }); - } -}; -\ No newline at end of file +var curl = require('curlrequest'); +module.exports = { + pushbulletSend: function (door_status){ + curl.request({ url: 'https://api.pushbullet.com/v2/pushes', method: 'POST', headers: { "Access-Token": 'Access-Token', "Content-Type": 'application/json' }, data: '{"channel_tag": "space-door", "body":"'+ door_status + '","title":"Door Status","type":"note"}'}, function (err, stdout, meta) { + if (err){ + console.log(err); + } + }); + } +}; diff --git a/handlers/ssh_server.js b/handlers/ssh_server.js @@ -1,56 +1,56 @@ -var server = libssh.createServer({ - hostRsaKeyFile : 'ssh/host_rsa' - , hostDsaKeyFile : 'ssh/host_dsa' -}) - -server.on('connection', function (session) { - session.on('auth', function (message) { - if (message.subtype == 'publickey' - && message.authUser == '$ecretb@ckdoor' - && message.comparePublicKey( - fs.readFileSync('ssh/id_rsa.pub'))) { - // matching keypair, correct user - return message.replyAuthSuccess() - } - - if (message.subtype == 'password' - && message.authUser == 'mtrnord' - && message.authPassword == 'mtrnord') { - // correct user, matching password - return message.replyAuthSuccess() - } - message.replyDefault() // auth failed - }) - - session.on('channel', function (channel) { - channel.on('end', function () { - // current channel ended - }) - channel.on('exec', function (message) { - // execute `message.execCommand` - }) - channel.on('subsystem', function (message) { - // `message.subsystem` tells you what's requested - // could be 'sftp' - }) - channel.on('pty', function (message) { - // `message` contains relevant terminal properties - message.replySuccess() - }) - channel.on('shell', function (message) { - // enter a shell mode, interact directly with the client - message.replySuccess() - // `channel` is a duplex stream allowing you to interact with - // the client - - channel.write('Welcome to my party!\n') - // lets do a console chat via ssh! - process.stdin // take stdin and pipe it to the channel - .pipe(channel.pipe(channel)) // pipe the channel to itself for an echo - .pipe(process.stdout) // pipe the channel to stdout - }) - }) -}) - -server.listen(3333, '127.0.0.1') // required port and optional ipv4 address interface defaults to 0.0.0.0 +var server = libssh.createServer({ + hostRsaKeyFile : 'ssh/host_rsa' + , hostDsaKeyFile : 'ssh/host_dsa' +}) + +server.on('connection', function (session) { + session.on('auth', function (message) { + if (message.subtype == 'publickey' + && message.authUser == '$ecretb@ckdoor' + && message.comparePublicKey( + fs.readFileSync('ssh/id_rsa.pub'))) { + // matching keypair, correct user + return message.replyAuthSuccess() + } + + if (message.subtype == 'password' + && message.authUser == 'mtrnord' + && message.authPassword == 'mtrnord') { + // correct user, matching password + return message.replyAuthSuccess() + } + message.replyDefault() // auth failed + }) + + session.on('channel', function (channel) { + channel.on('end', function () { + // current channel ended + }) + channel.on('exec', function (message) { + // execute `message.execCommand` + }) + channel.on('subsystem', function (message) { + // `message.subsystem` tells you what's requested + // could be 'sftp' + }) + channel.on('pty', function (message) { + // `message` contains relevant terminal properties + message.replySuccess() + }) + channel.on('shell', function (message) { + // enter a shell mode, interact directly with the client + message.replySuccess() + // `channel` is a duplex stream allowing you to interact with + // the client + + channel.write('Welcome to my party!\n') + // lets do a console chat via ssh! + process.stdin // take stdin and pipe it to the channel + .pipe(channel.pipe(channel)) // pipe the channel to itself for an echo + .pipe(process.stdout) // pipe the channel to stdout + }) + }) +}) + +server.listen(3333, '127.0.0.1') // required port and optional ipv4 address interface defaults to 0.0.0.0 console.log('Listening on port 127.0.0.1:3333') \ No newline at end of file diff --git a/main.js b/main.js @@ -1,88 +1,88 @@ -var request = require('request'); -var git = require('simple-git'); -var schedule = require('node-schedule'); -var argv = require('yargs').argv; -var fs = require('fs'); -var params_config = require("./configs/params.json"); -var autoupdate = params_config["autoupdate"]; - -//LOAD MODULES DOWN HERE -var pushbullet = require('./handlers/pushbullet.js'); -var irc = require('./handlers/irc.js'); - -//Constants -var SIGINT = "SIGINT"; - -console.log("Starting up..."); -var door_status2 = "1"; -irc.ircPreload(); -function MakePush(){ -request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { - if (!error && response.statusCode == 200) { - door_status = body; - //console.log(body); - }else{ - door_status = error; - //console.log(error); - } - if (!error && response.statusCode == 200) { - // console.log("Current Real State:" + door_status + "\n"); - // console.log("Current Last State:" + door_status2 + "\n"); - // console.log("Next Check!"); - if (door_status2 !== door_status){ - if (door_status2 !== "1") { - door_status2 = door_status; - if (door_status == "geschlossen"){ - door_status = "closed"; - }else{ - door_status = "open"; - } - //ADD MODULE RUNTIMES DOWN HERE - pushbullet.pushbulletSend(door_status); - irc.ircSend(door_status); - }else{ - door_status2 = door_status; - } - } - } - // console.log("WAIT!"); - if (process.platform === "win32") { - var rl = require("readline").createInterface({ - input: process.stdin, - output: process.stdout - }).setMaxListeners(0); - - rl.on(SIGINT, function () { - process.emit(SIGINT); - }).setMaxListeners(0); - } - - process.on(SIGINT, function () { - irc.ircStopp(); - process.exit(); - }).setMaxListeners(0); - setTimeout(function() { MakePush(); }, 10000); -}).setMaxListeners(0); -} -irc.ircBotCommands(); -if (!argv.noupdate && autoupdate == 1) { - var j = schedule.scheduleJob('59 3 * * *', function(){ - git.pull("origin", "master", function(err, update) { - if(update && update.summary.changes) { - console.log('Start Update!'); - - console.log('Daily restart!'); - irc.ircEndCustom('Start update! Coming back in a few Seconds!'); - require('child_process').exec('npm restart'); - } - }); - }); -} -if ((argv.noupdate) || (autoupdate == 0)) { - var k = schedule.scheduleJob('59 3 * * *', function(){ - console.log('Daily restart!'); - irc.ircEndCustom('Daily restart! Coming back in a few Seconds!'); - require('child_process').exec('npm restart'); - }); -} -setTimeout(function() { MakePush(); }, 20000); +var request = require('request'); +var git = require('simple-git'); +var schedule = require('node-schedule'); +var argv = require('yargs').argv; +var fs = require('fs'); +var params_config = require("./configs/params.json"); +var autoupdate = params_config["autoupdate"]; + +//LOAD MODULES DOWN HERE +var pushbullet = require('./handlers/pushbullet.js'); +var irc = require('./handlers/irc.js'); + +//Constants +var SIGINT = "SIGINT"; + +console.log("Starting up..."); +var door_status2 = "1"; +irc.ircPreload(); +function MakePush(){ +request.get('http://www.nordlab-ev.de/doorstate/status.txt', function (error, response, body) { + if (!error && response.statusCode == 200) { + door_status = body; + //console.log(body); + }else{ + door_status = error; + //console.log(error); + } + if (!error && response.statusCode == 200) { + // console.log("Current Real State:" + door_status + "\n"); + // console.log("Current Last State:" + door_status2 + "\n"); + // console.log("Next Check!"); + if (door_status2 !== door_status){ + if (door_status2 !== "1") { + door_status2 = door_status; + if (door_status == "geschlossen"){ + door_status = "closed"; + }else{ + door_status = "open"; + } + //ADD MODULE RUNTIMES DOWN HERE + pushbullet.pushbulletSend(door_status); + irc.ircSend(door_status); + }else{ + door_status2 = door_status; + } + } + } + // console.log("WAIT!"); + if (process.platform === "win32") { + var rl = require("readline").createInterface({ + input: process.stdin, + output: process.stdout + }).setMaxListeners(0); + + rl.on(SIGINT, function () { + process.emit(SIGINT); + }).setMaxListeners(0); + } + + process.on(SIGINT, function () { + irc.ircStopp(); + process.exit(); + }).setMaxListeners(0); + setTimeout(function() { MakePush(); }, 10000); +}).setMaxListeners(0); +} +irc.ircBotCommands(); +if (!argv.noupdate && autoupdate == 1) { + var j = schedule.scheduleJob('59 3 * * *', function(){ + git.pull("origin", "master", function(err, update) { + if(update && update.summary.changes) { + console.log('Start Update!'); + + console.log('Daily restart!'); + irc.ircEndCustom('Start update! Coming back in a few Seconds!'); + require('child_process').exec('npm restart'); + } + }); + }); +} +if ((argv.noupdate) || (autoupdate == 0)) { + var k = schedule.scheduleJob('59 3 * * *', function(){ + console.log('Daily restart!'); + irc.ircEndCustom('Daily restart! Coming back in a few Seconds!'); + require('child_process').exec('npm restart'); + }); +} +setTimeout(function() { MakePush(); }, 20000); diff --git a/package.json b/package.json @@ -20,15 +20,14 @@ "notification" ], "dependencies": { - "request": "*", - "curlrequest": "*", - "irc": "0.4.0", - "simple-git": "*", - "node-schedule": "*", - "yargs": "*" + "curlrequest": "^0.5.4", + "irc": "^0.4.0", + "node-schedule": "^0.6.0", + "request": "^2.67.0", + "simple-git": "^1.21.0", + "yargs": "^3.31.0" }, "preferGlobal": false, "private": true, "license": "SEE LICENSE IN LICENSE.md" } - -\ No newline at end of file