From 5e39c3a2a7b597f2333c3c8bcd35c9358267f312 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Tue, 26 Oct 2021 20:24:10 +0200 Subject: [PATCH] Move -redirect into the configuration file. --- README | 2 ++ galene.go | 2 -- group/group.go | 3 ++- webserver/webserver.go | 7 +++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README b/README index 66a5d4f..432cb83 100644 --- a/README +++ b/README @@ -43,11 +43,13 @@ The server may be configured in the JSON file `data/config.json`. This file may look as follows: { + "canonicalHost: "galene.example.org", "admin":[{"username":"root","password":"secret"}] } The fields are as follows: +- `canonicalHost`: the canonical name of the host running the server; - `admin` defines the users allowed to look at the `/stats.html` file; it has the same syntax as user definitions in groups (see below). diff --git a/galene.go b/galene.go index 033bf72..bb9c8bf 100644 --- a/galene.go +++ b/galene.go @@ -27,8 +27,6 @@ func main() { flag.StringVar(&httpAddr, "http", ":8443", "web server `address`") flag.StringVar(&webserver.StaticRoot, "static", "./static/", "web server root `directory`") - flag.StringVar(&webserver.Redirect, "redirect", "", - "redirect to canonical `host`") flag.BoolVar(&webserver.Insecure, "insecure", false, "act as an HTTP server rather than HTTPS") flag.StringVar(&group.DataDirectory, "data", "./data/", diff --git a/group/group.go b/group/group.go index 1c5800b..ee687ca 100644 --- a/group/group.go +++ b/group/group.go @@ -809,7 +809,8 @@ type Configuration struct { modTime time.Time `json:"-"` fileSize int64 `json:"-"` - Admin []ClientPattern `json:"admin"` + CanonicalHost string `json:"canonicalHost"` + Admin []ClientPattern `json:"admin"` } var configuration struct { diff --git a/webserver/webserver.go b/webserver/webserver.go index 7ed637c..da3bc08 100644 --- a/webserver/webserver.go +++ b/webserver/webserver.go @@ -32,8 +32,6 @@ var server atomic.Value var StaticRoot string -var Redirect string - var Insecure bool func Serve(address string, dataDir string) error { @@ -130,13 +128,14 @@ const ( ) func redirect(w http.ResponseWriter, r *http.Request) bool { - if Redirect == "" || strings.EqualFold(r.Host, Redirect) { + conf, err := group.GetConfiguration() + if err != nil || conf.CanonicalHost == "" { return false } u := url.URL{ Scheme: "https", - Host: Redirect, + Host: conf.CanonicalHost, Path: r.URL.Path, } http.Redirect(w, r, u.String(), http.StatusMovedPermanently)