From 8d18571e99dd28327728d6cd0b50271517ab35f8 Mon Sep 17 00:00:00 2001 From: RandomlyKnighted Date: Tue, 1 Dec 2015 23:08:12 -0600 Subject: [PATCH] Added powershell files --- 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