From eb867528e39cd7449f8c5f112c5a2ea564daa038 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Thu, 22 Jun 2023 07:01:29 +0200 Subject: [PATCH 1/2] feat - Allow to overwrite login template --- cmd/cc-backend/main.go | 7 +++++++ web/web.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/cmd/cc-backend/main.go b/cmd/cc-backend/main.go index f9868e6..86c5323 100644 --- a/cmd/cc-backend/main.go +++ b/cmd/cc-backend/main.go @@ -325,6 +325,13 @@ func main() { if config.Keys.EmbedStaticFiles { r.PathPrefix("/").Handler(web.ServeFiles()) + + if i, err := os.Stat("./var/img"); err == nil { + if i.IsDir() { + log.Info("Use local directory for static images") + r.Handle("/img", http.FileServer(http.Dir("./var/img"))) + } + } } else { r.PathPrefix("/").Handler(http.FileServer(http.Dir(config.Keys.StaticFiles))) } diff --git a/web/web.go b/web/web.go index 3547b85..d045b05 100644 --- a/web/web.go +++ b/web/web.go @@ -47,6 +47,14 @@ func init() { return nil } + if path == "templates/login.tmpl" { + if _, err := os.Stat("./var/login.tmpl"); err == nil { + log.Info("overwrite login.tmpl with local file") + templates[strings.TrimPrefix(path, "templates/")] = + template.Must(template.Must(base.Clone()).ParseFiles("./var/login.tmpl")) + return nil + } + } if path == "templates/imprint.tmpl" { if _, err := os.Stat("./var/imprint.tmpl"); err == nil { log.Info("overwrite imprint.tmpl with local file") From c1397ef7d56e3a99faab4fb3981e9074af00c174 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Fri, 23 Jun 2023 13:34:57 +0200 Subject: [PATCH 2/2] Make img directory configurable --- cmd/cc-backend/main.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/cc-backend/main.go b/cmd/cc-backend/main.go index 5c253b1..438c9ab 100644 --- a/cmd/cc-backend/main.go +++ b/cmd/cc-backend/main.go @@ -327,14 +327,13 @@ func main() { api.MountRoutes(secured) if config.Keys.EmbedStaticFiles { - r.PathPrefix("/").Handler(web.ServeFiles()) - if i, err := os.Stat("./var/img"); err == nil { if i.IsDir() { log.Info("Use local directory for static images") - r.Handle("/img", http.FileServer(http.Dir("./var/img"))) + r.PathPrefix("/img/").Handler(http.StripPrefix("/img/", http.FileServer(http.Dir("./var/img")))) } } + r.PathPrefix("/").Handler(web.ServeFiles()) } else { r.PathPrefix("/").Handler(http.FileServer(http.Dir(config.Keys.StaticFiles))) } @@ -402,14 +401,14 @@ func main() { // Because this program will want to bind to a privileged port (like 80), the listener must // be established first, then the user can be changed, and after that, // the actual http server can be started. - if err := runtimeEnv.DropPrivileges(config.Keys.Group, config.Keys.User); err != nil { + if err = runtimeEnv.DropPrivileges(config.Keys.Group, config.Keys.User); err != nil { log.Fatalf("error while preparing server start: %s", err.Error()) } wg.Add(1) go func() { defer wg.Done() - if err := server.Serve(listener); err != nil && err != http.ErrServerClosed { + if err = server.Serve(listener); err != nil && err != http.ErrServerClosed { log.Fatalf("starting server failed: %v", err) } }() @@ -435,7 +434,7 @@ func main() { log.Info("Register undead jobs service") s.Every(1).Day().At("3:00").Do(func() { - err := jobRepo.StopJobsExceedingWalltimeBy(config.Keys.StopJobsExceedingWalltime) + err = jobRepo.StopJobsExceedingWalltimeBy(config.Keys.StopJobsExceedingWalltime) if err != nil { log.Warnf("Error while looking for jobs exceeding their walltime: %s", err.Error()) } @@ -450,7 +449,7 @@ func main() { cfg.Retention.IncludeDB = true - if err := json.Unmarshal(config.Keys.Archive, &cfg); err != nil { + if err = json.Unmarshal(config.Keys.Archive, &cfg); err != nil { log.Warn("Error while unmarshaling raw config json") }