mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-04-07 14:04:35 +08:00
[bug] Fix info page for OpenSource; Fix bug 77514
This commit is contained in:
@ -4695,6 +4695,15 @@ exports.shutdown = function (req, res) {
|
||||
}
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Get active connections array
|
||||
* @returns {Array} Active connections
|
||||
*/
|
||||
function getConnections() {
|
||||
return connections;
|
||||
}
|
||||
|
||||
exports.getConnections = getConnections;
|
||||
exports.getEditorConnectionsCount = function (req, res) {
|
||||
const ctx = new operationContext.Context();
|
||||
let count = 0;
|
||||
|
||||
@ -54,8 +54,9 @@ function getLicenseNowUtc() {
|
||||
* License info endpoint handler
|
||||
* @param {import('express').Request} req Express request
|
||||
* @param {import('express').Response} res Express response
|
||||
* @param {Function} getConnections Function to get active connections
|
||||
*/
|
||||
async function licenseInfo(req, res) {
|
||||
async function licenseInfo(req, res, getConnections = null) {
|
||||
let isError = false;
|
||||
const serverDate = new Date();
|
||||
// Security risk of high-precision time
|
||||
@ -174,7 +175,8 @@ async function licenseInfo(req, res) {
|
||||
const nowUTC = getLicenseNowUtc();
|
||||
let execRes;
|
||||
execRes = await editorStat.getPresenceUniqueUser(ctx, nowUTC);
|
||||
output.quota.edit.connectionsCount = await editorStat.getEditorConnectionsCount(ctx, {});
|
||||
const connections = getConnections ? getConnections() : null;
|
||||
output.quota.edit.connectionsCount = await editorStat.getEditorConnectionsCount(ctx, connections);
|
||||
output.quota.edit.usersCount.unique = execRes.length;
|
||||
execRes.forEach(elem => {
|
||||
if (elem.anonym) {
|
||||
@ -183,7 +185,7 @@ async function licenseInfo(req, res) {
|
||||
});
|
||||
|
||||
execRes = await editorStat.getPresenceUniqueViewUser(ctx, nowUTC);
|
||||
output.quota.view.connectionsCount = await editorStat.getLiveViewerConnectionsCount(ctx, {});
|
||||
output.quota.view.connectionsCount = await editorStat.getLiveViewerConnectionsCount(ctx, connections);
|
||||
output.quota.view.usersCount.unique = execRes.length;
|
||||
execRes.forEach(elem => {
|
||||
if (elem.anonym) {
|
||||
@ -229,13 +231,16 @@ async function licenseInfo(req, res) {
|
||||
|
||||
/**
|
||||
* Create shared Info router
|
||||
* @param {Function} getConnections Optional function to get active connections
|
||||
* @returns {import('express').Router} Router instance
|
||||
*/
|
||||
function createInfoRouter() {
|
||||
function createInfoRouter(getConnections = null) {
|
||||
const router = express.Router();
|
||||
|
||||
// License info endpoint with CORS and client IP check
|
||||
router.get('/info.json', cors(), utils.checkClientIp, licenseInfo);
|
||||
router.get('/info.json', cors(), utils.checkClientIp, (req, res) => {
|
||||
licenseInfo(req, res, getConnections);
|
||||
});
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
@ -295,7 +295,7 @@ docsCoServer.install(server, app, () => {
|
||||
converterService.builder(req, res);
|
||||
});
|
||||
// Shared Info router (provides /info.json)
|
||||
app.use('/info', infoRouter());
|
||||
app.use('/info', infoRouter(docsCoServer.getConnections));
|
||||
app.put('/internal/cluster/inactive', utils.checkClientIp, docsCoServer.shutdown);
|
||||
app.delete('/internal/cluster/inactive', utils.checkClientIp, docsCoServer.shutdown);
|
||||
app.get('/internal/connections/edit', docsCoServer.getEditorConnectionsCount);
|
||||
|
||||
Reference in New Issue
Block a user