mirror of
https://github.com/jech/galene.git
synced 2024-11-08 17:55:59 +01:00
Move -redirect into the configuration file.
This commit is contained in:
parent
c0b30c8557
commit
5e39c3a2a7
4 changed files with 7 additions and 7 deletions
2
README
2
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).
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue