• Example of JS web redirects?

    From poindexter FORTRAN@VERT/REALITY to All on Monday, February 25, 2019 13:20:53
    The wiki mentions that you could include a JS rewrite command in the per-directory webctrl.ini file:

    REWRITE

    Specifies a Javascript snippet which can modify the http_request.request_string. This allows internal redirects like the RewriteRule feature in Apache .htaccess files. The key must *begin* with the string “Rewrite” which may be followed by any legal INI key characters. The order of execution is not guaranteed.

    Does anyone have an example of this?

    ---
    Synchronet realitycheckBBS -- http://realitycheckBBS.org
  • From Digital Man@VERT to poindexter FORTRAN on Monday, February 25, 2019 14:21:25
    Re: Example of JS web redirects?
    By: poindexter FORTRAN to All on Mon Feb 25 2019 03:20 pm

    The wiki mentions that you could include a JS rewrite command in the per-directory webctrl.ini file:

    REWRITE

    Specifies a Javascript snippet which can modify the http_request.request_string. This allows internal redirects like the RewriteRule feature in Apache .htaccess files. The key must *begin* with the string “Rewrite” which may be followed by any legal INI key characters. The order of execution is not guaranteed.

    Does anyone have an example of this?

    Here's an example:

    JSPreExec=load(js.startup_dir+'/doku_rewrite.js');
    Rewrite=doku_rewrite();

    And here's the contents of doku_rewrite.js:

    function doku_rewrite()
    {
    var n=http_request.request_string;

    // Simple replacements...
    n=n.replace(/^([^\?]*\/)_media\/(.*)/,"$1lib/exe/fetch.php?media=$2");

    n=n.replace(/^([^\?]*\/)_detail\/(.*)/,"$1lib/exe/detail.php?media=$2");

    n=n.replace(/^([^\?]*\/)_export\/([^\/]+)\/(.*)/,"$1doku.php?do=export_$2&id=$3 ");

    // This handles adding doku.php to the index bit of the URI
    var pi = http_request.path_info;
    if (pi[0]=='/') {
    pi=pi.substr(1).replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");;
    n=n.replace(new RegExp('^(.*)('+pi+'(?:\\?.*)?)$'), "$1doku.php?id=$2");
    }

    // If the URI ends with a slash, stuff in doku.php at the end.
    n=n.replace(/^([^\?]*\/)(\?.*)?$/,"$1doku.php$2");

    // index.php becomes doku.php
    n=n.replace(/^([^\?]*\/)index.php/,"$1doku.php");

    // Handle it.
    if (n != http_request.request_string) {
    // Replace all but the first '?' with '&'
    n=n.replace(/(^.*\?[^\?]*)\?/g,'$1&');
    http_request.request_string = n;
    return true;
    }
    return false;
    }


    digital man

    Synchronet/BBS Terminology Definition #36:
    IBM437 = Code Page 437 (so-called IBM Extended ASCII)
    Norco, CA WX: 65.0F, 50.0% humidity, 5 mph E wind, 0.00 inches rain/24hrs

    ---
    Synchronet Vertrauen Home of Synchronet [vert/cvs/bbs].synchro.net
  • From echicken@VERT/ECBBS to poindexter FORTRAN on Monday, February 25, 2019 17:22:20
    Re: Example of JS web redirects?
    By: poindexter FORTRAN to All on Mon Feb 25 2019 15:20:53

    Specifies a Javascript snippet which can modify the http_request.request_string. This allows internal redirects like the RewriteRule feature in Apache .htaccess files. The key must *begin* with the string “Rewrite” which may be followed by any legal INI key characters. The order of execution is not guaranteed.

    Does anyone have an example of this?

    A line like this in the root of a webctrl.ini file would generate a log message whenever that directory or any file in it was requested:

    RewriteOne=log('Generated by RewriteOne');

    You could limit it to a specific file or pattern by putting it in an ini section, per the normal webctrl.ini rules. And I guess you could have more rules named RewriteTwo, RewritePizza, whatver you like.

    I have tested this but I haven't done anything useful with it. I'm not sure if it's limited to modifying http_request.request_string, or if it's capable of more and that's just the intended use.

    ---
    echicken
    electronic chicken bbs - bbs.electronicchicken.com - 416-425-5435
    Synchronet electronic chicken bbs - bbs.electronicchicken.com