namirasoft-node 1.3.71 → 1.3.73
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/dist/BaseTable.d.ts +2 -0
- package/dist/BaseTable.js +10 -0
- package/dist/BaseTable.js.map +1 -1
- package/dist/CMDOperation.d.ts +4 -0
- package/dist/CMDOperation.js +43 -0
- package/dist/CMDOperation.js.map +1 -0
- package/dist/EmailService.d.ts +16 -0
- package/dist/EmailService.js +81 -0
- package/dist/EmailService.js.map +1 -0
- package/package.json +2 -2
- package/src/AnomalyDetector.ts +84 -84
- package/src/BaseApplication.ts +435 -435
- package/src/BaseApplicationLink.ts +6 -6
- package/src/BaseController.ts +193 -193
- package/src/BaseCron.ts +54 -54
- package/src/BaseDatabase.ts +192 -192
- package/src/BaseEmailService.ts +38 -38
- package/src/BaseTable.ts +109 -97
- package/src/CommandOperation.ts +32 -32
- package/src/EmptyDatabase.ts +7 -7
- package/src/EnvService.ts +22 -22
- package/src/GmailService.ts +22 -22
- package/src/IPOperation.ts +38 -38
- package/src/Meta.ts +40 -40
- package/src/OTPOperation.ts +64 -64
- package/src/RequestHeaderService.ts +27 -27
- package/src/SMTPService.ts +26 -26
- package/src/ServerToServerOperation.ts +23 -23
- package/src/index.ts +17 -17
package/dist/BaseTable.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export declare abstract class BaseTable<D extends BaseDatabase, ModelColumnOptio
|
|
|
6
6
|
abstract getName(): string;
|
|
7
7
|
addSecureColumns(columns: string[]): void;
|
|
8
8
|
addReadOnlyColumns(columns: string[]): void;
|
|
9
|
+
getSecureColumns(): string[];
|
|
10
|
+
getReadOnlyColumns(): string[];
|
|
9
11
|
secure(obj: any): any;
|
|
10
12
|
getArraySchema(require: boolean, name?: string): ArraySchema;
|
|
11
13
|
getSchema(require: boolean, name?: string): ObjectSchema;
|
package/dist/BaseTable.js
CHANGED
|
@@ -13,6 +13,16 @@ class BaseTable {
|
|
|
13
13
|
addReadOnlyColumns(columns) {
|
|
14
14
|
columns.toString();
|
|
15
15
|
}
|
|
16
|
+
getSecureColumns() {
|
|
17
|
+
let columns = [];
|
|
18
|
+
this.addSecureColumns(columns);
|
|
19
|
+
return columns;
|
|
20
|
+
}
|
|
21
|
+
getReadOnlyColumns() {
|
|
22
|
+
let columns = [];
|
|
23
|
+
this.addReadOnlyColumns(columns);
|
|
24
|
+
return columns;
|
|
25
|
+
}
|
|
16
26
|
secure(obj) {
|
|
17
27
|
if (obj.dataValues)
|
|
18
28
|
obj = obj.dataValues;
|
package/dist/BaseTable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseTable.js","sourceRoot":"","sources":["../src/BaseTable.ts"],"names":[],"mappings":";;;AAAA,yDAAkG;AAElG,qDAAiD;AAEjD,MAAsB,SAAS;IAG3B,YAAY,QAAW;QAEnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAEM,gBAAgB,CAAC,OAAiB;QAErC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACvB,CAAC;IACM,kBAAkB,CAAC,OAAiB;QAEvC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACvB,CAAC;IACM,MAAM,CAAC,GAAQ;QAElB,IAAI,GAAG,CAAC,UAAU;YACd,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC;QACzB,IAAI,aAAa,GAAa,EAAE,CAAC;QACjC,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;QACrC,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9C,OAAO,GAAG,CAAC;IACf,CAAC;IACM,cAAc,CAAC,OAAgB,EAAE,IAAa;QAEjD,IAAI,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACxC,OAAO,IAAI,+BAAW,CAAC,OAAO,EAAE,CAAC,GA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,eAAe,CAAC,OAAgB,EAAE,IAAa;QAElD,IAAI,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACxC,IAAI,IAAI,EACR;YACI,IAAI,KAAK,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAClC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACrB,MAAM,IAAI,KAAK,CAAC,kCAAkC,GAAG,IAAI,CAAC,CAAC;YAC/D,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;SAC7B;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IACM,oBAAoB,CAAC,OAAgB,EAAE,IAAa;QAEvD,IAAI,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC9C,OAAO,IAAI,+BAAW,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3C,CAAC;IACS,eAAe,CAAC,CAAe;IAEzC,CAAC;IACM,gBAAgB,CAAC,UAAsB;QAE1C,OAAO,gCAAc,CAAC,OAAO,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACnH,CAAC;CACJ;AAzGD,8BAyGC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.OTPOperation = void 0;
|
|
13
|
+
const { exec, execSync } = require('child_process');
|
|
14
|
+
class OTPOperation {
|
|
15
|
+
static run(command, cwd) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
yield exec(command, { cwd }, (error, stdout, stderr) => {
|
|
18
|
+
if (error) {
|
|
19
|
+
console.error(`error: ${error.message}`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (stderr) {
|
|
23
|
+
console.error(`stderr: ${stderr}`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
console.log(`stdout:\n${stdout}`);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
static runSync(command, cwd) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
try {
|
|
33
|
+
return yield execSync(command, { cwd, encoding: 'utf-8' });
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error(error.stdout);
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.OTPOperation = OTPOperation;
|
|
43
|
+
//# sourceMappingURL=CMDOperation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CMDOperation.js","sourceRoot":"","sources":["../src/CMDOperation.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AACpD,MAAa,YAAY;IAErB,MAAM,CAAO,GAAG,CAAC,OAAe,EAAE,GAAuB;;YAErD,MAAM,IAAI,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;gBAEnD,IAAI,KAAK,EACT;oBACI,OAAO,CAAC,KAAK,CAAC,UAAU,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;oBACzC,OAAO;iBACV;gBACD,IAAI,MAAM,EACV;oBACI,OAAO,CAAC,KAAK,CAAC,WAAW,MAAM,EAAE,CAAC,CAAC;oBACnC,OAAO;iBACV;gBACD,OAAO,CAAC,GAAG,CAAC,YAAY,MAAM,EAAE,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;QACP,CAAC;KAAA;IACD,MAAM,CAAO,OAAO,CAAC,OAAe,EAAE,GAAuB;;YAEzD,IACA;gBACI,OAAO,MAAM,QAAQ,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;aAC9D;YAAC,OAAO,KAAU,EACnB;gBACI,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBAC5B,MAAM,KAAK,CAAC;aACf;QACL,CAAC;KAAA;CACJ;AA9BD,oCA8BC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { AttachmentLike } from "nodemailer/lib/mailer";
|
|
4
|
+
import { Readable } from "stream";
|
|
5
|
+
export declare class EmailService {
|
|
6
|
+
host: string;
|
|
7
|
+
username: string;
|
|
8
|
+
username_from: string;
|
|
9
|
+
password: string;
|
|
10
|
+
error_title: string;
|
|
11
|
+
error_recipients: string;
|
|
12
|
+
constructor(host: string, username: string, username_from: string, password: string, error_title: string, error_recipients: string);
|
|
13
|
+
sendExeption(error: Error, meta: any, callback?: (err: Error | null, info: any) => void): void;
|
|
14
|
+
sendError(title: string, message: string, callback?: (err: Error | null, info: any) => void): void;
|
|
15
|
+
send(to: string, subject: string, text: string, html?: string | Buffer | Readable | AttachmentLike | undefined, callback?: (err: Error | null, info: any) => void): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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.EmailService = void 0;
|
|
7
|
+
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
8
|
+
const nodemailer_smtp_transport_1 = __importDefault(require("nodemailer-smtp-transport"));
|
|
9
|
+
class EmailService {
|
|
10
|
+
constructor(host, username, username_from, password, error_title, error_recipients) {
|
|
11
|
+
this.host = host;
|
|
12
|
+
this.username = username;
|
|
13
|
+
this.username_from = username_from;
|
|
14
|
+
this.password = password;
|
|
15
|
+
this.error_title = error_title;
|
|
16
|
+
this.error_recipients = error_recipients;
|
|
17
|
+
}
|
|
18
|
+
sendExeption(error, meta, callback) {
|
|
19
|
+
let title = error.message;
|
|
20
|
+
let message = title;
|
|
21
|
+
if (meta)
|
|
22
|
+
message += "\r\n" + JSON.stringify(meta);
|
|
23
|
+
message += "\r\n" + error.stack;
|
|
24
|
+
this.sendError(title, message, callback);
|
|
25
|
+
}
|
|
26
|
+
sendError(title, message, callback) {
|
|
27
|
+
if (!title)
|
|
28
|
+
title = '';
|
|
29
|
+
let toks = this.error_recipients.split(',');
|
|
30
|
+
for (let i = 0; i < toks.length; i++) {
|
|
31
|
+
const email = toks[i];
|
|
32
|
+
this.send(email, this.error_title + " - " + title, message, undefined, callback);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
send(to, subject, text, html, callback) {
|
|
36
|
+
if (!this.username)
|
|
37
|
+
return;
|
|
38
|
+
if (!this.password)
|
|
39
|
+
return;
|
|
40
|
+
let transform = {};
|
|
41
|
+
if (this.host === 'gmail')
|
|
42
|
+
transform = (0, nodemailer_smtp_transport_1.default)({
|
|
43
|
+
service: 'gmail',
|
|
44
|
+
host: 'smtp.gmail.com',
|
|
45
|
+
auth: {
|
|
46
|
+
user: this.username,
|
|
47
|
+
pass: this.password
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
else
|
|
51
|
+
transform = {
|
|
52
|
+
host: this.host,
|
|
53
|
+
port: 465,
|
|
54
|
+
secure: true,
|
|
55
|
+
auth: {
|
|
56
|
+
user: this.username,
|
|
57
|
+
pass: this.password
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
let transporter = nodemailer_1.default.createTransport(transform);
|
|
61
|
+
let mailOptions = {
|
|
62
|
+
from: this.username_from,
|
|
63
|
+
to,
|
|
64
|
+
subject,
|
|
65
|
+
text,
|
|
66
|
+
html
|
|
67
|
+
};
|
|
68
|
+
if (html)
|
|
69
|
+
mailOptions.html = html;
|
|
70
|
+
transporter.sendMail(mailOptions, function (error, info) {
|
|
71
|
+
if (callback)
|
|
72
|
+
callback(error, info);
|
|
73
|
+
else {
|
|
74
|
+
if (error)
|
|
75
|
+
console.log(error);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.EmailService = EmailService;
|
|
81
|
+
//# sourceMappingURL=EmailService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmailService.js","sourceRoot":"","sources":["../src/EmailService.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAoC;AACpC,0FAAsD;AAItD,MAAa,YAAY;IAQrB,YAAY,IAAY,EAAE,QAAgB,EAAE,aAAqB,EAAE,QAAgB,EAAE,WAAmB,EAAE,gBAAwB;QAE9H,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC7C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I,CAAC,QAAQ;oBACnB,IAAI,EAAE,IAAI,CAAC,QAAQ;iBACtB;aACJ,CAAC,CAAC;;YAEH,SAAS,GAAG;gBACR,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,IAAI,EAAE,GAAG;gBACT,MAAM,EAAE,IAAI;gBACZ,IAAI,EAAE;oBACF,IAAI,EAAE,IAAI,CAAC,QAAQ;oBACnB,IAAI,EAAE,IAAI,CAAC,QAAQ;iBACtB;aACJ,CAAC;QAEN,IAAI,WAAW,GAAG,oBAAU,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;QAExD,IAAI,WAAW,GAAiB;YAC5B,IAAI,EAAE,IAAI,CAAC,aAAa;YACxB,EAAE;YACF,OAAO;YACP,IAAI;YACJ,IAAI;SACP,CAAC;QACF,IAAI,IAAI;YACJ,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC;QAE5B,WAAW,CAAC,QAAQ,CAAC,WAAW,EAAE,UAAU,KAAK,EAAE,IAAI;YAEnD,IAAI,QAAQ;gBACR,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;iBAE1B;gBACI,IAAI,KAAK;oBACL,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;aAC1B;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AA3FD,oCA2FC"}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"framework": "npm",
|
|
9
9
|
"application": "package",
|
|
10
10
|
"private": false,
|
|
11
|
-
"version": "1.3.
|
|
11
|
+
"version": "1.3.73",
|
|
12
12
|
"author": "Amir Abolhasani",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"main": "./dist/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"cors": "^2.8.5",
|
|
33
33
|
"express": "^4.19.2",
|
|
34
34
|
"joi": "^17.13.3",
|
|
35
|
-
"namirasoft-core": "^1.3.
|
|
35
|
+
"namirasoft-core": "^1.3.80",
|
|
36
36
|
"namirasoft-log": "^1.3.30",
|
|
37
37
|
"namirasoft-schema": "^1.3.16",
|
|
38
38
|
"node-cron": "^3.0.3",
|
package/src/AnomalyDetector.ts
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
export class AnomalyDetector
|
|
2
|
-
{
|
|
3
|
-
static Main: AnomalyDetector = new AnomalyDetector();
|
|
4
|
-
// configuration
|
|
5
|
-
MAX_STORAGE_SIZE = 10000;
|
|
6
|
-
MAX_STORAGE_PER_IP = 25;
|
|
7
|
-
MIN_AVG_TIME = 200;
|
|
8
|
-
MIN_DATA_REQUIRE_FOR_AVG = 4;
|
|
9
|
-
MIN_AVG_TIME_PER_URL = 400;
|
|
10
|
-
MIN_DATA_REQUIRE_FOR_AVG_PER_URL = 3;
|
|
11
|
-
TIME_FADE_RATE = 0.9;
|
|
12
|
-
|
|
13
|
-
Storage: { [ip: string]: { url: string, time: number }[] } = {};
|
|
14
|
-
Storageـurl: { [ip: string]: { [url: string]: { time: number }[] } } = {};
|
|
15
|
-
Orders: string[] = [];
|
|
16
|
-
|
|
17
|
-
private weightedAverage(array: { time: number }[], fade_rate: number)
|
|
18
|
-
{
|
|
19
|
-
let sum = 0;
|
|
20
|
-
let sum_coef = 0;
|
|
21
|
-
for (let i = 1; i < array.length; i++)
|
|
22
|
-
{
|
|
23
|
-
let diff = array[i].time - array[i - 1].time;
|
|
24
|
-
let coef = Math.pow(fade_rate, (array.length - (i + 1)));
|
|
25
|
-
sum += diff * coef;
|
|
26
|
-
sum_coef += coef;
|
|
27
|
-
}
|
|
28
|
-
return sum / sum_coef;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
isAnomaly(ip: string, url: string): boolean
|
|
32
|
-
{
|
|
33
|
-
if (!this.Storage[ip])
|
|
34
|
-
{
|
|
35
|
-
this.Storage[ip] = [];
|
|
36
|
-
this.Storageـurl[ip] = {};
|
|
37
|
-
this.Orders.push(ip);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (this.Orders.length > this.MAX_STORAGE_SIZE)
|
|
41
|
-
{
|
|
42
|
-
let index = this.Orders.shift();
|
|
43
|
-
if (index)
|
|
44
|
-
{
|
|
45
|
-
delete this.Storage[index];
|
|
46
|
-
delete this.Storageـurl[index];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (this.Storage[ip].length >= this.MAX_STORAGE_PER_IP)
|
|
51
|
-
{
|
|
52
|
-
let record = this.Storage[ip].shift(); // remove first element
|
|
53
|
-
if (record)
|
|
54
|
-
this.Storageـurl[ip][record.url].shift(); // remove first element of url array
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
this.Storage[ip].push({
|
|
58
|
-
url: url,
|
|
59
|
-
time: +new Date()
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
if (!this.Storageـurl[ip][url])
|
|
63
|
-
this.Storageـurl[ip][url] = [];
|
|
64
|
-
this.Storageـurl[ip][url].push({
|
|
65
|
-
time: +new Date()
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// check conditions
|
|
69
|
-
// simple
|
|
70
|
-
if (this.Storage[ip].length >= this.MIN_DATA_REQUIRE_FOR_AVG)
|
|
71
|
-
{
|
|
72
|
-
let avg = this.weightedAverage(this.Storage[ip], this.TIME_FADE_RATE);
|
|
73
|
-
if (avg < this.MIN_AVG_TIME)
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
// by requst url
|
|
77
|
-
if (this.Storageـurl[ip][url].length >= this.MIN_DATA_REQUIRE_FOR_AVG_PER_URL)
|
|
78
|
-
{
|
|
79
|
-
let avg = this.weightedAverage(this.Storageـurl[ip][url], this.TIME_FADE_RATE);
|
|
80
|
-
if (avg < this.MIN_AVG_TIME_PER_URL)
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
1
|
+
export class AnomalyDetector
|
|
2
|
+
{
|
|
3
|
+
static Main: AnomalyDetector = new AnomalyDetector();
|
|
4
|
+
// configuration
|
|
5
|
+
MAX_STORAGE_SIZE = 10000;
|
|
6
|
+
MAX_STORAGE_PER_IP = 25;
|
|
7
|
+
MIN_AVG_TIME = 200;
|
|
8
|
+
MIN_DATA_REQUIRE_FOR_AVG = 4;
|
|
9
|
+
MIN_AVG_TIME_PER_URL = 400;
|
|
10
|
+
MIN_DATA_REQUIRE_FOR_AVG_PER_URL = 3;
|
|
11
|
+
TIME_FADE_RATE = 0.9;
|
|
12
|
+
|
|
13
|
+
Storage: { [ip: string]: { url: string, time: number }[] } = {};
|
|
14
|
+
Storageـurl: { [ip: string]: { [url: string]: { time: number }[] } } = {};
|
|
15
|
+
Orders: string[] = [];
|
|
16
|
+
|
|
17
|
+
private weightedAverage(array: { time: number }[], fade_rate: number)
|
|
18
|
+
{
|
|
19
|
+
let sum = 0;
|
|
20
|
+
let sum_coef = 0;
|
|
21
|
+
for (let i = 1; i < array.length; i++)
|
|
22
|
+
{
|
|
23
|
+
let diff = array[i].time - array[i - 1].time;
|
|
24
|
+
let coef = Math.pow(fade_rate, (array.length - (i + 1)));
|
|
25
|
+
sum += diff * coef;
|
|
26
|
+
sum_coef += coef;
|
|
27
|
+
}
|
|
28
|
+
return sum / sum_coef;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
isAnomaly(ip: string, url: string): boolean
|
|
32
|
+
{
|
|
33
|
+
if (!this.Storage[ip])
|
|
34
|
+
{
|
|
35
|
+
this.Storage[ip] = [];
|
|
36
|
+
this.Storageـurl[ip] = {};
|
|
37
|
+
this.Orders.push(ip);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (this.Orders.length > this.MAX_STORAGE_SIZE)
|
|
41
|
+
{
|
|
42
|
+
let index = this.Orders.shift();
|
|
43
|
+
if (index)
|
|
44
|
+
{
|
|
45
|
+
delete this.Storage[index];
|
|
46
|
+
delete this.Storageـurl[index];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (this.Storage[ip].length >= this.MAX_STORAGE_PER_IP)
|
|
51
|
+
{
|
|
52
|
+
let record = this.Storage[ip].shift(); // remove first element
|
|
53
|
+
if (record)
|
|
54
|
+
this.Storageـurl[ip][record.url].shift(); // remove first element of url array
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this.Storage[ip].push({
|
|
58
|
+
url: url,
|
|
59
|
+
time: +new Date()
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (!this.Storageـurl[ip][url])
|
|
63
|
+
this.Storageـurl[ip][url] = [];
|
|
64
|
+
this.Storageـurl[ip][url].push({
|
|
65
|
+
time: +new Date()
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// check conditions
|
|
69
|
+
// simple
|
|
70
|
+
if (this.Storage[ip].length >= this.MIN_DATA_REQUIRE_FOR_AVG)
|
|
71
|
+
{
|
|
72
|
+
let avg = this.weightedAverage(this.Storage[ip], this.TIME_FADE_RATE);
|
|
73
|
+
if (avg < this.MIN_AVG_TIME)
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
// by requst url
|
|
77
|
+
if (this.Storageـurl[ip][url].length >= this.MIN_DATA_REQUIRE_FOR_AVG_PER_URL)
|
|
78
|
+
{
|
|
79
|
+
let avg = this.weightedAverage(this.Storageـurl[ip][url], this.TIME_FADE_RATE);
|
|
80
|
+
if (avg < this.MIN_AVG_TIME_PER_URL)
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
85
|
}
|