whatap 1.0.5 → 1.0.6-canary.1
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.
|
@@ -19,6 +19,8 @@ const {Buffer} = require("buffer");
|
|
|
19
19
|
const shimmer = require('../core/shimmer');
|
|
20
20
|
const os = require('os');
|
|
21
21
|
const Transfer = require('../util/transfer');
|
|
22
|
+
const IPUtil = require('../util/iputil');
|
|
23
|
+
const UserIdUtil = require('../util/userid-util');
|
|
22
24
|
|
|
23
25
|
var _exts = new Set([".css", ".js", ".png", ".htm", ".html", ".gif", ".jpg", ".css", ".txt", ".ico"]);
|
|
24
26
|
|
|
@@ -216,19 +218,16 @@ function initCtx(req, res) {
|
|
|
216
218
|
if(remote_addr.includes(',')) {
|
|
217
219
|
remote_addr = remote_addr.split(',')[0].trim();
|
|
218
220
|
}
|
|
219
|
-
|
|
220
|
-
ctx.remoteIp = IPUtil.stringToInt(remote_addr);
|
|
221
|
+
ctx.remoteIp = IPUtil.checkIp4(remote_addr);
|
|
221
222
|
switch (conf.trace_user_using_type || 3) {
|
|
222
223
|
case 1:
|
|
223
224
|
ctx.userid = Long.fromNumber(ctx.remoteIp);
|
|
224
|
-
MeterUsers.add(ctx.userid);
|
|
225
225
|
break;
|
|
226
226
|
case 2:
|
|
227
227
|
// MeterUsers.add(ctx.userid);
|
|
228
228
|
break;
|
|
229
229
|
case 3:
|
|
230
230
|
ctx.userid = UserIdUtil.getUserId(req, res, 0);
|
|
231
|
-
MeterUsers.add(ctx.userid);
|
|
232
231
|
break;
|
|
233
232
|
}
|
|
234
233
|
} catch (e) {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2016 the WHATAP project authors. All rights reserved.
|
|
3
|
+
* Use of this source code is governed by a license that
|
|
4
|
+
* can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const WHATAP_R = "WHATAP";
|
|
8
|
+
|
|
9
|
+
var conf = require('../conf/configure'),
|
|
10
|
+
HashUtil = require('./hashutil'),
|
|
11
|
+
Hexa32 = require('./hexa32'),
|
|
12
|
+
KeyGen = require('./keygen'),
|
|
13
|
+
Long = require('long'),
|
|
14
|
+
Logger = require('../logger');
|
|
15
|
+
|
|
16
|
+
var getUserId = function (req, res, defValue) {
|
|
17
|
+
try {
|
|
18
|
+
if (conf.user_header_ticket_enabled === true) {
|
|
19
|
+
var ticket = req.headers[conf.user_header_ticket];
|
|
20
|
+
if (ticket != null && ticket.length > 0) {
|
|
21
|
+
return Long.fromNumber(HashUtil.hash(ticket));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
var cookie = req.headers.cookie;
|
|
25
|
+
if (cookie != null) {
|
|
26
|
+
if (cookie.length >= conf.trace_user_cookie_limit) {
|
|
27
|
+
return defValue;
|
|
28
|
+
}
|
|
29
|
+
var x1 = cookie.indexOf(WHATAP_R);
|
|
30
|
+
if (x1 >= 0) {
|
|
31
|
+
var value = '';
|
|
32
|
+
var x2 = cookie.indexOf(';', x1);
|
|
33
|
+
if (x2 > 0) {
|
|
34
|
+
value = cookie.substring(x1 + WHATAP_R.length + 1, x2);
|
|
35
|
+
} else {
|
|
36
|
+
value = cookie.substring(x1 + WHATAP_R.length + 1);
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
return Hexa32.toLong32(value);
|
|
40
|
+
} catch (th) {
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
var expires= new Date(Date.now() + (86409000*365*5)).toUTCString();
|
|
45
|
+
var cookie_str = WHATAP_R + "=" + Hexa32.toString32(KeyGen.next()) + "; expires=" + expires +"; path=/";
|
|
46
|
+
res.setHeader("Set-Cookie", cookie_str);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
Logger.printError('WHATAP-193', 'UserIdUtil Error', e);
|
|
49
|
+
}
|
|
50
|
+
return Long.ZERO;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
var UserIdUtil = {
|
|
54
|
+
getUserId : getUserId
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
module.exports = UserIdUtil;
|