@brickert/kerio-connect-api 0.0.4 → 0.0.5
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 +19 -0
- package/package.json +1 -1
- package/src/ipaddressgroups.js +7 -0
- package/src/kerio.js +3 -0
- package/src/logs.js +107 -0
package/index.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export interface GenericResponse {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
result?: {
|
|
75
|
+
viewport?: Array;
|
|
75
76
|
userDetails?: object;
|
|
76
77
|
list?: Array<object> | Array<IPAddressGroupItem>;
|
|
77
78
|
totalItems?: number;
|
|
@@ -104,6 +105,7 @@ export class Kerio extends WebClient {
|
|
|
104
105
|
|
|
105
106
|
IPAddressGroups: IPAddressGroup;
|
|
106
107
|
Session: Session;
|
|
108
|
+
Logs: Logs;
|
|
107
109
|
|
|
108
110
|
login(user: KerioUser): void;
|
|
109
111
|
|
|
@@ -243,4 +245,21 @@ export interface KerioInstanceUserResponse {
|
|
|
243
245
|
roles: {
|
|
244
246
|
userRole: string;
|
|
245
247
|
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export class Logs extends KerioModules {
|
|
251
|
+
/**
|
|
252
|
+
* Get logs from the specified log and number of most recent lines. Defaults to the last 5 security logs.
|
|
253
|
+
* @param logName
|
|
254
|
+
* @param line_count
|
|
255
|
+
* @returns An array of log lines structured with timestamp (DD/MMM/YYYY HH:MM:SS) in Kerio Connect's server timezone and the message
|
|
256
|
+
*/
|
|
257
|
+
list(logName: logName, line_count: number): Promise<Array<LogLineObject>>;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export type logName = "config" | "debug" | "error" | "mail" | "security" | "spam" | "warning";
|
|
261
|
+
|
|
262
|
+
export interface LogLineObject {
|
|
263
|
+
timestamp: string;
|
|
264
|
+
message: string;
|
|
246
265
|
}
|
package/package.json
CHANGED
package/src/ipaddressgroups.js
CHANGED
|
@@ -358,6 +358,13 @@ export class IPAddressGroup extends KerioModules {
|
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
|
|
361
|
+
/**
|
|
362
|
+
* Remove IPAddressGroupItem(s) of type 'host' by the description name from this group name. TAKE CARE as this will remove all items upto the specified max limit that share the same name. You may limit number of items to remove. They are sorted by their unique ID.
|
|
363
|
+
* @param {string} description Name of the group item(s)
|
|
364
|
+
* @param {string} group_name Name of the IPAddressGroup string to remove from
|
|
365
|
+
* @param {number} remove_limit Max number of group items to remove upto. Specifying -1 will remove ALL by the description name
|
|
366
|
+
* @returns Returns an array of host IP addresses that were removed
|
|
367
|
+
*/
|
|
361
368
|
async removeHostFromIPAddressGroupByDesc(description = null, group_name = null, remove_limit = 1) {
|
|
362
369
|
try {
|
|
363
370
|
|
package/src/kerio.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IPAddressGroup } from "./ipaddressgroups.js";
|
|
2
|
+
import { Logs } from "./logs.js";
|
|
2
3
|
import { Session } from "./session.js";
|
|
3
4
|
import { WebClient } from "./client.js";
|
|
4
5
|
import { CronJob } from 'cron';
|
|
@@ -21,6 +22,8 @@ export class Kerio extends WebClient {
|
|
|
21
22
|
|
|
22
23
|
this.IPAddressGroups = new IPAddressGroup(this);
|
|
23
24
|
|
|
25
|
+
this.Logs = new Logs(this);
|
|
26
|
+
|
|
24
27
|
this.Session = new Session(this);
|
|
25
28
|
|
|
26
29
|
this.logger = pino({
|
package/src/logs.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { KerioModules } from './modules.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @type {import('../index.js').Logs}
|
|
5
|
+
*/
|
|
6
|
+
export class Logs extends KerioModules {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get logs from the specified log and number of most recent lines. Defaults to the last 5 security logs.
|
|
10
|
+
* @param {import('../index.js').logName} logName
|
|
11
|
+
* @param {number} line_count
|
|
12
|
+
* @returns {Promise<Array<import('../index.js').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
|
+
*/
|
|
14
|
+
async list(logName = "security", line_count = 5) {
|
|
15
|
+
try {
|
|
16
|
+
|
|
17
|
+
if (!this.instance.logged_in) {
|
|
18
|
+
|
|
19
|
+
this.reset();
|
|
20
|
+
|
|
21
|
+
throw {
|
|
22
|
+
name: "KerioClientSessionError",
|
|
23
|
+
message: `Kerio session invalid. Try logging in again.`,
|
|
24
|
+
type: 'Kerio',
|
|
25
|
+
from: "Kerio.Logs.list"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!Number.isInteger(line_count) && line_count < 0) {
|
|
30
|
+
throw {
|
|
31
|
+
name: "KerioLogListCountError",
|
|
32
|
+
message: `Invalid log line count while processing API method 'Logs.get' for log '${logName}'`,
|
|
33
|
+
type: 'Kerio',
|
|
34
|
+
from: "Kerio.Logs.list"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!["config", "debug", "error", "mail", "security", "spam", "warning"].includes(logName)) {
|
|
39
|
+
throw {
|
|
40
|
+
name: "KerioLogNameError",
|
|
41
|
+
message: `Invalid log name while processing API method 'Logs.get' for log '${logName}'`,
|
|
42
|
+
type: 'Kerio',
|
|
43
|
+
from: "Kerio.Logs.list"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let log_list_response = await this.sessionedRequest({
|
|
48
|
+
http_method: 'POST',
|
|
49
|
+
api_method: 'Logs.get',
|
|
50
|
+
auth: {
|
|
51
|
+
cookie: this.instance.session_cookie,
|
|
52
|
+
token: this.instance.x_token
|
|
53
|
+
},
|
|
54
|
+
body_params: {
|
|
55
|
+
logName: logName,
|
|
56
|
+
fromLine : -1,
|
|
57
|
+
countLines: line_count
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
let response_body = log_list_response._body;
|
|
62
|
+
|
|
63
|
+
if (!response_body.result?.errors && !response_body?.error) {
|
|
64
|
+
|
|
65
|
+
var logLinesResult = new Array();
|
|
66
|
+
|
|
67
|
+
if (response_body.result.viewport.length > 0) {
|
|
68
|
+
|
|
69
|
+
response_body.result.viewport.forEach(line => {
|
|
70
|
+
|
|
71
|
+
let timestamp_string = line.content.split("]")[0];
|
|
72
|
+
timestamp_string = timestamp_string.substring(1, timestamp_string.length).trim();
|
|
73
|
+
|
|
74
|
+
let message = line.content.split("]")[1].trim();
|
|
75
|
+
|
|
76
|
+
logLinesResult.push({
|
|
77
|
+
timestamp: timestamp_string,
|
|
78
|
+
message
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.instance.logger.debug({
|
|
85
|
+
name: "KerioLogsList",
|
|
86
|
+
message: `listed ${logLinesResult.length} log lines from Log '${logName}'`,
|
|
87
|
+
type: 'Kerio',
|
|
88
|
+
from: "Kerio.Logs.list"
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return logLinesResult;
|
|
92
|
+
|
|
93
|
+
} else {
|
|
94
|
+
throw {
|
|
95
|
+
name: "KerioRequestError",
|
|
96
|
+
message: `Error occured while fetching results from API method 'Logs.get' for log '${logName}'`,
|
|
97
|
+
type: 'Kerio',
|
|
98
|
+
from: "Kerio.Logs.list"
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
} catch (e) {
|
|
103
|
+
this.instance.logger.error(e);
|
|
104
|
+
throw e;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|