Files
minisrv/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/get-lc2-page.js
zefie 6f2fa1d510 v0.9.16
- numerous bug fixes
 - improve session retention
 - use wtv-head-waiter:/relogin for boot url
   - viewer seems to retain only wtv-* and wtv-head-waiter, so lets try to be closer to protocol and boot with a wtv-head-waiter address instead of wtv-1800
   - we still handle via wtv-1800 but we accept wtv-head-waiter:/relogin and send the client on its way to the relogin path
 - update wtv-home:/home
   - remove spacing in favor of right alignment
   - add compression status
 - guest mode session store update
   - allow calls to saveSessionData() but do not actually write if user is guest
   - saveSessionData() returns true even if guest, because false is meant to define an error
   - You can also use SaveIfRegistered(), this will return false on both saveSessionData() errors AND guest mode;
   - if you want to block guests, check for isRegistered() and block the request if it is false
   - otherwise this update will allow all tools (including any logins) to work with guest mode, but the stored SessionData will not be persistently saved, and lost when the cleanup timeout hits (default 3 min), or the server is restarted.
 - more accurately mimic WTVP by accepting URLs without /
 - use service-style cookie links on tricks
 - add catchall system & http pc server
   - define a catchall name to run globally or per service
   - catchall must be javascript, but not necessarily a .js file
   - catchall can request async mode
   - catchall will catch any non-existing requests under its directory
   - see wtv-flashrom:/content/content-serve.js as an example, which will catch wtv-flashrom:/content/ URLs.
 - http pc: sends HTTP/1.0 to PC clients
   - can be disabled with `pc_server_hidden_service_enabled`: false
   - can change servicevault path by changing string of pc_server_hidden_service
   - get.js in default PC service vault to get any WTV Url on the service
 - flashrom system updates
   - fix bugs
   - more WNI-like flow path
   - make scripts use `service_name` variable so that they should work in a renamed service (eg not wtv-flashrom, untested)
 - rewrite wtv-disk system
   - move wtv-update to wtv-disk
   - allow accessing wtv-disk:/sync?group=&diskmap=
   - rewrite Download List generation to be more proper
   - only send files if diskmap has changed
   - allow force redownload with &force=true
2022-11-29 08:27:57 -05:00

150 lines
5.0 KiB
JavaScript

const WTVFlashrom = require("./WTVFlashrom.js");
var wtvflashrom;
request_is_async = true;
if (!request_headers.query.path) {
var errpage = doErrorPage(400);
headers = errpage[0];
data = errpage[1];
} else {
var wtvflashrom = new WTVFlashrom(service_vaults, service_name, minisrv_config.services[service_name].use_zefie_server, minisrv_config.services[service_name].debug);
var request_path = request_headers.query.path;
// read flashrom header info into array using WTVFlashrom class
wtvflashrom.getFlashromMeta(request_path, function (data) {
processLC2DownloadPage(request_headers.query.path, data, (request_headers.query.numparts || null));
});
}
async function processLC2DownloadPage(path, flashrom_info, numparts = null) {
if (numparts != null) flashrom_info.part_count = parseInt(numparts);
if (!flashrom_info.part_count) flashrom_info.part_count = parseInt(flashrom_info.message.substring(flashrom_info.message.length - 4).replace(/\D/g, ''));
if (!flashrom_info.part_number || !flashrom_info.is_last_part || !flashrom_info.rompath || !flashrom_info.next_rompath || !flashrom_info.is_bootrom) {
if (!flashrom_info.is_last_part || request_headers.query.last_part) {
flashrom_info.next_rompath = request_headers.request_url.replace(escape(request_headers.query.path), escape(flashrom_info.next_rompath.replace(service_name+":/","")));
}
headers = `200 OK
Content-type: text/html`
data = `<html>
<head>
<title>
Updating
</title>
<display switchtowebmode transition=none nostatus nooptions skipback clearback>
</head>
<body noscroll bgcolor="#191919" text="#42CC55" link="36d5ff"
hspace=0 vspace=0 fontsize="large">
<table cellspacing=0 cellpadding=0>
<tr>
<td width=104 height=74 valign=middle align=center bgcolor="3B3A4D">
<img src="${minisrv_config.config.service_logo}" width=87 height=67>
<td width=20 valign=top align=left bgcolor="3B3A4D">
<img src="${service_name}:/ROMCache/Spacer.gif" width=1 height=1>
<td colspan=10 width=436 valign=middle align=left bgcolor="3B3A4D">
<font color="D6DFD0" size="+2">
<blackface>
<shadow>
<img src="${service_name}:/ROMCache/Spacer.gif" width=1 height=4>
<br>
Updating now
</shadow>
</blackface>
</font>
<tr>
<td colspan=12 width=560 height=10 valign=top align=left>
<img src="${service_name}:/ROMCache/S40H1.gif" width=560 height=6>
<tr>
<td width=104 height=10 valign=top align=left>
<td width=20 valign=top align=left>
<td width=67 valign=top align=left>
<td width=20 valign=top align=left>
<td width=67 valign=top align=left>
<td width=20 valign=top align=left>
<td width=67 valign=top align=left>
<td width=20 valign=top align=left>
<td width=67 valign=top align=left>
<td width=20 valign=top align=left>
<td width=68 valign=top align=left>
<td width=20 valign=top align=left>
<form action="client:poweroff">
<tr>
<td width=104 valign=middle align=center>
<td width=20 valign=middle align=center>
<td colspan=9 width=100 height=258 valign=top align=left>
<font size=+1>
Your WebTV Unit is being<br>updated automatically.
<p> <font size=+1>
This will take a while, and<br>then you can use your WebTV again.
`;
if (flashrom_info.is_bootrom && flashrom_info.part_number == 16) {
data += `<p>
The system will pause for about 30 seconds at the end of this
update. Please <strong>do not</strong> interrupt the system
during this time.
`
}
data += `
</font>
<br><br><br><br><br>
<upgradeblock width=280 height=15
nexturl="${flashrom_info.next_rompath}"
errorurl="${service_name}:/lc2-download-failed?"
blockurl="${flashrom_info.rompath}"
lastblock="${flashrom_info.is_last_part}"
curblock="` + (flashrom_info.part_number + 1) + `"
`
if (flashrom_info.part_count) {
data += `totalblocks="${flashrom_info.part_count}"`;
}
data += `>
<font size="-1" color="#D6DFD0">
<br>
<img src="${service_name}:/ROMCache/Spacer.gif" width=2 height=10><br>
${flashrom_info.message}
<br><br>
<tr>
<td width=104 valign=middle align=center>
<td width=20 valign=middle align=center>
<td colspan=10 height=2 valign=middle align=center bgcolor="#191919">
<img src="${service_name}:/ROMCache/Spacer.gif" width=436 height=1>
<tr>
<td width=104 valign=middle align=center>
<td width=20 valign=middle align=center>
<td colspan=9 height=1 valign=top align=left>
<tr>
<td width=104 valign=middle align=center>
<td width=20 valign=middle align=center>
<td colspan=10 height=2 valign=top align=left bgcolor="#191919">
<img src="${service_name}:/ROMCache/Spacer.gif" width=436 height=1>
<tr>
<td width=104 valign=middle align=center>
<td width=20 valign=middle align=center>
<td colspan=9 height=4 valign=top align=left>
<tr>
<td width=104 valign=middle align=center>
<td width=20 valign=middle align=center>
<td colspan=9 width=416 valign=top align=right>
<table cellspacing=0 cellpadding=0>
<tr>
<td width=306 valign=top align=left>
<font size="-1"><i>
</i></font><td width=112 valign=top align=right>
<font size="-1" color="#191919">
</font>
</form>
</table>
<td width=20 valign=middle align=center>
</table>
</body>
</html>`;
} else {
var errpage = doErrorPage(400)
headers = errpage[0];
data = errpage[1];
}
sendToClient(socket, headers, data);
}