Compare commits
2 Commits
322f473671
...
d74d8184c3
Author | SHA1 | Date | |
---|---|---|---|
d74d8184c3 | |||
e20cb7e996 |
12
config.toml
12
config.toml
@ -2,7 +2,13 @@ server = "irc.supernets.org"
|
|||||||
port = 6697
|
port = 6697
|
||||||
use_ssl = true
|
use_ssl = true
|
||||||
nickname = "g1r"
|
nickname = "g1r"
|
||||||
channel = "#dev"
|
channel = "#superbowl"
|
||||||
sasl_username = "g1r"
|
sasl_username = ""
|
||||||
sasl_password = "fuckyou.lol"
|
sasl_password = ""
|
||||||
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, AsyncReadExt, AsyncWriteExt};
|
use tokio::io::{split, AsyncRead, AsyncWrite, 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,6 +7,7 @@ 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 {
|
||||||
@ -18,6 +19,14 @@ 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 {
|
||||||
@ -35,16 +44,34 @@ 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 {
|
||||||
let tcp_stream = TcpStream::connect(format!("{}:{}", config.server, config.port)).await;
|
if config.use_proxy {
|
||||||
println!("Connected to {}!", format!("{}:{}", config.server, config.port).green());
|
let tcp_stream = proxy_exec(&config).await;
|
||||||
|
match tcp_stream {
|
||||||
println!("Establishing TLS connection...");
|
Ok(tcp_stream) => {
|
||||||
let mut tls_stream = tls_exec (&config, tcp_stream.unwrap()).await.unwrap();
|
let tls_stream = tls_exec(&config, tcp_stream).await;
|
||||||
println!("TLS connection established!");
|
match tls_stream {
|
||||||
tls_stream.flush().await.unwrap();
|
Ok(tls_stream) => {
|
||||||
|
if let Err(e) = handler(tls_stream, config).await {
|
||||||
handler(tls_stream, config).await.unwrap();
|
println!("Error handling TLS connection: {}", e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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.");
|
||||||
}
|
}
|
||||||
@ -60,12 +87,37 @@ 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>> {
|
async fn tls_exec(config: &Config, tcp_stream: TcpStream) -> Result<tokio_native_tls::TlsStream<TcpStream>, Box<dyn std::error::Error + Send>> {
|
||||||
let tls_builder = NTlsConnector::builder().danger_accept_invalid_certs(true).build()?;
|
let tls_builder = NTlsConnector::builder().danger_accept_invalid_certs(true).build().unwrap();
|
||||||
let tls_connector = TlsConnector::from(tls_builder);
|
let tls_connector = TlsConnector::from(tls_builder);
|
||||||
Ok(tls_connector.connect(&config.server, tcp_stream).await?)
|
Ok(tls_connector.connect(&config.server, tcp_stream).await.unwrap())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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