Merge pull request #5682 from salleman33/devel

Update metrics.js
This commit is contained in:
Lauri Ojansivu 2025-02-11 17:28:33 +02:00 committed by GitHub
commit 1d8347cc23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9,6 +9,31 @@ function acceptedIpAddress(ipAddress) {
);
}
function accessToken(req) {
const valid_token = process.env.METRICS_ACCESS_TOKEN;
let token;
if (req.headers && req.headers.authorization) {
var parts = req.headers.authorization.split(" ");
if (parts.length === 2) {
var scheme = parts[0];
var credentials = parts[1];
if (/^Bearer$/i.test(scheme)) {
token = credentials;
}
}
}
if (!token && req.query && req.query.access_token) {
token = req.query.access_token;
}
return (
token !== undefined &&
valid_token !== undefined &&
token == valid_token
);
}
const getBoardTitleWithMostActivities = (dateWithXdaysAgo, nbLimit) => {
return Promise.await(
Activities.rawCollection()
@ -49,7 +74,7 @@ Meteor.startup(() => {
// }
// List of trusted ip adress will be found in environment variable "METRICS_ACCEPTED_IP_ADDRESS" (separeted with commas)
if (acceptedIpAddress(ipAddress)) {
if (acceptedIpAddress(ipAddress) || (accessToken(req)) {
let metricsRes = '';
let resCount = 0;
//connected users