Results 1 to 9 of 9

Thread: great mirror redirector -- if i can make it work

  1. #1
    Join Date
    Mar 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default great mirror redirector -- if i can make it work

    ok.. so ive been working on a mirror redirect page.... its purpose is to display a list of mirrors, display individual mirror status (online, offline), and then randomly redirect users to one of the ONLINE mirrors.... I have chosen to do it all client side... as users might not have the same access to the mirrors that one of the servers might (ip restrictions, etc).... I am using "online" images located on the mirror to determine its status, and I capture the <img OnError to display "offline" images... so far all works fine....
    where it all falls apart is when i try to use the img onerror to set a variable to so that that mirror will not be part of the random redirect... I am not getting any error messages so i do not know exactly what the problem is.... I think that the problem is when i try to set a variable that will inform my redirect script to ignore a mirror......
    i may not be explaining it well...... here's the code:

    <html>
    <head>
    <SCRIPT LANGUAGE="JavaScript">

    function changeImg(which, newimg) {
    which.src = newimg;
    return;
    }


    var brinksteronline
    var trefdynonline
    var awardspaceonline



    function SeTTem(setwhat) {
    setwhat = "true";
    }

    var brinkster="http://www30.brinkster.com/oxman/asp/";
    var trefdyn="http://tref.dyndns.org:22222/www/asp/";
    var trefdyn2="http://tref.dyndns.org:22222/www/php/";
    var awardspace="http://lucasbibby.awardspace.com/";

    if (brinksteronline == true) {brinkster = trefdyn;}
    if (trefdynonline == true) {trefdyn = awardspace; trefdyn2 = awardspace;}
    if (awardspaceonline == true) {awardspace = brinkster;}
    else {}


    var urlarray= new Array(
    brinkster,
    trefdyn,
    trefdyn2,
    awardspace);

    randomno=Math.floor((Math.random()*urlarray.length));

    urlran=urlarray[randomno]


    </SCRIPT>
    </head>
    <BODY>
    <table>
    <tr><td><center><a href='http://www30.brinkster.com/oxman/asp/'><span style="cursor:hand"> <b>Mirror 2</b><span></a></center></td><td><center>...<img src="http://www30.brinkster.com/oxman/asp/img-bin/misc/online.gif" OnError="SeTTem('brinksteronline'); changeImg(this, 'http://www30.brinkster.com/oxman/asp/img-bin/misc/offline.gif');" alt="status">...</center></td></tr>
    <tr><td><center><a href='http://tref.dyndns.org/www/asp/'><span style="cursor:hand"> <b>Mirror 1</b><span></a></center></td><td><center>...<img src="http://tref.dyndns.org/www/asp/img-bin/misc/online.gif" OnError="SeTTem('trefdynonline'); changeImg(this, 'http://www30.brinkster.com/oxman/asp/img-bin/misc/offline.gif');" alt="status">...</center></td></tr>
    <tr><td><center><a href='http://tref.dyndns.org/www/php/'><span style="cursor:hand"> <b>Mirror 1</b><span></a></center></td><td><center>...<img src="http://tref.dyndns.org/www/php/img-bin/misc/online.gif" OnError="SeTTem('trefdynonline'); changeImg(this, 'http://www30.brinkster.com/oxman/asp/img-bin/misc/offline.gif');" alt="status">...</center></td></tr>
    <tr><td><center><a href='http://lucasbibby.awardspace.com'><span style="cursor:hand"> <b>Mirror 5</b><span></a></center></td><td id="ignore"><center>...<img src="http://lucasbibby.awardspace.com/php/img-bin/misc/online.php" OnError="SeTTem('awardspaceonline'); changeImg(this, 'http://www30.brinkster.com/oxman/asp/img-bin/misc/offline.gif');" alt="status">...</center></td></tr>
    </table>
    <SCRIPT LANGUAGE="JavaScript">

    function go(){
    var url=urlran
    var target="_self"
    window.open(url,target)
    }


    function wait(delay){
    string="pauseforalert("+delay+");";
    setTimeout(string,delay);
    }
    function pauseforalert(delay){
    // document.write(urlarray) will be replaced by go();
    // once i am sure it works, in the mean time, lets me see the urlarray
    document.write(urlarray);
    }


    wait(5500)


    </SCRIPT>
    </body>



    *note that for testing purposes i have setup mirror 1 to always report offline

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Looks like things are slipping through the cracks, let's say they are all offline. In that case, they are all set to true:

    Code:
    if (brinksteronline == true) {brinkster = trefdyn;}
    //brink becomes tref which was thought to be online at that point
    if (trefdynonline == true) {trefdyn = awardspace; trefdyn2 = awardspace;}
    //tref is now set to award which, for the moment is thought to be good
    if (awardspaceonline == true) {awardspace = brinkster;}
    //award is set to brink which really is now tref from when it was thought to be OK.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    language is deprecated in favour of type:
    Code:
    <script type="text/javascript">
    But, more importantly, this ought to be done server-side. Server-side you can use a proper connection to the server, rather than this hack, and cater to non-Javascript browsers.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Mar 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I agree... it really should be done server side... the issue i have with that is that i often access the page from home which is on the same network as trefdyndns... due to issues with my monowall, i cannot access anthing from inside the network using the outside ip.... also, work blocks out ips from local isp's to keep people from remoting into their home networks... so, server side scripting really wont do what i need it to... mostly because of restrictions on trefdyndns based on locations I (and others) access the page from. essentially, the server the mirror page is hosted on may be able to access the mirror but the user cannot... therefore, i feel the check before redirect should be done client side...

    john, your point about what if they're all down... not likely that all the mirrors will be down at the same time... but possible... I originally had an else statement to redirect to a "all mirrorz down please try again" page.. but the problem was that was the only page it ever redirected to at all... so i killed that, also, this mirrorz page (and the auto mirror redirect script) are hosted on brinkster... so basically brinkster will never be down... if it goes down, you wont be able to get to the mirror page anyway... i know, I know, lame... eventually I plan to host the mirrorz page independant.. but for now i am working with what i have...

    finally, i have fixed the language vs. type... it is now type...

    any thoughts on how I could -- client side -- check my mirrorz for accessibility before randomly choosing one (of the accessible) and redirecting to it???? even a totaly new script??.. or how to make this one work??

  5. #5
    Join Date
    Mar 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I dont know... for some reason it is simply not setting my variable to true... or if it is it is not acting on it the way i have told it to..... everytime without fail the urlarray is unchanged.....

    here is the new code:

    <html>
    <head>
    <SCRIPT type="text/javascript">

    function changeImg(which, newimg) {
    which.src = newimg;
    return;
    }


    var brinkonline
    var trefonline
    var awardonline



    function SeTTem(setwhat) {
    setwhat = "true";
    }

    var brinkster="http://www30.brinkster.com/oxman/asp/";
    var trefdyn="http://tref.dyndns.org:22222/www/asp/";
    var trefdyn2="http://tref.dyndns.org:22222/www/php/";
    var awardspace="http://lucasbibby.awardspace.com/";

    if ((brinkonline == true)+(trefonline == true)+(awardonline == true)){
    // all offline, do something cuz they're all dead
    window.location = alloffline.htm;
    }
    else {
    if (brinkonline == true) {brinkster = trefdyn;}
    // brink becomes tref which, in the randomosity array,
    // gives double chances tref will be chosen
    if (trefonline == true) {trefdyn = awardspace; trefdyn2 = awardspace;}
    // tref becomes award which, in the randomosity array,
    // gives double chances award will be chosen
    if (awardonline == true) {awardspace = brinkster;}
    // award becomes brink which, in the randomosity array,
    // gives double chances brink will be chosen
    else {
    // all online, do nothing
    }
    }

    var urlarray= new Array(
    brinkster,
    trefdyn,
    trefdyn2,
    awardspace);

    randomno=Math.floor((Math.random()*urlarray.length));

    urlran=urlarray[randomno]


    </SCRIPT>
    </head>
    <BODY>
    <table>
    <tr><td><center><a href='http://www30.brinkster.com/oxman/asp/'><span style="cursor:hand"> <b>Mirror 2</b><span></a></center></td><td><center>...<img src="http://www30.brinkster.com/oxman/asp/img-bin/misc/online.gif" OnError="SeTTem('brinkonline'); changeImg(this, 'http://www30.brinkster.com/oxman/asp/img-bin/misc/offline.gif');" alt="status">...</center></td></tr>
    <tr><td><center><a href='http://tref.dyndns.org/www/asp/'><span style="cursor:hand"> <b>Mirror 1</b><span></a></center></td><td><center>...<img src="http://tref.dyndns.org/blahblah/online.gif" OnError="SeTTem('trefonline'); changeImg(this, 'http://www30.brinkster.com/oxman/asp/img-bin/misc/offline.gif');" alt="status">...</center></td></tr>
    <tr><td><center><a href='http://tref.dyndns.org/www/php/'><span style="cursor:hand"> <b>Mirror 1</b><span></a></center></td><td><center>...<img src="http://tref.dyndns.org/blahblah/online.gif" OnError="SeTTem('trefonline'); changeImg(this, 'http://www30.brinkster.com/oxman/asp/img-bin/misc/offline.gif');" alt="status">...</center></td></tr>
    <tr><td><center><a href='http://lucasbibby.awardspace.com'><span style="cursor:hand"> <b>Mirror 5</b><span></a></center></td><td id="ignore"><center>...<img src="http://lucasbibby.awardspace.com/php/img-bin/misc/online.php" OnError="SeTTem('awardonline'); changeImg(this, 'http://www30.brinkster.com/oxman/asp/img-bin/misc/offline.gif');" alt="status">...</center></td></tr>
    </table>
    <SCRIPT LANGUAGE="JavaScript">

    function go(){
    var url=urlran
    var target="_self"
    window.open(url,target)
    }


    function wait(delay){
    string="pauseforalert("+delay+");";
    setTimeout(string,delay);
    }
    function pauseforalert(delay){
    // document.write(urlarray) will be replaced by go();
    // once i am sure it works, in the mean time, lets me see the urlarray
    document.write(urlarray);
    }


    wait(5500)


    </SCRIPT>
    </body>



    hacky as it is... it should do what i want it to.... and its not... am I just a dumbass???? if i am just tell me im completely barkin up the wrong tree... and point me to the right tree... otherwise.. what in this code is broken???

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Having scanned it quickly, I think this is the problem:
    Code:
    function SeTTem(setwhat) {
    setwhat = "true";
    }
    I believe that in Javascript, only objects are passed by reference. The setwhat you're setting to "true" in that function is a completely different variable to the setwhat you passed to it.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Mar 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks twey....

    well that made sense to me... so i rewrote that part of the script thinking i had fixed it and it was all that simple.. but I was still getting the same results... so now i have rewritten the whole deal in order to isolate the issue.... here it is:

    <html>
    <head>
    <SCRIPT type="text/javascript">

    function changeImg(which, newimg) {
    which.src = newimg;
    return;
    }

    var brinkonline
    var trefonline
    var awardonline
    var setwhat

    function SeTTem(setwhat) {
    if (setwhat == 'brink') {brinkonline = "false";}
    if (setwhat != 'brink') {brinkonline = "true";}
    if (setwhat == 'tref') {trefonline = "false";}
    if (setwhat != 'tref') {trefonline = "true";}
    if (setwhat == 'award') {awardonline = "false";}
    if (setwhat != 'award') {awardonline = "true";}
    }


    if ((brinkonline == true)+(trefonline == true)+(awardonline == true)){
    // all online, impossible tref shoulda read an error
    brinkster = "allreadtrue";
    trefdyn = "allreadtrue";
    trefdyn2 = "allreadtrue";
    awardspace = "allreadtrue";
    }
    if ((brinkonline == false)+(trefonline == false)+(awardonline == false)){
    // all offline, not very likely
    brinkster = "allreadfalse";
    trefdyn = "allreadfalse";
    trefdyn2 = "allreadfalse";
    awardspace = "allreadfalse";
    }
    else {
    if ((brinkonline != true)+(brinkonline == false)) {brinkster = "brinksteroffline";}
    // if not true, but is false, brinkster is offline
    if ((brinkonline != true)+(brinkonline != false)) {brinkster = "novarpassedbrink";}
    // if neither true nor false no var set
    if ((trefonline != true)+(trefonline == false)) {trefdyn = "trefoffline"; trefdyn2 = "trefoffline";}
    // if not true, but is false, tref is offline
    if ((trefonline != true)+(trefonline != false)) {trefdyn = "novarpassedtref"; trefdyn2 = "novarpassedtref";}
    // if neither true nor false no var set
    if ((awardonline != true)+(awardonline == false)) {awardspace = "awardoffline";}
    // if not true, but is false, award is offline
    if ((awardonline != true)+(awardonline != false)) {awardspace = "novarpassedaward";}
    // if neither true nor false no var passed
    }

    var urlarray= new Array(
    brinkster,
    trefdyn,
    trefdyn2,
    awardspace);

    // randomno=Math.floor((Math.random()*urlarray.length));

    // urlran=urlarray[randomno]

    </SCRIPT>
    </head>
    <BODY>
    <table>
    <tr><td><center><a href='http://www30.brinkster.com/oxman/asp/'><span style="cursor:hand"> <b>Mirror 2--Brink</b><span></a></center></td><td><center>...<img src="http://www30.brinkster.com/oxman/asp/img-bin/misc/online.gif" OnError="SeTTem('brink'); changeImg(this, 'http://www30.brinkster.com/oxman/asp/img-bin/misc/offline.gif');" alt="status">...</center></td></tr>
    <tr><td><center><a href='http://tref.dyndns.org/www/asp/'><span style="cursor:hand"> <b>Mirror 1--TREFDYN</b><span></a></center></td><td><center>...<img src="http://tref.dyndns.org/blahblah/online.gif" OnError="SeTTem('tref'); changeImg(this, 'http://www30.brinkster.com/oxman/asp/img-bin/misc/offline.gif');" alt="status">...</center></td></tr>
    <tr><td><center><a href='http://tref.dyndns.org/www/php/'><span style="cursor:hand"> <b>Mirror 1--TREFDYN2</b><span></a></center></td><td><center>...<img src="http://tref.dyndns.org/blahblah/online.gif" OnError="SeTTem('tref'); changeImg(this, 'http://www30.brinkster.com/oxman/asp/img-bin/misc/offline.gif');" alt="status">...</center></td></tr>
    <tr><td><center><a href='http://lucasbibby.awardspace.com'><span style="cursor:hand"> <b>Mirror 5--award</b><span></a></center></td><td id="ignore"><center>...<img src="http://lucasbibby.awardspace.com/php/img-bin/misc/online.php" OnError="SeTTem('award'); changeImg(this, 'http://www30.brinkster.com/oxman/asp/img-bin/misc/offline.gif');" onLoad="SeTTem('none');" alt="status">...</center></td></tr>
    </table>
    <SCRIPT type="text/javascript">

    // function go(){
    // var url=urlran
    // var target="_self"
    // window.open(url,target)
    // }


    function wait(delay){
    string="pauseforalert("+delay+");";
    setTimeout(string,delay);
    }
    function pauseforalert(delay){
    // document.write(urlarray) will be replaced by go();
    // once i am sure it works, in the mean time, lets me see the urlarray
    document.write(urlarray);
    }


    wait(5500)


    </SCRIPT>
    </body>
    <html>



    now, it is outputting "novarpassed" for all of them... so.. for some reason or another, when <img OnError kicks... SeTTem is still not passing anything... so you are right... SeTTem is the problem... either in the function or in the way i execute it... any ideas how to make SeTTem give me something unique for each img that kicks the onerror and activates it?
    i guess what im asking is, how can i pass something to SeTTem then use that something to set a variable??
    Last edited by oxman; 04-04-2006 at 07:22 PM.

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's an easy one. You check to see if the values are true or false, but you set them to the strings "true" or "false." You also seem to have some very odd ideas about comparisons. If no value is set for a variable, it will equate as false. + is an addition or concatenation operator, not a boolean AND. == true is never needed, as it will already be a boolean value. I've done a quick cleanup:
    Code:
    function changeImg(whi, newimg) {
      whi.src = newimg;
    }
    
    var brinkonline,
      trefonline,
      awardonline,
      setwhat;
    
    function SeTTem(setwhat) {
      if (setwhat == 'brink') brinkonline = false;
      else brinkonline = true;
      if (setwhat == 'tref') trefonline = false;
      else trefonline = true;
      if (setwhat == 'award') awardonline = false;
      else awardonline = true;
    }
    
    
    if (brinkonline && trefonline && awardonline)
    // all online, impossible tref shoulda read an error
      brinkster =
        trefdyn =
          trefdyn2 =
            awardspace = "allreadtrue";
    else if (!(brinkonline || trefonline || awardonline))
    // all offline, not very likely
      brinkster =
        trefdyn =
          trefdyn2 =
            awardspace = "allreadfalse";
    else {
      if (!brinkoffline) brinkster = "brinksteroffline";
      // if not true, but is false, brinkster is offline
      if (!trefonline) trefdyn = trefdyn2 = "trefoffline";
      // if not true, but is false, tref is offline
      if (!awardonline) awardspace = "awardoffline";
      // if not true, but is false, award is offline
    }
    
    var urlarray= new Array(
      brinkster,
      trefdyn,
      trefdyn2,
      awardspace
    );
    
    var randomno=Math.floor((Math.random()*urlarray.length));
    
    var urlran = urlarray[randomno];
    ... but this could be done much better.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Mar 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok.. so.. that works... i guess.. but it still doesnt match the images.... the new code always reports false.. "allreadfalse" which, to me, means that in the table, in the <img> tag, where i tell it to OnError="SeTTem('nameofunavailableserver');" it never executes... or if it does it doesnt do what its supposed to... nothing gets set to true... nothing gets set to false... nothing gets set..... so.... what now?? this is exactly where this whole thing started... the code has evolved but the output is the same...
    i want to...... OnError tell the urlarray that the corresponding url is invalid......
    Last edited by oxman; 04-04-2006 at 10:02 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •