v0.9.11
- added example docker-compose for minisrv + webone - update: wtv-home:/home: reduce size of title to fit longer version numbers - update: wtv-chat:/home: fix colors - update: login system: do not send tellyscript nor login headers to reconnecting (eg client:redial) client - fix: fixed tellyscript path for wtv-1800:/noflash (bf0app braindead) - update flashrom subsystem: - moved duplicate code into WTVFlashrom class - smarter part information detection - http(s) proxy updates: - allow ~ character - fix HTTPS when using HTTP proxy - include example webone.conf for external HTTP Proxy - update: app.js: enable graceful shutdown with SIGTERM - update: add service ip to wtv-tricks:/info
This commit is contained in:
@@ -25,7 +25,7 @@ wtv-client-time-zone: GMT -0000
|
||||
wtv-client-time-dst-rule: GMT
|
||||
wtv-client-date: `+ strftime("%a, %d %b %Y %H:%M:%S", new Date(new Date().toUTCString())) + ` GMT`;
|
||||
|
||||
var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/BF0APP/bf0app_boot_uncompressed.tok";
|
||||
var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/bf0app/bf0app_WTV_18006138199.tok";
|
||||
|
||||
if (file_path) {
|
||||
request_is_async = true;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
var gourl = "wtv-head-waiter:/login?";
|
||||
if (request_headers.query.relogin) gourl += "relogin=true";
|
||||
if (request_headers.query.reconnect) gourl += "reconnect=true";
|
||||
|
||||
if (socket.ssid) {
|
||||
if (ssid_sessions[socket.ssid].data_store) {
|
||||
@@ -46,7 +47,7 @@ if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
|
||||
var send_tellyscripts = (minisrv_config.services[service_name].send_tellyscripts && !request_headers.query.relogin);
|
||||
var wtv_script_id = parseInt(ssid_sessions[socket.ssid].get("wtv-script-id"));
|
||||
var bootrom = ssid_sessions[socket.ssid].get("wtv-client-bootrom-version");
|
||||
if (request_headers.query.relogin && wtv_script_id != 0) send_tellyscripts = false;
|
||||
if ((request_headers.query.reconnect || request_headers.query.relogin) && wtv_script_id != 0) send_tellyscripts = false;
|
||||
if (send_tellyscripts) {
|
||||
if (minisrv_config.services[service_name].send_tellyscript_ssid_whitelist) {
|
||||
var send_telly_to_ssid = (minisrv_config.services[service_name].send_tellyscript_ssid_whitelist.findIndex(element => element == socket.ssid) != -1)
|
||||
@@ -101,9 +102,13 @@ if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
|
||||
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
||||
}
|
||||
|
||||
if (request_headers["wtv-ticket"]) {
|
||||
if (request_headers["wtv-ticket"] && !request_headers.query.reconnect) {
|
||||
gourl = "wtv-head-waiter:/login-stage-two?relogin=true";
|
||||
}
|
||||
}
|
||||
|
||||
if (request_headers.query.reconnect) {
|
||||
gourl = null;
|
||||
}
|
||||
|
||||
|
||||
if (!file_path != null && !zquiet) console.log(" * Sending TellyScript", file_path, "on socket", socket.id);
|
||||
@@ -125,7 +130,7 @@ if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
|
||||
headers += getServiceString('wtv-flashrom') + "\n";
|
||||
if (bf0app_update) headers += "wtv-boot-url: " + gourl + "\n";
|
||||
else headers += "wtv-boot-url: wtv-1800:/preregister?relogin=true\n";
|
||||
headers += "wtv-visit: " + gourl + "\n";
|
||||
if (gourl != null) headers += "wtv-visit: " + gourl + "\n";
|
||||
if (!bf0app_update && ssid_sessions[socket.ssid].get("wtv-open-access")) headers += "wtv-open-isp-disabled: false\n";
|
||||
headers += "wtv-client-time-zone: GMT -0000\n";
|
||||
headers += "wtv-client-time-dst-rule: GMT\n"
|
||||
|
||||
@@ -107,25 +107,25 @@ Chat Home (Testing)
|
||||
<table>
|
||||
<tr>
|
||||
<td abswidth="120">Server:</td>
|
||||
<td><input width="240" bgcolor=262626 text=ffc342 cursor=cc9933 font=proportional usestyle type="text" name="host" value="${request_headers.query.host || "chat.irchat.tv"}"></td>
|
||||
<td><input width="240" bgcolor=262626 text=D6D6D6 cursor=cc9933 font=proportional type="text" name="host" value="${request_headers.query.host || "chat.irchat.tv"}"></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Port:</td>
|
||||
<td><input width="240" bgcolor=262626 text=ffc342 cursor=cc9933 font=proportional usestyle type="text" name="port" value="${request_headers.query.port || 6667}"></td>
|
||||
<td><input width="240" bgcolor=262626 text=D6D6D6 cursor=cc9933 font=proportional type="text" name="port" value="${request_headers.query.port || 6667}"></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Channel:</td>
|
||||
<td><input width="240" bgcolor=262626 text=ffc342 cursor=cc9933 font=proportional usestyle type="text" name="channel" value="${request_headers.query.channel || "WebTV"}"></td>
|
||||
<td><input width="240" bgcolor=262626 text=D6D6D6 cursor=cc9933 font=proportional type="text" name="channel" value="${request_headers.query.channel || "WebTV"}"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>IRC Nick<sup>*</sup>:</td>
|
||||
<td><input width="240" bgcolor=262626 text=ffc342 cursor=cc9933 font=proportional usestyle maxlength=16 type="text" name="nick" value="${irc_nick}"></td>
|
||||
<td><input width="240" bgcolor=262626 text=D6D6D6 cursor=cc9933 font=proportional maxlength=16 type="text" name="nick" value="${irc_nick}"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" align="right">
|
||||
<input type=submit borderimage="file://ROM/Borders/ButtonBorder2.bif" value="Connect" usestyle width=100>
|
||||
<input type=submit borderimage="file://ROM/Borders/ButtonBorder2.bif" value="Connect" text=D6D6D6 width=100>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
const WTVFlashrom = require("./WTVFlashrom.js");
|
||||
request_is_async = true;
|
||||
|
||||
// this build can be local or on zefie's server
|
||||
// to get the path from zefie's server, browse
|
||||
// https://archive.midnightchannel.net/zefie/files/wtv-flashrom/content/artemis-webtv-000/
|
||||
@@ -5,110 +8,23 @@
|
||||
// example is below
|
||||
var default_build_to_send = minisrv_config.services[service_name].bf0app_default_rom || "content/artemis-webtv-000/build7181/daily-nondebug/bf0app-part000.rom";
|
||||
|
||||
headers = "200 OK\n";
|
||||
|
||||
var request_path = "";
|
||||
var bf0app_update = true;
|
||||
if (request_headers.query.path) request_path = unescape(request_headers.query.path);
|
||||
else request_path = default_build_to_send;
|
||||
request_is_async = true;
|
||||
|
||||
if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") == "bf0app" && ssid_sessions[socket.ssid].get("wtv-client-bootrom-version") == "105") {
|
||||
// assume old classic in flash mode, override user setting and send tellyscript
|
||||
// because it is required to proceed in flash mode
|
||||
bf0app_update = true;
|
||||
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
||||
headers += "minisrv-use-carriage-return: false\n";
|
||||
}
|
||||
|
||||
function doLocalFlashROM(flashrom_file_path) {
|
||||
// use local flashrom files;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
function calculatedPath(data, path, numparts = null) {
|
||||
var data_128 = new Buffer.alloc(128);
|
||||
data.copy(data_128, 0, 0, 128);
|
||||
var flashrom_numparts = null;
|
||||
var flashrom_message = new Buffer.from(data_128.toString('hex').substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
|
||||
|
||||
if (numparts != null) 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;
|
||||
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) + "&numparts=" + parseInt(flashrom_numparts);
|
||||
}
|
||||
return flashrom_next_rompath;
|
||||
}
|
||||
|
||||
if ((/\.brom$/).test(request_path)) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
|
||||
else headers += "Content-Type: binary/x-wtv-flashblock";
|
||||
|
||||
var flashrom_file_path = null;
|
||||
Object.keys(service_vaults).forEach(function (g) {
|
||||
if (flashrom_file_path != null) return;
|
||||
flashrom_file_path = service_vaults[g] + "/" + service_name + "/" + request_path;
|
||||
if (!fs.existsSync(flashrom_file_path)) flashrom_file_path = null;
|
||||
});
|
||||
if (minisrv_config.services[service_name].use_zefie_server && !flashrom_file_path) {
|
||||
// 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];
|
||||
}
|
||||
headers += "\nwtv-visit: " + calculatedPath(data, request_path);
|
||||
sendToClient(socket, headers, data);
|
||||
});
|
||||
});
|
||||
req.end();
|
||||
} else {
|
||||
doLocalFlashROM(flashrom_file_path);
|
||||
if (!ssid_sessions[socket.ssid].data_store.WTVFlashrom) {
|
||||
ssid_sessions[socket.ssid].data_store.WTVFlashrom = new WTVFlashrom(service_vaults, service_name, minisrv_config.services[service_name].use_zefie_server, bf0app_update);
|
||||
}
|
||||
|
||||
ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) {
|
||||
sendToClient(socket, headers, data);
|
||||
});
|
||||
@@ -1,117 +1,26 @@
|
||||
const WTVFlashrom = require("./WTVFlashrom.js");
|
||||
request_is_async = true;
|
||||
|
||||
|
||||
var bf0app_update = false;
|
||||
var request_path = unescape(request_headers.query.path);
|
||||
headers = "200 OK\n"
|
||||
|
||||
function doLocalFlashROM(flashrom_file_path) {
|
||||
// use local flashrom files;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") == "bf0app" && ssid_sessions[socket.ssid].get("wtv-client-bootrom-version") == "105") {
|
||||
// assume old classic in flash mode, override user setting and send tellyscript
|
||||
// because it is required to proceed in flash mode
|
||||
bf0app_update = true;
|
||||
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
||||
headers += "minisrv-use-carriage-return: false\n";
|
||||
}
|
||||
|
||||
|
||||
function calculatedPath(data, path, numparts = null) {
|
||||
var data_128 = new Buffer.alloc(128);
|
||||
data.copy(data_128, 0, 0, 128);
|
||||
var flashrom_numparts = null;
|
||||
var flashrom_message = new Buffer.from(data_128.toString('hex').substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
|
||||
|
||||
if (numparts != null) 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;
|
||||
if (flashrom_lastpart) flashrom_next_rompath = null;
|
||||
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) + "&numparts=" + parseInt(flashrom_numparts);
|
||||
}
|
||||
return flashrom_next_rompath;
|
||||
}
|
||||
|
||||
if (request_headers.query.raw || bf0app_update) {
|
||||
if ((/\.brom$/).test(request_path)) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
|
||||
else headers += "Content-Type: binary/x-wtv-flashblock";
|
||||
|
||||
var flashrom_file_path = null;
|
||||
Object.keys(service_vaults).forEach(function (g) {
|
||||
if (flashrom_file_path != null) return;
|
||||
flashrom_file_path = service_vaults[g] + "/" + service_name + "/" + request_path;
|
||||
if (!fs.existsSync(flashrom_file_path)) flashrom_file_path = null;
|
||||
});
|
||||
if (minisrv_config.services[service_name].use_zefie_server && !flashrom_file_path) {
|
||||
// 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];
|
||||
}
|
||||
if (bf0app_update) {
|
||||
var nextpath = calculatedPath(data, request_path, (request_headers.query.numparts || null));
|
||||
if (nextpath != null) headers += "\nwtv-visit: " + nextpath;
|
||||
}
|
||||
else headers += "\nwtv-connection-close: true";
|
||||
sendToClient(socket, headers, data);
|
||||
});
|
||||
});
|
||||
req.end();
|
||||
} else {
|
||||
doLocalFlashROM(flashrom_file_path);
|
||||
if (!ssid_sessions[socket.ssid].data_store.WTVFlashrom) {
|
||||
ssid_sessions[socket.ssid].data_store.WTVFlashrom = new WTVFlashrom(service_vaults, service_name, minisrv_config.services[service_name].use_zefie_server, bf0app_update);
|
||||
}
|
||||
|
||||
ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) {
|
||||
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
|
||||
headers = "200 OK\n"
|
||||
if (request_headers.query.path) {
|
||||
headers += "Content-type: text/html\n"
|
||||
headers += "wtv-visit: wtv-flashrom:/initiate-lc2-download?path=" + request_headers.query.path;
|
||||
|
||||
@@ -1,113 +1,32 @@
|
||||
// todo, actual file logic
|
||||
// - 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;
|
||||
|
||||
function doLocalFlashROM() {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
const WTVFlashrom = require("./WTVFlashrom.js");
|
||||
var wtvflashrom;
|
||||
var flashrom_info;
|
||||
request_is_async = true;
|
||||
|
||||
if (!request_headers.query.path) {
|
||||
var errpage = doErrorPage(400);
|
||||
headers = errpage[0];
|
||||
data = errpage[1];
|
||||
} else {
|
||||
} else {
|
||||
var wtvflashrom = new WTVFlashrom(service_vaults, service_name, minisrv_config.services[service_name].use_zefie_server);
|
||||
var request_path = unescape(request_headers.query.path);
|
||||
var flashrom_file_path = null;
|
||||
Object.keys(service_vaults).forEach(function (g) {
|
||||
if (flashrom_file_path != null) return;
|
||||
flashrom_file_path = service_vaults[g] + "/" + service_name + "/" + request_path;
|
||||
if (!fs.existsSync(flashrom_file_path)) flashrom_file_path = null;
|
||||
});
|
||||
|
||||
if (minisrv_config.services[service_name].use_zefie_server && !flashrom_file_path) {
|
||||
// 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
|
||||
doLocalFlashROM(flashrom_file_path);
|
||||
}
|
||||
// read 512 bytes of rom
|
||||
flashrom_info = wtvflashrom.getFlashRom(request_path, function (data, headers = null) {
|
||||
processLC2DownloadPage(request_headers.query.path, data, (request_headers.query.numparts || null));
|
||||
}, 512);
|
||||
}
|
||||
|
||||
async function processLC2DownloadPage(path, flashrom_message, numparts = null) {
|
||||
async function processLC2DownloadPage(path, flashrom_info, numparts = null) {
|
||||
var flashrom_numparts = null;
|
||||
if (numparts != null) 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_numparts) flashrom_numparts = parseInt(flashrom_info.message.substring(flashrom_info.message.length - 4).replace(/\D/g, ''));
|
||||
|
||||
if (!flashrom_info.is_last_part) {
|
||||
flashrom_info.next_rompath = flashrom_info.next_rompath.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) {
|
||||
if (!flashrom_info.part_number || !flashrom_info.is_last_part || !flashrom_info.rompath || !flashrom_info.next_rompath || !flashrom_info.is_bootrom) {
|
||||
|
||||
headers = `200 OK
|
||||
Content-type: text/html`
|
||||
@@ -163,7 +82,7 @@ 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_isboot && parseInt(flashrom_part_num) == 16) {
|
||||
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
|
||||
@@ -174,16 +93,20 @@ data += `
|
||||
</font>
|
||||
<br><br><br><br><br>
|
||||
<upgradeblock width=280 height=15
|
||||
nexturl="${flashrom_next_rompath}"
|
||||
nexturl="${flashrom_info.next_rompath}"
|
||||
errorurl="wtv-flashrom:/lc2-download-failed?"
|
||||
blockurl="${flashrom_rompath}"
|
||||
lastblock="${flashrom_lastpart}"
|
||||
curblock="` + (parseInt(flashrom_part_num) + 1) + `"
|
||||
totalblocks="${flashrom_numparts}">
|
||||
blockurl="${flashrom_info.rompath}"
|
||||
lastblock="${flashrom_info.is_last_part}"
|
||||
curblock="` + (flashrom_info.part_number + 1) + `"
|
||||
`
|
||||
if (flashrom_numparts) {
|
||||
data += `totalblocks="${flashrom_numparts}"`;
|
||||
}
|
||||
data += `>
|
||||
<font size="-1" color="#D6DFD0">
|
||||
<br>
|
||||
<img src="wtv-flashrom:/ROMCache/Spacer.gif" width=2 height=10><br>
|
||||
${flashrom_message}
|
||||
${flashrom_info.message}
|
||||
<br><br>
|
||||
<tr>
|
||||
<td width=104 valign=middle align=center>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
const WTVFlashrom = require("./WTVFlashrom.js");
|
||||
request_is_async = true;
|
||||
|
||||
// this build can be local or on zefie's server
|
||||
// to get the path from zefie's server, browse
|
||||
// https://archive.midnightchannel.net/zefie/files/wtv-flashrom/content/artemis-webtv-000/
|
||||
@@ -5,110 +8,23 @@
|
||||
// example is below
|
||||
var default_build_to_send = minisrv_config.services[service_name].bf0app_default_rom || "content/artemis-webtv-000/build7181/daily-nondebug/bf0app-part000.rom";
|
||||
|
||||
headers = "200 OK\n";
|
||||
|
||||
var request_path = "";
|
||||
var bf0app_update = true;
|
||||
if (request_headers.query.path) request_path = unescape(request_headers.query.path);
|
||||
else request_path = default_build_to_send;
|
||||
request_is_async = true;
|
||||
|
||||
if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") == "bf0app" && ssid_sessions[socket.ssid].get("wtv-client-bootrom-version") == "105") {
|
||||
// assume old classic in flash mode, override user setting and send tellyscript
|
||||
// because it is required to proceed in flash mode
|
||||
bf0app_update = true;
|
||||
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
||||
headers += "minisrv-use-carriage-return: false\n";
|
||||
}
|
||||
|
||||
function doLocalFlashROM(flashrom_file_path) {
|
||||
// use local flashrom files;
|
||||
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);
|
||||
}
|
||||
if (!ssid_sessions[socket.ssid].data_store.WTVFlashrom) {
|
||||
ssid_sessions[socket.ssid].data_store.WTVFlashrom = new WTVFlashrom(service_vaults, service_name, 0, minisrv_config.services[service_name].use_zefie_server, bf0app_update);
|
||||
}
|
||||
|
||||
function calculatedPath(data, path, numparts = null) {
|
||||
var data_128 = new Buffer.alloc(128);
|
||||
data.copy(data_128, 0, 0, 128);
|
||||
var flashrom_numparts = null;
|
||||
var flashrom_message = new Buffer.from(data_128.toString('hex').substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
|
||||
|
||||
if (numparts != null) 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;
|
||||
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) + "&numparts=" + parseInt(flashrom_numparts);
|
||||
}
|
||||
return flashrom_next_rompath;
|
||||
}
|
||||
|
||||
if ((/\.brom$/).test(request_path)) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
|
||||
else headers += "Content-Type: binary/x-wtv-flashblock";
|
||||
|
||||
var flashrom_file_path = null;
|
||||
Object.keys(service_vaults).forEach(function (g) {
|
||||
if (flashrom_file_path != null) return;
|
||||
flashrom_file_path = service_vaults[g] + "/" + service_name + "/" + request_path;
|
||||
if (!fs.existsSync(flashrom_file_path)) flashrom_file_path = null;
|
||||
ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) {
|
||||
sendToClient(socket, headers, data);
|
||||
});
|
||||
if (minisrv_config.services[service_name].use_zefie_server && !flashrom_file_path) {
|
||||
// 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];
|
||||
}
|
||||
headers += "\nwtv-visit: " + calculatedPath(data, request_path);
|
||||
sendToClient(socket, headers, data);
|
||||
});
|
||||
});
|
||||
req.end();
|
||||
} else {
|
||||
doLocalFlashROM(flashrom_file_path);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ wtv-wink-deferrer-retries: 3
|
||||
wtv-offline-mail-enable: false
|
||||
wtv-name-server: 8.8.8.8
|
||||
`;
|
||||
if (ssid_sessions[socket.ssid].get('wtv-need-upgrade') != 'true') {
|
||||
if (ssid_sessions[socket.ssid].get('wtv-need-upgrade') != 'true' && !request_headers.query.reconnect) {
|
||||
headers += "wtv-settings-url: wtv-setup:/get\n";
|
||||
}
|
||||
headers += `wtv-visit: wtv-home:/splash?
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
var challenge_response, challenge_header = '';
|
||||
|
||||
var gourl = "wtv-head-waiter:/login-stage-two?";
|
||||
if (request_headers.query.relogin) gourl += "relogin=true";
|
||||
if (request_headers.query.reconnect) gourl += "reconnect=true";
|
||||
|
||||
if (socket.ssid !== null) {
|
||||
var wtvsec_login = ssid_sessions[socket.ssid].get("wtvsec_login");
|
||||
if (request_headers["wtv-ticket"]) {
|
||||
@@ -56,10 +60,10 @@ Expires: Wed, 09 Oct 1991 22:00:00 GMT
|
||||
wtv-expire-all: wtv-head-waiter:
|
||||
`+ getServiceString('wtv-log') + `
|
||||
wtv-log-url: wtv-log:/log
|
||||
`+ challenge_header + `
|
||||
${challenge_header}
|
||||
wtv-relogin-url: wtv-1800:/preregister?relogin=true
|
||||
wtv-reconnect-url: wtv-1800:/preregister?reconnect=true
|
||||
wtv-visit: wtv-head-waiter:/login-stage-two?
|
||||
wtv-visit: ${gourl}
|
||||
Content-type: text/html`;
|
||||
data = '';
|
||||
} else {
|
||||
|
||||
@@ -24,7 +24,7 @@ function go() {
|
||||
location.href=document.access.url.value;
|
||||
}
|
||||
</script>
|
||||
<h2>Welcome to `+ z_title + `</h2>
|
||||
<h3>Welcome to `+ z_title + `</h3>
|
||||
<b>Encryption Status</b>: ${cryptstatus}<br>
|
||||
<b>Connection Speed</b>: &rate;
|
||||
<p>
|
||||
|
||||
@@ -76,6 +76,10 @@ Content-Type: text/html`
|
||||
<td valign=top align=right><shadow>Client IP number:</shadow>
|
||||
<td width=10>
|
||||
<td valign=top>${socket.remoteAddress}
|
||||
<tr>
|
||||
<td valign=top align=right><shadow>Service IP number:</shadow>
|
||||
<td width=10>
|
||||
<td valign=top>${service_ip}
|
||||
<tr>
|
||||
<td height=20>
|
||||
<tr>
|
||||
|
||||
Reference in New Issue
Block a user