Router WTF



  • Recently my dad asked me to help with a problem he was having with his router.
    The router has this little web interface where you can release/renew your ip address (it's PPTP)
    ... But that web interface refused to work when you open it via my dad's PocketPC.

    As it turns out, WindowsMobile doesn't correctly implement some crucial JavaScript functions like getElementById,
    which makes the shiny PoketPC more or less unusable for JS-only sites like the router interface ๐Ÿ˜ž

    Anyway I did a quick View Source in the router and found lots of useless functions like theone shown below.
    I know this doesn't qualify for a major WTF but sometimes a combination of a few small WTF's make a big WTF.
    And it is such WTF's that make poor dad get out of his bed to restart the router ๐Ÿ˜ž



    function dhcp_action(which_action,is_release)
    {
    var form1Id = document.getElementById("form1");

    if(is_release){
    which_action = which_action - 1;
    }

    if(which_action){
    form1Id.dhcp.value = which_action;
    }else{
    form1Id.dhcp.value = which_action;
    }
    form1Id.submit();
    }




  • Let's see if we can make this readable...



    function dhcp_action(which_action, is_release) {
    var form1Id = document.getElementById("form1");
    form1Id.dhcp.value = (is_release ? which_action : which_action - 1);
    form1Id.submit();
    }

    Kinda makes you wonder about the quality and reliability of the code you can't see.



  • @Brendan Kidwell said:

    Let's see if we can make this readable...


    function dhcp_action(which_action, is_release) {
    var form1Id = document.getElementById("form1");
    form1Id.dhcp.value = (is_release ? which_action : which_action - 1);
    form1Id.submit();
    }

    Kinda makes you wonder about the quality and reliability of the code you can't see.


    <font size="2">I think you have your terniary operands backwards, but the real question is why is this function even necessary? If you're releasing a lease, why not just have a checkbox for each leased IP and a button, "Release"?
    You can set a hidden form field (maybe named "action") to "release" and post.

    Maybe shops shouldn't have their embedded developers writing their web GUIs...</font>


  • @Brendan Kidwell said:

    function dhcp_action(which_action, is_release) {
    var form1Id = document.getElementById("form1");
    form1Id.dhcp.value = (is_release ? which_action : which_action - 1);
    form1Id.submit();
    }

    <FONT face=Tahoma>still won't work, it should be like</FONT>

    function dhcp_action(which_action, is_release) {
    ย ย ย form1.dhcp.value = (is_release ? which_action - 1 : which_action);
    ย ย  form1.submit();
    }

    <FONT face=Tahoma>because its been said that getElementById doesn't work in the PocketPC</FONT>



  • @Brendan Kidwell said:

    Kinda makes you wonder about the quality and reliability of the code you can't see.





    yeah, indeed. I'm not sure I wanna know what else is going on there ๐Ÿ™‚



    That router GUI should work just fine with a simple HTML form. But no
    it even does all the WEP key generation, port number validation and all
    that all in JS. For me this is unacceptable.



    Now that AJAX is the new tech buzzword, makes you think what else out
    there will soon rely on JS (and fail horribly when you don't have JS
    enabled)




  • @John Smallberries said:

    <font size="2">embedded developers</font>




    "There's a little man inside my computer!"






  • I use AJAX-type technologies, but only because I'm specifically writing
    a web application for use in controlled environments with IE6. (There
    is a necessary ActiveX control involved.)



    But in general, Rails has as much promise for quickly creating JS-less
    old-school interfaces as it does for creating new-fangled AJAX ones.



    And when you say, "But no
    it even does all the WEP key generation, port number validation and all
    that all in JS. For me this is unacceptable," I would say that it is
    fine for all that to be done in Javascript, just not on the client
    side. ๐Ÿ™‚



  • I've been doing some PocketPC JS today - it is possible, you just can't
    expect full DOM support in such a small (by todays standards)
    executable.



    Regardless I agree with Brendan - web developers should make their
    stuff either work or at least "fail cleanly" with JS disabled.



    This is what I tell my designers: "If your site doesn't work without
    JS, you're preventing 10% of people from using it properly, thus losing
    10% of your sales, 10% off the business revenue, so I'll just knock 10%
    off your salary shall I?"



  • These new small routers have web interfaces which are alledged to be "better" than the traditional telnet/serial configuration method. IMHO this isn't the case.

    The line "which_action = which_action - 1" followed by if(which_action) looks like a direct translation of a "JZ trellis", a common structure in embedded systems code; instead of comparing against values like

    if(which_action==1) { ... }

    if(which_action==2) { ... }

    if(which_action==3) { ... }

    this is used:

    which_action--;

    if(which_action) { ... }

    which_action--;

    if(which_action) { ... }

    which_action--;

    if(which_action) { ... }

    Obviously this is a low-level detail: in Asm, most processors have a short decrement instruction and a subsequent conditional jump, whereas repeated compare instructions would take more space and time. However translating this low-level detail into a high-level language like JS nulls any advantages.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.