generated from PlexSheep/rs-base
69 lines
1.8 KiB
Rust
69 lines
1.8 KiB
Rust
use std::fmt::{Debug, Display};
|
|
use std::net::SocketAddr;
|
|
use std::str::FromStr;
|
|
|
|
use clap::Parser;
|
|
use libpt::cli::args::VerbosityLevel;
|
|
use serde::Serialize;
|
|
|
|
pub const ENV_SECRET: &str = "WOOLY_SECRET";
|
|
|
|
/// Wooly Vault --- A few small hacking challenges
|
|
///
|
|
/// # Configuration
|
|
/// Each challenge requires some basic information to host:
|
|
///
|
|
/// * secret - a string that if found signifies that the challenge was solved
|
|
///
|
|
/// * addr - the network adress plus port the challenge should run on
|
|
///
|
|
/// * verbosity - how verbose the logging should be
|
|
///
|
|
/// * challenge - which challenge to host (there are a few)
|
|
///
|
|
/// The secret cannot be inputted with a command line argument, because the arguments can often be
|
|
/// seen in the process view. You may either specify a secret in the 'WOOLY_SECRET' environment
|
|
/// variable or input it interactively on start.
|
|
///
|
|
/// # Challenges
|
|
///
|
|
/// There are a number of challenges:
|
|
///
|
|
/// 1. Connect by TCP
|
|
///
|
|
/// 2. Connect by TCP and send a special u16
|
|
#[derive(Parser, Clone, PartialEq, Eq, Hash, Serialize)]
|
|
#[command(
|
|
author,
|
|
version,
|
|
about,
|
|
long_about,
|
|
help_template = libpt::cli::args::HELP_TEMPLATE)]
|
|
|
|
pub struct Config {
|
|
/// Index of the challenge
|
|
pub challenge: u16,
|
|
/// Network address to host the challenge on
|
|
pub addr: SocketAddr,
|
|
#[command(flatten)]
|
|
pub verbosity: VerbosityLevel,
|
|
}
|
|
|
|
impl Default for Config {
|
|
fn default() -> Self {
|
|
Self {
|
|
challenge: 1,
|
|
addr: SocketAddr::from_str("127.0.0.1:1337").unwrap(),
|
|
verbosity: VerbosityLevel::default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Debug for Config {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
f.debug_struct("Config")
|
|
.field("addr", &self.addr)
|
|
.field("verbosity", &self.verbosity.level())
|
|
.finish()
|
|
}
|
|
}
|