namirasoft-node 1.4.67 → 1.4.69
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/package.json +43 -43
- package/src/AnomalyDetector.ts +84 -84
- package/src/BaseApplication.ts +432 -432
- package/src/BaseApplicationLink.ts +6 -6
- package/src/BaseController.ts +205 -205
- package/src/BaseCron.ts +54 -54
- package/src/BaseDatabase.ts +45 -45
- package/src/BaseEmailService.ts +38 -38
- package/src/BaseFilterItemBuilder.ts +174 -174
- package/src/BaseFilterItemBuilderDatabase.ts +26 -26
- package/src/BaseFilterItemBuilderObject.ts +88 -88
- package/src/BaseTable.ts +132 -132
- package/src/CommandOperation.ts +32 -32
- package/src/EmptyDatabase.ts +11 -11
- package/src/GmailService.ts +22 -22
- package/src/IPOperation.ts +38 -38
- package/src/Meta.ts +41 -41
- package/src/OTPOperation.ts +84 -84
- package/src/RequestHeaderService.ts +27 -27
- package/src/SMTPService.ts +26 -26
- package/src/ServerToServerOperation.ts +23 -23
- package/src/index.ts +19 -19
package/package.json
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "namirasoft-node",
|
|
3
|
-
"title": "Namirasoft Node NPM Package",
|
|
4
|
-
"description": "Namira Software Corporation Node NPM Package",
|
|
5
|
-
"icon": "logo.png",
|
|
6
|
-
"logo": "https://static.namirasoft.com/image/namirasoft/site/logo/base.png",
|
|
7
|
-
"language": "ts",
|
|
8
|
-
"framework": "npm",
|
|
9
|
-
"application": "package",
|
|
10
|
-
"private": false,
|
|
11
|
-
"version": "1.4.
|
|
12
|
-
"author": "Amir Abolhasani",
|
|
13
|
-
"license": "MIT",
|
|
14
|
-
"main": "./dist/index.js",
|
|
15
|
-
"types": "./dist/index.d.ts",
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": ""
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"@supercharge/request-ip": "^1.2.0",
|
|
21
|
-
"@types/cors": "^2.8.17",
|
|
22
|
-
"@types/express": "^5.0.0",
|
|
23
|
-
"@types/node": "^22.13.1",
|
|
24
|
-
"@types/node-cron": "^3.0.11",
|
|
25
|
-
"@types/nodemailer": "^6.4.17",
|
|
26
|
-
"@types/nodemailer-smtp-transport": "^2.7.8",
|
|
27
|
-
"@types/serve-index": "^1.9.4",
|
|
28
|
-
"@types/swagger-jsdoc": "^6.0.4",
|
|
29
|
-
"@types/swagger-ui-express": "^4.1.7",
|
|
30
|
-
"cors": "^2.8.5",
|
|
31
|
-
"express": "^4.21.2",
|
|
32
|
-
"joi": "^17.13.3",
|
|
33
|
-
"namirasoft-core": "^1.4.
|
|
34
|
-
"namirasoft-log": "^1.4.19",
|
|
35
|
-
"namirasoft-schema": "^1.4.25",
|
|
36
|
-
"node-cron": "^3.0.3",
|
|
37
|
-
"nodemailer": "^6.10.0",
|
|
38
|
-
"nodemailer-smtp-transport": "^2.7.4",
|
|
39
|
-
"request-ip": "^3.3.0",
|
|
40
|
-
"serve-index": "^1.9.1",
|
|
41
|
-
"swagger-jsdoc": "^6.2.8",
|
|
42
|
-
"swagger-ui-express": "^5.0.1"
|
|
43
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "namirasoft-node",
|
|
3
|
+
"title": "Namirasoft Node NPM Package",
|
|
4
|
+
"description": "Namira Software Corporation Node NPM Package",
|
|
5
|
+
"icon": "logo.png",
|
|
6
|
+
"logo": "https://static.namirasoft.com/image/namirasoft/site/logo/base.png",
|
|
7
|
+
"language": "ts",
|
|
8
|
+
"framework": "npm",
|
|
9
|
+
"application": "package",
|
|
10
|
+
"private": false,
|
|
11
|
+
"version": "1.4.69",
|
|
12
|
+
"author": "Amir Abolhasani",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": ""
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@supercharge/request-ip": "^1.2.0",
|
|
21
|
+
"@types/cors": "^2.8.17",
|
|
22
|
+
"@types/express": "^5.0.0",
|
|
23
|
+
"@types/node": "^22.13.1",
|
|
24
|
+
"@types/node-cron": "^3.0.11",
|
|
25
|
+
"@types/nodemailer": "^6.4.17",
|
|
26
|
+
"@types/nodemailer-smtp-transport": "^2.7.8",
|
|
27
|
+
"@types/serve-index": "^1.9.4",
|
|
28
|
+
"@types/swagger-jsdoc": "^6.0.4",
|
|
29
|
+
"@types/swagger-ui-express": "^4.1.7",
|
|
30
|
+
"cors": "^2.8.5",
|
|
31
|
+
"express": "^4.21.2",
|
|
32
|
+
"joi": "^17.13.3",
|
|
33
|
+
"namirasoft-core": "^1.4.48",
|
|
34
|
+
"namirasoft-log": "^1.4.19",
|
|
35
|
+
"namirasoft-schema": "^1.4.25",
|
|
36
|
+
"node-cron": "^3.0.3",
|
|
37
|
+
"nodemailer": "^6.10.0",
|
|
38
|
+
"nodemailer-smtp-transport": "^2.7.4",
|
|
39
|
+
"request-ip": "^3.3.0",
|
|
40
|
+
"serve-index": "^1.9.1",
|
|
41
|
+
"swagger-jsdoc": "^6.2.8",
|
|
42
|
+
"swagger-ui-express": "^5.0.1"
|
|
43
|
+
}
|
|
44
44
|
}
|
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
|
}
|