diff --git a/tcp_relay_server/src/args.rs b/tcp_relay_server/src/args.rs index 7b24fce..422f453 100644 --- a/tcp_relay_server/src/args.rs +++ b/tcp_relay_server/src/args.rs @@ -8,6 +8,10 @@ pub struct Args { #[clap(short, long)] pub tokens: Vec, + /// Access tokens stored in a file, one token per line + #[clap(long)] + pub tokens_file: Option, + /// Forwarded ports #[clap(short, long)] pub ports: Vec, diff --git a/tcp_relay_server/src/main.rs b/tcp_relay_server/src/main.rs index f615f0b..bb008c2 100644 --- a/tcp_relay_server/src/main.rs +++ b/tcp_relay_server/src/main.rs @@ -35,14 +35,22 @@ pub async fn config_route(req: HttpRequest, data: Data>) -> impl Respo async fn main() -> std::io::Result<()> { env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); - let args: Args = Args::parse(); - let args = Arc::new(args); + let mut args: Args = Args::parse(); if args.ports.is_empty() { log::error!("No port to forward!"); std::process::exit(2); } + // Read tokens from file, if any + if let Some(file) = &args.tokens_file { + std::fs::read_to_string(file) + .expect("Failed to read tokens file!") + .split('\n') + .filter(|l| !l.is_empty()) + .for_each(|t| args.tokens.push(t.to_string())); + } + if args.tokens.is_empty() { log::error!("No tokens specified!"); std::process::exit(3); @@ -50,6 +58,7 @@ async fn main() -> std::io::Result<()> { log::info!("Starting relay on http://{}", args.listen_address); + let args = Arc::new(args); let args_clone = args.clone(); HttpServer::new(move || { App::new()