1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

newbie failing on wan-restart

Discussion in 'Tomato Firmware' started by antiplex, Sep 17, 2008.

  1. antiplex

    antiplex Addicted to LI Member

    dear community,

    i'm new not only to this community but also to the wonderfully impressive tomato firmware that i just got to run nicely a few days ago on my WRT54GL.

    one thing that might be very handy for me is being able to start/stop/restart the wan connection (pppoe in my case). i did a few forum searches and found this issue discussed earlier in some older threads (well, 2007...), for example this one.

    the solution found there is to use wget with the url 'http://root:password@192.168.0.1/service.cgi?_service=wan-restart' which sounds just like what i would want.
    this however i cant get to work though. of course i use my real password and adjusted the ip etc, but it is just not working.
    if i do a
    Code:
    wget http://root:password@192.168.0.1/
    i get the status mainpage correctly, but with to complete url i see wget connects successfully but doesn't get any answer at all.

    any ideas what could be wrong here?

    what appears strange to me is that i can see that the disconnect button on the overview page doesn't do anything different than submitting a hidden form to service.cgi with the same parameters...

    thanks in advance, anti
     
  2. bogderpirat

    bogderpirat Network Guru Member

  3. antiplex

    antiplex Addicted to LI Member

    thanks a lot for that hint!

    i don't quite get why this is a xss vulnerability since i still would need the password but i'm not very experienced on the field of xss an the like.

    nevertheless i thought i would prefer this to be done via perl, so i wrote a little perl script which allows to manage the wan-connection and get the current connection status and external ip.
    i called it twrc as 'tomato-wan-remote-control', it's available here.

    i'm not sure if this is worth/good enough to get submitted to polarcloud or the tomato-wiki (@ tools section?), maybe its helpful to others?
     
  4. Kleeschen

    Kleeschen Addicted to LI Member

    Thank you, I tried this out yesterday;

    here a log :


    oida reconnecten
    PHP Notice: Undefined variable: key in I:\jdownloader\WRT54GL script\routerreconnect.php on line 28
    PHP Notice: Undefined index: in I:\jdownloader\WRT54GL script\routerreconnect.php on line 28
    PHP Notice: Undefined offset: 1 in I:\jdownloader\WRT54GL script\routerreconnect.php on line 29

    --------------

    from reconnect file as here :


    <?php

    // geschrieben von bog fuer morphium den alten nub, gpl und so blabla

    error_reporting(E_NOTICE); // wenn notices kommen ging was schief mit dem ersten curl-befehl

    $router_login="admin"; // standard
    $router_pw="admin2"; // pw des webif
    $router_ip="192.168.2.1"; // nach moeglichkeit ip und nicht den hostnamen, resolven isn umstand

    // ersma das safeword extrahiern

    $url1="http://$router_login:$router_pw@$router_ip";

    $ch=curl_init();
    curl_setopt($ch,CURLOPT_URL,$url1);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HEADER,false);
    $quellkot=curl_exec($ch);
    curl_close($ch);
    $quellkot=explode("\n",$quellkot);


    for($i=0;$i<count($quellkot);$i++) {
    if( preg_match("/(.*)_http_id=[a-zA-Z0-9]{19}(.*)/",$quellkot[$i]) ) $key=$i;
    }

    $http_id=explode("_http_id=",$quellkot[$key]);
    $http_id=explode("'>",$http_id[1]);
    $http_id=$http_id[0];

    // unnu is party anjesacht

    $url2=$url1."/service.cgi";

    $ch=curl_init();
    curl_setopt($ch,CURLOPT_URL,$url2);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_POST,true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,"_service=wan-stop&_http_id=$http_id");
    curl_setopt($ch,CURLOPT_HEADER,false);
    $bla=curl_exec($ch);
    curl_close($ch);

    sleep(2); // ruendchen schlafen

    $ch=curl_init();
    curl_setopt($ch,CURLOPT_URL,$url2);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_POST,true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,"_service=wan-restart&_http_id=$http_id");
    curl_setopt($ch,CURLOPT_HEADER,false);
    $bla=curl_exec($ch);
    curl_close($ch);

    echo "shihatsu stinkt"; // spread the truth

    ?>

    -------------
    please respect the intellectual property rights of this script :
    http://jultech.wordpress.com/2008/08/30/wrt54g-tomato-reconnect-batchfile/


    Vielen Dank

    -Kleeschen-
     
  5. bogderpirat

    bogderpirat Network Guru Member

    from your comment on the blog i see that you still use 1.19. have you considered updating to a more recent version? the script works fine from 1.21 onwards.

    i'm asking because i'm too lazy to flash to 1.19 and see why the script isn't working. :tongue:

    if an update is a no-go for you, please be so kind to send me the html source code of your main tomato webif page. maybe then i can figure out what's different in 1.19 (as it obviously has trouble detecting your http_id variable).
     
  6. Kleeschen

    Kleeschen Addicted to LI Member

    Hi again;

    thank you for your consideration;

    well, my router's http_id is : TID5ad975db01696adc

    </script>
    <script type='text/javascript' src='status-data.jsx?_http_id=TID5ad975db01696adc'></script>

    <script type='text/javascript'>

    ---
    I upgraded to v_22 and v_23 without success
     
  7. bogderpirat

    bogderpirat Network Guru Member

    hi,

    it doesn't look like there is anything different about the html code, so the script should detect the http_id just fine. the only thing that leaves us with is that it doesn't correctly get the url. hence...
    are you certain that you haven't misspelled the password? is the ip correct? what's the setting in Administration -> Admin Access -> Local Access? if the latter is "HTTPS" instead of "HTTP" or "HTTP & HTTPS", you'll have to replace the http with https in line 13 of the script.


    e: ugh wait, i'm just noticing this now: the standard webif user name is "root", not "admin". this isn't intentional, is it?
     
  8. Kleeschen

    Kleeschen Addicted to LI Member

    e: ugh wait, i'm just noticing this now: the standard webif user name is "root", not "admin". this isn't intentional, is it?


    ---------

    Yep :thumbup:

    it has to be "root" of course. Not my Username of weblogin. tzzt tzz :cool:


    Thank you very much

    It is all working right now, it was completly my fault

    Best regards

    -Kleeschen-
     
  9. bogderpirat

    bogderpirat Network Guru Member

    happy to hear that =)
     
  10. Dushmanius

    Dushmanius Addicted to LI Member

    I have WRT54G v4 running Tomato 1.25 and I tried this and it doesn't work.
    When I start batch file it will find http_id of my router and it says reconnect... waiting... done! but it will not change my IP.
    it still stays the same.

    I am trying to make this work with jdownloader so I can avoid waiting on RS, MU and so on...

    Anyway this is my routerreconnect.php file:

    <?php

    // for contextual help, see http://bogy.mine.nu

    error_reporting(E_NOTICE); // if notices appear, we probably have an error somewhere

    $router_login="root"; // standard
    $router_pw=".exe"; // pw of the webif
    $router_ip="10.0.0.1"; // router's ip

    // we extract the xss constant

    $url1="http://$router_login:$router_pw@$router_ip";

    $ch=curl_init();
    curl_setopt($ch,CURLOPT_URL,$url1);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HEADER,false);
    $quellkot=curl_exec($ch);
    curl_close($ch);


    preg_match("/(.*)_http_id=(TID[a-zA-Z0-9]{2,})(.*)/",$quellkot,$results);
    $http_id=$results[2];

    echo "found http_id=".$http_id."\n";


    // invoking the disconnection command
    echo "disconnecting...\n";

    $url2=$url1."/service.cgi";

    $ch=curl_init();
    curl_setopt($ch,CURLOPT_URL,$url2);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_POST,true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,"_service=wan-stop&_http_id=$http_id");
    curl_setopt($ch,CURLOPT_HEADER,false);
    curl_exec($ch);
    curl_close($ch);

    echo "waiting";

    sleep(1); // sleep three seconds
    echo "."; sleep(1);
    echo "."; sleep(1);
    echo ".\n";

    echo "reconnecting...\n";

    $ch=curl_init();
    curl_setopt($ch,CURLOPT_URL,$url2);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_POST,true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,"_service=wan-restart&_http_id=$http_id");
    curl_setopt($ch,CURLOPT_HEADER,false);
    curl_exec($ch);
    curl_close($ch);

    echo "done!"; // hopefully

    ?>

    Am I missing something?
     
  11. fyellin

    fyellin LI Guru Member

    For what it's worth, the webif accepts either "root" or "admin" as the user name. Both use the same password.

    However for ssh, telnet, etc. you have to use "root".
     
  12. bogderpirat

    bogderpirat Network Guru Member

    a bit more info would be interesting:
    - what kind of connection? pppoe? dhcp? are you certain that your ISP uses dynamic ips?
    - go to your webif and check the overview - determine how long your wan connections has been active. then run the reconnect script and check again. if the timer has reset, the application worked as it is supposed to, and you'll have to find the error somewhere else.
     
  13. Dushmanius

    Dushmanius Addicted to LI Member

    I tried that . My lease time has restarted. But no new IP. Damn.

    Is there a way of going around this? I', on comcast broadband.
     
  14. rhester72

    rhester72 Network Guru Member

    If Comcast chooses not to issue you a new IP every time you renew your lease (which is pretty standard policy and a good practice), you're pretty much out of luck without going through gyrations like changing your MAC address every time (and that's likely not to work with Comcast anyway due to MAC locking).

    Rodney
     
  15. Dushmanius

    Dushmanius Addicted to LI Member

    Blast it. Well thanks for reply. : )
     

Share This Page