diff --git a/R/smack_my_bitch_up.R b/R/smack_my_bitch_up.R new file mode 100644 index 0000000..7257f88 --- /dev/null +++ b/R/smack_my_bitch_up.R @@ -0,0 +1,34 @@ +library(httr) + +today = Sys.Date() + +# skip weekends +if( weekdays(today) %in% c('Saturday','Sunday') ){ + quit() + } + +# exit if no sessions with my username are found +output = system("who", intern = TRUE) +if( !( grep('^my_user_name', output) ) ){ + quit() + } + +# returns 'None' if the key doesn't exist +TWILIO_ACCOUNT_SID = Sys.getenv('TWILIO_ACCOUNT_SID') +TWILIO_AUTH_TOKEN = Sys.getenv('TWILIO_AUTH_TOKEN') + +# Phone numbers +my_number = '+xxx' +her_number = '+xxx' + +reasons = c( + 'Working hard', + 'Gotta ship this feature', + 'Someone fucked the system again' + ) + +POST(paste("https://api.twilio.com/2010-04-01/Accounts/",TWILIO_ACCOUNT_SID,"/Messages.json",sep=""), + body = list(From=my_number,To=her_number,Body=sample(reasons,1) ), + authenticate(TWILIO_ACCOUNT_SID,TWILIO_AUTH_TOKEN) ) + +print( paste("Message sent at",Sys.time()) ) diff --git a/coffee/fucking.coffee b/coffee/fucking.coffee index d0f26bc..8df9dbe 100755 --- a/coffee/fucking.coffee +++ b/coffee/fucking.coffee @@ -14,15 +14,15 @@ process.exit 0 if new Date().getDay() in [6, 0] # no sessions process.exit 0 unless new RegExp(username).test sh('who -q').toString() -conn = require('net').createConnection(port, host) +conn = require('net').createConnection port, host setTimeout -> conn.write "#{pass}\nsys brew\n" setTimeout -> conn.end 'sys pour' - process.exit(0) + process.exit 0 , 2 * 1000 , 1 * 1000 # alert -sh('say come here and take your fucking coffee') +sh 'say come here and take your fucking coffee' diff --git a/go/hangover.go b/go/hangover.go new file mode 100644 index 0000000..12d5d3e --- /dev/null +++ b/go/hangover.go @@ -0,0 +1,47 @@ +package main + +import ( + "fmt" + "log" + "math/rand" + "os" + + "github.com/codeskyblue/go-sh" + "github.com/subosito/twilio" +) + +const my_number string = "+xxxxx" +const boss_number string = "+yyyyy" + +func main() { + //exit if sessions with my username are found + _, err := sh.Command("who").Command("grep", "my_username").Output() + if err != nil { + os.Exit(1) + } + + //Grab Twilio ID and token from environment variables + Account_Sid := os.Getenv("TWILIO_ACCOUNT_SID") + Auth_Token := os.Getenv("TWILIO_AUTH_TOKEN") + + //create the reasons slice and append reasons to it + reasons := make([]string, 0) + reasons = append(reasons, + "Locked out", + "Pipes broke", + "Food poisoning", + "Not feeling well") + + // Initialize Twilio client and send message + client := twilio.NewClient(Account_Sid, Auth_Token, nil) + message := fmt.Sprint("Gonna work from home...", reasons[rand.Intn(len(reasons))]) + + params := twilio.MessageParams{ + Body: message, + } + s, resp, err := client.Messages.Send(my_number, boss_number, params) + + if err == nil { + log.Fatal(s, resp, err) + } +} diff --git a/go/smack_my_bitch_up.go b/go/smack_my_bitch_up.go new file mode 100755 index 0000000..66f7311 --- /dev/null +++ b/go/smack_my_bitch_up.go @@ -0,0 +1,39 @@ +package main + +import( + "os/exec" + "fmt" + "strings" + "os" + "math/rand" + "time" + ) + +func main(){ + output1,err := exec.Command("who").Output() + output2 := os.Getenv("USER") + users := string(output1[:]) + current_user := string(output2[:]) + if(!strings.Contains(users,current_user)){ + return + } + + + reasons := []string {"Working hard","Gotta ship this feature","Someone fucked the system again"} + + rand.Seed(time.Now().UTC().UnixNano()) + message := "Late at work. " + reasons[rand.Intn(len(reasons))] + + TWILIO_ACCOUNT_SID := string(os.Getenv("TWILIO_ACCOUNT_SID")) + TWILIO_AUTH_TOKEN := string(os.Getenv("TWILIO_AUTH_TOKEN")) + MY_NUMBER := string(os.Getenv("MY_NUMBER")) + HER_NUMBER := string(os.Getenv("HER_NUMBER")) + + response,err := exec.Command("curl","-fSs","-u",TWILIO_ACCOUNT_SID + ":" + TWILIO_AUTH_TOKEN, "-d", "From=" + MY_NUMBER, "-d", "To=" + HER_NUMBER, "-d" , "Body=" + message, "https://api.twilio.com/2010-04-01/Accounts/" + TWILIO_ACCOUNT_SID + "/Messages").Output() + if(err != nil){ + fmt.Printf("Failed to send SMS: ",err) + return + } + + fmt.Printf("Message Sent Successfully with response: %s ",response) +} diff --git a/java/fucking_coffee.java b/java/fucking_coffee.java new file mode 100644 index 0000000..569314a --- /dev/null +++ b/java/fucking_coffee.java @@ -0,0 +1,34 @@ +import java.net.*; +import java.io.*; + +public class fucking_coffee{ + + private static final String MY_USERNAME = "my_username"; + private static final String PASSWORD_PROMPT = "Password: "; + private static final String PASSWORD = "1234"; + private static final String COFFEE_MACHINE_IP = "10.10.42.42"; + private static int DELAY_BEFORE_BREW = 17; + private static int DELAY = 24; + + public static void main(String[] args)throws Exception{ + for(int i = 1; i< args.length ; i++){ + if(!args[i].contains(MY_USERNAME)){ + return; + } + } + Socket telnet = new Socket(COFFEE_MACHINE_IP, 23); + PrintWriter out = new PrintWriter(telnet.getOutputStream(), true); + BufferedReader in = new BufferedReader(new InputStreamReader(telnet.getInputStream())); + Thread.sleep(DELAY_BEFORE_BREW*1000); + if(in.readLine() != PASSWORD_PROMPT){ + return ; + } + out.println(PASSWORD); + out.println("sys brew"); + Thread.sleep(DELAY*1000); + out.println("sys pour"); + out.close(); + in.close(); + telnet.close(); + } +} diff --git a/kumar_asshole.rb b/kumar_asshole.rb index fc6a2f0..0dc5cb7 100755 --- a/kumar_asshole.rb +++ b/kumar_asshole.rb @@ -8,21 +8,21 @@ Dotenv.load GMAIL_USERNAME = ENV['GMAIL_USERNAME'] GMAIL_PASSWORD = ENV['GMAIL_PASSWORD'] -gmail = Gmail.connect(GMAIL_USERNAME, GMAIL_PASSWORD) -kumars_email = 'kumar.a@example.com' +GMAIL = Gmail.connect(GMAIL_USERNAME, GMAIL_PASSWORD) +KUMARS_EMAIL = 'kumar.a@example.com' DB_NAME_REGEX = /\S+_staging/ KEYWORDS_REGEX = /sorry|help|wrong/i def create_reply(subject) - gmail.compose do - to kumars_email + GMAIL.compose do + to KUMARS_EMAIL subject "RE: #{subject}" body "No problem. I've fixed it. \n\n Please be careful next time." end end -gmail.inbox.find(:unread, from: kumars_email).each do |email| +GMAIL.inbox.find(:unread, from: KUMARS_EMAIL).each do |email| if email.body.raw_source[KEYWORDS_REGEX] && (db_name = email.body.raw_source[DB_NAME_REGEX]) backup_file = "/home/backups/databases/#{db_name}-" + (Date.today - 1).strftime('%Y%m%d') + '.gz' abort 'ERROR: Backup file not found' unless File.exist?(backup_file) @@ -34,6 +34,6 @@ gmail.inbox.find(:unread, from: kumars_email).each do |email| email.read! email.label('Database fixes') reply = create_reply(email.subject) - gmail.deliver(reply) + GMAIL.deliver(reply) end end diff --git a/nodejs/fucking_coffee.js b/nodejs/fucking_coffee.js new file mode 100644 index 0000000..b30a6b4 --- /dev/null +++ b/nodejs/fucking_coffee.js @@ -0,0 +1,41 @@ +#!/usr/bin/env node + +/* 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 = '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}); +}); diff --git a/nodejs/fucking_coffee_yo_server.js b/nodejs/fucking_coffee_yo_server.js new file mode 100755 index 0000000..28637c2 --- /dev/null +++ b/nodejs/fucking_coffee_yo_server.js @@ -0,0 +1,83 @@ +#!/usr/bin/env node + +/* Before running: + Setup Yo Callback URL and Yo username for coffee machine: + http://docs.justyo.co/docs/receiving-a-yo-with-the-api +*/ + +var exec = require('child_process').exec; +var telnet = require('telnet-client'); + +var ME = 'my_username'; +var AUTHORIZED_YO_NAMES = [ME]; +var COFFEE_MACHINE_YO_NAME = 'coffeemachine'; + +// These should be same as what you set up in the Yo API +var CALLBACK_URL = 'http://xxx.com'; +var CALLBACK_ENDPOINT = '/coffeemachine'; + +var PORT = '3000'; + +exec("who -q", function(error, stdout, stderr) { + + var express = require('express'); + var coffeeApp = express(); + + // Exit if no sessions with my username are found + if(stdout.indexOf(ME) == -1) + process.exit(1); + + // Got a Yo! + coffeeApp.get(CALLBACK_ENDPOINT, function (req, res) { + + if(req.query.username === undefined) { + // Not a Yo, don't make coffee. + res.sendStatus(401); + } + else if(AUTHORIZED_YO_NAMES.indexOf(req.query.username) == -1) { + // If authorized users didn't Yo, don't make coffee. + res.sendStatus(401); + + console.log(req.query.username + ' YO\'d.') + } + else { + res.sendStatus(200); + + 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}); + } + }); + + // Not Callback endpoint + coffeeApp.get('/*', function (req, res) { + res.sendStatus(404); + }); + + var coffeeServer = coffeeApp.listen(PORT, CALLBACK_URL, function() { + console.log('Coffee Server listening at %s:%s', + CALLBACK_URL, PORT); + console.log('\nYo Callback URL: %s:%s/%s', + CALLBACK_URL, PORT, CALLBACK_ENDPOINT); + }); +}); diff --git a/nodejs/hangover.js b/nodejs/hangover.js new file mode 100755 index 0000000..2088af3 --- /dev/null +++ b/nodejs/hangover.js @@ -0,0 +1,57 @@ +#!/usr/bin/env node + +/* Before running: + npm install twilio +*/ + +var exec = require('child_process').exec; + +var me = 'my_username'; + +exec("who -q", function(error, stdout, stderr) { + + // Exit if sessions with my username are found + if(stdout.indexOf(me) > -1) + process.exit(1); + + var TWILIO_ACCOUNT_SID = process.env['TWILIO_ACCOUNT_SID']; + var TWILIO_AUTH_TOKEN = process.env['TWILIO_AUTH_TOKEN']; + + // Phone numbers + var MY_NUMBER = '+xxx'; + var BOSS_NUMBER = '+xxx'; + + // Excuses + var excuses = [ + 'Locked out', + 'Pipes broke', + 'Food poisoning', + 'Not feeling well' + ]; + + // Generate BS message + var excuse = excuses[Math.floor(Math.random() * excuses.length)]; + var textMessage = 'Gonna work from home. ' + excuse; + + var client = require('twilio')(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN); + + // Shoot text + client.messages.create({ + body: textMessage, + to: BOSS_NUMBER, + from: MY_NUMBER + }, function(error, message) { + if(error) + console.log('Failed to send SMS: ' + error.message); + else { + var currentdate = new Date(); + + console.log('Message sent at: '+ (currentdate.getMonth() + 1) + '/' + + currentdate.getDate() + '/' + + currentdate.getFullYear() + ' ' + + currentdate.getHours() + ':' + + currentdate.getMinutes() + ':' + + currentdate.getSeconds() + '| Excuse: ' + excuse); + } + }); +}); diff --git a/nodejs/kumar_asshole.js b/nodejs/kumar_asshole.js new file mode 100755 index 0000000..0276f29 --- /dev/null +++ b/nodejs/kumar_asshole.js @@ -0,0 +1,113 @@ +#!/usr/bin/env node + +/* Before running: + npm install nodemailer + npm install imap + +I realize this is long. IMAP can only fetch emails and nodemailer can only +send. Could try implementing with Gmail Node API later. +*/ + +var GMAIL_USERNAME = process.env['GMAIL_USERNAME']; +var GMAIL_PASSWORD = process.env['GMAIL_PASSWORD']; + +var KUMAR_EMAIL = 'kumar.asshole@example.com'; +var EMAIL = 'No worries mate, be careful next time'; + +// Scan for unread email from Kumar +var Imap = require('imap'); +var imap = new Imap({ + user: GMAIL_USERNAME, + password: GMAIL_PASSWORD, + host: 'imap.gmail.com', + port: 993, + tls: true, + tlsOptions: { rejectUnauthorized: false } +}); + +function openInbox(cb) { + imap.openBox('INBOX', false, cb); +} + +imap.once('ready', function() { + openInbox(function(err, box) { + if (err) + process.exit(1); + + imap.search(['UNSEEN', ['FROM', KUMAR_EMAIL]], + function(err, results) { + + if (err) + process.exit(1); + + // RegEx search for keywords; ignore case + var kumarPattern = new RegExp(/sorry|help|wrong/i); + + // IMAP dumps all headers, so need to parse and get email body + var MailParser = require("mailparser").MailParser; + + var f = imap.fetch(results, {bodies: ''}); + f.on('message', function(msg, seqno) { + msg.on('body', function(stream, info) { + var kumarEmail = ""; + + stream.on('data', function(chunk) { + kumarEmail += chunk.toString('utf8'); + }); + + stream.once('end', function() { + var mailparser = new MailParser(); + mailparser.on("end", function(mail_object){ + + // If the RegEx matches + if(mail_object.text.match(kumarPattern)) { + // Shoot email to Kumar! + var nodemailer = require('nodemailer'); + + // create reusable transporter object using SMTP transport + var transporter = nodemailer.createTransport({ + service: 'Gmail', + auth: { + user: GMAIL_USERNAME, + pass: GMAIL_PASSWORD + } + }); + + // setup e-mail data + var mailOptions = { + from: GMAIL_USERNAME, + to: KUMAR_EMAIL, + subject: 'Database Fixes', + text: EMAIL + }; + + // send mail with defined transport object + transporter.sendMail(mailOptions, function(error, info) { + if(error) + process.exit(1) + }); + } + }); + + mailparser.write(kumarEmail); + mailparser.end(); + }); + }); + + msg.once('end', function() { + // Fetched all unread from kumar + }); + }); + + f.once('error', function(err) { + process.exit(1); + }); + + f.once('end', function() { + imap.end(); + }); + }); + }); +}); + +imap.connect(); diff --git a/nodejs/smack_my_bitch_up.js b/nodejs/smack_my_bitch_up.js new file mode 100755 index 0000000..ebc47ea --- /dev/null +++ b/nodejs/smack_my_bitch_up.js @@ -0,0 +1,56 @@ +#!/usr/bin/env node + +/* Before running: + npm install twilio +*/ + +var exec = require('child_process').exec; + +var me = 'my_username'; + +exec("who -q", function(error, stdout, stderr) { + + // Exit if no sessions with my username are found + if(stdout.indexOf(me) == -1) + process.exit(1); + + var TWILIO_ACCOUNT_SID = process.env['TWILIO_ACCOUNT_SID']; + var TWILIO_AUTH_TOKEN = process.env['TWILIO_AUTH_TOKEN']; + + // Phone numbers + var MY_NUMBER = '+xxx'; + var HER_NUMBER = '+xxx'; + + // Reasons + var reasons = [ + 'Working hard', + 'Gotta ship this feature', + 'Someone fucked the system again' + ]; + + // Generate BS message + var reason = reasons[Math.floor(Math.random() * reasons.length)]; + var textMessage = 'Late at work. ' + reason; + + var client = require('twilio')(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN); + + // Shoot text + client.messages.create({ + body: textMessage, + to: HER_NUMBER, + from: MY_NUMBER + }, function(error, message) { + if(error) + console.log('Failed to send SMS: ' + error.message); + else { + var currentdate = new Date(); + + console.log('Message sent at: '+ (currentdate.getMonth() + 1) + '/' + + currentdate.getDate() + '/' + + currentdate.getFullYear() + ' ' + + currentdate.getHours() + ':' + + currentdate.getMinutes() + ':' + + currentdate.getSeconds() + '| Excuse: ' + reason); + } + }); +}); diff --git a/perl/kumar-asshole.pl b/perl/kumar-asshole.pl index 06db753..af7a4d8 100755 --- a/perl/kumar-asshole.pl +++ b/perl/kumar-asshole.pl @@ -10,7 +10,7 @@ use Mail::Webmail::Gmail; # Config my $conf = Load( <<'...' ); --- -kumar_mail: kumar.a@examle.com +kumar_mail: kumar.a@example.com database_regex: \S+_staging keywords_regex: sorry|help|wrong backup_path: /home/backups/databases/ diff --git a/php/Lib/Telnet.php b/php/Lib/Telnet.php deleted file mode 100644 index 3409dc3..0000000 --- a/php/Lib/Telnet.php +++ /dev/null @@ -1,264 +0,0 @@ - - * Based on the code originally written by Marc Ennaji and extended by - * Matthias Blaser - * - * Extended by Christian Hammers - * Modified by Frederik Sauer - * - */ - -class Telnet { - - private $host; - private $port; - private $timeout; - private $stream_timeout_sec; - private $stream_timeout_usec; - - private $socket = NULL; - private $buffer = NULL; - private $prompt; - private $errno; - private $errstr; - private $strip_prompt = TRUE; - - private $NULL; - private $DC1; - private $WILL; - private $WONT; - private $DO; - private $DONT; - private $IAC; - - private $global_buffer = ''; - - const TELNET_ERROR = FALSE; - const TELNET_OK = TRUE; - - public function __construct($host = '127.0.0.1', $port = '23', $timeout = 10, $prompt = '$', $stream_timeout = 1) { - $this->host = $host; - $this->port = $port; - $this->timeout = $timeout; - $this->setPrompt($prompt); - $this->setStreamTimeout($stream_timeout); - - // set some telnet special characters - $this->NULL = chr(0); - $this->DC1 = chr(17); - $this->WILL = chr(251); - $this->WONT = chr(252); - $this->DO = chr(253); - $this->DONT = chr(254); - $this->IAC = chr(255); - - $this->connect(); - } - - public function __destruct() { - // clean up resources - $this->disconnect(); - $this->buffer = NULL; - $this->global_buffer = NULL; - } - - public function connect() { - // check if we need to convert host to IP - if (!preg_match('/([0-9]{1,3}\\.){3,3}[0-9]{1,3}/', $this->host)) { - $ip = gethostbyname($this->host); - - if ($this->host == $ip) { - throw new Exception("Cannot resolve $this->host"); - } else { - $this->host = $ip; - } - } - - // attempt connection - suppress warnings - $this->socket = @fsockopen($this->host, $this->port, $this->errno, $this->errstr, $this->timeout); - - if (!$this->socket) { - throw new Exception("Cannot connect to $this->host on port $this->port"); - } - - if (!empty($this->prompt)) { - $this->waitPrompt(); - } - - return self::TELNET_OK; - } - - public function disconnect() { - if ($this->socket) { - if (! fclose($this->socket)) { - throw new Exception("Error while closing telnet socket"); - } - $this->socket = NULL; - } - return self::TELNET_OK; - } - - public function exec($command, $add_newline = TRUE) { - $this->write($command, $add_newline); - $this->waitPrompt(); - return $this->getBuffer(); - } - - public function login($username, $password) { - try { - $this->setPrompt('login:'); - $this->waitPrompt(); - $this->write($username); - $this->setPrompt('Password:'); - $this->waitPrompt(); - $this->write($password); - $this->setPrompt(); - $this->waitPrompt(); - } catch (Exception $e) { - throw new Exception("Login failed."); - } - - return self::TELNET_OK; - } - - public function setPrompt($str = '$') { - return $this->setRegexPrompt(preg_quote($str, '/')); - } - - public function setRegexPrompt($str = '\$') { - $this->prompt = $str; - return self::TELNET_OK; - } - - public function setStreamTimeout($timeout) { - $this->stream_timeout_usec = (int)(fmod($timeout, 1) * 1000000); - $this->stream_timeout_sec = (int)$timeout; - } - - public function stripPromptFromBuffer($strip) { - $this->strip_prompt = $strip; - } // function stripPromptFromBuffer - - protected function getc() { - stream_set_timeout($this->socket, $this->stream_timeout_sec, $this->stream_timeout_usec); - $c = fgetc($this->socket); - $this->global_buffer .= $c; - return $c; - } - - public function clearBuffer() { - $this->buffer = ''; - } - - public function readTo($prompt) { - if (!$this->socket) { - throw new Exception("Telnet connection closed"); - } - - // clear the buffer - $this->clearBuffer(); - - $until_t = time() + $this->timeout; - do { - // time's up (loop can be exited at end or through continue!) - if (time() > $until_t) { - throw new Exception("Couldn't find the requested : '$prompt' within {$this->timeout} seconds"); - } - - $c = $this->getc(); - - if ($c === FALSE) { - if (empty($prompt)) { - return self::TELNET_OK; - } - throw new Exception("Couldn't find the requested : '" . $prompt . "', it was not in the data returned from server: " . $this->buffer); - } - - // Interpreted As Command - if ($c == $this->IAC) { - if ($this->negotiateTelnetOptions()) { - continue; - } - } - - // append current char to global buffer - $this->buffer .= $c; - - // we've encountered the prompt. Break out of the loop - if (!empty($prompt) && preg_match("/{$prompt}$/", $this->buffer)) { - return self::TELNET_OK; - } - - } while ($c != $this->NULL || $c != $this->DC1); - } - - public function write($buffer, $add_newline = TRUE) { - if (!$this->socket) { - throw new Exception("Telnet connection closed"); - } - - // clear buffer from last command - $this->clearBuffer(); - - if ($add_newline == TRUE) { - $buffer .= "\n"; - } - - $this->global_buffer .= $buffer; - if (!fwrite($this->socket, $buffer) < 0) { - throw new Exception("Error writing to socket"); - } - - return self::TELNET_OK; - } - - protected function getBuffer() { - // Remove all carriage returns from line breaks - $buf = preg_replace('/\r\n|\r/', "\n", $this->buffer); - // Cut last line from buffer (almost always prompt) - if ($this->strip_prompt) { - $buf = explode("\n", $buf); - unset($buf[count($buf) - 1]); - $buf = implode("\n", $buf); - } - return trim($buf); - } - - public function getGlobalBuffer() { - return $this->global_buffer; - } - - protected function negotiateTelnetOptions() { - $c = $this->getc(); - - if ($c != $this->IAC) { - if (($c == $this->DO) || ($c == $this->DONT)) { - $opt = $this->getc(); - fwrite($this->socket, $this->IAC . $this->WONT . $opt); - } else if (($c == $this->WILL) || ($c == $this->WONT)) { - $opt = $this->getc(); - fwrite($this->socket, $this->IAC . $this->DONT . $opt); - } else { - throw new Exception('Error: unknown control character ' . ord($c)); - } - } else { - throw new Exception('Error: Something Wicked Happened'); - } - - return self::TELNET_OK; - } - - protected function waitPrompt() { - return $this->readTo($this->prompt); - } -} \ No newline at end of file diff --git a/php/composer.json b/php/composer.json index 1d302d6..6cb990f 100644 --- a/php/composer.json +++ b/php/composer.json @@ -1,5 +1,10 @@ { "require": { +<<<<<<< HEAD +======= + "bestnetwork/telnet": "^1.0", + "vlucas/phpdotenv": "^2.0", +>>>>>>> NARKOZ/master "twilio/sdk": "^4.6" } } diff --git a/php/composer.lock b/php/composer.lock new file mode 100644 index 0000000..4ca6e33 --- /dev/null +++ b/php/composer.lock @@ -0,0 +1,69 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "ba2345d9958ec92d274d423597284494", + "content-hash": "448be28be374d66028c6713b61c15543", + "packages": [ + { + "name": "twilio/sdk", + "version": "4.6.1", + "source": { + "type": "git", + "url": "https://github.com/twilio/twilio-php.git", + "reference": "f83a9f8db1cc29f42edb77c7c77382bf9769953a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twilio/twilio-php/zipball/f83a9f8db1cc29f42edb77c7c77382bf9769953a", + "reference": "f83a9f8db1cc29f42edb77c7c77382bf9769953a", + "shasum": "" + }, + "require": { + "php": ">=5.2.1" + }, + "require-dev": { + "mockery/mockery": ">=0.7.2", + "phpunit/phpunit": "4.5.*" + }, + "type": "library", + "autoload": { + "files": [ + "Services/Twilio.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kevin Burke", + "email": "kevin@twilio.com" + }, + { + "name": "Kyle Conroy", + "email": "kyle+pear@twilio.com" + } + ], + "description": "A PHP wrapper for Twilio's API", + "homepage": "http://github.com/twilio/twilio-php", + "keywords": [ + "api", + "sms", + "twilio" + ], + "time": "2015-11-10 00:40:41" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/php/fucking_coffee.php b/php/fucking_coffee.php index 5ab70c7..074e22f 100644 --- a/php/fucking_coffee.php +++ b/php/fucking_coffee.php @@ -1,170 +1,14 @@ +#!/usr/bin/env php IsWeekend( date('m.d.y') ) == false ) - { - - return false; - } - - /** - * Create a new telnet class - */ - - $this->telnet = new Telnet( $this->host, $this->port ); - - /** - * Once we have completed this, we can brew our coffee! - */ - - $this->BrewCoffee( function(){ - - /** - * Echo out a message - */ - - echo "coffee has been poured"; - - /** - * Unset - */ - - unset( $this->telnet ); - }); - - /** - * Return tue - */ - - return true; - } - - /** - * Brews our coffee - * - * @param $callback - */ - - public function BrewCoffee( $callback ) - { - - if( $this->telnet != null ) - { - - /** - * Execute and enter the password - */ - - $this->telnet->exec('Password: ' . $this->password); - - /** - * Brew the coffee - */ - - $this->telnet->exec('sys brew'); - - /** - * Wait - */ - - sleep( $this->delay ); - - /** - * Pour the coffee - */ - - $this->telnet->exec('sys pour'); - - /** - * Execute our callback - */ - - call_user_func( $callback ); - } - } - - /** - * Is this currently the weekend? - * - * @param $date - * - * @return bool - */ - - public function IsWeekend( $date ) - { - - if( date('N', strtotime( $date ) ) >= 6 ) - { - - return true; - } - - return false; - } - -} \ No newline at end of file +(strpos(exec('who'), getenv('USER')) !== false) or exit('no session'); +sleep(17); +$con = new TelnetClient('10.10.42.42'); +$con->execute('1234', 'Password: '); +$con->execute('sys brew'); +sleep(24); +$con->execute('sys pour'); diff --git a/php/hangover.php b/php/hangover.php index e9456a7..2b930db 100644 --- a/php/hangover.php +++ b/php/hangover.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD load(); +(strpos(exec('who'), getenv('USER')) === false) or exit('session found'); + +$my_number = '+xxx'; +$number_of_boss = '+xxx'; +$excuse = ['Locked out', 'Pipes broke', 'Food poisoning', 'Not feeling well']; +$excuse = $excuse[array_rand($excuse)]; + +$twilio = new Services_Twilio(getenv('TWILIO_ACCOUNT_SID'), getenv('TWILIO_AUTH_TOKEN')); +$twilio->account->messages->sendMessage( + $my_number, + $number_of_boss, + "Gonna work from home. {$excuse}" +); + +echo "Message sent at: #".date('Y-m-d')." | Excuse: {$excuse}"; +>>>>>>> NARKOZ/master diff --git a/php/test.php b/php/test.php new file mode 100644 index 0000000..9407557 --- /dev/null +++ b/php/test.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/powershell/fucking_coffee.psm1 b/powershell/fucking_coffee.psm1 new file mode 100644 index 0000000..55b1289 --- /dev/null +++ b/powershell/fucking_coffee.psm1 @@ -0,0 +1,62 @@ +<# +.SYNOPSIS + Simple script to connect to a coffee part using TelNet then issue specific commands that + brew and pourt a cup of coffee for the user. +.DESCRIPTION + This script was converted using the ruby version of the fucking_coffee script. In this script, + I left the use of environment variables since its only use was to determine if the user was + still logged in to the system. Per issue #42 (https://github.com/NARKOZ/hacker-scripts/issues/42) + I left the password string hard coded until a decision is made by NARKOZ, the project owner, as + to how the information should be stored. +.OUTPUT + None +.NOTES + Author: Tyler Hughes + Twitter: @thughesIT + Blog: http://tylerhughes.info/ + + Changelog: + 1.0 Initial Release +#> + +Function Fucking-Coffee +{ + # Exit early if no sessions with my username are found + if ($env:Username.Count > 0) { + return + } + + $coffee_machine_ip = '10.10.42.42' + $password = '1234' + + Start-Sleep -s 17 + + $socket = New-Object System.Net.Sockets.TcpClient($coffee_machine_ip) + if ($socket) { + $stream = $connection.GetStream() + $Writer = New-Object System.IO.StreamWriter($Stream) + $Buffer = New-Object System.Byte[] 1024 + $Encoding = New-Object System.Text.AsciiEncoding + + # Start issuing the commands + Send-TelNetCommands($Writer, $password, 1) + Send-TelNetCommands($Writer, "sys brew", 24) + Send-TelNetCommands($Writer, "sys pour", 4) + + $socket.Close() + } +} + +Function Send-TelNetCommands +{ + Param ( + [Parameter(ValueFromPipeline=$false)] + [System.IO.StreamWriter]$writer, + [String]$command, + [int]$WaitTime + ) + + $writer.WriteLine($command) + $writer.Flush() + Start-Sleep -Milliseconds $WaitTime +} \ No newline at end of file diff --git a/powershell/hangover.psm1 b/powershell/hangover.psm1 new file mode 100644 index 0000000..fabb13f --- /dev/null +++ b/powershell/hangover.psm1 @@ -0,0 +1,64 @@ +<# +.SYNOPSIS + Simple script to SMS a supervisor informing them you will be working from home + on the day this script is used. +.DESCRIPTION + This script was converted using the ruby version of the hangover script. However, the ruby + version used environment variables to hold the user's account information. Due to issue #42 + (https://github.com/NARKOZ/hacker-scripts/issues/42) I opted to hard code the strings at + this time until a decision is made by NARKOZ, the project owner, as the how the information + should be stored. + + This script also uses Twilio to send the SMS messages. The from number MUST be a valid Twilio + phone number. The to number can be any outgoing number. +.OUTPUT + This script will output an error message to the PowerShell window if it fails + to send the message. +.NOTES + Author: Tyler Hughes + Twitter: @thughesIT + Blog: http://tylerhughes.info/ + + Changelog: + 1.0 Initial Release +#> +Function Hangover +{ + # Phone numbers (Must include country code and area code) + $from = '+XXXXXXXXXXX' + $to = '+XXXXXXXXXXX' + + # Twilio API Information + $twilio_base_url = 'https://api.twilio.com/2010-04-01' + $twilio_account_sid = 'XXXXXXXXXXXXXXXXXXX' + $twilio_auth_token = 'XXXXXXXXXXXXXXXXXX' + + $password = ConvertTo-SecureString -AsPlainText $twilio_auth_token -Force + $credentials = New-Object System.Management.Automation.PSCredential($twilio_account_sid, $password) + + # Get the message to send + $excuses = + 'Locked out', + 'Pipes broke', + 'Food poisoning', + 'Not feeling well' + + $excuse = $excuses | Get-Random + $message = "$excuse. Going to work from home today." + $body = @{ + From = $from; + To = $to; + Body = $message; + } + + # Send the message and log any errors + $uri = "$twilio_base_url/Accounts/" + $credentials.UserName + "/SMS/Messages" + + try { + $response = Invoke-RestMethod -Method Post -Uri $uri -Body $body -Credential $credentials + } + catch { + $time = Get-Date -format u + Write-Host $time " - Failed to send message: " $message + } +} \ No newline at end of file diff --git a/powershell/smack_my_bitch_up.ps1 b/powershell/smack_my_bitch_up.ps1 index 46c3d8f..903bd5c 100644 --- a/powershell/smack_my_bitch_up.ps1 +++ b/powershell/smack_my_bitch_up.ps1 @@ -6,7 +6,7 @@ if ($DAYOFWEEK -eq 6 -or $DAYOFWEEK -eq 7) { } # Exit early if no sessions with my username are found -if ((QWINSTA $env:USERNAME | measure).Count -gt 0){ +if (-not (QWINSTA | FINDSTR $env:USERNAME)) { return } @@ -14,26 +14,25 @@ if ((QWINSTA $env:USERNAME | measure).Count -gt 0){ $MY_NUMBER='+xxx' $HER_NUMBER='+xxx' -$TWILIO_ACCOUNT_SID = 'xxx' -$TWILIO_AUTH_TOKEN = 'xxx' - -$REASONS= +$REASONS = 'Working hard', 'Gotta ship this feature', 'Someone fucked the system again' +$reason = $REASONS | Get-Random +$message = "Late at work. $reason." -$RAND = Get-Random -Maximum $REASONS.Count +$API_URL = "https://api.twilio.com/2010-04-01/Accounts/$env:TWILIO_ACCOUNT_SID/Messages" +$BASE64AUTHINFO = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $env:TWILIO_ACCOUNT_SID,$env:TWILIO_AUTH_TOKEN))) +$body = @{ + From = $MY_NUMBER; + To = $HER_NUMBER; + Body = $message; +} -$MSG="Late at work. $REASONS[$RAND]" - - -$BASE64AUTHINFO = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $TWILIO_ACCOUNT_SID,$TWILIO_AUTH_TOKEN))) - -#Send a text messag and Log errors +#Send a text message and Log errors try{ - Invoke-RestMethod -Method Post -Headers @{Authorization=("Basic {0}" -f $BASE64AUTHINFO)} "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages" -Body "From=$MY_NUMBER&To=$HER_NUMBER&Body=$MSG" > $null + Invoke-RestMethod -Method Post -Headers @{Authorization=("Basic {0}" -f $BASE64AUTHINFO)} $API_URL -Body $body > $null } catch{ Write-Host "Failed to send SMS: $_" } - diff --git a/python/smack_my_bitch_up.py b/python/smack_my_bitch_up.py index 5a5d425..17bd321 100755 --- a/python/smack_my_bitch_up.py +++ b/python/smack_my_bitch_up.py @@ -17,7 +17,7 @@ TWILIO_ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID') TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN') # Phone numbers -my_number = '+xxx' +my_number = '+xxx' her_number = '+xxx' reasons = [ @@ -30,7 +30,7 @@ client = TwilioRestClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN) client.messages.create( to=her_number, - from=my_number, + from_=my_number, body="Late at work. " + random.choice(reasons) )