-
Notifications
You must be signed in to change notification settings - Fork 40
/
beaconSMS.cna
82 lines (69 loc) · 2.33 KB
/
beaconSMS.cna
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
73
74
75
76
77
78
79
80
81
82
global('@old $phonenumber');
# This script requires ssmtp. Use apt-get install ssmtp
# Setup ssmtp example http://tombuntu.com/index.php/2008/10/21/sending-email-from-your-system-with-ssmtp/
# Example ssmtp.conf for gmail
# Note: ***** You must allow access for "less secure apps" https://support.google.com/accounts/answer/6010255
# For information on how to email an SMS to through your cellular provider http://www.emailtextmessages.com/
on heartbeat_10s {
local('@beacons $beacon $bid %data @new @all');
# grab all beacon ids AND build a map between ids and data
@beacons = beacons();
foreach $beacon (@beacons) {
$bid = $beacon['id'];
%data[$bid] = $beacon;
push(@all, $bid);
}
# remove old beacons from current list... I use copy(@all)
# because removeAll is destructive to its first argument
@new = removeAll(copy(@all), @old);
# with old beacons removed; we have our new beacons...
foreach $bid (@new) {
fire_event("beacon_initial", $bid, %data[$bid]);
}
# make our list of all beacons into our old list now
@old = @all;
}
#################
# #
# Menu Settings #
# #
#################
menubar("SMS", "smsmenu", 2);
popup smsmenu {
item "Setup SMS Notification" {
beaconSMS_dialog();
}
}
#################
# #
# Act on beacon #
# #
#################
on beacon_initial {
global('$phonenumber');
local('$process @data');
println("I have a beacon: $1 from " . $2['internal']);
$process = exec("sh sendsms.sh");
@data = readAll($process);
closef($process);
bsleep($1, 5, 10);
}
sub beaconSMS_dialog {
global('$phonenumber');
local('$mailto $mailfrom $subject $data $file $handle $handle2 $smsscript');
exec("rm beaconalert.txt");
exec("rm sendsms.sh");
$phonenumber = prompt_text("SMS_Number:");
$mailto = prompt_text("Mailto:");
$mailfrom = prompt_text("Mailfrom:");
$subject = prompt_text("Subject:");
$data = "Alert: We have received a new Beacon!";
$file = ("To: $mailto $+ \nFrom: $mailfrom $+ \nSubject: $subject $+ \n\n$data");
$handle = openf(">beaconalert.txt");
writeb($handle, $file);
closef($handle);
$smsscript = ("\#/bin/bash $+ \ncat beaconalert.txt | ssmtp $phonenumber");
$handle2 = openf(">sendsms.sh");
writeb($handle2, $smsscript);
closef($handle2);
}