Submitting web forms programatically

Discussion in 'OT Technology' started by 5Gen_Prelude, Jan 29, 2009.

  1. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    We have some WG firewalls that are entirely web driven and based on specific events, we want to reboot the firewall via a script. How can I automate this task? The web page requires a username and password and this is the code within the page that deals with the button itself:

    Code:
                              <tr>
                                <!-- Activity Buttons -->
                                <td align=left bgcolor=#FFFFFF>
                                  <table border=0 cellpadding=0 cellspacing=0>
                                    <tr>
                                      <form method="POST" action="rebootreq">
                                      <td align=left bgcolor=#FFFFFF>
                                        <input type="submit" name="rebootBtn" value="Reboot">
                                      </td>
                                      </form>
                                      <form method="GET" action="update.htm">
                                      <td align=left bgcolor=#FFFFFF>
                                        <input type="submit" name="Update" value="Update">
                                      </td>
                                      </form>
                                    </tr>
                                  </table>
                                </td>
                              </tr>
    
    This sounds simple enough, but alas I don't know much about scripting within a web page, I don't even know where to start.

    Thanks!
     
  2. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
  3. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    You could use something like cURL to have a little command-line to post the form values to the firewall web interface, having that in a wee batch file on your desktop you could double-click.

    http://curl.haxx.se/
     
  4. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    I stumbled upon this after I posted as well but I didn't have much success with the arguments. I got the username and password working okay, but it doesn't appear to be submitting the form properly (and I'm not sure what it should look like if successful). I'll have to do some more testing tomorrow.
     
  5. Nocera

    Nocera ...

    Joined:
    Aug 9, 2000
    Messages:
    1,307
    Likes Received:
    0
    Location:
    Long Island, NY
    Depending on how many screens you need to go through before being able to restart the firewall, it might be easier to use a proxy that records your traffic and generates a script that can replay your actions. I've only used GUI examples, but the following command line program might suit you. It generates WWW::Mechanize scripts which can be replayed at the later time.

    http://search.cpan.org/~leira/HTTP-Recorder-0.05/lib/HTTP/Recorder.pm
    http://search.cpan.org/~petdance/WWW-Mechanize-1.54/lib/WWW/Mechanize.pm
     
  6. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Well it is on the first screen. I'll give those a try if I can't get curl to work.

    Thanks!
     
  7. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    You could use selenium. It's for automated web testing, but does remedial tasks nicely as well. Also has a built in record function instead of writing your own tests. I use it when I have to generate exports from Omnitures DWH as their SOAP API is broken. :(

    http://seleniumhq.org/
     
  8. red

    red New Member

    Joined:
    Jun 30, 2005
    Messages:
    87,095
    Likes Received:
    0
    .

    But wouldn't it make more sense, instead of filling out the online form via a script, to just write a script which submits the same POST info to whatever the form submits to?
     
  9. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    All valid points, but if I knew how to do that I wouldn't have asked the question :)

    I've done a LOT of batch and vbs scripting in the past. If this was a telnet enabled firewall, this would all be moot. This is the first web page I've encountered where I needed to use the web interface to get something done.
     
  10. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Got it! If anyone's at all interested:

    curl -u username:password -d "rebootBtn=Reboot" 192.168.100.180/rebootreq
     

Share This Page