mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-04-28 00:20:00 -07:00
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:
committed by
Will Greenberg
parent
781d07230c
commit
bef6b51e28
@@ -9,7 +9,9 @@ use axum::extract::State;
|
||||
use axum::http::header::{self, CONTENT_LENGTH, CONTENT_TYPE};
|
||||
use axum::http::{HeaderValue, StatusCode};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use chrono::{DateTime, Local};
|
||||
use log::{error, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use tokio::fs::write;
|
||||
use tokio::io::{AsyncReadExt, copy, duplex};
|
||||
@@ -170,6 +172,37 @@ pub async fn test_notification(
|
||||
})
|
||||
}
|
||||
|
||||
/// Response for GET /api/time
|
||||
#[derive(Serialize)]
|
||||
pub struct TimeResponse {
|
||||
/// The raw system time (without clock offset)
|
||||
pub system_time: DateTime<Local>,
|
||||
/// The adjusted time (system time + offset)
|
||||
pub adjusted_time: DateTime<Local>,
|
||||
/// The current offset in seconds
|
||||
pub offset_seconds: i64,
|
||||
}
|
||||
|
||||
/// Request for POST /api/time-offset
|
||||
#[derive(Deserialize)]
|
||||
pub struct SetTimeOffsetRequest {
|
||||
/// The offset to set, in seconds
|
||||
pub offset_seconds: i64,
|
||||
}
|
||||
|
||||
pub async fn get_time() -> Json<TimeResponse> {
|
||||
Json(TimeResponse {
|
||||
system_time: Local::now(),
|
||||
adjusted_time: rayhunter::clock::get_adjusted_now(),
|
||||
offset_seconds: rayhunter::clock::get_offset().num_seconds(),
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn set_time_offset(Json(req): Json<SetTimeOffsetRequest>) -> StatusCode {
|
||||
rayhunter::clock::set_offset(chrono::TimeDelta::seconds(req.offset_seconds));
|
||||
StatusCode::OK
|
||||
}
|
||||
|
||||
pub async fn get_zip(
|
||||
State(state): State<Arc<ServerState>>,
|
||||
Path(entry_name): Path<String>,
|
||||
|
||||
Reference in New Issue
Block a user