@brickert/kerio-connect-api 0.0.5 → 0.0.6
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 +87 -1
- package/package.json +1 -1
- package/src/domains.js +207 -0
- package/src/kerio.js +2 -2
- package/src/logs.js +3 -3
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,7 @@ export class Kerio extends WebClient {
|
|
|
106
107
|
IPAddressGroups: IPAddressGroup;
|
|
107
108
|
Session: Session;
|
|
108
109
|
Logs: Logs;
|
|
110
|
+
Domains: Domains;
|
|
109
111
|
|
|
110
112
|
login(user: KerioUser): void;
|
|
111
113
|
|
|
@@ -262,4 +264,88 @@ export type logName = "config" | "debug" | "error" | "mail" | "security" | "spam
|
|
|
262
264
|
export interface LogLineObject {
|
|
263
265
|
timestamp: string;
|
|
264
266
|
message: string;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export class Domains extends KerioModules {
|
|
270
|
+
/**
|
|
271
|
+
* Get a Mapped Array of KerioDomainItems indexed by their ID
|
|
272
|
+
* @returns {Promise<Map<import('../index.d.ts').KerioDomainID, import('../index.d.ts').KerioDomainItem>>}
|
|
273
|
+
*/
|
|
274
|
+
list(): Promise<Map<KerioDomainID, KerioDomainItem>>;
|
|
275
|
+
/**
|
|
276
|
+
* Get the DKIM DNS TXT record object for the domain name. TXT record name & value pair, selector name, and raw public key string.
|
|
277
|
+
* @param {string} domainName Name of the domain
|
|
278
|
+
* @returns {Promise<import('../index.d.ts').DKIMRecord>}
|
|
279
|
+
*/
|
|
280
|
+
getDKIMDNSRecord(domainName: string): Promise<DKIMRecord>;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* @example "keriodb://domain/1234-5678-901-2345"
|
|
285
|
+
*/
|
|
286
|
+
export type KerioDomainID = string;
|
|
287
|
+
|
|
288
|
+
export interface KerioDomainItem {
|
|
289
|
+
id: KerioDomainID;
|
|
290
|
+
name: string;
|
|
291
|
+
description: string;
|
|
292
|
+
primary: boolean;
|
|
293
|
+
userMaxCount: number;
|
|
294
|
+
passwords: {
|
|
295
|
+
expiration: {
|
|
296
|
+
enabled: boolean;
|
|
297
|
+
days: number;
|
|
298
|
+
};
|
|
299
|
+
historyCount: number;
|
|
300
|
+
enforceComplexity: boolean;
|
|
301
|
+
minLength: number;
|
|
302
|
+
};
|
|
303
|
+
messages: {
|
|
304
|
+
outgoingLimit: {
|
|
305
|
+
enabled: boolean,
|
|
306
|
+
size: number;
|
|
307
|
+
units: string;
|
|
308
|
+
};
|
|
309
|
+
autoClean: {
|
|
310
|
+
deleted: {
|
|
311
|
+
enabled: boolean;
|
|
312
|
+
days: number;
|
|
313
|
+
};
|
|
314
|
+
junk: {
|
|
315
|
+
enabled: boolean;
|
|
316
|
+
days: number;
|
|
317
|
+
};
|
|
318
|
+
sent: {
|
|
319
|
+
enabled: boolean;
|
|
320
|
+
days: number;
|
|
321
|
+
};
|
|
322
|
+
other: {
|
|
323
|
+
enabled: boolean;
|
|
324
|
+
days: number;
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
deleteRecovery: {
|
|
328
|
+
enabled: boolean;
|
|
329
|
+
days: number;
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
DKIMenabled: boolean;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export interface DKIMRecord {
|
|
336
|
+
/**
|
|
337
|
+
* @example 'mail._domainkey.example.org'
|
|
338
|
+
*/
|
|
339
|
+
name: string;
|
|
340
|
+
selector: string;
|
|
341
|
+
type: "TXT";
|
|
342
|
+
/**
|
|
343
|
+
* @example 'v=DKIM1; p=1234'
|
|
344
|
+
*/
|
|
345
|
+
value: string;
|
|
346
|
+
/**
|
|
347
|
+
* The 'p=' section of the TXT record value
|
|
348
|
+
* @example 'abcdefg1234567'
|
|
349
|
+
*/
|
|
350
|
+
raw_public_key: string;
|
|
265
351
|
}
|
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,7 @@
|
|
|
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";
|
|
4
5
|
import { WebClient } from "./client.js";
|
|
5
6
|
import { CronJob } from 'cron';
|
|
6
7
|
import pino from 'pino';
|
|
@@ -21,10 +22,9 @@ export class Kerio extends WebClient {
|
|
|
21
22
|
this.userAgent = userAgent;
|
|
22
23
|
|
|
23
24
|
this.IPAddressGroups = new IPAddressGroup(this);
|
|
24
|
-
|
|
25
25
|
this.Logs = new Logs(this);
|
|
26
|
-
|
|
27
26
|
this.Session = new Session(this);
|
|
27
|
+
this.Domains = new Domains(this);
|
|
28
28
|
|
|
29
29
|
this.logger = pino({
|
|
30
30
|
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 {
|