-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
177 lines (150 loc) · 4.41 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* Copyright (c) 2010-2014 BinarySEC SAS
* gatejs plugin interface [http://www.binarysec.com]
*
* This file is part of gateGhost
*
* Gate.js is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Origin: Michael VERGOZ
*/
var cluster = require('cluster');
var url = require('url');
var gateGhost = function(gjs) { };
gateGhost.version = "1.2";
gateGhost.db = require(__dirname+'/js/db.js');
/* used to instance object as lib */
gateGhost.getName = function() { return('gateGhost'); };
gateGhost.dbLog = function(pipe, rule) {
gateGhost.gjs.lib.core.logger.commonLogger(
'GhostDbLog',
{
request: pipe.request.urlParse,
ip: pipe.request.remoteAddress,
method: pipe.request.method,
userAgent: pipe.request.headers['user-agent'] ? pipe.request.headers['user-agent'] : '-',
referer: pipe.request.headers.referer ? pipe.request.headers.referer : '-',
rule: rule
}
);
}
gateGhost.refererLog = function(pipe) {
gateGhost.gjs.lib.core.logger.commonLogger(
'GhostRefererLog',
{
request: pipe.request.urlParse,
ip: pipe.request.remoteAddress,
method: pipe.request.method,
userAgent: pipe.request.headers['user-agent'] ? pipe.request.headers['user-agent'] : '-',
referer: pipe.request.headers.referer ? pipe.request.headers.referer : '-',
}
);
}
gateGhost.cookieLog = function(pipe, detection) {
gateGhost.gjs.lib.core.logger.commonLogger(
'GhostCookieLog',
{
request: pipe.request.urlParse,
ip: pipe.request.remoteAddress,
method: pipe.request.method,
userAgent: pipe.request.headers['user-agent'] ? pipe.request.headers['user-agent'] : '-',
referer: pipe.request.headers.referer ? pipe.request.headers.referer : '-',
detection: detection
}
);
}
gateGhost.loader = function(gjs) {
gateGhost.gjs = gjs;
if (cluster.isMaster) {
var logger = gjs.lib.core.logger;
/* create logging receiver */
var processDbLog = function(req) {
var dateStr = gjs.lib.core.dateToStr(req.msg.time);
var u = url.format(req.msg.request);
var info = '';
if(req.msg.rule.name)
info += '"'+req.msg.rule.name+'"';
if(req.msg.rule.category) {
info += ' '+req.msg.rule.category.toLowerCase()+' ';
}
else
info += ' ';
var inline =
dateStr+' '+
req.msg.ip+' '+
info+
req.msg.method+' '+
u+' '+
'"'+req.msg.userAgent+'" '+
req.msg.referer
;
/* write log */
var f = logger.selectFile(req.msg.site, 'gateGhost-trackers');
if(f)
f.stream.write(inline+'\n');
}
var processRefererLog = function(req) {
var dateStr = gjs.lib.core.dateToStr(req.msg.time);
var u = url.format(req.msg.request);
var inline =
dateStr+' '+
req.msg.ip+' '+
req.msg.method+' '+
u+' '+
'"'+req.msg.userAgent+'" '+
req.msg.referer
;
/* write log */
var f = logger.selectFile(req.msg.site, 'gateGhost-referer');
if(f)
f.stream.write(inline+'\n');
};
var processCookieLog = function(req) {
var dateStr = gjs.lib.core.dateToStr(req.msg.time);
var u = url.format(req.msg.request);
var info = '';
var first = true;
for(var a in req.msg.detection) {
if(first == false)
info += ',';
info += req.msg.detection[a].pattern;
first = false;
}
var inline =
dateStr+' '+
req.msg.ip+' cookies '+
info+' removed '+
req.msg.method+' '+
u+' '+
'"'+req.msg.userAgent+'" '+
req.msg.referer
;
/* write log */
var f = logger.selectFile(req.msg.site, 'gateGhost-cookies');
if(f)
f.stream.write(inline+'\n');
};
logger.typeTab['GhostDbLog'] = processDbLog;
logger.typeTab['GhostRefererLog'] = processRefererLog;
logger.typeTab['GhostCookieLog'] = processCookieLog;
return;
}
gateGhost.db.loader(gjs);
/* load opcodes */
gjs.lib.core.pipeline.scanOpcodes(
__dirname+'/pipeForward',
'forwarding'
);
};
module.exports = gateGhost;