forked from NARKOZ/hacker-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhangover.pl
More file actions
executable file
·73 lines (57 loc) · 1.51 KB
/
Copy pathhangover.pl
File metadata and controls
executable file
·73 lines (57 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/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";
}