mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Moved Devices to a models module
This commit is contained in:
Generated
+1
@@ -276,6 +276,7 @@ dependencies = [
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"wasm-bindgen",
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ serde_json = "1.0"
|
||||
rusqlite = { version = "0.38.0", features = ["bundled", "chrono"] }
|
||||
rusqlite_migration = { version = "2.4.0", features = ["from-directory"] }
|
||||
include_dir = "0.7.4"
|
||||
chrono = "0.4.43"
|
||||
chrono = {version = "0.4.43", features = ["serde"]}
|
||||
pushover = "0.4.0"
|
||||
config = "0.15.19"
|
||||
lazy_static = "1.5.0"
|
||||
|
||||
@@ -2,7 +2,7 @@ use log::{debug, error};
|
||||
use rusqlite::{Connection, params};
|
||||
use std::sync::MutexGuard;
|
||||
|
||||
use crate::device_finders::Device;
|
||||
use crate::model::devices::Device;
|
||||
|
||||
// Read device from its MAC address
|
||||
pub fn read(conn: MutexGuard<Connection>, mac_address: String) -> Option<Device> {
|
||||
|
||||
@@ -1,22 +1 @@
|
||||
pub mod arp;
|
||||
|
||||
use chrono::NaiveDateTime;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Device {
|
||||
pub mac_address: String,
|
||||
pub ipv4_address: String,
|
||||
pub vendor: String,
|
||||
pub last_seen: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl fmt::Display for Device {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"mac={}, ip={}, vendor={}, last_seen={}",
|
||||
self.mac_address, self.ipv4_address, self.vendor, self.last_seen
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
mod packet_send_receive;
|
||||
|
||||
use crate::{device_finders::Device, settings::CONFIG};
|
||||
use crate::model::devices::Device;
|
||||
use crate::settings::CONFIG;
|
||||
use duration_string::DurationString;
|
||||
use log::{debug, error, info, warn};
|
||||
use packet_send_receive::{listen_for_packets, send_packet};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::device_finders::Device;
|
||||
use crate::mac_vendor_finder;
|
||||
use crate::model::devices::Device;
|
||||
use chrono::Local;
|
||||
use duration_string::DurationString;
|
||||
use log::{debug, info, trace};
|
||||
@@ -110,7 +110,7 @@ pub async fn listen_for_packets(
|
||||
mac_address: packet_mac_address,
|
||||
ipv4_address: packet_ip_address,
|
||||
vendor: packet_vendor,
|
||||
last_seen: Local::now().naive_local(),
|
||||
last_seen: Local::now().to_utc(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ mod pushover;
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::{device_finders::Device, settings::CONFIG};
|
||||
use crate::model::devices::Device;
|
||||
use crate::settings::CONFIG;
|
||||
use chrono::Local;
|
||||
use duration_string::DurationString;
|
||||
use log::{debug, info, warn};
|
||||
@@ -31,8 +32,7 @@ pub fn trigger_new_device(device: Device) -> Result<(), String> {
|
||||
|
||||
pub fn trigger_existing_device(existing_device: Device, new_device: Device) -> Result<(), String> {
|
||||
// Notify if the device comes back online after not being seen for the configured period
|
||||
let elapsed_since_last_seen: Duration = (Local::now().naive_local()
|
||||
- existing_device.last_seen)
|
||||
let elapsed_since_last_seen: Duration = (Local::now().to_utc() - existing_device.last_seen)
|
||||
.to_std()
|
||||
.unwrap_or(Duration::from_secs(0));
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ mod db;
|
||||
mod device_finders;
|
||||
mod events;
|
||||
mod mac_vendor_finder;
|
||||
mod model;
|
||||
mod settings;
|
||||
|
||||
#[tokio::main]
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
pub mod devices;
|
||||
@@ -0,0 +1,22 @@
|
||||
use chrono::{DateTime, Utc, serde::ts_seconds};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct Device {
|
||||
pub mac_address: String,
|
||||
pub ipv4_address: String,
|
||||
pub vendor: String,
|
||||
#[serde(with = "ts_seconds")]
|
||||
pub last_seen: DateTime<Utc>,
|
||||
}
|
||||
|
||||
impl fmt::Display for Device {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"mac={}, ip={}, vendor={}, last_seen={}",
|
||||
self.mac_address, self.ipv4_address, self.vendor, self.last_seen
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user