@bmfk/api 0.0.0-stage → 1.0.0
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/CHANGELOG.md +83 -0
- package/LICENSE +21 -0
- package/README.md +1293 -2
- package/dist/apiServer/APIService.d.ts +125 -0
- package/dist/apiServer/APIService.js +769 -0
- package/dist/apiServer/BaseEndpoint.d.ts +90 -0
- package/dist/apiServer/BaseEndpoint.js +314 -0
- package/dist/apiServer/BaseService.d.ts +17 -0
- package/dist/apiServer/BaseService.js +39 -0
- package/dist/apiServer/DBService.d.ts +131 -0
- package/dist/apiServer/DBService.js +290 -0
- package/dist/apiServer/DocumentService.d.ts +9 -0
- package/dist/apiServer/DocumentService.js +65 -0
- package/dist/apiServer/LocalRequest.d.ts +3 -0
- package/dist/apiServer/LocalRequest.js +6 -0
- package/dist/apiServer/LogService.d.ts +78 -0
- package/dist/apiServer/LogService.js +349 -0
- package/dist/apiServer/MonitorService.d.ts +102 -0
- package/dist/apiServer/MonitorService.js +615 -0
- package/dist/apiServer/StatService.d.ts +4 -0
- package/dist/apiServer/StatService.js +10 -0
- package/dist/apiServer/TimeframeService.d.ts +28 -0
- package/dist/apiServer/TimeframeService.js +97 -0
- package/dist/apiServer/WebSocketServer.d.ts +39 -0
- package/dist/apiServer/WebSocketServer.js +173 -0
- package/dist/apiServer/db/IDBAdapter.d.ts +14 -0
- package/dist/apiServer/db/IDBAdapter.js +2 -0
- package/dist/apiServer/db/MysqlAdapter.d.ts +72 -0
- package/dist/apiServer/db/MysqlAdapter.js +869 -0
- package/dist/apiServer/db/PostgresAdapter.d.ts +41 -0
- package/dist/apiServer/db/PostgresAdapter.js +73 -0
- package/dist/apiServer/deployment/AccessConfigWizard.d.ts +5 -0
- package/dist/apiServer/deployment/AccessConfigWizard.js +254 -0
- package/dist/apiServer/deployment/Activate.d.ts +4 -0
- package/dist/apiServer/deployment/Activate.js +124 -0
- package/dist/apiServer/deployment/BackupManager.d.ts +33 -0
- package/dist/apiServer/deployment/BackupManager.js +174 -0
- package/dist/apiServer/deployment/Backups.d.ts +2 -0
- package/dist/apiServer/deployment/Backups.js +44 -0
- package/dist/apiServer/deployment/BlueGreenState.d.ts +31 -0
- package/dist/apiServer/deployment/BlueGreenState.js +150 -0
- package/dist/apiServer/deployment/Bundler.d.ts +12 -0
- package/dist/apiServer/deployment/Bundler.js +178 -0
- package/dist/apiServer/deployment/ConfigService.d.ts +203 -0
- package/dist/apiServer/deployment/ConfigService.js +195 -0
- package/dist/apiServer/deployment/Deploy.d.ts +4 -0
- package/dist/apiServer/deployment/Deploy.js +404 -0
- package/dist/apiServer/deployment/DeployKeyWizard.d.ts +2 -0
- package/dist/apiServer/deployment/DeployKeyWizard.js +84 -0
- package/dist/apiServer/deployment/Deployer.d.ts +13 -0
- package/dist/apiServer/deployment/Deployer.js +96 -0
- package/dist/apiServer/deployment/DeployerInit.d.ts +25 -0
- package/dist/apiServer/deployment/DeployerInit.js +214 -0
- package/dist/apiServer/deployment/DeployerService.d.ts +378 -0
- package/dist/apiServer/deployment/DeployerService.js +1553 -0
- package/dist/apiServer/deployment/HashPassword.d.ts +3 -0
- package/dist/apiServer/deployment/HashPassword.js +126 -0
- package/dist/apiServer/deployment/MigrateConfigsWizard.d.ts +1 -0
- package/dist/apiServer/deployment/MigrateConfigsWizard.js +202 -0
- package/dist/apiServer/deployment/MigrateProject.d.ts +31 -0
- package/dist/apiServer/deployment/MigrateProject.js +335 -0
- package/dist/apiServer/deployment/NginxHelper.d.ts +10 -0
- package/dist/apiServer/deployment/NginxHelper.js +111 -0
- package/dist/apiServer/deployment/Notifier.d.ts +30 -0
- package/dist/apiServer/deployment/Notifier.js +82 -0
- package/dist/apiServer/deployment/ProjectConfigWizard.d.ts +1 -0
- package/dist/apiServer/deployment/ProjectConfigWizard.js +148 -0
- package/dist/apiServer/deployment/Restore.d.ts +2 -0
- package/dist/apiServer/deployment/Restore.js +89 -0
- package/dist/apiServer/deployment/ReviewStore.d.ts +62 -0
- package/dist/apiServer/deployment/ReviewStore.js +186 -0
- package/dist/apiServer/deployment/SecretsInjector.d.ts +21 -0
- package/dist/apiServer/deployment/SecretsInjector.js +189 -0
- package/dist/apiServer/deployment/SetupConfigWizard.d.ts +1 -0
- package/dist/apiServer/deployment/SetupConfigWizard.js +238 -0
- package/dist/apiServer/deployment/Status.d.ts +2 -0
- package/dist/apiServer/deployment/Status.js +83 -0
- package/dist/apiServer/deployment/TelegramNotifier.d.ts +8 -0
- package/dist/apiServer/deployment/TelegramNotifier.js +23 -0
- package/dist/apiServer/deployment/Watchdog.d.ts +15 -0
- package/dist/apiServer/deployment/Watchdog.js +65 -0
- package/dist/apiServer/deployment/Wizards.d.ts +1 -0
- package/dist/apiServer/deployment/Wizards.js +83 -0
- package/dist/apiServer/deployment/cli.d.ts +2 -0
- package/dist/apiServer/deployment/cli.js +224 -0
- package/dist/apiServer/deployment/cliCommon.d.ts +27 -0
- package/dist/apiServer/deployment/cliCommon.js +110 -0
- package/dist/apiServer/deployment/cliPrompt.d.ts +5 -0
- package/dist/apiServer/deployment/cliPrompt.js +38 -0
- package/dist/apiServer/deployment/resolveConfig.d.ts +19 -0
- package/dist/apiServer/deployment/resolveConfig.js +139 -0
- package/dist/apiServer/documentation/Documentation.d.ts +18 -0
- package/dist/apiServer/documentation/Documentation.js +143 -0
- package/dist/apiServer/documentation/index.html +460 -0
- package/dist/apiServer/external/MicroserviceClient.d.ts +28 -0
- package/dist/apiServer/external/MicroserviceClient.js +144 -0
- package/dist/apiServer/external/MicroserviceHost.d.ts +52 -0
- package/dist/apiServer/external/MicroserviceHost.js +183 -0
- package/dist/apiServer/external/MicroserviceHostController.d.ts +6 -0
- package/dist/apiServer/external/MicroserviceHostController.js +65 -0
- package/dist/apiServer/helper/AppDataPath.d.ts +9 -0
- package/dist/apiServer/helper/AppDataPath.js +81 -0
- package/dist/apiServer/helper/ClientIp.d.ts +3 -0
- package/dist/apiServer/helper/ClientIp.js +33 -0
- package/dist/apiServer/helper/DataProvider.d.ts +18 -0
- package/dist/apiServer/helper/DataProvider.js +57 -0
- package/dist/apiServer/helper/IpAllowList.d.ts +8 -0
- package/dist/apiServer/helper/IpAllowList.js +40 -0
- package/dist/apiServer/helper/JSONStableStringify.d.ts +1 -0
- package/dist/apiServer/helper/JSONStableStringify.js +15 -0
- package/dist/apiServer/helper/PasswordHash.d.ts +5 -0
- package/dist/apiServer/helper/PasswordHash.js +52 -0
- package/dist/apiServer/helper/Sleep.d.ts +1 -0
- package/dist/apiServer/helper/Sleep.js +5 -0
- package/dist/apiServer/helper/Trace.d.ts +8 -0
- package/dist/apiServer/helper/Trace.js +30 -0
- package/dist/apiServer/helper/UID.d.ts +16 -0
- package/dist/apiServer/helper/UID.js +98 -0
- package/dist/apiServer/helper/Validator.d.ts +86 -0
- package/dist/apiServer/helper/Validator.js +560 -0
- package/dist/apiServer/helper/YYYYMMDDHH.d.ts +2 -0
- package/dist/apiServer/helper/YYYYMMDDHH.js +31 -0
- package/dist/apiServer/helper/ZipUtils.d.ts +6 -0
- package/dist/apiServer/helper/ZipUtils.js +28 -0
- package/dist/apiServer/http/Http.d.ts +183 -0
- package/dist/apiServer/http/Http.js +627 -0
- package/dist/apiServer/interceptors/InterceptorPayAuth.d.ts +19 -0
- package/dist/apiServer/interceptors/InterceptorPayAuth.js +124 -0
- package/dist/apiServer/interceptors/InterceptorSignedAuth.d.ts +40 -0
- package/dist/apiServer/interceptors/InterceptorSignedAuth.js +150 -0
- package/dist/apiServer/monitor/AccessStore.d.ts +27 -0
- package/dist/apiServer/monitor/AccessStore.js +163 -0
- package/dist/apiServer/monitor/LogFiles.d.ts +34 -0
- package/dist/apiServer/monitor/LogFiles.js +109 -0
- package/dist/apiServer/monitor/Monitor.d.ts +54 -0
- package/dist/apiServer/monitor/Monitor.js +447 -0
- package/dist/apiServer/monitor/MonitorAuth.d.ts +87 -0
- package/dist/apiServer/monitor/MonitorAuth.js +474 -0
- package/dist/apiServer/monitor/ProcessMonitor.d.ts +177 -0
- package/dist/apiServer/monitor/ProcessMonitor.js +468 -0
- package/dist/apiServer/monitor/SystemInfo.d.ts +70 -0
- package/dist/apiServer/monitor/SystemInfo.js +217 -0
- package/dist/apiServer/monitor/ThreatMonitor.d.ts +73 -0
- package/dist/apiServer/monitor/ThreatMonitor.js +239 -0
- package/dist/apiServer/monitor/index.html +591 -0
- package/dist/apiServer/review/Review.d.ts +23 -0
- package/dist/apiServer/review/Review.js +149 -0
- package/dist/apiServer/review/ReviewAuth.d.ts +56 -0
- package/dist/apiServer/review/ReviewAuth.js +147 -0
- package/dist/apiServer/review/ReviewDiff.d.ts +43 -0
- package/dist/apiServer/review/ReviewDiff.js +175 -0
- package/dist/apiServer/review/index.html +501 -0
- package/dist/apiServer/routes/Liveness.d.ts +7 -0
- package/dist/apiServer/routes/Liveness.js +27 -0
- package/dist/apiServer/routes/Readiness.d.ts +13 -0
- package/dist/apiServer/routes/Readiness.js +20 -0
- package/dist/apiServer/security/BlockedIps.d.ts +46 -0
- package/dist/apiServer/security/BlockedIps.js +185 -0
- package/dist/apiServer/structures/DefaultErrors.d.ts +36 -0
- package/dist/apiServer/structures/DefaultErrors.js +52 -0
- package/dist/apiServer/structures/HTTPStatus.d.ts +7 -0
- package/dist/apiServer/structures/HTTPStatus.js +11 -0
- package/dist/apiServer/structures/Interfaces.d.ts +55 -0
- package/dist/apiServer/structures/Interfaces.js +2 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +110 -0
- package/dist/signal/Signal.d.ts +23 -0
- package/dist/signal/Signal.js +85 -0
- package/package.json +88 -4
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Signal } from "../../signal/Signal";
|
|
2
|
+
import { APIServiceOptions } from "../APIService";
|
|
3
|
+
import { BaseEndpoint } from "../BaseEndpoint";
|
|
4
|
+
import { IRequest, IResponse } from "../structures/Interfaces";
|
|
5
|
+
import { TMonitorCapability } from "./MonitorAuth";
|
|
6
|
+
export interface IUserAction {
|
|
7
|
+
action: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const S_MONITOR_REGISTRATE_ACTION: Signal<IUserAction>;
|
|
10
|
+
export interface IRestartRequest {
|
|
11
|
+
by: string;
|
|
12
|
+
name: string | null;
|
|
13
|
+
pmId: string | null;
|
|
14
|
+
}
|
|
15
|
+
export declare const S_MONITOR_RESTART_REQUESTED: Signal<IRestartRequest>;
|
|
16
|
+
export declare class Monitor extends BaseEndpoint {
|
|
17
|
+
ignoreHttpLogging: boolean;
|
|
18
|
+
ignoreInDocumentation: boolean;
|
|
19
|
+
indexHtmlFile: string | null;
|
|
20
|
+
apiServiceOptions: APIServiceOptions;
|
|
21
|
+
fileParsed: boolean;
|
|
22
|
+
lastTimeCacheChecked: number;
|
|
23
|
+
constructor(options: APIServiceOptions);
|
|
24
|
+
__precheck(req: IRequest): Promise<IResponse<any> | null>;
|
|
25
|
+
loadHTMLFile(): Promise<string>;
|
|
26
|
+
html(req: IRequest): Promise<IResponse>;
|
|
27
|
+
controllers(req: IRequest): Promise<IResponse>;
|
|
28
|
+
changeLogLevel(req: IRequest): Promise<IResponse>;
|
|
29
|
+
logs(req: IRequest): Promise<IResponse>;
|
|
30
|
+
netlog(req: IRequest): Promise<IResponse>;
|
|
31
|
+
outgoingNetlog(req: IRequest): Promise<IResponse>;
|
|
32
|
+
sysinfo(req: IRequest): Promise<IResponse>;
|
|
33
|
+
procinfo(req: IRequest): Promise<IResponse>;
|
|
34
|
+
fdreport(req: IRequest): Promise<IResponse>;
|
|
35
|
+
login(req: IRequest): Promise<IResponse>;
|
|
36
|
+
enroll2fa(req: IRequest): Promise<IResponse>;
|
|
37
|
+
logout(req: IRequest): Promise<IResponse>;
|
|
38
|
+
restart(req: IRequest): Promise<IResponse>;
|
|
39
|
+
httpstats(req: IRequest): Promise<IResponse>;
|
|
40
|
+
inventory(req: IRequest): Promise<IResponse>;
|
|
41
|
+
metrics(req: IRequest): Promise<IResponse>;
|
|
42
|
+
threats(req: IRequest): Promise<IResponse>;
|
|
43
|
+
blocked(req: IRequest): Promise<IResponse>;
|
|
44
|
+
block(req: IRequest): Promise<IResponse>;
|
|
45
|
+
unblock(req: IRequest): Promise<IResponse>;
|
|
46
|
+
logfiles(req: IRequest): Promise<IResponse>;
|
|
47
|
+
logtail(req: IRequest): Promise<IResponse>;
|
|
48
|
+
metricsWeeks(req: IRequest): Promise<IResponse>;
|
|
49
|
+
metricsWeek(req: IRequest): Promise<IResponse>;
|
|
50
|
+
connections(req: IRequest): Promise<IResponse>;
|
|
51
|
+
db(req: IRequest): Promise<IResponse>;
|
|
52
|
+
requireAccess(req: IRequest, capability: TMonitorCapability): Promise<string>;
|
|
53
|
+
checkAuthentication(req: IRequest): Promise<string>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Monitor = exports.S_MONITOR_RESTART_REQUESTED = exports.S_MONITOR_REGISTRATE_ACTION = void 0;
|
|
7
|
+
const Signal_1 = require("../../signal/Signal");
|
|
8
|
+
const APIService_1 = require("../APIService");
|
|
9
|
+
const IpAllowList_1 = require("../helper/IpAllowList");
|
|
10
|
+
const BaseEndpoint_1 = require("../BaseEndpoint");
|
|
11
|
+
const BaseService_1 = require("../BaseService");
|
|
12
|
+
const LogService_1 = require("../LogService");
|
|
13
|
+
const DefaultErrors_1 = __importDefault(require("../structures/DefaultErrors"));
|
|
14
|
+
const fs_1 = __importDefault(require("fs"));
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const Http_1 = require("../http/Http");
|
|
17
|
+
const MonitorService_1 = require("../MonitorService");
|
|
18
|
+
const DBService_1 = require("../DBService");
|
|
19
|
+
const SystemInfo_1 = require("./SystemInfo");
|
|
20
|
+
const ProcessMonitor_1 = require("./ProcessMonitor");
|
|
21
|
+
const LogFiles_1 = require("./LogFiles");
|
|
22
|
+
const MonitorAuth_1 = require("./MonitorAuth");
|
|
23
|
+
const ThreatMonitor_1 = require("./ThreatMonitor");
|
|
24
|
+
const BlockedIps_1 = require("../security/BlockedIps");
|
|
25
|
+
exports.S_MONITOR_REGISTRATE_ACTION = new Signal_1.Signal();
|
|
26
|
+
exports.S_MONITOR_RESTART_REQUESTED = new Signal_1.Signal();
|
|
27
|
+
const logMap = {
|
|
28
|
+
ALL: 10,
|
|
29
|
+
API: 19,
|
|
30
|
+
INFO: 20,
|
|
31
|
+
DB: 25,
|
|
32
|
+
WARN: 30,
|
|
33
|
+
ERROR: 40,
|
|
34
|
+
CRIT: 50,
|
|
35
|
+
};
|
|
36
|
+
class Monitor extends BaseEndpoint_1.BaseEndpoint {
|
|
37
|
+
ignoreHttpLogging = true;
|
|
38
|
+
ignoreInDocumentation = true;
|
|
39
|
+
indexHtmlFile = null;
|
|
40
|
+
apiServiceOptions;
|
|
41
|
+
fileParsed = false;
|
|
42
|
+
lastTimeCacheChecked = 0;
|
|
43
|
+
constructor(options) {
|
|
44
|
+
super("sm");
|
|
45
|
+
this.apiServiceOptions = options;
|
|
46
|
+
MonitorAuth_1.MonitorAuth.configure({ authFile: options.monitorAuthFile, authDir: options.monitorAuthDir, projectName: options.projectName });
|
|
47
|
+
this.registerEndpoints([
|
|
48
|
+
{ ignoreInterceptor: true, endpoint: "html", handler: this.html },
|
|
49
|
+
{ ignoreInterceptor: true, endpoint: "log", handler: this.logs },
|
|
50
|
+
{ ignoreInterceptor: true, endpoint: "netlog", handler: this.netlog },
|
|
51
|
+
{ ignoreInterceptor: true, endpoint: "outgoingnetlog", handler: this.outgoingNetlog },
|
|
52
|
+
{ ignoreInterceptor: true, endpoint: "sysinfo", handler: this.sysinfo },
|
|
53
|
+
{ ignoreInterceptor: true, endpoint: "procinfo", handler: this.procinfo },
|
|
54
|
+
{ ignoreInterceptor: true, endpoint: "fdreport", handler: this.fdreport },
|
|
55
|
+
{ ignoreInterceptor: true, endpoint: "login", handler: this.login, validationModel: {
|
|
56
|
+
login: "",
|
|
57
|
+
password: "",
|
|
58
|
+
totp: "",
|
|
59
|
+
$__totp_optional: true
|
|
60
|
+
} },
|
|
61
|
+
{ ignoreInterceptor: true, endpoint: "enroll2fa", handler: this.enroll2fa, validationModel: {
|
|
62
|
+
enrollmentToken: "",
|
|
63
|
+
totp: ""
|
|
64
|
+
} },
|
|
65
|
+
{ ignoreInterceptor: true, endpoint: "logout", handler: this.logout },
|
|
66
|
+
{ ignoreInterceptor: true, endpoint: "restart", handler: this.restart, validationModel: {
|
|
67
|
+
confirm: "",
|
|
68
|
+
password: "",
|
|
69
|
+
totp: "",
|
|
70
|
+
$__totp_optional: true
|
|
71
|
+
} },
|
|
72
|
+
{ ignoreInterceptor: true, endpoint: "inventory", handler: this.inventory },
|
|
73
|
+
{ ignoreInterceptor: true, endpoint: "httpstats", handler: this.httpstats },
|
|
74
|
+
{ ignoreInterceptor: true, endpoint: "metrics", handler: this.metrics, validationModel: {
|
|
75
|
+
range: "",
|
|
76
|
+
$__range_values: ["week", "day", "hour"]
|
|
77
|
+
} },
|
|
78
|
+
{ ignoreInterceptor: true, endpoint: "threats", handler: this.threats, validationModel: {
|
|
79
|
+
limit: 0,
|
|
80
|
+
$__limit_optional: true
|
|
81
|
+
} },
|
|
82
|
+
{ ignoreInterceptor: true, endpoint: "logfiles", handler: this.logfiles },
|
|
83
|
+
{ ignoreInterceptor: true, endpoint: "logtail", handler: this.logtail, validationModel: {
|
|
84
|
+
source: "",
|
|
85
|
+
$__source_values: [...LogFiles_1.LOG_SOURCES],
|
|
86
|
+
lines: 0,
|
|
87
|
+
$__lines_optional: true,
|
|
88
|
+
since: 0,
|
|
89
|
+
$__since_optional: true,
|
|
90
|
+
filter: "",
|
|
91
|
+
$__filter_optional: true
|
|
92
|
+
} },
|
|
93
|
+
{ ignoreInterceptor: true, endpoint: "metricsWeeks", handler: this.metricsWeeks },
|
|
94
|
+
{ ignoreInterceptor: true, endpoint: "metricsWeek", handler: this.metricsWeek, validationModel: {
|
|
95
|
+
weekKey: ""
|
|
96
|
+
} },
|
|
97
|
+
{ ignoreInterceptor: true, endpoint: "connections", handler: this.connections },
|
|
98
|
+
{ ignoreInterceptor: true, endpoint: "db", handler: this.db, validationModel: {
|
|
99
|
+
range: "",
|
|
100
|
+
$__range_values: ["week", "day", "hour"]
|
|
101
|
+
} },
|
|
102
|
+
{ ignoreInterceptor: true, endpoint: "blocked", handler: this.blocked },
|
|
103
|
+
{ ignoreInterceptor: true, endpoint: "block", handler: this.block, validationModel: {
|
|
104
|
+
ip: "", reason: "", $__reason_optional: true, hours: 0, $__hours_optional: true
|
|
105
|
+
} },
|
|
106
|
+
{ ignoreInterceptor: true, endpoint: "unblock", handler: this.unblock, validationModel: { ip: "" } },
|
|
107
|
+
{ ignoreInterceptor: true, endpoint: "controllers", handler: this.controllers },
|
|
108
|
+
{ ignoreInterceptor: true, endpoint: "changeLogLevel", handler: this.changeLogLevel, validationModel: {
|
|
109
|
+
level: Object.keys(logMap).join(",")
|
|
110
|
+
} }
|
|
111
|
+
]);
|
|
112
|
+
}
|
|
113
|
+
async __precheck(req) {
|
|
114
|
+
const entries = await APIService_1.REQ_MONITOR_ALLOWED_IPS.request();
|
|
115
|
+
if (!entries || entries.length === 0)
|
|
116
|
+
return null;
|
|
117
|
+
const { list, error } = IpAllowList_1.IpAllowList.build(entries);
|
|
118
|
+
if (error) {
|
|
119
|
+
(0, LogService_1.logError)(`Monitor: monitorAllowedIps is invalid (${error}) — the monitor refuses every request until it is fixed`);
|
|
120
|
+
return { error: { ...DefaultErrors_1.default.FORBIDDEN } };
|
|
121
|
+
}
|
|
122
|
+
if (!IpAllowList_1.IpAllowList.allows(list, req.ip)) {
|
|
123
|
+
(0, LogService_1.logWarn)(`Monitor: request refused from ${req.ip ?? "unknown"} — not in monitorAllowedIps`);
|
|
124
|
+
return { error: { ...DefaultErrors_1.default.FORBIDDEN } };
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
async loadHTMLFile() {
|
|
129
|
+
if (!this.indexHtmlFile)
|
|
130
|
+
this.indexHtmlFile = fs_1.default.readFileSync(path_1.default.resolve(__dirname, "index.html")).toString("utf-8");
|
|
131
|
+
return this.indexHtmlFile;
|
|
132
|
+
}
|
|
133
|
+
async html(req) {
|
|
134
|
+
this.indexHtmlFile = await this.loadHTMLFile();
|
|
135
|
+
if (!this.fileParsed) {
|
|
136
|
+
this.fileParsed = true;
|
|
137
|
+
let bend = this.apiServiceOptions.baseEndPoint;
|
|
138
|
+
if (!bend.endsWith("/"))
|
|
139
|
+
bend += "/";
|
|
140
|
+
let end = this.endpoint;
|
|
141
|
+
if (!end.endsWith("/"))
|
|
142
|
+
end += "/";
|
|
143
|
+
if (end.startsWith("/"))
|
|
144
|
+
end = end.substring(1);
|
|
145
|
+
const endpoint = bend + end;
|
|
146
|
+
this.indexHtmlFile = this.indexHtmlFile.replace(/{{host}}/g, endpoint);
|
|
147
|
+
let projectName = this.apiServiceOptions.projectName;
|
|
148
|
+
if (!projectName)
|
|
149
|
+
projectName = "API Server";
|
|
150
|
+
projectName += " - Monitoring";
|
|
151
|
+
if (this.apiServiceOptions.appVersion)
|
|
152
|
+
projectName += " (v.:" + this.apiServiceOptions.appVersion + ")";
|
|
153
|
+
this.indexHtmlFile = this.indexHtmlFile.replace(/{{title}}/g, projectName);
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
rawResponse: true,
|
|
157
|
+
data: this.indexHtmlFile,
|
|
158
|
+
headers: {
|
|
159
|
+
"Content-Type": "text/html",
|
|
160
|
+
"Content-Length": Buffer.byteLength(this.indexHtmlFile).toString()
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
async controllers(req) {
|
|
165
|
+
await this.requireAccess(req, "dashboard");
|
|
166
|
+
return {};
|
|
167
|
+
}
|
|
168
|
+
async changeLogLevel(req) {
|
|
169
|
+
await this.requireAccess(req, "admin");
|
|
170
|
+
const val = logMap[req.data.level];
|
|
171
|
+
if (!val)
|
|
172
|
+
throw { ...DefaultErrors_1.default.BAD_REQUEST, details: "bad log level" };
|
|
173
|
+
LogService_1.S_LOG_CHANGE_LEVEL.invoke(req.data.level);
|
|
174
|
+
return { data: (await LogService_1.REQ_CURRENT_LOG_LEVEL.request()) };
|
|
175
|
+
}
|
|
176
|
+
async logs(req) {
|
|
177
|
+
await this.requireAccess(req, "logs");
|
|
178
|
+
const services = await LogService_1.REQ_LOG_UNIQUE_SERVICES.request();
|
|
179
|
+
const log = await LogService_1.REQ_LOG.request({
|
|
180
|
+
lastID: req.data.lastID ?? 0
|
|
181
|
+
});
|
|
182
|
+
return {
|
|
183
|
+
data: {
|
|
184
|
+
services,
|
|
185
|
+
log
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
async netlog(req) {
|
|
190
|
+
await this.requireAccess(req, "logs");
|
|
191
|
+
const log = await APIService_1.REQ_HTTP_LOG.request(req.data);
|
|
192
|
+
return { data: log };
|
|
193
|
+
}
|
|
194
|
+
async outgoingNetlog(req) {
|
|
195
|
+
await this.requireAccess(req, "logs");
|
|
196
|
+
return { data: Http_1.Http.getOutgoingLogSnapshot() };
|
|
197
|
+
}
|
|
198
|
+
async sysinfo(req) {
|
|
199
|
+
await this.requireAccess(req, "dashboard");
|
|
200
|
+
return { data: await (0, SystemInfo_1.collectSystemInfo)() };
|
|
201
|
+
}
|
|
202
|
+
async procinfo(req) {
|
|
203
|
+
await this.requireAccess(req, "dashboard");
|
|
204
|
+
return { data: await ProcessMonitor_1.ProcessMonitor.getSnapshot() };
|
|
205
|
+
}
|
|
206
|
+
async fdreport(req) {
|
|
207
|
+
await this.requireAccess(req, "dashboard");
|
|
208
|
+
return { data: await ProcessMonitor_1.ProcessMonitor.getFdReport() };
|
|
209
|
+
}
|
|
210
|
+
async login(req) {
|
|
211
|
+
const users = await APIService_1.REQ_MONITOR_USERS.request();
|
|
212
|
+
if (!users || users.length === 0) {
|
|
213
|
+
(0, LogService_1.logWarn)("Monitor: sign-in refused — no monitor users are configured (access.monitor)");
|
|
214
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED };
|
|
215
|
+
}
|
|
216
|
+
const { user, error, enrollmentRequired } = await MonitorAuth_1.MonitorAuth.authenticate(users, req.data.login, req.data.password, req.data.totp);
|
|
217
|
+
if (!user || error) {
|
|
218
|
+
(0, LogService_1.logWarn)(`Monitor login failed for "${req.data.login}" from ${req.ip ?? "unknown"}: ${error}`);
|
|
219
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: error ?? "Invalid user" };
|
|
220
|
+
}
|
|
221
|
+
if (enrollmentRequired) {
|
|
222
|
+
const issuer = this.apiServiceOptions.projectName || "Monitor";
|
|
223
|
+
const { token, secret, uri } = MonitorAuth_1.MonitorAuth.beginEnrollment(user.login, issuer);
|
|
224
|
+
(0, LogService_1.logInfo)(`Monitor 2FA enrollment started for "${user.login}"`, "Monitor");
|
|
225
|
+
return { data: {
|
|
226
|
+
enrollmentRequired: true,
|
|
227
|
+
enrollmentToken: token,
|
|
228
|
+
secret,
|
|
229
|
+
otpauthUri: uri,
|
|
230
|
+
expiresInMs: MonitorAuth_1.MonitorAuth.ENROLLMENT_TTL_MS,
|
|
231
|
+
} };
|
|
232
|
+
}
|
|
233
|
+
const session = MonitorAuth_1.MonitorAuth.createSession(user.login);
|
|
234
|
+
(0, LogService_1.logInfo)(`Monitor login: "${user.login}" from ${req.ip ?? "unknown"}`, "Monitor");
|
|
235
|
+
return { data: {
|
|
236
|
+
token: session.token,
|
|
237
|
+
login: user.login,
|
|
238
|
+
idleTimeoutMs: MonitorAuth_1.MonitorAuth.SESSION_IDLE_MS,
|
|
239
|
+
maxLifetimeMs: MonitorAuth_1.MonitorAuth.SESSION_MAX_MS,
|
|
240
|
+
twoFactor: true,
|
|
241
|
+
...MonitorAuth_1.MonitorAuth.describeRole(user.role),
|
|
242
|
+
} };
|
|
243
|
+
}
|
|
244
|
+
async enroll2fa(req) {
|
|
245
|
+
const { login, error } = MonitorAuth_1.MonitorAuth.completeEnrollment(req.data.enrollmentToken, req.data.totp);
|
|
246
|
+
if (!login || error || login.includes(":")) {
|
|
247
|
+
(0, LogService_1.logWarn)(`Monitor 2FA enrollment failed: ${error}`);
|
|
248
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: error ?? "Enrollment failed" };
|
|
249
|
+
}
|
|
250
|
+
const users = await APIService_1.REQ_MONITOR_USERS.request();
|
|
251
|
+
const user = users?.find(u => u?.login === login);
|
|
252
|
+
const session = MonitorAuth_1.MonitorAuth.createSession(login);
|
|
253
|
+
return { data: {
|
|
254
|
+
token: session.token,
|
|
255
|
+
login,
|
|
256
|
+
idleTimeoutMs: MonitorAuth_1.MonitorAuth.SESSION_IDLE_MS,
|
|
257
|
+
maxLifetimeMs: MonitorAuth_1.MonitorAuth.SESSION_MAX_MS,
|
|
258
|
+
twoFactor: true,
|
|
259
|
+
...MonitorAuth_1.MonitorAuth.describeRole(user?.role),
|
|
260
|
+
} };
|
|
261
|
+
}
|
|
262
|
+
async logout(req) {
|
|
263
|
+
const token = (req.headers['authorization'] ?? "").split(" ").pop() ?? "";
|
|
264
|
+
MonitorAuth_1.MonitorAuth.revokeSession(token);
|
|
265
|
+
return { data: { ok: true } };
|
|
266
|
+
}
|
|
267
|
+
async restart(req) {
|
|
268
|
+
const login = await this.requireAccess(req, "admin");
|
|
269
|
+
const users = await APIService_1.REQ_MONITOR_USERS.request();
|
|
270
|
+
const stepUp = await MonitorAuth_1.MonitorAuth.authenticate(users ?? [], login, req.data.password, req.data.totp);
|
|
271
|
+
if (!stepUp.user) {
|
|
272
|
+
(0, LogService_1.logWarn)(`Monitor restart re-auth failed for "${login}": ${stepUp.error}`);
|
|
273
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "Re-authentication required: " + (stepUp.error ?? "invalid credentials") };
|
|
274
|
+
}
|
|
275
|
+
const id = ProcessMonitor_1.ProcessMonitor.getPm2Identity();
|
|
276
|
+
if (!id.managed)
|
|
277
|
+
throw { ...DefaultErrors_1.default.BAD_REQUEST, details: "Process is not managed by pm2 (no pm_id in env) — refusing to exit, nothing would restart it." };
|
|
278
|
+
if (req.data.confirm !== id.name)
|
|
279
|
+
throw { ...DefaultErrors_1.default.BAD_REQUEST, details: `Confirmation mismatch. To restart send { "confirm": "${id.name}" }.` };
|
|
280
|
+
exports.S_MONITOR_RESTART_REQUESTED.invoke({ by: login, name: id.name, pmId: id.pmId });
|
|
281
|
+
exports.S_MONITOR_REGISTRATE_ACTION.invoke({ action: `restart requested by "${login}" for pm2 "${id.name}" (id ${id.pmId})` });
|
|
282
|
+
(0, LogService_1.logInfo)(`Restart requested via monitor by "${login}" for pm2 process "${id.name}" (id ${id.pmId})`, "Monitor");
|
|
283
|
+
const graceMs = 750;
|
|
284
|
+
setTimeout(() => {
|
|
285
|
+
(0, LogService_1.logInfo)(`Exiting now for pm2 restart (requested by "${login}")`, "Monitor");
|
|
286
|
+
process.exit(0);
|
|
287
|
+
}, graceMs);
|
|
288
|
+
return { data: { restarting: true, name: id.name, pmId: id.pmId, by: login, graceMs } };
|
|
289
|
+
}
|
|
290
|
+
async httpstats(req) {
|
|
291
|
+
await this.requireAccess(req, "dashboard");
|
|
292
|
+
return { data: Http_1.Http.getHttpStats() };
|
|
293
|
+
}
|
|
294
|
+
async inventory(req) {
|
|
295
|
+
await this.requireAccess(req, "dashboard");
|
|
296
|
+
const now = Date.now();
|
|
297
|
+
const services = BaseService_1.BaseService.allInstances.map(s => ({
|
|
298
|
+
className: s.constructor.name,
|
|
299
|
+
name: s.getName(),
|
|
300
|
+
initialized: s.initializedAt !== null,
|
|
301
|
+
createdAt: s.createdAt,
|
|
302
|
+
initializedAt: s.initializedAt,
|
|
303
|
+
applicationReadyAt: s.applicationReadyAt,
|
|
304
|
+
uptimeSec: s.initializedAt ? Math.round((now - s.initializedAt) / 1000) : null,
|
|
305
|
+
}));
|
|
306
|
+
const endpoints = BaseEndpoint_1.BaseEndpoint.allInstances.map(e => e.getInventory());
|
|
307
|
+
return {
|
|
308
|
+
data: {
|
|
309
|
+
services,
|
|
310
|
+
endpoints,
|
|
311
|
+
counts: {
|
|
312
|
+
services: services.length,
|
|
313
|
+
endpoints: endpoints.length,
|
|
314
|
+
totalHandlers: endpoints.reduce((sum, e) => sum + e.handlerCount, 0),
|
|
315
|
+
},
|
|
316
|
+
entrypoint: BaseEndpoint_1.BaseEndpoint.getEntryPoint(),
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
async metrics(req) {
|
|
321
|
+
await this.requireAccess(req, "dashboard");
|
|
322
|
+
const result = await MonitorService_1.REQ_STAT.request(req.data);
|
|
323
|
+
return { data: result };
|
|
324
|
+
}
|
|
325
|
+
async threats(req) {
|
|
326
|
+
await this.requireAccess(req, "logs");
|
|
327
|
+
const limit = Number(req.data.limit) || 50;
|
|
328
|
+
const snap = ThreatMonitor_1.ThreatMonitor.snapshot(limit);
|
|
329
|
+
return { data: { ...snap, offenders: snap.offenders.map(o => ({ ...o, blocked: BlockedIps_1.BlockedIps.isBlocked(o.ip) })) } };
|
|
330
|
+
}
|
|
331
|
+
async blocked(req) {
|
|
332
|
+
await this.requireAccess(req, "logs");
|
|
333
|
+
return { data: BlockedIps_1.BlockedIps.snapshot() };
|
|
334
|
+
}
|
|
335
|
+
async block(req) {
|
|
336
|
+
const login = await this.requireAccess(req, "admin");
|
|
337
|
+
const ip = String(req.data.ip ?? "").trim();
|
|
338
|
+
const built = IpAllowList_1.IpAllowList.build([ip]);
|
|
339
|
+
if (!ip || built.error)
|
|
340
|
+
throw { ...DefaultErrors_1.default.BAD_REQUEST, details: built.error ?? "ip is required" };
|
|
341
|
+
if (IpAllowList_1.IpAllowList.allows(built.list, "127.0.0.1") || IpAllowList_1.IpAllowList.allows(built.list, "::1"))
|
|
342
|
+
throw { ...DefaultErrors_1.default.BAD_REQUEST, details: "Loopback can't be blocked" };
|
|
343
|
+
if (req.ip && IpAllowList_1.IpAllowList.allows(built.list, req.ip))
|
|
344
|
+
throw { ...DefaultErrors_1.default.BAD_REQUEST, details: `This would block your own address (${req.ip})` };
|
|
345
|
+
const hours = Number(req.data.hours) || 0;
|
|
346
|
+
if (hours < 0 || hours > 24 * 365)
|
|
347
|
+
throw { ...DefaultErrors_1.default.BAD_REQUEST, details: "hours must be between 0 (permanent) and 8760" };
|
|
348
|
+
const entry = {
|
|
349
|
+
ip,
|
|
350
|
+
...(req.data.reason ? { reason: String(req.data.reason).slice(0, 200) } : {}),
|
|
351
|
+
until: hours ? new Date(Date.now() + hours * 3600_000).toISOString() : null,
|
|
352
|
+
by: login,
|
|
353
|
+
at: new Date().toISOString(),
|
|
354
|
+
};
|
|
355
|
+
try {
|
|
356
|
+
BlockedIps_1.BlockedIps.add(entry);
|
|
357
|
+
}
|
|
358
|
+
catch (e) {
|
|
359
|
+
throw { ...DefaultErrors_1.default.INTERNAL_SERVER_ERROR, details: e?.message ?? String(e) };
|
|
360
|
+
}
|
|
361
|
+
(0, LogService_1.logWarn)(`Monitor: "${login}" blocked ${ip}${hours ? ` for ${hours} h` : " permanently"}${entry.reason ? ` — ${entry.reason}` : ""}`);
|
|
362
|
+
return { data: BlockedIps_1.BlockedIps.snapshot() };
|
|
363
|
+
}
|
|
364
|
+
async unblock(req) {
|
|
365
|
+
const login = await this.requireAccess(req, "admin");
|
|
366
|
+
const ip = String(req.data.ip ?? "").trim();
|
|
367
|
+
let removed;
|
|
368
|
+
try {
|
|
369
|
+
removed = BlockedIps_1.BlockedIps.remove(ip);
|
|
370
|
+
}
|
|
371
|
+
catch (e) {
|
|
372
|
+
throw { ...DefaultErrors_1.default.INTERNAL_SERVER_ERROR, details: e?.message ?? String(e) };
|
|
373
|
+
}
|
|
374
|
+
if (!removed)
|
|
375
|
+
throw { ...DefaultErrors_1.default.NOT_FOUND, details: `${ip} is not in the list` };
|
|
376
|
+
(0, LogService_1.logWarn)(`Monitor: "${login}" unblocked ${ip}`);
|
|
377
|
+
return { data: BlockedIps_1.BlockedIps.snapshot() };
|
|
378
|
+
}
|
|
379
|
+
async logfiles(req) {
|
|
380
|
+
await this.requireAccess(req, "logs");
|
|
381
|
+
return { data: await (0, LogFiles_1.listLogSources)(this.apiServiceOptions.logFiles) };
|
|
382
|
+
}
|
|
383
|
+
async logtail(req) {
|
|
384
|
+
await this.requireAccess(req, "logs");
|
|
385
|
+
const num = (v) => (v === undefined || v === null || v === "" ? undefined : Number(v));
|
|
386
|
+
try {
|
|
387
|
+
return { data: await (0, LogFiles_1.tailLog)(req.data.source, this.apiServiceOptions.logFiles, {
|
|
388
|
+
lines: num(req.data.lines),
|
|
389
|
+
since: num(req.data.since),
|
|
390
|
+
filter: req.data.filter,
|
|
391
|
+
}) };
|
|
392
|
+
}
|
|
393
|
+
catch (e) {
|
|
394
|
+
const details = e?.code === "ENOENT" ? "log file not found"
|
|
395
|
+
: e?.code === "EACCES" ? "permission denied: the node process user can't read this file (nginx logs are usually root:adm 0640 — add the user to the adm group or point access_log to a readable file)"
|
|
396
|
+
: String(e?.message ?? e);
|
|
397
|
+
throw { ...DefaultErrors_1.default.BAD_REQUEST, details };
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
async metricsWeeks(req) {
|
|
401
|
+
await this.requireAccess(req, "dashboard");
|
|
402
|
+
return { data: await MonitorService_1.REQ_STAT_WEEKS.request() };
|
|
403
|
+
}
|
|
404
|
+
async metricsWeek(req) {
|
|
405
|
+
await this.requireAccess(req, "dashboard");
|
|
406
|
+
return { data: await MonitorService_1.REQ_STAT_WEEK.request({ weekKey: req.data.weekKey }) };
|
|
407
|
+
}
|
|
408
|
+
async connections(req) {
|
|
409
|
+
await this.requireAccess(req, "dashboard");
|
|
410
|
+
return { data: Http_1.Http.getActiveConnectionsSnapshot() };
|
|
411
|
+
}
|
|
412
|
+
async db(req) {
|
|
413
|
+
await this.requireAccess(req, "dashboard");
|
|
414
|
+
return { data: DBService_1.DBService.healthcheck(req.data.range) };
|
|
415
|
+
}
|
|
416
|
+
async requireAccess(req, capability) {
|
|
417
|
+
const login = await this.checkAuthentication(req);
|
|
418
|
+
const users = await APIService_1.REQ_MONITOR_USERS.request();
|
|
419
|
+
const user = users?.find(u => u?.login === login);
|
|
420
|
+
if (!user) {
|
|
421
|
+
MonitorAuth_1.MonitorAuth.revokeAllFor(login);
|
|
422
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "User no longer has monitor access" };
|
|
423
|
+
}
|
|
424
|
+
if (!MonitorAuth_1.MonitorAuth.roleAllows(user.role, capability)) {
|
|
425
|
+
const { role } = MonitorAuth_1.MonitorAuth.describeRole(user?.role);
|
|
426
|
+
(0, LogService_1.logWarn)(`Monitor access denied: "${login}" (role ${role}) tried a "${capability}" endpoint`);
|
|
427
|
+
throw { ...DefaultErrors_1.default.FORBIDDEN, details: `Role "${role}" is not allowed to access ${capability} endpoints` };
|
|
428
|
+
}
|
|
429
|
+
return login;
|
|
430
|
+
}
|
|
431
|
+
async checkAuthentication(req) {
|
|
432
|
+
const users = await APIService_1.REQ_MONITOR_USERS.request();
|
|
433
|
+
if (!users || users.length == 0)
|
|
434
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED };
|
|
435
|
+
const header = req.headers['authorization'];
|
|
436
|
+
if (!header)
|
|
437
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "No authorization header found" };
|
|
438
|
+
const token = header.split(" ").pop() ?? "";
|
|
439
|
+
if (!token || token.length < 32)
|
|
440
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "Wrong authorization header" };
|
|
441
|
+
const session = MonitorAuth_1.MonitorAuth.touchSession(token);
|
|
442
|
+
if (!session)
|
|
443
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "Session is invalid or expired" };
|
|
444
|
+
return session.login;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
exports.Monitor = Monitor;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { IMonitorUser } from "../APIService";
|
|
2
|
+
export interface IMonitorSession {
|
|
3
|
+
token: string;
|
|
4
|
+
login: string;
|
|
5
|
+
createdAt: number;
|
|
6
|
+
lastSeenAt: number;
|
|
7
|
+
}
|
|
8
|
+
export type TMonitorRole = "admin" | "it" | "analytic";
|
|
9
|
+
export type TMonitorCapability = "dashboard" | "logs" | "admin";
|
|
10
|
+
export declare class MonitorAuth {
|
|
11
|
+
private static readonly ROLE_CAPS;
|
|
12
|
+
static roleAllows(role: string | undefined | null, capability: TMonitorCapability): boolean;
|
|
13
|
+
static describeRole(role: string | undefined | null): {
|
|
14
|
+
role: string;
|
|
15
|
+
capabilities: TMonitorCapability[];
|
|
16
|
+
};
|
|
17
|
+
private static authFile;
|
|
18
|
+
private static projectKey;
|
|
19
|
+
private static enrolled;
|
|
20
|
+
private static storeLoaded;
|
|
21
|
+
private static fileSafe;
|
|
22
|
+
static configure(opts?: {
|
|
23
|
+
authFile?: string | null;
|
|
24
|
+
authDir?: string | null;
|
|
25
|
+
projectName?: string;
|
|
26
|
+
}): void;
|
|
27
|
+
private static storeHash;
|
|
28
|
+
private static refusedHash;
|
|
29
|
+
private static storeWatcher;
|
|
30
|
+
private static storePoll;
|
|
31
|
+
private static storeDebounce;
|
|
32
|
+
private static missingSince;
|
|
33
|
+
private static sectionOf;
|
|
34
|
+
private static loadStore;
|
|
35
|
+
private static reloadStore;
|
|
36
|
+
private static watchStore;
|
|
37
|
+
private static stopWatchingStore;
|
|
38
|
+
private static saveEnrollment;
|
|
39
|
+
static secretFor(user: IMonitorUser): string | null;
|
|
40
|
+
static isEnrolled(user: IMonitorUser): boolean;
|
|
41
|
+
static MIN_PASSWORD_LENGTH: number;
|
|
42
|
+
static SESSION_IDLE_MS: number;
|
|
43
|
+
static SESSION_MAX_MS: number;
|
|
44
|
+
static MAX_FAILED_ATTEMPTS: number;
|
|
45
|
+
static LOCKOUT_MS: number;
|
|
46
|
+
private static sessions;
|
|
47
|
+
private static failures;
|
|
48
|
+
private static usedTotpCounter;
|
|
49
|
+
static passwordPolicyError(password: string | undefined | null): string | null;
|
|
50
|
+
static compliantUsers(users: IMonitorUser[]): IMonitorUser[];
|
|
51
|
+
static policyReportFor(users: IMonitorUser[]): string[];
|
|
52
|
+
static PLAINTEXT_ERROR: string;
|
|
53
|
+
static plaintextLogins(users: IMonitorUser[]): string[];
|
|
54
|
+
private static base32Decode;
|
|
55
|
+
private static hotp;
|
|
56
|
+
static verifyTotp(login: string, secretBase32: string, code: string): string | null;
|
|
57
|
+
private static base32Encode;
|
|
58
|
+
static generateTotpSecret(login: string, issuer?: string): {
|
|
59
|
+
secret: string;
|
|
60
|
+
uri: string;
|
|
61
|
+
};
|
|
62
|
+
static lockoutRemainingMs(login: string): number;
|
|
63
|
+
private static registerFailure;
|
|
64
|
+
private static clearFailures;
|
|
65
|
+
private static sameSecret;
|
|
66
|
+
static authenticate(users: IMonitorUser[], login: string, password: string, totp?: string): Promise<{
|
|
67
|
+
user?: IMonitorUser;
|
|
68
|
+
error?: string;
|
|
69
|
+
enrollmentRequired?: boolean;
|
|
70
|
+
}>;
|
|
71
|
+
private static pendingEnrollments;
|
|
72
|
+
static ENROLLMENT_TTL_MS: number;
|
|
73
|
+
static beginEnrollment(login: string, issuer?: string, label?: string): {
|
|
74
|
+
token: string;
|
|
75
|
+
secret: string;
|
|
76
|
+
uri: string;
|
|
77
|
+
};
|
|
78
|
+
static completeEnrollment(token: string, code: string): {
|
|
79
|
+
login?: string;
|
|
80
|
+
error?: string;
|
|
81
|
+
};
|
|
82
|
+
private static purgeSessions;
|
|
83
|
+
static createSession(login: string): IMonitorSession;
|
|
84
|
+
static touchSession(token: string): IMonitorSession | null;
|
|
85
|
+
static revokeSession(token: string): void;
|
|
86
|
+
static revokeAllFor(login: string): void;
|
|
87
|
+
}
|