PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > submitting an html form with curl from bash
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

submitting an html form with curl from bash

Réponse
 
LinkBack Outils de la discussion
Vieux 03/05/2008, 09h22   #1
Colin Brace
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut submitting an html form with curl from bash

Hi all,

I am not sure if this is the best newsgroup for my question, so feel
free to redirect me.

I am trying to manipulate my ADSL modem via its web interface in a
shell script. Basically, I need to disable and reactive a certain
setting, something called ZIPB mode. I am assigned a dynamic IP by my
ISP, and when this changes, I need to reactivate ZIPB on the modem
manually (an unfortunate limitation on the manufacturer's part).

The HTML form looks like this:

# <i>disabled.</i>
# <FORM method="post" ACTION="/configuration/zipb.html/enable">
# <INPUT type="hidden" name="EmWeb_ns:vim:
4.ImZipbAgent:enabled" value="true">
# <INPUT type="hidden" name="EmWeb_ns:vim:3" value="/
configuration/zipb.html">
# <INPUT type="submit" value="Enable">
# </FORM>

So, I try something like this in my shell script:

#!/usr/local/bin/bash

brackets () {
sed -e '
s/</&lt;/g
s/>/&gt;/g
s,/,%2f,g
s/?/%3f/g
s/:/%3a/g
s/@/%40/g
s/&/%26/g
s/=/%3d/g
s/+/%2b/g
s/\$/%24/g
s/,/%2c/g
s/ /%20/g
'
}

input1=$(echo "EmWeb_ns:vim:4.ImZipbAgent:enabled"|brackets)"="$ (echo
"true"|brackets)
input2=$(echo "EmWeb_ns:vim:3"|brackets)"="$(echo "/configuration/
zipb.html"|brackets)
input3="Enable"

curl -d '"'$input1"&"$input2"&"$input3'"'
http://$user:$pass@copperjet/configuration/zipb.html/enable >2&1> /dev/
null

but all I get is a rather unful reply:

curl: (52) Empty reply from server

Can anyone suggest ways of debugging this and/or easier ways to go
about this?

On a related note, I see that there is a book called from No Starch
called "Webbots, Spiders, and Screen Scrapers: A Guide to Developing
Internet Agents with PHP/CURL" which looks like it covers these
techniques, but

a) I am not to keen on buying a book on a topic which I don't plan to
pursue further than this simple task, and

b) I am likewise not so keen on having to learn PHP just to enable me
to do this.

Thanks for any ideas,
-- Colin
  Réponse avec citation
Vieux 03/05/2008, 14h35   #2
mop2
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: submitting an html form with curl from bash

Hi,
I'm using bash for that.
My script is below.
I don't remember about it because it don't give me troubles.

The program "ngrep" is very useful to see communication. As root:
/usr/bin/ngrep -W byline -d eth0 -l -p -P ^

Can be redirected to a file if needed.
The password is in base64.
Just adapt the script or see how it works.
Important: it is for http, not https.

A good start point is you make what you do manually with ngrep writing
to a file.
After see the streams between devices you can adapt the script.


-----
exec 3<>/dev/tcp/10.0.0.15/2345||return

case $1 in
IP)
echo -e "\
GET /summary.htm HTTP/1.1\r
Authorization: Basic OIUojLjloiujljloiUohuiuhihgi=\r
Cache-Control: no-cache\r
Connection: Close\r
\r
" >&3

/usr/bin/tr \< \\n <&3|/bin/grep 'FONT color=#008800>'|\
/bin/grep \\.|/bin/cut -d \> -f 2

;;
RST)
echo -en "\nModem Reset: `/bin/date`" >&2
echo -en "\
POST /reboot.cgi HTTP/1.1\r
Connection: Close\r
Authorization: Basic OIUojLjloiujljloiUohuiuhihgi=\r
Content-Length: 14\r
\r
submit1=Reboot">&3

#while read -t 3;do echo "$REPLY" >&2;done <&3

esac
exec 3<&-




Colin Brace wrote:
> Hi all,
>
> I am not sure if this is the best newsgroup for my question, so feel
> free to redirect me.
>
> I am trying to manipulate my ADSL modem via its web interface in a
> shell script. Basically, I need to disable and reactive a certain
> setting, something called ZIPB mode. I am assigned a dynamic IP by my
> ISP, and when this changes, I need to reactivate ZIPB on the modem
> manually (an unfortunate limitation on the manufacturer's part).
>
> The HTML form looks like this:
>
> # <i>disabled.</i>
> # <FORM method="post" ACTION="/configuration/zipb.html/enable">
> # <INPUT type="hidden" name="EmWeb_ns:vim:
> 4.ImZipbAgent:enabled" value="true">
> # <INPUT type="hidden" name="EmWeb_ns:vim:3" value="/
> configuration/zipb.html">
> # <INPUT type="submit" value="Enable">
> # </FORM>
>
> So, I try something like this in my shell script:
>
> #!/usr/local/bin/bash
>
> brackets () {
> sed -e '
> s/</&lt;/g
> s/>/&gt;/g
> s,/,%2f,g
> s/?/%3f/g
> s/:/%3a/g
> s/@/%40/g
> s/&/%26/g
> s/=/%3d/g
> s/+/%2b/g
> s/\$/%24/g
> s/,/%2c/g
> s/ /%20/g
> '
> }
>
> input1=$(echo "EmWeb_ns:vim:4.ImZipbAgent:enabled"|brackets)"="$ (echo
> "true"|brackets)
> input2=$(echo "EmWeb_ns:vim:3"|brackets)"="$(echo "/configuration/
> zipb.html"|brackets)
> input3="Enable"
>
> curl -d '"'$input1"&"$input2"&"$input3'"'
> http://$user:$pass@copperjet/configuration/zipb.html/enable >2&1> /dev/
> null
>
> but all I get is a rather unful reply:
>
> curl: (52) Empty reply from server
>
> Can anyone suggest ways of debugging this and/or easier ways to go
> about this?
>
> On a related note, I see that there is a book called from No Starch
> called "Webbots, Spiders, and Screen Scrapers: A Guide to Developing
> Internet Agents with PHP/CURL" which looks like it covers these
> techniques, but
>
> a) I am not to keen on buying a book on a topic which I don't plan to
> pursue further than this simple task, and
>
> b) I am likewise not so keen on having to learn PHP just to enable me
> to do this.
>
> Thanks for any ideas,
> -- Colin

  Réponse avec citation
Vieux 05/05/2008, 08h13   #3
Colin Brace
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: submitting an html form with curl from bash

On May 3, 3:35pm, mop2 <mop2bky4mz5tyjwa8ersp7hrg5u...@gmail.com>
wrote:

> I'm using bash for that.
> My script is below.


Hi,

By coincidence, I found another of doing this on this web page:

https://secure.dd-wrt.com/phpBB2/vie...c0d0cf6709bd72

It uses the telnet interface of the ADSL modem I have, a Copperjet
from Allied Data. I adapted it in my script like this:

in /etc/hosts:
172.19.3.1 copperjet

#!/usr/local/bin/bash
[...]
# copperjet username and password
cjtuser="colin"
cjtpass="xxxxxxxxxx"

# my PC
mypc="venus"

# procedure to reset ZIPB mode on the Copperjet
resetZIPB () {
(
sleep 1
printf "$cjtuser\r"
sleep 1
printf "$cjtpass\r"
sleep 1
printf "zipb set public device $mypc\r"
sleep 1
printf "user logout\r") | telnet copperjet
}
[...]

It works really well. I guess I will have to save studying HTML POST
for another project. Thanks anyway for your ideas.

-Colin
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 20h57.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13022 seconds with 11 queries