-
Notifications
You must be signed in to change notification settings - Fork 0
/
ooma.pl
executable file
·129 lines (105 loc) · 2.94 KB
/
ooma.pl
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/perl -w
#
#
# ooma.pl - Give me my mp3 voicemail in an email without paying for Ooma Premier
#
# @gitrc - summer 2010
#
# screen scraping still valuable
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request::Common;
use HTTP::Cookies;
use File::Slurp;
use MIME::Lite;
use Data::Dumper;
use strict;
my $debug;
$debug = exists( $ENV{SSH_CLIENT} ) ? 1 : 0;
my $auth_url = 'https://my.ooma.com/home/login';
my $inbox_url = 'https://my.ooma.com/inbox';
my $log_url = 'https://my.ooma.com/call_logs/export';
my $username = 'username';
my $password = 'password';
my $submit_value = 'commit';
my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
$ua->cookie_jar(
HTTP::Cookies->new(
file => "ooma_cookies",
autosave => 0,
ignore_discard => 0
)
);
my $content = $ua->get($auth_url)->as_string;
die "Couldn't get $auth_url" unless defined $content;
$content =~ m/"authenticity_token"[^<]+value="(.*?)"/;
my $token = $1;
$content = $ua->request(
POST $auth_url ,
[
username => $username,
password => $password,
authenticity_token => $token
]
);
die "Couldn't get $auth_url" unless defined $content;
$content = $ua->get($inbox_url)->as_string;
die "Couldn't get $inbox_url" unless defined $content;
$content =~
m/download_message\?caller_name=(\d+)\&message_uid=(\w+-\w+-\w+-\w+-\w+)/;
my $caller = $1;
my $uidnumber = $2;
my $file_url =
"https://my.ooma.com/inbox/download_message?caller_name=$caller&message_uid=$uidnumber";
print "DEBUG: caller=$caller uidnumber=$uidnumber file_url = $file_url\n"
if $debug;
$content = $ua->get($file_url)->as_string;
write_file( '/tmp/message.mp3', { binmode => ':raw' }, $content );
my $response = $ua->get($log_url);
$content = $response->content;
my @content = split( "\n", $content );
my @missed = grep( /Missed/, @content );
my $line = $missed[0];
print "DEBUG LOGLINE: $line\n" if $debug;
my $callerid;
my ( $type, $local, $remote, $id, $date, $duration ) = split( /\t/, $line );
if ( $id eq " " ) {
$callerid = $remote;
}
else {
$callerid = $id;
}
my $filename = "/tmp/message.mp3";
# Cleanup the body
my $body = "Date/Time Caller
$date $remote";
my $subject = "New VM from $callerid";
# Generate the Email
### Create a new multipart message:
my $msg = MIME::Lite->new(
From => '[email protected]',
To => '[email protected]',
Cc => '[email protected]',
Subject => $subject,
Type => 'multipart/mixed'
);
#$msg->add('X-Priority' => 1);
### Add parts (each "attach" has same arguments as "new"):
$msg->attach(
Type => 'TEXT',
Data => $body
);
$msg->attach(
Type => 'audio/mpeg',
Path => $filename,
Disposition => 'attachment'
);
# send the email
if ($debug) {
print Dumper $msg;
}
else {
MIME::Lite->send( 'smtp', 'localhost', Timeout => 10 );
$msg->send();
}