mirror of
https://github.com/jech/galene.git
synced 2024-11-10 02:35:58 +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:
|
file may look as follows:
|
||||||
|
|
||||||
{
|
{
|
||||||
|
"canonicalHost: "galene.example.org",
|
||||||
"admin":[{"username":"root","password":"secret"}]
|
"admin":[{"username":"root","password":"secret"}]
|
||||||
}
|
}
|
||||||
|
|
||||||
The fields are as follows:
|
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
|
- `admin` defines the users allowed to look at the `/stats.html` file; it
|
||||||
has the same syntax as user definitions in groups (see below).
|
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(&httpAddr, "http", ":8443", "web server `address`")
|
||||||
flag.StringVar(&webserver.StaticRoot, "static", "./static/",
|
flag.StringVar(&webserver.StaticRoot, "static", "./static/",
|
||||||
"web server root `directory`")
|
"web server root `directory`")
|
||||||
flag.StringVar(&webserver.Redirect, "redirect", "",
|
|
||||||
"redirect to canonical `host`")
|
|
||||||
flag.BoolVar(&webserver.Insecure, "insecure", false,
|
flag.BoolVar(&webserver.Insecure, "insecure", false,
|
||||||
"act as an HTTP server rather than HTTPS")
|
"act as an HTTP server rather than HTTPS")
|
||||||
flag.StringVar(&group.DataDirectory, "data", "./data/",
|
flag.StringVar(&group.DataDirectory, "data", "./data/",
|
||||||
|
|
|
@ -809,6 +809,7 @@ type Configuration struct {
|
||||||
modTime time.Time `json:"-"`
|
modTime time.Time `json:"-"`
|
||||||
fileSize int64 `json:"-"`
|
fileSize int64 `json:"-"`
|
||||||
|
|
||||||
|
CanonicalHost string `json:"canonicalHost"`
|
||||||
Admin []ClientPattern `json:"admin"`
|
Admin []ClientPattern `json:"admin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,6 @@ var server atomic.Value
|
||||||
|
|
||||||
var StaticRoot string
|
var StaticRoot string
|
||||||
|
|
||||||
var Redirect string
|
|
||||||
|
|
||||||
var Insecure bool
|
var Insecure bool
|
||||||
|
|
||||||
func Serve(address string, dataDir string) error {
|
func Serve(address string, dataDir string) error {
|
||||||
|
@ -130,13 +128,14 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func redirect(w http.ResponseWriter, r *http.Request) bool {
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
u := url.URL{
|
u := url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
Host: Redirect,
|
Host: conf.CanonicalHost,
|
||||||
Path: r.URL.Path,
|
Path: r.URL.Path,
|
||||||
}
|
}
|
||||||
http.Redirect(w, r, u.String(), http.StatusMovedPermanently)
|
http.Redirect(w, r, u.String(), http.StatusMovedPermanently)
|
||||||
|
|
Loading…
Reference in a new issue