WWW/SMS/Gomobile.pm

filter: Statementstmt 38.7% 19 / 49 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 1 totaltotal 28.4% 23 / 81 CC 10 SCAR 38.5
CC
10
Cov
27%
_send
69.7
hnd_error
2.0
BEGIN
1.0
CRAP 46.9
« WWW/SMS/Everyday.pm ↑ Summary WWW/SMS/Libero.pm »
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 <eim@eimbox.org>
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 ▶use Telephone::Number;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 1 require Exporter;
64  
65 # definitions
66 1 @ISA = qw(Exporter);
67 1 @EXPORT = qw();
68 1 @EXPORT_OK = qw(@PREFIXES _send MAXLENGTH);
69 1 @PREFIXES = (Telephone::Number->new('43', [ qw(676 650 699 664) ], undef));
70 1 $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 0 ▶sub hnd_error {
Subroutine hnd_error: not called CC=1 SCAR=6.9
Pod undocumented
83 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 0 ▶sub _send {
Subroutine _send: not called CC=10 SCAR=42.4
91  
92 # external libraries
93 1 ▶ use HTTP::Request::Common qw(GET POST);
Subroutine BEGIN: called CC=1 SCAR=0.0
94 1 ▶ use LWP::UserAgent; # the LWP user agent
Subroutine BEGIN: called CC=1 SCAR=0.0
95 1 ▶ use HTTP::Cookies; # cookie support in LWP
Subroutine BEGIN: called CC=1 SCAR=0.0
96  
97 # private vars
98 0 my $self = shift; # no idea actually
99 0 my $debug = 0; # enable debug
100
101 # check if message is too long
102 0 ▶ if (length($self->{smstext})>MAXLENGTH) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"smstext"} > 500) 0 0 0
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 ▶ $ua->proxy('http', $self->{proxy}) if ($self->{proxy});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"proxy"} 0 0 0
114  
115 # user agent cookie settings
116 $ua->cookie_jar(HTTP::Cookies->new(
117  
118 file => $self->{cookie_jar}, # saves to lwpcookies.txt
119 0 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 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 0 ];
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 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
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 $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 0 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 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
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 ▶ return &hnd_error($debug ? "$step ($file)" : $step)
Branch: 2 branches
BranchTrueFalseTotal
unless $file =~ /Your text message has been successfully sent to/ or $file =~ /Ihre Nachricht wurde erfolgreich gesendet an/ or $file =~ /stato trasmesso con successo a/ or $file =~ /avec succ/ 0 0 0
$debug ? : 0 0 0
Condition0%0/9
$file =~ /Your text message has been successfully sent to/ or $file =~ /Ihre Nachricht wurde erfolgreich gesendet an/ or $file =~ /stato trasmesso con successo a/ or $file =~ /avec succ/
l!l&&r!l&&!r
000
$file =~ /Your text message has been successfully sent to/ or $file =~ /Ihre Nachricht wurde erfolgreich gesendet an/ or $file =~ /stato trasmesso con successo a/
l!l&&r!l&&!r
000
$file =~ /Your text message has been successfully sent to/ or $file =~ /Ihre Nachricht wurde erfolgreich gesendet an/
l!l&&r!l&&!r
000
MC/DC0%0/4
$file =~ /Your text message has been successfully sent to/ or $file =~ /Ihre Nachricht wurde erfolgreich gesendet an/ or $file =~ /stato trasmesso con successo a/ or $file =~ /avec succ/
$file =~ /Your text message has been successfully sent to/ $file =~ /Ihre Nachricht wurde erfolgreich gesendet an/ $file =~ /stato trasmesso con successo a/ $file =~ /avec succ/
Truth table0%0/5
A or B or C or D
A= $file =~ /Your text message has been successfully sent to/B= $file =~ /Ihre Nachricht wurde erfolgreich gesendet an/C= $file =~ /stato trasmesso con successo a/D= $file =~ /avec succ/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
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 1;
« WWW/SMS/Everyday.pm ↑ Summary WWW/SMS/Libero.pm »