diff --git a/README.md b/README.md index b1267da..7ceec80 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,14 @@ This is a minimal go ldap frontend for users to change their password. **This frontend is intended to run behind a reverse proxy and has no native TLS/SSL support!** +## Getting Started + +```sh +go build + +./goldap +``` + ## Licence diff --git a/goldap.ini b/goldap.ini index 946768e..33c4b56 100644 --- a/goldap.ini +++ b/goldap.ini @@ -18,3 +18,7 @@ url: http://the.url.of.your.portal.site:6969 listen_address: 0.0.0.0:6969 # Page title page_title_prefix: "LDAP Portal" + +[content] +# Information box +information: Aktuell wird keine Passwortzurücksetzung unterstützt. Wenn Sie Ihr Passwort vergessen oder verloren haben, wenden Sie sich bitte an unseren Support unter kernteam@urz.uni-heidelberg.de. diff --git a/html/templates/login_form.html b/html/templates/login_form.html index 477ebfc..9f1b143 100644 --- a/html/templates/login_form.html +++ b/html/templates/login_form.html @@ -33,5 +33,12 @@

Bitte melden Sie sich an, um Ihr Passwort zu ändern

+ {{ if .information }} +
+ +
+ {{ end }} diff --git a/parseini.go b/parseini.go index a4f161b..3228131 100644 --- a/parseini.go +++ b/parseini.go @@ -2,10 +2,11 @@ package main import ( "fmt" + "os" + "github.com/go-playground/validator/v10" "github.com/rs/zerolog/log" "gopkg.in/ini.v1" - "os" ) // Configuration struct for general app configuration values @@ -16,7 +17,8 @@ type Config struct { ListenAddress string `validate:"required,tcp_addr"` PageTitlePrefix string `validate:"required"` } - LDAP struct { + Information string + LDAP struct { Server struct { Host string `validate:"required,hostname"` Port uint `validate:"required,gt=0,lte=65535"` @@ -65,6 +67,11 @@ func ReadINI(configPath string, configPointer *Config) error { log.Error().Err(err).Msg("ReadINI") return err } + err = readContent(cfg, configPointer) + if err != nil { + log.Error().Err(err).Msg("ReadINI") + return err + } validate := validator.New() @@ -94,6 +101,15 @@ func readWebserver(cfg *ini.File, configPointer *Config) error { configPointer.Webserver.URL = cfg.Section("webserver").Key("url").String() configPointer.Webserver.ListenAddress = cfg.Section("webserver").Key("listen_address").String() configPointer.Webserver.PageTitlePrefix = cfg.Section("webserver").Key("page_title_prefix").String() + configPointer.Information = cfg.Section("content").Key("information").String() + + return err +} + +func readContent(cfg *ini.File, configPointer *Config) error { + err := error(nil) + + configPointer.Information = cfg.Section("content").Key("information").String() return err } diff --git a/webserver.go b/webserver.go index bca68a2..9e6361b 100644 --- a/webserver.go +++ b/webserver.go @@ -3,6 +3,7 @@ package main import ( _ "embed" "fmt" + "html/template" "net/http" "github.com/go-ldap/ldap" @@ -48,10 +49,11 @@ func serveFavicon(w http.ResponseWriter, r *http.Request) { func loginHandler(w http.ResponseWriter, r *http.Request) { // create context for template - ctx := make(map[string]string) + ctx := make(map[string]any) ctx["token"] = nosurf.Token(r) ctx["send_to"] = "/login" ctx["title_prefix"] = CConfig.Webserver.PageTitlePrefix + ctx["information"] = template.HTML(CConfig.Information) if r.Method == "POST" { if err := r.ParseForm(); err != nil {