line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: Libero.pm,v 1.4 2003/03/20 00:07:32 eim Exp $ |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
############################################################################# |
6
|
|
|
|
|
|
|
# # |
7
|
|
|
|
|
|
|
# IMPORTANT NOTE # |
8
|
|
|
|
|
|
|
# # |
9
|
|
|
|
|
|
|
# !!! THE AUTHOR IS ==NOT== RESPONSIBLE FOR ANY USE OF THIS PROGRAM !!! # |
10
|
|
|
|
|
|
|
# # |
11
|
|
|
|
|
|
|
# GPL LICENSE # |
12
|
|
|
|
|
|
|
# # |
13
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify # |
14
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by # |
15
|
|
|
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or # |
16
|
|
|
|
|
|
|
# (at your option) any later version. # |
17
|
|
|
|
|
|
|
# # |
18
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, # |
19
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
20
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
21
|
|
|
|
|
|
|
# GNU General Public License for more details. # |
22
|
|
|
|
|
|
|
# # |
23
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License # |
24
|
|
|
|
|
|
|
# along with this program; if not, write to the Free Software # |
25
|
|
|
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, # |
26
|
|
|
|
|
|
|
# MA 02111-1307 USA # |
27
|
|
|
|
|
|
|
# # |
28
|
|
|
|
|
|
|
############################################################################# |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# |
31
|
|
|
|
|
|
|
# ABOUT THIS MODULE |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
# This WWW-SMS module provides an interface to the Libero/Wind SMS gateway |
34
|
|
|
|
|
|
|
# available over at http://windeureka.libero.it, all is done in two steps: |
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
# STEP 1 Authenticate and login. |
37
|
|
|
|
|
|
|
# STEP 2 Send the SMS message. |
38
|
|
|
|
|
|
|
# |
39
|
|
|
|
|
|
|
# Here is a list af all the Italian operators supported by this gateway: |
40
|
|
|
|
|
|
|
# |
41
|
|
|
|
|
|
|
# WIND TIM |
42
|
|
|
|
|
|
|
# 320, 328, 329 330, 333, 334, 335, 336, 337, 338, 339, 360, 368 |
43
|
|
|
|
|
|
|
# |
44
|
|
|
|
|
|
|
# OMNITEL BLU |
45
|
|
|
|
|
|
|
# 340, 347, 348, 349 380, 388, 389 |
46
|
|
|
|
|
|
|
# |
47
|
|
|
|
|
|
|
# Note that $debug=1 will print out all the HTML source code of the portal |
48
|
|
|
|
|
|
|
# the best thing you can do is to redirect the debugging output to a file. |
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
# Doc note: The Perl LWP (libwww-perl) documentation is avaiable in your |
51
|
|
|
|
|
|
|
# local perldoc repository, see: % perldoc lwpcook it's always usefull. |
52
|
|
|
|
|
|
|
# |
53
|
|
|
|
|
|
|
# This packages was written by: Ivo Mario |
54
|
|
|
|
|
|
|
# and was last modified: $Date: 2003/03/20 00:07:32 $ |
55
|
|
|
|
|
|
|
# |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# |
59
|
|
|
|
|
|
|
# LIBS AND CONFIGS |
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
package WWW::SMS::Libero; |
63
|
1
|
|
|
1
|
|
577
|
use Telephone::Number; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
180
|
|
64
|
|
|
|
|
|
|
require Exporter; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$VERSION = '1.00'; |
67
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
68
|
|
|
|
|
|
|
@EXPORT = qw(); |
69
|
|
|
|
|
|
|
@EXPORT_OK = qw(@PREFIXES _send MAXLENGTH); |
70
|
|
|
|
|
|
|
@PREFIXES = (Telephone::Number->new('39', [ |
71
|
|
|
|
|
|
|
qw(320 328 329 330 333 334 335 336 337 338 339 360 368 340 347 348 349 380 388 389) |
72
|
|
|
|
|
|
|
], undef) |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# |
77
|
|
|
|
|
|
|
# SUBROUTINES |
78
|
|
|
|
|
|
|
# |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# |
81
|
|
|
|
|
|
|
# Message max length defintion. |
82
|
|
|
|
|
|
|
# |
83
|
|
|
|
|
|
|
sub MAXLENGTH () {96} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# |
86
|
|
|
|
|
|
|
# Error handling functions. |
87
|
|
|
|
|
|
|
# |
88
|
|
|
|
|
|
|
sub hnd_error { |
89
|
0
|
|
|
0
|
0
|
|
$_ = shift; |
90
|
0
|
|
|
|
|
|
$WWW::SMS::Error = "Failed at step $_ of module Libero.pm\n"; |
91
|
0
|
|
|
|
|
|
return 0; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# |
95
|
|
|
|
|
|
|
# Operations to send the SMS message. |
96
|
|
|
|
|
|
|
# |
97
|
|
|
|
|
|
|
sub _send { |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
1
|
|
7
|
use HTTP::Request::Common qw(GET POST); # the base LWP stuff |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
68
|
|
100
|
1
|
|
|
1
|
|
6
|
use LWP::UserAgent; # the LWP user agent |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
101
|
1
|
|
|
1
|
|
5
|
use HTTP::Cookies; # cookie support in LWP |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
510
|
|
102
|
0
|
|
|
0
|
|
|
my $self = shift; # shift the self array |
103
|
0
|
|
|
|
|
|
my $debug = 0; # debug option |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# cut message if it's too long |
106
|
0
|
0
|
|
|
|
|
if (length($self->{smstext})>MAXLENGTH) { |
107
|
0
|
|
|
|
|
|
$self->{smstext} = substr($self->{smstext}, 0, MAXLENGTH - 1); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; # create user agent object |
111
|
0
|
|
|
|
|
|
$ua->agent('Mozilla/5.0'); # user agent properties |
112
|
0
|
0
|
|
|
|
|
$ua->proxy('http', $self->{proxy}) if ($self->{proxy}); # proxy settings if available |
113
|
0
|
|
|
|
|
|
$ua->cookie_jar(HTTP::Cookies->new( # user agent cookie settings |
114
|
|
|
|
|
|
|
file => $self->{cookie_jar}, # saves to lwpcookies.txt |
115
|
|
|
|
|
|
|
autosave => 1 # save automaticly |
116
|
|
|
|
|
|
|
) |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# |
120
|
|
|
|
|
|
|
# STEP 1 |
121
|
|
|
|
|
|
|
# |
122
|
|
|
|
|
|
|
# Let's authenticate and login, cookies are optional, sessions are serverside. |
123
|
|
|
|
|
|
|
# |
124
|
0
|
|
|
|
|
|
my $step = 1; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
$req = POST 'http://windeureka.libero.it/sms/inviosms.php', |
127
|
|
|
|
|
|
|
[ |
128
|
|
|
|
|
|
|
telefono => '', |
129
|
|
|
|
|
|
|
PrefissoBox => '', |
130
|
|
|
|
|
|
|
telefonoBox => '', |
131
|
|
|
|
|
|
|
Testo => '', |
132
|
|
|
|
|
|
|
tipo => '', |
133
|
|
|
|
|
|
|
username => $self->{username}, |
134
|
|
|
|
|
|
|
pwd => $self->{passwd}, |
135
|
|
|
|
|
|
|
dominio => 'libero', |
136
|
|
|
|
|
|
|
Act_Login => '' |
137
|
|
|
|
|
|
|
]; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
$file = $ua->request($req)->as_string; |
140
|
|
|
|
|
|
|
|
141
|
0
|
0
|
|
|
|
|
if ($debug) { |
142
|
0
|
|
|
|
|
|
print "\n\n#####################\n"; |
143
|
0
|
|
|
|
|
|
print "# DEBUG FOR STEP: $step #\n"; |
144
|
0
|
|
|
|
|
|
print "#####################\n\n"; |
145
|
0
|
|
|
|
|
|
print $file; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
0
|
0
|
|
|
|
|
return &hnd_error($debug ? "$step ($file)" : $step) |
|
|
0
|
|
|
|
|
|
149
|
|
|
|
|
|
|
unless $file =~ /COMPONI IL MESSAGGIO/; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# |
152
|
|
|
|
|
|
|
# STEP 2 |
153
|
|
|
|
|
|
|
# |
154
|
|
|
|
|
|
|
# Now let's send the SMS message, folks. Here wo go, woheeeee! |
155
|
|
|
|
|
|
|
# |
156
|
0
|
|
|
|
|
|
$step++; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
$req = POST 'http://windeureka.libero.it/sms/inviasms.php', |
159
|
|
|
|
|
|
|
[ |
160
|
|
|
|
|
|
|
telefono => $self->{prefix} . $self->{telnum}, |
161
|
|
|
|
|
|
|
Testo => $self->{smstext}, |
162
|
|
|
|
|
|
|
Counter => 92, |
163
|
|
|
|
|
|
|
tipo => 'immediato', |
164
|
|
|
|
|
|
|
ore => '', |
165
|
|
|
|
|
|
|
minuti => '', |
166
|
|
|
|
|
|
|
giorno => '' |
167
|
|
|
|
|
|
|
]; |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
$file = $ua->simple_request($req)->as_string; |
170
|
|
|
|
|
|
|
|
171
|
0
|
0
|
|
|
|
|
if ($debug) { |
172
|
0
|
|
|
|
|
|
print "\n\n#####################\n"; |
173
|
0
|
|
|
|
|
|
print "# DEBUG FOR STEP: $step #\n"; |
174
|
0
|
|
|
|
|
|
print "#####################\n\n"; |
175
|
0
|
|
|
|
|
|
print $file; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
0
|
0
|
|
|
|
|
return &hnd_error($debug ? "$step ($file)" : $step) |
|
|
0
|
|
|
|
|
|
179
|
|
|
|
|
|
|
unless $file =~ /SMS inviati correttamente/; |
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
1; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |