-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
284 lines (265 loc) · 9.07 KB
/
init.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
package connect
import "encoding/json"
// InitGetHostname - Returns FQDN (fully qualified domain name) of the server (e.g. mail.companyname.com).
// Return
// hostname - name of the server
func (c *ServerConnection) InitGetHostname() (string, error) {
data, err := c.CallRaw("Init.getHostname", nil)
if err != nil {
return "", err
}
hostname := struct {
Result struct {
Hostname string `json:"hostname"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &hostname)
return hostname.Result.Hostname, err
}
// InitCheckHostname - Check existence of domain name in the DNS. Existence of DN record with type "A" in appropriate DNS zone.
// Parameters
// hostname - fully qualified domain name of the server
func (c *ServerConnection) InitCheckHostname(hostname string) error {
params := struct {
Hostname string `json:"hostname"`
}{hostname}
_, err := c.CallRaw("Init.checkHostname", params)
return err
}
// InitCheckMxRecord - Check existence of MX record in the DNS for specified domain.
// Parameters
// domainName - fully qualified domain name
func (c *ServerConnection) InitCheckMxRecord(domainName string) error {
params := struct {
DomainName string `json:"domainName"`
}{domainName}
_, err := c.CallRaw("Init.checkMxRecord", params)
return err
}
// InitSetHostname - Set Internet hostname of the server. This name is used for server identification in SMTP, POP3 and similar protocols.
// Parameters
// hostname - new fully qualified domain name of the server
func (c *ServerConnection) InitSetHostname(hostname string) error {
params := struct {
Hostname string `json:"hostname"`
}{hostname}
_, err := c.CallRaw("Init.setHostname", params)
return err
}
// InitGetDistributableDomains - Retrieve domains, which can be distributed, from the master server as a standalone server.
// Parameters
// authentication - Structure with a credential. Credential will be used when connected is false.
// Return
// domainNames - List of domains which can be distributed (they have a directory service set).
func (c *ServerConnection) InitGetDistributableDomains(authentication ClusterAuthentication) (StringList, error) {
params := struct {
Authentication ClusterAuthentication `json:"authentication"`
}{authentication}
data, err := c.CallRaw("Init.getDistributableDomains", params)
if err != nil {
return nil, err
}
domainNames := struct {
Result struct {
DomainNames StringList `json:"domainNames"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &domainNames)
return domainNames.Result.DomainNames, err
}
// InitCreateDistributableDomain - Connect server to cluster as slave and create distributable domain.
// Parameters
// domainName - domain which can be distributed (they have a directory service set) and exist on master server.
// authentication - Structure with a credential. Credential will be used when connected is false.
// Return
// result - if ClusterErrorType is not clSuccess, error argument contains additional error info
func (c *ServerConnection) InitCreateDistributableDomain(domainName string, authentication ClusterAuthentication) (*ClusterError, error) {
params := struct {
DomainName string `json:"domainName"`
Authentication ClusterAuthentication `json:"authentication"`
}{domainName, authentication}
data, err := c.CallRaw("Init.createDistributableDomain", params)
if err != nil {
return nil, err
}
result := struct {
Result struct {
Result ClusterError `json:"result"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &result)
return &result.Result.Result, err
}
// InitCreatePrimaryDomain - Creates the primary email domain.
// Parameters
// domainName - fully qualified name of the domain
func (c *ServerConnection) InitCreatePrimaryDomain(domainName string) error {
params := struct {
DomainName string `json:"domainName"`
}{domainName}
_, err := c.CallRaw("Init.createPrimaryDomain", params)
return err
}
// InitCreateAdministratorAccount - Creates the administrator account. This account will be created in primary domain.
// Parameters
// loginName - login name for administrator (without domain name)
// password - administrator password
func (c *ServerConnection) InitCreateAdministratorAccount(loginName string, password string) error {
params := struct {
LoginName string `json:"loginName"`
Password string `json:"password"`
}{loginName, password}
_, err := c.CallRaw("Init.createAdministratorAccount", params)
return err
}
// InitGetMessageStorePath - Get current path to message store. Default path is "store" subdirectory in installation directory.
// Return
// path - full path to message store directory
// freeSpace - amount of free space in the directory
func (c *ServerConnection) InitGetMessageStorePath() (string, int, error) {
data, err := c.CallRaw("Init.getMessageStorePath", nil)
if err != nil {
return "", 0, err
}
path := struct {
Result struct {
Path string `json:"path"`
FreeSpace int `json:"freeSpace"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &path)
return path.Result.Path, path.Result.FreeSpace, err
}
// InitSetMessageStorePath - Set path to message store directory.
// Parameters
// path - full path to message store directory
func (c *ServerConnection) InitSetMessageStorePath(path string) error {
params := struct {
Path string `json:"path"`
}{path}
_, err := c.CallRaw("Init.setMessageStorePath", params)
return err
}
// InitGetDirs - Obtain a list of directories in a particular path.
// Parameters
// fullPath - directory for listing, if full path is empty logical drives will be listed
// Return
// dirList - List of directories
func (c *ServerConnection) InitGetDirs(fullPath string) (DirectoryList, error) {
params := struct {
FullPath string `json:"fullPath"`
}{fullPath}
data, err := c.CallRaw("Init.getDirs", params)
if err != nil {
return nil, err
}
dirList := struct {
Result struct {
DirList DirectoryList `json:"dirList"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &dirList)
return dirList.Result.DirList, err
}
// InitCheckMessageStorePath - Check if message store path is correct and can be created in the file system.
// Parameters
// path - full path to message store directory
// Return
// result - result of the check
// freeSpace - amount of free space in the directory
func (c *ServerConnection) InitCheckMessageStorePath(path string) (*DirectoryAccessResult, int, error) {
params := struct {
Path string `json:"path"`
}{path}
data, err := c.CallRaw("Init.checkMessageStorePath", params)
if err != nil {
return nil, 0, err
}
result := struct {
Result struct {
Result DirectoryAccessResult `json:"result"`
FreeSpace int `json:"freeSpace"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &result)
return &result.Result.Result, result.Result.FreeSpace, err
}
// InitSetClientStatistics - Set client statistics settings.
// Parameters
// isEnabled - flag if statistics are enabled
func (c *ServerConnection) InitSetClientStatistics(isEnabled bool) error {
params := struct {
IsEnabled bool `json:"isEnabled"`
}{isEnabled}
_, err := c.CallRaw("Init.setClientStatistics", params)
return err
}
// InitFinish - Finish initial configuration of Kerio Connect.
func (c *ServerConnection) InitFinish() error {
_, err := c.CallRaw("Init.finish", nil)
return err
}
// InitGetNamedConstantList - Server side list of constants.
// Return
// constants - list of constants
func (c *ServerConnection) InitGetNamedConstantList() (NamedConstantList, error) {
data, err := c.CallRaw("Init.getNamedConstantList", nil)
if err != nil {
return nil, err
}
constants := struct {
Result struct {
Constants NamedConstantList `json:"constants"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &constants)
return constants.Result.Constants, err
}
// InitGetBrowserLanguages - Returns a list of user-preferred languages set in browser.
// Return
// calculatedLanguage - a list of 2-character language codes
func (c *ServerConnection) InitGetBrowserLanguages() (StringList, error) {
data, err := c.CallRaw("Init.getBrowserLanguages", nil)
if err != nil {
return nil, err
}
calculatedLanguage := struct {
Result struct {
CalculatedLanguage StringList `json:"calculatedLanguage"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &calculatedLanguage)
return calculatedLanguage.Result.CalculatedLanguage, err
}
// InitGetProductInfo - Get basic information about product and its version.
// Return
// info - structure with basic information about product
func (c *ServerConnection) InitGetProductInfo() (*ProductInfo, error) {
data, err := c.CallRaw("Init.getProductInfo", nil)
if err != nil {
return nil, err
}
info := struct {
Result struct {
Info ProductInfo `json:"info"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &info)
return &info.Result.Info, err
}
// InitGetEula - Obtain EULA.
// Return
// content - plain text of EULA
func (c *ServerConnection) InitGetEula() (string, error) {
data, err := c.CallRaw("Init.getEula", nil)
if err != nil {
return "", err
}
content := struct {
Result struct {
Content string `json:"content"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &content)
return content.Result.Content, err
}