Skip to content

Commit 1d8347c

Browse files
authored
Merge pull request wekan#5682 from salleman33/devel
Update metrics.js
2 parents 3e18f82 + 874abf2 commit 1d8347c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

models/server/metrics.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@ function acceptedIpAddress(ipAddress) {
99
);
1010
}
1111

12+
function accessToken(req) {
13+
const valid_token = process.env.METRICS_ACCESS_TOKEN;
14+
let token;
15+
if (req.headers && req.headers.authorization) {
16+
var parts = req.headers.authorization.split(" ");
17+
18+
if (parts.length === 2) {
19+
var scheme = parts[0];
20+
var credentials = parts[1];
21+
22+
if (/^Bearer$/i.test(scheme)) {
23+
token = credentials;
24+
}
25+
}
26+
}
27+
if (!token && req.query && req.query.access_token) {
28+
token = req.query.access_token;
29+
}
30+
return (
31+
token !== undefined &&
32+
valid_token !== undefined &&
33+
token == valid_token
34+
);
35+
}
36+
1237
const getBoardTitleWithMostActivities = (dateWithXdaysAgo, nbLimit) => {
1338
return Promise.await(
1439
Activities.rawCollection()
@@ -49,7 +74,7 @@ Meteor.startup(() => {
4974
// }
5075

5176
// List of trusted ip adress will be found in environment variable "METRICS_ACCEPTED_IP_ADDRESS" (separeted with commas)
52-
if (acceptedIpAddress(ipAddress)) {
77+
if (acceptedIpAddress(ipAddress) || (accessToken(req)) {
5378
let metricsRes = '';
5479
let resCount = 0;
5580
//connected users

0 commit comments

Comments
 (0)