1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-09 18:25:58 +01:00

Add configuration option publicServer.

This commit is contained in:
Juliusz Chroboczek 2023-07-10 20:40:42 +02:00
parent bb0a01895e
commit 90e2de0b2d
3 changed files with 23 additions and 1 deletions

3
README
View file

@ -74,6 +74,9 @@ The fields are as follows:
- `admin` defines the users allowed to look at the `/stats.html` file; it
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
address of the proxy.
- `canonicalHost`: the canonical name of the host running the server; this

View file

@ -854,6 +854,7 @@ type Configuration struct {
modTime time.Time `json:"-"`
fileSize int64 `json:"-"`
PublicServer bool `json:"publicServer"`
CanonicalHost string `json:"canonicalHost"`
ProxyURL string `json:"proxyURL"`
Admin []ClientPattern `json:"admin"`

View file

@ -479,8 +479,26 @@ var wsUpgrader = websocket.Upgrader{
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) {
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 {
log.Printf("Websocket upgrade: %v", err)
return