diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-1800/noflash.js b/zefie_wtvp_minisrv/ServiceVault/wtv-1800/noflash.js index 984e5442..1c68e5b8 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-1800/noflash.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-1800/noflash.js @@ -1,5 +1,5 @@ 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.set_incarnation(request_headers["wtv-incarnation"]); ssid_sessions[socket.ssid].set("wtvsec_login", wtvsec_login); diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-1800/preregister.js b/zefie_wtvp_minisrv/ServiceVault/wtv-1800/preregister.js index 8548ff59..43f3e7d6 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-1800/preregister.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-1800/preregister.js @@ -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 (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; } - 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.set_incarnation(request_headers["wtv-incarnation"] || 1); } else { @@ -117,7 +117,7 @@ if (ssid_sessions[socket.ssid].data_store.wtvsec_login) { 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) { send_tellyscript = false; diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-disk/content/Modem_Firmware/Locale/en-US/modem_firmware.dat.gz b/zefie_wtvp_minisrv/ServiceVault/wtv-disk/content/Modem_Firmware/Locale/en-US/modem_firmware.dat.gz new file mode 100644 index 00000000..70fb3441 Binary files /dev/null and b/zefie_wtvp_minisrv/ServiceVault/wtv-disk/content/Modem_Firmware/Locale/en-US/modem_firmware.dat.gz differ diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-disk/content/Modem_Firmware/Locale/ja-JP/modem_firmware.dat.gz b/zefie_wtvp_minisrv/ServiceVault/wtv-disk/content/Modem_Firmware/Locale/ja-JP/modem_firmware.dat.gz new file mode 100644 index 00000000..a936d1dd Binary files /dev/null and b/zefie_wtvp_minisrv/ServiceVault/wtv-disk/content/Modem_Firmware/Locale/ja-JP/modem_firmware.dat.gz differ diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-disk/content/diskmaps/ModemFirmware.json b/zefie_wtvp_minisrv/ServiceVault/wtv-disk/content/diskmaps/ModemFirmware.json new file mode 100644 index 00000000..25de241e --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-disk/content/diskmaps/ModemFirmware.json @@ -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" + } + ] + } +} \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-disk/sync.js b/zefie_wtvp_minisrv/ServiceVault/wtv-disk/sync.js index 7352e28f..0b1b075b 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-disk/sync.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-disk/sync.js @@ -90,6 +90,7 @@ if (request_headers['wtv-request-type'] == 'download') { } } var download_list = wtvdl.getDownloadList(); + if (minisrv_config.config.show_diskmap) console.log(download_list); return download_list; } @@ -259,13 +260,13 @@ if (request_headers['wtv-request-type'] == 'download') { var errpage = doErrorPage(404, "The requested DiskMap does not exist."); headers = errpage[0]; 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 { var errpage = doErrorPage(400); headers = errpage[0]; 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) { var message = request_headers.query.message || "Retrieving files..."; diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-disk/userstore.js b/zefie_wtvp_minisrv/ServiceVault/wtv-disk/userstore.js index 2ca7c442..f53bd496 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-disk/userstore.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-disk/userstore.js @@ -1,9 +1,9 @@ if (request_headers.post_data) { - if (request_headers.query.partialPath) { + if (request_headers.query.partialPath || request_headers.query.path) { if (socket.ssid) { if (ssid_sessions[socket.ssid]) { if (ssid_sessions[socket.ssid].isRegistered()) { - var result = ssid_sessions[socket.ssid].storeUserStoreFile(request_headers.query.partialPath, new Buffer.from(request_headers.post_data.toString(CryptoJS.enc.Hex), 'hex'), request_headers.query['last-modified-seconds'] || null, (request_headers.query.no_overwrite) ? false : true); + var result = ssid_sessions[socket.ssid].storeUserStoreFile(request_headers.query.path || request_headers.query.partialPath, new Buffer.from(request_headers.post_data.toString(CryptoJS.enc.Hex), 'hex'), request_headers.query['last-modified-seconds'] || null, (request_headers.query.no_overwrite) ? false : true); if (result) { headers = "200 OK\n"; headers += "Content-Type: text/plain"; diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/content/content-serve.js b/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/content/content-serve.js index 9753fcc2..9687db6f 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/content/content-serve.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/content/content-serve.js @@ -14,7 +14,7 @@ if ((romtype == "bf0app" || !romtype) && (bootver == "105" || !bootver)) { } 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) { diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/current-noflash.js b/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/current-noflash.js index 642803cf..745d92ff 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/current-noflash.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/current-noflash.js @@ -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) { - 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) { diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/get-by-path.js b/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/get-by-path.js index a2ad57e0..5815eb2b 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/get-by-path.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/get-by-path.js @@ -15,7 +15,7 @@ if ((romtype == "bf0app" || !romtype) && (bootver == "105" || !bootver)) { if (request_headers.query.raw || bf0app_update) { 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) { diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/get-lc2-page.js b/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/get-lc2-page.js index 3a4ea4fa..4a70db6d 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/get-lc2-page.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/get-lc2-page.js @@ -8,7 +8,7 @@ if (!request_headers.query.path) { headers = errpage[0]; data = errpage[1]; } 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; // read flashrom header info into array using WTVFlashrom class diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/noflash.js b/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/noflash.js index 03c990e9..1ee36f57 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/noflash.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/noflash.js @@ -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) { - 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) { diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/willie.js b/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/willie.js index 765de4e3..2ac678cf 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/willie.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/willie.js @@ -32,7 +32,7 @@ const req = https.request(options, function (res) { }); 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) headers = errpage[0]; data = errpage[1]; @@ -40,7 +40,7 @@ const req = https.request(options, function (res) { }); 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) { headers += "\nwtv-expire-all: "+service_name; } diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login-stage-two.js b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login-stage-two.js index 40281814..9d6dee8c 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login-stage-two.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login-stage-two.js @@ -2,7 +2,7 @@ var challenge_response, challenge_header = ''; var gourl; 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.set_incarnation(request_headers["wtv-incarnation"]); ssid_sessions[socket.ssid].set("wtvsec_login", wtvsec_login); @@ -21,8 +21,8 @@ if (socket.ssid !== null) { } else { console.log(" * wtv-challenge-response FAILED for " + wtvshared.filterSSID(socket.ssid)); - if (zdebug) 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 Expected:", challenge_response.toString(CryptoJS.enc.Base64)); + if (minisrv_config.config.debug_flags.debug) console.log("Response Received:", client_challenge_response) gourl = "wtv-head-waiter:/login?reissue_challenge=true"; } } else { diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-log/log.js b/zefie_wtvp_minisrv/ServiceVault/wtv-log/log.js index 84c43d47..b3e69ae5 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-log/log.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-log/log.js @@ -22,7 +22,7 @@ Content-length: 0`; logdata_outstring_hex += request_headers.post_data.toString(CryptoJS.enc.Hex); if (minisrv_config.services[service_name].write_logs_to_disk) { 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); }); } else { @@ -41,7 +41,7 @@ Content-length: 0`; var logdata_outstring_hex = Buffer.from(logdata_outstring, 'utf8').toString('hex'); if (minisrv_config.services[service_name].write_logs_to_disk) { 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); }); } else { diff --git a/zefie_wtvp_minisrv/WTVClientSessionData.js b/zefie_wtvp_minisrv/WTVClientSessionData.js index 48adda55..97c01819 100644 --- a/zefie_wtvp_minisrv/WTVClientSessionData.js +++ b/zefie_wtvp_minisrv/WTVClientSessionData.js @@ -103,15 +103,6 @@ class WTVClientSessionData { 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 {number} Number of cookies @@ -123,7 +114,7 @@ class WTVClientSessionData { resetCookies() { 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. - 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) { diff --git a/zefie_wtvp_minisrv/WTVDownloadList.js b/zefie_wtvp_minisrv/WTVDownloadList.js index 5e3c60f1..712a67e5 100644 --- a/zefie_wtvp_minisrv/WTVDownloadList.js +++ b/zefie_wtvp_minisrv/WTVDownloadList.js @@ -104,6 +104,7 @@ class WTVDownloadList { * @param {string} group Group to which it belongs */ delete(path, group = null) { + path = this.wtvshared.stripGzipFromPath(path); this.download_list += "DELETE " + path + "\n"; if (group !== null) this.download_list += "group: " + group + "\n\n"; } @@ -115,7 +116,7 @@ class WTVDownloadList { */ put(path, destination) { this.download_list += "PUT " + path + "\n"; - this.download_list += "location: " + destination + "\n"; + this.download_list += "location: " + destination + "\n\n"; } /** @@ -124,8 +125,7 @@ class WTVDownloadList { * @param {string} destination Destination file path in the User Store */ putUserStoreDest(path, destination) { - this.download_list += "PUT " + path + "\n"; - this.download_list += "location: " + this.service_name + ":/userstore?partialPath="+escape(destination) + "\n"; + this.put(path, this.service_name + ":/userstore?partialPath=" + escape(destination)); } /** @@ -134,8 +134,7 @@ class WTVDownloadList { */ putUserStore(path) { var destination = path.replace("file://", ""); - this.download_list += "PUT " + path + "\n"; - this.download_list += "location: " + this.service_name + ":/userstore?partialPath=" + escape(destination) + "\n\n"; + this.putUserStoreDest(path, destination); } /** * Adds a GET command to the download list @@ -147,13 +146,16 @@ class WTVDownloadList { * @param {string} checksum md5sum of the file * @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 += "group: " + group + "-UPDATE\n"; this.download_list += "location: " + source + "\n"; this.download_list += "file-permission: " + file_permission + "\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"; + path = this.wtvshared.stripGzipFromPath(path); this.download_list += "client-dest-location: " + path + "\n\n"; } @@ -165,6 +167,8 @@ class WTVDownloadList { * @param {string} destgroup Destination Group */ rename(srcfile, destfile, srcgroup, destgroup) { + srcfile = this.wtvshared.stripGzipFromPath(srcfile); + destfile = this.wtvshared.stripGzipFromPath(destfile); this.download_list += "RENAME " + srcfile + "\n"; this.download_list += "group: " + srcgroup + "-UPDATE\n"; this.download_list += "destination-group: " + destgroup + "\n"; diff --git a/zefie_wtvp_minisrv/WTVFlashrom.js b/zefie_wtvp_minisrv/WTVFlashrom.js index 93aba8f7..4985e54a 100644 --- a/zefie_wtvp_minisrv/WTVFlashrom.js +++ b/zefie_wtvp_minisrv/WTVFlashrom.js @@ -6,15 +6,15 @@ class WTVFlashrom { bf0app_update = false; service_vaults = new Array(); 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_name = service_name; this.use_zefie_server = use_zefie_server; 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.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); - 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); - 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); - 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; - 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); - 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 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 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.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.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 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 is Last Part", flashrom_info.is_last_part); if (flashrom_info.is_last_part && this.bf0app_update) { flashrom_info.next_rompath = null; @@ -179,7 +179,7 @@ class WTVFlashrom { }) 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) { var data = Buffer.from(data_hex, 'hex'); } else if (res.statusCode == 206) { diff --git a/zefie_wtvp_minisrv/WTVLzpf.js b/zefie_wtvp_minisrv/WTVLzpf.js index 5bfea2ea..09eb3cfd 100644 --- a/zefie_wtvp_minisrv/WTVLzpf.js +++ b/zefie_wtvp_minisrv/WTVLzpf.js @@ -400,8 +400,6 @@ class WTVLzpf { this.EncodeLiteral(code_length, code); } } - - return Buffer.from(this.encoded_data); } /** @@ -442,32 +440,26 @@ class WTVLzpf { // End this.AddByte((this.current_literal >>> 0x18) & 0xFF); this.AddByte(0x20); + + return Buffer.from(this.encoded_data); } /** * Converts the data to a Javascript Buffer object * - * @param data {String|Buffer|CryptoJS.lib.WordArray} Data to convert + * @param data {String|Buffer} Data to convert * * @returns {Buffer} Javascript Buffer object */ ConvertToBuffer(data) { - if (data.words) { - var WTVSec = require("./WTVSec.js"); - wtvsec = new WTVSec(1); - data = wtvsec.wordArrayToBuffer(data); - WTVSec, wtvsec = null; - } else if (!data.byteLength) { - // otherwise if its not already a Buffer, convert it to one - data = new Buffer.from(data); - } + data = new Buffer.from(data.toString('binary')); return data; } /** * Compress data using WebTV's Lzpf compression algorithm and adds the footer to the end. * - * @param uncompressed_data {String|Buffer|CryptoJS.lib.WordArray} data to compress + * @param uncompressed_data {String|Buffer} data to compress * * @returns {Buffer} Lzpf compression data */ @@ -475,9 +467,7 @@ class WTVLzpf { uncompressed_data = this.ConvertToBuffer(uncompressed_data); this.Begin(); this.EncodeBlock(uncompressed_data, true); - this.Finish(); - - return Buffer.from(this.encoded_data); + return this.Finish(); } } diff --git a/zefie_wtvp_minisrv/WTVSec.js b/zefie_wtvp_minisrv/WTVSec.js index 1d937b94..a73a5c31 100644 --- a/zefie_wtvp_minisrv/WTVSec.js +++ b/zefie_wtvp_minisrv/WTVSec.js @@ -31,19 +31,18 @@ class WTVSec { hRC4_Key1 = null; hRC4_Key2 = null; RC4Session = new Array(); - zdebug = false; - + minisrv_config = []; /** * * Initialize the WTVSec class. * * @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) { - this.zdebug = zdebug; + constructor(minisrv_config, wtv_incarnation = 1) { + this.minisrv_config = minisrv_config; this.initial_shared_key = CryptoJS.enc.Base64.parse(this.initial_shared_key_b64); if (this.initial_shared_key.sigBytes === 8) { @@ -248,7 +247,7 @@ class WTVSec { * */ 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)]); endianness(buf, 4); diff --git a/zefie_wtvp_minisrv/WTVShared.js b/zefie_wtvp_minisrv/WTVShared.js index eb744aff..a53a7800 100644 --- a/zefie_wtvp_minisrv/WTVShared.js +++ b/zefie_wtvp_minisrv/WTVShared.js @@ -5,6 +5,7 @@ class WTVShared { path = require('path'); + fs = require('fs'); 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 * @param {string|Array} obj SSID String or Headers Object @@ -66,6 +94,20 @@ class WTVShared { 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 * @param {string} path diff --git a/zefie_wtvp_minisrv/app.js b/zefie_wtvp_minisrv/app.js index fa4463a7..b7830369 100644 --- a/zefie_wtvp_minisrv/app.js +++ b/zefie_wtvp_minisrv/app.js @@ -134,7 +134,8 @@ async function processPath(socket, service_vault_file_path, request_headers = ne // file exists, read it and return it service_vault_found = 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); headers = "200 OK\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")) { // raw text format, entire payload expected (headers and content) 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; + 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) { if (file_raw.indexOf("\n\n") > 0) { // 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 // `socket` is already defined and should be passed-through. 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 var service_dir = service_vault_dir + path.sep + service_name; socket_sessions[socket.id].starttime = Math.floor(new Date().getTime() / 1000); var jscript_eval = fs.readFileSync(service_vault_file_path + ".js").toString(); 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")) { // Standard HTML with no headers, WTV Style 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; headers = "200 OK\n" 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) { var catchall_file = service_check_dir.join(path.sep) + path.sep + minisrv_catchall_file_name; 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(); // don't pass these vars to the script var service_check_dir, minisrv_catchall_file_name = null; 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 { service_check_dir.pop(); } @@ -269,6 +274,7 @@ async function processURL(socket, request_headers) { } else { 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) { var post_data_string = ''; @@ -351,7 +357,8 @@ async function processURL(socket, request_headers) { // assume webtv since there is a :/ in the GET var service_name = shortURL.split(':/')[0]; 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); } else if (shortURL.indexOf('http://') >= 0 || shortURL.indexOf('https://') >= 0) { doHTTPProxy(socket, request_headers); @@ -368,7 +375,7 @@ async function processURL(socket, request_headers) { async function doHTTPProxy(socket, request_headers) { 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) { case "https": var proxy_agent = https; @@ -567,11 +574,32 @@ async function sendToClient(socket, headers_obj, data) { 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 // small files actually get larger, so don't compress them var compression_type = 0; 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 if (compression_type > 0 && content_length > 0 && headers_obj['http_response'].substring(0,3) == "200") { var uncompressed_content_length = content_length; @@ -602,8 +630,9 @@ async function sendToClient(socket, headers_obj, data) { // ultimately send original content length if lzpf compressed_content_length = data.byteLength; } - var compression_percentage = ((compressed_content_length / uncompressed_content_length) * 100).toFixed(1).toString() + "%"; - 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_percentage); + var compression_ratio = (uncompressed_content_length / compressed_content_length).toFixed(2); + var compression_percentage = ((1 - (compressed_content_length / uncompressed_content_length)) * 100).toFixed(1); + 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 @@ -611,7 +640,7 @@ async function sendToClient(socket, headers_obj, data) { headers_obj["wtv-encrypted"] = 'true'; headers_obj = moveObjectElement('wtv-encrypted', 'Connection', headers_obj); 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); data = enc_data; } @@ -643,7 +672,7 @@ async function sendToClient(socket, headers_obj, data) { } // 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) { if (k == "http_response") { headers += headers_obj[k] + end_of_line; @@ -664,16 +693,16 @@ async function sendToClient(socket, headers_obj, data) { toClient = headers + end_of_line + data; socket.write(toClient); } 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) { // 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); socket.write(new Uint8Array(concatArrayBuffer(enc_headers, data))); } else { 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; @@ -781,7 +810,7 @@ function checkSecurity(socket) { } else { 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 @@ -850,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 if (socket_sessions[socket.id].secure != true) { // 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); - socket_sessions[socket.id].wtvsec = new WTVSec(1, zdebug); + 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(minisrv_config); socket_sessions[socket.id].wtvsec.IssueChallenge(); socket_sessions[socket.id].wtvsec.SecureOn(); socket_sessions[socket.id].secure = true; @@ -925,14 +954,14 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq if (ssid_sessions[socket.ssid]) { if (headers["wtv-ticket"]) { 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.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.DecodeTicket(ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64); } else { 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.DecodeTicket(ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64); ssid_sessions[socket.ssid].data_store.wtvsec_login.set_incarnation(headers["wtv-incarnation"]); @@ -944,11 +973,11 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq if ((headers.secure === true || headers.encrypted === true) && !skipSecure) { 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")) { - 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 { - 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.ticket_b64 = headers["wtv-ticket"]; @@ -956,7 +985,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq } if (socket_sessions[socket.id].secure != true) { // 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; } if (!headers.request_url) { @@ -990,8 +1019,8 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq if (!secure_headers) return; delete socket_sessions[socket.id].secure_buffer; - if (zdebug) console.log(" # Encrypted Request (SECURE ON)", "on", socket.id); - if (zshowheaders) console.log(secure_headers); + if (minisrv_config.config.debug_flags.debug) console.log(" # Encrypted Request (SECURE ON)", "on", socket.id); + if (minisrv_config.config.debug_flags.show_headers) console.log(secure_headers); if (!secure_headers.request) { socket_sessions[socket.id].secure = false; var errpage = doErrorPage(400); @@ -1133,9 +1162,9 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq socket.setTimeout(minisrv_config.config.socket_timeout * 1000); headers.post_data = CryptoJS.enc.Hex.parse(socket_sessions[socket.id].post_data); 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 { - 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].post_data; @@ -1157,7 +1186,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq } else if (!skipSecure) { if (!encryptedRequest) { 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.SecureOn(); socket_sessions[socket.id].secure = true; @@ -1221,7 +1250,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq async function cleanupSocket(socket) { try { 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]; } if (socket.ssid) { @@ -1241,7 +1270,7 @@ async function cleanupSocket(socket) { // set timeout to check ssid_sessions[socket.ssid].data_store.socket_check = setTimeout(function (ssid) { 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]; } }, timeout, socket.ssid); @@ -1374,7 +1403,7 @@ try { } } } 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) { @@ -1456,40 +1485,41 @@ process.on('uncaughtException', function (err) { }); // defaults -var zdebug = false; -var zquiet = true; // will squash zdebug even if its true -var zshowheaders = false; +minisrv_config.config.debug_flags = []; +minisrv_config.config.debug_flags.debug = 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) { switch (minisrv_config.config.verbosity) { case 0: - zdebug = false; - zquiet = true; - zshowheaders = false; + minisrv_config.config.debug_flags.debug = false; + minisrv_config.config.debug_flags.quiet = true; + minisrv_config.config.debug_flags.show_headers = false; console.log(" * Console Verbosity level 0 (quietest)") break; case 1: - zdebug = false; - zquiet = true; - zshowheaders = true; + minisrv_config.config.debug_flags.debug = false; + minisrv_config.config.debug_flags.quiet = true; + minisrv_config.config.debug_flags.show_headers = true; console.log(" * Console Verbosity level 1 (headers shown)") break; case 2: - zdebug = true; - zquiet = true; - zshowheaders = false; + minisrv_config.config.debug_flags.debug = true; + minisrv_config.config.debug_flags.quiet = true; + minisrv_config.config.debug_flags.show_headers = false; console.log(" * Console Verbosity level 2 (verbose without headers)") break; case 3: - zdebug = true; - zquiet = true; - zshowheaders = true; + minisrv_config.config.debug_flags.debug = true; + minisrv_config.config.debug_flags.quiet = true; + minisrv_config.config.debug_flags.show_headers = true; console.log(" * Console Verbosity level 3 (verbose with headers)") break; default: - zdebug = true; - zquiet = false; - zshowheaders = true; + minisrv_config.config.debug_flags.debug = true; + minisrv_config.config.debug_flags.quiet = false; + minisrv_config.config.debug_flags.show_headers = true; console.log(" * Console Verbosity level 4 (debug verbosity)") break; } diff --git a/zefie_wtvp_minisrv/config.json b/zefie_wtvp_minisrv/config.json index 34e80099..101339f4 100644 --- a/zefie_wtvp_minisrv/config.json +++ b/zefie_wtvp_minisrv/config.json @@ -21,6 +21,7 @@ "enable_gzip_compression": true, "pc_server_hidden_service": "http_pc", "pc_server_hidden_service_enabled": false, + "show_diskmap": false, "allow_guests": true }, "services": {