Skip to content

Commit

Permalink
server: expose ja4db update over the http api
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonish committed Jul 6, 2024
1 parent 0dd7b17 commit 1ebdc8b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod version;
mod agent;
mod bookmark;
mod cert;
mod commands;
mod config;
mod datetime;
mod elastic;
Expand All @@ -25,7 +26,6 @@ mod resource;
mod rules;
mod sqlite;
mod util;
mod commands;

#[macro_use]
extern crate lazy_static;
Expand Down
26 changes: 26 additions & 0 deletions src/server/api/admin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: (C) 2024 Jason Ish <[email protected]>
// SPDX-License-Identifier: MIT

use std::sync::Arc;

use axum::{Extension, Json};
use tracing::info;

use crate::server::{main::SessionExtractor, ServerContext};

use super::ApiError;

pub(super) async fn update_ja4db(
context: Extension<Arc<ServerContext>>,
_session: SessionExtractor,
) -> Result<Json<serde_json::Value>, ApiError> {
let mut conn = context.config_repo.pool.begin().await?;
info!("Updating JA4db");
let n = crate::commands::ja4db::updatedb(&mut conn).await?;
conn.commit().await?;
let response = json!({
"entries": n,
});
info!("JA4db successfully updated: entries={n}");
Ok(Json(response))
}
7 changes: 6 additions & 1 deletion src/server/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use tracing::{error, info, warn};
use self::genericquery::TimeRange;
use self::util::parse_duration;

pub(crate) mod admin;
pub(crate) mod agg;
pub(crate) mod eve2pcap;
pub(crate) mod genericquery;
Expand Down Expand Up @@ -63,6 +64,7 @@ pub(crate) fn router() -> axum::Router<Arc<ServerContext>> {
.route("/api/1/sqlite/fts/enable", post(sqlite::fts_enable))
.route("/api/1/sqlite/fts/disable", post(sqlite::fts_disable))
.route("/api/ja4db/:fingerprint", get(ja4db))
.route("/api/admin/update/ja4db", post(admin::update_ja4db))
.nest("/api/1/stats", stats::router())
}

Expand Down Expand Up @@ -434,7 +436,10 @@ async fn ja4db(
if let Some(entry) = entry {
Ok(Json(entry).into_response())
} else {
Ok(StatusCode::NOT_FOUND.into_response())
let response = json!({
"message": "fingerprint not found",
});
Ok((StatusCode::NOT_FOUND, Json(response)).into_response())
}
}

Expand Down

0 comments on commit 1ebdc8b

Please sign in to comment.