badmfck-api-server 1.5.3 → 1.5.4
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.
@@ -12,6 +12,9 @@ const DefaultErrors_1 = __importDefault(require("./structures/DefaultErrors"));
|
|
12
12
|
const badmfck_signal_1 = require("badmfck-signal");
|
13
13
|
const LogService_1 = require("./LogService");
|
14
14
|
const Monitor_1 = require("./monitor/Monitor");
|
15
|
+
const path_1 = __importDefault(require("path"));
|
16
|
+
const crypto_1 = __importDefault(require("crypto"));
|
17
|
+
const fs_1 = __importDefault(require("fs"));
|
15
18
|
function getDefaultOptions() {
|
16
19
|
return {
|
17
20
|
port: 8091,
|
@@ -44,9 +47,10 @@ async function Initializer(services) {
|
|
44
47
|
exports.Initializer = Initializer;
|
45
48
|
class APIService extends BaseService_1.BaseService {
|
46
49
|
static nextLogID = 0;
|
47
|
-
version = "1.5.
|
50
|
+
version = "1.5.4";
|
48
51
|
options;
|
49
52
|
monitor;
|
53
|
+
monitorIndexFile;
|
50
54
|
netLog = [];
|
51
55
|
constructor(options) {
|
52
56
|
super('HTTP Service');
|
@@ -60,6 +64,11 @@ class APIService extends BaseService_1.BaseService {
|
|
60
64
|
this.monitor = new Monitor_1.Monitor();
|
61
65
|
this.options.endpoints.push(this.monitor);
|
62
66
|
console.log("Service Monitor initialized");
|
67
|
+
console.log("monitor links:");
|
68
|
+
for (let i of this.options.monitor) {
|
69
|
+
const hash = crypto_1.default.createHash("sha256").update(i.login + i.password).digest().toString("hex");
|
70
|
+
console.log("/sm-" + hash);
|
71
|
+
}
|
63
72
|
}
|
64
73
|
}
|
65
74
|
async init() {
|
@@ -189,6 +198,40 @@ class APIService extends BaseService_1.BaseService {
|
|
189
198
|
}
|
190
199
|
app.use((req, res, next) => {
|
191
200
|
const tme = +new Date();
|
201
|
+
if (this.monitor && this.options && this.options.monitor) {
|
202
|
+
if (req.method === "GET") {
|
203
|
+
let monitorRequest = false;
|
204
|
+
for (let i of this.options.monitor) {
|
205
|
+
const hash = crypto_1.default.createHash("sha256").update(i.login + i.password).digest().toString("hex");
|
206
|
+
if (req.originalUrl.endsWith("/sm-" + hash)) {
|
207
|
+
monitorRequest = true;
|
208
|
+
break;
|
209
|
+
}
|
210
|
+
}
|
211
|
+
if (monitorRequest) {
|
212
|
+
const date = new Date();
|
213
|
+
try {
|
214
|
+
if (!this.monitorIndexFile)
|
215
|
+
this.monitorIndexFile = fs_1.default.readFileSync(path_1.default.resolve(__dirname, "monitor", "index.html"));
|
216
|
+
res.setHeader("Content-Type", "text/html");
|
217
|
+
res.setHeader("Content-Length", this.monitorIndexFile.byteLength);
|
218
|
+
res.status(200).send(this.monitorIndexFile);
|
219
|
+
}
|
220
|
+
catch (e) {
|
221
|
+
this.sendResponse(res, {
|
222
|
+
error: {
|
223
|
+
code: 10002,
|
224
|
+
message: "Internal server error",
|
225
|
+
details: `${e}`
|
226
|
+
},
|
227
|
+
data: null,
|
228
|
+
httpStatus: 500
|
229
|
+
}, tme, req.path);
|
230
|
+
}
|
231
|
+
return;
|
232
|
+
}
|
233
|
+
}
|
234
|
+
}
|
192
235
|
this.sendResponse(res, {
|
193
236
|
error: DefaultErrors_1.default.UNKNOWN_REQUEST,
|
194
237
|
data: null,
|
@@ -3,11 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.Monitor = void 0;
|
6
|
+
exports.Monitor = exports.indexFilePath = void 0;
|
7
7
|
const APIService_1 = require("../APIService");
|
8
8
|
const BaseEndpoint_1 = require("../BaseEndpoint");
|
9
9
|
const LogService_1 = require("../LogService");
|
10
10
|
const crypto_1 = __importDefault(require("crypto"));
|
11
|
+
const path_1 = __importDefault(require("path"));
|
12
|
+
exports.indexFilePath = path_1.default.resolve(__dirname, "index.html");
|
11
13
|
class Monitor extends BaseEndpoint_1.BaseEndpoint {
|
12
14
|
ignoreHttpLogging = true;
|
13
15
|
startedAt = new Date();
|