From 42636e17623eb13bf0739e844f912addcc435cf8 Mon Sep 17 00:00:00 2001 From: hzwanghonglai Date: Fri, 27 Nov 2015 16:10:43 +0800 Subject: [PATCH 01/28] fucking coffee using coffeescript --- coffee/fucking.coffee | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 coffee/fucking.coffee diff --git a/coffee/fucking.coffee b/coffee/fucking.coffee new file mode 100755 index 0000000..d0f26bc --- /dev/null +++ b/coffee/fucking.coffee @@ -0,0 +1,28 @@ +#!/usr/bin/env coffee + +username = 'name' + +host = 'localhost' +port = '3000' +pass = '5555' + +sh = require('child_process').execSync + +# weekend +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) + +setTimeout -> + conn.write "#{pass}\nsys brew\n" + setTimeout -> + conn.end 'sys pour' + process.exit(0) + , 2 * 1000 +, 1 * 1000 + +# alert +sh('say come here and take your fucking coffee') From b88a838136afbcec83020e21c39943abff95ba03 Mon Sep 17 00:00:00 2001 From: Maxime Orefice Date: Fri, 27 Nov 2015 11:32:10 +0100 Subject: [PATCH 02/28] Update smack_my_bitch_up.rb Correct exit session unless session with username is found --- smack_my_bitch_up.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smack_my_bitch_up.rb b/smack_my_bitch_up.rb index e970f2c..b81a334 100755 --- a/smack_my_bitch_up.rb +++ b/smack_my_bitch_up.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # Exit early if no sessions with my username are found -exit if `who -q`.include? ENV['USER'] +exit unless `who -q`.include? ENV['USER'] require 'dotenv' require 'twilio-ruby' From 5829f504f6fbda46887425589d37d3552cd25ed6 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Fri, 27 Nov 2015 22:01:08 +0400 Subject: [PATCH 03/28] fix ruby script closes #53 --- kumar_asshole.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/kumar_asshole.rb b/kumar_asshole.rb index ca5b9f6..fc6a2f0 100755 --- a/kumar_asshole.rb +++ b/kumar_asshole.rb @@ -14,8 +14,16 @@ 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 + 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| - if email.body[KEYWORDS_REGEX] && (db_name = email.body[DB_NAME_REGEX]) + 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) @@ -29,11 +37,3 @@ gmail.inbox.find(:unread, from: kumars_email).each do |email| gmail.deliver(reply) end end - -def create_reply(subject) - 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 From bac50db40b513d59a4acbaf4f19045b49c47d132 Mon Sep 17 00:00:00 2001 From: mhsjlw Date: Tue, 24 Nov 2015 20:12:54 -0500 Subject: [PATCH 04/28] The coffee machines uses telnet not SSH Update the TCP socket Oops! Fix a grammar mistake --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a34a21..bfda095 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ story](https://www.jitbit.com/alexblog/249-now-thats-what-i-call-a-hacker/)_: > xxx: [`hangover.sh`](https://github.com/NARKOZ/hacker-scripts/blob/master/hangover.sh) - another cron-job that is set to specific dates. Sends automated emails like "not feeling well/gonna work from home" etc. Adds a random "reason" from another predefined array of strings. Fires if there are no interactive sessions on the server at 8:45am. -> xxx: (and the oscar goes to) [`fucking-coffee.sh`](https://github.com/NARKOZ/hacker-scripts/blob/master/fucking-coffee.sh) - this one waits exactly 17 seconds (!), then opens an SSH session to our coffee-machine (we had no frikin idea the coffee machine is on the network, runs linux and has SSHD up and running) and sends some weird gibberish to it. Looks binary. Turns out this thing starts brewing a mid-sized half-caf latte and waits another 24 (!) seconds before pouring it into a cup. The timing is exactly how long it takes to walk to the machine from the dudes desk. +> xxx: (and the oscar goes to) [`fucking-coffee.sh`](https://github.com/NARKOZ/hacker-scripts/blob/master/fucking-coffee.sh) - this one waits exactly 17 seconds (!), then opens a telnet session to our coffee-machine (we had no frikin idea the coffee machine is on the network, runs linux and has a TCP socket up and running) and sends something like `sys brew`. Turns out this thing starts brewing a mid-sized half-caf latte and waits another 24 (!) seconds before pouring it into a cup. The timing is exactly how long it takes to walk to the machine from the dudes desk. > xxx: holy sh*t I'm keeping those From 4526889d7147d3478e166fc7d4e8a71a9de090fb Mon Sep 17 00:00:00 2001 From: robaganrab Date: Fri, 27 Nov 2015 15:43:13 +0100 Subject: [PATCH 05/28] Add perl/smack-my-bitch-up.pl Dependencies: - DateTime - SMS::Send::Twilio - YAML --- perl/smack-my-bitch-up.pl | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 perl/smack-my-bitch-up.pl diff --git a/perl/smack-my-bitch-up.pl b/perl/smack-my-bitch-up.pl new file mode 100755 index 0000000..4707518 --- /dev/null +++ b/perl/smack-my-bitch-up.pl @@ -0,0 +1,72 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use DateTime; +use SMS::Send; +use YAML; + +# Config +my $conf = Load( <<'...' ); +--- +phone_numbers: + my_number: +15005550006 + her_number: +xxx +reasons: + - Working hard + - Gotta ship this feature + - Someone fucked the system again +... + +my $date = DateTime->now; + +# Skip on weekends +if ( $date->day_of_week >= 6 ) { + exit; +} + +# Exit early if no sessions with my username are found +open( my $cmd_who, '-|', 'who' ) || die "Cannot pipe who command ". $!; + +my @sessions = grep { + m/$ENV{'USER'}/ +} <$cmd_who>; + +close $cmd_who; + +exit if ( scalar( @sessions ) == 0 ); + +# Load Twilio API config +open( my $env, '<', '../.env' ) || die "Cannot find .env file in project root."; +LINE: while ( my $line = <$env> ) { + next LINE unless ( $line =~ m/^(TWILIO[^=]+)=(.*)(?:[\n\r]*)/ ); + $conf->{'env'}->{ $1 } = $2; +} + +close $env; + +# Randomize excuse +my $reason_number = int( rand( scalar( @{ $conf->{'reasons'} } ) ) ); +my $sms_text = "Late at work. ". $conf->{'reasons'}[ $reason_number ]; + +# Create an object. There are three required values: +my $sender = SMS::Send->new('Twilio', + _accountsid => $conf->{'env'}->{'TWILIO_ACCOUNT_SID'}, + _authtoken => $conf->{'env'}->{'TWILIO_AUTH_TOKEN'}, + _from => $conf->{'phone_numbers'}->{'my_number'}, +); + +# Send a message to me +my $sent = $sender->send_sms( + text => $sms_text, + to => $conf->{'phone_numbers'}->{'her_number'}, +); + +# Did it send? +if ( $sent ) { + print "Sent message.\n"; +} else { + print "Message failed.\n"; +} + From 5614ec64b76e8f6090442168c55ba9a4a3401eed Mon Sep 17 00:00:00 2001 From: robaganrab Date: Fri, 27 Nov 2015 15:44:17 +0100 Subject: [PATCH 06/28] Add perl/hangover.pl Dependencies: - DateTime - SMS::Send::Twilio - YAML --- perl/hangover.pl | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 perl/hangover.pl diff --git a/perl/hangover.pl b/perl/hangover.pl new file mode 100755 index 0000000..dda41a9 --- /dev/null +++ b/perl/hangover.pl @@ -0,0 +1,73 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use DateTime; +use SMS::Send; +use YAML; + +# Config +my $conf = Load( <<'...' ); +--- +phone_numbers: + my_number: +15005550006 + boss_number: +xxx +reasons: + - Locked out + - Pipes broke + - Food poisoning + - Not feeling well +... + +my $date = DateTime->now; + +# Skip on weekends +if ( $date->day_of_week >= 6 ) { + exit; +} + +# Exit early if no sessions with my username are found +open( my $cmd_who, '-|', 'who' ) || die "Cannot pipe who command ". $!; + +my @sessions = grep { + m/$ENV{'USER'}/ +} <$cmd_who>; + +close $cmd_who; + +exit if ( scalar( @sessions ) == 0 ); + +# Load Twilio API config +open( my $env, '<', '../.env' ) || die "Cannot find .env file in project root."; +LINE: while ( my $line = <$env> ) { + next LINE unless ( $line =~ m/^(TWILIO[^=]+)=(.*)(?:[\n\r]*)/ ); + $conf->{'env'}->{ $1 } = $2; +} + +close $env; + +# Randomize excuse +my $reason_number = int( rand( scalar( @{ $conf->{'reasons'} } ) ) ); +my $sms_text = "Gonna work from home. ". $conf->{'reasons'}[ $reason_number ]; + +# Create an object. There are three required values: +my $sender = SMS::Send->new('Twilio', + _accountsid => $conf->{'env'}->{'TWILIO_ACCOUNT_SID'}, + _authtoken => $conf->{'env'}->{'TWILIO_AUTH_TOKEN'}, + _from => $conf->{'phone_numbers'}->{'my_number'}, +); + +# Send a message to me +my $sent = $sender->send_sms( + text => $sms_text, + to => $conf->{'phone_numbers'}->{'boss_number'}, +); + +# Did it send? +if ( $sent ) { + print "Sent message.\n"; +} else { + print "Message failed.\n"; +} + From 0b8d25ee842ab9b22cd48f4ad5b47d72f7889a4b Mon Sep 17 00:00:00 2001 From: robaganrab Date: Fri, 27 Nov 2015 15:45:12 +0100 Subject: [PATCH 07/28] Add perl/fucking-coffee.pl Dependencies: - DateTime - Net::Telnet - YAML --- perl/fucking-coffee.pl | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 perl/fucking-coffee.pl diff --git a/perl/fucking-coffee.pl b/perl/fucking-coffee.pl new file mode 100755 index 0000000..bc08054 --- /dev/null +++ b/perl/fucking-coffee.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use DateTime; +use YAML; +use Net::Telnet; + +# Config +my $conf = Load( <<'...' ); +--- +coffee_machine_ip: 10.10.42.42 +password: 1234 +password_prompt: Password: +delay_before_brew: 17 +delay: 24 +... + +# Skip on weekends +my $date = DateTime->now; +if ( $date->day_of_week >= 6 ) { + exit; +} + +# Exit early if no sessions with my username are found +open( my $cmd_who, '-|', 'who' ) || die "Cannot pipe who command ". $!; + +my @sessions = grep { + m/$ENV{'USER'}/ +} <$cmd_who>; + +close $cmd_who; + +exit if ( scalar( @sessions ) == 0 ); + +sleep $conf->{'delay_before_brew'}; + +my $con = Net::Telnet->new( + 'Host' => $conf->{'coffee_machine_ip'}, +); + +$con->watifor( $conf->{'password_prompt'} ); +$con->cmd( $conf->{'password'} ); +$con->cmd( 'sys brew' ); +sleep $conf->{'delay'}; +$con->cmd( 'sys pour' ); +$con->close; + From 579b3df43b2ca1d43543ee2636e4f8e4b9bb88c4 Mon Sep 17 00:00:00 2001 From: robaganrab Date: Fri, 27 Nov 2015 15:46:03 +0100 Subject: [PATCH 08/28] Add perl/kumar-asshole.pl Dependencies: - DateTime - Mail::Webmail::Gmail - YAML TODO: Rewrite using a different GMail interface. --- perl/kumar-asshole.pl | 88 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 perl/kumar-asshole.pl diff --git a/perl/kumar-asshole.pl b/perl/kumar-asshole.pl new file mode 100755 index 0000000..06db753 --- /dev/null +++ b/perl/kumar-asshole.pl @@ -0,0 +1,88 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use YAML; +use DateTime; +use Mail::Webmail::Gmail; + +# Config +my $conf = Load( <<'...' ); +--- +kumar_mail: kumar.a@examle.com +database_regex: \S+_staging +keywords_regex: sorry|help|wrong +backup_path: /home/backups/databases/ +... +$conf->{'database_regex'} = qr/ ( $conf->{'database_regex'} ) /x; +$conf->{'keywords_regex'} = qr/ ( $conf->{'keywords_regex'} ) /x; + +my $date = DateTime->now->subtract( + 'days' => 1 +); + +# Load GMail API config +open( my $env, '<', '../.env' ) || die "Cannot find .env file in project root."; +LINE: while ( my $line = <$env> ) { + next LINE unless ( $line =~ m/^(GMAIL[^=]+)=(.*)(?:[\n\r]*)/ ); + $conf->{'env'}->{ $1 } = $2; +} + +close $env; + +my $gmail = Mail::Webmail::Gmail->new( + username => $conf->{'env'}->{'GMAIL_USERNAME'}, + password => $conf->{'env'}->{'GMAIL_PASSWORD'}, + encrypt_session => 1, +); + +my $messages = $gmail->get_messages( label => $Mail::Webmail::Gmail::FOLDERS{ 'INBOX' } ); +die "Cannot fetch emails: ". $gmail->error_msg(); + +MESSAGE: foreach my $message ( @{ $messages } ) { + unless ( + ( $message->{ 'new' } ) + && ( $message->{'sender_email'} eq $conf->{'kumars_email'} ) + && ( $message->{'body'} =~ m/$conf->{'keywords_regex'}/ ) + && ( $message->{'body'} =~ m/$conf->{'database_regex'}/ ) + ) { + print "Skipping mail from=[". $message->{'sender_email'}."] subject=[". $message->{'subject'} ."]\n"; + next MESSAGE; + } + exit 1; + + my $database = $1; + my $backup_file = $conf->{'backup_path'} . $database .'-'. $date->ymd() .'.gz'; + + unless ( -f $backup_file ) { + die 'Cannot find backup file=['. $backup_file ."]\n"; + } + + print 'Restoring database=['. $database .'] from day=['. $date->ymd() .'] from file=['. $backup_file ."]\n"; + + # Restore DB + system( 'gunzip -c '. $backup_file .' | psql '. $database ); + die "Error while restoring the database=[". $database ."] from file=[". $backup_file ."]" if ( $? >> 8 ); + + # Mark as read, add label, reply + $gmail->edit_labels( + 'label' => 'Database fixes', + 'action' => 'add', + 'msgid' => $message->{'id'} + ); + + $gmail->send_message( + 'to' => $conf->{'kumars_email'}, + 'subject' => 'RE: '. $message->{'subject'}, + 'msgbody' => "No problem. I've fixed it. \n\n Please be careful next time.", + ); + + $gmail->edit_labels( + 'label' => 'unread', + 'action' => 'remove', + 'msgid' => $message->{'id'} + ); + +} + From a152d067ee4cb3630712292bb9e1b2656a3e5fd1 Mon Sep 17 00:00:00 2001 From: bitsapien Date: Sat, 28 Nov 2015 11:26:22 +0530 Subject: [PATCH 09/28] fixed issue with gmail, kumars_email variable scope --- kumar_asshole.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 From d940ab08f06fd1f726c2632d21d4c449696c4954 Mon Sep 17 00:00:00 2001 From: Alexander Vega Date: Sat, 28 Nov 2015 20:58:18 -0500 Subject: [PATCH 10/28] Error on line 33 Error resulting in missing underscore after "from" on line 33 --- python/smack_my_bitch_up.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/smack_my_bitch_up.py b/python/smack_my_bitch_up.py index 5a5d425..02c7e05 100755 --- a/python/smack_my_bitch_up.py +++ b/python/smack_my_bitch_up.py @@ -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) ) From 77b658f15262daa810c6790e67f6a980a5df02da Mon Sep 17 00:00:00 2001 From: Zen Laboratory Date: Sun, 29 Nov 2015 04:04:28 +0100 Subject: [PATCH 11/28] Update kumar-asshole.pl --- perl/kumar-asshole.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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/ From d70ade58e19adc42d48620b1e2553b38f3aeefa8 Mon Sep 17 00:00:00 2001 From: Samir Madhavan Date: Mon, 30 Nov 2015 01:34:38 +0530 Subject: [PATCH 12/28] R version: smack_my_bitch_up.R --- R/smack_my_bitch_up.R | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 R/smack_my_bitch_up.R 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()) ) From 4b8c917151eda70a38a6d48a69ba14956bd34334 Mon Sep 17 00:00:00 2001 From: alexesprit Date: Sun, 29 Nov 2015 23:26:33 +0300 Subject: [PATCH 13/28] Proper check if user is logged in --- powershell/smack_my_bitch_up.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powershell/smack_my_bitch_up.ps1 b/powershell/smack_my_bitch_up.ps1 index 46c3d8f..7b30b27 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 } From dc7188cf432b79c0f4dcd4f9aea5a6425a63ad5a Mon Sep 17 00:00:00 2001 From: alexesprit Date: Mon, 30 Nov 2015 00:08:19 +0300 Subject: [PATCH 14/28] Fix sms sending When post data is set as text string, some characters like `plus` were not escaped. --- powershell/smack_my_bitch_up.ps1 | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/powershell/smack_my_bitch_up.ps1 b/powershell/smack_my_bitch_up.ps1 index 7b30b27..8b690bd 100644 --- a/powershell/smack_my_bitch_up.ps1 +++ b/powershell/smack_my_bitch_up.ps1 @@ -14,9 +14,6 @@ if (-not (QWINSTA | FINDSTR $env:USERNAME)) { $MY_NUMBER='+xxx' $HER_NUMBER='+xxx' -$TWILIO_ACCOUNT_SID = 'xxx' -$TWILIO_AUTH_TOKEN = 'xxx' - $REASONS= 'Working hard', 'Gotta ship this feature', @@ -26,14 +23,18 @@ $RAND = Get-Random -Maximum $REASONS.Count $MSG="Late at work. $REASONS[$RAND]" +$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 = $MSG; +} -$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: $_" } - From 7cc4b01a8bab25b35e0e0d37909e7c265a5ab3ca Mon Sep 17 00:00:00 2001 From: alexesprit Date: Mon, 30 Nov 2015 00:19:03 +0300 Subject: [PATCH 15/28] Get random reason easier --- powershell/smack_my_bitch_up.ps1 | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/powershell/smack_my_bitch_up.ps1 b/powershell/smack_my_bitch_up.ps1 index 8b690bd..903bd5c 100644 --- a/powershell/smack_my_bitch_up.ps1 +++ b/powershell/smack_my_bitch_up.ps1 @@ -14,21 +14,19 @@ if (-not (QWINSTA | FINDSTR $env:USERNAME)) { $MY_NUMBER='+xxx' $HER_NUMBER='+xxx' -$REASONS= +$REASONS = 'Working hard', 'Gotta ship this feature', 'Someone fucked the system again' - -$RAND = Get-Random -Maximum $REASONS.Count - -$MSG="Late at work. $REASONS[$RAND]" +$reason = $REASONS | Get-Random +$message = "Late at work. $reason." $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 = $MSG; + Body = $message; } #Send a text message and Log errors From 85ef697f1ccc878cef10cef1e3d0fb2317e01651 Mon Sep 17 00:00:00 2001 From: Lipis Date: Mon, 30 Nov 2015 11:13:27 +0100 Subject: [PATCH 16/28] Removed parenthesis for consistency --- coffee/fucking.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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' From 20f45b0c857f2b772a2aec23f86b7551c0a3158c Mon Sep 17 00:00:00 2001 From: Ahmad Samiei Date: Mon, 30 Nov 2015 14:14:35 +0800 Subject: [PATCH 17/28] keep things simple --- php/composer.json | 5 ++ php/fucking_coffee.php | 177 +++-------------------------------------- 2 files changed, 16 insertions(+), 166 deletions(-) create mode 100644 php/composer.json diff --git a/php/composer.json b/php/composer.json new file mode 100644 index 0000000..fb10072 --- /dev/null +++ b/php/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "bestnetwork/telnet": "^1.0" + } +} diff --git a/php/fucking_coffee.php b/php/fucking_coffee.php index 5ab70c7..cbce398 100644 --- a/php/fucking_coffee.php +++ b/php/fucking_coffee.php @@ -1,170 +1,15 @@ +#!/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 +(date('N') < 6) or exit('weekend'); +(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'); \ No newline at end of file From fc3e403aaf2f5f38ef9e06c6ae64f7b8f2547280 Mon Sep 17 00:00:00 2001 From: Ahmad Samiei Date: Mon, 30 Nov 2015 14:15:07 +0800 Subject: [PATCH 18/28] lib added to composer --- php/Lib/Telnet.php | 264 --------------------------------------------- 1 file changed, 264 deletions(-) delete mode 100644 php/Lib/Telnet.php 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 From 44e563f00180b71b3f5584859f4ce9ea5c1db569 Mon Sep 17 00:00:00 2001 From: Ahmad Samiei Date: Mon, 30 Nov 2015 14:16:52 +0800 Subject: [PATCH 19/28] no need to check date. handeled by cronjob --- php/fucking_coffee.php | 1 - 1 file changed, 1 deletion(-) diff --git a/php/fucking_coffee.php b/php/fucking_coffee.php index cbce398..ea794ff 100644 --- a/php/fucking_coffee.php +++ b/php/fucking_coffee.php @@ -5,7 +5,6 @@ require 'vendor/autoload.php'; use Bestnetwork\Telnet\TelnetClient; -(date('N') < 6) or exit('weekend'); (strpos(exec('who'), getenv('USER')) !== false) or exit('no session'); sleep(17); $con = new TelnetClient('10.10.42.42'); From 363e0ce0b6a015ca6fdd6b47a35d81522e362c21 Mon Sep 17 00:00:00 2001 From: Ahmad Samiei Date: Mon, 30 Nov 2015 14:20:05 +0800 Subject: [PATCH 20/28] oops! newline end of file. --- php/fucking_coffee.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/fucking_coffee.php b/php/fucking_coffee.php index ea794ff..074e22f 100644 --- a/php/fucking_coffee.php +++ b/php/fucking_coffee.php @@ -11,4 +11,4 @@ $con = new TelnetClient('10.10.42.42'); $con->execute('1234', 'Password: '); $con->execute('sys brew'); sleep(24); -$con->execute('sys pour'); \ No newline at end of file +$con->execute('sys pour'); From a948abdb9732fee489b4b30fc306c9d9496aa915 Mon Sep 17 00:00:00 2001 From: arjunnambiartc Date: Mon, 30 Nov 2015 15:23:17 +0530 Subject: [PATCH 21/28] Ported hangover script to golang --- go/hangover.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 go/hangover.go 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) + } +} From 20a22e5553801be0151c0906acd813a043c778db Mon Sep 17 00:00:00 2001 From: Anubhav Singh Date: Mon, 30 Nov 2015 21:21:04 +0530 Subject: [PATCH 22/28] golang smacked my bitch up --- go/smack_my_bitch_up.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 go/smack_my_bitch_up.go diff --git a/go/smack_my_bitch_up.go b/go/smack_my_bitch_up.go new file mode 100755 index 0000000..fd4f68c --- /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.mess) + return + } + + fmt.Printf("Message Sent Successfully with response: %s ",response) +} From a19a4ad8a8888fd2687e3d73493c3013b2a2dc04 Mon Sep 17 00:00:00 2001 From: Anubhav Singh Date: Tue, 1 Dec 2015 13:10:25 +0530 Subject: [PATCH 23/28] removed .mess bug of smack_my_bitch_up --- go/smack_my_bitch_up.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/smack_my_bitch_up.go b/go/smack_my_bitch_up.go index fd4f68c..66f7311 100755 --- a/go/smack_my_bitch_up.go +++ b/go/smack_my_bitch_up.go @@ -31,7 +31,7 @@ func main(){ 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.mess) + fmt.Printf("Failed to send SMS: ",err) return } From 9fe5471499c76dd1da0f39b0cc68bda285efcabf Mon Sep 17 00:00:00 2001 From: Yudi Purwanto Date: Tue, 1 Dec 2015 16:31:24 +0700 Subject: [PATCH 24/28] require phpdotenv --- php/composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/php/composer.json b/php/composer.json index fb10072..376b494 100644 --- a/php/composer.json +++ b/php/composer.json @@ -1,5 +1,6 @@ { "require": { - "bestnetwork/telnet": "^1.0" + "bestnetwork/telnet": "^1.0", + "vlucas/phpdotenv": "^2.0" } } From 13585ce3e8f8f771c53d8dd91ad1a0ba20817935 Mon Sep 17 00:00:00 2001 From: Yudi Purwanto Date: Tue, 1 Dec 2015 16:33:14 +0700 Subject: [PATCH 25/28] load phpenv --- php/fucking_coffee.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/php/fucking_coffee.php b/php/fucking_coffee.php index 074e22f..071d1d7 100644 --- a/php/fucking_coffee.php +++ b/php/fucking_coffee.php @@ -3,6 +3,9 @@ require 'vendor/autoload.php'; +$dotenv = new Dotenv\Dotenv(__DIR__); +$dotenv->load(); + use Bestnetwork\Telnet\TelnetClient; (strpos(exec('who'), getenv('USER')) !== false) or exit('no session'); From 269d2b6d08eb3fa0d40ba2b3799d541d4bd6ab7d Mon Sep 17 00:00:00 2001 From: Akshay Kashyap Date: Tue, 1 Dec 2015 16:54:25 -0500 Subject: [PATCH 26/28] NodeJS Implementation Made executable NodeJS Implementation of fucking_coffee --- 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..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}); +}); From 83abc3cff677d81935752b7525eaf6095047cd77 Mon Sep 17 00:00:00 2001 From: Akshay Kashyap Date: Tue, 1 Dec 2015 22:09:12 -0500 Subject: [PATCH 27/28] NodeJS for hangover and smack_my_bitch_up --- nodejs/hangover.js | 57 +++++++++++++++++++++++++++++++++++++ nodejs/smack_my_bitch_up.js | 56 ++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100755 nodejs/hangover.js create mode 100755 nodejs/smack_my_bitch_up.js 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/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); + } + }); +}); From 380cefee2121c76856ea5631518e9986f937d1b4 Mon Sep 17 00:00:00 2001 From: RandomlyKnighted Date: Sat, 28 Nov 2015 16:01:11 -0600 Subject: [PATCH 28/28] Added fucking_coffee and hangover PowerShell modules --- powershell/fucking_coffee.psm1 | 62 ++++++++++++++++++++++++++++++++ powershell/hangover.psm1 | 64 ++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 powershell/fucking_coffee.psm1 create mode 100644 powershell/hangover.psm1 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