From bee492b703ba566445f24fa3ea11c72b24f8c953 Mon Sep 17 00:00:00 2001 From: rzuasti Date: Tue, 2 Jun 2026 18:33:35 -0400 Subject: [PATCH] Default web_server.ip_address and port Fall back to "0.0.0.0" and 3000 when these fields are omitted from the [web_server] section (api_key remains required). Update the sample TOML and README to reflect the new defaults; the Nix module already used them. Co-Authored-By: Claude Opus 4.8 --- README.md | 4 ++-- backend/src/settings.rs | 33 +++++++++++++++++++++++++++++++++ examples/sample_oott.toml | 4 ++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 70c9661..0022094 100644 --- a/README.md +++ b/README.md @@ -160,8 +160,8 @@ Options marked **Required** have no built-in default and must be set in your con |`database.path`|**Required**|Location of the system database. Must be `/db/oott.db` when using the Docker image.| |`networking.interface`|auto-detected|Network interface to use for scans. Optional — if not set, the first non-loopback connected interface is used automatically.| |`log.level`|`warn`|Log level to use (off, error, warn, info, debug, trace)| -|`web_server.ip_address`|**Required**|Address the API and web UI bind to. Use `0.0.0.0` to bind all interfaces.| -|`web_server.port`|**Required**|Port the API and web UI listen on.| +|`web_server.ip_address`|`0.0.0.0`|Address the API and web UI bind to. Use `0.0.0.0` to bind all interfaces.| +|`web_server.port`|`3000`|Port the API and web UI listen on.| |`web_server.api_key`|**Required**|API key the app must present to use the backend.| |`arp_scanner.enabled`|`true`|Whether to run the ARP scanner. The whole `[arp_scanner]` section is optional; omit it to use the defaults below. Set to `false` to turn it off.| |`arp_scanner.wait_between_scans`|`30m`|Time to wait between each network scan (you can express it in seconds, minutes, hours, etc. as a suffix - for example: 30s, 10m, 1h)| diff --git a/backend/src/settings.rs b/backend/src/settings.rs index 2b221bc..55d889d 100644 --- a/backend/src/settings.rs +++ b/backend/src/settings.rs @@ -14,6 +14,14 @@ fn default_log_level() -> String { "warn".to_string() } +fn default_ip_address() -> String { + "0.0.0.0".to_string() +} + +fn default_port() -> u16 { + 3000 +} + #[derive(Debug, Deserialize, Clone)] pub struct Database { pub path: String, @@ -143,7 +151,9 @@ pub struct Notifications { #[derive(Debug, Deserialize, Clone)] pub struct WebServer { + #[serde(default = "default_ip_address")] pub ip_address: String, + #[serde(default = "default_port")] pub port: u16, pub api_key: String, } @@ -365,6 +375,29 @@ mod tests { assert_eq!(settings.log.level, "warn"); } + #[test] + fn web_server_address_and_port_default_when_fields_omitted() { + // Keep the `[web_server]` section (api_key is required) but drop ip_address and port. + const NO_ADDR_CONFIG: &str = r#" + [database] + path = "./oott.db" + [networking] + [log] + level = "info" + [notifications] + method = "none" + notify_when_not_seen_for = "1w" + [notifications.pushover] + token = "" + user_key = "" + [web_server] + api_key = "test" + "#; + let settings = parse(NO_ADDR_CONFIG); + assert_eq!(settings.web_server.ip_address, "0.0.0.0"); + assert_eq!(settings.web_server.port, 3000); + } + #[test] fn device_events_dedup_window_defaults_when_section_omitted() { let settings = parse(BASE_CONFIG); diff --git a/examples/sample_oott.toml b/examples/sample_oott.toml index ed9bf89..cb7da33 100644 --- a/examples/sample_oott.toml +++ b/examples/sample_oott.toml @@ -43,8 +43,8 @@ token="" # Your pushover token goes here, just copy&paste from their website aft user_key="" # User key goes here, this is the account wide code for pushover [web_server] -ip_address="0.0.0.0" # IP to bind the web server for the API and web UI to, use 0.0.0.0 to bind it to all interfaces -port=3000 # Port to listen on +ip_address="0.0.0.0" # IP to bind the web server for the API and web UI to, use 0.0.0.0 to bind it to all interfaces. Defaults to "0.0.0.0" if omitted +port=3000 # Port to listen on. Defaults to 3000 if omitted api_key="CHANGE_ME" # API Key to use the system's API, change this! [retention]