This commit is contained in:
Alexey Golubev
2017-10-31 18:51:20 +03:00
6 changed files with 47 additions and 18 deletions

View File

@ -46,6 +46,12 @@ exports.RIGHTS = {
View : 4
};
exports.LICENSE_MODE = {
None: 0,
Trial: 1,
Developer: 2
};
exports.LICENSE_RESULT = {
Error : 1,
Expired : 2,
@ -172,6 +178,7 @@ exports.EDITOR_TYPE_CONVERTATION = 3;
exports.PACKAGE_TYPE_OS = 0;
exports.PACKAGE_TYPE_I = 1;
exports.PACKAGE_TYPE_D = 2;
exports.REDIS_KEY_PUBSUB = 'pubsub';
exports.REDIS_KEY_SAVE_LOCK = 'savelock:';

View File

@ -52,8 +52,17 @@ const redisKeyLicense = cfgRedisPrefix + ((constants.PACKAGE_TYPE_OS === oPackag
exports.readLicense = function*() {
const c_LR = constants.LICENSE_RESULT;
const resMax = {count: 999999, type: c_LR.Success};
const res = {count: 1, type: c_LR.Error, light: false, packageType: oPackageType, trial: false, branding: false, connections: constants.LICENSE_CONNECTIONS};
const c_LM = constants.LICENSE_MODE;
const resMax = {count: 999999, type: c_LR.Success, mode: c_LM.None, connections: 999999999};
const res = {
count: 1,
type: c_LR.Error,
light: false,
packageType: oPackageType,
mode: c_LM.None,
branding: false,
connections: constants.LICENSE_CONNECTIONS
};
let checkFile = false;
try {
const oFile = fs.readFileSync(configL.get('license_file')).toString();
@ -67,10 +76,12 @@ 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']);
const isTrial = res.trial = (true === oLicense['trial'] || 'true' === oLicense['trial']); // Someone who likes to put json string instead of bool
const checkDate = (isTrial && constants.PACKAGE_TYPE_OS === oPackageType) ? new Date() : oBuildDate;
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;
if (endDate >= checkDate && 2 <= oLicense['version']) {
res.count = Math.min(Math.max(res.count, oLicense['process'] >> 0), resMax.count);
res.connections = Math.max(res.count, oLicense['process'] >> 0) * 75;
res.count = resMax.count;
res.type = c_LR.Success;
} else {
res.type = isTrial ? c_LR.ExpiredTrial : c_LR.Expired;
@ -79,7 +90,7 @@ exports.readLicense = function*() {
res.light = (true === oLicense['light'] || 'true' === oLicense['light']); // Someone who likes to put json string instead of bool
res.branding = (true === oLicense['branding'] || 'true' === oLicense['branding']); // Someone who likes to put json string instead of bool
if (oLicense.hasOwnProperty('connections')) {
res.connections = oLicense['connections'];
res.connections = oLicense['connections'] >> 0;
}
} else {
throw 'verify';
@ -98,8 +109,8 @@ exports.readLicense = function*() {
} else {
res.type = (yield* _getFileState()) ? c_LR.Success : c_LR.ExpiredTrial;
if (res.type === c_LR.Success) {
res.trial = true;
res.count = 2;
res.mode = c_LM.Trial;
res.count = resMax.count;
return res;
}
}
@ -118,6 +129,11 @@ exports.readLicense = function*() {
};
exports.packageType = oPackageType;
function getLicenseMode(mode) {
const c_LM = constants.LICENSE_MODE;
return 'developer' === mode ? c_LM.Developer : ('trial' === mode ? c_LM.Trial : c_LM.None);
}
function* _getFileState() {
const val = yield utils.promiseRedis(redisClient, redisClient.hget, redisKeyLicense, redisKeyLicense);
if (constants.PACKAGE_TYPE_OS === oPackageType) {

View File

@ -9,6 +9,7 @@
"co": "^4.6.0",
"config": "^1.21.0",
"cron": "^1.1.0",
"deep-equal": "^1.0.1",
"express": "^4.14.0",
"fakeredis": "^1.0.3",
"jsonwebtoken": "^7.1.9",

View File

@ -85,6 +85,7 @@ const co = require('co');
const jwt = require('jsonwebtoken');
const jwa = require('jwa');
const ms = require('ms');
const deepEqual = require('deep-equal');
const storage = require('./../../Common/sources/storage-base');
const logger = require('./../../Common/sources/logger');
const constants = require('./../../Common/sources/constants');
@ -1654,12 +1655,14 @@ exports.install = function(server, callbackFunction) {
function isEditMode(permissions, mode, def) {
if (permissions && mode) {
//as in web-apps/apps/documenteditor/main/app/controller/Main.js
return (permissions.edit !== false || permissions.review === true) && mode !== 'view';
return ((permissions.edit !== false || permissions.review === true) && mode !== 'view') ||
permissions.comment === true;
} else {
return def;
}
}
function fillDataFromJwt(decoded, data) {
let res = true;
var openCmd = data.openCmd;
if (decoded.document) {
var doc = decoded.document;
@ -1670,6 +1673,7 @@ exports.install = function(server, callbackFunction) {
}
}
if(doc.permissions) {
res = deepEqual(data.permissions, doc.permissions, {strict: true});
if(!data.permissions){
data.permissions = {};
}
@ -1729,6 +1733,7 @@ exports.install = function(server, callbackFunction) {
if (decoded.iss) {
data.iss = decoded.iss;
}
return res;
}
function fillVersionHistoryFromJwt(decoded, cmd) {
if (decoded.changesUrl && decoded.previous && (cmd.getServerVersion() === commonDefines.buildVersion)) {
@ -1779,7 +1784,11 @@ exports.install = function(server, callbackFunction) {
const isSession = !!data.jwtSession;
const checkJwtRes = checkJwt(docId, data.jwtSession || data.jwtOpen, isSession);
if (checkJwtRes.decoded) {
fillDataFromJwt(checkJwtRes.decoded, data);
if (!fillDataFromJwt(checkJwtRes.decoded, data)) {
logger.warn("fillDataFromJwt return false: docId = %s", docId);
conn.close(constants.ACCESS_DENIED_CODE, constants.ACCESS_DENIED_REASON);
return;
}
} else {
conn.close(checkJwtRes.code, checkJwtRes.description);
return;
@ -2519,7 +2528,7 @@ exports.install = function(server, callbackFunction) {
license: {
type: licenseType,
light: licenseInfo.light,
trial: constants.PACKAGE_TYPE_OS === licenseInfo.packageType ? false : licenseInfo.trial,
mode: licenseInfo.mode,
rights: rights,
buildVersion: commonDefines.buildVersion,
buildNumber: commonDefines.buildNumber,

View File

@ -303,7 +303,8 @@ function builderRequest(req, res) {
}
}
}
if (error === constants.NO_ERROR && (params.key || params.url || (req.body && Buffer.isBuffer(req.body)))) {
if (error === constants.NO_ERROR &&
(params.key || params.url || (req.body && Buffer.isBuffer(req.body) && req.body.length > 0))) {
docId = params.key;
let cmd = new commonDefines.InputCommand();
cmd.setCommand('builder');
@ -331,7 +332,7 @@ function builderRequest(req, res) {
urls = yield storageBase.getSignedUrls(utils.getBaseUrlByRequest(req), docId + '/output',
commonDefines.c_oAscUrlTypes.Temporary);
}
} else {
} else if (error === constants.NO_ERROR) {
error = constants.UNKNOWN;
}
logger.debug('End builderRequest request: docId = %s urls = %j end = %s error = %s', docId, urls, end, error);

View File

@ -228,11 +228,6 @@ if (cluster.isMaster) {
app.get('/healthcheck', utils.checkClientIp, docsCoServer.healthCheck);
app.post('/docbuilder', utils.checkClientIp, rawFileParser, (req, res) => {
if (constants.PACKAGE_TYPE_I !== license.packageType) {
logger.error('In this installation there is no docbuilder');
res.sendStatus(403);
return;
}
const licenseInfo = docsCoServer.getLicenseInfo();
if (licenseInfo.type !== constants.LICENSE_RESULT.Success) {
logger.error('License expired');