v0.9.9
- update: config.json: add DoNotEncrypt flags to http and https - update: app.js: add ability to override service flags when using getServiceString - update: app.js: add ability to disable 'wtv-star' while keeping 'wtv-*' - update: app.js: add internal header 'minisrv-use-carriage-return', set to 'false' to disable `\r` in headers - implement bf0app flashrom functionality - update: actually fix wtv-1800:/preregister and include tellyscripts
This commit is contained in:
@@ -12,11 +12,12 @@ if (wtvsec_login) {
|
||||
|
||||
headers = `200 OK
|
||||
Connection: Keep-Alive
|
||||
minisrv-use-carriage-return: false
|
||||
wtv-initial-key: ` + wtvsec_login.challenge_key.toString(CryptoJS.enc.Base64) + `
|
||||
Content-Type: text/tellyscript
|
||||
wtv-service: reset
|
||||
` + getServiceString('wtv-head-waiter') + `
|
||||
` + getServiceString('wtv-star') + `
|
||||
` + getServiceString('wtv-star', { "no_star_word": true }) + `
|
||||
` + getServiceString('wtv-flashrom') + `
|
||||
wtv-boot-url: wtv-head-waiter:/login?
|
||||
wtv-visit: wtv-head-waiter:/login?
|
||||
@@ -24,22 +25,16 @@ wtv-client-time-zone: GMT -0000
|
||||
wtv-client-time-dst-rule: GMT
|
||||
wtv-client-date: `+ strftime("%a, %d %b %Y %H:%M:%S", new Date(new Date().toUTCString())) + ` GMT`;
|
||||
|
||||
var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/bf0app/bf0app_production_braindead";
|
||||
//var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/LC2/LC2_OISP_5555732_56k.tok";
|
||||
var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/BF0APP/bf0app_boot_uncompressed.tok";
|
||||
|
||||
if (file_path) {
|
||||
request_is_async = true;
|
||||
fs.readFile(file_path, null, function (err, file_read_data) {
|
||||
if (err) {
|
||||
|
||||
headers=`500 Some error occurred...`
|
||||
}
|
||||
sendToClient(socket, headers, file_read_data);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
console.log(" * Something bad happened (we don't know the client ssid???)");
|
||||
@@ -1,6 +1,5 @@
|
||||
var gourl = "wtv-head-waiter:/login?";
|
||||
if (request_headers.query.relogin) gourl += "relogin=true";
|
||||
var send_initial_key = true;
|
||||
|
||||
if (socket.ssid) {
|
||||
if (ssid_sessions[socket.ssid].data_store) {
|
||||
@@ -46,7 +45,7 @@ if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
|
||||
var send_tellyscripts = (minisrv_config.services[service_name].send_tellyscripts && !request_headers.query.relogin);
|
||||
var wtv_script_id = parseInt(ssid_sessions[socket.ssid].get("wtv-script-id"));
|
||||
var bootrom = ssid_sessions[socket.ssid].get("wtv-client-bootrom-version");
|
||||
if (request_headers.query.relogin && wtv_script_id != 0) send_tellyscript = false;
|
||||
if (request_headers.query.relogin && wtv_script_id != 0) send_tellyscripts = false;
|
||||
if (send_tellyscripts) {
|
||||
if (minisrv_config.services[service_name].send_tellyscript_ssid_whitelist) {
|
||||
var send_telly_to_ssid = (minisrv_config.services[service_name].send_tellyscript_ssid_whitelist.findIndex(element => element == socket.ssid) != -1)
|
||||
@@ -103,36 +102,43 @@ if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
|
||||
// assume old classic in flash mode, override user setting and send tellyscript
|
||||
// because it is required to proceed in flash mode
|
||||
prereg_contype = "text/tellyscript";
|
||||
var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/bf0app/bf0app_production_braindead.tok";
|
||||
bf0app_update = true;
|
||||
var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/BF0APP/bf0app_boot_uncompressed.tok";
|
||||
var bf0app_update = true;
|
||||
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
||||
}
|
||||
|
||||
if (request_headers["wtv-ticket"]) {
|
||||
gourl = "wtv-head-waiter:/login-stage-two?relogin=true";
|
||||
send_initial_key = false;
|
||||
}
|
||||
|
||||
headers = "200 OK\n"
|
||||
if (bf0app_update) headers += "minisrv-use-carriage-return: false\n";
|
||||
headers += "Connection: Keep-Alive\n";
|
||||
if (send_initial_key) headers += "wtv-initial-key: " + ssid_sessions[socket.ssid].data_store.wtvsec_login.challenge_key.toString(CryptoJS.enc.Base64) + "\n";
|
||||
headers += "wtv-initial-key: " + ssid_sessions[socket.ssid].data_store.wtvsec_login.challenge_key.toString(CryptoJS.enc.Base64) + "\n";
|
||||
headers += "Content-Type: " + prereg_contype + "\n";
|
||||
headers += "wtv-service: reset\n";
|
||||
headers += getServiceString('wtv-1800') + "\n";
|
||||
headers += getServiceString('wtv-star') + "\n";
|
||||
if (!bf0app_update) headers += getServiceString('wtv-head-waiter') + "\n";
|
||||
if (!bf0app_update) headers += getServiceString('wtv-1800') + "\n";
|
||||
|
||||
if (bf0app_update) headers += getServiceString('wtv-head-waiter', { "flags": "0x00000001" }) + "\n";
|
||||
else headers += getServiceString('wtv-head-waiter') + "\n";
|
||||
|
||||
if (bf0app_update) headers += getServiceString('wtv-star', { "no_star_word": true }) + "\n";
|
||||
else headers += getServiceString('wtv-star') + "\n";
|
||||
|
||||
headers += getServiceString('wtv-flashrom') + "\n";
|
||||
if (!bf0app_update) headers += "wtv-boot-url: wtv-1800:/preregister?relogin=true\n"
|
||||
if (bf0app_update) headers += "wtv-boot-url: " + gourl + "\n";
|
||||
else headers += "wtv-boot-url: wtv-1800:/preregister?relogin=true\n";
|
||||
headers += "wtv-visit: " + gourl + "\n";
|
||||
if (!bf0app_update) headers += "wtv-open-isp-disabled: false\n";
|
||||
if (!bf0app_update) headers += "wtv-visit: "+gourl+"\n";
|
||||
if (!bf0app_update) headers += "wtv-client-time-zone: GMT -0000\n";
|
||||
if (!bf0app_update) headers += "wtv-client-time-dst-rule: GMT\n"
|
||||
if (!bf0app_update) headers += "wtv-client-date: " + strftime("%a, %d %b %Y %H:%M:%S", new Date(new Date().toUTCString())) + " GMT";
|
||||
headers += "wtv-client-time-zone: GMT -0000\n";
|
||||
headers += "wtv-client-time-dst-rule: GMT\n"
|
||||
headers += "wtv-client-date: " + strftime("%a, %d %b %Y %H:%M:%S", new Date(new Date().toUTCString())) + " GMT";
|
||||
|
||||
if (file_path) {
|
||||
request_is_async = true;
|
||||
fs.readFile(file_path, null, function (err, file_read_data) {
|
||||
if (err) {
|
||||
var errmsg = doErrorCode(400);
|
||||
var errmsg = doErrorPage(400);
|
||||
headers = errmsg[0];
|
||||
file_read_data = errmsg[1] + "\n" + err.toString();
|
||||
}
|
||||
@@ -140,7 +146,7 @@ if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
var errpage = doErrorCode(400);
|
||||
var errpage = doErrorPage(400);
|
||||
headers = errpage[0];
|
||||
data = errpage[1];
|
||||
}
|
||||
114
zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/current-noflash.js
Normal file
114
zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/current-noflash.js
Normal file
@@ -0,0 +1,114 @@
|
||||
// this build can be local or on zefie's server
|
||||
// to get the path from zefie's server, browse
|
||||
// https://archive.midnightchannel.net/zefie/files/wtv-flashrom/content/artemis-webtv-000/
|
||||
// and put everything from 'content/' onwards, including the part000.rom filename
|
||||
// example is below
|
||||
var default_build_to_send = minisrv_config.services[service_name].bf0app_default_rom || "content/artemis-webtv-000/build7181/daily-nondebug/bf0app-part000.rom";
|
||||
|
||||
headers = "200 OK\n";
|
||||
var request_path = "";
|
||||
var bf0app_update = true;
|
||||
if (request_headers.query.path) request_path = unescape(request_headers.query.path);
|
||||
else request_path = default_build_to_send;
|
||||
request_is_async = true;
|
||||
|
||||
if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") == "bf0app" && ssid_sessions[socket.ssid].get("wtv-client-bootrom-version") == "105") {
|
||||
// assume old classic in flash mode, override user setting and send tellyscript
|
||||
// because it is required to proceed in flash mode
|
||||
bf0app_update = true;
|
||||
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
||||
headers += "minisrv-use-carriage-return: false\n";
|
||||
}
|
||||
|
||||
function doLocalFlashROM(flashrom_file_path) {
|
||||
// use local flashrom files;
|
||||
try {
|
||||
fs.readFile(flashrom_file_path, null, function (err, data) {
|
||||
if (err) {
|
||||
errpage = doErrorPage(400)
|
||||
headers = errpage[0];
|
||||
data = err.toString();
|
||||
}
|
||||
sendToClient(socket, headers, data);
|
||||
});
|
||||
} catch (e) {
|
||||
var errpage = doErrorPage(404, "The service could not find the requested ROM.")
|
||||
headers = errpage[0];
|
||||
data = errpage[1];
|
||||
sendToClient(socket, headers, data);
|
||||
}
|
||||
}
|
||||
|
||||
function calculatedPath(data, path, numparts = null) {
|
||||
var data_128 = new Buffer.alloc(128);
|
||||
data.copy(data_128, 0, 0, 128);
|
||||
var flashrom_numparts = null;
|
||||
var flashrom_message = new Buffer.from(data_128.toString('hex').substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
|
||||
|
||||
if (numparts != null) flashrom_numparts = parseInt(numparts);
|
||||
if (!flashrom_numparts) flashrom_numparts = flashrom_message.substring(flashrom_message.length - 4).replace(/\D/g, '');
|
||||
|
||||
var ind = new Array();
|
||||
ind[0] = (path.indexOf("part") + 4);
|
||||
ind[1] = (path.indexOf(".", ind[0]) + 1);
|
||||
var flashrom_part_num = path.substr(ind[0], (path.length - ind[1]));
|
||||
var flashrom_lastpart = (flashrom_numparts == (parseInt(flashrom_part_num) + 1)) ? true : false;
|
||||
var flashrom_rompath = 'wtv-flashrom:/get-by-path?path=' + path;
|
||||
if (flashrom_lastpart) {
|
||||
flashrom_next_rompath = "wtv-flashrom:/lc2-download-complete?";
|
||||
} else {
|
||||
var flashrom_next_part_num = (parseInt(flashrom_part_num) + 1);
|
||||
if (flashrom_next_part_num < 10) flashrom_next_part_num = "00" + flashrom_next_part_num; // 1s
|
||||
else if (flashrom_next_part_num >= 10 && flashrom_next_part_num < 100) flashrom_next_part_num = "0" + flashrom_next_part_num; // 10s
|
||||
var flashrom_next_rompath = flashrom_rompath.replace("part" + flashrom_part_num, "part" + flashrom_next_part_num) + "&numparts=" + parseInt(flashrom_numparts);
|
||||
}
|
||||
return flashrom_next_rompath;
|
||||
}
|
||||
|
||||
if ((/\.brom$/).test(request_path)) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
|
||||
else headers += "Content-Type: binary/x-wtv-flashblock";
|
||||
|
||||
var flashrom_file_path = null;
|
||||
Object.keys(service_vaults).forEach(function (g) {
|
||||
if (flashrom_file_path != null) return;
|
||||
flashrom_file_path = service_vaults[g] + "/" + service_name + "/" + request_path;
|
||||
if (!fs.existsSync(flashrom_file_path)) flashrom_file_path = null;
|
||||
});
|
||||
if (minisrv_config.services[service_name].use_zefie_server && !flashrom_file_path) {
|
||||
// get flashrom files from archive.midnightchannel.net
|
||||
var options = {
|
||||
host: "archive.midnightchannel.net",
|
||||
path: "/zefie/files/wtv-flashrom/" + request_path,
|
||||
timeout: 5000,
|
||||
method: 'GET'
|
||||
}
|
||||
const req = https.request(options, function (res) {
|
||||
var data_hex = '';
|
||||
res.setEncoding('hex');
|
||||
|
||||
res.on('data', d => {
|
||||
data_hex += d;
|
||||
})
|
||||
|
||||
res.on('end', function () {
|
||||
if (!zquiet) console.log(` * Zefie's FlashROM Server HTTP Status: ${res.statusCode} ${res.statusMessage}`)
|
||||
if (res.statusCode == 200) {
|
||||
data = Buffer.from(data_hex, 'hex');
|
||||
} else if (res.statusCode == 404) {
|
||||
var errpage = doErrorPage(404, "The service could not find the requested ROM on zefie's server.")
|
||||
headers = errpage[0];
|
||||
data = errpage[1];
|
||||
} else {
|
||||
var errpage = doErrorPage(400)
|
||||
headers = errpage[0];
|
||||
data = errpage[1];
|
||||
}
|
||||
headers += "\nwtv-visit: " + calculatedPath(data, request_path);
|
||||
sendToClient(socket, headers, data);
|
||||
});
|
||||
});
|
||||
req.end();
|
||||
} else {
|
||||
doLocalFlashROM(flashrom_file_path);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
request_is_async = true;
|
||||
|
||||
|
||||
var bf0app_update = false;
|
||||
var request_path = unescape(request_headers.query.path);
|
||||
headers = "200 OK\n"
|
||||
|
||||
@@ -22,11 +24,44 @@ function doLocalFlashROM(flashrom_file_path) {
|
||||
}
|
||||
}
|
||||
|
||||
var romtype = ssid_sessions[socket.ssid].get("wtv-client-rom-type");
|
||||
if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") == "bf0app" && ssid_sessions[socket.ssid].get("wtv-client-bootrom-version") == "105") {
|
||||
// assume old classic in flash mode, override user setting and send tellyscript
|
||||
// because it is required to proceed in flash mode
|
||||
bf0app_update = true;
|
||||
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
||||
headers += "minisrv-use-carriage-return: false\n";
|
||||
}
|
||||
|
||||
if (request_headers.query.raw || romtype == "bf0app") {
|
||||
|
||||
function calculatedPath(data, path, numparts = null) {
|
||||
var data_128 = new Buffer.alloc(128);
|
||||
data.copy(data_128, 0, 0, 128);
|
||||
var flashrom_numparts = null;
|
||||
var flashrom_message = new Buffer.from(data_128.toString('hex').substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
|
||||
|
||||
if (numparts != null) flashrom_numparts = parseInt(numparts);
|
||||
if (!flashrom_numparts) flashrom_numparts = flashrom_message.substring(flashrom_message.length - 4).replace(/\D/g, '');
|
||||
|
||||
var ind = new Array();
|
||||
ind[0] = (path.indexOf("part") + 4);
|
||||
ind[1] = (path.indexOf(".", ind[0]) + 1);
|
||||
var flashrom_part_num = path.substr(ind[0], (path.length - ind[1]));
|
||||
var flashrom_lastpart = (flashrom_numparts == (parseInt(flashrom_part_num) + 1)) ? true : false;
|
||||
var flashrom_rompath = 'wtv-flashrom:/get-by-path?path=' + path;
|
||||
if (flashrom_lastpart) flashrom_next_rompath = null;
|
||||
else {
|
||||
var flashrom_next_part_num = (parseInt(flashrom_part_num) + 1);
|
||||
if (flashrom_next_part_num < 10) flashrom_next_part_num = "00" + flashrom_next_part_num; // 1s
|
||||
else if (flashrom_next_part_num >= 10 && flashrom_next_part_num < 100) flashrom_next_part_num = "0" + flashrom_next_part_num; // 10s
|
||||
var flashrom_next_rompath = flashrom_rompath.replace("part" + flashrom_part_num, "part" + flashrom_next_part_num) + "&numparts=" + parseInt(flashrom_numparts);
|
||||
}
|
||||
return flashrom_next_rompath;
|
||||
}
|
||||
|
||||
if (request_headers.query.raw || bf0app_update) {
|
||||
if ((/\.brom$/).test(request_path)) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
|
||||
else headers += "Content-Type: binary/x-wtv-flashblock";
|
||||
|
||||
var flashrom_file_path = null;
|
||||
Object.keys(service_vaults).forEach(function (g) {
|
||||
if (flashrom_file_path != null) return;
|
||||
@@ -62,6 +97,11 @@ if (request_headers.query.raw || romtype == "bf0app") {
|
||||
headers = errpage[0];
|
||||
data = errpage[1];
|
||||
}
|
||||
if (bf0app_update) {
|
||||
var nextpath = calculatedPath(data, request_path, (request_headers.query.numparts || null));
|
||||
if (nextpath != null) headers += "\nwtv-visit: " + nextpath;
|
||||
}
|
||||
else headers += "\nwtv-connection-close: true";
|
||||
sendToClient(socket, headers, data);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -89,7 +89,8 @@ if (!request_headers.query.path) {
|
||||
}
|
||||
|
||||
async function processLC2DownloadPage(path, flashrom_message, numparts = null) {
|
||||
if (numparts != null) var flashrom_numparts = parseInt(numparts);
|
||||
var flashrom_numparts = null;
|
||||
if (numparts != null) flashrom_numparts = parseInt(numparts);
|
||||
if (!flashrom_numparts) flashrom_numparts = flashrom_message.substring(flashrom_message.length - 4).replace(/\D/g, '');
|
||||
var ind = new Array();
|
||||
ind[0] = (path.indexOf("part") + 4);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
if (request_headers.query.path) {
|
||||
var url = "wtv-flashrom:/get-lc2-page?path=" + request_headers.query.path;
|
||||
var romtype = ssid_sessions[socket.ssid].get("wtv-client-rom-type");
|
||||
if (romtype == "bf0app") {
|
||||
url = "client:updateflash?ipaddr="+minisrv_config.services[service_name].host+"&port="+minisrv_config.services[service_name].port+"&path=" + request_headers.query.path;
|
||||
}
|
||||
if (romtype == "bf0app") {
|
||||
url = "client:updateflash?ipaddr=" + minisrv_config.services[service_name].host + "&port=" + minisrv_config.services[service_name].port + "&path=" + escape(url.replace("get-lc2-page", "get-by-path"));
|
||||
if (request_headers.query.numparts) url += escape("&numparts=" + request_headers.query.numparts);
|
||||
}
|
||||
headers = "300 OK\n";
|
||||
headers += "wtv-visit: " + url + "\n";
|
||||
headers += "Location: " + url + "\n";
|
||||
|
||||
114
zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/noflash.js
Normal file
114
zefie_wtvp_minisrv/ServiceVault/wtv-flashrom/noflash.js
Normal file
@@ -0,0 +1,114 @@
|
||||
// this build can be local or on zefie's server
|
||||
// to get the path from zefie's server, browse
|
||||
// https://archive.midnightchannel.net/zefie/files/wtv-flashrom/content/artemis-webtv-000/
|
||||
// and put everything from 'content/' onwards, including the part000.rom filename
|
||||
// example is below
|
||||
var default_build_to_send = minisrv_config.services[service_name].bf0app_default_rom || "content/artemis-webtv-000/build7181/daily-nondebug/bf0app-part000.rom";
|
||||
|
||||
headers = "200 OK\n";
|
||||
var request_path = "";
|
||||
var bf0app_update = true;
|
||||
if (request_headers.query.path) request_path = unescape(request_headers.query.path);
|
||||
else request_path = default_build_to_send;
|
||||
request_is_async = true;
|
||||
|
||||
if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") == "bf0app" && ssid_sessions[socket.ssid].get("wtv-client-bootrom-version") == "105") {
|
||||
// assume old classic in flash mode, override user setting and send tellyscript
|
||||
// because it is required to proceed in flash mode
|
||||
bf0app_update = true;
|
||||
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
||||
headers += "minisrv-use-carriage-return: false\n";
|
||||
}
|
||||
|
||||
function doLocalFlashROM(flashrom_file_path) {
|
||||
// use local flashrom files;
|
||||
try {
|
||||
fs.readFile(flashrom_file_path, null, function (err, data) {
|
||||
if (err) {
|
||||
errpage = doErrorPage(400)
|
||||
headers = errpage[0];
|
||||
data = err.toString();
|
||||
}
|
||||
sendToClient(socket, headers, data);
|
||||
});
|
||||
} catch (e) {
|
||||
var errpage = doErrorPage(404, "The service could not find the requested ROM.")
|
||||
headers = errpage[0];
|
||||
data = errpage[1];
|
||||
sendToClient(socket, headers, data);
|
||||
}
|
||||
}
|
||||
|
||||
function calculatedPath(data, path, numparts = null) {
|
||||
var data_128 = new Buffer.alloc(128);
|
||||
data.copy(data_128, 0, 0, 128);
|
||||
var flashrom_numparts = null;
|
||||
var flashrom_message = new Buffer.from(data_128.toString('hex').substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
|
||||
|
||||
if (numparts != null) flashrom_numparts = parseInt(numparts);
|
||||
if (!flashrom_numparts) flashrom_numparts = flashrom_message.substring(flashrom_message.length - 4).replace(/\D/g, '');
|
||||
|
||||
var ind = new Array();
|
||||
ind[0] = (path.indexOf("part") + 4);
|
||||
ind[1] = (path.indexOf(".", ind[0]) + 1);
|
||||
var flashrom_part_num = path.substr(ind[0], (path.length - ind[1]));
|
||||
var flashrom_lastpart = (flashrom_numparts == (parseInt(flashrom_part_num) + 1)) ? true : false;
|
||||
var flashrom_rompath = 'wtv-flashrom:/get-by-path?path=' + path;
|
||||
if (flashrom_lastpart) {
|
||||
flashrom_next_rompath = "wtv-flashrom:/lc2-download-complete?";
|
||||
} else {
|
||||
var flashrom_next_part_num = (parseInt(flashrom_part_num) + 1);
|
||||
if (flashrom_next_part_num < 10) flashrom_next_part_num = "00" + flashrom_next_part_num; // 1s
|
||||
else if (flashrom_next_part_num >= 10 && flashrom_next_part_num < 100) flashrom_next_part_num = "0" + flashrom_next_part_num; // 10s
|
||||
var flashrom_next_rompath = flashrom_rompath.replace("part" + flashrom_part_num, "part" + flashrom_next_part_num) + "&numparts=" + parseInt(flashrom_numparts);
|
||||
}
|
||||
return flashrom_next_rompath;
|
||||
}
|
||||
|
||||
if ((/\.brom$/).test(request_path)) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
|
||||
else headers += "Content-Type: binary/x-wtv-flashblock";
|
||||
|
||||
var flashrom_file_path = null;
|
||||
Object.keys(service_vaults).forEach(function (g) {
|
||||
if (flashrom_file_path != null) return;
|
||||
flashrom_file_path = service_vaults[g] + "/" + service_name + "/" + request_path;
|
||||
if (!fs.existsSync(flashrom_file_path)) flashrom_file_path = null;
|
||||
});
|
||||
if (minisrv_config.services[service_name].use_zefie_server && !flashrom_file_path) {
|
||||
// get flashrom files from archive.midnightchannel.net
|
||||
var options = {
|
||||
host: "archive.midnightchannel.net",
|
||||
path: "/zefie/files/wtv-flashrom/" + request_path,
|
||||
timeout: 5000,
|
||||
method: 'GET'
|
||||
}
|
||||
const req = https.request(options, function (res) {
|
||||
var data_hex = '';
|
||||
res.setEncoding('hex');
|
||||
|
||||
res.on('data', d => {
|
||||
data_hex += d;
|
||||
})
|
||||
|
||||
res.on('end', function () {
|
||||
if (!zquiet) console.log(` * Zefie's FlashROM Server HTTP Status: ${res.statusCode} ${res.statusMessage}`)
|
||||
if (res.statusCode == 200) {
|
||||
data = Buffer.from(data_hex, 'hex');
|
||||
} else if (res.statusCode == 404) {
|
||||
var errpage = doErrorPage(404, "The service could not find the requested ROM on zefie's server.")
|
||||
headers = errpage[0];
|
||||
data = errpage[1];
|
||||
} else {
|
||||
var errpage = doErrorPage(400)
|
||||
headers = errpage[0];
|
||||
data = errpage[1];
|
||||
}
|
||||
headers += "\nwtv-visit: " + calculatedPath(data, request_path);
|
||||
sendToClient(socket, headers, data);
|
||||
});
|
||||
});
|
||||
req.end();
|
||||
} else {
|
||||
doLocalFlashROM(flashrom_file_path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user