|
-
May 23rd, 2009, 03:00 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Router Reset Script.
AT my home I have a WAMP server running on a computer I have designated as a webserver.
Everyday I've got a script to restart the webserver at some wee hour in the morning.
I would also like to extend this to the router running the network. The router is good, but generally every 4 or so days it wants a reset. It's a LINKSYS WRT350N.
Basically, the process is as such with a browser:
- Navigate to router
- Place in login details (It's one of those htaccess login prompt boxes)
- The first page that loads up has a "Save Settings" button which resets the router.
The first page is:
/setup.cgi?next_file=Setup.htm
The "Save Setting" button's code is:
PHP Code:
<input type="BUTTON" name="save" value="Save Settings" onClick="checkData();">
The check data function is way too long, and is not needed to know (I believe).
The reset page is a loading screen. It takes roughly about a minute for the router to reset. Navigating directly to this page will cause the router to reset, but you have to still be authenticated in:
/setup.cgi?next_file=reboot_guage.htm
If some one could point me in the right direction on how to automate this process it would be greatly appreciated . I don't have any idea what to search for.
-
May 23rd, 2009, 04:44 AM
#2
Re: Router Reset Script.
My first initial reaction to that would be to buy a new router 
How do you authenticate yourself on the router? Is it via a web page or does a authentication dialog pop up when you attempt to access it?
-
May 24th, 2009, 02:12 AM
#3
Thread Starter
Fanatic Member
-
May 24th, 2009, 02:16 AM
#4
Re: Router Reset Script.
It is using HTTP authentication. If you send along an authorization header in PHP (which the browser does with every request) then it should work.
PHP Code:
header ('Authorization: ' . base64_encode($username . ':' . $password));
-
May 24th, 2009, 03:37 AM
#5
Thread Starter
Fanatic Member
Re: Router Reset Script.
PHP Code:
header ('Authorization: ' . base64_encode($username . ':' . $password));
header ('Location: /setup.cgi?next_file=reboot_guage.htm');
Something like that? Or does PHP support this type of login over multiple requests, or how to I place this in for every page PHP needs to navigate to? Not too sure how it works XD.
-
May 24th, 2009, 04:12 AM
#6
Re: Router Reset Script.
Silly me, i have got it the wrong way around. 
You need to actually request the page manually using fsockopen and include the header within that. Have a look at the fsockopen page as it has an example of how to make an HTTP request directly:
http://uk2.php.net/fsockopen
-
May 24th, 2009, 05:43 AM
#7
Thread Starter
Fanatic Member
Re: Router Reset Script.
PHP Code:
<?php $fp = fsockopen("192.168.1.1", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET /setup.cgi?next_file=reboot_guage.htm HTTP/1.1\r\n"; $out .= "Host: 192.168.1.1\r\n"; $out .= 'Authorization: ' . base64_encode($username . ':' . $password) . '\r\n'; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); /*while (!feof($fp)) { echo fgets($fp, 128); // dnt need to see it :). }*/ fclose($fp); } ?>
I think I got it ?
-
May 24th, 2009, 05:49 AM
#8
Re: Router Reset Script.
Did it work? You should at least read the first line of the response to check that it succeeded (i.e. you get a HCCP 200 OK).
-
May 24th, 2009, 07:58 AM
#9
Thread Starter
Fanatic Member
Re: Router Reset Script.
Nahh, it didn't work. I'm just getting Wireshark now and going to spy on the headers to see the browser doing it .
It gave me a 401.
HTTP/1.1 401 Unauthorized Server: Date: Sun, 24 May 2009 22:57:48 GMT WWW-Authenticate: Basic realm="Linksys WRT350N" Content-Type: text/html Connection: close
401 Unauthorized
Authorization required.
I tried:
PHP Code:
$out .= 'Authorization: Basic ' . base64_encode($username . ':' . $password) . '\r\n';
As well.
-
May 24th, 2009, 08:43 AM
#10
Thread Starter
Fanatic Member
Re: Router Reset Script.
Got it working . It just wanted:
PHP Code:
$out .= "Keep-Alive: 300\r\n";
$out .= "Connection: keep-alive\r\n";
Router is being difficult, lol.
Thanks for your help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|