forked from pydio/cells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootconf.go
159 lines (141 loc) · 5.49 KB
/
bootconf.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package frontend
import (
"context"
"crypto/md5"
"encoding/hex"
"strconv"
"strings"
"github.com/micro/go-config/reader"
"github.com/pborman/uuid"
"go.uber.org/zap"
"github.com/pydio/cells/common"
"github.com/pydio/cells/common/config"
"github.com/pydio/cells/common/log"
"github.com/pydio/cells/common/utils/i18n"
)
type BackendConf struct {
BuildRevision string
BuildStamp string
License string
PackageLabel string
PackageType string
Version string
}
type CustomWording struct {
Title string `json:"title"`
Icon string `json:"icon"`
IconBinary string `json:"iconBinary"`
}
type BootConf struct {
AjxpResourcesFolder string `json:"ajxpResourcesFolder"`
ENDPOINT_REST_API string
ENDPOINT_S3_GATEWAY string
ENDPOINT_WEBSOCKET string
FRONTEND_URL string
PUBLIC_BASEURI string
ZipEnabled bool `json:"zipEnabled"`
MultipleFilesDownloadEnabled bool `json:"multipleFilesDownloadEnabled"`
CustomWording CustomWording `json:"customWording"`
UsersEnabled bool `json:"usersEnabled"`
LoggedUser bool `json:"loggedUser"`
CurrentLanguage string `json:"currentLanguage"`
Session_timeout int `json:"session_timeout"`
Client_timeout int `json:"client_timeout"`
Client_timeout_warning int `json:"client_timeout_warning"`
AvailableLanguages map[string]string `json:"availableLanguages"`
UsersEditable bool `json:"usersEditable"`
AjxpVersion string `json:"ajxpVersion"`
AjxpVersionDate string `json:"ajxpVersionDate"`
I18nMessages map[string]string `json:"i18nMessages"`
Theme string `json:"theme"`
AjxpImagesCommon bool `json:"ajxpImagesCommon"`
ValidMailer bool `json:"validMailer"`
Backend BackendConf `json:"backend"`
Other map[string]interface{} `json:"other,omitempty"`
}
var versionHash string
func VersionHash() string {
if versionHash != "" {
return versionHash
}
// Create version seed
vSeed := config.Get("frontend", "versionSeed").String("")
if vSeed == "" {
vSeed = uuid.New()
config.Set(vSeed, "frontend", "versionSeed")
config.Save(common.PYDIO_SYSTEM_USERNAME, "Generating version seed")
}
md := md5.New()
md.Write([]byte(vSeed + common.Version().String()))
versionHash = hex.EncodeToString(md.Sum(nil))
return versionHash
}
func numberFromIntOrString(value reader.Value, def int) int {
intVal := def
if value.Int(-1) != -1 {
intVal = value.Int(def)
} else if value.String("") != "" {
if parsed, e := strconv.ParseInt(value.String(""), 10, 32); e == nil {
intVal = int(parsed)
}
}
return intVal
}
func ComputeBootConf(pool *PluginsPool, showVersion ...bool) *BootConf {
url := config.Get("defaults", "url").String("")
wsUrl := strings.Replace(strings.Replace(url, "https", "wss", -1), "http", "ws", -1)
lang := config.Get("frontend", "plugin", "core.pydio", "DEFAULT_LANGUAGE").String("en-us")
clientSession := numberFromIntOrString(config.Get("frontend", "plugin", "gui.ajax", "CLIENT_TIMEOUT"), 24)
timeoutWarn := numberFromIntOrString(config.Get("frontend", "plugin", "gui.ajax", "CLIENT_TIMEOUT_WARN"), 3)
vHash := VersionHash()
vDate := ""
vRev := ""
if len(showVersion) > 0 && showVersion[0] {
vHash = common.Version().String()
vDate = common.BuildStamp
vRev = common.BuildRevision
}
b := &BootConf{
AjxpResourcesFolder: "plug/gui.ajax/res",
ENDPOINT_REST_API: url + "/a",
ENDPOINT_S3_GATEWAY: url + "/io",
ENDPOINT_WEBSOCKET: wsUrl + "/ws/event",
FRONTEND_URL: url,
PUBLIC_BASEURI: "/public",
ZipEnabled: true,
MultipleFilesDownloadEnabled: true,
UsersEditable: true,
UsersEnabled: true,
LoggedUser: false,
CurrentLanguage: lang,
Session_timeout: SessionTimeoutMinutes * 60,
Client_timeout: clientSession * 60,
Client_timeout_warning: timeoutWarn,
AjxpVersion: vHash,
AjxpVersionDate: vDate,
ValidMailer: config.Get("services", "pydio.grpc.mailer", "valid").Bool(false),
Theme: "material",
AjxpImagesCommon: true,
CustomWording: CustomWording{
Title: config.Get("frontend", "plugin", "core.pydio", "APPLICATION_TITLE").String("Pydio Cells"),
Icon: "plug/gui.ajax/res/themes/common/images/LoginBoxLogo.png",
},
AvailableLanguages: i18n.AvailableLanguages,
I18nMessages: pool.I18nMessages(lang).Messages,
Backend: BackendConf{
PackageType: common.PackageType,
PackageLabel: common.PackageLabel,
Version: vHash,
BuildRevision: vRev,
BuildStamp: vDate,
License: "agplv3",
},
}
if icBinary := config.Get("frontend", "plugin", "gui.ajax", "CUSTOM_ICON_BINARY").String(""); icBinary != "" {
b.CustomWording.IconBinary = icBinary
}
if e := ApplyBootConfModifiers(b); e != nil {
log.Logger(context.Background()).Error("Error while applying BootConf modifiers", zap.Error(e))
}
return b
}