| 1 | #!/usr/bin/perl -w | ||||||||||||||
| 2 | |||||||||||||||
| 3 | # $Id: Omnitel.pm,v 1.1 2003/03/21 00:10:44 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 Omnitel SMS gateway | ||||||||||||||
| 34 | # available over at http://www.omnitel.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 | # OMNITEL | ||||||||||||||
| 42 | # 340, 347, 348, 349 | ||||||||||||||
| 43 | # | ||||||||||||||
| 44 | # The maximal length of each message is 1200 chars, this is quite cool. | ||||||||||||||
| 45 | # | ||||||||||||||
| 46 | # Note that $debug=1 will print out all the HTML source code of the portal | ||||||||||||||
| 47 | # the best thing you can do is to redirect the debugging output to a file. | ||||||||||||||
| 48 | # | ||||||||||||||
| 49 | # Doc note: The Perl LWP (libwww-perl) documentation is avaiable in your | ||||||||||||||
| 50 | # local perldoc repository, see: % perldoc lwpcook it's always usefull. | ||||||||||||||
| 51 | # | ||||||||||||||
| 52 | # This packages was written by: Ivo Mario <eim@users.sourceforge.net> | ||||||||||||||
| 53 | # and was last modified: $Date: 2003/03/21 00:10:44 $ | ||||||||||||||
| 54 | # | ||||||||||||||
| 55 | |||||||||||||||
| 56 | |||||||||||||||
| 57 | # | ||||||||||||||
| 58 | # LIBS AND CONFIGS | ||||||||||||||
| 59 | # | ||||||||||||||
| 60 | |||||||||||||||
| 61 | package WWW::SMS::Omnitel; | ||||||||||||||
| 62 | 1 | ▶ | use Telephone::Number; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 63 | 1 | require Exporter; | |||||||||||||
| 64 | |||||||||||||||
| 65 | 1 | $VERSION = '1.00'; | |||||||||||||
| 66 | 1 | @ISA = qw(Exporter); | |||||||||||||
| 67 | 1 | @EXPORT = qw(); | |||||||||||||
| 68 | 1 | @EXPORT_OK = qw(@PREFIXES _send MAXLENGTH); | |||||||||||||
| 69 | 1 | @PREFIXES = (Telephone::Number->new('39', [ | |||||||||||||
| 70 | qw(340 347 348 349) | ||||||||||||||
| 71 | ], undef) | ||||||||||||||
| 72 | ); | ||||||||||||||
| 73 | |||||||||||||||
| 74 | |||||||||||||||
| 75 | # | ||||||||||||||
| 76 | # SUBROUTINES | ||||||||||||||
| 77 | # | ||||||||||||||
| 78 | |||||||||||||||
| 79 | # | ||||||||||||||
| 80 | # Message max length defintion. | ||||||||||||||
| 81 | # | ||||||||||||||
| 82 | sub MAXLENGTH () {1200} | ||||||||||||||
| 83 | |||||||||||||||
| 84 | # | ||||||||||||||
| 85 | # Error handling functions. | ||||||||||||||
| 86 | # | ||||||||||||||
| 87 | 0 | ▶ | sub hnd_error { | ||||||||||||
|
Subroutine
hnd_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 88 | 0 | $_ = shift; | |||||||||||||
| 89 | 0 | $WWW::SMS::Error = "Failed at step $_ of module Omnitel.pm\n"; | |||||||||||||
| 90 | 0 | return 0; | |||||||||||||
| 91 | } | ||||||||||||||
| 92 | |||||||||||||||
| 93 | # | ||||||||||||||
| 94 | # Operations to send the SMS message. | ||||||||||||||
| 95 | # | ||||||||||||||
| 96 | 0 | ▶ | sub _send { | ||||||||||||
|
Subroutine
_send: not called CC=9 SCAR=40.0
| |||||||||||||||
| 97 | |||||||||||||||
| 98 | 1 | ▶ | use HTTP::Request::Common qw(GET POST); # the base LWP stuff | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 99 | 1 | ▶ | use LWP::UserAgent; # the LWP user agent | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 100 | 1 | ▶ | use HTTP::Cookies; # cookie support in LWP | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 101 | 0 | my $self = shift; # shift the self array | |||||||||||||
| 102 | 0 | my $debug = 0; # debug option | |||||||||||||
| 103 | |||||||||||||||
| 104 | # cut message if it's too long | ||||||||||||||
| 105 | 0 | ▶ | if (length($self->{smstext})>MAXLENGTH) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 106 | 0 | $self->{smstext} = substr($self->{smstext}, 0, MAXLENGTH - 1); | |||||||||||||
| 107 | } | ||||||||||||||
| 108 | |||||||||||||||
| 109 | 0 | my $ua = LWP::UserAgent->new; # create user agent object | |||||||||||||
| 110 | 0 | $ua->agent('Mozilla/5.0'); # user agent properties | |||||||||||||
| 111 | 0 | ▶ | $ua->proxy('http', $self->{proxy}) if ($self->{proxy}); # proxy settings if available | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 112 | $ua->cookie_jar(HTTP::Cookies->new( # user agent cookie settings | ||||||||||||||
| 113 | file => $self->{cookie_jar}, # saves to lwpcookies.txt | ||||||||||||||
| 114 | 0 | autosave => 1 # save automaticly | |||||||||||||
| 115 | ) | ||||||||||||||
| 116 | ); | ||||||||||||||
| 117 | |||||||||||||||
| 118 | # | ||||||||||||||
| 119 | # STEP 1 | ||||||||||||||
| 120 | # | ||||||||||||||
| 121 | # Let's authenticate and login, cookies are optional, sessions are serverside. | ||||||||||||||
| 122 | # | ||||||||||||||
| 123 | 0 | my $step = 1; | |||||||||||||
| 124 | |||||||||||||||
| 125 | $req = POST 'http://www.areaprivati.190.it/_mem_bin/verifpwd.asp', | ||||||||||||||
| 126 | [ | ||||||||||||||
| 127 | ApriPopUp => '0', | ||||||||||||||
| 128 | username => $self->{username}, | ||||||||||||||
| 129 | password => $self->{passwd}, | ||||||||||||||
| 130 | 0 | URL => '', | |||||||||||||
| 131 | HomePage => 'NO', | ||||||||||||||
| 132 | '19A' => 'YES' | ||||||||||||||
| 133 | ]; | ||||||||||||||
| 134 | |||||||||||||||
| 135 | 0 | $file = $ua->request($req)->as_string; | |||||||||||||
| 136 | |||||||||||||||
| 137 | 0 | ▶ | if ($debug) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 138 | 0 | print "\n\n#####################\n"; | |||||||||||||
| 139 | 0 | print "# DEBUG FOR STEP: $step #\n"; | |||||||||||||
| 140 | 0 | print "#####################\n\n"; | |||||||||||||
| 141 | 0 | print $file; | |||||||||||||
| 142 | } | ||||||||||||||
| 143 | |||||||||||||||
| 144 | 0 | ▶ | return &hnd_error($debug ? "$step ($file)" : $step) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 145 | unless $file =~ /exch.vodafoneomnitel.it/; | ||||||||||||||
| 146 | |||||||||||||||
| 147 | # | ||||||||||||||
| 148 | # STEP 2 | ||||||||||||||
| 149 | # | ||||||||||||||
| 150 | # Now let's send the SMS message, folks. Here wo go, woheeeee! | ||||||||||||||
| 151 | # | ||||||||||||||
| 152 | 0 | $step++; | |||||||||||||
| 153 | |||||||||||||||
| 154 | $req = POST 'http://freesms.190.it/190personal/sms_hp_send.asp', | ||||||||||||||
| 155 | [ | ||||||||||||||
| 156 | num => $self->{prefix} . $self->{telnum}, | ||||||||||||||
| 157 | msg => $self->{smstext}, | ||||||||||||||
| 158 | 0 | Prov => 1 | |||||||||||||
| 159 | ]; | ||||||||||||||
| 160 | |||||||||||||||
| 161 | 0 | $file = $ua->simple_request($req)->as_string; | |||||||||||||
| 162 | |||||||||||||||
| 163 | 0 | ▶ | if ($debug) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 164 | 0 | print "\n\n#####################\n"; | |||||||||||||
| 165 | 0 | print "# DEBUG FOR STEP: $step #\n"; | |||||||||||||
| 166 | 0 | print "#####################\n\n"; | |||||||||||||
| 167 | 0 | print $file; | |||||||||||||
| 168 | } | ||||||||||||||
| 169 | |||||||||||||||
| 170 | 0 | ▶ | return &hnd_error($debug ? "$step ($file)" : $step) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 171 | unless $file =~ /SMS_HP_SendOk.asp\?nsms=/; | ||||||||||||||
| 172 | |||||||||||||||
| 173 | 0 | 1; | |||||||||||||
| 174 | } | ||||||||||||||
| 175 | |||||||||||||||
| 176 | 1 | 1; | |||||||||||||