On Wednesday, Feb 23, 2005, at 12:50 US/Central, Ed Howland wrote:
From the shell i'd use wget --post-data

wget --post-data 'Reboot=1' ip-address-of-router

I'm not sure what the javascript does. Does is submit Reboot or connectflag?

That's what I wanted to know, what is the browser sending to the router? I found a way to find the answer in my "The Linux Web Server" CD Bookshelf, specifically, "CGI Programming with Perl" Very nice book that is. Borrowing some code from the examples, I created this CGI program called env.cgi and put it in my cgi-bin folder:


#!/usr/local/bin/perl -wT
# Print a formatted list of all the environment variables
use strict;
$|=1;
print "Content-type: text/html\n\n";
my $var_name;
print "<html><head></head><body><table>\n";
foreach $var_name ( sort keys %ENV ) {
print "<tr><td><B>$var_name</B></td>\n";
print "<td>$ENV{$var_name}</td></tr>\n";
}
print "</table>\n";
if ( $ENV{REQUEST_METHOD} eq 'POST' ) {
my $query = "";
read( STDIN, $query, $ENV{CONTENT_LENGTH} ) == $ENV{CONTENT_LENGTH} or return undef;
print "<p>\n";
print "$query\n";
print "</p>\n";
}
print "</body></html>\n";


I then modified line 59 in a local copy of the html file ( I named it router.html ) from this:

    59  <form method="POST" action="tools_misc.html" name="tF">

to this

59 <form method="POST" action="http://localhost/cgi-bin/env.cgi"; name="tF">

I then opened the router.html in FireFox, pressed the "reboot" button, and pressed the "OK" button. FireFox then presented a list of environment variables and their settings along with this nice long string:

page=tools_misc&connectflag=1&PingIP=&C1=0&upnp=1&game=1&pptp_pt=1&ipsec _pt=1&DynamicDNS=0&SevericeURL=1&DDNSHostName=&DDNSLoginName=&DDNSLoginP assword=

Also, you can use the LWP library in Perl for this.

Under Linux, the GET, POST and PUT commands are wrappers around this (lwp-request)

Both of these can use a username/password pair for authentication.

Right. That was the second part, how can I send that string to the router in a script? As you mentioned, I could use POST on my linux box to send the string to the router:


{ echo -n 'page=tools_misc&connectflag=1&PingIP=&C1=0&upnp=1&game=1&'
echo -n 'pptp_pt=1&ipsec_pt=1&DynamicDNS=0&SevericeURL=1&'
echo -n 'DDNSHostName=&DDNSLoginName=&DDNSLoginPassword='
} | POST -C $user:$passwd http://192.168.0.1/tools_misc.html

Worked like a charm, as shown by a ping that was running in another shell at the time I sent the POST:

...
64 bytes from 192.168.0.1: icmp_seq=10 ttl=255 time=1.649 ms
64 bytes from 192.168.0.1: icmp_seq=11 ttl=255 time=1.649 ms
64 bytes from 192.168.0.1: icmp_seq=17 ttl=255 time=3.912 ms
64 bytes from 192.168.0.1: icmp_seq=18 ttl=255 time=1.628 ms
...

Lastly, after a bit of trial and error, I was able to whittle the POST string down and use lynx (since POST isn't on my Mac and wget on the MAc doesn't have the --post-data option) to send it to the router:

echo 'page=tools_misc&connectflag=1' |
lynx -post_data -auth=$user:$passwd \
  http://192.168.0.1/tools_misc.html >& /dev/null

And that's small enough to fit in a crontab.

Regards,
- Robert
http://www.cwelug.org/downloads
Help others get OpenSource software.  Distribute FLOSS
for Windows, Linux, *BSD, and MacOS X with BitTorrent

_______________________________________________
CWE-LUG mailing list
http://www.cwelug.org/ [email protected]
http://lists.firepipe.net/listinfo/cwe-lug

Reply via email to