From ce077f2efcc9298ec77efd5d9583ebd49d3a4c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferdinand=20M=C3=BCtsch?= Date: Sat, 4 Mar 2023 09:33:36 +0100 Subject: [PATCH] chore: ability to disable home page (resolve #460) --- README.md | 1 + config.default.yml | 1 + config/config.go | 7 ++++--- routes/home.go | 4 ++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8e65790..027c401 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ You can specify configuration options either via a config file (default: `config | `security.insecure_cookies` /
`WAKAPI_INSECURE_COOKIES` | `false` | Whether or not to allow cookies over HTTP | | `security.cookie_max_age` /
`WAKAPI_COOKIE_MAX_AGE` | `172800` | Lifetime of authentication cookies in seconds or `0` to use [Session](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Define_the_lifetime_of_a_cookie) cookies | | `security.allow_signup` /
`WAKAPI_ALLOW_SIGNUP` | `true` | Whether to enable user registration | +| `security.disable_frontpage` /
`WAKAPI_DISABLE_FRONTPAGE` | `false` | Whether to disable landing page (useful for personal instances) | | `security.expose_metrics` /
`WAKAPI_EXPOSE_METRICS` | `false` | Whether to expose Prometheus metrics under `/api/metrics` | | `db.host` /
`WAKAPI_DB_HOST` | - | Database host | | `db.port` /
`WAKAPI_DB_PORT` | - | Database port | diff --git a/config.default.yml b/config.default.yml index 6cab403..5f089fe 100644 --- a/config.default.yml +++ b/config.default.yml @@ -55,6 +55,7 @@ security: insecure_cookies: true # should be set to 'false', except when not running with HTTPS (e.g. on localhost) cookie_max_age: 172800 allow_signup: true + disable_frontpage: false expose_metrics: false enable_proxy: false # only intended for production instance at wakapi.dev diff --git a/config/config.go b/config/config.go index 3613d8c..c48f941 100644 --- a/config/config.go +++ b/config/config.go @@ -87,9 +87,10 @@ type appConfig struct { } type securityConfig struct { - AllowSignup bool `yaml:"allow_signup" default:"true" env:"WAKAPI_ALLOW_SIGNUP"` - ExposeMetrics bool `yaml:"expose_metrics" default:"false" env:"WAKAPI_EXPOSE_METRICS"` - EnableProxy bool `yaml:"enable_proxy" default:"false" env:"WAKAPI_ENABLE_PROXY"` // only intended for production instance at wakapi.dev + AllowSignup bool `yaml:"allow_signup" default:"true" env:"WAKAPI_ALLOW_SIGNUP"` + ExposeMetrics bool `yaml:"expose_metrics" default:"false" env:"WAKAPI_EXPOSE_METRICS"` + EnableProxy bool `yaml:"enable_proxy" default:"false" env:"WAKAPI_ENABLE_PROXY"` // only intended for production instance at wakapi.dev + DisableFrontpage bool `yaml:"disable_frontpage" default:"false" env:"WAKAPI_DISABLE_FRONTPAGE"` // this is actually a pepper (https://en.wikipedia.org/wiki/Pepper_(cryptography)) PasswordSalt string `yaml:"password_salt" default:"" env:"WAKAPI_PASSWORD_SALT"` InsecureCookies bool `yaml:"insecure_cookies" default:"false" env:"WAKAPI_INSECURE_COOKIES"` diff --git a/routes/home.go b/routes/home.go index 354fe2b..03df813 100644 --- a/routes/home.go +++ b/routes/home.go @@ -46,6 +46,10 @@ func (h *HomeHandler) GetIndex(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, fmt.Sprintf("%s/summary", h.config.Server.BasePath), http.StatusFound) return } + if h.config.Security.DisableFrontpage { + http.Redirect(w, r, fmt.Sprintf("%s/login", h.config.Server.BasePath), http.StatusFound) + return + } templates[conf.IndexTemplate].Execute(w, h.buildViewModel(r, w)) }