Anubis module for Caddy

wip

Changed files
+14 -6
example
+1 -1
README.md
···
```
xcaddy build \
-
--with gl.kot.pink/kot/caddy-anubis \
--replace github.com/TecharoHQ/anubis=github.com/kotx/anubis-static@v1.21.0
# ...any other plugins
```
···
```
xcaddy build \
+
--with github.com/kotx/caddy-anubis \
--replace github.com/TecharoHQ/anubis=github.com/kotx/anubis-static@v1.21.0
# ...any other plugins
```
+8
caddy_anubis.go
···
import (
"fmt"
"net"
"net/http"
···
func (m *AnubisMiddleware) Provision(ctx caddy.Context) error {
m.log = ctx.Logger(m)
m.log.Debug("loading anubis policies", zap.String("policy_file", m.PolicyFname), zap.Int("default_difficulty", m.DefaultDifficulty))
policy, err := libanubis.LoadPoliciesOrDefault(ctx, m.PolicyFname, m.DefaultDifficulty)
if err != nil {
···
d.Next()
m.DefaultDifficulty = anubis.DefaultDifficulty
for nesting := d.Nesting(); d.NextBlock(nesting); {
switch d.Val() {
case "target":
}
} // anubis options
···
import (
"fmt"
+
"log/slog"
"net"
"net/http"
···
func (m *AnubisMiddleware) Provision(ctx caddy.Context) error {
m.log = ctx.Logger(m)
+
slog.SetLogLoggerLevel(slog.LevelDebug) // TODO: customizable log level
+
m.log.Debug("loading anubis policies", zap.String("policy_file", m.PolicyFname), zap.Int("default_difficulty", m.DefaultDifficulty))
policy, err := libanubis.LoadPoliciesOrDefault(ctx, m.PolicyFname, m.DefaultDifficulty)
if err != nil {
···
d.Next()
m.DefaultDifficulty = anubis.DefaultDifficulty
+
m.Options.CookieExpiration = anubis.CookieDefaultExpirationTime
+
m.Options.CookieSecure = true // TODO: temporary
for nesting := d.Nesting(); d.NextBlock(nesting); {
switch d.Val() {
case "target":
+
case "opengraph":
+
m.Options.OpenGraph.Enabled = true
+
}
} // anubis options
+4 -4
example/Caddyfile
···
-
eri.elf-bramble.ts.net {
@anubis {
-
path /
path /.within.website/* # required
}
anubis @anubis {
-
# required for OpenGraph passthrough!
## TODO: access backend directly somehow?
## otherwise anubis may trigger itself
-
## additionally, https://github.com/TecharoHQ/anubis/issues/319
# target http://localhost:8080
}
···
+
localhost {
@anubis {
+
path / # don't let AI scrapers list files!
path /.within.website/* # required
}
anubis @anubis {
+
# FIXME: required for OpenGraph passthrough!
## TODO: access backend directly somehow?
## otherwise anubis may trigger itself
+
## additionally, https://github.com/TecharoHQ/anubis/issues/329
# target http://localhost:8080
}
+1 -1
go.mod
···
-
module gl.kot.pink/kot/caddy-anubis
go 1.24.2
···
+
module gl.kot.pink/kot/caddy-anubis // TODO: change to github
go 1.24.2