#!/usr/bin/perl -w ### Sidekick::Login v0.3.1 ### ### Copyright 2002 Leigh L. Klotz Jr. ### Permission is hereby granted, free of charge, to any person obtaining ### a copy of this software and associated documentation files (the ### "Software"), to deal in the Software without restriction, including ### without limitation the rights to use, copy, modify, merge, publish, ### distribute, sublicense, and/or sell copies of the Software, and to ### permit persons to whom the Software is furnished to do so, subject to ### the following conditions: ### ### The above copyright notice and this permission notice shall be ### included in all copies or substantial portions of the Software. ### ### THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ### EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ### MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ### NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE ### LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION ### OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION ### WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package Sidekick::Login; use LWP::UserAgent; use LWP::Protocol::https; use HTTP::Cookies; use HTTP::Request::Common; sub new($$) { my $type = shift; my %params = @_; my $self = {}; $self->{'username'} = $params{'username'}; $self->{'password'} = $params{'password'}; $self->{'phone'} = $params{'phone'}; $self->{'cookiedir'} = $params{'cookiedir'} || $ENV{'HOME'}; $self->{'cookiesfile'} = $self->{'cookiedir'} . "/" . $params{'username'} . ".cookies"; $self->{'error'} = ""; bless $self, $type; if (! -f $self->{'cookiesfile'}) { $self->login(); } else { $self->{'cookies'} = HTTP::Cookies->new(file => $self->{'cookiesfile'}, ignore_discard => 1, autosave => 1); } return $self; } sub login() { my $self = shift; my $username = $self->{'username'} || ""; my $phone = $self->{'phone'} || ""; # Make sure the cookie jar file is readable only to group and owner # since it is usually shared between a web server and a user # procmail. { my $old_umask = umask; umask 007; $self->{'cookies'} = HTTP::Cookies->new(file => $self->{'cookiesfile'}, ignore_discard => 1, autosave => 1); umask $old_umask; } # Create a user agent object my $ua = LWP::UserAgent->new; $ua->agent("Sidekick::Login/0.3 "); $ua->cookie_jar($self->{'cookies'}); { # Create a request # Create a request my $req = POST 'https://wipcore.t-mobile.com/login', [ "txtMSISDN" => $phone, "hdnAOL" => "", "tmobile" => "true" , "txtPassword" => $self->{'password'}, "txtUserName" => $username, "chkRemember" => "chkRemember" ]; # Pass request to the user agent and get a response back print STDERR __LINE__, " POST https://wipcore.t-mobile.com/login $username\n"; my $res = $ua->request($req); # Check the outcome of the response print STDERR __LINE__, " ", $res->status_line, "\n"; if ($res->is_redirect) { print STDERR __LINE__, " Redirect to ", $res->header('Location'), "\n"; if ($res->header('Location') =~ m/login=BadPass/) { $self->{'error'} = "bad password"; return $self; } } if ($res->is_error) { print STDERR __LINE__, " Error: ", $res->status_line, " ", $res; $self->{'error'} = "Error: " . $res->status_line; return $self; } } { my $req = HTTP::Request->new(GET => 'https://www.t-mobile.com/mytmobile/sidekick/dngrjmp.asp'); # Pass request to the user agent and get a response back print STDERR __LINE__, " GET https://www.t-mobile.com/mytmobile/sidekick/dngrjmp.asp\n"; my $res = $ua->request($req); # Check the outcome of the response print STDERR __LINE__, " ", $res->status_line, "\n"; if ($res->is_redirect) { print STDERR __LINE__, " Redirect to ", $res->header('Location'), "\n"; if ($res->header('Location') =~ m/login=BadPass/) { $self->{'error'} = "bad password"; return $self; } } if ($res->is_error) { print STDERR __LINE__, "Error: ", $res->status_line, " ", $res; $self->{'error'} = "Error: " . $res->status_line; return $self; } } return $self; } sub geterror() { my $self = shift; return $self->{'error'}; } sub cookies { my $self = shift; return $self->{'cookies'}; } #package main; #use Login; # First Time #my $cookies = Login->new( 'username' => $username, 'password' => $password); # From then on, do this to get the cookies: #my $auth = Login->new()->cookies; # If you want to change your username or password: #my $cookies = Login->new( 'username' => $username, 'password' => $password)->login() # You can use 'phone' instead of 'username' 1;