Compare commits
No commits in common. "d74d8184c387fa7af73fca65e2a7a655d7a70b21" and "322f473671adc736360358a2ab0bee5bd96655b7" have entirely different histories.
d74d8184c3
...
322f473671
12
config.toml
12
config.toml
@ -2,13 +2,7 @@ server = "irc.supernets.org"
|
|||||||
port = 6697
|
port = 6697
|
||||||
use_ssl = true
|
use_ssl = true
|
||||||
nickname = "g1r"
|
nickname = "g1r"
|
||||||
channel = "#superbowl"
|
channel = "#dev"
|
||||||
sasl_username = ""
|
sasl_username = "g1r"
|
||||||
sasl_password = ""
|
sasl_password = "fuckyou.lol"
|
||||||
capabilities = ["sasl"]
|
capabilities = ["sasl"]
|
||||||
use_proxy = false
|
|
||||||
proxy_type = "socks5"
|
|
||||||
proxy_addr = "127.0.0.1"
|
|
||||||
proxy_port = 9050
|
|
||||||
proxy_username = ""
|
|
||||||
proxy_password = ""
|
|
||||||
|
78
src/main.rs
78
src/main.rs
@ -1,4 +1,4 @@
|
|||||||
use tokio::io::{split, AsyncRead, AsyncWrite, AsyncReadExt, AsyncWriteExt};
|
use tokio::io::{split, AsyncReadExt, AsyncWriteExt};
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
use tokio_native_tls::native_tls::TlsConnector as NTlsConnector;
|
use tokio_native_tls::native_tls::TlsConnector as NTlsConnector;
|
||||||
use tokio_native_tls::TlsConnector;
|
use tokio_native_tls::TlsConnector;
|
||||||
@ -7,7 +7,6 @@ use serde::Deserialize;
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use colored::*;
|
use colored::*;
|
||||||
use tokio_socks::tcp::Socks5Stream;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Config {
|
struct Config {
|
||||||
@ -19,14 +18,6 @@ struct Config {
|
|||||||
sasl_username: Option<String>,
|
sasl_username: Option<String>,
|
||||||
sasl_password: Option<String>,
|
sasl_password: Option<String>,
|
||||||
capabilities: Option<Vec<String>>,
|
capabilities: Option<Vec<String>>,
|
||||||
|
|
||||||
// Proxy
|
|
||||||
use_proxy: bool,
|
|
||||||
proxy_type: Option<String>,
|
|
||||||
proxy_addr: Option<String>,
|
|
||||||
proxy_port: Option<u16>,
|
|
||||||
proxy_username: Option<String>,
|
|
||||||
proxy_password: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod mods {
|
mod mods {
|
||||||
@ -44,34 +35,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let config = loaded_config().expect("Error parsing config.toml");
|
let config = loaded_config().expect("Error parsing config.toml");
|
||||||
println!("Config loaded!");
|
println!("Config loaded!");
|
||||||
|
|
||||||
let server = format!("{}:{}", config.server, config.port);
|
|
||||||
|
|
||||||
if config.use_ssl {
|
if config.use_ssl {
|
||||||
if config.use_proxy {
|
let tcp_stream = TcpStream::connect(format!("{}:{}", config.server, config.port)).await;
|
||||||
let tcp_stream = proxy_exec(&config).await;
|
println!("Connected to {}!", format!("{}:{}", config.server, config.port).green());
|
||||||
match tcp_stream {
|
|
||||||
Ok(tcp_stream) => {
|
println!("Establishing TLS connection...");
|
||||||
let tls_stream = tls_exec(&config, tcp_stream).await;
|
let mut tls_stream = tls_exec (&config, tcp_stream.unwrap()).await.unwrap();
|
||||||
match tls_stream {
|
println!("TLS connection established!");
|
||||||
Ok(tls_stream) => {
|
tls_stream.flush().await.unwrap();
|
||||||
if let Err(e) = handler(tls_stream, config).await {
|
|
||||||
println!("Error handling TLS connection: {}", e);
|
handler(tls_stream, config).await.unwrap();
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
println!("Error establishing TLS connection: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
println!("Error connecting to proxy: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let tcp_stream = TcpStream::connect(server).await.expect("Error connecting to server");
|
|
||||||
let tls_stream = tls_exec(&config, tcp_stream).await.expect("Error establishing TLS connection");
|
|
||||||
handler(tls_stream, config).await.unwrap();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
println!("Non-SSL connection not implemented.");
|
println!("Non-SSL connection not implemented.");
|
||||||
}
|
}
|
||||||
@ -87,37 +60,12 @@ fn loaded_config() -> Result<Config, Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Establish a TLS connection to the server
|
/// Establish a TLS connection to the server
|
||||||
async fn tls_exec(config: &Config, tcp_stream: TcpStream) -> Result<tokio_native_tls::TlsStream<TcpStream>, Box<dyn std::error::Error + Send>> {
|
async fn tls_exec(config: &Config, tcp_stream: TcpStream) -> Result<tokio_native_tls::TlsStream<TcpStream>, Box<dyn std::error::Error>> {
|
||||||
let tls_builder = NTlsConnector::builder().danger_accept_invalid_certs(true).build().unwrap();
|
let tls_builder = NTlsConnector::builder().danger_accept_invalid_certs(true).build()?;
|
||||||
let tls_connector = TlsConnector::from(tls_builder);
|
let tls_connector = TlsConnector::from(tls_builder);
|
||||||
Ok(tls_connector.connect(&config.server, tcp_stream).await.unwrap())
|
Ok(tls_connector.connect(&config.server, tcp_stream).await?)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Establish a connection to the proxy
|
|
||||||
async fn proxy_exec(config: &Config) -> Result<TcpStream, Box<dyn std::error::Error + Send>> {
|
|
||||||
let proxy_addr = match config.proxy_addr.as_ref() {
|
|
||||||
Some(addr) => addr,
|
|
||||||
None => "127.0.0.1",
|
|
||||||
};
|
|
||||||
let proxy_port = config.proxy_port.unwrap_or(9050);
|
|
||||||
let proxy = format!("{}:{}", proxy_addr, proxy_port);
|
|
||||||
let server = format!("{}:{}", config.server, config.port);
|
|
||||||
let proxy_stream = TcpStream::connect(proxy).await.unwrap();
|
|
||||||
let username = config.proxy_username.clone().unwrap();
|
|
||||||
let password = config.proxy_password.clone().unwrap();
|
|
||||||
let tcp_stream = if !&username.is_empty() && !password.is_empty() {
|
|
||||||
let tcp_stream = Socks5Stream::connect_with_password_and_socket(proxy_stream, server, &username, &password).await.unwrap();
|
|
||||||
tcp_stream
|
|
||||||
|
|
||||||
} else {
|
|
||||||
let tcp_stream = Socks5Stream::connect_with_socket(proxy_stream, server).await.unwrap();
|
|
||||||
tcp_stream
|
|
||||||
};
|
|
||||||
let tcp_stream = tcp_stream.into_inner();
|
|
||||||
|
|
||||||
Ok(tcp_stream)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handle the connection to the server
|
/// Handle the connection to the server
|
||||||
async fn handler(tls_stream: tokio_native_tls::TlsStream<TcpStream>, config: Config) -> Result<(), Box<dyn std::error::Error>> {
|
async fn handler(tls_stream: tokio_native_tls::TlsStream<TcpStream>, config: Config) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
Loading…
Reference in New Issue
Block a user