whatap 1.0.5 → 1.0.6-canary.0
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
|
|
|
@@ -221,14 +223,12 @@ function initCtx(req, res) {
|
|
|
221
223
|
switch (conf.trace_user_using_type || 3) {
|
|
222
224
|
case 1:
|
|
223
225
|
ctx.userid = Long.fromNumber(ctx.remoteIp);
|
|
224
|
-
MeterUsers.add(ctx.userid);
|
|
225
226
|
break;
|
|
226
227
|
case 2:
|
|
227
228
|
// MeterUsers.add(ctx.userid);
|
|
228
229
|
break;
|
|
229
230
|
case 3:
|
|
230
231
|
ctx.userid = UserIdUtil.getUserId(req, res, 0);
|
|
231
|
-
MeterUsers.add(ctx.userid);
|
|
232
232
|
break;
|
|
233
233
|
}
|
|
234
234
|
} 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;
|