fix compatbility with ancient bf0 builds

This commit is contained in:
zefie
2024-05-26 15:31:47 -04:00
parent f3feae65f3
commit 6b74a54118
2 changed files with 10 additions and 5 deletions

View File

@@ -965,6 +965,7 @@ function handleProxy(socket, request_type, request_headers, res, data) {
} }
var data_hex = Buffer.concat(data).toString('hex'); var data_hex = Buffer.concat(data).toString('hex');
if (data_hex.substring(0, 8) == "0d0a0d0a") data_hex = data_hex.substring(8); if (data_hex.substring(0, 8) == "0d0a0d0a") data_hex = data_hex.substring(8);
if (data_hex.substring(0, 8) == "0a0d0a") data_hex = data_hex.substring(6);
if (data_hex.substring(0, 4) == "0a0a") data_hex = data_hex.substring(4); if (data_hex.substring(0, 4) == "0a0a") data_hex = data_hex.substring(4);
sendToClient(socket, headers, Buffer.from(data_hex, 'hex')); sendToClient(socket, headers, Buffer.from(data_hex, 'hex'));
} }
@@ -1473,9 +1474,12 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
} }
var data = Buffer.from(data_hex, 'hex').toString('ascii'); var data = Buffer.from(data_hex, 'hex').toString('ascii');
if (typeof data === "string") { if (typeof data === "string") {
if ((data.indexOf("\r\n\r\n") != -1 || data.indexOf("\n\n") != -1) && typeof socket_sessions[socket.id].post_data == "undefined") { if ((data.indexOf("\r\n\r\n") != -1 || data.indexOf("\n\n") != -1 || data.indexOf("\n\r\n") != -1) && typeof socket_sessions[socket.id].post_data == "undefined") {
if (data.indexOf("\r\n\r\n") != -1) { if (data.indexOf("\r\n\r\n") != -1) {
data = data.split("\r\n\r\n")[0]; data = data.split("\r\n\r\n")[0];
} else if (data.indexOf("\n\r\n") != -1) {
// early builds
data = data.split("\n\r\n")[0];
} else { } else {
data = data.split("\n\n")[0]; data = data.split("\n\n")[0];
} }
@@ -1652,7 +1656,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
var secure_headers = null; var secure_headers = null;
if (headers['request']) { if (headers['request']) {
if (headers['request'] == "GET") { if (headers['request'] == "GET") {
if (socket_sessions[socket.id].secure_buffer.indexOf("0d0a0d0a") || socket_sessions[socket.id].secure_buffer.indexOf("0a0a")) { if (socket_sessions[socket.id].secure_buffer.indexOf("0d0a0d0a") || socket_sessions[socket.id].secure_buffer.indexOf("0a0d0a") ||socket_sessions[socket.id].secure_buffer.indexOf("0a0a")) {
secure_headers = await processRequest(socket, socket_sessions[socket.id].secure_buffer, true, true); secure_headers = await processRequest(socket, socket_sessions[socket.id].secure_buffer, true, true);
} }
} else { } else {
@@ -1714,6 +1718,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
// the client may have just sent the data with the primary headers, so lets look for that. // the client may have just sent the data with the primary headers, so lets look for that.
if (data_hex.indexOf("0d0a0d0a") != -1) socket_sessions[socket.id].post_data = data_hex.substring(data_hex.indexOf("0d0a0d0a") + 8); if (data_hex.indexOf("0d0a0d0a") != -1) socket_sessions[socket.id].post_data = data_hex.substring(data_hex.indexOf("0d0a0d0a") + 8);
if (data_hex.indexOf("0a0d0a") != -1) socket_sessions[socket.id].post_data = data_hex.substring(data_hex.indexOf("0a0d0a") + 6);
if (data_hex.indexOf("0a0a") != -1) socket_sessions[socket.id].post_data = data_hex.substring(data_hex.indexOf("0a0a") + 4); if (data_hex.indexOf("0a0a") != -1) socket_sessions[socket.id].post_data = data_hex.substring(data_hex.indexOf("0a0a") + 4);
} }
@@ -1850,7 +1855,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
var secure_headers = null; var secure_headers = null;
if (headers['request']) { if (headers['request']) {
if (headers['request'] == "GET") { if (headers['request'] == "GET") {
if (socket_sessions[socket.id].secure_buffer.indexOf("0d0a0d0a") || socket_sessions[socket.id].secure_buffer.indexOf("0a0a")) { if (socket_sessions[socket.id].secure_buffer.indexOf("0d0a0d0a") || socket_sessions[socket.id].secure_buffer.indexOf("0a0d0a") || socket_sessions[socket.id].secure_buffer.indexOf("0a0a")) {
secure_headers = await processRequest(socket, socket_sessions[socket.id].secure_buffer, true, true); secure_headers = await processRequest(socket, socket_sessions[socket.id].secure_buffer, true, true);
} }
} else { } else {
@@ -1954,7 +1959,7 @@ async function handleSocket(socket) {
// buffer unencrypted data until we see the classic double-newline, or get blank // buffer unencrypted data until we see the classic double-newline, or get blank
if (!socket_sessions[socket.id].header_buffer) socket_sessions[socket.id].header_buffer = ""; if (!socket_sessions[socket.id].header_buffer) socket_sessions[socket.id].header_buffer = "";
socket_sessions[socket.id].header_buffer += data_hex; socket_sessions[socket.id].header_buffer += data_hex;
if (socket_sessions[socket.id].header_buffer.indexOf("0d0a0d0a") != -1 || socket_sessions[socket.id].header_buffer.indexOf("0a0a") != -1) { if (socket_sessions[socket.id].header_buffer.indexOf("0d0a0d0a") != -1 || socket_sessions[socket.id].header_buffer.indexOf("0a0d0a") != -1 || socket_sessions[socket.id].header_buffer.indexOf("0a0a") != -1) {
data_hex = socket_sessions[socket.id].header_buffer; data_hex = socket_sessions[socket.id].header_buffer;
delete socket_sessions[socket.id].header_buffer; delete socket_sessions[socket.id].header_buffer;
processRequest(this, data_hex); processRequest(this, data_hex);

View File

@@ -177,7 +177,7 @@ if (session_data.data_store.wtvsec_login) {
if (!session_data.lockdown) headers += getServiceString('wtv-flashrom') + "\n"; if (!session_data.lockdown) headers += getServiceString('wtv-flashrom') + "\n";
if (bf0app_update) headers += "wtv-boot-url: " + gourl + "\n"; if (bf0app_update) headers += "wtv-boot-url: " + gourl + "\n";
else { else {
headers += "wtv-boot-url: wtv-head-waiter:/relogin?relogin=true"; headers += "wtv-boot-url: wtv-head-waiter:/login?relogin=true";
if (request_headers.query.guest_login) headers += "&guest_login=true"; if (request_headers.query.guest_login) headers += "&guest_login=true";
headers += "\n"; headers += "\n";
} }