Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ log = "0.4"
simplelog = "0.12"
base64 = "0.21"
dotenvy = "0.15"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
20 changes: 20 additions & 0 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use tokio_rustls::TlsAcceptor;
use log::{info, error, warn};
use crate::auth::verify_basic_auth;
use std::env;
use std::fs::OpenOptions;
use std::io::Write;
use chrono::Local;

// 获取系统代理设置
fn get_system_proxy() -> Option<(String, u16)> {
Expand Down Expand Up @@ -43,6 +46,21 @@ fn parse_proxy_url(url: &str) -> Option<(String, u16)> {
None
}

fn record_connection(ip: std::net::IpAddr, target: &str) {
let now = Local::now().format("%Y-%m-%d %H:%M:%S");
match OpenOptions::new().create(true).append(true).open("connections.txt") {
Ok(mut file) => {
let line = format!("{} {} {}\n", now, ip, target);
if let Err(e) = file.write_all(line.as_bytes()) {
error!("\u5199\u5165\u8fde\u63a5\u8bb0\u5f55\u5931\u8d25: {}", e);
}
}
Err(e) => {
error!("\u65e0\u6cd5\u6253\u5f00\u8fde\u63a5\u8bb0\u5f55\u6587\u4ef6: {}", e);
}
}
}

// 通过代理连接目标
async fn connect_through_proxy(proxy_host: &str, proxy_port: u16, target: &str) -> Result<TcpStream, Box<dyn std::error::Error + Send + Sync>> {
info!("通过代理 {}:{} 连接目标: {}", proxy_host, proxy_port, target);
Expand Down Expand Up @@ -204,6 +222,8 @@ Proxy-Authenticate: Basic realm=\"EasyProxy\"\r\n\r\n",
.await;
return;
}

record_connection(peer.ip(), target);

// 连接目标服务器(通过系统代理或直接连接)
info!("开始连接目标服务器: {}", target);
Expand Down
Loading