forked from pydio/cells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.libreoffice.go
109 lines (86 loc) · 2.44 KB
/
editor.libreoffice.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package modifiers
import (
"bytes"
"fmt"
"html/template"
"net/url"
"go.uber.org/zap"
"github.com/pydio/cells/common"
"github.com/pydio/cells/common/caddy"
"github.com/pydio/cells/common/config"
"github.com/pydio/cells/common/log"
"github.com/pydio/cells/common/plugins"
)
var (
editorLibreOfficeTemplate *template.Template
editorLibreOfficeTemplateStr = `
proxy /wopi/ {{.WOPI | urls}} {
transparent
}
proxy /loleaflet/ {{.Collabora.Scheme}}://{{.Collabora.Host}}/loleaflet {
transparent
insecure_skip_verify
without /loleaflet/
}
proxy /hosting/discovery {{.Collabora.Scheme}}://{{.Collabora.Host}}/hosting/discovery {
transparent
insecure_skip_verify
without /hosting/discovery
}
proxy /lool/ {{.Collabora.Scheme}}://{{.Collabora.Host}}/lool/ {
transparent
insecure_skip_verify
websocket
without /lool/
}
`
)
type EditorLibreOffice struct {
WOPI string
Collabora *url.URL
}
func init() {
plugins.Register(func() {
caddy.RegisterPluginTemplate(
caddy.TemplateFunc(play),
[]string{"frontend", "plugin", "editor.libreoffice"},
"/wopi/",
"/loleaflet/",
"/hosting/discovery",
"/lool/",
)
tmpl, err := template.New("caddyfile").Funcs(caddy.FuncMap).Parse(editorLibreOfficeTemplateStr)
if err != nil {
log.Fatal("Could not read template ", zap.Error(err))
}
editorLibreOfficeTemplate = tmpl
})
}
func play() (*bytes.Buffer, error) {
e := new(EditorLibreOffice)
e.WOPI = common.SERVICE_GATEWAY_WOPI
if err := getCollaboraConfig(&e.Collabora); err != nil {
log.Error("could not retrieve collabora config", zap.Any("error ", err))
return nil, err
}
buf := bytes.NewBuffer([]byte{})
if err := editorLibreOfficeTemplate.Execute(buf, e); err != nil {
return nil, err
}
return buf, nil
}
func getCollaboraConfig(collabora **url.URL) error {
tls := config.Get("frontend", "plugin", "editor.libreoffice", "LIBREOFFICE_SSL").Bool(true)
host := config.Get("frontend", "plugin", "editor.libreoffice", "LIBREOFFICE_HOST").String("localhost")
port := config.Get("frontend", "plugin", "editor.libreoffice", "LIBREOFFICE_PORT").String("9980")
scheme := "http"
if tls {
scheme = "https"
}
u, err := url.Parse(fmt.Sprintf("%s://%s:%s", scheme, host, port))
if err != nil {
return err
}
*collabora = u
return nil
}