lots more stuff

- proper gzip download for disk system (aka WNI reinventing the Content-Encoding: gzip wheel)
- send Last-Modified for static files
- send wtv-checksum for all disk system downloads
- other fixes
This commit is contained in:
zefie
2021-08-11 00:56:21 -04:00
parent 11935a5886
commit 95442a12af
21 changed files with 185 additions and 100 deletions

View File

@@ -1,5 +1,5 @@
if (socket.ssid != null && !ssid_sessions[socket.ssid].get("wtvsec_login")) { if (socket.ssid != null && !ssid_sessions[socket.ssid].get("wtvsec_login")) {
var wtvsec_login = new WTVSec(); var wtvsec_login = new WTVSec(minisrv_config);
wtvsec_login.IssueChallenge(); wtvsec_login.IssueChallenge();
wtvsec_login.set_incarnation(request_headers["wtv-incarnation"]); wtvsec_login.set_incarnation(request_headers["wtv-incarnation"]);
ssid_sessions[socket.ssid].set("wtvsec_login", wtvsec_login); ssid_sessions[socket.ssid].set("wtvsec_login", wtvsec_login);

View File

@@ -20,15 +20,15 @@
} }
} }
}); });
if (i > 0 && zdebug) console.log(" # Closed", i, "previous sockets for", wtvshared.filterSSID(socket.ssid)); if (i > 0 && minisrv_config.config.debug_flags.debug) console.log(" # Closed", i, "previous sockets for", wtvshared.filterSSID(socket.ssid));
} }
} }
if (ssid_sessions[socket.ssid].data_store.wtvsec_login) { if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
if (zdebug) console.log(" # Recreating primary WTVSec login instance for", wtvshared.filterSSID(socket.ssid)); if (minisrv_config.config.debug_flags.debug) console.log(" # Recreating primary WTVSec login instance for", wtvshared.filterSSID(socket.ssid));
delete ssid_sessions[socket.ssid].data_store.wtvsec_login; delete ssid_sessions[socket.ssid].data_store.wtvsec_login;
} }
ssid_sessions[socket.ssid].data_store.wtvsec_login = new WTVSec(); ssid_sessions[socket.ssid].data_store.wtvsec_login = new WTVSec(minisrv_config);
ssid_sessions[socket.ssid].data_store.wtvsec_login.IssueChallenge(); ssid_sessions[socket.ssid].data_store.wtvsec_login.IssueChallenge();
ssid_sessions[socket.ssid].data_store.wtvsec_login.set_incarnation(request_headers["wtv-incarnation"] || 1); ssid_sessions[socket.ssid].data_store.wtvsec_login.set_incarnation(request_headers["wtv-incarnation"] || 1);
} else { } else {
@@ -117,7 +117,7 @@ if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
if (request_headers.query.reconnect) gourl = null; if (request_headers.query.reconnect) gourl = null;
if (!file_path != null && !zquiet) console.log(" * Sending TellyScript", file_path, "on socket", socket.id); if (!file_path != null && !minisrv_config.config.debug_flags.quiet) console.log(" * Sending TellyScript", file_path, "on socket", socket.id);
if (request_headers.query.guest_login) { if (request_headers.query.guest_login) {
send_tellyscript = false; send_tellyscript = false;

View File

@@ -0,0 +1,17 @@
{
"ModemFirmware": {
"base": "file://Disk/Browser/Modem_Firmware/",
"location": "content/Modem_Firmware/",
"execute": "client:ModemReload",
"execute_when": "atEnd",
"service_owned": true,
"files": [
{
"file": "file://Disk/Browser/Modem_Firmware/Locale/en-US/modem_firmware.dat.gz"
},
{
"file": "file://Disk/Browser/Modem_Firmware/Locale/ja-JP/modem_firmware.dat.gz"
}
]
}
}

View File

@@ -90,7 +90,7 @@ if (request_headers['wtv-request-type'] == 'download') {
} }
} }
var download_list = wtvdl.getDownloadList(); var download_list = wtvdl.getDownloadList();
console.log(download_list); if (minisrv_config.config.show_diskmap) console.log(download_list);
return download_list; return download_list;
} }
@@ -260,13 +260,13 @@ if (request_headers['wtv-request-type'] == 'download') {
var errpage = doErrorPage(404, "The requested DiskMap does not exist."); var errpage = doErrorPage(404, "The requested DiskMap does not exist.");
headers = errpage[0]; headers = errpage[0];
data = errpage[1]; data = errpage[1];
if (zdebug) console.error(" # " + service_name +":/sync error", "could not find diskmap"); if (minisrv_config.config.debug_flags.debug) console.error(" # " + service_name +":/sync error", "could not find diskmap");
} }
} else { } else {
var errpage = doErrorPage(400); var errpage = doErrorPage(400);
headers = errpage[0]; headers = errpage[0];
data = errpage[1]; data = errpage[1];
if (zdebug) console.error(" # " + service_name + ":/sync error", "missing query arguments"); if (minisrv_config.config.debug_flags.debug) console.error(" # " + service_name + ":/sync error", "missing query arguments");
} }
} else if (request_headers.query.group && request_headers.query.diskmap) { } else if (request_headers.query.group && request_headers.query.diskmap) {
var message = request_headers.query.message || "Retrieving files..."; var message = request_headers.query.message || "Retrieving files...";

View File

@@ -14,7 +14,7 @@ if ((romtype == "bf0app" || !romtype) && (bootver == "105" || !bootver)) {
} }
if (!ssid_sessions[socket.ssid].data_store.WTVFlashrom) { 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, minisrv_config.services[service_name].debug); ssid_sessions[socket.ssid].data_store.WTVFlashrom = new WTVFlashrom(minisrv_config, service_vaults, service_name, minisrv_config.services[service_name].use_zefie_server, bf0app_update, minisrv_config.services[service_name].debug);
} }
ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) { ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) {

View File

@@ -22,7 +22,7 @@ if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") == "bf0app" && ssid_se
} }
if (!ssid_sessions[socket.ssid].data_store.WTVFlashrom) { 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, minisrv_config.services[service_name].debug); ssid_sessions[socket.ssid].data_store.WTVFlashrom = new WTVFlashrom(minisrv_config, service_vaults, service_name, minisrv_config.services[service_name].use_zefie_server, bf0app_update, minisrv_config.services[service_name].debug);
} }
ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) { ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) {

View File

@@ -15,7 +15,7 @@ if ((romtype == "bf0app" || !romtype) && (bootver == "105" || !bootver)) {
if (request_headers.query.raw || bf0app_update) { if (request_headers.query.raw || bf0app_update) {
if (!ssid_sessions[socket.ssid].data_store.WTVFlashrom) { 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, minisrv_config.services[service_name].debug); ssid_sessions[socket.ssid].data_store.WTVFlashrom = new WTVFlashrom(minisrv_config, service_vaults, service_name, minisrv_config.services[service_name].use_zefie_server, bf0app_update, minisrv_config.services[service_name].debug);
} }
ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) { ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) {

View File

@@ -8,7 +8,7 @@ if (!request_headers.query.path) {
headers = errpage[0]; headers = errpage[0];
data = errpage[1]; data = errpage[1];
} else { } else {
var wtvflashrom = new WTVFlashrom(service_vaults, service_name, minisrv_config.services[service_name].use_zefie_server); var wtvflashrom = new WTVFlashrom(minisrv_config, service_vaults, service_name, minisrv_config.services[service_name].use_zefie_server);
var request_path = request_headers.query.path; var request_path = request_headers.query.path;
// read flashrom header info into array using WTVFlashrom class // read flashrom header info into array using WTVFlashrom class

View File

@@ -22,7 +22,7 @@ if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") == "bf0app" && ssid_se
} }
if (!ssid_sessions[socket.ssid].data_store.WTVFlashrom) { 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, minisrv_config.services[service_name].debug); ssid_sessions[socket.ssid].data_store.WTVFlashrom = new WTVFlashrom(minisrv_config, service_vaults, service_name, 0, minisrv_config.services[service_name].use_zefie_server, bf0app_update, minisrv_config.services[service_name].debug);
} }
ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) { ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) {

View File

@@ -32,7 +32,7 @@ const req = https.request(options, function (res) {
}); });
res.on('error', function (e) { res.on('error', function (e) {
if (!zquiet) console.log(" * Upstream Ultra Willies HTTP Error:", e); if (!minisrv_config.config.debug_flags.quiet) console.log(" * Upstream Ultra Willies HTTP Error:", e);
var errpage = doErrorPage(400) var errpage = doErrorPage(400)
headers = errpage[0]; headers = errpage[0];
data = errpage[1]; data = errpage[1];
@@ -40,7 +40,7 @@ const req = https.request(options, function (res) {
}); });
res.on('end', function () { res.on('end', function () {
if (!zquiet) console.log(" * Upstream Ultra Willies HTTP Response:", res.statusCode, res.statusMessage); if (!minisrv_config.config.debug_flags.quiet) console.log(" * Upstream Ultra Willies HTTP Response:", res.statusCode, res.statusMessage);
if (request_headers.query.clear_cache) { if (request_headers.query.clear_cache) {
headers += "\nwtv-expire-all: "+service_name; headers += "\nwtv-expire-all: "+service_name;
} }

View File

@@ -2,7 +2,7 @@ var challenge_response, challenge_header = '';
var gourl; var gourl;
if (socket.ssid != null && !ssid_sessions[socket.ssid].get("wtvsec_login")) { if (socket.ssid != null && !ssid_sessions[socket.ssid].get("wtvsec_login")) {
var wtvsec_login = new WTVSec(1,zdebug); var wtvsec_login = new WTVSec(minisrv_config);
wtvsec_login.IssueChallenge(); wtvsec_login.IssueChallenge();
wtvsec_login.set_incarnation(request_headers["wtv-incarnation"]); wtvsec_login.set_incarnation(request_headers["wtv-incarnation"]);
ssid_sessions[socket.ssid].set("wtvsec_login", wtvsec_login); ssid_sessions[socket.ssid].set("wtvsec_login", wtvsec_login);
@@ -21,8 +21,8 @@ if (socket.ssid !== null) {
} else { } else {
console.log(" * wtv-challenge-response FAILED for " + wtvshared.filterSSID(socket.ssid)); console.log(" * wtv-challenge-response FAILED for " + wtvshared.filterSSID(socket.ssid));
if (zdebug) console.log("Response Expected:", challenge_response.toString(CryptoJS.enc.Base64)); if (minisrv_config.config.debug_flags.debug) console.log("Response Expected:", challenge_response.toString(CryptoJS.enc.Base64));
if (zdebug) console.log("Response Received:", client_challenge_response) if (minisrv_config.config.debug_flags.debug) console.log("Response Received:", client_challenge_response)
gourl = "wtv-head-waiter:/login?reissue_challenge=true"; gourl = "wtv-head-waiter:/login?reissue_challenge=true";
} }
} else { } else {

View File

@@ -22,7 +22,7 @@ Content-length: 0`;
logdata_outstring_hex += request_headers.post_data.toString(CryptoJS.enc.Hex); logdata_outstring_hex += request_headers.post_data.toString(CryptoJS.enc.Hex);
if (minisrv_config.services[service_name].write_logs_to_disk) { if (minisrv_config.services[service_name].write_logs_to_disk) {
fs.writeFile(fullpath, logdata_outstring_hex, "Hex", function () { fs.writeFile(fullpath, logdata_outstring_hex, "Hex", function () {
if (!zquiet) console.log(" * Wrote POST log data from", wtvshared.filterSSID(socket.ssid), "for", socket.id); if (!minisrv_config.config.debug_flags.quiet) console.log(" * Wrote POST log data from", wtvshared.filterSSID(socket.ssid), "for", socket.id);
sendToClient(socket, headers, data); sendToClient(socket, headers, data);
}); });
} else { } else {
@@ -41,7 +41,7 @@ Content-length: 0`;
var logdata_outstring_hex = Buffer.from(logdata_outstring, 'utf8').toString('hex'); var logdata_outstring_hex = Buffer.from(logdata_outstring, 'utf8').toString('hex');
if (minisrv_config.services[service_name].write_logs_to_disk) { if (minisrv_config.services[service_name].write_logs_to_disk) {
fs.writeFile(fullpath, logdata_outstring_hex, "Hex", function () { fs.writeFile(fullpath, logdata_outstring_hex, "Hex", function () {
if (!zquiet) console.log(" * Wrote GET log data from", wtvshared.filterSSID(socket.ssid), "for", socket.id); if (!minisrv_config.config.debug_flags.quiet) console.log(" * Wrote GET log data from", wtvshared.filterSSID(socket.ssid), "for", socket.id);
sendToClient(socket, headers, data); sendToClient(socket, headers, data);
}); });
} else { } else {

View File

@@ -103,15 +103,6 @@ class WTVClientSessionData {
return this.wtvmime.getSimpleContentType(path); return this.wtvmime.getSimpleContentType(path);
} }
/**
* Returns a RFC7231 compliant UTC Date String from the current time
* @param {Number} offset Offset from current time (+/-)
* @returns {string} A RFC7231 compliant UTC Date String from the current time
*/
getUTCTime(offset = 0) {
return new Date((new Date).getTime() + offset).toUTCString();
}
/** /**
* Returns the number of user cookies * Returns the number of user cookies
* @returns {number} Number of cookies * @returns {number} Number of cookies
@@ -123,7 +114,7 @@ class WTVClientSessionData {
resetCookies() { resetCookies() {
this.session_store.cookies = {}; this.session_store.cookies = {};
// webtv likes to have at least one cookie in the list, set a dummy cookie for zefie's site expiring in 1 year. // webtv likes to have at least one cookie in the list, set a dummy cookie for zefie's site expiring in 1 year.
this.addCookie("wtv.zefie.com", "/", this.getUTCTime(365 * 86400000), "cookie_type=chocolatechip"); this.addCookie("wtv.zefie.com", "/", this.wtvshared.getUTCTime(365 * 86400000), "cookie_type=chocolatechip");
} }
addCookie(domain, path = null, expires = null, data = null) { addCookie(domain, path = null, expires = null, data = null) {

View File

@@ -104,6 +104,7 @@ class WTVDownloadList {
* @param {string} group Group to which it belongs * @param {string} group Group to which it belongs
*/ */
delete(path, group = null) { delete(path, group = null) {
path = this.wtvshared.stripGzipFromPath(path);
this.download_list += "DELETE " + path + "\n"; this.download_list += "DELETE " + path + "\n";
if (group !== null) this.download_list += "group: " + group + "\n\n"; if (group !== null) this.download_list += "group: " + group + "\n\n";
} }
@@ -145,13 +146,16 @@ class WTVDownloadList {
* @param {string} checksum md5sum of the file * @param {string} checksum md5sum of the file
* @param {string} file_permission File permissions * @param {string} file_permission File permissions
*/ */
get(file, path, source, group, checksum = null, file_permission = 'r') { get(file, path, source, group, checksum = null, uncompressed_size = null, file_permission = 'r') {
file = this.wtvshared.stripGzipFromPath(file);
this.download_list += "GET " + file + "\n"; this.download_list += "GET " + file + "\n";
this.download_list += "group: " + group + "-UPDATE\n"; this.download_list += "group: " + group + "-UPDATE\n";
this.download_list += "location: " + source + "\n"; this.download_list += "location: " + source + "\n";
this.download_list += "file-permission: " + file_permission + "\n"; this.download_list += "file-permission: " + file_permission + "\n";
if (checksum != null) this.download_list += "wtv-checksum: " + checksum + "\n"; if (checksum != null) this.download_list += "wtv-checksum: " + checksum + "\n";
if (uncompressed_size != null) this.download_list += "wtv-uncompressed-filesize: " + uncompressed_size + "\n";
this.download_list += "service-source-location: /webtv/content/" + source.substr(source.indexOf('-') + 1, source.indexOf(':/') - source.indexOf('-') - 1) + "d/" + source.substr(source.indexOf(':/') + 2) + "\n"; this.download_list += "service-source-location: /webtv/content/" + source.substr(source.indexOf('-') + 1, source.indexOf(':/') - source.indexOf('-') - 1) + "d/" + source.substr(source.indexOf(':/') + 2) + "\n";
path = this.wtvshared.stripGzipFromPath(path);
this.download_list += "client-dest-location: " + path + "\n\n"; this.download_list += "client-dest-location: " + path + "\n\n";
} }
@@ -163,6 +167,8 @@ class WTVDownloadList {
* @param {string} destgroup Destination Group * @param {string} destgroup Destination Group
*/ */
rename(srcfile, destfile, srcgroup, destgroup) { rename(srcfile, destfile, srcgroup, destgroup) {
srcfile = this.wtvshared.stripGzipFromPath(srcfile);
destfile = this.wtvshared.stripGzipFromPath(destfile);
this.download_list += "RENAME " + srcfile + "\n"; this.download_list += "RENAME " + srcfile + "\n";
this.download_list += "group: " + srcgroup + "-UPDATE\n"; this.download_list += "group: " + srcgroup + "-UPDATE\n";
this.download_list += "destination-group: " + destgroup + "\n"; this.download_list += "destination-group: " + destgroup + "\n";

View File

@@ -6,15 +6,15 @@ class WTVFlashrom {
bf0app_update = false; bf0app_update = false;
service_vaults = new Array(); service_vaults = new Array();
service_name = ""; service_name = "";
zdebug = false; minisrv_config = [];
constructor(service_vaults, service_name, use_zefie_server = true, bf0app_update = false, debug = false) { constructor(minisrv_config, service_vaults, service_name, use_zefie_server = true, bf0app_update = false, debug = false) {
this.service_vaults = service_vaults; this.service_vaults = service_vaults;
this.service_name = service_name; this.service_name = service_name;
this.use_zefie_server = use_zefie_server; this.use_zefie_server = use_zefie_server;
this.bf0app_update = bf0app_update; this.bf0app_update = bf0app_update;
this.zdebug = debug; this.minisrv_config.config.debug_flags.debug = debug;
} }
@@ -95,31 +95,31 @@ class WTVFlashrom {
if (flashrom_info.magic == flashrom_magic) flashrom_info.valid_flashrom = true; if (flashrom_info.magic == flashrom_magic) flashrom_info.valid_flashrom = true;
if (!flashrom_info.valid_flashrom) console.error(" * Warning! FlashROM File Magic (" + flashrom_info.magic + ") did not match expected magic (" + flashrom_magic + ")..."); if (!flashrom_info.valid_flashrom) console.error(" * Warning! FlashROM File Magic (" + flashrom_info.magic + ") did not match expected magic (" + flashrom_magic + ")...");
if (this.zdebug) console.log(" # FlashROM File Magic (" + flashrom_info.magic + "), expected magic (" + flashrom_magic + "), OK = " + flashrom_info.valid_flashrom + "..."); if (this.minisrv_config.config.debug_flags.debug) console.log(" # FlashROM File Magic (" + flashrom_info.magic + "), expected magic (" + flashrom_magic + "), OK = " + flashrom_info.valid_flashrom + "...");
flashrom_info.byte_progress = data.readUInt32BE(68); flashrom_info.byte_progress = data.readUInt32BE(68);
if (this.zdebug) console.log(" # Flashrom Part Bytes Sent:", flashrom_info.byte_progress); if (this.minisrv_config.config.debug_flags.debug) console.log(" # Flashrom Part Bytes Sent:", flashrom_info.byte_progress);
flashrom_info.compression_type = parseInt(part_header[16], 16); flashrom_info.compression_type = parseInt(part_header[16], 16);
if (this.zdebug) console.log(" # Flashrom Part Compression Type:", flashrom_info.compression_type); if (this.minisrv_config.config.debug_flags.debug) console.log(" # Flashrom Part Compression Type:", flashrom_info.compression_type);
flashrom_info.part_data_size = data.readUInt32BE(4); flashrom_info.part_data_size = data.readUInt32BE(4);
if (this.zdebug) console.log(" # Flashrom Part Data Size:", flashrom_info.part_data_size); if (this.minisrv_config.config.debug_flags.debug) console.log(" # Flashrom Part Data Size:", flashrom_info.part_data_size);
flashrom_info.part_total_size = flashrom_info.part_data_size + flashrom_info.header_length; flashrom_info.part_total_size = flashrom_info.part_data_size + flashrom_info.header_length;
if (this.zdebug) console.log(" # Flashrom Part Total Size:", flashrom_info.part_total_size); if (this.minisrv_config.config.debug_flags.debug) console.log(" # Flashrom Part Total Size:", flashrom_info.part_total_size);
flashrom_info.total_parts_size = data.readUInt32BE(32); flashrom_info.total_parts_size = data.readUInt32BE(32);
if (this.zdebug) console.log(" # Flashrom All Parts Total Size:", flashrom_info.total_parts_size); if (this.minisrv_config.config.debug_flags.debug) console.log(" # Flashrom All Parts Total Size:", flashrom_info.total_parts_size);
// read current part number bit from part header // read current part number bit from part header
flashrom_info.part_number = data.readUInt16BE(28); flashrom_info.part_number = data.readUInt16BE(28);
if (this.zdebug) console.log(" # Flashrom Current Part Number:", flashrom_info.part_number); if (this.minisrv_config.config.debug_flags.debug) console.log(" # Flashrom Current Part Number:", flashrom_info.part_number);
// read current part display message from part header // read current part display message from part header
flashrom_info.message = new Buffer.from(part_header.toString('hex').substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, ""); flashrom_info.message = new Buffer.from(part_header.toString('hex').substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
flashrom_info.is_last_part = ((flashrom_info.byte_progress + flashrom_info.part_total_size) == flashrom_info.total_parts_size) ? true : false; flashrom_info.is_last_part = ((flashrom_info.byte_progress + flashrom_info.part_total_size) == flashrom_info.total_parts_size) ? true : false;
flashrom_info.rompath = `wtv-flashrom:/${path}`; flashrom_info.rompath = `wtv-flashrom:/${path}`;
if (this.zdebug) console.log(" # Flashrom Part Bytes Sent (after this part):", flashrom_info.byte_progress + flashrom_info.part_total_size); if (this.minisrv_config.config.debug_flags.debug) console.log(" # Flashrom Part Bytes Sent (after this part):", flashrom_info.byte_progress + flashrom_info.part_total_size);
if (this.zdebug) console.log(" # Flashrom Part is Last Part", flashrom_info.is_last_part); if (this.minisrv_config.config.debug_flags.debug) console.log(" # Flashrom Part is Last Part", flashrom_info.is_last_part);
if (flashrom_info.is_last_part && this.bf0app_update) { if (flashrom_info.is_last_part && this.bf0app_update) {
flashrom_info.next_rompath = null; flashrom_info.next_rompath = null;
@@ -179,7 +179,7 @@ class WTVFlashrom {
}) })
res.on('end', function () { res.on('end', function () {
if (this.zdebug) console.log(` * Zefie's FlashROM Server HTTP Status: ${res.statusCode} ${res.statusMessage}`) if (this.minisrv_config.config.debug_flags.debug) console.log(` * Zefie's FlashROM Server HTTP Status: ${res.statusCode} ${res.statusMessage}`)
if (res.statusCode == 200) { if (res.statusCode == 200) {
var data = Buffer.from(data_hex, 'hex'); var data = Buffer.from(data_hex, 'hex');
} else if (res.statusCode == 206) { } else if (res.statusCode == 206) {

View File

@@ -31,19 +31,18 @@ class WTVSec {
hRC4_Key1 = null; hRC4_Key1 = null;
hRC4_Key2 = null; hRC4_Key2 = null;
RC4Session = new Array(); RC4Session = new Array();
zdebug = false; minisrv_config = [];
/** /**
* *
* Initialize the WTVSec class. * Initialize the WTVSec class.
* *
* @param {Number} wtv_incarnation Sets the wtv-incarnation for this instance * @param {Number} wtv_incarnation Sets the wtv-incarnation for this instance
* @param {Boolean} zdebug Enable debugging * @param {Boolean} minisrv_config.config.debug_flags.debug Enable debugging
* *
*/ */
constructor(wtv_incarnation = 1, zdebug = false) { constructor(minisrv_config, wtv_incarnation = 1) {
this.zdebug = zdebug; this.minisrv_config = minisrv_config;
this.initial_shared_key = CryptoJS.enc.Base64.parse(this.initial_shared_key_b64); this.initial_shared_key = CryptoJS.enc.Base64.parse(this.initial_shared_key_b64);
if (this.initial_shared_key.sigBytes === 8) { if (this.initial_shared_key.sigBytes === 8) {
@@ -248,7 +247,7 @@ class WTVSec {
* *
*/ */
SecureOn(rc4session = null) { SecureOn(rc4session = null) {
if (this.zdebug) console.log(" # Generating RC4 sessions with wtv-incarnation: " + this.incarnation); if (this.minisrv_config.config.debug_flags.debug) console.log(" # Generating RC4 sessions with wtv-incarnation: " + this.incarnation);
var buf = new Uint8Array([0xff & this.incarnation, 0xff & (this.incarnation >> 8), 0xff & (this.incarnation >> 16), 0xff & (this.incarnation >> 24)]); var buf = new Uint8Array([0xff & this.incarnation, 0xff & (this.incarnation >> 8), 0xff & (this.incarnation >> 16), 0xff & (this.incarnation >> 24)]);
endianness(buf, 4); endianness(buf, 4);

View File

@@ -5,6 +5,7 @@
class WTVShared { class WTVShared {
path = require('path'); path = require('path');
fs = require('fs');
minisrv_config = []; minisrv_config = [];
constructor(minisrv_config) { constructor(minisrv_config) {
@@ -19,6 +20,33 @@ class WTVShared {
} }
} }
/**
* Returns the Last-Modified date in Unix Timestamp format
* @param {string} file Path to a file
*/
getFileLastModified(file) {
var stats = this.fs.lstatSync(file);
if (stats) return new Date(stats.mtimeMs);
return false;
}
/**
* Returns the Last-Modified date in a RFC7231 compliant UTC Date String
* @param {string} file Path to a file
*/
getFileLastModifiedUTCString(file) {
return this.getFileLastModified(file).toUTCString();
}
/**
* Returns a RFC7231 compliant UTC Date String from the current time
* @param {Number} offset Offset from current time (+/-)
* @returns {string} A RFC7231 compliant UTC Date String from the current time
*/
getUTCTime(offset = 0) {
return new Date((new Date).getTime() + offset).toUTCString();
}
/** /**
* Returns a censored SSID * Returns a censored SSID
* @param {string|Array} obj SSID String or Headers Object * @param {string|Array} obj SSID String or Headers Object
@@ -66,6 +94,20 @@ class WTVShared {
return path; return path;
} }
/**
* If the file ends with .gz, remove it
* @param {string} path
* @return {string} path without gz, or unmodified path if it isnt a gz
*/
stripGzipFromPath(path) {
var path_split = path.split('.');
if (path_split[path_split.length - 1].toLowerCase() == "gz") {
path_split.pop();
path = path_split.join(".");
}
return path;
}
/** /**
* Gets the file extension from a path * Gets the file extension from a path
* @param {string} path * @param {string} path

View File

@@ -134,7 +134,8 @@ async function processPath(socket, service_vault_file_path, request_headers = ne
// file exists, read it and return it // file exists, read it and return it
service_vault_found = true; service_vault_found = true;
request_is_async = true; request_is_async = true;
if (!zquiet) console.log(" * Found " + service_vault_file_path + " to handle request (Direct File Mode) [Socket " + socket.id + "]"); if (!minisrv_config.config.debug_flags.quiet) console.log(" * Found " + service_vault_file_path + " to handle request (Direct File Mode) [Socket " + socket.id + "]");
request_headers.service_file_path = service_vault_file_path;
var contypes = wtvmime.getContentType(service_vault_file_path); var contypes = wtvmime.getContentType(service_vault_file_path);
headers = "200 OK\n" headers = "200 OK\n"
headers += "Content-Type: " + contypes[0] + "\n"; headers += "Content-Type: " + contypes[0] + "\n";
@@ -145,8 +146,9 @@ async function processPath(socket, service_vault_file_path, request_headers = ne
} else if (fs.existsSync(service_vault_file_path + ".txt")) { } else if (fs.existsSync(service_vault_file_path + ".txt")) {
// raw text format, entire payload expected (headers and content) // raw text format, entire payload expected (headers and content)
service_vault_found = true; service_vault_found = true;
if (!zquiet) console.log(" * Found " + service_vault_file_path + ".txt to handle request (Raw TXT Mode) [Socket " + socket.id + "]");
request_is_async = true; request_is_async = true;
if (!minisrv_config.config.debug_flags.quiet) console.log(" * Found " + service_vault_file_path + ".txt to handle request (Raw TXT Mode) [Socket " + socket.id + "]");
request_headers.service_file_path = service_vault_file_path + ".txt";
fs.readFile(service_vault_file_path + ".txt", 'Utf-8', function (err, file_raw) { fs.readFile(service_vault_file_path + ".txt", 'Utf-8', function (err, file_raw) {
if (file_raw.indexOf("\n\n") > 0) { if (file_raw.indexOf("\n\n") > 0) {
// split headers and data by newline (unix format) // split headers and data by newline (unix format)
@@ -176,18 +178,20 @@ async function processPath(socket, service_vault_file_path, request_headers = ne
// In Asynchronous mode, you are expected to call sendToClient(socket,headers,data) by the end of your script // In Asynchronous mode, you are expected to call sendToClient(socket,headers,data) by the end of your script
// `socket` is already defined and should be passed-through. // `socket` is already defined and should be passed-through.
service_vault_found = true; service_vault_found = true;
if (!zquiet) console.log(" * Found " + service_vault_file_path + ".js to handle request (JS Interpreter mode) [Socket " + socket.id + "]"); if (!minisrv_config.config.debug_flags.quiet) console.log(" * Found " + service_vault_file_path + ".js to handle request (JS Interpreter mode) [Socket " + socket.id + "]");
request_headers.service_file_path = service_vault_file_path + ".js";
// expose var service_dir for script path to the root of the wtv-service // expose var service_dir for script path to the root of the wtv-service
var service_dir = service_vault_dir + path.sep + service_name; var service_dir = service_vault_dir + path.sep + service_name;
socket_sessions[socket.id].starttime = Math.floor(new Date().getTime() / 1000); socket_sessions[socket.id].starttime = Math.floor(new Date().getTime() / 1000);
var jscript_eval = fs.readFileSync(service_vault_file_path + ".js").toString(); var jscript_eval = fs.readFileSync(service_vault_file_path + ".js").toString();
eval(jscript_eval); eval(jscript_eval);
if (request_is_async && !zquiet) console.log(" * Script requested Asynchronous mode"); if (request_is_async && !minisrv_config.config.debug_flags.quiet) console.log(" * Script requested Asynchronous mode");
} }
else if (fs.existsSync(service_vault_file_path + ".html")) { else if (fs.existsSync(service_vault_file_path + ".html")) {
// Standard HTML with no headers, WTV Style // Standard HTML with no headers, WTV Style
service_vault_found = true; service_vault_found = true;
if (!zquiet) console.log(" * Found " + service_vault_file_path + ".html to handle request (HTML Mode) [Socket " + socket.id + "]"); if (!minisrv_config.config.debug_flags.quiet) console.log(" * Found " + service_vault_file_path + ".html to handle request (HTML Mode) [Socket " + socket.id + "]");
request_headers.service_file_path = service_vault_file_path + ".html";
request_is_async = true; request_is_async = true;
headers = "200 OK\n" headers = "200 OK\n"
headers += "Content-Type: text/html" headers += "Content-Type: text/html"
@@ -207,12 +211,13 @@ async function processPath(socket, service_vault_file_path, request_headers = ne
while (service_check_dir.join(path.sep) != service_vault_dir) { while (service_check_dir.join(path.sep) != service_vault_dir) {
var catchall_file = service_check_dir.join(path.sep) + path.sep + minisrv_catchall_file_name; var catchall_file = service_check_dir.join(path.sep) + path.sep + minisrv_catchall_file_name;
if (fs.existsSync(catchall_file)) { if (fs.existsSync(catchall_file)) {
if (!zquiet) console.log(" * Found catchall at " + catchall_file + ".html to handle request (HTML Mode) [Socket " + socket.id + "]"); if (!minisrv_config.config.debug_flags.quiet) console.log(" * Found catchall at " + catchall_file + ".html to handle request (HTML Mode) [Socket " + socket.id + "]");
equest_headers.service_file_path = catchall_file;
var jscript_eval = fs.readFileSync(catchall_file).toString(); var jscript_eval = fs.readFileSync(catchall_file).toString();
// don't pass these vars to the script // don't pass these vars to the script
var service_check_dir, minisrv_catchall_file_name = null; var service_check_dir, minisrv_catchall_file_name = null;
eval(jscript_eval); eval(jscript_eval);
if (request_is_async && !zquiet) console.log(" * Script requested Asynchronous mode"); if (request_is_async && !minisrv_config.config.debug_flags.quiet) console.log(" * Script requested Asynchronous mode");
} else { } else {
service_check_dir.pop(); service_check_dir.pop();
} }
@@ -269,6 +274,7 @@ async function processURL(socket, request_headers) {
} else { } else {
shortURL = unescape(request_headers.request_url); shortURL = unescape(request_headers.request_url);
} }
if (request_headers['wtv-request-type']) socket_sessions[socket.id].wtv_request_type = request_headers['wtv-request-type'];
if (request_headers.post_data) { if (request_headers.post_data) {
var post_data_string = ''; var post_data_string = '';
@@ -351,7 +357,8 @@ async function processURL(socket, request_headers) {
// assume webtv since there is a :/ in the GET // assume webtv since there is a :/ in the GET
var service_name = shortURL.split(':/')[0]; var service_name = shortURL.split(':/')[0];
var urlToPath = service_name + path.sep + shortURL.split(':/')[1]; var urlToPath = service_name + path.sep + shortURL.split(':/')[1];
if (zshowheaders) console.log(" * Incoming headers on socket ID", socket.id, (await wtvshared.filterSSID(request_headers))); if (minisrv_config.config.debug_flags.show_headers) console.log(" * Incoming headers on socket ID", socket.id, (await wtvshared.filterSSID(request_headers)));
socket_sessions[socket.id].request_headers = request_headers;
processPath(socket, urlToPath, request_headers, service_name); processPath(socket, urlToPath, request_headers, service_name);
} else if (shortURL.indexOf('http://') >= 0 || shortURL.indexOf('https://') >= 0) { } else if (shortURL.indexOf('http://') >= 0 || shortURL.indexOf('https://') >= 0) {
doHTTPProxy(socket, request_headers); doHTTPProxy(socket, request_headers);
@@ -368,7 +375,7 @@ async function processURL(socket, request_headers) {
async function doHTTPProxy(socket, request_headers) { async function doHTTPProxy(socket, request_headers) {
var request_type = (request_headers.request_url.substring(0, 5) == "https") ? "https" : "http"; var request_type = (request_headers.request_url.substring(0, 5) == "https") ? "https" : "http";
if (zshowheaders) console.log(request_type.toUpperCase() +" Proxy: Client Request Headers on socket ID", socket.id, (await wtvshared.filterSSID(request_headers))); if (minisrv_config.config.debug_flags.show_headers) console.log(request_type.toUpperCase() +" Proxy: Client Request Headers on socket ID", socket.id, (await wtvshared.filterSSID(request_headers)));
switch (request_type) { switch (request_type) {
case "https": case "https":
var proxy_agent = https; var proxy_agent = https;
@@ -567,11 +574,32 @@ async function sendToClient(socket, headers_obj, data) {
delete headers_obj["Content-type"]; delete headers_obj["Content-type"];
} }
// Add last modified if not a dynamic script
if (wtvshared.getFileExt(socket_sessions[socket.id].request_headers.service_file_path).toLowerCase() !== "js") {
var last_modified = wtvshared.getFileLastModifiedUTCString(socket_sessions[socket.id].request_headers.service_file_path);
if (last_modified) headers_obj["Last-Modified"] = last_modified;
}
// if box can do compression, see if its worth enabling // if box can do compression, see if its worth enabling
// small files actually get larger, so don't compress them // small files actually get larger, so don't compress them
var compression_type = 0; var compression_type = 0;
if (content_length >= 256) compression_type = wtvmime.shouldWeCompress(ssid_sessions[socket.ssid], headers_obj); if (content_length >= 256) compression_type = wtvmime.shouldWeCompress(ssid_sessions[socket.ssid], headers_obj);
// disk service hack before further processing :)
if (socket_sessions[socket.id].wtv_request_type == "download") {
if (headers_obj['Content-Type'] == "application/gzip") {
var gunzipped = zlib.gunzipSync(data);
headers_obj['wtv-checksum'] = CryptoJS.MD5(CryptoJS.lib.WordArray.create(gunzipped)).toString(CryptoJS.enc.Hex).toLowerCase();
headers_obj['wtv-uncompressed-filesize'] = gunzipped.byteLength;
headers_obj['Content-Type'] = wtvmime.getSimpleContentType(wtvshared.stripGzipFromPath(socket_sessions[socket.id].request_headers.request_url));
gunzipped = null;
} else {
headers_obj['wtv-checksum'] = CryptoJS.MD5(CryptoJS.lib.WordArray.create(data)).toString(CryptoJS.enc.Hex).toLowerCase();
}
}
delete socket_sessions[socket.id].wtv_request_type;
delete socket_sessions[socket.id].request_headers;
// compress if needed // compress if needed
if (compression_type > 0 && content_length > 0 && headers_obj['http_response'].substring(0,3) == "200") { if (compression_type > 0 && content_length > 0 && headers_obj['http_response'].substring(0,3) == "200") {
var uncompressed_content_length = content_length; var uncompressed_content_length = content_length;
@@ -604,7 +632,7 @@ async function sendToClient(socket, headers_obj, data) {
} }
var compression_ratio = (uncompressed_content_length / compressed_content_length).toFixed(2); var compression_ratio = (uncompressed_content_length / compressed_content_length).toFixed(2);
var compression_percentage = ((1 - (compressed_content_length / uncompressed_content_length)) * 100).toFixed(1); var compression_percentage = ((1 - (compressed_content_length / uncompressed_content_length)) * 100).toFixed(1);
if (uncompressed_content_length != compressed_content_length) if (zdebug) console.log(" # Compression stats: Orig Size:", uncompressed_content_length, "~ Comp Size:", compressed_content_length, "~ Ratio:", compression_ratio, "Saved:", compression_percentage.toString() + "%"); if (uncompressed_content_length != compressed_content_length) if (minisrv_config.config.debug_flags.debug) console.log(" # Compression stats: Orig Size:", uncompressed_content_length, "~ Comp Size:", compressed_content_length, "~ Ratio:", compression_ratio, "Saved:", compression_percentage.toString() + "%");
} }
// encrypt if needed // encrypt if needed
@@ -612,7 +640,7 @@ async function sendToClient(socket, headers_obj, data) {
headers_obj["wtv-encrypted"] = 'true'; headers_obj["wtv-encrypted"] = 'true';
headers_obj = moveObjectElement('wtv-encrypted', 'Connection', headers_obj); headers_obj = moveObjectElement('wtv-encrypted', 'Connection', headers_obj);
if (content_length > 0 && socket_sessions[socket.id].wtvsec) { if (content_length > 0 && socket_sessions[socket.id].wtvsec) {
if (!zquiet) console.log(" * Encrypting response to client ...") if (!minisrv_config.config.debug_flags.quiet) console.log(" * Encrypting response to client ...")
var enc_data = socket_sessions[socket.id].wtvsec.Encrypt(1, data); var enc_data = socket_sessions[socket.id].wtvsec.Encrypt(1, data);
data = enc_data; data = enc_data;
} }
@@ -644,7 +672,7 @@ async function sendToClient(socket, headers_obj, data) {
} }
// header object to string // header object to string
if (zshowheaders) console.log(" * Outgoing headers on socket ID", socket.id, (await wtvshared.filterSSID(headers_obj))); if (minisrv_config.config.debug_flags.show_headers) console.log(" * Outgoing headers on socket ID", socket.id, (await wtvshared.filterSSID(headers_obj)));
Object.keys(headers_obj).forEach(function (k) { Object.keys(headers_obj).forEach(function (k) {
if (k == "http_response") { if (k == "http_response") {
headers += headers_obj[k] + end_of_line; headers += headers_obj[k] + end_of_line;
@@ -665,16 +693,16 @@ async function sendToClient(socket, headers_obj, data) {
toClient = headers + end_of_line + data; toClient = headers + end_of_line + data;
socket.write(toClient); socket.write(toClient);
} else if (typeof data == 'object') { } else if (typeof data == 'object') {
if (zquiet) var verbosity_mod = (headers_obj["wtv-encrypted"] == 'true') ? " encrypted response" : ""; if (minisrv_config.config.debug_flags.quiet) var verbosity_mod = (headers_obj["wtv-encrypted"] == 'true') ? " encrypted response" : "";
if (socket_sessions[socket.id].secure_headers == true) { if (socket_sessions[socket.id].secure_headers == true) {
// encrypt headers // encrypt headers
if (zquiet) verbosity_mod += " with encrypted headers"; if (minisrv_config.config.debug_flags.quiet) verbosity_mod += " with encrypted headers";
var enc_headers = socket_sessions[socket.id].wtvsec.Encrypt(1, headers + end_of_line); var enc_headers = socket_sessions[socket.id].wtvsec.Encrypt(1, headers + end_of_line);
socket.write(new Uint8Array(concatArrayBuffer(enc_headers, data))); socket.write(new Uint8Array(concatArrayBuffer(enc_headers, data)));
} else { } else {
socket.write(new Uint8Array(concatArrayBuffer(Buffer.from(headers + end_of_line), data))); socket.write(new Uint8Array(concatArrayBuffer(Buffer.from(headers + end_of_line), data)));
} }
if (zquiet) console.log(" * Sent" + verbosity_mod + " " + headers_obj.http_response + " to client (Content-Type:", headers_obj['Content-Type'], "~", headers_obj['Content-length'], "bytes)"); if (minisrv_config.config.debug_flags.quiet) console.log(" * Sent" + verbosity_mod + " " + headers_obj.http_response + " to client (Content-Type:", headers_obj['Content-Type'], "~", headers_obj['Content-length'], "bytes)");
} }
if (socket_sessions[socket.id].expecting_post_data) delete socket_sessions[socket.id].expecting_post_data; if (socket_sessions[socket.id].expecting_post_data) delete socket_sessions[socket.id].expecting_post_data;
@@ -782,7 +810,7 @@ function checkSecurity(socket) {
} else { } else {
rejectSSIDConnection(socket.ssid, blacklist); rejectSSIDConnection(socket.ssid, blacklist);
} }
if (ssid_access_list_ip_override && zdebug) console.log(" * Request from disallowed SSID", wtvshared.filterSSID(ssid), "was allowed due to IP address whitelist"); if (ssid_access_list_ip_override && minisrv_config.config.debug_flags.debug) console.log(" * Request from disallowed SSID", wtvshared.filterSSID(ssid), "was allowed due to IP address whitelist");
} }
// process whitelist first // process whitelist first
@@ -851,8 +879,8 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
// its not a POST and it failed the isUnencryptedString test, so we think this is an encrypted blob // its not a POST and it failed the isUnencryptedString test, so we think this is an encrypted blob
if (socket_sessions[socket.id].secure != true) { if (socket_sessions[socket.id].secure != true) {
// first time so reroll sessions // first time so reroll sessions
if (zdebug) console.log(" # [ UNEXPECTED BINARY BLOCK ] First sign of encryption, re-creating RC4 sessions for socket id", socket.id); if (minisrv_config.config.debug_flags.debug) console.log(" # [ UNEXPECTED BINARY BLOCK ] First sign of encryption, re-creating RC4 sessions for socket id", socket.id);
socket_sessions[socket.id].wtvsec = new WTVSec(1, zdebug); socket_sessions[socket.id].wtvsec = new WTVSec(minisrv_config);
socket_sessions[socket.id].wtvsec.IssueChallenge(); socket_sessions[socket.id].wtvsec.IssueChallenge();
socket_sessions[socket.id].wtvsec.SecureOn(); socket_sessions[socket.id].wtvsec.SecureOn();
socket_sessions[socket.id].secure = true; socket_sessions[socket.id].secure = true;
@@ -926,14 +954,14 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
if (ssid_sessions[socket.ssid]) { if (ssid_sessions[socket.ssid]) {
if (headers["wtv-ticket"]) { if (headers["wtv-ticket"]) {
if (!ssid_sessions[socket.ssid].data_store.wtvsec_login) { if (!ssid_sessions[socket.ssid].data_store.wtvsec_login) {
ssid_sessions[socket.ssid].data_store.wtvsec_login = new WTVSec(); ssid_sessions[socket.ssid].data_store.wtvsec_login = new WTVSec(minisrv_config);
ssid_sessions[socket.ssid].data_store.wtvsec_login.IssueChallenge(); ssid_sessions[socket.ssid].data_store.wtvsec_login.IssueChallenge();
ssid_sessions[socket.ssid].data_store.wtvsec_login.set_incarnation(headers["wtv-incarnation"]); ssid_sessions[socket.ssid].data_store.wtvsec_login.set_incarnation(headers["wtv-incarnation"]);
ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64 = headers["wtv-ticket"]; ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64 = headers["wtv-ticket"];
ssid_sessions[socket.ssid].data_store.wtvsec_login.DecodeTicket(ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64); ssid_sessions[socket.ssid].data_store.wtvsec_login.DecodeTicket(ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64);
} else { } else {
if (ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64 != headers["wtv-ticket"]) { if (ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64 != headers["wtv-ticket"]) {
if (zdebug) console.log(" # New ticket from client"); if (minisrv_config.config.debug_flags.debug) console.log(" # New ticket from client");
ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64 = headers["wtv-ticket"]; ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64 = headers["wtv-ticket"];
ssid_sessions[socket.ssid].data_store.wtvsec_login.DecodeTicket(ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64); ssid_sessions[socket.ssid].data_store.wtvsec_login.DecodeTicket(ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64);
ssid_sessions[socket.ssid].data_store.wtvsec_login.set_incarnation(headers["wtv-incarnation"]); ssid_sessions[socket.ssid].data_store.wtvsec_login.set_incarnation(headers["wtv-incarnation"]);
@@ -945,11 +973,11 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
if ((headers.secure === true || headers.encrypted === true) && !skipSecure) { if ((headers.secure === true || headers.encrypted === true) && !skipSecure) {
if (!socket_sessions[socket.id].wtvsec) { if (!socket_sessions[socket.id].wtvsec) {
if (!zquiet) console.log(" * Starting new WTVSec instance on socket", socket.id); if (!minisrv_config.config.debug_flags.quiet) console.log(" * Starting new WTVSec instance on socket", socket.id);
if (ssid_sessions[socket.ssid].get("wtv-incarnation")) { if (ssid_sessions[socket.ssid].get("wtv-incarnation")) {
socket_sessions[socket.id].wtvsec = new WTVSec(ssid_sessions[socket.ssid].get("wtv-incarnation"), zdebug); socket_sessions[socket.id].wtvsec = new WTVSec(minisrv_config, ssid_sessions[socket.ssid].get("wtv-incarnation"));
} else { } else {
socket_sessions[socket.id].wtvsec = new WTVSec(1, zdebug); socket_sessions[socket.id].wtvsec = new WTVSec(minisrv_config);
} }
socket_sessions[socket.id].wtvsec.DecodeTicket(headers["wtv-ticket"]); socket_sessions[socket.id].wtvsec.DecodeTicket(headers["wtv-ticket"]);
socket_sessions[socket.id].wtvsec.ticket_b64 = headers["wtv-ticket"]; socket_sessions[socket.id].wtvsec.ticket_b64 = headers["wtv-ticket"];
@@ -957,7 +985,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
} }
if (socket_sessions[socket.id].secure != true) { if (socket_sessions[socket.id].secure != true) {
// first time so reroll sessions // first time so reroll sessions
if (zdebug) console.log(" # [ SECURE ON BLOCK (" + socket.id + ") ]"); if (minisrv_config.config.debug_flags.debug) console.log(" # [ SECURE ON BLOCK (" + socket.id + ") ]");
socket_sessions[socket.id].secure = true; socket_sessions[socket.id].secure = true;
} }
if (!headers.request_url) { if (!headers.request_url) {
@@ -991,8 +1019,8 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
if (!secure_headers) return; if (!secure_headers) return;
delete socket_sessions[socket.id].secure_buffer; delete socket_sessions[socket.id].secure_buffer;
if (zdebug) console.log(" # Encrypted Request (SECURE ON)", "on", socket.id); if (minisrv_config.config.debug_flags.debug) console.log(" # Encrypted Request (SECURE ON)", "on", socket.id);
if (zshowheaders) console.log(secure_headers); if (minisrv_config.config.debug_flags.show_headers) console.log(secure_headers);
if (!secure_headers.request) { if (!secure_headers.request) {
socket_sessions[socket.id].secure = false; socket_sessions[socket.id].secure = false;
var errpage = doErrorPage(400); var errpage = doErrorPage(400);
@@ -1134,9 +1162,9 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
socket.setTimeout(minisrv_config.config.socket_timeout * 1000); socket.setTimeout(minisrv_config.config.socket_timeout * 1000);
headers.post_data = CryptoJS.enc.Hex.parse(socket_sessions[socket.id].post_data); headers.post_data = CryptoJS.enc.Hex.parse(socket_sessions[socket.id].post_data);
if (socket_sessions[socket.id].secure == true) { if (socket_sessions[socket.id].secure == true) {
if (zdebug) console.log(" # Encrypted POST Content (SECURE ON)", "on", socket.id, "[", headers.post_data.sigBytes, "bytes ]"); if (minisrv_config.config.debug_flags.debug) console.log(" # Encrypted POST Content (SECURE ON)", "on", socket.id, "[", headers.post_data.sigBytes, "bytes ]");
} else { } else {
if (zdebug) console.log(" # Unencrypted POST Content", "on", socket.id); if (minisrv_config.config.debug_flags.debug) console.log(" # Unencrypted POST Content", "on", socket.id);
} }
delete socket_sessions[socket.id].headers; delete socket_sessions[socket.id].headers;
delete socket_sessions[socket.id].post_data; delete socket_sessions[socket.id].post_data;
@@ -1158,7 +1186,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
} else if (!skipSecure) { } else if (!skipSecure) {
if (!encryptedRequest) { if (!encryptedRequest) {
if (socket_sessions[socket.id].secure != true) { if (socket_sessions[socket.id].secure != true) {
socket_sessions[socket.id].wtvsec = new WTVSec(1, zdebug); socket_sessions[socket.id].wtvsec = new WTVSec(minisrv_config);
socket_sessions[socket.id].wtvsec.IssueChallenge(); socket_sessions[socket.id].wtvsec.IssueChallenge();
socket_sessions[socket.id].wtvsec.SecureOn(); socket_sessions[socket.id].wtvsec.SecureOn();
socket_sessions[socket.id].secure = true; socket_sessions[socket.id].secure = true;
@@ -1222,7 +1250,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
async function cleanupSocket(socket) { async function cleanupSocket(socket) {
try { try {
if (socket_sessions[socket.id]) { if (socket_sessions[socket.id]) {
if (!zquiet) console.log(" * Cleaning up disconnected socket", socket.id); if (!minisrv_config.config.debug_flags.quiet) console.log(" * Cleaning up disconnected socket", socket.id);
delete socket_sessions[socket.id]; delete socket_sessions[socket.id];
} }
if (socket.ssid) { if (socket.ssid) {
@@ -1242,7 +1270,7 @@ async function cleanupSocket(socket) {
// set timeout to check // set timeout to check
ssid_sessions[socket.ssid].data_store.socket_check = setTimeout(function (ssid) { ssid_sessions[socket.ssid].data_store.socket_check = setTimeout(function (ssid) {
if (ssid_sessions[ssid].currentConnections() === 0) { if (ssid_sessions[ssid].currentConnections() === 0) {
if (!zquiet) console.log(" * WebTV SSID", wtvshared.filterSSID(ssid), " has not been seen in", (timeout / 1000), "seconds, cleaning up session data for this SSID"); if (!minisrv_config.config.debug_flags.quiet) console.log(" * WebTV SSID", wtvshared.filterSSID(ssid), " has not been seen in", (timeout / 1000), "seconds, cleaning up session data for this SSID");
delete ssid_sessions[ssid]; delete ssid_sessions[ssid];
} }
}, timeout, socket.ssid); }, timeout, socket.ssid);
@@ -1375,7 +1403,7 @@ try {
} }
} }
} catch (e) { } catch (e) {
if (zdebug) console.error(" * Notice: Could not find user configuration (user_config.json). Using default configuration."); if (minisrv_config.config.debug_flags.debug) console.error(" * Notice: Could not find user configuration (user_config.json). Using default configuration.");
} }
if (throw_me) { if (throw_me) {
@@ -1457,40 +1485,41 @@ process.on('uncaughtException', function (err) {
}); });
// defaults // defaults
var zdebug = false; minisrv_config.config.debug_flags = [];
var zquiet = true; // will squash zdebug even if its true minisrv_config.config.debug_flags.debug = false;
var zshowheaders = false; minisrv_config.config.debug_flags.quiet = true; // will squash minisrv_config.config.debug_flags.debug even if its true
minisrv_config.config.debug_flags.show_headers = false;
if (minisrv_config.config.verbosity) { if (minisrv_config.config.verbosity) {
switch (minisrv_config.config.verbosity) { switch (minisrv_config.config.verbosity) {
case 0: case 0:
zdebug = false; minisrv_config.config.debug_flags.debug = false;
zquiet = true; minisrv_config.config.debug_flags.quiet = true;
zshowheaders = false; minisrv_config.config.debug_flags.show_headers = false;
console.log(" * Console Verbosity level 0 (quietest)") console.log(" * Console Verbosity level 0 (quietest)")
break; break;
case 1: case 1:
zdebug = false; minisrv_config.config.debug_flags.debug = false;
zquiet = true; minisrv_config.config.debug_flags.quiet = true;
zshowheaders = true; minisrv_config.config.debug_flags.show_headers = true;
console.log(" * Console Verbosity level 1 (headers shown)") console.log(" * Console Verbosity level 1 (headers shown)")
break; break;
case 2: case 2:
zdebug = true; minisrv_config.config.debug_flags.debug = true;
zquiet = true; minisrv_config.config.debug_flags.quiet = true;
zshowheaders = false; minisrv_config.config.debug_flags.show_headers = false;
console.log(" * Console Verbosity level 2 (verbose without headers)") console.log(" * Console Verbosity level 2 (verbose without headers)")
break; break;
case 3: case 3:
zdebug = true; minisrv_config.config.debug_flags.debug = true;
zquiet = true; minisrv_config.config.debug_flags.quiet = true;
zshowheaders = true; minisrv_config.config.debug_flags.show_headers = true;
console.log(" * Console Verbosity level 3 (verbose with headers)") console.log(" * Console Verbosity level 3 (verbose with headers)")
break; break;
default: default:
zdebug = true; minisrv_config.config.debug_flags.debug = true;
zquiet = false; minisrv_config.config.debug_flags.quiet = false;
zshowheaders = true; minisrv_config.config.debug_flags.show_headers = true;
console.log(" * Console Verbosity level 4 (debug verbosity)") console.log(" * Console Verbosity level 4 (debug verbosity)")
break; break;
} }

View File

@@ -21,6 +21,7 @@
"enable_gzip_compression": true, "enable_gzip_compression": true,
"pc_server_hidden_service": "http_pc", "pc_server_hidden_service": "http_pc",
"pc_server_hidden_service_enabled": false, "pc_server_hidden_service_enabled": false,
"show_diskmap": false,
"allow_guests": true "allow_guests": true
}, },
"services": { "services": {