Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Perl and Javascript

by mattdeans (Novice)
on Sep 27, 2011 at 06:23 UTC ( #928017=perlquestion: print w/replies, xml ) Need Help??
mattdeans has asked for the wisdom of the Perl Monks concerning the following question:


I'm using perl to auto login a website(not public). I use firebug in Firefox to capture the login process:
1. post user=&pwd= to a fixed url.
2. this post return a javascript code. Some random stuff:
and sso.gen is defined in a single js file,almost 20K (cannot post here).
In this complex single js file, ----cannot fully understand.
Yet I see it use the RANDOM_STUFF and something in cookie, to generate a random url with some random params, and set cookies.
3. GET this new rand url. ( looks like request by javascript, within the js file )
I tried LWP::UserAgent and JE . It seems not possible...
so how could I auto login this website with perl? Any advice? Any other options?


Replies are listed 'Best First'.
Re: Perl and Javascript
by Corion (Pope) on Sep 27, 2011 at 06:48 UTC

    Have you looked at WWW::Mechanize::Firefox? If you cannot reverse engineer what sso.gen does, you will have to use a Javascript interpreter.

      It seems WWW::Mechanize::Firefox need firefox install? I cannot, its a server.
      Is JE - Pure-Perl ECMAScript (JavaScript) Engine a Javascript interpreter?

        If it is a server, then yes, you will have to make-do with the other solutions (Javascript). I'm currently working on getting nodejs to do the same as WWW::Mechanize::Firefox does, except without the need for a display, but that is still very much a work in progress, so I recommend you look at the other methods.

        Alternatively, you could write a small Javascript wrapper for your sso.gen script and call it via node sso.gen-wrapper.js $ARG1 $ARG2 via backticks.

Re: Perl and Javascript
by technojosh (Priest) on Sep 28, 2011 at 17:02 UTC
    With a little more info about the REQUEST/RESPONSE sequences, I think I can help. Your post is kind of unclear... (How do I post a question effectively?)

    1. use WWW::Mechanize (no need for Firefox specifics, I don't think. Its ok to use Firebug to "discover" how to automate a process, but it doesnt' really tie you to firefox after that point)
    2. you seem to indicate you are able to pull the new, random URL you need from sso.gen??

    *If* #2 is true, or at least close to reality, you should be able to parse that random URL and load it through a second GET request (I think that is what you are asking for in #3??)

    If #2 is not true, then I think that will be your focus. If you get sso.gen successfully, are you able to successfully parse this random URL from the javascript? the "GET" method returns a HTTP::Response object, can you learn anything from that?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://928017]
Approved by moritz
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2016-09-27 02:33 GMT
Find Nodes?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:

    Results (493 votes). Check out past polls.