Can specify tokens in a file
This commit is contained in:
parent
dde219a717
commit
53ad29727e
@ -8,6 +8,10 @@ pub struct Args {
|
||||
#[clap(short, long)]
|
||||
pub tokens: Vec<String>,
|
||||
|
||||
/// Access tokens stored in a file, one token per line
|
||||
#[clap(long)]
|
||||
pub tokens_file: Option<String>,
|
||||
|
||||
/// Forwarded ports
|
||||
#[clap(short, long)]
|
||||
pub ports: Vec<u16>,
|
||||
|
@ -35,14 +35,22 @@ pub async fn config_route(req: HttpRequest, data: Data<Arc<Args>>) -> 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()
|
||||
|
Loading…
Reference in New Issue
Block a user