rename json to caddy

it was misleading
This commit is contained in:
Pierre Dubouilh
2026-08-28 00:34:23 +02:00
committed by Pierre Dubouilh
parent e8437d33fb
commit 2df9519224
5 changed files with 39 additions and 39 deletions
+6 -6
View File
@@ -9,10 +9,10 @@ build::
run:: run::
touch /tmp/clftest touch /tmp/clftest
touch /tmp/jsontest touch /tmp/caddytest
touch /tmp/generictest touch /tmp/generictest
cargo build cargo build
sudo target/debug/blockfast -v -c=/tmp/clftest -j=/tmp/jsontest --generic-logpath=/tmp/generictest --generic-ip='from ([0-9a-fA-F:.]+) port' --generic-positive='Failed password' sudo target/debug/blockfast -v --clf-logpath=/tmp/clftest --caddy-logpath=/tmp/caddytest --generic-logpath=/tmp/generictest --generic-ip='from ([0-9a-fA-F:.]+) port' --generic-positive='Failed password'
ci:: test ci:: test
cargo fmt --all -- --check cargo fmt --all -- --check
@@ -55,9 +55,9 @@ hit-clf::
ok-clf:: ok-clf::
echo "2.124.36.195 - p [25/Sep/2021:13:49:56 +0200] \"POST /some/rpc HTTP/2.0\" 200 23012" >> /tmp/clftest echo "2.124.36.195 - p [25/Sep/2021:13:49:56 +0200] \"POST /some/rpc HTTP/2.0\" 200 23012" >> /tmp/clftest
hit-json:: hit-caddy::
echo "{\"request\":{\"remote_ip\":\"1.124.36.19\"}, \"status\": 400}" >> /tmp/jsontest echo "{\"request\":{\"remote_ip\":\"1.124.36.19\"}, \"status\": 400}" >> /tmp/caddytest
ok-json:: ok-caddy::
echo "{\"request\":{\"remote_ip\":\"2.124.36.19\"}, \"status\": 200}" >> /tmp/jsontest echo "{\"request\":{\"remote_ip\":\"2.124.36.19\"}, \"status\": 200}" >> /tmp/caddytest
+17 -17
View File
@@ -3,8 +3,8 @@
Block internets scanners fast 🍶 Block internets scanners fast 🍶
Features: Features:
- Common Log Format parser (apache logs, etc...) - Common Log Format parser (apache, nginx logs, etc...)
- JSON log parser (caddy logs) - Caddy JSON log parser
- Generic log parser - Generic log parser
- Sane defaults - Sane defaults
- Fast ip ban with `ipset` - Fast ip ban with `ipset`
@@ -13,15 +13,15 @@ Features:
## example ## example
```txt ```txt
$ ./blockfast -j=/caddy/logs $ ./blockfast --caddy-logpath=/caddy/logs
1737927469 - starting with json parsing at "/tmp/jsontest" 1737927469 - starting with caddy parsing at "/tmp/caddytest"
1737927469 - jail setup, allowance 5, time 21600s 1737927469 - jail setup, allowance 5, time 21600s
1737927477 - json logged offence for 9.124.36.195 1737927477 - caddy logged offence for 9.124.36.195
1737927478 - json logged offence for 9.124.36.195 1737927478 - caddy logged offence for 9.124.36.195
1737927479 - json logged offence for 9.124.36.195 1737927479 - caddy logged offence for 9.124.36.195
1737927479 - json logged offence for 9.124.36.195 1737927479 - caddy logged offence for 9.124.36.195
1737927480 - json logged offence for 9.124.36.195 1737927480 - caddy logged offence for 9.124.36.195
1737927480 - json jailtime for 9.124.36.195 1737927480 - caddy jailtime for 9.124.36.195
``` ```
## build ## build
@@ -34,11 +34,11 @@ Blockfast - block internets scanners fast 🍶
Author: pierre dubouilh <pldubouilh@gmail.com> Author: pierre dubouilh <pldubouilh@gmail.com>
Blockfast reads logs from various sources and blocks the offending IPs using iptables and ipset. Blockfast reads logs from various sources and blocks the offending IPs using iptables and ipset.
It supports logs in Common-Log-Format (Apache, etc..), JSON (Caddy) and a generic logs parser. It supports logs in Common-Log-Format (Apache, nginx, etc..), Caddy JSON and a generic logs parser.
Example: Example:
# block invalid http statuses from caddy # block invalid http statuses from caddy
./blockfast -j=/caddy/logs ./blockfast --caddy-logpath=/caddy/logs
# generic log parser example with a log text to flag, and a regex to parse the offending IP. # generic log parser example with a log text to flag, and a regex to parse the offending IP.
./blockfast --generic-logpath=/tmp/generictest --generic-positive='Failed password' --generic-ip='from ([0-9a-fA-F:.]+) port' ./blockfast --generic-logpath=/tmp/generictest --generic-positive='Failed password' --generic-ip='from ([0-9a-fA-F:.]+) port'
@@ -52,10 +52,10 @@ Options:
how many offences allowed (max 255) [default: 5] how many offences allowed (max 255) [default: 5]
-v, --verbose -v, --verbose
log all offences log all offences
-c, --clf-logpath <CLF_LOGPATH> --clf-logpath <CLF_LOGPATH>
path of Common-Log-Format logfile (Apache, etc..), can be repeated path of Common-Log-Format logfile (Apache, nginx, etc..), can be repeated
-j, --json-logpath <JSON_LOGPATH> --caddy-logpath <CADDY_LOGPATH>
path of JSON logfile (works with Caddy), can be repeated path of Caddy JSON logfile, can be repeated
--generic-logpath <GENERIC_LOGPATH> --generic-logpath <GENERIC_LOGPATH>
generic parser log file path, can be repeated generic parser log file path, can be repeated
--generic-ip <GENERIC_IP> --generic-ip <GENERIC_IP>
@@ -65,7 +65,7 @@ Options:
--generic-negative <GENERIC_NEGATIVE> --generic-negative <GENERIC_NEGATIVE>
generic parser negative - if a logline contains this, it is considered good, the rest is bad generic parser negative - if a logline contains this, it is considered good, the rest is bad
--invalid-http-statuses <INVALID_HTTP_STATUSES> --invalid-http-statuses <INVALID_HTTP_STATUSES>
invalid http statuses (for CLF and JSON logs). Coma separated list, accepts ranges with XX [default: 400,401,402,403] invalid http statuses (for CLF and Caddy logs). Coma separated list, accepts ranges with XX [default: 400,401,402,403]
-h, --help -h, --help
Print help Print help
-V, --version -V, --version
View File
+8 -8
View File
@@ -4,9 +4,9 @@ use anyhow::*;
use clap::Parser; use clap::Parser;
use linemux::{Line, MuxedLines}; use linemux::{Line, MuxedLines};
mod caddy;
mod clf; mod clf;
mod generic; mod generic;
mod json;
mod utils; mod utils;
mod jail; mod jail;
@@ -39,14 +39,14 @@ async fn run() -> Result<()> {
log!("starting with clf parsing at {:?}", &p); log!("starting with clf parsing at {:?}", &p);
} }
// json // caddy json
let json_logpaths = &args.json_logpath; let caddy_logpaths = &args.caddy_logpath;
for p in json_logpaths { for p in caddy_logpaths {
ml.add_file(&p).await?; ml.add_file(&p).await?;
log!("starting with json parsing at {:?}", &p); log!("starting with caddy parsing at {:?}", &p);
} }
if json_logpaths.is_empty() && clf_logpaths.is_empty() && generic_paths.is_empty() { if caddy_logpaths.is_empty() && clf_logpaths.is_empty() && generic_paths.is_empty() {
bail!("no log files to parse, see --help"); bail!("no log files to parse, see --help");
} }
@@ -60,8 +60,8 @@ async fn run() -> Result<()> {
let (target, ret) = if path.is_some_and(|p| clf_logpaths.contains(p)) { let (target, ret) = if path.is_some_and(|p| clf_logpaths.contains(p)) {
("clf", clf::parse(payload, invalid_statuses_ref)?) ("clf", clf::parse(payload, invalid_statuses_ref)?)
} else if path.is_some_and(|p| json_logpaths.contains(p)) { } else if path.is_some_and(|p| caddy_logpaths.contains(p)) {
("json", json::parse(payload, invalid_statuses_ref)?) ("caddy", caddy::parse(payload, invalid_statuses_ref)?)
} else if path.is_some_and(|p| generic_paths.contains(p)) { } else if path.is_some_and(|p| generic_paths.contains(p)) {
( (
"generic", "generic",
+8 -8
View File
@@ -86,11 +86,11 @@ Blockfast - block internets scanners fast 🍶
Author: pierre dubouilh <pldubouilh@gmail.com> Author: pierre dubouilh <pldubouilh@gmail.com>
Blockfast reads logs from various sources and blocks the offending IPs using iptables and ipset. Blockfast reads logs from various sources and blocks the offending IPs using iptables and ipset.
It supports logs in Common-Log-Format (Apache, etc..), JSON (Caddy) and a generic logs parser. It supports logs in Common-Log-Format (Apache, nginx, etc..), Caddy JSON and a generic logs parser.
Example: Example:
# block invalid http statuses from caddy # block invalid http statuses from caddy
./blockfast -j=/caddy/logs ./blockfast --caddy-logpath=/caddy/logs
# generic log parser example with a log text to flag, and a regex to parse the offending IP. # generic log parser example with a log text to flag, and a regex to parse the offending IP.
./blockfast --generic-logpath=/tmp/generictest --generic-positive='Failed password' --generic-ip='from ([0-9a-fA-F:.]+) port'", ./blockfast --generic-logpath=/tmp/generictest --generic-positive='Failed password' --generic-ip='from ([0-9a-fA-F:.]+) port'",
@@ -110,13 +110,13 @@ pub struct Args {
#[clap(short, long)] #[clap(short, long)]
pub verbose: bool, pub verbose: bool,
/// path of Common-Log-Format logfile (Apache, etc..), can be repeated /// path of Common-Log-Format logfile (Apache, nginx, etc..), can be repeated
#[clap(short, long, value_parser = resolve_path)] #[clap(long, value_parser = resolve_path)]
pub clf_logpath: Vec<PathBuf>, pub clf_logpath: Vec<PathBuf>,
/// path of JSON logfile (works with Caddy), can be repeated /// path of Caddy JSON logfile, can be repeated
#[clap(short, long, value_parser = resolve_path)] #[clap(long, value_parser = resolve_path)]
pub json_logpath: Vec<PathBuf>, pub caddy_logpath: Vec<PathBuf>,
/// generic parser log file path, can be repeated /// generic parser log file path, can be repeated
#[clap(long, value_parser = resolve_path, requires_all = ["generic_ip", "generic_match"])] #[clap(long, value_parser = resolve_path, requires_all = ["generic_ip", "generic_match"])]
@@ -134,7 +134,7 @@ pub struct Args {
#[clap(long, requires = "generic_logpath")] #[clap(long, requires = "generic_logpath")]
pub generic_negative: Option<String>, pub generic_negative: Option<String>,
/// invalid http statuses (for CLF and JSON logs). Coma separated list, accepts ranges with XX. /// invalid http statuses (for CLF and Caddy logs). Coma separated list, accepts ranges with XX.
#[clap(long, default_value = "400,401,402,403")] #[clap(long, default_value = "400,401,402,403")]
pub invalid_http_statuses: String, pub invalid_http_statuses: String,
} }