diff --git a/.gitignore b/.gitignore index ed2031a..72a2526 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target oott.db +oott.toml diff --git a/sample_oott.toml b/sample_oott.toml new file mode 100644 index 0000000..e73bd01 --- /dev/null +++ b/sample_oott.toml @@ -0,0 +1,6 @@ +[log] +level = "info" # off, error, warn, info, debug, trace + +[timings] +arp_sender_timeout="30" +arp_scan_duration="60" diff --git a/src/db/devices.rs b/src/db/devices.rs index 30e7638..8a3244a 100644 --- a/src/db/devices.rs +++ b/src/db/devices.rs @@ -6,7 +6,6 @@ use crate::device_finders::Device; // Read device from its MAC address pub fn read(conn: MutexGuard, mac_address: String) -> Option { - // TODO: Add last_seen let result: Result = conn.query_one( "SELECT mac_address, ipv4_address, vendor, last_seen FROM devices WHERE mac_address=?1", params![mac_address], diff --git a/src/mac_vendor_finder.rs b/src/mac_vendor_finder.rs index 2374f6b..6f23a00 100644 --- a/src/mac_vendor_finder.rs +++ b/src/mac_vendor_finder.rs @@ -1,8 +1,8 @@ +use lazy_static::lazy_static; use log::{debug, error, info}; use serde::Deserialize; use std::collections::HashMap; use std::fs; -use std::sync::LazyLock; #[derive(Deserialize)] #[serde(rename_all = "camelCase")] @@ -14,37 +14,46 @@ struct MacRecord { // last_update: String, } -// TODO : Change to lazy_load macro (like CONFIG) // Initialize mac vendors database as a static lazy loaded unit -static MAC_VENDORS_DATABASE: LazyLock> = LazyLock::new(|| { - info!("Loading MAC vendor database into memory"); +lazy_static! { + static ref MAC_VENDORS_DATABASE: HashMap = { + info!("Loading MAC vendor database into memory"); - let mut database = HashMap::new(); - let data = match fs::read_to_string("data/mac-vendors-export.json") { - Ok(value) => value, - Err(error) => { - error!("Error reading mac vendors database (data/mac-vendors-export.json): {error}"); - panic!("Error reading mac vendors database (data/mac-vendors-export.json): {error}"); + let mut database = HashMap::new(); + let data = match fs::read_to_string("data/mac-vendors-export.json") { + Ok(value) => value, + Err(error) => { + error!( + "Error reading mac vendors database (data/mac-vendors-export.json): {error}" + ); + panic!( + "Error reading mac vendors database (data/mac-vendors-export.json): {error}" + ); + } + }; + + let json: Vec = match serde_json::from_str(&data) { + Ok(value) => value, + Err(error) => { + error!( + "Error parsing mac vendors database (data/mac-vendors-export.json): {error}" + ); + panic!( + "Error parsing mac vendors database (data/mac-vendors-export.json): {error}" + ); + } + }; + + debug!("Found {} records in the database", json.len()); + + for el in json { + database.insert(el.mac_prefix.to_uppercase(), el.vendor_name); } + + info!("MAC vendor database loaded"); + database }; - - let json: Vec = match serde_json::from_str(&data) { - Ok(value) => value, - Err(error) => { - error!("Error parsing mac vendors database (data/mac-vendors-export.json): {error}"); - panic!("Error parsing mac vendors database (data/mac-vendors-export.json): {error}"); - } - }; - - debug!("Found {} records in the database", json.len()); - - for el in json { - database.insert(el.mac_prefix.to_uppercase(), el.vendor_name); - } - - info!("MAC vendor database loaded"); - database -}); +} // Find a vendor based on the MAC prefix pub fn find(mac_prefix: String) -> String {