mirror of
https://github.com/wekan/wekan.git
synced 2025-09-22 01:50:48 +02:00
Update metrics.js
Add possibility to use a token in place of ipaddress to access metrics route
This commit is contained in:
parent
3e18f820ea
commit
874abf2c41
1 changed files with 26 additions and 1 deletions
|
@ -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) => {
|
const getBoardTitleWithMostActivities = (dateWithXdaysAgo, nbLimit) => {
|
||||||
return Promise.await(
|
return Promise.await(
|
||||||
Activities.rawCollection()
|
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)
|
// 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 metricsRes = '';
|
||||||
let resCount = 0;
|
let resCount = 0;
|
||||||
//connected users
|
//connected users
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue