feat: adding handler for fail2ban

This commit is contained in:
Lomain 2026-03-08 15:23:28 +01:00
parent 981a7cd9dd
commit de3937721a
2 changed files with 27 additions and 1 deletions

25
bin/handlers/404-to-fail2ban.py Executable file
View file

@ -0,0 +1,25 @@
# In your `jail.local`, add:
# [copyparty]
# enabled = true
# logpath = /path/to/log/file # or keep the default value if you're using systemd
# Create the `copyparty.conf` file in `filter.d` with the following:
# [Definition]
# failregex = ^ fail2ban\s*WARN: <ADDR>$
# ignoreregex =
# datepattern = ^%%H:%%M:%%S\.%%f
# First check `--dont-ban`, and if it doesn't match, log the line to be intercepted by fail2ban.
def main(cli, vn, rem):
cond = cli.args.dont_ban
if (
cond == "any"
or (cond == "auth" and cli.uname != "*")
or (cond == "aa" and cli.avol)
or (cond == "av" and cli.can_admin)
or (cond == "rw" and cli.can_read and cli.can_write)
):
return ""
cli.log_func("fail2ban", f"{cli.ip}", 3)
return ""

View file

@ -22,10 +22,11 @@ each plugin must define a `main()` which takes 3 arguments;
* [redirect.py](redirect.py) sends an HTTP 301 or 302, redirecting the client to another page/file * [redirect.py](redirect.py) sends an HTTP 301 or 302, redirecting the client to another page/file
* [randpic.py](randpic.py) redirects `/foo/bar/randpic.jpg` to a random pic in `/foo/bar/` * [randpic.py](randpic.py) redirects `/foo/bar/randpic.jpg` to a random pic in `/foo/bar/`
* [sorry.py](answer.py) replies with a custom message instead of the usual 404 * [sorry.py](sorry.py) replies with a custom message instead of the usual 404
* [nooo.py](nooo.py) replies with an endless noooooooooooooo * [nooo.py](nooo.py) replies with an endless noooooooooooooo
* [never404.py](never404.py) 100% guarantee that 404 will never be a thing again as it automatically creates dummy files whenever necessary * [never404.py](never404.py) 100% guarantee that 404 will never be a thing again as it automatically creates dummy files whenever necessary
* [caching-proxy.py](caching-proxy.py) transforms copyparty into a squid/varnish knockoff * [caching-proxy.py](caching-proxy.py) transforms copyparty into a squid/varnish knockoff
* [404-to-fail2ban.py](404-to-fail2ban.py) creates 404 logs for fail2ban
## on403 ## on403