1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2025-08-10 22:41:43 +02:00
This commit is contained in:
Anton Titovets
2025-08-07 15:34:14 +03:00
parent 9f974a73c6
commit 706084560d
6 changed files with 30 additions and 54 deletions

View File

@@ -1,9 +1,9 @@
"MAIN ---"
linux-vdso.so.1 (0x00007ffd271d0000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007597c2a00000)
libc.so.6 => /lib64/libc.so.6 (0x00007597c2600000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007597c2200000)
/lib64/ld-linux-x86-64.so.2 (0x00007597c3000000)
linux-vdso.so.1 (0x00007ffe01bd1000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x000070999de00000)
libc.so.6 => /lib64/libc.so.6 (0x000070999da00000)
libdl.so.2 => /lib64/libdl.so.2 (0x000070999d600000)
/lib64/ld-linux-x86-64.so.2 (0x000070999e400000)
GLIBC_2.2.5
GLIBC_2.3
GLIBC_2.3.4

View File

@@ -6,6 +6,8 @@ use base64::{Engine as _, engine::general_purpose};
use suppaftp::FtpError;
use crate::component::configuration::{FtpProxySettings, FtpSettings};
use std::vec::IntoIter;
use std::fmt::Write as FmtWrite;
pub fn make_passive_proxy_stream(
ftp_settings: &FtpSettings,
@@ -124,35 +126,30 @@ fn connect_via_socks4(proxy_settings: &FtpProxySettings, target_addr: (&str, u16
.map_err(|e| format!("SOCKS4 error: {}", e))
}
pub fn connect_via_http_proxy(
proxy_settings: &FtpProxySettings,
target_addr: (&str, u16),
) -> Result<TcpStream, String> {
pub fn connect_via_http_proxy(proxy_settings: &FtpProxySettings, target_addr: (&str, u16)) -> Result<TcpStream, String> {
let proxy_addr = format!("{}:{}", proxy_settings.server, proxy_settings.port);
let max_retries = 5;
let connect_timeout = Duration::from_secs(10);
for attempt in 1..=max_retries {
let mut stream = TcpStream::connect_timeout(
&proxy_addr.to_socket_addrs()
let mut stream = TcpStream::connect(
proxy_addr.to_socket_addrs()
.map_err(|e| format!("Failed to resolve proxy address: {}", e))?
.next()
.ok_or_else(|| "Proxy address resolution returned no results".to_string())?,
connect_timeout,
.ok_or_else(|| "Proxy address resolution returned no results".to_string())?
).map_err(|e| format!("Failed to connect to HTTP proxy: {}", e))?;
stream.set_read_timeout(Some(Duration::from_secs(5))).map_err(|e| format!("Failed to set read timeout: {}", e))?;
stream.set_write_timeout(Some(Duration::from_secs(5))).map_err(|e| format!("Failed to set write timeout: {}", e))?;
stream.set_read_timeout(Some(Duration::from_secs(10))).ok();
stream.set_write_timeout(Some(Duration::from_secs(10))).ok();
let host_port = format!("{}:{}", target_addr.0, target_addr.1);
let mut request = format!(
"CONNECT {} HTTP/1.1\r\nHost: {}\r\n",
"CONNECT {} HTTP/1.1\r\nHost: {}\r\nConnection: keep-alive\r\n",
host_port, host_port
);
if let (Some(user), Some(pass)) = (&proxy_settings.login, &proxy_settings.password) {
let auth = general_purpose::STANDARD.encode(format!("{}:{}", user, pass));
request.push_str(&format!("Proxy-Authorization: Basic {}\r\n", auth));
write!(request, "Proxy-Authorization: Basic {}\r\n", auth).unwrap();
}
request.push_str("\r\n");
@@ -160,59 +157,38 @@ pub fn connect_via_http_proxy(
.map_err(|e| format!("Failed to send CONNECT request: {}", e))?;
let mut buf = [0u8; 4096];
let mut total_read = 0;
let mut response_code = None;
// Read until we get complete headers or buffer is full
while total_read < buf.len() && response_code.is_none() {
let n = stream.read(&mut buf[total_read..])
let n = stream.read(&mut buf)
.map_err(|e| format!("Failed to read proxy response: {}", e))?;
if n == 0 {
return Err("Proxy closed connection prematurely".to_string());
}
total_read += n;
// Parse HTTP response
let mut headers = [httparse::EMPTY_HEADER; 16];
let mut resp = httparse::Response::new(&mut headers);
match resp.parse(&buf[..total_read]) {
Ok(httparse::Status::Complete(parsed_len)) => {
response_code = resp.code;
// Consume any additional data in the buffer
if total_read > parsed_len {
// TODO: Handle any additional data if needed
}
}
Ok(httparse::Status::Partial) => continue, // Need more data
let mut response = httparse::Response::new(&mut headers);
match response.parse(&buf[..n]) {
Ok(httparse::Status::Complete(_)) => {},
Ok(httparse::Status::Partial) => return Err("Incomplete proxy response".to_string()),
Err(e) => return Err(format!("Failed to parse proxy response: {:?}", e)),
}
}
let code = response_code.ok_or_else(|| "Failed to parse HTTP status code".to_string())?;
let code = response.code.ok_or_else(|| "Missing HTTP status code in proxy response".to_string())?;
match code {
200 => return Ok(stream),
407 => return Err("Proxy authentication required (HTTP 407)".to_string()),
500..=599 => {
500 => {
if attempt < max_retries {
std::thread::sleep(Duration::from_millis(200 * attempt));
std::thread::sleep(Duration::from_millis(200));
continue;
} else {
let resp_str = String::from_utf8_lossy(&buf[..total_read]);
return Err(format!("Proxy error: HTTP {} after {} retries\nFull response:\n{}",
code, max_retries, resp_str));
let resp_str = String::from_utf8_lossy(&buf[..n]);
return Err(format!("Proxy error: HTTP 500 after {} retries\nFull response:\n{}", max_retries, resp_str));
}
}
_ => {
let resp_str = String::from_utf8_lossy(&buf[..total_read]);
let resp_str = String::from_utf8_lossy(&buf[..n]);
return Err(format!("Proxy error: HTTP {}\nFull response:\n{}", code, resp_str));
}
}
}
Err(format!("Failed to connect via proxy after {} attempts", max_retries))
Err("Unexpected proxy connection loop exit".to_string())
}

Binary file not shown.

Binary file not shown.