2026-01-27 09:21:00 -05:00
|
|
|
use clap::Parser;
|
2026-01-21 15:36:27 -05:00
|
|
|
use config::{Config, ConfigError, File};
|
2026-01-23 14:35:28 -05:00
|
|
|
use duration_string::DurationString;
|
2026-01-21 15:36:27 -05:00
|
|
|
use lazy_static::lazy_static;
|
2026-01-27 09:21:00 -05:00
|
|
|
use log::{error, info};
|
2026-01-21 15:36:27 -05:00
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
// Configuration structure
|
2026-01-23 11:00:24 -05:00
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
|
pub struct Networking {
|
|
|
|
|
pub interface: String,
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-21 15:36:27 -05:00
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
|
pub struct Log {
|
|
|
|
|
pub level: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
|
pub struct Timings {
|
2026-01-23 14:35:28 -05:00
|
|
|
pub wait_between_scans: DurationString,
|
|
|
|
|
pub arp_sender_timeout: DurationString,
|
|
|
|
|
pub arp_scan_duration: DurationString,
|
2026-01-21 15:36:27 -05:00
|
|
|
}
|
|
|
|
|
|
2026-01-23 10:25:45 -05:00
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
|
pub struct Pushover {
|
|
|
|
|
pub token: String,
|
|
|
|
|
pub user_key: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
|
pub struct Notifications {
|
|
|
|
|
pub method: String,
|
|
|
|
|
pub pushover: Pushover,
|
2026-01-23 15:08:58 -05:00
|
|
|
pub notify_when_not_seen_for: DurationString,
|
2026-01-23 10:25:45 -05:00
|
|
|
}
|
|
|
|
|
|
2026-01-21 15:36:27 -05:00
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
|
pub struct Settings {
|
2026-01-23 11:00:24 -05:00
|
|
|
pub networking: Networking,
|
2026-01-21 15:36:27 -05:00
|
|
|
pub log: Log,
|
|
|
|
|
pub timings: Timings,
|
2026-01-23 10:25:45 -05:00
|
|
|
pub notifications: Notifications,
|
2026-01-21 15:36:27 -05:00
|
|
|
}
|
|
|
|
|
// End configuration structure
|
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
|
2026-01-27 09:21:00 -05:00
|
|
|
// Command line parameters relevant to configuration
|
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
|
#[command(version, about, long_about = None)]
|
|
|
|
|
struct Args {
|
|
|
|
|
/// Config file path
|
|
|
|
|
#[arg(short, long)]
|
|
|
|
|
config: Option<String>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DEFAULT_CONFIG_FILE_PATH: &str = "./oott.toml";
|
2026-01-21 15:36:27 -05:00
|
|
|
|
|
|
|
|
impl Settings {
|
|
|
|
|
pub fn new() -> Result<Self, ConfigError> {
|
2026-01-27 09:21:00 -05:00
|
|
|
let args = Args::parse();
|
|
|
|
|
|
|
|
|
|
let config_path = args.config.unwrap_or(DEFAULT_CONFIG_FILE_PATH.to_string());
|
|
|
|
|
|
|
|
|
|
info!("Reading configuration from {}", config_path);
|
|
|
|
|
|
2026-01-21 15:36:27 -05:00
|
|
|
let local_settings = Config::builder()
|
2026-01-27 09:21:00 -05:00
|
|
|
.add_source(File::with_name(config_path.as_str()))
|
2026-01-21 15:36:27 -05:00
|
|
|
.build()?;
|
|
|
|
|
|
|
|
|
|
local_settings.try_deserialize()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
|
pub static ref CONFIG: Settings = match Settings::new() {
|
|
|
|
|
Ok(value) => value,
|
|
|
|
|
Err(error) => {
|
2026-01-27 09:21:00 -05:00
|
|
|
error!("Error reading configuration file: {error}");
|
|
|
|
|
panic!("Error reading configuration file: {error}");
|
2026-01-21 15:36:27 -05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|