Topic: HTML form action: "post" in shell script?

Hi all,

I use a Copperjet ADSL/VoATM modem from Allied Data for my internet connection. I have it configured for ZIPB mode, which is a kind of half-bridge setup, whereby my FreeBSD gateway/server shares the external IP.

I am assigned a dynamic IP number by my ISP. I poll the Copperjet every file minutes with the following line in a script ("copperjet" is listed in my /etc/hosts file):

 curl http://$cjtuser:$cjtpass@copperjet/status.html 2> /dev/null | grep -A 1 "WAN IP Address:" | tail -1 | cut -b6- | awk -F '<' '{ print $1 }'

This scrapes the current IP from the "status" webpage; when it changes, I update my DNS records via dnsomatic.

Alas, on acount of limitations in the way it is implemented in the Copperjet, I have to disable and reenable ZIPB in order for the FreeBSD box to get the external IP. To do this interactively, I click on a button called "Disable" on the respective web page, then "Enable". Here is the relevant HTML:

 <FORM method="post" ACTION="/configuration/zipb.html/disable">
       <INPUT type="hidden" name="EmWeb_ns:vim:4.ImZipbAgent:enabled" value="false">
       <INPUT type="hidden" name="EmWeb_ns:vim:3" value="/configuration/zipb.html">
       <INPUT type="submit" value="Disable">

When I try to do this with curl I get an error message:

$ curl http://$cjtuser:$cjtpass@copperjet/configuration/zipb.html/disable                                                                     
405 Method Not Allowed

Anyone know how to manage a "post" action in a script?


Re: HTML form action: "post" in shell script?

I've found a web page that is pointing me in the right direction:

4.2 POST

  The GET method makes all input field names get displayed in the URL field of
  your browser. That's generally a good thing when you want to be able to
  bookmark that page with your given data, but it is an obvious disadvantage
  if you entered secret information in one of the fields or if there are a
  large amount of fields creating a very long and unreadable URL.

  The HTTP protocol then offers the POST method. This way the client sends the
  data separated from the URL and thus you won't see any of it in the URL
  address field.

  The form would look very similar to the previous one:

        <form method="POST" action="junk.cgi">
          <input type=text name="birthyear">
          <input type=submit name=press value=" OK ">

  And to use curl to post this form with the same data filled in as before, we
  could do it like:

        curl -d "birthyear=1905&press=%20OK%20"

  This kind of POST will use the Content-Type
  application/x-www-form-urlencoded and is the most widely used POST kind.

  The data you send to the server MUST already be properly encoded, curl will
  not do that for you. For example, if you want the data to contain a space,
  you need to replace that space with %20 etc. Failing to comply with this
  will most likely cause your data to be received wrongly and messed up.

(from: Using cURL to automate HTTP jobs)

but I am having a little difficulty which name/value parameters to pass with the "-d" option.

Re: HTML form action: "post" in shell script?

thanks cbrace smile

oh yeah, here's the code:

curl -d "EmWeb_ns:vim:4.ImZipbAgent:enabled=false&EmWeb_ns:vim:3=/configuration/zipb.html& \
    /configuration/zipb.html/disable=disable" http://$cjtuser:$cjtpass@copperjet/configuration/zipb.html/disable

something along those lines should work

Last edited by dannyp (2008-05-14 14:39:25)