dcsimg
Results 1 to 10 of 10

Thread: [RESOLVED] Router Reset Script.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Resolved [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:

    1. Navigate to router
    2. Place in login details (It's one of those htaccess login prompt boxes)
    3. 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.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,907

    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?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Router Reset Script.

    Yes, I know. But it's an awesome router . It just gets stuck after too much traffic runs through it (I have a media centre streaming some DVDs throughout the house, and it crashes usually a short time after it).

    It's a dialog popup. Not one of those in page ones with a textbox and a submit button.

    I attached a screenshot for you .
    Attached Images Attached Images  

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,907

    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)); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    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.

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,907

    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
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Router Reset Script.

    PHP Code:
    <?php
    $fp 
    fsockopen("192.168.1.1"80$errno$errstr30);
    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 ?

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,907

    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).
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    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.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    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
  •  



Featured


Click Here to Expand Forum to Full Width