Skip to content

Commit ded4526

Browse files
committed
Merge pull request NARKOZ#89 from RandomlyKnighted/powershell
Added powershell files for coffee and hangover scripts
2 parents d006970 + 8d18571 commit ded4526

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

powershell/fucking_coffee.psm1

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<#
2+
.SYNOPSIS
3+
Simple script to connect to a coffee part using TelNet then issue specific commands that
4+
brew and pourt a cup of coffee for the user.
5+
.DESCRIPTION
6+
This script was converted using the ruby version of the fucking_coffee script. In this script,
7+
I left the use of environment variables since its only use was to determine if the user was
8+
still logged in to the system. Per issue #42 (https://github.com/NARKOZ/hacker-scripts/issues/42)
9+
I left the password string hard coded until a decision is made by NARKOZ, the project owner, as
10+
to how the information should be stored.
11+
.OUTPUT
12+
None
13+
.NOTES
14+
Author: Tyler Hughes
15+
Twitter: @thughesIT
16+
Blog: http://tylerhughes.info/
17+
18+
Changelog:
19+
1.0 Initial Release
20+
#>
21+
22+
Function Fucking-Coffee
23+
{
24+
# Exit early if no sessions with my username are found
25+
if ($env:Username.Count > 0) {
26+
return
27+
}
28+
29+
$coffee_machine_ip = '10.10.42.42'
30+
$password = '1234'
31+
32+
Start-Sleep -s 17
33+
34+
$socket = New-Object System.Net.Sockets.TcpClient($coffee_machine_ip)
35+
if ($socket) {
36+
$stream = $connection.GetStream()
37+
$Writer = New-Object System.IO.StreamWriter($Stream)
38+
$Buffer = New-Object System.Byte[] 1024
39+
$Encoding = New-Object System.Text.AsciiEncoding
40+
41+
# Start issuing the commands
42+
Send-TelNetCommands($Writer, $password, 1)
43+
Send-TelNetCommands($Writer, "sys brew", 24)
44+
Send-TelNetCommands($Writer, "sys pour", 4)
45+
46+
$socket.Close()
47+
}
48+
}
49+
50+
Function Send-TelNetCommands
51+
{
52+
Param (
53+
[Parameter(ValueFromPipeline=$false)]
54+
[System.IO.StreamWriter]$writer,
55+
[String]$command,
56+
[int]$WaitTime
57+
)
58+
59+
$writer.WriteLine($command)
60+
$writer.Flush()
61+
Start-Sleep -Milliseconds $WaitTime
62+
}

powershell/hangover.psm1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<#
2+
.SYNOPSIS
3+
Simple script to SMS a supervisor informing them you will be working from home
4+
on the day this script is used.
5+
.DESCRIPTION
6+
This script was converted using the ruby version of the hangover script. However, the ruby
7+
version used environment variables to hold the user's account information. Due to issue #42
8+
(https://github.com/NARKOZ/hacker-scripts/issues/42) I opted to hard code the strings at
9+
this time until a decision is made by NARKOZ, the project owner, as the how the information
10+
should be stored.
11+
12+
This script also uses Twilio to send the SMS messages. The from number MUST be a valid Twilio
13+
phone number. The to number can be any outgoing number.
14+
.OUTPUT
15+
This script will output an error message to the PowerShell window if it fails
16+
to send the message.
17+
.NOTES
18+
Author: Tyler Hughes
19+
Twitter: @thughesIT
20+
Blog: http://tylerhughes.info/
21+
22+
Changelog:
23+
1.0 Initial Release
24+
#>
25+
Function Hangover
26+
{
27+
# Phone numbers (Must include country code and area code)
28+
$from = '+XXXXXXXXXXX'
29+
$to = '+XXXXXXXXXXX'
30+
31+
# Twilio API Information
32+
$twilio_base_url = 'https://api.twilio.com/2010-04-01'
33+
$twilio_account_sid = 'XXXXXXXXXXXXXXXXXXX'
34+
$twilio_auth_token = 'XXXXXXXXXXXXXXXXXX'
35+
36+
$password = ConvertTo-SecureString -AsPlainText $twilio_auth_token -Force
37+
$credentials = New-Object System.Management.Automation.PSCredential($twilio_account_sid, $password)
38+
39+
# Get the message to send
40+
$excuses =
41+
'Locked out',
42+
'Pipes broke',
43+
'Food poisoning',
44+
'Not feeling well'
45+
46+
$excuse = $excuses | Get-Random
47+
$message = "$excuse. Going to work from home today."
48+
$body = @{
49+
From = $from;
50+
To = $to;
51+
Body = $message;
52+
}
53+
54+
# Send the message and log any errors
55+
$uri = "$twilio_base_url/Accounts/" + $credentials.UserName + "/SMS/Messages"
56+
57+
try {
58+
$response = Invoke-RestMethod -Method Post -Uri $uri -Body $body -Credential $credentials
59+
}
60+
catch {
61+
$time = Get-Date -format u
62+
Write-Host $time " - Failed to send message: " $message
63+
}
64+
}

0 commit comments

Comments
 (0)