#!/usr/bin/perl # # PLEASE NOTE: THIS IS OUTDATED!! # # SEE http://www.slacky.de/docs/projects/o2-sms.html # AND http://www.slacky.de/files/gnu-projects/o2-sms.pl # # (lf, 16.05.2004) # ########################################################################## # # # Send SMS via Genion WWW Gateway (O 2 Only!) # # # # invoke syntax: sms.pl 01791234567 "message ... message ... and so on" # # # ########################################################################## # --------------- used modules use strict; use URI::Escape; use LWP::UserAgent; use HTTP::Request::Common; use HTTP::Cookies; # --------------- settings my $url_base = "http://web2sms.genion.de/"; my $url_startpage = $url_base . "eingabe.asp"; my $url_agbpage = $url_base . "agbs.asp"; my $url_sendpage = $url_base . "process.asp"; my $debug = 0; # --------------- fake these user agents via rand() call my %agents = ( 0 => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)', 1 => 'Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)', 2 => 'Mozilla/5.0 Galeon/1.2.5 (X11; Linux i686; U;) Gecko/20020606', 3 => 'Mozilla/4.0 (compatible; MSIE 5.0; Windows 2000) Opera 6.04 [en]', 4 => 'Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90)', 5 => 'Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; DT)', 6 => 'Mozilla 4.0 (compatible; MSIE 5.01; Windows NT 5.0)', 7 => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)', 8 => 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0; LVR)', 9 => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)', 10 => 'Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.1b) Gecko/20020722' ); # --------------- collect needed information from command line input die ("No number and/or no message text") if ($#ARGV != 1); my $prefix = "49" . substr ($ARGV[0], 1, 3); my $number = substr ($ARGV[0], 4, 8); shift(@ARGV); my $messagetext = join (" ", @ARGV); $messagetext =~ s/ /+/g; my $num = length ($messagetext); $messagetext = uri_escape (uri_escape ($messagetext, "^A-Za-z0-9")); $messagetext =~ s/%252B/%2B/g; # --------------- some initial error handling: check input values die ("Number is too short/too long") if ((length ($number) < 7) || (length ($number) > 8)); die ("Message text is too long: $num") if ($num > 120); # --------------- set up a new user agent object and save cookies between requests my $ua = new LWP::UserAgent; # --------------- fake a real user agent my $max = -1; $max++ foreach (keys %agents); $ua->agent ($agents{int (rand ($max))}); # --------------- enable cookie transport my $cookies = new HTTP::Cookies; $ua->cookie_jar ($cookies); # --------------- fetch start page to receive appropriate cookie there print "Requesting " . $url_startpage . "...\n" if ($debug); my $response = $ua->request (GET $url_startpage); # --------------- post data to AGB page my $req = new HTTP::Request POST => $url_agbpage; $req->content_type ('application/x-www-form-urlencoded'); $req->referer ($url_startpage); $req->content ("http_referrer=&BannerMode=&prefix=" . $prefix . "&msisdn=" . $number . "&messagetext=" . $messagetext . "&num=" . $num . "&Anzahl=160&image1_x=" . int (rand (52)) . "&image1_y=" . int (rand (13))); print "Requesting " . $url_agbpage . "...\n" if ($debug); $response = $ua->request ($req); die ("Error requesting " . $url_agbpage) if (!$response->is_success); # -------------- now proceed to send page $req = new HTTP::Request POST => $url_sendpage; $req->content_type ('application/x-www-form-urlencoded'); $req->referer ($url_agbpage); $req->content ("BannerMode=&MSISDN=" . $prefix . $number . "&MessageText=" . $messagetext . "&akzeptieren_x=" . int (rand (139)) . "&akzeptieren_y=" . int (rand (13))); print "Requesting " . $url_sendpage . "...\n" if ($debug); $response = $ua->request ($req); # -------------- our message is being sent, accept redirection (to senden.asp) print "Redirecting to " . $url_base . $response->header ('location') . "...\n" if ($debug); $response = $ua->request (GET $url_base . $response->header ('location')); # -------------- emulate meta-tag redirection my @lines = split /\n/, $response->content(); foreach (@lines) { if (/.*http-equiv.*refresh.*/i) { chomp $_; $_ =~ s/.*content=\"(.*)\">/$1/g; my ($r_delay, $r_url) = split /;/, $_; $r_url =~ s/^url=//g; print "Meta-Redirecting to " . $url_base . $r_url . " in " . $r_delay . " seconds...\n" if ($debug); sleep $r_delay; $ua->request (GET $url_base . $r_url); } } print "Done.\n\n" if ($debug);