Skip to content

Commit

Permalink
Merge pull request #4 from bwInfoSec/add-notification
Browse files Browse the repository at this point in the history
Add notification banner
  • Loading branch information
stefanDeveloper authored Oct 11, 2023
2 parents c4a5d4f + bf51cb3 commit bc34b5d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions goldap.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="mailto:kernteam@urz.uni-heidelberg.de">kernteam@urz.uni-heidelberg.de</a>.
7 changes: 7 additions & 0 deletions html/templates/login_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,12 @@ <h3 class="my-3">Bitte melden Sie sich an, um Ihr Passwort zu ändern</h3>
</div>
</div>
</div>
{{ if .information }}
<div class="container py-5 h-100">
<div class="alert alert-warning text-center" role="alert">
{{ .information }}
</div>
</div>
{{ end }}
</body>
</html>
20 changes: 18 additions & 2 deletions parseini.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
_ "embed"
"fmt"
"html/template"
"net/http"

"github.com/go-ldap/ldap"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bc34b5d

Please sign in to comment.