diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 6eea2815..5c1992a8 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -2,24 +2,33 @@ version: '2' services: app: container_name: filestash - image: machines/filestash + image: machines/filestash:latest restart: always environment: - - APPLICATION_URL= - - GDRIVE_CLIENT_ID= - - GDRIVE_CLIENT_SECRET= - - DROPBOX_CLIENT_ID= - - ONLYOFFICE_URL=http://onlyoffice + - APPLICATION_URL=127.0.0.1:8334 - CANARY=true + - OFFICE_URL=http://127.0.0.1:9980 + - OFFICE_FILESTASH_URL=http://app:8334 ports: - "8334:8334" volumes: - filestash:/app/data/state/ - onlyoffice: - container_name: filestash_oods - image: onlyoffice/documentserver:7.1 + wopi_server: + container_name: filestash_wopi + image: collabora/code:24.04.10.2.1 restart: always + environment: + - "extra_params=--o:ssl.enable=false" + command: + - /bin/bash + - -c + - | + curl -o /usr/share/coolwsd/browser/dist/branding-desktop.css https://gist.githubusercontent.com/mickael-kerjean/bc1f57cd312cf04731d30185cc4e7ba2/raw/d706dcdf23c21441e5af289d871b33defc2770ea/destop.css + /bin/su -s /bin/bash -c '/start-collabora-online.sh' cool + user: root + ports: + - "9980:9980" volumes: filestash: {} \ No newline at end of file diff --git a/server/plugin/index.go b/server/plugin/index.go index d2d2f026..076004ae 100644 --- a/server/plugin/index.go +++ b/server/plugin/index.go @@ -26,7 +26,6 @@ import ( _ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_storj" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_tmp" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_webdav" - _ "github.com/mickael-kerjean/filestash/server/plugin/plg_editor_onlyoffice" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_editor_wopi" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_handler_console" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_image_ascii" diff --git a/server/plugin/plg_editor_wopi/config.go b/server/plugin/plg_editor_wopi/config.go index d33a538e..5c18f787 100644 --- a/server/plugin/plg_editor_wopi/config.go +++ b/server/plugin/plg_editor_wopi/config.go @@ -14,7 +14,7 @@ func plugin_enable() bool { } f.Name = "enable" f.Type = "enable" - f.Target = []string{"office_server"} + f.Target = []string{"office_server", "filestash_server", "rewrite_discovery_url"} f.Description = "Enable/Disable the wopi office suite and options to manage word, excel and powerpoint documents." f.Default = false if u := os.Getenv("OFFICE_URL"); u != "" { @@ -42,3 +42,41 @@ func server_url() string { return f }).String() } + +func origin() string { + return Config.Get("features.office.filestash_server").Schema(func(f *FormElement) *FormElement { + if f == nil { + f = &FormElement{} + } + f.Id = "filestash_server" + f.Name = "filestash_server" + f.Type = "text" + f.Description = "Location of your Filestash server from the point of view of the office server. Keep blank if you don't use fancy networking via docker/k8s,..." + f.Default = "http://app:8334" + f.Placeholder = "Eg: http://app:8334" + if u := os.Getenv("OFFICE_FILESTASH_URL"); u != "" { + f.Default = u + f.Placeholder = fmt.Sprintf("Default: '%s'", u) + } + return f + }).String() +} + +func rewrite_url() string { + return Config.Get("features.office.rewrite_discovery_url").Schema(func(f *FormElement) *FormElement { + if f == nil { + f = &FormElement{} + } + f.Id = "rewrite_discovery_url" + f.Name = "rewrite_discovery_url" + f.Type = "text" + f.Description = "Rewrite the discovery URL to something else. Typical example is a deployment via docker where your office server resolve via http://wopi_service:9980 but such URL would be unknown when given to a browser. Keep empty if you're not doing a docker / k8s deployment" + f.Default = "" + f.Placeholder = "Eg: http://localhost:9980" + if u := os.Getenv("OFFICE_REWRITE_URL"); u != "" { + f.Default = u + f.Placeholder = fmt.Sprintf("Default: '%s'", u) + } + return f + }).String() +} diff --git a/server/plugin/plg_editor_wopi/handler.go b/server/plugin/plg_editor_wopi/handler.go index 34b367b0..b153ef6e 100644 --- a/server/plugin/plg_editor_wopi/handler.go +++ b/server/plugin/plg_editor_wopi/handler.go @@ -43,7 +43,11 @@ var WOPIOverrides = ` ` func WOPIHandler_CheckFileInfo(w http.ResponseWriter, r *http.Request) { - WOPIExecute(w, r)(func(ctx *App, fullpath string) { + if plugin_enable() == false { + SendErrorResult(w, ErrNotFound) + return + } + WOPIExecute(w, r)(func(ctx *App, fullpath string, w http.ResponseWriter) { w.Header().Set("Content-Type", "application/json") if err := json.NewEncoder(w).Encode(map[string]any{ "BaseFileName": filepath.Base(fullpath), @@ -59,7 +63,7 @@ func WOPIHandler_CheckFileInfo(w http.ResponseWriter, r *http.Request) { } func WOPIHandler_GetFile(w http.ResponseWriter, r *http.Request) { - WOPIExecute(w, r)(func(ctx *App, fullpath string) { + WOPIExecute(w, r)(func(ctx *App, fullpath string, w http.ResponseWriter) { f, err := ctx.Backend.Cat(fullpath) if err != nil { SendErrorResult(w, err) @@ -71,7 +75,7 @@ func WOPIHandler_GetFile(w http.ResponseWriter, r *http.Request) { func WOPIHandler_PutFile(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() - WOPIExecute(w, r)(func(ctx *App, fullpath string) { + WOPIExecute(w, r)(func(ctx *App, fullpath string, w http.ResponseWriter) { err := ctx.Backend.Save(fullpath, r.Body) if err != nil { SendErrorResult(w, err) @@ -81,8 +85,8 @@ func WOPIHandler_PutFile(w http.ResponseWriter, r *http.Request) { }) } -func WOPIExecute(w http.ResponseWriter, r *http.Request) func(func(*App, string)) { - return func(fn func(*App, string)) { +func WOPIExecute(w http.ResponseWriter, r *http.Request) func(func(*App, string, http.ResponseWriter)) { + return func(fn func(*App, string, http.ResponseWriter)) { path64 := mux.Vars(r)["path64"] p, err := base64.StdEncoding.DecodeString(path64) if err != nil { @@ -91,7 +95,7 @@ func WOPIExecute(w http.ResponseWriter, r *http.Request) func(func(*App, string) } middleware.NewMiddlewareChain( func(ctx *App, w http.ResponseWriter, r *http.Request) { - fn(ctx, string(p)) + fn(ctx, string(p), w) }, []Middleware{middleware.SessionStart}, App{}, @@ -206,14 +210,23 @@ func wopiDiscovery(ctx *App, fullpath string) (string, error) { if err != nil { return "", err } - myURL := "http://" - if Config.Get("general.force_ssl").Bool() { - myURL = "https://" + myURL := origin() + if myURL == "" { + myURL := "http://" + if Config.Get("general.force_ssl").Bool() { + myURL = "https://" + } + myURL += Config.Get("general.host").String() } - myURL += Config.Get("general.host").String() p := u.Query() p.Set("WOPISrc", myURL+"/api/wopi/files/"+base64.StdEncoding.EncodeToString([]byte(fullpath))) p.Set("access_token", ctx.Authorization) u.RawQuery = p.Encode() + if newHost := rewrite_url(); newHost != "" { + if p, err := url.Parse(newHost); err == nil { + u.Host = p.Host + u.Scheme = p.Scheme + } + } return u.String(), nil } diff --git a/server/plugin/plg_editor_wopi/index.go b/server/plugin/plg_editor_wopi/index.go index f4bd2bc6..579befee 100644 --- a/server/plugin/plg_editor_wopi/index.go +++ b/server/plugin/plg_editor_wopi/index.go @@ -5,11 +5,13 @@ import ( ) func init() { - Hooks.Register.HttpEndpoint(WOPIRoutes) - Hooks.Register.XDGOpen(WOPIOverrides) - Hooks.Register.Onload(func() { - plugin_enable() server_url() + origin() + rewrite_url() + if plugin_enable() { + Hooks.Register.XDGOpen(WOPIOverrides) + } }) + Hooks.Register.HttpEndpoint(WOPIRoutes) }