• Dump Globals

    From Mortifis@VERT/ALLEYCAT to All on Saturday, February 16, 2019 11:26:39
    Is there a js function similar to php var_dump($GLOBALS); ?

    2 wrongs don't make a right, but 3 left turns will get you back on the freeway!

    ---
    þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81
  • From echicken@VERT/ECBBS to Mortifis on Saturday, February 16, 2019 11:36:44
    Re: Dump Globals
    By: Mortifis to All on Sat Feb 16 2019 11:26:39

    Is there a js function similar to php var_dump($GLOBALS); ?

    Not that I'm aware of. It's easier and less verbose to target the variable that you want rather than dumping the entire global space:

    writeln(JSON.stringify(my_var));

    You could use this to dump the global scope of your script:

    function scope_dump() {
    Object.keys(js.scope).forEach(function (e) {
    const exclude = [
    'conio',
    'js',
    'stderr',
    'stdin',
    'stdout'
    ];
    if (exclude.indexOf(e) > -1) return;
    writeln(e + ':\r\n' + JSON.stringify(js.scope[e]) + '\r\n');
    });
    }

    Tweak the 'exclude' array to filter unneeded stuff like 'system', 'msg_area', 'file_area', 'xtrn_area'. The defaults are there to avoid problems and should be left in, though some don't matter in certain contexts (like the webserver).

    ---
    echicken
    electronic chicken bbs - bbs.electronicchicken.com - 416-425-5435
    þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.com
  • From Mortifis@VERT/ALLEYCAT to echicken on Saturday, February 16, 2019 13:04:07
    Re: Dump Globals
    By: Mortifis to All on Sat Feb 16 2019 11:26:39

    Is there a js function similar to php var_dump($GLOBALS); ?

    Not that I'm aware of. It's easier and less verbose to target the variable that you want rather than dumping the entire global space:

    writeln(JSON.stringify(my_var));

    You could use this to dump the global scope of your script:

    function scope_dump() {
    Object.keys(js.scope).forEach(function (e) {
    const exclude = [
    'conio',
    'js',
    'stderr',
    'stdin',
    'stdout'
    ];
    if (exclude.indexOf(e) > -1) return;
    writeln(e + ':\r\n' + JSON.stringify(js.scope[e]) + '\r\n');
    });
    }



    perfect, thank you, one thing I am having trouble with is set_cookie(..., (time() - 1000, ...) I keep getting an error: cannot convert NaN to integer

    2 wrongs don't make a right, but 3 left turns will get you back on the freeway!

    ---
    þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81
  • From echicken@VERT/ECBBS to Mortifis on Saturday, February 16, 2019 12:32:19
    Re: Re: Dump Globals
    By: Mortifis to echicken on Sat Feb 16 2019 13:04:07

    perfect, thank you, one thing I am having trouble with is set_cookie(..., (time() - 1000, ...) I keep getting an error: cannot convert NaN to integer

    http://wiki.synchro.net/server:web#extra_global_methods

    What you're passing as the expiration time can't be interpreted as an integer. Mind the order of parameters you're passing to set_cookie. The first two parameters need to be strings. The third parameter is optional, and if passed needs to be a number, being the expiration time. See the wiki for the rest of the parameters.

    So what you want is something like this:

    set_cookie('key', 'value', time() - 1000); // Or time() - 1000 or whatever

    ---
    echicken
    electronic chicken bbs - bbs.electronicchicken.com - 416-425-5435
    þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.com
  • From Mortifis@VERT/ALLEYCAT to echicken on Saturday, February 16, 2019 15:33:53
    Re: Re: Dump Globals
    By: Mortifis to echicken on Sat Feb 16 2019 13:04:07

    perfect, thank you, one thing I am having trouble with is set_cookie(..., (time() - 1000, ...) I keep getting an error: cannot convert NaN to integer

    http://wiki.synchro.net/server:web#extra_global_methods

    What you're passing as the expiration time can't be interpreted as an integer. Mind the order of parameters you're passing to set_cookie. The first two parameters need to be strings. The third parameter is optional, and if passed needs to be a number, being the expiration time. See the wiki for the rest of the parameters.

    So what you want is something like this:

    set_cookie('key', 'value', time() - 1000); // Or time() - 1000 or whatever

    that's is the format I have been using, though I believe I tracked the issue down to a misplace , :/ so in the web interface I am, ahem, scripting, I set the cookie then did the scope_dump() you gave me and http_request:{ ... cookie is still cookie{} ...

    new question: how would one do a logout from the interface ... tried setting user.numer = 0; with no affect

    2 wrongs don't make a right, but 3 left turns will get you back on the freeway!

    ---
    þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81
  • From echicken@VERT/ECBBS to Mortifis on Saturday, February 16, 2019 17:53:05
    Re: Re: Dump Globals
    By: Mortifis to echicken on Sat Feb 16 2019 15:33:53

    new question: how would one do a logout from the interface ... tried setting user.numer = 0; with no affect

    How are you logging the user in in the first place?

    I believe the Runemaster web UI uses HTTP authentication that's baked into the web server. The user is already logged in before the script begins to execute, and I don't think there's a proper way to log them out after that. With most browsers, the only way to log out of this type of session is to close the browser. Clearing the cache may work. I see a logout.ssjs that attempts to do just this, but if it does it wouldn't take effect until the next request comes in from that client.

    My web UI does things a bit differently and does have a way of destroying a session, but that's a whole other story. It's also something I'm planning on revising in the near term.

    Are you creating a web interface from scratch, or is this a mod of something that already exists?

    ---
    echicken
    electronic chicken bbs - bbs.electronicchicken.com - 416-425-5435
    þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.com
  • From Mortifis@VERT/ALLEYCAT to echicken on Saturday, February 16, 2019 20:08:10
    Re: Re: Dump Globals
    By: Mortifis to echicken on Sat Feb 16 2019 15:33:53

    new question: how would one do a logout from the interface ... tried setting user.numer = 0; with no affect

    How are you logging the user in in the first place?

    I believe the Runemaster web UI uses HTTP authentication that's baked into the web server. The user is already logged in before the script begins to execute, and I don't think there's a proper way to log them out after that. With most browsers, the only way to log out of this type of session is to close the browser. Clearing the cache may work. I see a logout.ssjs that attempts to do just this, but if it does it wouldn't take effect until the next request comes in from that client.

    I had been using runemaster logout.ssjs and fiddling with it because it didn't actually logout, even if you close the browser and reopen it you're still logged in; unless you clear the cache and cookies etc ...

    Are you creating a web interface from scratch, or is this a mod of something that already exists?

    half of both ... I migrated a php theme I wrote for my transport management suite and am modifying it for js, ssjs, xjs and in an attempt to change the current login.ssjs and logout.ssjs I am running into the issues you mention, especially since the theme navigation remains and content is in a centre, ahem, <iframe> some, if not most, of the content is ripped and modified from web/root web/templates/nightshade

    I'll just leave it with the baked in stock login.ssjs and forget logouts :-Þ




    2 wrongs don't make a right, but 3 left turns will get you back on the freeway!

    ---
    þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81
  • From Mortifis@VERT/ALLEYCAT to echicken on Saturday, February 16, 2019 20:37:39
    Re: Re: Dump Globals
    By: Mortifis to echicken on Sat Feb 16 2019 15:33:53


    Are you creating a web interface from scratch, or is this a mod of something that already exists?


    I have a basic running model at http://ephram.synchro.net
    2 wrongs don't make a right, but 3 left turns will get you back on the freeway!

    ---
    þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81