fix post bug, work on proxy

This commit is contained in:
zefie
2025-07-23 16:28:50 -04:00
parent 008c8a8bc3
commit 902ca0cda2
2 changed files with 19 additions and 8 deletions

View File

@@ -1951,8 +1951,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
socket.setTimeout(minisrv_config.config.post_data_socket_timeout * 1000); socket.setTimeout(minisrv_config.config.post_data_socket_timeout * 1000);
if (typeof socket_sessions[socket.id].post_data == "undefined") { if (typeof socket_sessions[socket.id].post_data == "undefined") {
if (socket_sessions[socket.id].post_data_percents_shown) delete socket_sessions[socket.id].post_data_percents_shown; if (socket_sessions[socket.id].post_data_percents_shown) delete socket_sessions[socket.id].post_data_percents_shown;
socket_sessions[socket.id].post_data_length = headers['Content-length'] || headers['Content-Length'] || 0; socket_sessions[socket.id].post_data_length = parseInt(headers['Content-length'] || headers['Content-Length'] || 0);
socket_sessions[socket.id].post_data_length = parseInt(socket_sessions[socket.id].post_data_length);
socket_sessions[socket.id].post_data = ""; socket_sessions[socket.id].post_data = "";
socket_sessions[socket.id].headers = headers; socket_sessions[socket.id].headers = headers;
var post_string = "POST"; var post_string = "POST";
@@ -1996,16 +1995,22 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
return; return;
} }
} else { } else {
if (headers.length > 0) {
socket_sessions[socket.id].headers = headers; socket_sessions[socket.id].headers = headers;
} }
}
} else if (socket.ssid) { } else if (socket.ssid) {
try { try {
// handle streaming POST // handle streaming POST
if (socket_sessions[socket.id].expecting_post_data && headers) { if (socket_sessions[socket.id].expecting_post_data && headers) {
if (socket_sessions[socket.id].post_data_length > (minisrv_config.config.max_post_length * 1024 * 1024)) { if (socket_sessions[socket.id].post_data_length > (minisrv_config.config.max_post_length * 1024 * 1024)) {
closeSocket(socket); closeSocket(socket);
} else {
if (headers.length == 0) {
headers = socket_sessions[socket.id].headers;
} else { } else {
socket_sessions[socket.id].headers = headers; socket_sessions[socket.id].headers = headers;
}
if (socket_sessions[socket.id].post_data.length < (socket_sessions[socket.id].post_data_length * 2)) { if (socket_sessions[socket.id].post_data.length < (socket_sessions[socket.id].post_data_length * 2)) {
new_header_obj = null; new_header_obj = null;
var enc_data = CryptoJS.enc.Hex.parse(data_hex); var enc_data = CryptoJS.enc.Hex.parse(data_hex);
@@ -2040,24 +2045,30 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
} }
} }
} }
if (socket_sessions[socket.id].post_data.length == (socket_sessions[socket.id].post_data_length * 2)) { if (socket_sessions[socket.id].post_data.length == (socket_sessions[socket.id].post_data_length * 2)) {
// got all expected data // got all expected data
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;
socket.setTimeout(minisrv_config.config.socket_timeout * 1000); socket.setTimeout(minisrv_config.config.socket_timeout * 1000);
if (headers.length == 0) {
var errpage = wtvshared.doErrorPage(400, `${minisrv_config.config.service_name} ran into a technical problem, please try again.`);
headers = errpage[0];
data = errpage[1];
sendToClient(socket, headers, data);
return;
}
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 (minisrv_config.config.debug_flags.debug) console.debug(" # Encrypted POST Content (SECURE ON)", "on", socket.id, "[", headers.post_data.sigBytes, "bytes ]"); if (minisrv_config.config.debug_flags.debug) console.debug(" # Encrypted POST Content (SECURE ON)", "on", socket.id, "[", headers.post_data.sigBytes, "bytes ]");
} else { } else {
if (minisrv_config.config.debug_flags.debug) console.debug(" # Unencrypted POST Content", "on", socket.id); if (minisrv_config.config.debug_flags.debug) console.debug(" # Unencrypted POST Content", "on", socket.id);
} }
socket_sessions[socket.id].expecting_post_data = false;
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;
delete socket_sessions[socket.id].post_data_length; delete socket_sessions[socket.id].post_data_length;
processURL(socket, headers); processURL(socket, headers);
return; return;
} else if (socket_sessions[socket.id].post_data.length > (socket_sessions[socket.id].post_data_length * 2)) { } else if (socket_sessions[socket.id].post_data.length > (socket_sessions[socket.id].post_data_length * 2)) {
socket_sessions[socket.id].expecting_post_data = false;
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;
socket.setTimeout(minisrv_config.config.socket_timeout * 1000); socket.setTimeout(minisrv_config.config.socket_timeout * 1000);
// got too much data ? ... should not ever reach this code // got too much data ? ... should not ever reach this code

View File

@@ -164,7 +164,7 @@ wtv-expire-all: wtv-proxy:/`;
<display nooptions skipback showwhencomplete> <display nooptions skipback showwhencomplete>
<body bgcolor="#191919" text="#44cc55" link="36d5ff" vlink="36d5ff" fontsize="small"> <body bgcolor="#191919" text="#44cc55" link="36d5ff" vlink="36d5ff" fontsize="small">
<form method="POST" action="wtv-proxy:/proxy"> <form method="POST" action="wtv-proxy:/proxy">
<label for="url">URL:</label> <label for="url">&nbsp; URL:</label>
<input type="text" id="url" name="url" value="${url || request_headers.query.url}" size=30> <input type="text" id="url" name="url" value="${url || request_headers.query.url}" size=30>
<input type="hidden" name="z" value="${request_headers.query.z || '1.0'}"> <input type="hidden" name="z" value="${request_headers.query.z || '1.0'}">
<input type="hidden" name="t" value="${request_headers.query.t || 'jpg'}"> <input type="hidden" name="t" value="${request_headers.query.t || 'jpg'}">