@brickert/kerio-connect-api 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +143 -1
- package/package.json +1 -1
- package/src/domains.js +207 -0
- package/src/kerio.js +4 -2
- package/src/logs.js +3 -3
- package/src/users.js +208 -0
package/index.d.ts
CHANGED
|
@@ -74,7 +74,7 @@ export interface GenericResponse {
|
|
|
74
74
|
result?: {
|
|
75
75
|
viewport?: Array;
|
|
76
76
|
userDetails?: object;
|
|
77
|
-
list?: Array
|
|
77
|
+
list?: Array;
|
|
78
78
|
totalItems?: number;
|
|
79
79
|
errors?: Array<{
|
|
80
80
|
code: number,
|
|
@@ -82,6 +82,7 @@ export interface GenericResponse {
|
|
|
82
82
|
}>;
|
|
83
83
|
result?: Array;
|
|
84
84
|
token?: string;
|
|
85
|
+
detail?: string;
|
|
85
86
|
}
|
|
86
87
|
};
|
|
87
88
|
}
|
|
@@ -106,6 +107,8 @@ export class Kerio extends WebClient {
|
|
|
106
107
|
IPAddressGroups: IPAddressGroup;
|
|
107
108
|
Session: Session;
|
|
108
109
|
Logs: Logs;
|
|
110
|
+
Domains: Domains;
|
|
111
|
+
Users: Users;
|
|
109
112
|
|
|
110
113
|
login(user: KerioUser): void;
|
|
111
114
|
|
|
@@ -262,4 +265,143 @@ export type logName = "config" | "debug" | "error" | "mail" | "security" | "spam
|
|
|
262
265
|
export interface LogLineObject {
|
|
263
266
|
timestamp: string;
|
|
264
267
|
message: string;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export class Domains extends KerioModules {
|
|
271
|
+
/**
|
|
272
|
+
* Get a Mapped Array of KerioDomainItems indexed by their ID
|
|
273
|
+
* @returns {Promise<Map<import('../index.d.ts').KerioDomainID, import('../index.d.ts').KerioDomainItem>>}
|
|
274
|
+
*/
|
|
275
|
+
list(): Promise<Map<KerioDomainID, KerioDomainItem>>;
|
|
276
|
+
/**
|
|
277
|
+
* Get the DKIM DNS TXT record object for the domain name. TXT record name & value pair, selector name, and raw public key string.
|
|
278
|
+
* @param {string} domainName Name of the domain
|
|
279
|
+
* @returns {Promise<import('../index.d.ts').DKIMRecord>}
|
|
280
|
+
*/
|
|
281
|
+
getDKIMDNSRecord(domainName: string): Promise<DKIMRecord>;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* @example "keriodb://domain/1234-5678-901-2345"
|
|
286
|
+
*/
|
|
287
|
+
export type KerioDomainID = string;
|
|
288
|
+
|
|
289
|
+
export interface KerioDomainItem {
|
|
290
|
+
id: KerioDomainID;
|
|
291
|
+
name: string;
|
|
292
|
+
description: string;
|
|
293
|
+
primary: boolean;
|
|
294
|
+
userMaxCount: number;
|
|
295
|
+
passwords: {
|
|
296
|
+
expiration: {
|
|
297
|
+
enabled: boolean;
|
|
298
|
+
days: number;
|
|
299
|
+
};
|
|
300
|
+
historyCount: number;
|
|
301
|
+
enforceComplexity: boolean;
|
|
302
|
+
minLength: number;
|
|
303
|
+
};
|
|
304
|
+
messages: {
|
|
305
|
+
outgoingLimit: {
|
|
306
|
+
enabled: boolean,
|
|
307
|
+
size: number;
|
|
308
|
+
units: string;
|
|
309
|
+
};
|
|
310
|
+
autoClean: {
|
|
311
|
+
deleted: {
|
|
312
|
+
enabled: boolean;
|
|
313
|
+
days: number;
|
|
314
|
+
};
|
|
315
|
+
junk: {
|
|
316
|
+
enabled: boolean;
|
|
317
|
+
days: number;
|
|
318
|
+
};
|
|
319
|
+
sent: {
|
|
320
|
+
enabled: boolean;
|
|
321
|
+
days: number;
|
|
322
|
+
};
|
|
323
|
+
other: {
|
|
324
|
+
enabled: boolean;
|
|
325
|
+
days: number;
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
deleteRecovery: {
|
|
329
|
+
enabled: boolean;
|
|
330
|
+
days: number;
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
DKIMenabled: boolean;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export interface DKIMRecord {
|
|
337
|
+
/**
|
|
338
|
+
* @example 'mail._domainkey.example.org'
|
|
339
|
+
*/
|
|
340
|
+
name: string;
|
|
341
|
+
selector: string;
|
|
342
|
+
type: "TXT";
|
|
343
|
+
/**
|
|
344
|
+
* @example 'v=DKIM1; p=1234'
|
|
345
|
+
*/
|
|
346
|
+
value: string;
|
|
347
|
+
/**
|
|
348
|
+
* The 'p=' section of the TXT record value
|
|
349
|
+
* @example 'abcdefg1234567'
|
|
350
|
+
*/
|
|
351
|
+
raw_public_key: string;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export class Users extends KerioModules {
|
|
355
|
+
/**
|
|
356
|
+
* Get a Mapped Array of KerioUserItems indexed by their ID for the specified domain name
|
|
357
|
+
* @param {string} domainName Name of the domain
|
|
358
|
+
* @returns {Promise<Map<import('../index.d.ts').KerioUserID, import('../index.d.ts').KerioUserItem>>}
|
|
359
|
+
*/
|
|
360
|
+
list(domainName: string): Promise<Map<KerioUserID, KerioUserItem>>;
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Get statistics of the Kerio User. Such as mailbox size and last login timestamp in server's local time zone
|
|
364
|
+
* @param kerioUserID Kerio user UUID
|
|
365
|
+
*/
|
|
366
|
+
getStatistics(kerioUserID: KerioUserID): Promise<KerioUserStatistic>;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* @example "keriodb://user/1234-5678-901-2345/1234-5678-901"
|
|
371
|
+
*/
|
|
372
|
+
export type KerioUserID = string;
|
|
373
|
+
|
|
374
|
+
export interface KerioUserItem {
|
|
375
|
+
id: string;
|
|
376
|
+
domainId: string;
|
|
377
|
+
loginName: string;
|
|
378
|
+
fullName: string;
|
|
379
|
+
description: string;
|
|
380
|
+
enabled: boolean;
|
|
381
|
+
primaryEmailAddress: string; //loginName + domainName;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export interface KerioUserStatistic {
|
|
385
|
+
storage: {
|
|
386
|
+
items: number;
|
|
387
|
+
value: number;
|
|
388
|
+
units: "Bytes" | string;
|
|
389
|
+
},
|
|
390
|
+
lastLogin: string; //YYYY-MM-DD HH:MM in local server time
|
|
391
|
+
loginCount: {
|
|
392
|
+
pop3: number;
|
|
393
|
+
pop3s: number;
|
|
394
|
+
imap: number;
|
|
395
|
+
imaps: number;
|
|
396
|
+
http: number;
|
|
397
|
+
https: number;
|
|
398
|
+
ldap: number;
|
|
399
|
+
ldaps: number;
|
|
400
|
+
nntp: number;
|
|
401
|
+
nntps: number;
|
|
402
|
+
activeSync: number;
|
|
403
|
+
secureActiveSync: number;
|
|
404
|
+
xmpp: number;
|
|
405
|
+
xmpps: number;
|
|
406
|
+
}
|
|
265
407
|
}
|
package/package.json
CHANGED
package/src/domains.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { KerioModules } from './modules.js';
|
|
2
|
+
|
|
3
|
+
export class Domains extends KerioModules {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get a Mapped Array of KerioDomainItems indexed by their ID
|
|
7
|
+
* @returns {Promise<Map<import('../index.d.ts').KerioDomainID, import('../index.d.ts').KerioDomainItem>>}
|
|
8
|
+
*/
|
|
9
|
+
async list() {
|
|
10
|
+
try {
|
|
11
|
+
if (!this.instance.logged_in) {
|
|
12
|
+
|
|
13
|
+
this.reset();
|
|
14
|
+
|
|
15
|
+
throw {
|
|
16
|
+
name: "KerioClientSessionError",
|
|
17
|
+
message: `Kerio session invalid. Try logging in again.`,
|
|
18
|
+
type: 'Kerio',
|
|
19
|
+
from: "Kerio.Domains.list"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let domain_list_response = await this.sessionedRequest({
|
|
24
|
+
http_method: 'POST',
|
|
25
|
+
api_method: 'Domains.get',
|
|
26
|
+
auth: {
|
|
27
|
+
cookie: this.instance.session_cookie,
|
|
28
|
+
token: this.instance.x_token
|
|
29
|
+
},
|
|
30
|
+
body_params: {
|
|
31
|
+
query: {
|
|
32
|
+
orderBy: [
|
|
33
|
+
{
|
|
34
|
+
columnName: "name",
|
|
35
|
+
direction: "Asc"
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
let response_body = domain_list_response._body;
|
|
43
|
+
|
|
44
|
+
if (!response_body.result?.errors && !response_body?.error) {
|
|
45
|
+
|
|
46
|
+
var domainsListResult = new Map();
|
|
47
|
+
|
|
48
|
+
if (response_body.result.list.length > 0) {
|
|
49
|
+
|
|
50
|
+
response_body.result.list.forEach(domain => {
|
|
51
|
+
/**
|
|
52
|
+
* @type {import('../index.d.ts').KerioDomainItem}
|
|
53
|
+
*/
|
|
54
|
+
var obj = {
|
|
55
|
+
id: domain.id,
|
|
56
|
+
name: domain.name,
|
|
57
|
+
description: domain.description,
|
|
58
|
+
primary: domain.isPrimary,
|
|
59
|
+
userMaxCount: domain.userMaxCount,
|
|
60
|
+
passwords: {
|
|
61
|
+
expiration: {
|
|
62
|
+
enabled: domain.passwordExpirationEnabled,
|
|
63
|
+
days: domain.passwordExpirationEnabled
|
|
64
|
+
},
|
|
65
|
+
historyCount: domain.passwordHistoryCount,
|
|
66
|
+
enforceComplexity: domain.passwordComplexityEnabled,
|
|
67
|
+
minLength: domain.passwordMinimumLength
|
|
68
|
+
},
|
|
69
|
+
messages: {
|
|
70
|
+
outgoingLimit: {
|
|
71
|
+
enabled: domain.outgoingMessageLimit.isActive,
|
|
72
|
+
size: domain.outgoingMessageLimit.limit.value,
|
|
73
|
+
units: domain.outgoingMessageLimit.limit.units
|
|
74
|
+
},
|
|
75
|
+
autoClean: {
|
|
76
|
+
deleted: {
|
|
77
|
+
enabled: domain.deletedItems.isEnabled,
|
|
78
|
+
days: domain.deletedItems.days
|
|
79
|
+
},
|
|
80
|
+
junk: {
|
|
81
|
+
enabled: domain.junkEmail.isEnabled,
|
|
82
|
+
days: domain.junkEmail.days
|
|
83
|
+
},
|
|
84
|
+
sent: {
|
|
85
|
+
enabled: domain.sentItems.isEnabled,
|
|
86
|
+
days: domain.sentItems.days
|
|
87
|
+
},
|
|
88
|
+
other: {
|
|
89
|
+
enabled: domain.autoDelete.isEnabled,
|
|
90
|
+
days: domain.autoDelete.days
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
deleteRecovery: {
|
|
94
|
+
enabled: domain.keepForRecovery.isEnabled,
|
|
95
|
+
days: domain.keepForRecovery.days
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
DKIMenabled: domain.isDkimEnabled
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
domainsListResult.set(domain.id, obj);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
this.instance.logger.debug({
|
|
106
|
+
name: "KerioDomainsList",
|
|
107
|
+
message: `listed ${domainsListResult.size} domains entities`,
|
|
108
|
+
type: 'Kerio',
|
|
109
|
+
from: "Kerio.Domains.list"
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return domainsListResult;
|
|
113
|
+
|
|
114
|
+
} else {
|
|
115
|
+
throw {
|
|
116
|
+
name: "KerioRequestError",
|
|
117
|
+
message: `Error occured while fetching results from API method 'Domains.get' for all domains`,
|
|
118
|
+
type: 'Kerio',
|
|
119
|
+
from: "Kerio.Domains.list"
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
} catch (e) {
|
|
124
|
+
this.instance.logger.error(e);
|
|
125
|
+
throw e;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Get the DKIM DNS TXT record object for the domain name. TXT record name & value pair, selector name, and raw public key string.
|
|
131
|
+
* @param {string} domainName Name of the domain
|
|
132
|
+
* @returns {Promise<import('../index.d.ts').DKIMRecord>}
|
|
133
|
+
*/
|
|
134
|
+
async getDKIMDNSRecord(domainName = null) {
|
|
135
|
+
try {
|
|
136
|
+
|
|
137
|
+
if (!this.instance.logged_in) {
|
|
138
|
+
|
|
139
|
+
this.reset();
|
|
140
|
+
|
|
141
|
+
throw {
|
|
142
|
+
name: "KerioClientSessionError",
|
|
143
|
+
message: `Kerio session invalid. Try logging in again.`,
|
|
144
|
+
type: 'Kerio',
|
|
145
|
+
from: "Kerio.Domains.getDKIMDNSRecord"
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (!domainName) {
|
|
150
|
+
throw {
|
|
151
|
+
name: "KerioDKIMDomainNameError",
|
|
152
|
+
message: `Invalid Domain Name while processing API method 'Domains.getDkimDnsRecord' for domain '${domainName}'`,
|
|
153
|
+
type: 'Kerio',
|
|
154
|
+
from: "Kerio.Domains.getDKIMDNSRecord"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let dkim_record_response = await this.sessionedRequest({
|
|
159
|
+
http_method: 'POST',
|
|
160
|
+
api_method: 'Domains.getDkimDnsRecord',
|
|
161
|
+
auth: {
|
|
162
|
+
cookie: this.instance.session_cookie,
|
|
163
|
+
token: this.instance.x_token
|
|
164
|
+
},
|
|
165
|
+
body_params: {
|
|
166
|
+
domain: domainName
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
let response_body = dkim_record_response._body;
|
|
171
|
+
|
|
172
|
+
if (!response_body.result?.errors && !response_body?.error) {
|
|
173
|
+
|
|
174
|
+
let _record = response_body.result.detail;
|
|
175
|
+
let name = _record.split("\n")[0].split(":")[1].trim();
|
|
176
|
+
let value = _record.split("\n")[1].split("value:")[1].trim().split(";").join("; ");
|
|
177
|
+
let raw_key = value.split("; p=")[1];
|
|
178
|
+
|
|
179
|
+
this.instance.logger.debug({
|
|
180
|
+
name: "KerioDKIMDomainRecord",
|
|
181
|
+
message: `A DKIM record was obtained. Excerpt of: ${raw_key.substring(0, 10)}`,
|
|
182
|
+
type: "Kerio",
|
|
183
|
+
from: "Kerio.Domains.getDKIMDNSRecord"
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
name,
|
|
188
|
+
selector: name.split(".")[0],
|
|
189
|
+
type: "TXT",
|
|
190
|
+
value,
|
|
191
|
+
raw_public_key: raw_key
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
} else {
|
|
195
|
+
throw {
|
|
196
|
+
name: "KerioRequestError",
|
|
197
|
+
message: `Error occured while fetching results from API method 'Domains.getDkimDnsRecord' for domain '${domainName}'`,
|
|
198
|
+
type: 'Kerio',
|
|
199
|
+
from: "Kerio.Domains.getDKIMDNSRecord"
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} catch (e) {
|
|
203
|
+
this.instance.logger.error(e);
|
|
204
|
+
throw e;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
package/src/kerio.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { IPAddressGroup } from "./ipaddressgroups.js";
|
|
2
2
|
import { Logs } from "./logs.js";
|
|
3
3
|
import { Session } from "./session.js";
|
|
4
|
+
import { Domains } from "./domains.js";
|
|
5
|
+
import { Users } from "./users.js";
|
|
4
6
|
import { WebClient } from "./client.js";
|
|
5
7
|
import { CronJob } from 'cron';
|
|
6
8
|
import pino from 'pino';
|
|
@@ -21,10 +23,10 @@ export class Kerio extends WebClient {
|
|
|
21
23
|
this.userAgent = userAgent;
|
|
22
24
|
|
|
23
25
|
this.IPAddressGroups = new IPAddressGroup(this);
|
|
24
|
-
|
|
25
26
|
this.Logs = new Logs(this);
|
|
26
|
-
|
|
27
27
|
this.Session = new Session(this);
|
|
28
|
+
this.Domains = new Domains(this);
|
|
29
|
+
this.Users = new Users(this);
|
|
28
30
|
|
|
29
31
|
this.logger = pino({
|
|
30
32
|
level: "debug",
|
package/src/logs.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { KerioModules } from './modules.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @type {import('../index.
|
|
4
|
+
* @type {import('../index.d.ts').Logs}
|
|
5
5
|
*/
|
|
6
6
|
export class Logs extends KerioModules {
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Get logs from the specified log and number of most recent lines. Defaults to the last 5 security logs.
|
|
10
|
-
* @param {import('../index.
|
|
10
|
+
* @param {import('../index.d.ts').logName} logName
|
|
11
11
|
* @param {number} line_count
|
|
12
|
-
* @returns {Promise<Array<import('../index.
|
|
12
|
+
* @returns {Promise<Array<import('../index.d.ts').LogLineObject>>} An array of log lines structured with timestamp (DD/MMM/YYYY HH:MM:SS) in Kerio Connect's server timezone and the message
|
|
13
13
|
*/
|
|
14
14
|
async list(logName = "security", line_count = 5) {
|
|
15
15
|
try {
|
package/src/users.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { KerioModules } from './modules.js';
|
|
2
|
+
|
|
3
|
+
export class Users extends KerioModules {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get a Mapped Array of KerioUserItems indexed by their ID for the specified domain name. Does not include aliases or user groups.
|
|
7
|
+
* @param {string} domainName Name of the domain
|
|
8
|
+
* @returns {Promise<Map<import('../index.d.ts').KerioUserID, import('../index.d.ts').KerioUserItem>>}
|
|
9
|
+
*/
|
|
10
|
+
async list(domainName = null) {
|
|
11
|
+
try {
|
|
12
|
+
if (!this.instance.logged_in) {
|
|
13
|
+
|
|
14
|
+
this.reset();
|
|
15
|
+
|
|
16
|
+
throw {
|
|
17
|
+
name: "KerioClientSessionError",
|
|
18
|
+
message: `Kerio session invalid. Try logging in again.`,
|
|
19
|
+
type: 'Kerio',
|
|
20
|
+
from: "Kerio.Users.list"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!domainName) {
|
|
25
|
+
throw {
|
|
26
|
+
name: "KerioDomainNameUserError",
|
|
27
|
+
message: `Invalid Domain Name to find Domain ID while processing API method 'Users.get' for domain '${domainName}'`,
|
|
28
|
+
type: 'Kerio',
|
|
29
|
+
from: "Kerio.Users.list"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let domains = await this.instance.Domains.list();
|
|
34
|
+
|
|
35
|
+
if (domains.size != 0) {
|
|
36
|
+
|
|
37
|
+
let domainId = Array.from(domains.values()).find(d => d.name.toLowerCase() == domainName.toLowerCase()).id;
|
|
38
|
+
|
|
39
|
+
let users_response = await this.sessionedRequest({
|
|
40
|
+
http_method: 'POST',
|
|
41
|
+
api_method: 'Users.get',
|
|
42
|
+
auth: {
|
|
43
|
+
cookie: this.instance.session_cookie,
|
|
44
|
+
token: this.instance.x_token
|
|
45
|
+
},
|
|
46
|
+
body_params: {
|
|
47
|
+
query: {
|
|
48
|
+
},
|
|
49
|
+
domainId: domainId
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
let response_body = users_response._body;
|
|
54
|
+
|
|
55
|
+
if (!response_body.result?.errors && !response_body?.error) {
|
|
56
|
+
|
|
57
|
+
var userListResult = new Map();
|
|
58
|
+
|
|
59
|
+
if (response_body.result.list.length > 0) {
|
|
60
|
+
|
|
61
|
+
response_body.result.list.forEach(user => {
|
|
62
|
+
/**
|
|
63
|
+
* @type {import('../index.d.ts').KerioUserItem}
|
|
64
|
+
*/
|
|
65
|
+
var obj = {
|
|
66
|
+
id: user.id,
|
|
67
|
+
domainId: user.domainId,
|
|
68
|
+
loginName: user.loginName,
|
|
69
|
+
fullName: user.fullName,
|
|
70
|
+
description: user.description,
|
|
71
|
+
enabled: user.isEnabled,
|
|
72
|
+
primaryEmailAddress: `${user.loginName}@${domainName}`
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
userListResult.set(user.id, obj);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return userListResult;
|
|
80
|
+
|
|
81
|
+
} else {
|
|
82
|
+
throw {
|
|
83
|
+
name: "KerioRequestError",
|
|
84
|
+
message: `Error occured while fetching results from API method 'Users.get' for domain ${domainName}`,
|
|
85
|
+
type: 'Kerio',
|
|
86
|
+
from: "Kerio.Users.list"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
} else {
|
|
91
|
+
throw {
|
|
92
|
+
name: "KerioDomainError",
|
|
93
|
+
message: `Domain Name not found to find Domain ID while processing API method 'Users.get' for domain '${domainName}'`,
|
|
94
|
+
type: 'Kerio',
|
|
95
|
+
from: "Kerio.Users.list"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
} catch (e) {
|
|
100
|
+
this.instance.logger.error(e);
|
|
101
|
+
throw e;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async getStatistics(kerioUserID = null) {
|
|
106
|
+
try {
|
|
107
|
+
if (!this.instance.logged_in) {
|
|
108
|
+
|
|
109
|
+
this.reset();
|
|
110
|
+
|
|
111
|
+
throw {
|
|
112
|
+
name: "KerioClientSessionError",
|
|
113
|
+
message: `Kerio session invalid. Try logging in again.`,
|
|
114
|
+
type: 'Kerio',
|
|
115
|
+
from: "Kerio.Users.getStatistics"
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!kerioUserID || !kerioUserID.startsWith("keriodb://user/")) {
|
|
120
|
+
throw {
|
|
121
|
+
name: "KerioUserIDError",
|
|
122
|
+
message: `Invalid User ID while processing API method 'Users.getStatistics' for user ID '${kerioUserID}'`,
|
|
123
|
+
type: 'Kerio',
|
|
124
|
+
from: "Kerio.Users.getStatistics"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let user_stats_response = await this.sessionedRequest({
|
|
129
|
+
http_method: 'POST',
|
|
130
|
+
api_method: 'Users.getStatistics',
|
|
131
|
+
auth: {
|
|
132
|
+
cookie: this.instance.session_cookie,
|
|
133
|
+
token: this.instance.x_token
|
|
134
|
+
},
|
|
135
|
+
body_params: {
|
|
136
|
+
query: {
|
|
137
|
+
|
|
138
|
+
},
|
|
139
|
+
userIds: [
|
|
140
|
+
kerioUserID
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
let response_body = user_stats_response._body;
|
|
146
|
+
|
|
147
|
+
if (!response_body.result?.errors && !response_body?.error) {
|
|
148
|
+
|
|
149
|
+
if (Array.isArray(response_body.result.list) && response_body.result.list.length > 0) {
|
|
150
|
+
|
|
151
|
+
let _stats = response_body.result.list[0];
|
|
152
|
+
|
|
153
|
+
let res = {
|
|
154
|
+
storage: {
|
|
155
|
+
items: _stats.occupiedSpace.items,
|
|
156
|
+
value: _stats.occupiedSpace.storage.value,
|
|
157
|
+
units: _stats.occupiedSpace.storage.units
|
|
158
|
+
},
|
|
159
|
+
lastLogin: "",
|
|
160
|
+
loginCount: {
|
|
161
|
+
pop3: _stats.pop3.count,
|
|
162
|
+
pop3s: _stats.securePop3.count,
|
|
163
|
+
imap: _stats.imap.count,
|
|
164
|
+
imaps: _stats.secureImap.count,
|
|
165
|
+
http: _stats.http.count,
|
|
166
|
+
https: _stats.secureHttp.count,
|
|
167
|
+
ldap: _stats.ldap.count,
|
|
168
|
+
ldaps: _stats.secureLdap.count,
|
|
169
|
+
nntp: _stats.nntp.count,
|
|
170
|
+
nntps: _stats.secureNntp.count,
|
|
171
|
+
activeSync: _stats.activeSync.count,
|
|
172
|
+
secureActiveSync: _stats.secureActiveSync.count,
|
|
173
|
+
xmpp: _stats.xmpp.count,
|
|
174
|
+
xmpps: _stats.secureXmpp.count
|
|
175
|
+
},
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let login_timestamps_arr = Object.values(_stats).filter(services => services.lastLogin).map(t => t.lastLogin);
|
|
179
|
+
|
|
180
|
+
//most recent login timestamp YYYY-MM-DD HH:MM in server's local time zone
|
|
181
|
+
res.lastLogin = login_timestamps_arr.sort().at(-1);
|
|
182
|
+
|
|
183
|
+
return res;
|
|
184
|
+
|
|
185
|
+
} else {
|
|
186
|
+
throw {
|
|
187
|
+
name: "KerioUserStatsError",
|
|
188
|
+
message: `User may not exist. No statistics found for user ID ${kerioUserID}`,
|
|
189
|
+
type: 'Kerio',
|
|
190
|
+
from: "Kerio.Users.getStatistics"
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
} else {
|
|
195
|
+
throw {
|
|
196
|
+
name: "KerioRequestError",
|
|
197
|
+
message: `Error occured while fetching results from API method 'User.getStatistics'`,
|
|
198
|
+
type: 'Kerio',
|
|
199
|
+
from: "Kerio.Users.getStatistics"
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
} catch (e) {
|
|
204
|
+
this.instance.logger.error(e);
|
|
205
|
+
throw e;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|