* feat: numa setup-phone — QR-based mobile DoT onboarding Adds a CLI subcommand that generates a one-time mobileconfig profile containing both the Numa local CA (as a com.apple.security.root payload) and the DoT DNS settings, then serves it via a temporary HTTP server and prints a scannable QR code in the terminal. Flow: 1. User runs `numa setup-phone` (no sudo needed) 2. Detects current LAN IP, reads CA from /usr/local/var/numa/ca.pem 3. Builds combined mobileconfig (CA trust + DoT) 4. Renders QR code with qrcode crate (Unicode block characters) 5. Serves the profile on port 8765, stays open until Ctrl+C 6. Counts successful downloads (multi-device households) Important caveat documented in instructions: even with the CA bundled in the profile, iOS still requires the user to manually enable trust in Settings → General → About → Certificate Trust Settings. Verified on a real iPhone. Stable PayloadIdentifiers/UUIDs ensure re-running replaces the existing profile on iOS rather than accumulating duplicates. - New module: src/setup_phone.rs (~270 lines) - New CLI subcommand: `numa setup-phone` - New dependency: qrcode = "0.14" (default-features = false) - tokio "signal" feature added for Ctrl+C handling - 3 unit tests: PEM stripping, mobileconfig generation, QR rendering Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: mobile API, enriched /health, mobileconfig module Adds a persistent read-only HTTP listener (default port 8765, LAN-bound) serving a dedicated subset of Numa's API for iOS/Android companion apps and as a replacement for the one-shot server setup_phone used to spin up: GET /health — enriched JSON with version, hostname, LAN IP, SNI, DoT config, mobile API port, CA fingerprint, features (shared handler with the main API on port 5380) GET /ca.pem — public CA certificate (shared handler) GET /mobileconfig — full iOS profile (CA trust + DNS settings pinned to current LAN IP) GET /ca.mobileconfig — CA-only iOS profile (trust anchor without DNS override — for the iOS companion app's programmatic DNS flow via NEDNSSettingsManager) All routes are idempotent GETs. The mobile API never serves the state-mutating routes that live on the main API (overrides, blocking toggle, service CRUD, cache flush), so it is safe to expose on the LAN regardless of the main API's bind address. The CA private key is never served by any route. Opt-in via `[mobile] enabled = true`. Default is false so new installs do not silently expose a LAN listener after upgrading; our committed numa.toml template enables it explicitly for spike testing. New modules: - src/mobileconfig.rs — ProfileMode::{Full, CaOnly} enum with plist builder lifted from setup_phone.rs. Full and CaOnly share the CA payload UUID (same trust anchor) but have distinct top-level UUIDs so they coexist as separate installable profiles on iOS. - src/health.rs — HealthMeta cached metadata built once at startup from config + CA fingerprint (SHA-256 of the PEM via ring), and the HealthResponse JSON shape shared between the main and mobile APIs. - src/mobile_api.rs — axum Router for the persistent listener. Reuses api::health and api::serve_ca from the main API; owns the two mobileconfig handlers. Modified: - src/api.rs — health() returns the enriched HealthResponse, now pub. serve_ca is now pub so mobile_api can reuse it. - src/config.rs — MobileConfig section (enabled, port, bind_addr). - src/ctx.rs — health_meta: HealthMeta field on ServerCtx. - src/main.rs — builds HealthMeta at startup, spawns mobile API listener if enabled. - src/lan.rs — build_announcement takes &HealthMeta and writes enriched TXT records (version, api_port, proto, dot_port, ca_fp). SRV port now reports the mobile API port; peer discovery still reads TXT `services=` so this is backwards compatible. Always announces even when no .numa services are registered, so the iOS companion app can discover Numa via mDNS regardless of service state. - src/setup_phone.rs — reduced from 267 to 100 lines. The CLI is now a thin QR wrapper over the persistent /mobileconfig endpoint; the hand-rolled one-shot HTTP server (accept_loop, RUST_OK_HEADERS, RUST_NOT_FOUND, download counter) is gone. - src/dot.rs — test fixture updated with HealthMeta::test_fixture(). - numa.toml — commented [mobile] section, enabled = true for spike. Tests: 136 unit tests passing (5 new in mobileconfig, 3 new in health). cargo clippy clean. Integration sanity check: curl'd /health, /ca.pem, /mobileconfig, /ca.mobileconfig against a running numa — all return 200 with correct content types and valid response bodies. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: setup-phone probe, unknown command error, query source in dashboard - setup-phone now probes the mobile API before printing the QR code and shows an actionable error if [mobile] is not enabled - Unknown CLI subcommands print an error instead of silently attempting to start a full server - Dashboard query log shows source IP under timestamp (localhost for loopback, full IP for LAN devices) with full addr on hover Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
166 lines
4.9 KiB
Rust
166 lines
4.9 KiB
Rust
pub mod api;
|
|
pub mod blocklist;
|
|
pub mod buffer;
|
|
pub mod cache;
|
|
pub mod config;
|
|
pub mod ctx;
|
|
pub mod dnssec;
|
|
pub mod dot;
|
|
pub mod forward;
|
|
pub mod header;
|
|
pub mod health;
|
|
pub mod lan;
|
|
pub mod mobile_api;
|
|
pub mod mobileconfig;
|
|
pub mod override_store;
|
|
pub mod packet;
|
|
pub mod proxy;
|
|
pub mod query_log;
|
|
pub mod question;
|
|
pub mod record;
|
|
pub mod recursive;
|
|
pub mod service_store;
|
|
pub mod setup_phone;
|
|
pub mod srtt;
|
|
pub mod stats;
|
|
pub mod system_dns;
|
|
pub mod tls;
|
|
|
|
pub type Error = Box<dyn std::error::Error + Send + Sync>;
|
|
pub type Result<T> = std::result::Result<T, Error>;
|
|
|
|
/// Detect the machine hostname via the `hostname` command. Returns the
|
|
/// full hostname (e.g., `macbook-pro.local`), or `"numa"` if the command
|
|
/// fails. Call sites that need the short form (e.g., mDNS instance
|
|
/// names) should truncate at the first `.`.
|
|
pub fn hostname() -> String {
|
|
std::process::Command::new("hostname")
|
|
.output()
|
|
.ok()
|
|
.and_then(|o| String::from_utf8(o.stdout).ok())
|
|
.map(|h| h.trim().to_string())
|
|
.filter(|h| !h.is_empty())
|
|
.unwrap_or_else(|| "numa".to_string())
|
|
}
|
|
|
|
/// Shared config directory for persistent data (services.json, etc).
|
|
/// Unix users: ~/.config/numa/
|
|
/// Linux root daemon: /var/lib/numa (FHS) — falls back to /usr/local/var/numa
|
|
/// if a pre-v0.10.1 install already lives there.
|
|
/// macOS root daemon: /usr/local/var/numa (Homebrew prefix)
|
|
/// Windows: %APPDATA%\numa
|
|
pub fn config_dir() -> std::path::PathBuf {
|
|
#[cfg(windows)]
|
|
{
|
|
std::path::PathBuf::from(
|
|
std::env::var("APPDATA").unwrap_or_else(|_| "C:\\ProgramData".into()),
|
|
)
|
|
.join("numa")
|
|
}
|
|
#[cfg(not(windows))]
|
|
{
|
|
config_dir_unix()
|
|
}
|
|
}
|
|
|
|
#[cfg(not(windows))]
|
|
fn config_dir_unix() -> std::path::PathBuf {
|
|
// When run via sudo, SUDO_USER has the real user
|
|
if let Ok(user) = std::env::var("SUDO_USER") {
|
|
let home = if cfg!(target_os = "macos") {
|
|
format!("/Users/{}", user)
|
|
} else {
|
|
format!("/home/{}", user)
|
|
};
|
|
return std::path::PathBuf::from(home).join(".config").join("numa");
|
|
}
|
|
|
|
// Normal user (not root)
|
|
if let Ok(home) = std::env::var("HOME") {
|
|
let path = std::path::PathBuf::from(&home);
|
|
if !home.starts_with("/var/root") && !home.starts_with("/root") {
|
|
return path.join(".config").join("numa");
|
|
}
|
|
}
|
|
|
|
// Running as root daemon (launchd/systemd) — use system-wide path
|
|
daemon_data_dir()
|
|
}
|
|
|
|
/// Default system-wide data directory for TLS certs. Overridable via
|
|
/// `[server] data_dir = "..."` in numa.toml — this function only provides
|
|
/// the fallback when the config doesn't set it.
|
|
/// Linux: /var/lib/numa (FHS) — falls back to /usr/local/var/numa if a
|
|
/// pre-v0.10.1 install already has data there.
|
|
/// macOS: /usr/local/var/numa (Homebrew prefix)
|
|
/// Windows: %PROGRAMDATA%\numa
|
|
pub fn data_dir() -> std::path::PathBuf {
|
|
#[cfg(windows)]
|
|
{
|
|
std::path::PathBuf::from(
|
|
std::env::var("PROGRAMDATA").unwrap_or_else(|_| "C:\\ProgramData".into()),
|
|
)
|
|
.join("numa")
|
|
}
|
|
#[cfg(not(windows))]
|
|
{
|
|
daemon_data_dir()
|
|
}
|
|
}
|
|
|
|
/// Resolve the system-wide data directory for the running platform.
|
|
/// Honors backwards compatibility with pre-v0.10.1 installs that still
|
|
/// have their CA cert + services.json under `/usr/local/var/numa`.
|
|
#[cfg(not(windows))]
|
|
fn daemon_data_dir() -> std::path::PathBuf {
|
|
#[cfg(target_os = "linux")]
|
|
{
|
|
std::path::PathBuf::from(resolve_linux_data_dir(
|
|
std::path::Path::new("/usr/local/var/numa").exists(),
|
|
std::path::Path::new("/var/lib/numa").exists(),
|
|
))
|
|
}
|
|
#[cfg(target_os = "macos")]
|
|
{
|
|
// macOS uses the Homebrew prefix convention; no FHS migration needed.
|
|
std::path::PathBuf::from("/usr/local/var/numa")
|
|
}
|
|
}
|
|
|
|
/// Extracted as a pure function so the migration logic is unit-testable
|
|
/// without touching the real filesystem.
|
|
#[cfg(any(target_os = "linux", test))]
|
|
fn resolve_linux_data_dir(legacy_exists: bool, fhs_exists: bool) -> &'static str {
|
|
if legacy_exists && !fhs_exists {
|
|
"/usr/local/var/numa"
|
|
} else {
|
|
"/var/lib/numa"
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn linux_data_dir_fresh_install_uses_fhs() {
|
|
assert_eq!(resolve_linux_data_dir(false, false), "/var/lib/numa");
|
|
}
|
|
|
|
#[test]
|
|
fn linux_data_dir_upgrading_install_keeps_legacy() {
|
|
// Migration must keep legacy so the user doesn't lose their CA on upgrade.
|
|
assert_eq!(resolve_linux_data_dir(true, false), "/usr/local/var/numa");
|
|
}
|
|
|
|
#[test]
|
|
fn linux_data_dir_after_migration_uses_fhs() {
|
|
assert_eq!(resolve_linux_data_dir(true, true), "/var/lib/numa");
|
|
}
|
|
|
|
#[test]
|
|
fn linux_data_dir_only_fhs_uses_fhs() {
|
|
assert_eq!(resolve_linux_data_dir(false, true), "/var/lib/numa");
|
|
}
|
|
}
|