Skip to content

Commit

Permalink
Reduce complexity of fetching help mail
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Jan 23, 2024
1 parent 7f98ea4 commit 1818f4d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
10 changes: 8 additions & 2 deletions internal/data/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,14 @@ func SetHelpMail(helpMail string) error {
return err
}

func GetHelpMail() (string, error) {
return getGeneric(helpMailKey)
func GetHelpMail() string {

mail, err := getGeneric(helpMailKey)
if err != nil {
return "Server Error"
}

return mail
}

func SetExternalAddress(externalAddress string) error {
Expand Down
5 changes: 1 addition & 4 deletions internal/webserver/authenticators/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ func resultMessage(err error) (string, int) {
return "Success", http.StatusOK
}

mail, err := data.GetHelpMail()
if err != nil {
mail = "Server Error"
}
mail := data.GetHelpMail()

msg := "Validation failed"
if strings.Contains(err.Error(), "account is locked") {
Expand Down
8 changes: 1 addition & 7 deletions internal/webserver/authenticators/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,8 @@ func (o *Oidc) AuthorisationAPI(w http.ResponseWriter, r *http.Request) {

w.WriteHeader(http.StatusUnauthorized)

mail, err := data.GetHelpMail()
if err != nil {
log.Println("Error getting help mail: ", err)
http.Error(w, "Server Error", http.StatusInternalServerError)
return
}
err = resources.Render("oidc_error.html", w, &resources.Msg{
HelpMail: mail,
HelpMail: data.GetHelpMail(),
NumMethods: NumberOfMethods(),
Message: msg,
URL: rp.GetEndSessionEndpoint(),
Expand Down
5 changes: 2 additions & 3 deletions internal/webserver/authenticators/pam.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"fmt"

"github.com/NHAS/wag/internal/config"
"github.com/NHAS/wag/internal/data"
"github.com/NHAS/wag/internal/router"
"github.com/NHAS/wag/internal/users"
Expand Down Expand Up @@ -184,7 +183,7 @@ func (t *Pam) AuthoriseFunc(w http.ResponseWriter, r *http.Request) types.Authen

func (t *Pam) MFAPromptUI(w http.ResponseWriter, r *http.Request, username, ip string) {
if err := resources.Render("prompt_mfa_pam.html", w, &resources.Msg{
HelpMail: config.Values().HelpMail,
HelpMail: data.GetHelpMail(),
NumMethods: NumberOfMethods(),
}); err != nil {
log.Println(username, ip, "unable to render pam prompt template: ", err)
Expand All @@ -193,7 +192,7 @@ func (t *Pam) MFAPromptUI(w http.ResponseWriter, r *http.Request, username, ip s

func (t *Pam) RegistrationUI(w http.ResponseWriter, r *http.Request, username, ip string) {
if err := resources.Render("register_mfa_pam.html", w, &resources.Msg{
HelpMail: config.Values().HelpMail,
HelpMail: data.GetHelpMail(),
NumMethods: NumberOfMethods(),
}); err != nil {
log.Println(username, ip, "unable to render pam mfa template: ", err)
Expand Down
16 changes: 12 additions & 4 deletions internal/webserver/authenticators/totp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"sync"
"time"

"github.com/NHAS/wag/internal/config"
"github.com/NHAS/wag/internal/data"
"github.com/NHAS/wag/internal/router"
"github.com/NHAS/wag/internal/users"
Expand Down Expand Up @@ -73,8 +72,15 @@ func (t *Totp) RegistrationAPI(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":

issuer, err := data.GetIssuer()
if err != nil {
log.Println(user.Username, clientTunnelIp, "unable to get issuer from datastore")

http.Error(w, "Bad request", 400)
return
}
key, err := totp.Generate(totp.GenerateOpts{
Issuer: config.Values().Authenticators.Issuer,
Issuer: issuer,
AccountName: user.Username,
})
if err != nil {
Expand Down Expand Up @@ -210,17 +216,19 @@ func (t *Totp) AuthoriseFunc(w http.ResponseWriter, r *http.Request) types.Authe
}

func (t *Totp) MFAPromptUI(w http.ResponseWriter, r *http.Request, username, ip string) {

if err := resources.Render("prompt_mfa_totp.html", w, &resources.Msg{
HelpMail: config.Values().HelpMail,
HelpMail: data.GetHelpMail(),
NumMethods: NumberOfMethods(),
}); err != nil {
log.Println(username, ip, "unable to render totp prompt template: ", err)
}
}

func (t *Totp) RegistrationUI(w http.ResponseWriter, r *http.Request, username, ip string) {

if err := resources.Render("register_mfa_totp.html", w, &resources.Msg{
HelpMail: config.Values().HelpMail,
HelpMail: data.GetHelpMail(),
NumMethods: NumberOfMethods(),
}); err != nil {
log.Println(username, ip, "unable to render totp mfa template: ", err)
Expand Down
5 changes: 2 additions & 3 deletions internal/webserver/authenticators/webauthn.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/NHAS/session"
"github.com/NHAS/wag/internal/config"
"github.com/NHAS/wag/internal/data"
"github.com/NHAS/wag/internal/router"
"github.com/NHAS/wag/internal/users"
Expand Down Expand Up @@ -284,7 +283,7 @@ func (wa *Webauthn) AuthorisationAPI(w http.ResponseWriter, r *http.Request) {
func (wa *Webauthn) MFAPromptUI(w http.ResponseWriter, r *http.Request, username, ip string) {

if err := resources.Render("prompt_mfa_webauthn.html", w, &resources.Msg{
HelpMail: config.Values().HelpMail,
HelpMail: data.GetHelpMail(),
NumMethods: NumberOfMethods(),
}); err != nil {
log.Println(username, ip, "unable to render weauthn prompt template: ", err)
Expand All @@ -294,7 +293,7 @@ func (wa *Webauthn) MFAPromptUI(w http.ResponseWriter, r *http.Request, username
func (wa *Webauthn) RegistrationUI(w http.ResponseWriter, r *http.Request, username, ip string) {

if err := resources.Render("register_mfa_webauthn.html", w, &resources.Msg{
HelpMail: config.Values().HelpMail,
HelpMail: data.GetHelpMail(),
NumMethods: NumberOfMethods(),
}); err != nil {
log.Println(username, ip, "unable to render weauthn prompt template: ", err)
Expand Down

0 comments on commit 1818f4d

Please sign in to comment.