#!/usr/bin/perl # Do what thou wilt shall be the whole of the law (MIT license :)) use HTTP::Cookies; use LWP; $ua = LWP::UserAgent->new; my $req; my $res; $read_err= "Could not open config file!\n\nPlease save your login details in a file named .config\ncontained in the same directory as the script\n\nPut your meteor number on the 2nd line, and your pin on the 4th\n\nError occured at"; $pbook_err= "Error opening phone book\nSave a file called .aliases in the same directory as the script\nError"; $conf_file=".config"; $aliases_file=".aliases"; $argcnt = $#ARGV + 1; if ($argcnt != 1) { print "\nUsage: Type meteor 08xxxxxxxx to send a message to the number 08xxxxxxxx\n"; exit 0; } $recipient=$ARGV[0]; open(DAT, $conf_file) || die("$read_err"); @raw_data=; close(DAT); open(PBOOK, $aliases_file) || die("$pbook_err"); @add_data=; close(PBOOK); $i=0; foreach $dataline (@add_data) { chop($dataline); if ($add_data[$i-1] eq $ARGV[0]) #if one of the lines matches the arg { if ($ARGV[0]==/^-?\d+$/) #if arg isnt an int { print "\nFound name --$ARGV[0]--\n"; $recipient = $dataline; } $exi = 1;#means we found a match } $i=($i+1); } if ($exi!=1)#if we didnt find a match { print "\nCould not find --$ARGV[0]--\n"; if ($ARGV[0]==/^-?\d+$/) {exit 0;} #if we didnt find a match and the arg is a string,we #cannot send the message, quit print "\nWould you like to save this number? Type yes to save number:\n"; $choice = ; chomp($choice); if ($choice eq 'yes') { print "Type name:\n"; $name = ; open FH, ">> $aliases_file" or die ("$read_err"); print FH "\n"; print FH $name; print FH $ARGV[0]; } } $i = 0; foreach $dataline (@raw_data) { $i=($i+1); chop($dataline); if ($i==2){ $mobno= $dataline; } if ($i==4){ $pinno= $dataline; } } print "\nType message, press return when finished:\n"; $message = ; # Order: URL, form method, parameters, regular expression to match so we know we're on the right page, # reference to function that handles this result, ref to function that handles it if expression doesn't match @url = ( # Page is for logging in ['https://www.mymeteor.ie/mymeteor/process_login.cfm', "POST", 'username=' . $mobno . '&userpass=' . $pinno . '&dologin=1&returnTo=/mymeteor/login.cfm', "stat=success", \&callback_login, \&callback_loginfailed, ], # Page is for getting SMS info (free texts left) ['https://www.mymeteor.ie/mymeteor/system/view/sms.cfm', "GET", "", 'Free web texts left .*Group web texts left new( file => "$ENV{'HOME'}/lwp_cookies.dat", autosave => 1); $ua->cookie_jar($cookie_jar); print "Attempting login...\n"; HTTPrequest->(@url[0]); print "Attempting to get SMS page...\n"; HTTPrequest->(@url[1]); print "Adding recipient..."; HTTPrequest->(@url[2]); print "Sending text..."; HTTPrequest->(@url[3]); ###################################################### # Begin subroutine handlers # #################################################### sub callback_login { print "\nLogged in successfully...\n"; } sub callback_loginfailed { # Meteor gives captcha page sometimes if($res->as_string =~ m/(login\.cfm\?stat=req.*\n)/) { print STDERR "\nGot CAPTCHA page from meteor, can't login with this account right now\n"; exit 0; } if($res->as_string !~ m/stat=stui/) { print STDERR "\nERROR: Epic Fail while trying to log in, didn't receive either login failed, login succeeded or CAPTCHA page\n"; exit 0; } print STDERR "\nERROR: Login failed - incorrect username or password\n"; exit 0; } sub callback_smsinfo { print "\nFree web texts left: " . $1 . ", Group web texts left: " . $2 . "\n"; if ($1 == 0) { print "\nNo free web texts left. This program does not support group texts.\n"; } } sub callback_smsinfofailed { print STDERR "\nERROR: Could not get SMS info page\n"; exit 0; } sub callback_addrecipient { print "\nSuccessfully added receipient...\n"; } sub callback_addrecipientfailed { print "\nERROR: Could not add recipient\n"; exit 0; } sub callback_sent { print "\nMessage sent.\n"; } sub callback_sentfailed { print "\nERROR: Message sending failed\n"; } ##################################################### # Unlikely you will have to make changes beyond this point # ################################################### sub HTTPrequest { # Log in to meteor $req = HTTP::Request->new($_[0][1], $_[0][0]); if($login[1] == "POST") { $req->content_type('application/x-www-form-urlencoded'); } $req->content($_[0][2]); $res = $ua->request($req); $cookie_jar->extract_cookies($res); # Enable to dump HTTP data # print $req->as_string . "\n\n"; # print $res->as_string; # Check if it worked if($res->as_string !~ m/$_[0][3]/s) { $_[0][5]->(); } else { $_[0][4]->(); } }