From 3e7bb04b4a60201c4b52b30e3e8627ef09116a2b Mon Sep 17 00:00:00 2001 From: Akshay Kashyap Date: Tue, 1 Dec 2015 11:56:02 -0500 Subject: [PATCH 1/5] NodeJS Implementation --- nodejs/fucking_coffee.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 nodejs/fucking_coffee.js diff --git a/nodejs/fucking_coffee.js b/nodejs/fucking_coffee.js new file mode 100644 index 0000000..6e0b00e --- /dev/null +++ b/nodejs/fucking_coffee.js @@ -0,0 +1,40 @@ +/* Before running: + npm install telnet-client +*/ + +var exec = require('child_process').exec; +var telnet = require('telnet-client') + +var me = 'my_username' + +exec("who", function(error, stdout, stderr) { + + // Exit if no sessions with my username are found + if(stdout.indexOf(me) == -1) + process.exit(/*1*/) + + var coffee_machine_ip = '10.10.42.42' + var password = '1234' + var cmd = 'Password: ' + password + var con = new telnet() + + con.on('ready', function(prompt) { + con.exec(cmd, function(error, res) { + + // Brew Coffee! + con.exec('sys brew', function(error, res) { + + // Wait for 24s + setTimeout(function() { + + // Pour Coffee! + con.exec('sys pour', function(error, res) { + con.end() + }) + }, 24000); + }) + }) + }) + + con.connect({host: coffee_machine_ip}) +}); From d992e28f4cb3c0e1f6ac77defb8892640a274f16 Mon Sep 17 00:00:00 2001 From: Akshay Kashyap Date: Tue, 1 Dec 2015 12:24:01 -0500 Subject: [PATCH 2/5] IP and Password change --- nodejs/fucking_coffee.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/nodejs/fucking_coffee.js b/nodejs/fucking_coffee.js index 6e0b00e..c4c92b9 100644 --- a/nodejs/fucking_coffee.js +++ b/nodejs/fucking_coffee.js @@ -1,5 +1,5 @@ /* Before running: - npm install telnet-client +npm install telnet-client */ var exec = require('child_process').exec; @@ -13,13 +13,12 @@ exec("who", function(error, stdout, stderr) { if(stdout.indexOf(me) == -1) process.exit(/*1*/) - var coffee_machine_ip = '10.10.42.42' - var password = '1234' - var cmd = 'Password: ' + password + var coffee_machine_ip = 'xxx.xxx.xxx.xxx' + var password = 'xxxx' var con = new telnet() con.on('ready', function(prompt) { - con.exec(cmd, function(error, res) { + con.exec('Password: ' + password, function(error, res) { // Brew Coffee! con.exec('sys brew', function(error, res) { From c23f8733645bb8c2a7d7a994c85e18279f7eaf91 Mon Sep 17 00:00:00 2001 From: Akshay Kashyap Date: Tue, 1 Dec 2015 12:41:05 -0500 Subject: [PATCH 3/5] Added missing semicolons. --- nodejs/fucking_coffee.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/nodejs/fucking_coffee.js b/nodejs/fucking_coffee.js index c4c92b9..a926dda 100644 --- a/nodejs/fucking_coffee.js +++ b/nodejs/fucking_coffee.js @@ -1,21 +1,21 @@ /* Before running: -npm install telnet-client + npm install telnet-client */ var exec = require('child_process').exec; -var telnet = require('telnet-client') +var telnet = require('telnet-client'); -var me = 'my_username' +var me = 'my_username'; exec("who", function(error, stdout, stderr) { // Exit if no sessions with my username are found if(stdout.indexOf(me) == -1) - process.exit(/*1*/) + process.exit(/*1*/); - var coffee_machine_ip = 'xxx.xxx.xxx.xxx' - var password = 'xxxx' - var con = new telnet() + var coffee_machine_ip = 'xxx.xxx.xxx.xxx'; + var password = 'xxxx'; + var con = new telnet(); con.on('ready', function(prompt) { con.exec('Password: ' + password, function(error, res) { @@ -28,12 +28,12 @@ exec("who", function(error, stdout, stderr) { // Pour Coffee! con.exec('sys pour', function(error, res) { - con.end() - }) + con.end(); + }); }, 24000); - }) - }) - }) + }); + }); + }); - con.connect({host: coffee_machine_ip}) + con.connect({host: coffee_machine_ip}); }); From 90c2bfc7d86213a92c89d11c72a0c83e10393655 Mon Sep 17 00:00:00 2001 From: Akshay Kashyap Date: Tue, 1 Dec 2015 16:39:19 -0500 Subject: [PATCH 4/5] Added shebang --- nodejs/fucking_coffee.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nodejs/fucking_coffee.js b/nodejs/fucking_coffee.js index a926dda..badab95 100644 --- a/nodejs/fucking_coffee.js +++ b/nodejs/fucking_coffee.js @@ -2,6 +2,8 @@ npm install telnet-client */ +#!/usr/bin/env node + var exec = require('child_process').exec; var telnet = require('telnet-client'); From 486b340e6cf8fa3edee7f7085c32435488f1c2d3 Mon Sep 17 00:00:00 2001 From: Akshay Kashyap Date: Tue, 1 Dec 2015 16:44:10 -0500 Subject: [PATCH 5/5] NodeJS Implementation --- nodejs/fucking_coffee.js | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 nodejs/fucking_coffee.js diff --git a/nodejs/fucking_coffee.js b/nodejs/fucking_coffee.js new file mode 100644 index 0000000..badab95 --- /dev/null +++ b/nodejs/fucking_coffee.js @@ -0,0 +1,41 @@ +/* Before running: + npm install telnet-client +*/ + +#!/usr/bin/env node + +var exec = require('child_process').exec; +var telnet = require('telnet-client'); + +var me = 'my_username'; + +exec("who", function(error, stdout, stderr) { + + // Exit if no sessions with my username are found + if(stdout.indexOf(me) == -1) + process.exit(/*1*/); + + var coffee_machine_ip = 'xxx.xxx.xxx.xxx'; + var password = 'xxxx'; + var con = new telnet(); + + con.on('ready', function(prompt) { + con.exec('Password: ' + password, function(error, res) { + + // Brew Coffee! + con.exec('sys brew', function(error, res) { + + // Wait for 24s + setTimeout(function() { + + // Pour Coffee! + con.exec('sys pour', function(error, res) { + con.end(); + }); + }, 24000); + }); + }); + }); + + con.connect({host: coffee_machine_ip}); +});