line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Net::SMS::TMobile::UK . This module allows the sending of SMS Text Messages via |
3
|
|
|
|
|
|
|
# the T-Mobile UK Website. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Author: Ben Charlton |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Copyright (c) 2007-2009 Ben Charlton. All Rights Reserved. |
8
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
9
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Net::SMS::TMobile::UK; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
36857
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
18
|
1
|
|
|
1
|
|
1328
|
use HTTP::Request::Common qw(POST GET); |
|
1
|
|
|
|
|
28619
|
|
|
1
|
|
|
|
|
89
|
|
19
|
1
|
|
|
1
|
|
1175
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
23716
|
|
|
1
|
|
|
|
|
760
|
|
20
|
|
|
|
|
|
|
my $debug = 0; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Net::SMS::TMobile::UK - Send SMS Messages via the T-Mobile UK Website. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Net::SMS::TMobile::UK; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $sms = Net::SMS::TMobile::UK->new(username=>$username, password=>$password); |
31
|
|
|
|
|
|
|
$sms->sendsms(to=>$target, message=>$message); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
T-Mobile is a major mobile network. Their UK Website allows the sending of 'webtext' |
36
|
|
|
|
|
|
|
messages which are an SMS sent from the users mobile number and charged against their |
37
|
|
|
|
|
|
|
mobile phone account. This module allows the sending of these messages - ideal if you |
38
|
|
|
|
|
|
|
pay for a bundle of SMS messages in advance. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Please note that this module is nothing to do with T-Mobile, and will probably stop |
41
|
|
|
|
|
|
|
working should T-Mobile ever change the method for sms submission. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 METHODS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 new |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Creates the Net::SMS::TMobile::UK object. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Usage: |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $sms = Net::SMS::TMobile::UK->new (username=>$username, password=>$password); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
The complete list of arguments is: |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
username : Your registered T-Mobile username. |
56
|
|
|
|
|
|
|
password : Your registered T-Mobile password. |
57
|
|
|
|
|
|
|
useragent : Name of the user agent you want to display to T-Mobile. |
58
|
|
|
|
|
|
|
debug : 0 (default) or 1 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Debug is optional and defaults to off, but can be set to 1 which prints |
61
|
|
|
|
|
|
|
out the text of the http responses. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub new { |
66
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
67
|
0
|
0
|
|
|
|
|
unless ($class) { |
68
|
0
|
|
|
|
|
|
return undef; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my %args = ( |
72
|
|
|
|
|
|
|
useragent=>'TMobileUK.pm/'.$Net::SMS::TMobile::UK::VERSION, |
73
|
|
|
|
|
|
|
@_ ); |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
unless ($args{username}) { |
76
|
0
|
|
|
|
|
|
return undef; |
77
|
|
|
|
|
|
|
} |
78
|
0
|
0
|
|
|
|
|
unless ($args{password}) { |
79
|
0
|
|
|
|
|
|
return undef; |
80
|
|
|
|
|
|
|
} |
81
|
0
|
0
|
|
|
|
|
if ($args{debug} == 1) { |
82
|
0
|
|
|
|
|
|
$debug = 1; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
86
|
0
|
|
|
|
|
|
$ua->cookie_jar( {} ); |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return bless { PASSWORD=>$args{password}, |
89
|
|
|
|
|
|
|
USERNAME=>$args{username}, |
90
|
|
|
|
|
|
|
USERAGENT=>$args{useragent}, |
91
|
|
|
|
|
|
|
ERROR=>0, |
92
|
|
|
|
|
|
|
LWP_UA=>$ua |
93
|
|
|
|
|
|
|
}, $class; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 sendsms |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Sends a message through the T-Mobile website. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Usage: |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$sms->sendsms( to => $mobile_phone, message => $msg, report => 0 ); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
where $mobile_phone is the mobile phone number that you're sending a |
106
|
|
|
|
|
|
|
message to and $msg is the message text. Setting report to 1 will enable |
107
|
|
|
|
|
|
|
delivery reports, but is otherwise optional. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This method returns 1 if we successfully send the message and undef on failure. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub sendsms () { |
114
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
115
|
0
|
|
|
|
|
|
my %args = ( @_ ); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $ua = $self->{LWP_UA}; |
118
|
0
|
|
|
|
|
|
$ua->agent($self->{USERAGENT}); |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
my $target=$args{to}; |
121
|
0
|
|
|
|
|
|
my $message=$args{message}; |
122
|
0
|
0
|
|
|
|
|
my $report='on' if $args{report}; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
## Check we have a target and message |
125
|
0
|
0
|
0
|
|
|
|
unless ($target && $message) { |
126
|
0
|
|
|
|
|
|
$self->error(5); |
127
|
0
|
|
|
|
|
|
return undef; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
## Get initial session cookie. Sadly no longer optional :( |
131
|
0
|
|
|
|
|
|
my $req = GET 'http://www.t-mobile.co.uk/'; |
132
|
0
|
|
|
|
|
|
my $res = $ua->request($req); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
## Log in and get a session cookie |
135
|
0
|
|
|
|
|
|
$req = POST 'https://www.t-mobile.co.uk/service/your-account/login/', |
136
|
|
|
|
|
|
|
[ username=>$self->{USERNAME}, |
137
|
|
|
|
|
|
|
password=>$self->{PASSWORD}, |
138
|
|
|
|
|
|
|
submit=>"Log in"]; |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
$res = $ua->request($req); |
141
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
if ($debug) { |
143
|
0
|
|
|
|
|
|
print "Login request:\n==================\n"; |
144
|
0
|
|
|
|
|
|
print $res->as_string; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
## Check for successful request |
148
|
0
|
0
|
|
|
|
|
unless ($res->is_redirect) { |
149
|
0
|
|
|
|
|
|
$self->error(3); |
150
|
0
|
|
|
|
|
|
return undef; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my $content = $res->as_string; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
## check for valid credentials |
156
|
0
|
0
|
|
|
|
|
if ($content =~ m/Please enter a valid username and password/) { |
157
|
0
|
|
|
|
|
|
$self->error(2); |
158
|
0
|
|
|
|
|
|
return undef; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
## Collect struts token for SMS form submission: |
163
|
0
|
|
|
|
|
|
$req = GET 'https://www.t-mobile.co.uk/service/your-account/private/wgt/send-text-preparing/'; |
164
|
0
|
|
|
|
|
|
$res = $ua->request($req); |
165
|
0
|
0
|
|
|
|
|
if ($debug) { |
166
|
0
|
|
|
|
|
|
print "Token request:\n==================\n"; |
167
|
0
|
|
|
|
|
|
print $res->as_string; |
168
|
|
|
|
|
|
|
} |
169
|
0
|
0
|
|
|
|
|
unless ($res->is_success) { |
170
|
0
|
|
|
|
|
|
$self->error(3); |
171
|
0
|
|
|
|
|
|
return undef; |
172
|
|
|
|
|
|
|
} |
173
|
0
|
|
|
|
|
|
$content = $res->as_string; |
174
|
0
|
|
|
|
|
|
my ($token) = ($content =~ m//is); |
175
|
|
|
|
|
|
|
|
176
|
0
|
0
|
|
|
|
|
unless ($token) { |
177
|
0
|
|
|
|
|
|
$self->error(4); |
178
|
0
|
|
|
|
|
|
return undef; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
## Post to SMS sending form with message details and struts token. |
182
|
0
|
|
|
|
|
|
$req = POST 'https://www.t-mobile.co.uk/service/your-account/private/wgt/send-text-processing/', |
183
|
|
|
|
|
|
|
[ 'org.apache.struts.taglib.html.TOKEN'=>$token, |
184
|
|
|
|
|
|
|
'selectedRecipients'=>$target, |
185
|
|
|
|
|
|
|
'message'=>$message, |
186
|
|
|
|
|
|
|
'sendDeliveryReport'=>$report, |
187
|
|
|
|
|
|
|
'submit'=>'Send' ]; |
188
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
$res = $ua->request($req); |
190
|
|
|
|
|
|
|
|
191
|
0
|
0
|
|
|
|
|
if ($debug) { |
192
|
0
|
|
|
|
|
|
print "SMS POST:\n==================\n"; |
193
|
0
|
|
|
|
|
|
print $res->as_string; |
194
|
|
|
|
|
|
|
} |
195
|
0
|
0
|
0
|
|
|
|
unless (($res->is_success) or ($res->is_redirect)) { |
196
|
0
|
|
|
|
|
|
$self->error(3); |
197
|
0
|
|
|
|
|
|
return undef; |
198
|
|
|
|
|
|
|
} |
199
|
0
|
|
|
|
|
|
$content = $res->as_string; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
## Check for success |
202
|
0
|
0
|
|
|
|
|
if ($content =~ m/(Success|sent-confirmation)/is) { |
203
|
0
|
|
|
|
|
|
return 1; |
204
|
|
|
|
|
|
|
} else { |
205
|
0
|
|
|
|
|
|
$self->error(4); |
206
|
0
|
|
|
|
|
|
return undef; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head2 error |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Returns a code that describes the last error ocurred. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Example: |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
if(my $error = $sms->error) { |
217
|
|
|
|
|
|
|
if($error == 5) { |
218
|
|
|
|
|
|
|
die("Message or Destination missing\n"); |
219
|
|
|
|
|
|
|
} elsif ($error == 2) { |
220
|
|
|
|
|
|
|
die("Username or password invalid\n"); |
221
|
|
|
|
|
|
|
} else { |
222
|
|
|
|
|
|
|
die("Unexpected fault\n"); |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Using same error codes as Net::SMS::Clickatell where possible: |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
0 - No error |
229
|
|
|
|
|
|
|
1 - Username or password not defined (not used, as we require these during module construction) |
230
|
|
|
|
|
|
|
2 - Username or password wrong |
231
|
|
|
|
|
|
|
3 - Server has problems |
232
|
|
|
|
|
|
|
4 - The message couldn't be sent |
233
|
|
|
|
|
|
|
5 - No message or destination specified |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=cut |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
sub error { |
238
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
239
|
0
|
0
|
|
|
|
|
if(!defined $self) { |
240
|
0
|
|
|
|
|
|
return undef; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
0
|
|
|
|
|
|
my $error = shift; |
244
|
0
|
0
|
|
|
|
|
if(!defined $error) { |
245
|
0
|
|
|
|
|
|
return $self->{ERROR}; |
246
|
|
|
|
|
|
|
} else { |
247
|
0
|
|
|
|
|
|
$self->{ERROR} = $error; |
248
|
0
|
|
|
|
|
|
return 1; |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head1 AUTHOR |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Ben Charlton, C<< >> |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head1 BUGS |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
259
|
|
|
|
|
|
|
C, or through the web interface at |
260
|
|
|
|
|
|
|
L. |
261
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
262
|
|
|
|
|
|
|
your bug as I make changes. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head1 SUPPORT |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
perldoc Net::SMS::TMobile::UK |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
You can also look for information at: |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=over 4 |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
L |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=item * CPAN Ratings |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
L |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
L |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=item * Search CPAN |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
L |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=back |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
Net:SMS::Clickatell by Roberto Alamos Moreno for inspiration. |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
Copyright (c) 2007,2008 Ben Charlton. All Rights Reserved. |
299
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
300
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
This software or the author aren't related to T-Mobile in any way. |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=cut |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
1; |