1

My friend wrote a script, which uses ruby's mechanize to get a cookie off a page after login.

  • start mechanize
  • go through login
  • get cookie value from page delivered by form

The script seems to work for him, but doesn't for me. I've tried doing this interactively and I noticed I get a different page title returned from Mechanize than the one for my browser. When I log in, the page title is "SSL VPN - Home", but when I look at the title attribute on my returned submission object I get "Please wait..."

irb(main):084:0> intermediate.title
=> "Please wait..."
irb(main):085:0> intermediate.iframes
=> [#<Mechanize::Page::Frame nil "/dana-na/html/blank.html">

Is Mechanize possibly not waiting long enough to get the destination page? The "Please wait..." seems to hint at some intermediate page that gets refreshed or redirected that the Mechanize session isn't getting to. Either way I don't get the same title value.

=> #<Mechanize::Page
 {url
  #<URI::HTTPS:0x00000002b49338 URL:https://vpn1.example.com/dana/home/starter0.cgi?check=yes>}
 {meta_refresh}
 {title "Please wait..."}
 {iframes #<Mechanize::Page::Frame nil "/dana-na/html/blank.html">}
 {frames}
 {links}
 {forms
  #<Mechanize::Form
   {name "frmGrab"}
   {method "POST"}
   {action "/dana/home/starter0.cgi"}
   {fields
    [hidden:0x15b9860 type: hidden name: xsauth value: a0395604a9f4f531504a7f6b6dc86051]
    [hidden:0x15b94a0 type: hidden name: tz_offset value: ]
    [hidden:0x15b92e8 type: hidden name: clienttime value: ]
    [hidden:0x15b8ff0 type: hidden name: url value: ]
    [hidden:0x15b8ac8 type: hidden name: activex_enabled value: 0]
    [hidden:0x15b8898 type: hidden name: java_enabled value: 0]
    [hidden:0x15b8690 type: hidden name: power_user value: 0]
    [hidden:0x15b84ec type: hidden name: grab value: 1]
    [hidden:0x15b8348 type: hidden name: browserproxy value: ]
    [hidden:0x15b8168 type: hidden name: browsertype value: ]
    [hidden:0x15b7fb0 type: hidden name: browserproxysettings value: ]
    [hidden:0x15b7df8 type: hidden name: check value: yes]
    [hidden:0x15b7c54 type: hidden name: nextpage value: ]
    [hidden:0x15bb8f4 type: hidden name: mid value: ]
    [hidden:0x15bb5d4 type: hidden name: signin value: ]
    [hidden:0x15bb2dc type: hidden name: alias value: ]
    [hidden:0x15bb05c type: hidden name: id value: ]
    [hidden:0x15baeb8 type: hidden name: username value: ]
    [hidden:0x15bacb0 type: hidden name: password value: ]
    [hidden:0x15bab20 type: hidden name: occurrence value: ]}
   {radiobuttons}
   {checkboxes}
   {file_uploads}
   {buttons}>}>
voodoogiant
  • 2,118
  • 6
  • 29
  • 49

2 Answers2

0

It's giving you another login form so my guess is the first login didn't work for some reason.

pguardiario
  • 53,827
  • 19
  • 119
  • 159
0

I have no idea why this works for your friend and not for you... from the output you posted it does seem like it generally wouldn't work.

Based on the URL, it appears the page you're attempting to access is a login page for a Juniper Networks based VPN appliance/server and I know that the login pages for those things redirect you all over the place :/

Anyways, based on your output the page returned by Mechanize has a {meta_refresh} and by default mechanize does not automatically follow meta refreshes. It's possible mechanize isn't taking too long but has just stopped after getting a response.

You can have Mechanize follow the {meta_refresh} two different ways... Here's some fake code; sorry in advance if the variables do not match your actual code.

Manually (docs):

agent = Mechanize.new
intermediate = agent.get('http://your_url')
intermediate = intermediate.meta_refresh.first.click # Manually click the meta-refresh

Automatically (docs):

agent = Mechanize.new
# All requests made using this agent will follow meta refreshes automatically
agent.follow_meta_refresh = true 
intermediate = agent.get('http://your_url')

If this were my code, I'd probably do things manually unless Juniper does this on a lot of the pages you have to access after getting logged in... which would be lame. :)

Mario Zigliotto
  • 8,315
  • 7
  • 52
  • 71