fix wtv-tricks:/info, tidy up eval VM related stuff

This commit is contained in:
zefie
2022-09-26 17:20:27 -04:00
parent 8b49e1ec29
commit 6a21c4a851
2 changed files with 36 additions and 11 deletions

View File

@@ -11,7 +11,7 @@ if (client_caps) {
headers = `200 OK headers = `200 OK
Content-Type: text/html` Content-Type: text/html`
var service_ip = minisrv_config.config.service_ip
var client_label = "TODO"; var client_label = "TODO";
var boot_client_label = "TODO"; var boot_client_label = "TODO";
var wtv_system_sysconfig_str = "TODO"; var wtv_system_sysconfig_str = "TODO";
@@ -58,7 +58,7 @@ Content-Type: text/html`
<tr> <tr>
<td valign=top align=right width=150><shadow>Service:</shadow> <td valign=top align=right width=150><shadow>Service:</shadow>
<td width=10> <td width=10>
<td valign=top>${z_title} <td valign=top>${minisrv_version_string}
<tr> <tr>
<td valign=top align=right><shadow>Client:</shadow> <td valign=top align=right><shadow>Client:</shadow>
<td width=10> <td width=10>

View File

@@ -110,21 +110,34 @@ async function processPath(socket, service_vault_file_path, request_headers = ne
var usingSharedROMCache = false; var usingSharedROMCache = false;
// Here we define the ServiceVault Script Context Object // Here we define the ServiceVault Script Context Object
// The ServiceVault scripts will only be allowed to access the following variables. // The ServiceVault scripts will only be allowed to access the following variables.
// Furthermore, only modifications to "headers", "data", "ssid_sessions" and "socket_sessions" will be saved. // Furthermore, only modifications to variables in `updateFromVM` will be saved.
// Example: an attempt to change "minisrv_config" from a ServiceVault script would be discarded // Example: an attempt to change "minisrv_config" from a ServiceVault script would be discarded
// node core functions/vars
var contextObj = { var contextObj = {
console: console, console: console,
require: require, require: require,
__dirname: __dirname
}
// Our modules
contextObj = {
...contextObj,
wtvmime: wtvmime, wtvmime: wtvmime,
http: http, http: http,
https: https, https: https,
wtvshared: wtvshared, wtvshared: wtvshared,
clientShowAlert: clientShowAlert, clientShowAlert: clientShowAlert,
WTVClientSessionData: WTVClientSessionData, WTVClientSessionData: WTVClientSessionData,
WTVClientCapabilities: WTVClientCapabilities,
strftime: strftime, strftime: strftime,
CryptoJS: CryptoJS, CryptoJS: CryptoJS,
fs: fs, fs: fs
__dirname: __dirname, }
// Our variables
contextObj = {
...contextObj,
minisrv_config: minisrv_config, minisrv_config: minisrv_config,
getServiceString: getServiceString, getServiceString: getServiceString,
sendToClient: sendToClient, sendToClient: sendToClient,
@@ -138,10 +151,24 @@ async function processPath(socket, service_vault_file_path, request_headers = ne
headers: headers, headers: headers,
data: data, data: data,
request_is_async: request_is_async, request_is_async: request_is_async,
minisrv_version_string: z_title
}
// Our prototype overrides
contextObj = {
...contextObj,
Buffer: Buffer, Buffer: Buffer,
String: String, String: String,
Object: Object Object: Object
} }
var updateFromVM = [
["headers", "headers"],
["data", "data"],
["ssid_sessions", "ssid_sessions"],
["socket_sessions", "socket_sessions"]
];
try { try {
service_vaults.forEach(function (service_vault_dir) { service_vaults.forEach(function (service_vault_dir) {
if (service_vault_found) return; if (service_vault_found) return;
@@ -305,11 +332,9 @@ async function processPath(socket, service_vault_file_path, request_headers = ne
}); });
// Here we read back certain data from the ServiceVault Script Context Object // Here we read back certain data from the ServiceVault Script Context Object
headers = contextObj.headers; updateFromVM.forEach((item) => {
data = contextObj.data; eval(item[0] +' = contextObj["'+item[1]+'"]');
request_is_async = contextObj.request_is_async; })
ssid_sessions = contextObj.ssid_sessions;
socket_sessions = contextObj.socket_sessions;
if (request_is_async && !minisrv_config.config.debug_flags.quiet) console.log(" * Script requested Asynchronous mode"); if (request_is_async && !minisrv_config.config.debug_flags.quiet) console.log(" * Script requested Asynchronous mode");
} }