1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-12-26 01:05:48 +01:00

Move -redirect into the configuration file.

This commit is contained in:
Juliusz Chroboczek 2021-10-26 20:24:10 +02:00
parent c0b30c8557
commit 5e39c3a2a7
4 changed files with 7 additions and 7 deletions

2
README
View file

@ -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).

View file

@ -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/",

View file

@ -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 {

View file

@ -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)