Skip to content

Commit

Permalink
version bumps
Browse files Browse the repository at this point in the history
  • Loading branch information
ddboline committed Apr 28, 2024
1 parent 6110e59 commit 347c748
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 41 deletions.
31 changes: 16 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "security_log_analysis_rust"
version = "0.11.6"
version = "0.11.7"
authors = ["Daniel Boline <[email protected]>"]
edition = "2018"

Expand All @@ -14,51 +14,52 @@ Analyze Auth Logs."""

[dependencies]
anyhow = "1.0"
authorized_users = { git = "https://github.com/ddboline/auth_server_rust.git", tag="0.11.8"}
authorized_users = { git = "https://github.com/ddboline/auth_server_rust.git", tag="0.11.13"}
aws-config = {version="1.0", features=["behavior-version-latest"]}
aws-sdk-s3 = "1.1"
aws-sdk-ses = "1.1"
bytes = "1.0"
cached = {version="0.46", features=["async", "async_tokio_rt_multi_thread"]}
cached = {version="0.50", features=["async", "async_tokio_rt_multi_thread"]}
chrono = "0.4"
clap = {version="4.0", features=["derive"]}
deadpool = {version = "0.10", features=["serde", "rt_tokio_1"]}
deadpool-postgres = {version="0.12", features=["serde"]}
deadpool = {version = "0.11", features=["serde", "rt_tokio_1"]}
deadpool-postgres = {version="0.13", features=["serde"]}
deadqueue = "0.2"
derive_more = "0.99"
dioxus = "0.4"
dioxus-ssr = "0.4"
dioxus = "0.5"
dioxus-core = "0.5"
dioxus-ssr = "0.5"
dirs = "5.0"
dotenv = "0.15"
envy = "0.4"
env_logger = "0.10"
env_logger = "0.11"
flate2 = "1.0"
futures = "0.3"
glob = "0.3"
itertools = "0.12"
log = "0.4"
maplit = "1.0"
parking_lot = "0.12"
polars = {version="0.35", features=["temporal", "parquet", "lazy"]}
postgres_query = {git = "https://github.com/ddboline/rust-postgres-query", tag = "0.3.6", features=["deadpool"]}
polars = {version="0.39", features=["temporal", "parquet", "lazy"]}
postgres_query = {git = "https://github.com/ddboline/rust-postgres-query", tag = "0.3.7", features=["deadpool"]}
postgres-types = {version="0.2", features=["with-time-0_3", "with-uuid-1", "with-serde_json-1"]}
rand = "0.8"
rayon = "1.5"
refinery = {version="0.8", features=["tokio-postgres"]}
reqwest = {version="0.11", features=["json", "rustls-tls"], default_features=false}
reqwest = {version="0.12", features=["json", "rustls-tls"], default_features=false}
serde = { version="1.0", features=["derive"]}
serde_json = "1.0"
serde_yaml = "0.9"
smallvec = "1.6"
stack-string = { git = "https://github.com/ddboline/stack-string-rs.git", features=["postgres_types", "rweb-openapi"], tag="0.9.2" }
stack-string = { git = "https://github.com/ddboline/stack-string-rs.git", features=["postgres_types", "rweb-openapi"], tag="0.9.3" }
stdout-channel = "0.6"
thiserror = "1.0"
time = {version="0.3", features=["serde-human-readable", "macros", "formatting"]}
time-tz = {version="2.0", features=["system"]}
tokio-postgres = {version="0.7", features=["with-time-0_3", "with-uuid-1", "with-serde_json-1"]}
tokio = {version="1.35", features=["rt", "macros", "rt-multi-thread"]}
rweb = {git = "https://github.com/ddboline/rweb.git", features=["openapi"], default-features=false, tag="0.15.1-1"}
rweb-helper = { git = "https://github.com/ddboline/rweb_helper.git", tag="0.5.1" }
tokio = {version="1.37", features=["rt", "macros", "rt-multi-thread"]}
rweb = {git = "https://github.com/ddboline/rweb.git", features=["openapi"], default-features=false, tag="0.15.2"}
rweb-helper = { git = "https://github.com/ddboline/rweb_helper.git", tag="0.5.3" }
uuid = { version = "1.0", features = ["serde", "v4"] }

[[bin]]
Expand Down
3 changes: 3 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rweb::{
use std::borrow::Cow;
use thiserror::Error;
use tokio::task::JoinError;
use std::fmt::Error as FmtError;

#[derive(Error, Debug)]
pub enum ServiceError {
Expand All @@ -22,6 +23,8 @@ pub enum ServiceError {
JoinError(#[from] JoinError),
#[error("PgError {0}")]
PgError(#[from] PgError),
#[error("FmtError {0}")]
FmtError(#[from] FmtError),
}

impl Reject for ServiceError {}
Expand Down
24 changes: 10 additions & 14 deletions src/polars_analysis.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use anyhow::{format_err, Error};
use chrono::{Duration, NaiveDateTime, Utc};
use chrono::{Duration, NaiveDateTime, DateTime, Utc};
use futures::TryStreamExt;
use log::info;
use polars::{
chunked_array::ops::SortOptions,
chunked_array::ops::SortMultipleOptions,
df as dataframe,
frame::DataFrame,
io::{
parquet::{ParquetReader, ParquetWriter},
SerReader,
},
lazy::{dsl::functions::col, frame::IntoLazy},
prelude::{lit, LazyFrame, NamedFrom, ScanArgsParquet, UniqueKeepStrategy},
prelude::{lit, LazyFrame, ScanArgsParquet, UniqueKeepStrategy},
};
use postgres_query::{query, FromSqlRow};
use stack_string::{format_sstr, StackString};
Expand Down Expand Up @@ -117,9 +117,7 @@ pub async fn insert_db_into_parquet(
acc.server.push(row.server);

let d = row.datetime.to_offset(UtcOffset::UTC);
let datetime =
NaiveDateTime::from_timestamp_opt(d.unix_timestamp(), d.nanosecond())
.unwrap_or_default();
let datetime = DateTime::from_timestamp(d.unix_timestamp(), d.nanosecond()).unwrap_or_default().naive_utc();
acc.datetime.push(datetime);
acc.host.push(row.host);
acc.username.push(row.username);
Expand Down Expand Up @@ -233,14 +231,14 @@ pub fn read_parquet_files(
.group_by(["country"])
.agg([col("country_count").sum().alias("count")])
.sort(
"count",
SortOptions {
descending: true,
..SortOptions::default()
["count"],
SortMultipleOptions {
descending: vec![true],
..SortMultipleOptions::default()
},
)
.collect()?;
let country_iter = df.column("country")?.utf8()?.into_iter();
let country_iter = df.column("country")?.str()?.into_iter();
let count_iter = df.column("count")?.u32()?.into_iter();
let code_count: Vec<_> = country_iter
.zip(count_iter)
Expand Down Expand Up @@ -270,9 +268,7 @@ fn get_country_count(
df = df.filter(col("server").eq(lit(server.to_str())));
}
if let Some(ndays) = ndays {
let begin_timestamp = (Utc::now() - Duration::days(i64::from(ndays)))
.naive_utc()
.timestamp_millis();
let begin_timestamp = (Utc::now() - Duration::days(i64::from(ndays))).timestamp_millis();
df = df.filter(
col("datetime")
.dt()
Expand Down
23 changes: 15 additions & 8 deletions src/security_log_element.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
use dioxus::prelude::{
component, dioxus_elements, format_args_f, rsx, Element, GlobalAttributes, IntoDynNode,
LazyNodes, Props, Scope, VNode, VirtualDom,
Props, VNode, VirtualDom,
};
use stack_string::StackString;
use std::fmt::Write;

use security_log_analysis_rust::{config::Config, CountryCount};

pub fn index_body(data: StackString, config: Config) -> String {
use security_log_analysis_rust::errors::ServiceError as Error;

pub fn index_body(data: StackString, config: Config) -> Result<String, Error> {
let mut app = VirtualDom::new_with_props(IndexElement, IndexElementProps { data, config });
drop(app.rebuild());
dioxus_ssr::render(&app)
app.rebuild_in_place();
let mut renderer = dioxus_ssr::Renderer::default();
let mut buffer = String::new();
renderer
.render_to(&mut buffer, &app)
.map_err(Into::<Error>::into)?;
Ok(buffer)
}

#[component]
fn IndexElement(cx: Scope, data: StackString, config: Config) -> Element {
fn IndexElement(data: StackString, config: Config) -> Element {
let maps_script = config.maps_api_key.as_ref().map(|map_api_key| {
rsx! {
script {
Expand All @@ -29,7 +36,7 @@ fn IndexElement(cx: Scope, data: StackString, config: Config) -> Element {
writeln!(&mut script_body, "\tdraw_map(data);").unwrap();
script_body.push_str("}()");

cx.render(rsx! {
rsx! {
head {
script {
"type": "text/javascript",
Expand All @@ -41,7 +48,7 @@ fn IndexElement(cx: Scope, data: StackString, config: Config) -> Element {
}
},
body {
maps_script,
{maps_script},
script {
dangerous_inner_html: "{script_body}",
}
Expand All @@ -50,5 +57,5 @@ fn IndexElement(cx: Scope, data: StackString, config: Config) -> Element {
style: "width: 900px; height: 500px;",
}
}
})
}
}
8 changes: 4 additions & 4 deletions src/security_log_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl fmt::Display for AttemptsQuery {
}

#[cached(
type = "TimedSizedCache<StackString, StackString>",
ty = "TimedSizedCache<StackString, StackString>",
create = "{ TimedSizedCache::with_size_and_lifespan(100, 3600) }",
convert = r#"{ format_sstr!("{}", query) }"#,
result = true
Expand Down Expand Up @@ -192,12 +192,12 @@ async fn intrusion_attempts(
let query = query.into_inner();
let config = data.config.clone();
let data = get_cached_country_count(&data.pool, query).await?;
let body = security_log_element::index_body(data, config);
let body = security_log_element::index_body(data, config)?;
Ok(HtmlBase::new(body.into()).into())
}

#[cached(
type = "TimedSizedCache<StackString, StackString>",
ty = "TimedSizedCache<StackString, StackString>",
create = "{ TimedSizedCache::with_size_and_lifespan(100, 3600) }",
convert = r#"{ format_sstr!("{}", query) }"#,
result = true
Expand Down Expand Up @@ -236,7 +236,7 @@ async fn intrusion_attempts_all(
let query = query.into_inner();
let config = data.config.clone();
let data = get_cached_country_count_all(config.clone(), query).await?;
let body = security_log_element::index_body(data, config);
let body = security_log_element::index_body(data, config)?;
Ok(HtmlBase::new(body.into()).into())
}

Expand Down

0 comments on commit 347c748

Please sign in to comment.