-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathindex.js
80 lines (65 loc) · 1.78 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const lib = require("./lib");
const defaultParams = require("./lib/defaults");
const ddos = function(params) {
if (!params) params = {};
params = Object.assign({}, defaultParams(), params);
params.maxcount = params.limit * 2;
if (params.testmode) {
console.log("ddos: starting params: ", params);
}
this.table = {};
this.timer = setInterval(this.update.bind(this), params.checkinterval * 1000);
this.express = this.handle.bind(this);
this.middleware = this.handle.bind(this);
this.params = params;
};
ddos.prototype.addWhitelist = lib.addWhitelist;
ddos.prototype.stop = lib.stop;
ddos.prototype.end = ddos.prototype.stop;
ddos.prototype.update = lib.update;
ddos.prototype.handle = lib.handle;
ddos.prototype.express = lib.handle;
ddos.prototype.koa = function() {
return function(ctx, next) {
var req = ctx.req;
var res = ctx.res;
return lib._handle(this.params,this.table, req)
.then(() => {
return next()
})
};
};
ddos.prototype.hapi17 = function (request, h) {
const req = request.raw.req;
const params = this.params;
const table = this.table;
return lib._handle(params, table, req)
.then(() => {
return h.continue
})
.catch((e) => {
if (e.action === "respond") {
const response = h.response(e.message);
response.takeover();
response.code(e.code);
return response;
}
})
}
ddos.prototype.hapi = function(request, reply) {
const req = request.raw.req;
const res = reply;
const table = this.table;
const params = this.params;
return lib._handle(params, table, req)
.then(() => {
return reply.continue();
})
.catch((e) => {
if (e.action === "respond") {
return res(e.message).code(e.code);
}
})
};
ddos.prototype.ipv4re = lib.ipv4re;
module.exports = exports = ddos;