Commit 1decdc69 authored by Rob Swindell's avatar Rob Swindell 💬

External program "use shell" option can be used to use a new JS context

Rather than introduce yet-another-external-program/config flag to enable
the "new JS run-time/context" per invocation of any particular JS command,
I'm using the XTRN/EX_SH ("Use Shell") option as it had no function for
JavaScript command-lines and the concept is similar.

So if you want to invoke a JS external program/timed-event in its own
"sandbox", enable the "Use Shell / New Context" option for that
program/command in SCFG. There may be performance penalties when running
JS mods in this way, but you get the benefit of isolating one JS module
from all others, if/when necessary.
parent 25625186
Pipeline #30 failed with stage
in 5 minutes and 24 seconds
......@@ -732,13 +732,9 @@ long sbbs_t::js_execfile(const char *cmd, const char* startup_dir, JSObject* sco
return(result);
}
// Execute a JS Module in its own runtime and context
// Experimental and currently broken
long sbbs_t::js_execmodule(const char *cmd, long mode, const char* startup_dir)
// Execute a JS Module in its own temporary JS runtime and context
long sbbs_t::js_execxtrn(const char *cmd, const char* startup_dir)
{
if(!(mode&EX_JS_CX))
return js_execfile(cmd, startup_dir);
JSRuntime* js_runtime;
JSObject* js_glob;
JSContext* js_cx = js_init(&js_runtime, &js_glob, "XtrnModule");
......@@ -748,7 +744,6 @@ long sbbs_t::js_execmodule(const char *cmd, long mode, const char* startup_dir)
JS_RemoveObjectRoot(js_cx, &js_glob);
JS_ENDREQUEST(js_cx);
JS_DestroyContext(js_cx);
lprintf(LOG_DEBUG,"JavaScript: Destroying runtime");
jsrt_Release(js_runtime);
return result;
}
......
......@@ -407,7 +407,7 @@ public:
JSObject* js_hotkey_glob;
js_callback_t js_callback;
long js_execfile(const char *fname, const char* startup_dir, JSObject* scope = NULL, JSContext* cx = NULL, JSObject* glob = NULL);
long js_execmodule(const char *fname, long mode, const char* startup_dir);
long js_execxtrn(const char *fname, const char* startup_dir);
JSContext* js_init(JSRuntime**, JSObject**, const char* desc);
void js_cleanup(void);
bool js_create_user_objects(JSContext*, JSObject* glob);
......
......@@ -40,6 +40,21 @@
char *daystr(char days);
static void hotkey_cfg(void);
static char* use_shell_opt = "Use Shell / New Context";
static char* use_shell_help =
"`Use System Shell or New JavaScript Context to Execute:`\n"
"\n"
"If this command-line requires the system command shell to execute\n"
"(e.g. uses pipes/redirection or invokes a Unix shell script or\n"
"DOS/Windows batch/command file), then set this option to ~Yes~.\n"
"\n"
"If this command-line is invoking a Synchronet JavaScript module\n"
"(e.g. it begins with a '`?`' character), then setting this option to ~Yes~\n"
"will enable the creation and initialization of a new JavaScript run-time\n"
"context for it to execute within, for every invocation."
;
static char* use_shell_prompt = "Use System Shell or New JavaScript Context to Execute";
#define CUT_XTRNSEC_NUM USHRT_MAX
static bool new_timed_event(unsigned new_event_num)
......@@ -509,7 +524,7 @@ void tevents_cfg()
,cfg.event[i]->misc&EVENT_FORCE ? "Yes":"No");
sprintf(opt[k++],"%-32.32s%s","Native Executable"
,cfg.event[i]->misc&EX_NATIVE ? "Yes" : "No");
sprintf(opt[k++],"%-32.32s%s","Use Shell to Execute"
sprintf(opt[k++],"%-32.32s%s",use_shell_opt
,cfg.event[i]->misc&XTRN_SH ? "Yes" : "No");
sprintf(opt[k++],"%-32.32s%s","Background Execution"
,cfg.event[i]->misc&EX_BG ? "Yes" : "No");
......@@ -798,14 +813,9 @@ void tevents_cfg()
case 12:
k=(cfg.event[i]->misc&XTRN_SH) ? 0:1;
uifc.helpbuf=
"`Use Shell to Execute Command:`\n"
"\n"
"If this command-line requires the system command shell to execute (Unix\n"
"shell script or DOS/Windows batch/command file), set this option to ~Yes~.\n"
;
uifc.helpbuf = use_shell_help;
k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0
,"Use System Command Shell",uifcYesNoOpts);
,use_shell_prompt, uifcYesNoOpts);
if(!k && !(cfg.event[i]->misc&XTRN_SH)) {
cfg.event[i]->misc|=XTRN_SH;
uifc.changes=TRUE;
......@@ -1006,7 +1016,7 @@ void xtrn_cfg(uint section)
==(XTRN_STDIO|XTRN_NOECHO) ? ", No Echo" : nulstr);
sprintf(opt[k++],"%-27.27s%s","Native Executable"
,cfg.xtrn[i]->misc&XTRN_NATIVE ? "Yes" : "No");
sprintf(opt[k++],"%-27.27s%s","Use Shell to Execute"
sprintf(opt[k++],"%-27.27s%s",use_shell_opt
,cfg.xtrn[i]->misc&XTRN_SH ? "Yes" : "No");
sprintf(opt[k++],"%-27.27s%s","Modify User Data"
,cfg.xtrn[i]->misc&MODUSERDAT ? "Yes" : "No");
......@@ -1055,6 +1065,9 @@ void xtrn_cfg(uint section)
"`Online Program Configuration:`\n"
"\n"
"This menu is for configuring the selected online program.\n"
"\n"
"For detailed instructions for configuring BBS doors, see\n"
"`http://wiki.synchro.net/howto:door:index`"
;
switch(uifc.list(WIN_SAV|WIN_ACT|WIN_MID,0,0,60,&opt_dflt,&sub_bar,cfg.xtrn[i]->name
,opt)) {
......@@ -1266,14 +1279,9 @@ void xtrn_cfg(uint section)
break;
case 11:
k=(cfg.xtrn[i]->misc&XTRN_SH) ? 0:1;
uifc.helpbuf=
"`Use Shell to Execute Command:`\n"
"\n"
"If this command-line requires the system command shell to execute, (Unix\n"
"shell script or DOS batch file), set this option to ~Yes~.\n"
;
uifc.helpbuf = use_shell_help;
k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0
,"Use Shell",uifcYesNoOpts);
,use_shell_prompt,uifcYesNoOpts);
if(!k && !(cfg.xtrn[i]->misc&XTRN_SH)) {
cfg.xtrn[i]->misc|=XTRN_SH;
uifc.changes=TRUE;
......@@ -1667,7 +1675,7 @@ void xedit_cfg()
==(XTRN_STDIO|WWIVCOLOR) ? ", WWIV Color" : nulstr);
sprintf(opt[k++],"%-32.32s%s","Native Executable"
,cfg.xedit[i]->misc&XTRN_NATIVE ? "Yes" : "No");
sprintf(opt[k++],"%-32.32s%s","Use Shell to Execute"
sprintf(opt[k++],"%-32.32s%s",use_shell_opt
,cfg.xedit[i]->misc&XTRN_SH ? "Yes" : "No");
sprintf(opt[k++],"%-32.32s%s","Record Terminal Width"
,cfg.xedit[i]->misc&SAVECOLUMNS ? "Yes" : "No");
......@@ -1852,14 +1860,9 @@ void xedit_cfg()
break;
case 6:
k=(cfg.xedit[i]->misc&XTRN_SH) ? 0:1;
uifc.helpbuf=
"`Use Shell to Execute Command:`\n"
"\n"
"If this command-line requires the system command shell to execute, (Unix \n"
"shell script or DOS batch file), set this option to ~Yes~.\n"
;
uifc.helpbuf = use_shell_help;
k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0
,"Use Shell",uifcYesNoOpts);
,use_shell_prompt, uifcYesNoOpts);
if(!k && !(cfg.xedit[i]->misc&XTRN_SH)) {
cfg.xedit[i]->misc|=XTRN_SH;
uifc.changes=TRUE;
......
......@@ -264,8 +264,10 @@ static bool native_executable(scfg_t* cfg, const char* cmdline, long mode)
return(exec_bin(cmdline+1,&main_csi,startup_dir))
#ifdef JAVASCRIPT
#define XTRN_LOADABLE_JS_MODULE(cmdline,mode,startup_dir) \
if(cmdline[0]=='?') /* JavaScript */ \
return(js_execmodule(cmdline+1,mode,startup_dir))
if(cmdline[0]=='?' && (mode&EX_SH)) \
return(js_execxtrn(cmdline+1, startup_dir)) \
if(cmdline[0]=='?') \
return(js_execfile(cmdline+1,startup_dir))
#else
#define XTRN_LOADABLE_JS_MODULE
#endif
......
......@@ -1598,7 +1598,7 @@ bool sbbs_t::exec_xtrn(uint xtrnnum)
mode|=EX_STDIO;
else if(cfg.xtrn[xtrnnum]->misc&XTRN_CONIO)
mode|=EX_CONIO;
mode|=(cfg.xtrn[xtrnnum]->misc&(XTRN_CHKTIME|XTRN_NATIVE|XTRN_NOECHO|WWIVCOLOR|XTRN_JS_CX));
mode|=(cfg.xtrn[xtrnnum]->misc&(XTRN_CHKTIME|XTRN_NATIVE|XTRN_NOECHO|WWIVCOLOR));
if(cfg.xtrn[xtrnnum]->misc&MODUSERDAT) { /* Delete MODUSER.DAT */
SAFEPRINTF(str,"%sMODUSER.DAT",dropdir); /* if for some weird */
removecase(str); /* reason it's there */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment