mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-04-07 14:04:35 +08:00
Merge pull request #95 from ONLYOFFICE/feature/license-info
Feature/license info
This commit is contained in:
@ -27,6 +27,10 @@
|
||||
"path": "/var/www/onlyoffice/documentserver/server/welcome",
|
||||
"options": {"maxAge": "7d"}
|
||||
},
|
||||
"/info": {
|
||||
"path": "/var/www/onlyoffice/documentserver/server/info",
|
||||
"options": {"maxAge": "7d"}
|
||||
},
|
||||
"/sdkjs-plugins": {
|
||||
"path": "/var/www/onlyoffice/documentserver/sdkjs-plugins",
|
||||
"options": {"maxAge": "7d"}
|
||||
|
||||
@ -30,6 +30,10 @@
|
||||
"/welcome": {
|
||||
"path": "../../welcome",
|
||||
"options": {"maxAge": "7d"}
|
||||
},
|
||||
"/info": {
|
||||
"path": "../../info",
|
||||
"options": {"maxAge": "7d"}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -206,6 +206,7 @@ exports.REDIS_KEY_SHUTDOWN = 'shutdown';
|
||||
exports.REDIS_KEY_COLLECT_LOST = 'collectlost';
|
||||
exports.REDIS_KEY_LICENSE = 'license';
|
||||
exports.REDIS_KEY_LICENSE_T = 'licenseT';
|
||||
exports.REDIS_KEY_EDITOR_CONNECTIONS = 'editorconnections';
|
||||
|
||||
exports.SHUTDOWN_CODE = 4001;
|
||||
exports.SHUTDOWN_REASON = 'server shutdown';
|
||||
|
||||
@ -65,7 +65,9 @@ exports.readLicense = function*() {
|
||||
usersCount: 0,
|
||||
usersExpire: constants.LICENSE_EXPIRE_USERS_ONE_DAY,
|
||||
hasLicense: false,
|
||||
plugins: false
|
||||
plugins: false,
|
||||
buildDate: oBuildDate,
|
||||
endDate: null
|
||||
};
|
||||
let checkFile = false;
|
||||
try {
|
||||
@ -80,6 +82,7 @@ exports.readLicense = function*() {
|
||||
const publicKey = '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDRhGF7X4A0ZVlEg594WmODVVUI\niiPQs04aLmvfg8SborHss5gQXu0aIdUT6nb5rTh5hD2yfpF2WIW6M8z0WxRhwicg\nXwi80H1aLPf6lEPPLvN29EhQNjBpkFkAJUbS8uuhJEeKw0cE49g80eBBF4BCqSL6\nPFQbP9/rByxdxEoAIQIDAQAB\n-----END PUBLIC KEY-----\n';
|
||||
if (verify.verify(publicKey, sign, 'hex')) {
|
||||
const endDate = new Date(oLicense['end_date']);
|
||||
res.endDate = endDate;
|
||||
const isTrial = (true === oLicense['trial'] || 'true' === oLicense['trial']); // Someone who likes to put json string instead of bool
|
||||
res.mode = isTrial ? c_LM.Trial : getLicenseMode(oLicense['mode']);
|
||||
const checkDate = c_LM.Trial === res.mode ? new Date() : oBuildDate;
|
||||
|
||||
@ -159,6 +159,7 @@ const redisKeyForceSaveTimer = cfgRedisPrefix + constants.REDIS_KEY_FORCE_SAVE_T
|
||||
const redisKeyForceSaveTimerLock = cfgRedisPrefix + constants.REDIS_KEY_FORCE_SAVE_TIMER_LOCK;
|
||||
const redisKeySaved = cfgRedisPrefix + constants.REDIS_KEY_SAVED;
|
||||
const redisKeyPresenceUniqueUsers = cfgRedisPrefix + constants.REDIS_KEY_PRESENCE_UNIQUE_USERS;
|
||||
const redisKeyEditorConnections = cfgRedisPrefix + constants.REDIS_KEY_EDITOR_CONNECTIONS;
|
||||
|
||||
const EditorTypes = {
|
||||
document : 0,
|
||||
@ -181,6 +182,10 @@ const FORCE_SAVE_EXPIRATION = Math.min(Math.max(cfgForceSaveInterval, MIN_SAVE_E
|
||||
cfgQueueRetentionPeriod * 1000);
|
||||
const HEALTH_CHECK_KEY_MAX = 10000;
|
||||
|
||||
const PRECISION = [{name: 'hour', val: ms('1h')}, {name: 'day', val: ms('1d')}, {name: 'week', val: ms('7d')},
|
||||
{name: 'month', val: ms('31d')},
|
||||
];
|
||||
|
||||
function getIsShutdown() {
|
||||
return shutdownFlag;
|
||||
}
|
||||
@ -2952,6 +2957,19 @@ exports.install = function(server, callbackFunction) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function* collectStats(countEdit, countView) {
|
||||
let now = Date.now();
|
||||
var multi = redisClient.multi(
|
||||
[
|
||||
['lpop', redisKeyEditorConnections],
|
||||
['rpush', redisKeyEditorConnections, JSON.stringify({time: now, edit: countEdit, view: countView})]
|
||||
]);
|
||||
let multiRes = yield utils.promiseRedis(multi, multi.exec);
|
||||
if (multiRes.length > 1 && JSON.parse(multiRes[0]).time > now - PRECISION[PRECISION.length - 1].val) {
|
||||
yield utils.promiseRedis(redisClient, redisClient.lpush, redisKeyEditorConnections, multiRes[0]);
|
||||
}
|
||||
}
|
||||
function expireDoc() {
|
||||
var cronJob = this;
|
||||
return co(function* () {
|
||||
@ -3006,6 +3024,7 @@ exports.install = function(server, callbackFunction) {
|
||||
idSet.forEach(function(value1, value2, set) {
|
||||
commands.push(['zadd', redisKeyDocuments, expireAt, value1]);
|
||||
});
|
||||
yield* collectStats(countEdit, countView);
|
||||
if (commands.length > 0) {
|
||||
var multi = redisClient.multi(commands);
|
||||
yield utils.promiseRedis(multi, multi.exec);
|
||||
@ -3093,6 +3112,80 @@ exports.healthCheck = function(req, res) {
|
||||
}
|
||||
});
|
||||
};
|
||||
exports.licenseInfo = function(req, res) {
|
||||
return co(function*() {
|
||||
let isError = false;
|
||||
let output = {
|
||||
connectionsStat: {}, licenseInfo: {}, serverInfo: {
|
||||
buildVersion: commonDefines.buildVersion, buildNumber: commonDefines.buildNumber,
|
||||
}
|
||||
};
|
||||
Object.assign(output.licenseInfo, licenseInfo);
|
||||
try {
|
||||
logger.debug('licenseInfo start');
|
||||
var precisionSum = {};
|
||||
for (let i = 0; i < PRECISION.length; ++i) {
|
||||
precisionSum[PRECISION[i].name] = {
|
||||
edit: {min: Number.MAX_VALUE, sum: 0, count: 0, max: 0, time: null, period: PRECISION[i].val},
|
||||
view: {min: Number.MAX_VALUE, sum: 0, count: 0, max: 0}
|
||||
};
|
||||
output.connectionsStat[PRECISION[i].name] = {
|
||||
edit: {min: 0, avr: 0, max: 0},
|
||||
view: {min: 0, avr: 0, max: 0}
|
||||
};
|
||||
}
|
||||
var redisRes = yield utils.promiseRedis(redisClient, redisClient.lrange, redisKeyEditorConnections, 0, -1);
|
||||
const now = Date.now();
|
||||
var precisionIndex = 0;
|
||||
for (let i = redisRes.length - 1; i >= 1; i -= 2) {
|
||||
for (let j = precisionIndex; j < PRECISION.length; ++j) {
|
||||
let elem = JSON.parse(redisRes[i]);
|
||||
if (now - elem.time < PRECISION[j].val) {
|
||||
let precision = precisionSum[PRECISION[j].name];
|
||||
precision.edit.min = Math.min(precision.edit.min, elem.edit);
|
||||
precision.edit.max = Math.max(precision.edit.max, elem.edit);
|
||||
precision.edit.sum += elem.edit;
|
||||
precision.edit.count++;
|
||||
precision.edit.time = elem.time;
|
||||
precision.view.min = Math.min(precision.view.min, elem.view);
|
||||
precision.view.max = Math.max(precision.view.max, elem.view);
|
||||
precision.view.sum += elem.view;
|
||||
precision.view.count++;
|
||||
} else {
|
||||
precisionIndex = j + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let i in precisionSum) {
|
||||
let precision = precisionSum[i];
|
||||
let precisionOut = output.connectionsStat[i];
|
||||
//scale compensates for the lack of points at server start
|
||||
let scale = (now - precision.edit.time) / precision.edit.period;
|
||||
if (precision.edit.count > 0) {
|
||||
precisionOut.edit.avr = Math.round((precision.edit.sum / precision.edit.count) * scale);
|
||||
precisionOut.edit.min = precision.edit.min;
|
||||
precisionOut.edit.max = precision.edit.max;
|
||||
}
|
||||
if (precision.view.count > 0) {
|
||||
precisionOut.view.avr = Math.round((precision.view.sum / precision.view.count) * scale);
|
||||
precisionOut.view.min = precision.view.min;
|
||||
precisionOut.view.max = precision.view.max;
|
||||
}
|
||||
}
|
||||
logger.debug('licenseInfo end');
|
||||
} catch (err) {
|
||||
isError = true;
|
||||
logger.error('licenseInfo error\r\n%s', err.stack);
|
||||
} finally {
|
||||
if (!isError) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(JSON.stringify(output));
|
||||
} else {
|
||||
res.sendStatus(400);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
// Команда с сервера (в частности teamlab)
|
||||
exports.commandFromServer = function (req, res) {
|
||||
return co(function* () {
|
||||
|
||||
@ -234,6 +234,7 @@ if (cluster.isMaster) {
|
||||
}
|
||||
converterService.builder(req, res);
|
||||
});
|
||||
app.get('/info/info.json', utils.checkClientIp, docsCoServer.licenseInfo);
|
||||
|
||||
const sendUserPlugins = (res, data) => {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
|
||||
10
Makefile
10
Makefile
@ -93,6 +93,10 @@ WELCOME_DIR = welcome
|
||||
WELCOME_FILES = $(WELCOME_DIR)/**
|
||||
WELCOME = $(OUTPUT)/$(WELCOME_DIR)/
|
||||
|
||||
INFO_DIR = info
|
||||
INFO_FILES = $(INFO_DIR)/**
|
||||
INFO = $(OUTPUT)/$(INFO_DIR)/
|
||||
|
||||
CORE_FONTS_DIR = core-fonts
|
||||
CORE_FONTS_FILES = ../$(CORE_FONTS_DIR)/**
|
||||
CORE_FONTS = $(OUTPUT)/../$(CORE_FONTS_DIR)/
|
||||
@ -100,7 +104,7 @@ CORE_FONTS = $(OUTPUT)/../$(CORE_FONTS_DIR)/
|
||||
.PHONY: all clean install uninstall build-date htmlfileinternal docbuilder
|
||||
|
||||
.NOTPARALLEL:
|
||||
all: $(FILE_CONVERTER) $(SPELLCHECKER_DICTIONARIES) $(TOOLS) $(SCHEMA) $(CORE_FONTS) $(LICENSE) $(WELCOME) build-date
|
||||
all: $(FILE_CONVERTER) $(SPELLCHECKER_DICTIONARIES) $(TOOLS) $(SCHEMA) $(CORE_FONTS) $(LICENSE) $(WELCOME) $(INFO) build-date
|
||||
|
||||
ext: htmlfileinternal docbuilder
|
||||
|
||||
@ -147,6 +151,10 @@ $(WELCOME):
|
||||
mkdir -p $(WELCOME) && \
|
||||
cp -r -t $(WELCOME) $(WELCOME_FILES)
|
||||
|
||||
$(INFO):
|
||||
mkdir -p $(INFO) && \
|
||||
cp -r -t $(INFO) $(INFO_FILES)
|
||||
|
||||
$(CORE_FONTS):
|
||||
mkdir -p $(CORE_FONTS) && \
|
||||
cp -r -t $(CORE_FONTS) $(CORE_FONTS_FILES)
|
||||
|
||||
BIN
info/img/favicon.ico
Normal file
BIN
info/img/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
info/img/icon-cross.png
Normal file
BIN
info/img/icon-cross.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
info/img/logo.png
Normal file
BIN
info/img/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
274
info/index.html
Normal file
274
info/index.html
Normal file
@ -0,0 +1,274 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>ONLYOFFICE™</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=IE8"/>
|
||||
<link href="img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
|
||||
<style type="text/css">
|
||||
html {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
height: 100%;
|
||||
min-width: 600px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
font-family: 'Open Sans', sans-serif;
|
||||
font-size: 12px;
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
header {
|
||||
background: #3D4A6B;
|
||||
height: 80px;
|
||||
margin: 0 auto;
|
||||
min-width: 600px;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
header img {
|
||||
margin: 20px 0 0 16px;
|
||||
}
|
||||
|
||||
table {
|
||||
table-layout: fixed;
|
||||
border-spacing: 0;
|
||||
}
|
||||
|
||||
td {
|
||||
padding-left: 0;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.main-panel {
|
||||
margin: 80px auto 16px;
|
||||
width: 600px;
|
||||
}
|
||||
|
||||
.header0 {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.header1 {
|
||||
font-size: 20px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.header2 {
|
||||
font-size: 16px;
|
||||
padding: 30px 0 5px 0;
|
||||
}
|
||||
|
||||
#doc-server-wait {
|
||||
text-align: center;
|
||||
}
|
||||
#doc-server-err > div {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
#status-err-icon {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
text-align: left;
|
||||
width:48px;
|
||||
height: 48px;
|
||||
margin-right: 15px;
|
||||
background: url(img/icon-cross.png) center no-repeat;
|
||||
}
|
||||
|
||||
#status-err-help {
|
||||
font-size: 18px;
|
||||
font-weight: normal;
|
||||
margin-top: 5px;
|
||||
}
|
||||
.hidden {
|
||||
display: none !important;
|
||||
visibility: hidden;
|
||||
}
|
||||
.critical {
|
||||
color: #ff0000;
|
||||
font-weight: bold;
|
||||
}
|
||||
.warning {
|
||||
color: #ff8a00;
|
||||
font-weight: bold;
|
||||
}
|
||||
.td-caption {
|
||||
font-weight: bold;
|
||||
}
|
||||
.td-center {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<img src="img/logo.png" alt="ONLYOFFICE">
|
||||
</header>
|
||||
<div class="main-panel">
|
||||
<div class="header0" id="doc-server-wait">Please, wait...</div>
|
||||
<div class="hidden" id="doc-server-ok">
|
||||
<div class="header1">Document Server information</div>
|
||||
<div class="header2">Build</div>
|
||||
<table>
|
||||
<tr>
|
||||
<td width="120px" class="td-caption">Type:</td>
|
||||
<td width="500px" id="build-type"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="td-caption">Date:</td>
|
||||
<td id="build-date"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="td-caption">Version:</td>
|
||||
<td id="build-version"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="header2">License</div>
|
||||
<table>
|
||||
<tr>
|
||||
<td width="280px" class="td-caption" id="lic-valid-type">Valid:</td>
|
||||
<td width="500px">until <span id="lic-valid"></span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="td-caption" id="limit-type">Concurrent users limit:</td>
|
||||
<td id="lic-limit"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="header2">Number Concurrent Connections</div>
|
||||
<table width="600px">
|
||||
<tr class="td-caption">
|
||||
<td></td>
|
||||
<td class="td-center">Last Hour</td>
|
||||
<td class="td-center">Last 24 Hours</td>
|
||||
<td class="td-center">Last Week</td>
|
||||
<td class="td-center">Last Month</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="td-caption">Maximum:</td>
|
||||
<td id="cell-hour-max" class="td-center">0</td>
|
||||
<td id="cell-day-max" class="td-center">0</td>
|
||||
<td id="cell-week-max" class="td-center">0</td>
|
||||
<td id="cell-month-max" class="td-center">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="td-caption">Minimum:</td>
|
||||
<td id="cell-hour-min" class="td-center">0</td>
|
||||
<td id="cell-day-min" class="td-center">0</td>
|
||||
<td id="cell-week-min" class="td-center">0</td>
|
||||
<td id="cell-month-min" class="td-center">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="td-caption">Average:</td>
|
||||
<td id="cell-hour-avr" class="td-center">0</td>
|
||||
<td id="cell-day-avr" class="td-center">0</td>
|
||||
<td id="cell-week-avr" class="td-center">0</td>
|
||||
<td id="cell-month-avr" class="td-center">0</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="hidden header0" id="doc-server-err">
|
||||
<div id="status-err-icon"></div>
|
||||
<div>
|
||||
<div>Something went wrong during installation</div>
|
||||
<div id="status-err-help">Make sure that you have followed the <a href="http://helpcenter.onlyoffice.com/server/document.aspx" target="_blank">installation instructions</a></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var _createXMLHTTPObject = function() {
|
||||
var xmlhttp;
|
||||
try {
|
||||
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
|
||||
}
|
||||
catch (e) {
|
||||
try {
|
||||
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
}
|
||||
catch (E) {
|
||||
xmlhttp = false;
|
||||
}
|
||||
}
|
||||
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
|
||||
xmlhttp = new XMLHttpRequest();
|
||||
}
|
||||
return xmlhttp;
|
||||
};
|
||||
function fillInfo(licenseInfo, serverInfo) {
|
||||
var elem = document.getElementById('build-type');
|
||||
elem.innerText = (licenseInfo.packageType == 0) ? 'Open source' : ((licenseInfo.packageType == 1) ? 'Integration' : 'Developer');
|
||||
|
||||
elem = document.getElementById('build-date');
|
||||
var builddate = new Date(licenseInfo.buildDate);
|
||||
elem.innerText = builddate.toLocaleDateString();
|
||||
|
||||
elem = document.getElementById('build-version');
|
||||
elem.innerText = serverInfo.buildVersion + '.' + serverInfo.buildNumber;
|
||||
|
||||
elem = document.getElementById('limit-type');
|
||||
elem.innerText = (licenseInfo.usersCount>0) ? 'Concurrent users limit:' : 'Concurrent connections limit:';
|
||||
|
||||
elem = document.getElementById('lic-limit');
|
||||
elem.innerText = (licenseInfo.usersCount || licenseInfo.connections);
|
||||
|
||||
elem = document.getElementById('lic-valid-type');
|
||||
elem.innerText = (licenseInfo.mode == 1) ? 'Valid:' : 'Updates available:';
|
||||
|
||||
var licdate = new Date(licenseInfo.endDate);
|
||||
elem = document.getElementById('lic-valid');
|
||||
elem.innerText = licdate.toLocaleDateString();
|
||||
if (Date.now() > licdate)
|
||||
elem.classList.add('critical');
|
||||
|
||||
return (licenseInfo.usersCount>0) ? 1000000 : licenseInfo.connections;
|
||||
}
|
||||
function fillConnections(info, limit) {
|
||||
for (var precision in info.connectionsStat) {
|
||||
for (var agregate in info.connectionsStat[precision].edit) {
|
||||
var value = info.connectionsStat[precision].edit[agregate];
|
||||
var elem = document.getElementById('cell-' + precision + '-' + agregate);
|
||||
elem.innerText = value;
|
||||
if (value >= limit) {
|
||||
elem.classList.add("critical");
|
||||
} else if (value >= limit * 0.7) {
|
||||
elem.classList.add("warning");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(function(){
|
||||
try {
|
||||
var xhrObj = _createXMLHTTPObject();
|
||||
if (xhrObj) {
|
||||
var index_html = window["location"]["href"];
|
||||
var healthcheck_url = index_html.substring(0, index_html.lastIndexOf("/") + 1) + 'info.json';
|
||||
xhrObj.open('GET', healthcheck_url);
|
||||
xhrObj.onreadystatechange = function() {
|
||||
if (xhrObj.readyState == 4) {
|
||||
document.getElementById('doc-server-wait').classList.add("hidden");
|
||||
if (xhrObj.status == 200) {
|
||||
document.getElementById('doc-server-ok').classList.remove("hidden");
|
||||
var info = JSON.parse(xhrObj.responseText);
|
||||
fillConnections(info, fillInfo(info.licenseInfo, info.serverInfo));
|
||||
} else {
|
||||
document.getElementById('doc-server-err').classList.remove("hidden");
|
||||
}
|
||||
}
|
||||
};
|
||||
xhrObj.send('');
|
||||
}
|
||||
}
|
||||
catch (e) {}
|
||||
})();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user