Add nested rules Add backend action, allow wildcard in backends Remove poison from tree, update README with action table Allow defining pass/fail actions on challenge, Remove redirect/referer parameters on backend pass Set challenge cookie tied to host Rewrite DNSBL condition into a challenge Allow passing an arbitrary path for assets to js challenges Optimize programs exhaustively on compilation Activation instead of map for CEL context, faster map access, new network override Return valid host on cookie setting in case Host is an IP address. bug: does not work with IPv6, see https://github.com/golang/go/issues/65521 Apply TLS fingerprinter on GetConfigForClient instead of GetCertificate Cleanup go-away cookies before passing to backend Code action for specifically replying with an HTTP code
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package embed
|
|
|
|
import (
|
|
"embed"
|
|
"errors"
|
|
"io/fs"
|
|
"os"
|
|
)
|
|
|
|
//go:embed assets
|
|
var assetsFs embed.FS
|
|
|
|
//go:embed challenge
|
|
var challengeFs embed.FS
|
|
|
|
//go:embed templates
|
|
var templatesFs embed.FS
|
|
|
|
type FSInterface interface {
|
|
fs.FS
|
|
fs.ReadDirFS
|
|
fs.ReadFileFS
|
|
}
|
|
|
|
func trimPrefix(embedFS embed.FS, prefix string) FSInterface {
|
|
subFS, err := fs.Sub(embedFS, prefix)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if properFS, ok := subFS.(FSInterface); ok {
|
|
return properFS
|
|
} else {
|
|
panic("unsupported")
|
|
}
|
|
}
|
|
|
|
var ChallengeFs = trimPrefix(challengeFs, "challenge")
|
|
|
|
var TemplatesFs = trimPrefix(templatesFs, "templates")
|
|
var AssetsFs = trimPrefix(assetsFs, "assets")
|
|
|
|
func GetFallbackFS(embedFS FSInterface, prefix string) (FSInterface, error) {
|
|
var outFs fs.FS
|
|
if stat, err := os.Stat(prefix); err == nil && stat.IsDir() {
|
|
outFs = embedFS
|
|
} else if _, err := embedFS.ReadDir(prefix); err == nil {
|
|
outFs, err = fs.Sub(embedFS, prefix)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
} else {
|
|
return nil, err
|
|
}
|
|
if properFS, ok := outFs.(FSInterface); ok {
|
|
return properFS, nil
|
|
} else {
|
|
return nil, errors.New("unsupported FS")
|
|
}
|
|
}
|