Commit 5e39c3a2 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Move -redirect into the configuration file.

parent c0b30c85
......@@ -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).
......
......@@ -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/",
......
......@@ -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 {
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment