Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions wallguard-common/src/protobuf/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::pedantic)]
#![allow(clippy::large_enum_variant)]
#![allow(clippy::result_large_err)]
#![allow(clippy::double_must_use)]

#[allow(clippy::enum_variant_names)]
#[rustfmt::skip]
Expand Down
1 change: 0 additions & 1 deletion wallguard-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@
| `CONTROL_SERVICE_PORT` | Port to bind control service to |
| `HTTP_PROXY_HOST` | HTTP proxy host |
| `HTTP_PROXY_PORT` | HTTP proxy port |
| `IP_INFO_API_KEY` | API key for IP info service |
1 change: 1 addition & 0 deletions wallguard-server/src/datastore/generated/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::pedantic)]
#![allow(clippy::large_enum_variant)]
#![allow(clippy::result_large_err)]
#![allow(clippy::double_must_use)]
#[allow(clippy::enum_variant_names)]
#[rustfmt::skip]
#[allow(dead_code)]
Expand Down
40 changes: 3 additions & 37 deletions wallguard-server/src/traffic_handler/ip_info.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::app_context::AppContext;
use indexmap::IndexSet;
use nullnet_liberror::Error;
use nullnet_libipinfo::{ApiFields, IpInfoHandler, IpInfoProvider};
use nullnet_libipinfo::IpInfoHandler;
use std::net::IpAddr;
use std::sync::mpsc::Receiver;
use tokio::runtime::Handle;
Expand Down Expand Up @@ -41,13 +41,6 @@ async fn get_and_store_ip_info(ip: IpAddr, context: AppContext) -> Result<(), Er
log::info!("Looking up IP information for {ip}");
let ip_info = HANDLER.lookup(&ip).await?;
log::info!("Looked up IP information for {ip}: {ip_info:?}");
let ip_info = if ip_info.country.is_none() && ip_info.asn.is_none() && ip_info.org.is_none()
{
log::warn!("IP info API lookup returned empty result for {ip}, falling back to MMDB");
MMDB_HANDLER.lookup(&ip).await?
} else {
ip_info
};
context
.datastore
.create_ip_info(&token.jwt, &ip_info, &ip)
Expand Down Expand Up @@ -82,33 +75,6 @@ impl IpCache {
}
}

static HANDLER: std::sync::LazyLock<IpInfoHandler> = std::sync::LazyLock::new(|| {
#[cfg(not(debug_assertions))]
let url = "https://ipapi.co/{ip}/json/?key={api_key}";
#[cfg(debug_assertions)]
let url = "https://ipapi.co/{ip}/json";

let api_key = std::env::var("IP_INFO_API_KEY").unwrap_or_else(|_| {
log::warn!("IP_INFO_API_KEY environment variable not set");
String::new()
});

IpInfoHandler::new(vec![IpInfoProvider::new_api_provider(
url,
&api_key,
ApiFields {
country: Some("/country"),
asn: Some("/asn"),
org: Some("/org"),
continent_code: Some("/continent_code"),
city: Some("/city"),
region: Some("/region"),
postal: Some("/postal"),
timezone: Some("/timezone"),
},
)])
.unwrap()
});

static MMDB_HANDLER: std::sync::LazyLock<IpInfoHandler> =
// No API providers: lookups always use the free db-ip.com lite MMDB databases
static HANDLER: std::sync::LazyLock<IpInfoHandler> =
std::sync::LazyLock::new(|| IpInfoHandler::new(vec![]).unwrap());
Loading