mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Created config sample (get real config out of git). Changed
mac_vendor_finder to use lazy_static instead of LazyLock
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
/target
|
||||
oott.db
|
||||
oott.toml
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
[log]
|
||||
level = "info" # off, error, warn, info, debug, trace
|
||||
|
||||
[timings]
|
||||
arp_sender_timeout="30"
|
||||
arp_scan_duration="60"
|
||||
@@ -6,7 +6,6 @@ use crate::device_finders::Device;
|
||||
|
||||
// Read device from its MAC address
|
||||
pub fn read(conn: MutexGuard<Connection>, mac_address: String) -> Option<Device> {
|
||||
// TODO: Add last_seen
|
||||
let result: Result<Device, rusqlite::Error> = conn.query_one(
|
||||
"SELECT mac_address, ipv4_address, vendor, last_seen FROM devices WHERE mac_address=?1",
|
||||
params![mac_address],
|
||||
|
||||
+37
-28
@@ -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<HashMap<String, String>> = LazyLock::new(|| {
|
||||
info!("Loading MAC vendor database into memory");
|
||||
lazy_static! {
|
||||
static ref MAC_VENDORS_DATABASE: HashMap<String, String> = {
|
||||
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<MacRecord> = 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<MacRecord> = 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 {
|
||||
|
||||
Reference in New Issue
Block a user