File Coverage

blib/lib/WWW/SMS/Gomobile.pm
Criterion Covered Total %
statement 12 42 28.5
branch 0 12 0.0
condition 0 9 0.0
subroutine 4 6 66.6
pod 0 1 0.0
total 16 70 22.8


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2             # option -w == warnings ON
3              
4             # CVS related code
5             # $Id: Gomobile.pm,v 1.5 2002/12/28 17:32:17 eim Exp $
6              
7             #############################################################################
8             # #
9             # IMPORTANT NOTE #
10             # #
11             # !!! THE AUTHOR IS ==NOT== RESPONSIBLE FOR ANY USE OF THIS PROGRAM !!! #
12             # #
13             # GPL LICENSE #
14             # #
15             # This program is free software; you can redistribute it and/or modify #
16             # it under the terms of the GNU General Public License as published by #
17             # the Free Software Foundation; either version 2 of the License, or #
18             # (at your option) any later version. #
19             # #
20             # This program is distributed in the hope that it will be useful, #
21             # but WITHOUT ANY WARRANTY; without even the implied warranty of #
22             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
23             # GNU General Public License for more details. #
24             # #
25             # You should have received a copy of the GNU General Public License #
26             # along with this program; if not, write to the Free Software #
27             # Foundation, Inc., 59 Temple Place, Suite 330, Boston, #
28             # MA 02111-1307 USA #
29             # #
30             #############################################################################
31              
32              
33             #////////////////////////////////////////#
34             # A B O U T T H I S P A C K A G E #
35             #////////////////////////////////////////#
36              
37             # This is a module for www.gomobile.ch you must have a valid user account
38             # at www.gomobile.ch which will provide you with login and password.
39              
40             # You can get a free user account on the www.gomobile.ch website,
41             # furthermore you'll be able to send SMS all over the world without
42             # per day SMS limits, I would say this is quite cool.
43              
44             # Note that $debug=1 will print out all the HTML source code of the portal
45             # the best thing you can do is to redirect the debugging output to a file.
46              
47             # Doc note: The Perl LWP (libwww-perl) documentation is avaiable in your
48             # local perldoc repository, see: % perldoc lwpcook it's always usefull.
49              
50             # This packages was written by: Ivo Mario
51             # and was last modified: $Date: 2002/12/28 17:32:17 $
52              
53              
54             #////////////////////////////////////////#
55             # L I B S A N D C O N F I G S #
56             #////////////////////////////////////////#
57              
58             # name of this package
59             package WWW::SMS::Gomobile;
60              
61             # other modules we need
62 1     1   496 use Telephone::Number;
  1         2  
  1         146  
63             require Exporter;
64              
65             # definitions
66             @ISA = qw(Exporter);
67             @EXPORT = qw();
68             @EXPORT_OK = qw(@PREFIXES _send MAXLENGTH);
69             @PREFIXES = (Telephone::Number->new('43', [ qw(676 650 699 664) ], undef));
70             $VERSION = '1.00'; # package version
71              
72              
73             #////////////////////////////////////////#
74             # S U B R O U T I N E S #
75             #////////////////////////////////////////#
76              
77             # subroutine to define max message length
78             sub MAXLENGTH () {500}
79              
80              
81             # subroutine to handle errors
82             sub hnd_error {
83 0     0 0   $_ = shift;
84 0           $WWW::SMS::Error = "Failed at step $_ of module Gomobile.pm\n";
85 0           return 0;
86             }
87              
88              
89             # subroutine to send SMS
90             sub _send {
91              
92             # external libraries
93 1     1   4 use HTTP::Request::Common qw(GET POST);
  1         2  
  1         57  
94 1     1   4 use LWP::UserAgent; # the LWP user agent
  1         2  
  1         24  
95 1     1   5 use HTTP::Cookies; # cookie support in LWP
  1         20  
  1         499  
96              
97             # private vars
98 0     0     my $self = shift; # no idea actually
99 0           my $debug = 0; # enable debug
100            
101             # check if message is too long
102 0 0         if (length($self->{smstext})>MAXLENGTH) {
103            
104             # cut the message
105 0           $self->{smstext} = substr($self->{smstext}, 0, MAXLENGTH - 1);
106             }
107              
108             # create user agent object
109 0           my $ua = LWP::UserAgent->new;
110              
111             # user agent properties
112 0           $ua->agent('Mozilla/5.0');
113 0 0         $ua->proxy('http', $self->{proxy}) if ($self->{proxy});
114              
115             # user agent cookie settings
116 0           $ua->cookie_jar(HTTP::Cookies->new(
117              
118             file => $self->{cookie_jar}, # saves to lwpcookies.txt
119             autosave => 1 # save automaticly
120             )
121             );
122              
123            
124             # =======================
125             # STEP 1
126             # Let's log on the portal
127             # =======================
128            
129 0           my $step = 1; # define the step
130            
131             # define the LWP request
132 0           my $req = POST 'http://www.gomobile.ch/Portal?cmd=procLogin',
133             [
134             Referer => 'http://www.gomobile.ch/Portal?cmd=GenHomepage',
135             Host => 'www.gomobile.ch',
136             cmd => 'procLogin',
137             userName => $self->{username},
138             password => $self->{passwd}
139             ];
140            
141              
142             # execute the LWP request
143 0           my $file = $ua->request($req)->as_string;
144              
145             # if we are in debugging mode
146 0 0         if ($debug) {
147              
148 0           print "\n\n#####################\n"; # print debug title
149 0           print "# DEBUG FOR STEP: $step #\n"; # print debug title
150 0           print "#####################\n\n"; # print debug title
151 0           print $file; # print debug infos
152             }
153              
154             # check if we arrived on the everyday startpage
155             # if not so, well... report an error and exit !
156             # return &hnd_error($debug ? "$step ($file)" : $step)
157             # unless $file =~ m{ no-checks-here }i;
158              
159              
160             # ==================================================
161             # STEP 2
162             # Ok folks, lets send out the SMS, it quite rox, yes
163             # ==================================================
164              
165 0           $step++; # increment to next step
166              
167             # define the LWP request
168 0           $req = POST 'http://www.gomobile.ch/Portal',
169             [
170             Host => 'www.movilnets.net',
171             Referer => 'http://www.gomobile.ch/Portal?cmd=startFreeSMS',
172             cmd => 'procGenSendFreeSMS',
173             abbreviations => '',
174             contacts => '',
175             abbreviationPage => 1,
176             address => '00' . $self->{intpref} . $self->{prefix} . $self->{telnum},
177             abbreviation => 'Goodbye+for+ever%2C+boss%21+Just+won+the+lottery.',
178             smstext => $self->{smstext},
179             nSMS => 1,
180             emoticonSelection => '%3A%29',
181             smil=> ''
182             ];
183              
184             # execute the LWP request
185 0           $file = $ua->request($req)->as_string;
186              
187             # if we are in debugging mode
188 0 0         if ($debug) {
189              
190 0           print "\n\n#####################\n"; # print debug title
191 0           print "# DEBUG FOR STEP: $step #\n"; # print debug title
192 0           print "#####################\n\n"; # print debug title
193 0           print $file; # print debug infos
194             }
195              
196             # check if the message was sent successfully if not report an error and exit.
197 0 0 0       return &hnd_error($debug ? "$step ($file)" : $step)
    0 0        
      0        
198             unless (
199             $file =~ /Your text message has been successfully sent to/
200             || $file =~ /Ihre Nachricht wurde erfolgreich gesendet an/
201             || $file =~ /stato trasmesso con successo a/
202             || $file =~ /avec succ/
203             );
204            
205             # clear the cookie
206 0           $ua->cookie_jar->clear('www.gomobile.ch');
207              
208 0           1;
209             }
210              
211             1;