- FlashROM Support for LC2 and newer.
- FlashROM system can handle local files, or proxy from server (default). No need to have a local FlashROM collection!
- Added 'verbosity' configuration option
- Update HTML Mode to async fileRead
- Config option for sending tellyscripts or not
- Config option to mask SSIDs in console log
- Update wtv-home:/home and wtv-home:/zefie
- Update .gitignore
- Add wtv-music:/demo/index courtesy of MattMan69
- Update HTML Mode to async fileRead
- Update Raw TXT Mode to async fileRead
- Replaced .async.js feature with defining `request_is_async` in standard .js script
- Cleaned up code a bit
- Moved global var 'query' to 'request_headers.query'
- Tidied ServiceDeps
- Upgraded wtv-log:/log to async, now also logs query arguments, saves to .txt for easier reading.
This commit is contained in:
zefie
2021-07-17 19:32:35 -04:00
parent 87bd990383
commit a6f8674a0a
160 changed files with 1383 additions and 382 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@@ -0,0 +1,74 @@
request_is_async = true;
var request_path = unescape(request_headers.query.path);
headers = "200 OK\n"
if (request_headers.query.raw) {
if ((/\.brom$/).test(request_path)) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
else headers += "Content-Type: binary/x-wtv-flashblock";
if (services_configured.services[service_name].use_zefie_server) {
// get flashrom files from archive.midnightchannel.net
var options = {
host: "archive.midnightchannel.net",
path: "/zefie/files/wtv-flashrom/" + request_path,
timeout: 5000,
method: 'GET'
}
const req = https.request(options, function (res) {
var data_hex = '';
res.setEncoding('hex');
res.on('data', d => {
data_hex += d;
})
res.on('end', function () {
if (!zquiet) console.log(` * Zefie's FlashROM Server HTTP Status: ${res.statusCode} ${res.statusMessage}`)
if (res.statusCode == 200) {
data = Buffer.from(data_hex, 'hex');
} else if (res.statusCode == 404) {
var errpage = doErrorPage(404, "The service could not find the requested ROM on zefie's server.")
headers = errpage[0];
data = errpage[1];
} else {
var errpage = doErrorPage(400)
headers = errpage[0];
data = errpage[1];
}
sendToClient(socket, headers, data);
});
});
req.end();
} else {
// use local flashrom files);
var flashrom_file_path = service_dir + '/' + request_path;
try {
fs.readFile(flashrom_file_path, null, function (err, data) {
if (err) {
errpage = doErrorPage(400)
headers = errpage[0];
data = err.toString();
}
sendToClient(socket, headers, data);
});
} catch (e) {
var errpage = doErrorPage(404, "The service could not find the requested ROM.")
headers = errpage[0];
data = errpage[1];
sendToClient(socket, headers, data);
}
}
} else {
// no support for bf0app yet, but here we send the client to initiate-lc2-download
// to get the rom image
if (request_headers.query.path) {
headers += "Content-type: text/html\n"
headers += "wtv-visit: wtv-flashrom:/initiate-lc2-download?path=" + request_headers.query.path;
data = '';
} else {
var errpage = doErrorPage(404)
headers = errpage[0];
data = errpage[1];
}
sendToClient(socket, headers, data);
}

View File

@@ -2,11 +2,106 @@
// - ready query param to get flashrom path, check for its existance
// - handle last part to redirect to lc2-download-complete
// - handle failures
request_is_async = true;
headers = `200 OK
if (!request_headers.query.path) {
var errpage = doErrorPage(400);
headers = errpage[0];
data = errpage[1];
} else {
var request_path = unescape(request_headers.query.path);
if (services_configured.services[service_name].use_zefie_server) {
// read first 256 bytes of flashrom file from archive.midnightchannel.net
// to get `flashrom_message` and `numparts` if missing
var options = {
host: "archive.midnightchannel.net",
path: "/zefie/files/wtv-flashrom/" + request_path,
method: 'GET',
timeout: 5000,
headers: {
'Range': 'bytes=0-256'
}
}
var chunk;
const req = https.request(options, function (res) {
var data = '';
res.setEncoding('hex');
res.on('data', function (d) {
data += d;
});
res.on('error', function (e) {
console.log(" * Upstream FlashROM Error:", e);
var errpage = doErrorPage(400)
headers = errpage[0];
data = errpage[1];
sendToClient(socket, headers, data);
});
res.on('end', function () {
if (res.statusCode == 206) {
var flashrom_message = new Buffer.from(data.substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
processLC2DownloadPage(request_headers.query.path, flashrom_message, (request_headers.query.numparts || null));
return;
} else if (res.statusCode == 404) {
var errpage = doErrorPage(404, "The service could not find the requested ROM on zefie's server.")
headers = errpage[0];
data = errpage[1];
} else {
var errpage = doErrorPage(400)
headers = errpage[0];
data = errpage[1];
}
sendToClient(socket, headers, data);
});
});
req.end();
} else {
// use local flashrom files
var flashrom_file_path = service_dir + '/' + request_path;
fs.readFile(flashrom_file_path, null, function (err, data) {
try {
var data_128 = new Buffer.alloc(128);
data.copy(data_128, 0, 0, 128);
var flashrom_message = new Buffer.from(data_128.toString('hex').substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
processLC2DownloadPage(request_headers.query.path, flashrom_message, (request_headers.query.numparts || null));
} catch (e) {
var errpage = doErrorPage(404, "The service could not find the requested ROM.")
headers = errpage[0];
data = errpage[1];
sendToClient(socket, headers, data);
}
});
}
}
async function processLC2DownloadPage(path, flashrom_message, numparts = null) {
if (numparts != null) var flashrom_numparts = parseInt(numparts);
if (!flashrom_numparts) flashrom_numparts = flashrom_message.substring(flashrom_message.length - 4).replace(/\D/g, '');
var ind = new Array();
ind[0] = (path.indexOf("part") + 4);
ind[1] = (path.indexOf(".", ind[0]) + 1);
var flashrom_part_num = path.substr(ind[0], (path.length - ind[1]));
var flashrom_lastpart = (flashrom_numparts == (parseInt(flashrom_part_num) + 1)) ? true : false;
var flashrom_rompath = 'wtv-flashrom:/get-by-path?path=' + path + '&raw=true';
var flashrom_isboot = (/\.brom$/).test(path);
if (flashrom_lastpart) {
flashrom_next_rompath = "wtv-flashrom:/lc2-download-complete?";
} else {
var flashrom_next_part_num = (parseInt(flashrom_part_num) + 1);
if (flashrom_next_part_num < 10) flashrom_next_part_num = "00" + flashrom_next_part_num; // 1s
else if (flashrom_next_part_num >= 10 && flashrom_next_part_num < 100) flashrom_next_part_num = "0" + flashrom_next_part_num; // 10s
var flashrom_next_rompath = flashrom_rompath.replace("part"+flashrom_part_num, "part"+flashrom_next_part_num).replace('get-by-path', 'get-lc2-page').replace("&raw=true", "&numparts=" + parseInt(flashrom_numparts));
}
if (!flashrom_part_num || !flashrom_lastpart || !flashrom_rompath || !flashrom_next_rompath || !flashrom_isboot) {
headers = `200 OK
Content-type: text/html`
data = `<html>
data = `<html>
<head>
<title>
Updating
@@ -18,18 +113,22 @@ 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="wtv-flashrom:/ROMCache/HackTVLogoJewel.gif" width=87 height=67>
<td width=20 valign=top align=left bgcolor="3B3A4D">
<img src="wtv-flashrom:/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="wtv-flashrom:/ROMCache/Spacer.gif" width=1 height=4>
<br>
Updating now...
Updating now
</shadow>
</blackface>
</font>
<tr>
<td colspan=12 width=560 height=10 valign=top align=left>
<img src="wtv-flashrom:/ROMCache/S40H1.gif" width=560 height=6>
<tr>
<td width=104 height=10 valign=top align=left>
<td width=20 valign=top align=left>
@@ -49,38 +148,37 @@ Updating now...
<td width=20 valign=middle align=center>
<td colspan=9 width=100 height=258 valign=top align=left>
<font size=+1>
Your Internet Receiver is being<br>updated automatically.
Your WebTV Unit is being<br>updated automatically.
<p> <font size=+1>
This will take a while, and then<br> your unit will reboot.<br><br>
This will take a while, and<br>then you can use your WebTV again.
`;
if (flashrom_isboot && flashrom_part == 16) {
data += `<p>
if (flashrom_isboot && parseInt(flashrom_part_num) == 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>
</table>
<table width="100%">
<tr>
<td align="left"><font size="-1" color="#D6DFD0"><small>&nbsp; &nbsp; Receiving part ${flashrom_part} of ${flashrom_total_parts}</small></font></td>
<td align="right"><font size="-1" color="#D6DFD0"><small>v${flashrom_version} (${flashrom_type}) &nbsp; &nbsp;</small></font></td>
</tr>
</table>
<center>
<upgradeblock width=520 height=15
${nextrompath}
errorurl="wtv-flashrom:/lc2-download-failed"
blockurl="wtv-flashrom:/${flashrom_rompath}
lastblock=${flashrom_lastpart}
curblock="${flashrom_part}"
totalblocks="${flashrom_total_parts}"></center>
}
data += `
</font>
<br><br><br><br><br>
<upgradeblock width=280 height=15
nexturl="${flashrom_next_rompath}"
errorurl="wtv-flashrom:/lc2-download-failed?"
blockurl="${flashrom_rompath}"
lastblock="${flashrom_lastpart}"
curblock="` + (parseInt(flashrom_part_num) + 1) + `"
totalblocks="${flashrom_numparts}">
<font size="-1" color="#D6DFD0">
<br>
<img src="wtv-flashrom:/ROMCache/Spacer.gif" width=2 height=10><br>
${flashrom_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="wtv-flashrom:/ROMCache/Spacer.gif" width=436 height=1>
<tr>
<td width=104 valign=middle align=center>
<td width=20 valign=middle align=center>
@@ -89,6 +187,7 @@ totalblocks="${flashrom_total_parts}"></center>
<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="wtv-flashrom:/ROMCache/Spacer.gif" width=436 height=1>
<tr>
<td width=104 valign=middle align=center>
<td width=20 valign=middle align=center>
@@ -109,4 +208,11 @@ totalblocks="${flashrom_total_parts}"></center>
<td width=20 valign=middle align=center>
</table>
</body>
</html>`
</html>`;
} else {
var errpage = doErrorPage(400)
headers = errpage[0];
data = errpage[1];
}
sendToClient(socket, headers, data);
}

View File

@@ -0,0 +1,11 @@
if (request_headers.query.path) {
headers = "300 OK\n";
headers += "wtv-visit: wtv-flashrom:/get-lc2-page?path=" + request_headers.query.path + "\n";
headers += "Location: wtv-flashrom:/get-lc2-page?path=" + request_headers.query.path + "\n";
headers += "Content-type: text/html";
data = '';
} else {
var errpage = doErrorPage(400)
headers = errpage[0];
data = errpage[1];
}

View File

@@ -23,7 +23,7 @@ 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="wtv-flashrom:/ROMCache/MSNLogo.gif" width=87 height=67>
<img src="wtv-flashrom:/ROMCache/HackTVLogoJewel.gif" width=87 height=67>
<td width=20 valign=top align=left bgcolor="3B3A4D">
<img src="wtv-flashrom:/ROMCache/Spacer.gif" width=1 height=1>
<td colspan=10 width=436 valign=middle align=left bgcolor="3B3A4D">

View File

@@ -1,50 +0,0 @@
<html>
<head>
<title>
Updating failed
</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="wtv-flashrom:/ROMCache/MSNLogo.gif" width=87 height=67>
<td width=20 valign=top align=left bgcolor="3B3A4D">
<img src="wtv-flashrom:/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="wtv-flashrom:/ROMCache/Spacer.gif" width=1 height=4>
<br>
Updated failed
</shadow>
</blackface>
</font>
<tr>
<td colspan=12 width=560 height=10 valign=top align=left>
<img src="wtv-flashrom:/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>
Update failed, gomennasai.
</body>
</html>

View File

@@ -0,0 +1,140 @@
var error = '';
if (request_headers.query.error) {
switch (request_headers.query.error) {
case "1":
error = "uncompression failed";
break;
case "2":
error = "upgrade write failed";
break;
case "3":
error = "signature verification failed";
break;
case "4":
error = "cannot upgrade bootstrap";
break;
case "5":
error = "out of memory";
break;
case "-7":
error = "response error";
break;
case "-20":
error = "timed out";
break;
case "99":
error = "test code";
break;
default:
error = "unknown error";
break;
}
}
var try_again_url = 'wtv-flashrom:/willie';
var try_again_url_path = ''
var try_again_url_start_time = parseInt(new Date().toUTCString()) / 1000;
headers = `200 OK
Content-type: text/html`
data = `<html>
<head>
<display switchtowebmode nooptions nostatus skipback clearback>
<title>Update failed</title>
</head>
<body noscroll bgcolor="#191919" text="#42CC55" link="36d5ff"
hspace=0 vspace=0 transition=none fontsize="large">
<table cellspacing=0 cellpadding=0>
<tr>
<td width=104 height=74 valign=middle align=center bgcolor="3B3A4D">
<img src="wtv-flashrom:/ROMCache/HackTVLogoJewel.gif" width=87 height=67>
<td width=20 valign=top align=left bgcolor="3B3A4D">
<img src="wtv-flashrom:/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="wtv-flashrom:/ROMCache/Spacer.gif" width=1 height=4>
<br>
Updating failed
</shadow>
</blackface>
</font>
<tr>
<td colspan=12 width=560 height=10 valign=top align=left>
<img src="wtv-flashrom:/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="${try_again_url}">
<input type="hidden" name="clear_cache" value="true">
<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>
We ran into a technical problem while updating
your unit. (Error: ${error})
Choose <b>Try Again</b> to try again now.
<p><font size=+1>Press the <b>power</b> button to switch off your unit.
<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="2B2B2B">
<img src="wtv-flashrom:/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="0D0D0D">
<img src="wtv-flashrom:/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=left>
<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="#E7CE4A">
<shadow>
<input selected
name="Try Again"
value="Try Again"
type=submit Value=TryAgain name="Try Again"
borderimage="file://ROM/Borders/ButtonBorder2.bif" usestyle width=110>
</shadow>
</font>
</form>
</table>
<td width=20 valign=middle align=center>
</table>
</body>
</html>`;

View File

@@ -1,35 +0,0 @@
// willie is just a graphical frontend to a list of ROMs
// the rest of the scripts should work if you manually link to a ROM, and actually have it.
var proxy_query = '';
if (query['flash']) delete query['flash'];
if (query['vflash']) delete query['vflash'];
for (const [key, value] of Object.entries(query)) {
proxy_query += "&" + key + "=" + value;
}
console.log(proxy_query);
var options = {
host: "wtv.zefie.com",
path: "/willie.php?pflash=" + getSessionData(socket_session_data[socket.id].ssid, 'wtv-client-rom-type') + proxy_query,
method: 'GET'
}
headers = "200 OK\nContent-type: text/html";
const req = http.request(options, function (res) {
data = '';
console.log(` * Upstream HTTP StatusCode: ${res.statusCode}`)
res.on('data', d => {
data += d;
})
res.on('end', function () {
sendToClient(socket, headers, data);
});
});
req.end();

View File

@@ -0,0 +1,50 @@
// willie is just a graphical frontend to a list of ROMs
// the rest of the scripts should work if you manually link to a ROM, and actually have it.
request_is_async = true;
var proxy_query = '';
if (request_headers.query.flash) delete request_headers.query.flash;
if (request_headers.query.vflash) delete request_headers.query.vflash;
if (request_headers.query.pflash) delete request_headers.query.pflash;
for (const [key, value] of Object.entries(request_headers.query)) {
proxy_query += "&" + key + "=" + value;
}
if (!services_configured.services[service_name].use_zefie_server) {
proxy_query += "&minisrv_local_mode=true";
}
var options = {
host: "wtv.zefie.com",
path: "/willie.php?minisrv=true&pflash=" + getSessionData(socket_session_data[socket.id].ssid, 'wtv-client-rom-type') + proxy_query,
timeout: 5000,
method: 'GET'
}
headers = "200 OK\nContent-type: text/html";
const req = https.request(options, function (res) {
data = '';
res.on('data', d => {
data += d;
});
res.on('error', function (e) {
if (!zquiet) console.log(" * Upstream Ultra Willies HTTP Error:", e);
var errpage = doErrorPage(400)
headers = errpage[0];
data = errpage[1];
sendToClient(socket, headers, data);
});
res.on('end', function () {
if (!zquiet) console.log(" * Upstream Ultra Willies HTTP Response:", res.statusCode, res.statusMessage);
if (request_headers.query.clear_cache) {
headers += "\nwtv-expire-all: wtv-flashrom";
}
sendToClient(socket, headers, data);
});
});
req.end();