Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Custom HTML Headers and static assets got lost on caddy adapt #290

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions assets/cla/consent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@
email: [email protected]
- name: Freddy Heppell
email: [email protected]
- name: Peter Oettig
email: [email protected]
23 changes: 6 additions & 17 deletions caddyfile_authn_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/greenpau/caddy-security/pkg/util"
"github.com/greenpau/go-authcrunch/pkg/authn"
"github.com/greenpau/go-authcrunch/pkg/authn/ui"
"io/ioutil"
"strings"
)

Expand Down Expand Up @@ -130,19 +129,7 @@ func parseCaddyfileAuthPortalUI(h *caddyfile.Dispenser, repl *caddy.Replacer, po
case strings.HasPrefix(args, "js"):
portal.UI.CustomJsPath = strings.ReplaceAll(args, "js ", "")
case strings.HasPrefix(args, "html header path"):
args = strings.ReplaceAll(args, "html header path ", "")
b, err := ioutil.ReadFile(args)
if err != nil {
return h.Errf("%s %s subdirective: %s %v", rootDirective, subDirective, args, err)
}
for k, v := range ui.PageTemplates {
headIndex := strings.Index(v, "<meta name=\"description\"")
if headIndex < 1 {
continue
}
v = v[:headIndex] + string(b) + v[headIndex:]
ui.PageTemplates[k] = v
}
portal.UI.CustomHTMLHeaderPath = strings.ReplaceAll(args, "html header path ", "")
case args == "":
return h.Errf("%s %s directive has no value", rootDirective, subDirective)
default:
Expand All @@ -161,9 +148,11 @@ func parseCaddyfileAuthPortalUI(h *caddyfile.Dispenser, repl *caddy.Replacer, po
return h.Errf("auth backend %s subdirective %s URI must be prefixed with %s, got %s",
rootDirective, subDirective, prefix, assetURI)
}
if err := ui.StaticAssets.AddAsset(assetURI, assetContentType, assetPath); err != nil {
return h.Errf("auth backend %s subdirective %s failed: %s", rootDirective, subDirective, err)
}
portal.UI.StaticAssets = append(portal.UI.StaticAssets, ui.StaticAsset{
Path: assetURI,
FsPath: assetPath,
ContentType: assetContentType,
})
case "disable":
args := util.FindReplaceAll(repl, h.RemainingArgs())
if err := portal.UI.DisablePage(args); err != nil {
Expand Down