Commit 90e2de0b authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Add configuration option publicServer.

parent bb0a0189
...@@ -74,6 +74,9 @@ The fields are as follows: ...@@ -74,6 +74,9 @@ The fields are as follows:
- `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).
- `publicServer`: if true, then cross-origin access to the server is
allowed. This is safe if the server is on the public Internet, but not
necessarily so if it is on a private network.
- `proxyURL`: if running behind a reverse proxy, this specifies the - `proxyURL`: if running behind a reverse proxy, this specifies the
address of the proxy. address of the proxy.
- `canonicalHost`: the canonical name of the host running the server; this - `canonicalHost`: the canonical name of the host running the server; this
......
...@@ -854,6 +854,7 @@ type Configuration struct { ...@@ -854,6 +854,7 @@ type Configuration struct {
modTime time.Time `json:"-"` modTime time.Time `json:"-"`
fileSize int64 `json:"-"` fileSize int64 `json:"-"`
PublicServer bool `json:"publicServer"`
CanonicalHost string `json:"canonicalHost"` CanonicalHost string `json:"canonicalHost"`
ProxyURL string `json:"proxyURL"` ProxyURL string `json:"proxyURL"`
Admin []ClientPattern `json:"admin"` Admin []ClientPattern `json:"admin"`
......
...@@ -479,8 +479,26 @@ var wsUpgrader = websocket.Upgrader{ ...@@ -479,8 +479,26 @@ var wsUpgrader = websocket.Upgrader{
HandshakeTimeout: 30 * time.Second, HandshakeTimeout: 30 * time.Second,
} }
var wsPublicUpgrader = websocket.Upgrader{
HandshakeTimeout: 30 * time.Second,
CheckOrigin: func(r *http.Request) bool {
return true
},
}
func wsHandler(w http.ResponseWriter, r *http.Request) { func wsHandler(w http.ResponseWriter, r *http.Request) {
conn, err := wsUpgrader.Upgrade(w, r, nil) conf, err := group.GetConfiguration()
if err != nil {
http.Error(w, "Internal server error",
http.StatusInternalServerError)
return
}
upgrader := wsUpgrader
if conf.PublicServer {
upgrader = wsPublicUpgrader
}
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil { if err != nil {
log.Printf("Websocket upgrade: %v", err) log.Printf("Websocket upgrade: %v", err)
return return
......
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