| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::SMS::MyTMN; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23127
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
49
|
|
|
4
|
1
|
|
|
1
|
|
8
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
70
|
|
|
5
|
|
|
|
|
|
|
require WWW::Mechanize; |
|
6
|
|
|
|
|
|
|
require Exporter; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Net::SMS::MyTMN - Send SMS trough MyTMN! |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.08 |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
|
17
|
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
1090
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$VERSION = '0.08'; |
|
21
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
22
|
|
|
|
|
|
|
@EXPORT = qw(); |
|
23
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
|
24
|
|
|
|
|
|
|
DEFAULT => [qw//], |
|
25
|
|
|
|
|
|
|
VALID => [qw/sms_mytmn check_sms/], |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
@EXPORT_OK = qw/sms_mytmn check_sms/; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Quick and dirty way to send SMS trough portuguese mobile operator. |
|
32
|
|
|
|
|
|
|
Note: you need to have an account on www.mytmn.pt |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
35
|
|
|
|
|
|
|
use strict; |
|
36
|
|
|
|
|
|
|
use warnings; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
use Net::SMS::MyTMN; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
print Net::SMS::MyTMN::sms_mytmn({ |
|
41
|
|
|
|
|
|
|
'username' => '960000000', |
|
42
|
|
|
|
|
|
|
'password' => 'password', |
|
43
|
|
|
|
|
|
|
'targets' => [960000000,910000000], |
|
44
|
|
|
|
|
|
|
'message' => 'message goes here!', |
|
45
|
|
|
|
|
|
|
}); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
print Net::SMS::MyTMN::check_mytmn({ |
|
48
|
|
|
|
|
|
|
'username' => '960000000', |
|
49
|
|
|
|
|
|
|
'password' => 'password', |
|
50
|
|
|
|
|
|
|
}); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 EXPORT |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sms_mytmn() to send messages and check_sms() to check how many free sms are left |
|
56
|
|
|
|
|
|
|
for the current month. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 sms_mytmn() |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
The following 4 parameters are *REQUIRED*: |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
username : probably your phone number |
|
65
|
|
|
|
|
|
|
password : the password you use to log onto www.mytmn.pt |
|
66
|
|
|
|
|
|
|
targets : up to five phone numbers |
|
67
|
|
|
|
|
|
|
message : a string with the message you're about to send |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Return a string: "Message sent" |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 check_mytmn() |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
The following 2 parameters are *REQUIRED*: |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
username : probably your phone number |
|
76
|
|
|
|
|
|
|
password : the password you use to log onto www.mytmn.pt |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Returns the number of messages left. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub sms_mytmn { |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
0
|
|
|
|
my $username = ( $self->{'username'} || undef ); |
|
87
|
0
|
|
0
|
|
|
|
my $password = ( $self->{'password'} || undef ); |
|
88
|
0
|
|
0
|
|
|
|
my $targets = ( $self->{'targets'} || undef ); |
|
89
|
0
|
|
0
|
|
|
|
my $message = ( $self->{'message'} || undef ); |
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $valid = _valid( |
|
92
|
|
|
|
|
|
|
{ |
|
93
|
|
|
|
|
|
|
'username' => $username, |
|
94
|
|
|
|
|
|
|
'password' => $password, |
|
95
|
|
|
|
|
|
|
'targets' => $targets, |
|
96
|
|
|
|
|
|
|
'message' => $message, |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
); |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
return $valid unless !$valid; |
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $target_fields = { |
|
103
|
|
|
|
|
|
|
'message' => $message, |
|
104
|
|
|
|
|
|
|
'event' => 'confirmSend', |
|
105
|
|
|
|
|
|
|
}; |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my $i = 1; |
|
108
|
0
|
|
|
|
|
|
foreach ( @{$targets} ) { |
|
|
0
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$target_fields->{ 'phoneNumber' . $i } = $_; |
|
110
|
0
|
|
|
|
|
|
$i++; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my $mech = WWW::Mechanize->new(); |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
$mech->get('http://www.tmn.pt:80/portal/site/tmn'); |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
$mech->submit_form( |
|
118
|
|
|
|
|
|
|
form_number => 1, |
|
119
|
|
|
|
|
|
|
fields => { |
|
120
|
|
|
|
|
|
|
'usr' => $username, |
|
121
|
|
|
|
|
|
|
'pwd' => $password, |
|
122
|
|
|
|
|
|
|
}, |
|
123
|
|
|
|
|
|
|
); |
|
124
|
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
sleep 1; |
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
my $r = $mech->get('http://my.tmn.pt/web/easysms/EasySmsConfirmSend.po'); |
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
my ($idsessao) = $r->content() =~ /\.*tmnsessionid\%3D(\w{32})\.*/gmx; |
|
130
|
|
|
|
|
|
|
|
|
131
|
0
|
0
|
|
|
|
|
die "Cannot read sessionid!\n" unless $idsessao; |
|
132
|
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$mech->get( |
|
134
|
|
|
|
|
|
|
qq|http://my.tmn.pt/web/easysms/EasySms.po?silentauthdone=1&tmnsessionid=$idsessao| |
|
135
|
|
|
|
|
|
|
); |
|
136
|
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
my $rr = $mech->submit_form( |
|
138
|
|
|
|
|
|
|
form_name => 'easySmsForm', |
|
139
|
|
|
|
|
|
|
fields => $target_fields, |
|
140
|
|
|
|
|
|
|
); |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
$mech->submit_form( form_name => 'headerForm' ); |
|
143
|
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
undef $mech; |
|
145
|
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
return qq|Message sent\n|; |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub check_mytmn { |
|
151
|
|
|
|
|
|
|
|
|
152
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
153
|
|
|
|
|
|
|
|
|
154
|
0
|
|
0
|
|
|
|
my $username = ( $self->{'username'} || undef ); |
|
155
|
0
|
|
0
|
|
|
|
my $password = ( $self->{'password'} || undef ); |
|
156
|
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
my $valid = _valid( |
|
158
|
|
|
|
|
|
|
{ |
|
159
|
|
|
|
|
|
|
'username' => $username, |
|
160
|
|
|
|
|
|
|
'password' => $password, |
|
161
|
|
|
|
|
|
|
'targets' => ['960000000'], |
|
162
|
|
|
|
|
|
|
'message' => '-', |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
); |
|
165
|
|
|
|
|
|
|
|
|
166
|
0
|
0
|
|
|
|
|
return $valid unless !$valid; |
|
167
|
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
my $mech = WWW::Mechanize->new(); |
|
169
|
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
$mech->get('http://www.tmn.pt:80/portal/site/tmn'); |
|
171
|
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
$mech->submit_form( |
|
173
|
|
|
|
|
|
|
form_number => 1, |
|
174
|
|
|
|
|
|
|
fields => { |
|
175
|
|
|
|
|
|
|
'usr' => $username, |
|
176
|
|
|
|
|
|
|
'pwd' => $password, |
|
177
|
|
|
|
|
|
|
}, |
|
178
|
|
|
|
|
|
|
); |
|
179
|
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
sleep 1; |
|
181
|
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
my $r = $mech->get('http://my.tmn.pt/web/easysms/EasySmsConfirmSend.po'); |
|
183
|
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
my ($idsessao) = $r->content() =~ /\.*tmnsessionid\%3D(\w{32})\.*/gmx; |
|
185
|
|
|
|
|
|
|
|
|
186
|
0
|
0
|
|
|
|
|
die "Cannot read sessionid!\n" unless $idsessao; |
|
187
|
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
$r = $mech->get( |
|
189
|
|
|
|
|
|
|
qq|http://my.tmn.pt/web/easysms/EasySms.po?silentauthdone=1&tmnsessionid=$idsessao| |
|
190
|
|
|
|
|
|
|
); |
|
191
|
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
my ($free) = $r->content() =~ /.*messagesCanBeSent">(\d+)<\//igmx; |
|
193
|
0
|
0
|
|
|
|
|
$free = q|0| unless $free; |
|
194
|
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
undef $mech; |
|
196
|
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
return $free; |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub _valid { |
|
202
|
|
|
|
|
|
|
|
|
203
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
204
|
|
|
|
|
|
|
|
|
205
|
0
|
0
|
0
|
|
|
|
return _errors(1) |
|
206
|
|
|
|
|
|
|
unless $self->{'username'} |
|
207
|
|
|
|
|
|
|
&& $self->{'username'} =~ /^96\d{7}$/; |
|
208
|
|
|
|
|
|
|
|
|
209
|
0
|
0
|
0
|
|
|
|
return _errors(2) |
|
210
|
|
|
|
|
|
|
unless $self->{'password'} |
|
211
|
|
|
|
|
|
|
&& $self->{'password'} =~ |
|
212
|
|
|
|
|
|
|
/^\w+|\W+$/; # need to check wich characters are allowed |
|
213
|
|
|
|
|
|
|
|
|
214
|
0
|
|
|
|
|
|
return _errors(3) |
|
215
|
|
|
|
|
|
|
unless $self->{'targets'} |
|
216
|
|
|
|
|
|
|
&& ref( $self->{'targets'} ) eq 'ARRAY' |
|
217
|
0
|
|
|
|
|
|
&& scalar @{ $self->{'targets'} } >= 1 |
|
218
|
0
|
0
|
0
|
|
|
|
&& scalar @{ $self->{'targets'} } <= 5; |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
219
|
|
|
|
|
|
|
|
|
220
|
0
|
0
|
0
|
|
|
|
return _errors(4) |
|
221
|
|
|
|
|
|
|
unless $self->{'message'} |
|
222
|
|
|
|
|
|
|
&& length $self->{'message'} <= 140; |
|
223
|
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
return undef; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub _errors { |
|
228
|
|
|
|
|
|
|
|
|
229
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
230
|
0
|
0
|
|
|
|
|
return if !$self; |
|
231
|
|
|
|
|
|
|
|
|
232
|
0
|
|
|
|
|
|
my $errors = { |
|
233
|
|
|
|
|
|
|
1 => qq|Missing or invalid username\n|, |
|
234
|
|
|
|
|
|
|
2 => qq|Missing or invalid password\n|, |
|
235
|
|
|
|
|
|
|
3 => qq|Missing or invalid targets\n|, |
|
236
|
|
|
|
|
|
|
4 => qq|Missing or invalid message\n|, |
|
237
|
|
|
|
|
|
|
}; |
|
238
|
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
return $errors->{$self}; |
|
240
|
|
|
|
|
|
|
} |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 AUTHOR |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Miguel Santinho, C<< >> |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 BUGS |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
249
|
|
|
|
|
|
|
C, or through the web interface at |
|
250
|
|
|
|
|
|
|
L. |
|
251
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
|
252
|
|
|
|
|
|
|
your bug as I make changes. |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 SUPPORT |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Note that this module requires www::mechanize to automate the proccess of logging in |
|
257
|
|
|
|
|
|
|
and sending SMSs trough the www.mytmn.pt. If the operator makes any changes to |
|
258
|
|
|
|
|
|
|
the forms they use, this module will stop working. |
|
259
|
|
|
|
|
|
|
If that happens, please, report that to the author's e-mail. |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Copyright 2007 Miguel Santinho, all rights reserved. |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
267
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=cut |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
1; # End of Net::SMS::MyTMN |