Archive

Posts Tagged ‘lwp’

Login Cookie Redirect Snippet

January 27th, 2010 Comments off

Hi,

I’m having problems writing a snippet of code that I need for my remote login script. You are writing a small section of code, less then 30-40 lines. I need this done very quickly. Hopefully you can do it within 2 hours. I’m just not that familiar with cookies and the LWP module that is needed. I’m guessing if you are familiar with LWP you can accomplish this task pretty quickly.

Here is what needs to be done. I have a remote/redirect login area script that needs to login into this webmail interface located here.

http://ml6.myemail.com/surgeweb/

You can login directly to see what is supposed to happen…
username: testaccountATmyemail.com # this should be an AT sign in front of myemail, scriptlance does not allow within submission posts
pass: sunnyday

The problem that I’m having is that this interface uses cookies, and I have been unable to correctly pass them from this remote login script location.

I need to use LWP to capture the cookies from the interface during the post to this script. Then I need to print header info, cookies, and the result of the post back to the users browser.

Here is a url of someone else trying to accomplish the same task.
http://www.perlmonks.org/?node_id=456612

Here is LWP documentation.
http://www.perl.com/pub/a/2002/08/20/perlandlwp.html?page=2

If you put this URL into a browser window you can see that it works, but this will not work via a remote script unless you capture the cookies and push them back to the users browser correctly.
http://ml6.myemail.com/surgeweb?username_ex=testaccountATmyemail.com&password=sunnyday&interface_ex=ajax&cmd_login=login –replace the AT with the AT sign.

To get this to work, we may also have to add one more variable to the post…
remember=on or remember=1 or remember=true Not sure which one is YES. :-)

Here is what I have so far, but don’t know how to print it back out to the users browser. I’m not even sure what I have below is correct.

#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(GET);
use HTTP::Cookies;

my $cookie_jar = HTTP::Cookies->new;

# A variable that holds our POST request to the site

my $ua = LWP::UserAgent->new;
my $action = $ua->post( ‘http://ml6.myemail.com/surgeweb’,
[
'username_ex' => 'testaccount/ATmyemail.com', # this should be an AT sign in front of myemail, scriptlance does not allow within submission posts
'password' => 'sunnyday',
'interface_ex' => 'ajax',
'cmd_login' => 'login'
],
);

Here are the 2 cookies that should be captured and redirected within the result of the post.

SW-AUTHTOKEN
SW-I

You can write a simple demo.cgi on your server. When loaded it should just capture cookies, result of post and print to users browser and login correctly. Hopefully we can get this to work.

Good luck.

Wyatt

Categories: Perl/CGI Tags: , , , , , ,

Very Simple Perl Lwp Script

December 11th, 2009 Comments off

I need a script coded that scrapes urls in myspace like so:
myspace.com/1
myspace.com/2
myspace.com/3
myspace.com/4
myspace.com/5

it should have syntax as follows:
get.pl 1-1000 file.txt
The syntax above should go from
myspace.com/1 to myspace.com/1000 while storing all the data in file.txt

this script should collect data from the html web page and store it in this format in the defined text file:
Myspace ID—Last Login—Display Name

it should skip deleted/not found IDs not logging them.

Need someone within the next 2 hrs

can pay via paypal/wire

Bear