namirasoft-node 1.1.3 → 1.1.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/.gitlab-ci.yml +14 -0
- package/package.json +3 -3
- package/public/index.html +109 -109
- package/src/AnomalyDetector.ts +84 -84
- package/src/BaseApplication.ts +186 -186
- package/src/BaseApplicationLink.ts +6 -6
- package/src/BaseController.ts +131 -131
- package/src/BaseDatabase.ts +4 -4
- package/src/BaseMySqlDatabase.ts +7 -7
- package/src/BaseSequelizeDatabase.ts +83 -83
- package/src/BaseSequelizeModel.ts +4 -4
- package/src/BaseSequelizeTable.ts +54 -54
- package/src/BaseTable.ts +21 -21
- package/src/EmailService.ts +96 -96
- package/src/EnvService.ts +21 -21
- package/src/IPOperation.ts +38 -38
- package/src/Meta.ts +34 -34
- package/src/OTPOperation.ts +64 -64
- package/src/RequestHeaderService.ts +22 -22
- package/src/ServerToServerOperation.ts +23 -23
- package/src/index.ts +16 -16
- package/tsconfig.json +29 -29
package/.gitlab-ci.yml
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "namirasoft-node",
|
|
3
3
|
"description": "Namira Software Corporation Node NPM Package",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.5",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {},
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"cors": "^2.8.5",
|
|
19
19
|
"express": "^4.18.2",
|
|
20
20
|
"joi": "^17.11.0",
|
|
21
|
-
"namirasoft-core": "^1.1.
|
|
22
|
-
"namirasoft-log": "^1.1.
|
|
21
|
+
"namirasoft-core": "^1.1.3",
|
|
22
|
+
"namirasoft-log": "^1.1.1",
|
|
23
23
|
"nodemailer": "^6.9.7",
|
|
24
24
|
"nodemailer-smtp-transport": "^2.7.4",
|
|
25
25
|
"request-ip": "^3.3.0",
|
package/public/index.html
CHANGED
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="UTF-8">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
-
<title>@title</title>
|
|
8
|
-
<!-- Include Bootstrap CSS -->
|
|
9
|
-
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
|
10
|
-
<link rel="icon" type="image/x-icon" href="@logo">
|
|
11
|
-
<meta property="og:image" content="@logo">
|
|
12
|
-
<style>
|
|
13
|
-
body {
|
|
14
|
-
background-color: #f8f9fa;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.header {
|
|
18
|
-
text-align: center;
|
|
19
|
-
padding: 20px;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.border {
|
|
23
|
-
background-color: #fff;
|
|
24
|
-
padding: 20px;
|
|
25
|
-
border-radius: 10px;
|
|
26
|
-
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.company {
|
|
30
|
-
text-align: center;
|
|
31
|
-
margin-top: 20px;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
img {
|
|
35
|
-
width: 64px;
|
|
36
|
-
height: 64px;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.card {
|
|
40
|
-
display: flex;
|
|
41
|
-
flex-direction: row;
|
|
42
|
-
align-content: center;
|
|
43
|
-
align-items: center;
|
|
44
|
-
gap: 16px;
|
|
45
|
-
width: 100%;
|
|
46
|
-
min-height: 160px;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
.page-parent {
|
|
50
|
-
min-height: 100vh;
|
|
51
|
-
display: flex;
|
|
52
|
-
flex-direction: column;
|
|
53
|
-
justify-content: space-between;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.big-logo {
|
|
57
|
-
width: 128px;
|
|
58
|
-
height: 128px;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
h3 {
|
|
62
|
-
font-size: 1.25rem;
|
|
63
|
-
}
|
|
64
|
-
</style>
|
|
65
|
-
</head>
|
|
66
|
-
|
|
67
|
-
<body>
|
|
68
|
-
<div class="container page-parent">
|
|
69
|
-
<div>
|
|
70
|
-
<div class="header">
|
|
71
|
-
<img src="@logo" alt="Project Logo" class="img-fluid big-logo">
|
|
72
|
-
<h1>@title</h1>
|
|
73
|
-
<h5>@description</h5>
|
|
74
|
-
</div>
|
|
75
|
-
|
|
76
|
-
<div class="content container">
|
|
77
|
-
<div class="row gy-5">
|
|
78
|
-
<@row>
|
|
79
|
-
<div class="p-2 col-md-6">
|
|
80
|
-
<a target="_blank" href="@row_url" class="border card">
|
|
81
|
-
<img src="@row_logo" class="img-fluid">
|
|
82
|
-
<div class="content">
|
|
83
|
-
<h2>@row_name</h2>
|
|
84
|
-
<p>@row_description</p>
|
|
85
|
-
</div>
|
|
86
|
-
</a>
|
|
87
|
-
</div>
|
|
88
|
-
</@row>
|
|
89
|
-
</div>
|
|
90
|
-
</div>
|
|
91
|
-
</div>
|
|
92
|
-
<div class="company">
|
|
93
|
-
<a href="https://namirasoft.com" target="_blank">
|
|
94
|
-
<img src="https://static.namirasoft.com/logo/namirasoft/base.png" alt="Company Logo"
|
|
95
|
-
class="img-fluid big-logo">
|
|
96
|
-
<h3>Namira Software Corporation</h3>
|
|
97
|
-
</a>
|
|
98
|
-
<p>©Copyright 2010 to 2023 <a target="_blank" href="https://namirasoft.com">Namira Software Corporation</a>.
|
|
99
|
-
All rights
|
|
100
|
-
reserved.</p>
|
|
101
|
-
</div>
|
|
102
|
-
</div>
|
|
103
|
-
|
|
104
|
-
<!-- Include Bootstrap JS and jQuery -->
|
|
105
|
-
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
|
106
|
-
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
|
|
107
|
-
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
|
108
|
-
</body>
|
|
109
|
-
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>@title</title>
|
|
8
|
+
<!-- Include Bootstrap CSS -->
|
|
9
|
+
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
|
10
|
+
<link rel="icon" type="image/x-icon" href="@logo">
|
|
11
|
+
<meta property="og:image" content="@logo">
|
|
12
|
+
<style>
|
|
13
|
+
body {
|
|
14
|
+
background-color: #f8f9fa;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.header {
|
|
18
|
+
text-align: center;
|
|
19
|
+
padding: 20px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.border {
|
|
23
|
+
background-color: #fff;
|
|
24
|
+
padding: 20px;
|
|
25
|
+
border-radius: 10px;
|
|
26
|
+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.company {
|
|
30
|
+
text-align: center;
|
|
31
|
+
margin-top: 20px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
img {
|
|
35
|
+
width: 64px;
|
|
36
|
+
height: 64px;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.card {
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-direction: row;
|
|
42
|
+
align-content: center;
|
|
43
|
+
align-items: center;
|
|
44
|
+
gap: 16px;
|
|
45
|
+
width: 100%;
|
|
46
|
+
min-height: 160px;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.page-parent {
|
|
50
|
+
min-height: 100vh;
|
|
51
|
+
display: flex;
|
|
52
|
+
flex-direction: column;
|
|
53
|
+
justify-content: space-between;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.big-logo {
|
|
57
|
+
width: 128px;
|
|
58
|
+
height: 128px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
h3 {
|
|
62
|
+
font-size: 1.25rem;
|
|
63
|
+
}
|
|
64
|
+
</style>
|
|
65
|
+
</head>
|
|
66
|
+
|
|
67
|
+
<body>
|
|
68
|
+
<div class="container page-parent">
|
|
69
|
+
<div>
|
|
70
|
+
<div class="header">
|
|
71
|
+
<img src="@logo" alt="Project Logo" class="img-fluid big-logo">
|
|
72
|
+
<h1>@title</h1>
|
|
73
|
+
<h5>@description</h5>
|
|
74
|
+
</div>
|
|
75
|
+
|
|
76
|
+
<div class="content container">
|
|
77
|
+
<div class="row gy-5">
|
|
78
|
+
<@row>
|
|
79
|
+
<div class="p-2 col-md-6">
|
|
80
|
+
<a target="_blank" href="@row_url" class="border card">
|
|
81
|
+
<img src="@row_logo" class="img-fluid">
|
|
82
|
+
<div class="content">
|
|
83
|
+
<h2>@row_name</h2>
|
|
84
|
+
<p>@row_description</p>
|
|
85
|
+
</div>
|
|
86
|
+
</a>
|
|
87
|
+
</div>
|
|
88
|
+
</@row>
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
<div class="company">
|
|
93
|
+
<a href="https://namirasoft.com" target="_blank">
|
|
94
|
+
<img src="https://static.namirasoft.com/logo/namirasoft/base.png" alt="Company Logo"
|
|
95
|
+
class="img-fluid big-logo">
|
|
96
|
+
<h3>Namira Software Corporation</h3>
|
|
97
|
+
</a>
|
|
98
|
+
<p>©Copyright 2010 to 2023 <a target="_blank" href="https://namirasoft.com">Namira Software Corporation</a>.
|
|
99
|
+
All rights
|
|
100
|
+
reserved.</p>
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
|
|
104
|
+
<!-- Include Bootstrap JS and jQuery -->
|
|
105
|
+
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
|
106
|
+
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
|
|
107
|
+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
|
108
|
+
</body>
|
|
109
|
+
|
|
110
110
|
</html>
|
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
|
}
|