Add button to set current time

When there is a significant difference between the user's browser's time
and the system time, a button appears in the web UI to fix the system
time. This time will then be used to correct both data inside of PCAPs
and any metadata.

We don't actually set the system time to this value. Instead, rayhunter
adjusts any timestamps it handles by an offset. That offset defaults to
zero, and the user adjusts it by hitting the button in the web UI. The
main reason for this is device portability.

I haven't investigated whether it would actually be easy to set the real
system time. It's possible that it works the same way across all
devices.
This commit is contained in:
Markus Unterwaditzer
2026-01-25 19:45:08 +01:00
committed by Will Greenberg
parent 781d07230c
commit bef6b51e28
10 changed files with 216 additions and 16 deletions

25
lib/src/clock.rs Normal file
View File

@@ -0,0 +1,25 @@
//! Global clock offset for adjusting timestamps.
//!
//! This module provides a global clock offset that can be used to adjust
//! timestamps when the device's system clock is incorrect. The offset is
//! stored in memory and is not persisted across restarts.
use chrono::{DateTime, Local, TimeDelta};
use std::sync::RwLock;
static CLOCK_OFFSET: RwLock<TimeDelta> = RwLock::new(TimeDelta::zero());
/// Get the current clock offset.
pub fn get_offset() -> TimeDelta {
*CLOCK_OFFSET.read().unwrap()
}
/// Set the clock offset.
pub fn set_offset(offset: TimeDelta) {
*CLOCK_OFFSET.write().unwrap() = offset;
}
/// Get the current adjusted time (system time + offset).
pub fn get_adjusted_now() -> DateTime<Local> {
Local::now() + get_offset()
}

View File

@@ -360,7 +360,8 @@ impl Timestamp {
let mut delta_seconds = ts_upper as f64 * 1.25;
delta_seconds += ts_lower as f64 / 40960.0;
let ts_delta = chrono::Duration::milliseconds(delta_seconds as i64);
epoch + ts_delta
// Apply global clock offset to adjust for incorrect device time
epoch + ts_delta + crate::clock::get_offset()
}
}

View File

@@ -12,6 +12,7 @@ pub fn init_logging(default_level: log::LevelFilter) {
}
pub mod analysis;
pub mod clock;
pub mod diag;
pub mod gsmtap;
pub mod gsmtap_parser;