diff --git a/Common/sources/constants.js b/Common/sources/constants.js index 9d1d1774..221bb5f6 100644 --- a/Common/sources/constants.js +++ b/Common/sources/constants.js @@ -156,6 +156,9 @@ exports.EDITOR_TYPE_SPREADSHEET = 1; exports.EDITOR_TYPE_PRESENTATION = 2; exports.EDITOR_TYPE_CONVERTATION = 3; +exports.PACKAGE_TYPE_OS = 0; +exports.PACKAGE_TYPE_I = 1; + exports.REDIS_KEY_PUBSUB = 'pubsub'; exports.REDIS_KEY_SAVE_LOCK = 'savelock:'; exports.REDIS_KEY_PRESENCE_HASH = 'presence:hash:'; @@ -170,6 +173,7 @@ exports.REDIS_KEY_FORCE_SAVE = 'forcesave:'; exports.REDIS_KEY_SAVED = 'saved:'; exports.REDIS_KEY_SHUTDOWN = 'shutdown'; exports.REDIS_KEY_LICENSE = 'license'; +exports.REDIS_KEY_LICENSE_T = 'licenseT'; exports.SHUTDOWN_CODE = 4001; exports.SHUTDOWN_REASON = 'server shutdown'; diff --git a/Common/sources/license.js b/Common/sources/license.js index b7c6b64f..13417722 100644 --- a/Common/sources/license.js +++ b/Common/sources/license.js @@ -40,18 +40,20 @@ const utils = require('./utils'); const pubsubRedis = require('./../../DocService/sources/pubsubRedis'); const redisClient = pubsubRedis.getClientRedis(); -const cfgRedisPrefix = config.get('services.CoAuthoring.redis.prefix'); -const redisKeyLicense = cfgRedisPrefix + constants.REDIS_KEY_LICENSE; - const buildVersion = '4.0.0'; const buildNumber = 19; const buildDate = '6/29/2016'; const oBuildDate = new Date(buildDate); +const oPackageType = constants.PACKAGE_TYPE_OS; + +const cfgRedisPrefix = config.get('services.CoAuthoring.redis.prefix'); +const redisKeyLicense = cfgRedisPrefix + ((constants.PACKAGE_TYPE_OS === oPackageType) ? constants.REDIS_KEY_LICENSE : + constants.REDIS_KEY_LICENSE_T); exports.readLicense = function*() { const c_LR = constants.LICENSE_RESULT; const resMax = {count: 999999, type: c_LR.Success}; - var res = {count: 1, type: c_LR.Error, light: false}; + var res = {count: 1, type: c_LR.Error, light: false, packageType: oPackageType}; var checkFile = false; try { var oFile = fs.readFileSync(configL.get('license_file')).toString(); @@ -80,8 +82,19 @@ exports.readLicense = function*() { res.count = 1; res.type = c_LR.Error; - if (checkFile || (yield* _getFileState())) { + if (checkFile) { res.type = c_LR.ExpiredTrial; + } else { + if (constants.PACKAGE_TYPE_OS === oPackageType) { + if (yield* _getFileState()) { + res.type = c_LR.ExpiredTrial; + } + } else { + res.type = (yield* _getFileState()) ? c_LR.Success : c_LR.ExpiredTrial; + if (res.type === c_LR.Success) { + return res; + } + } } } if (res.type === c_LR.Expired || res.type === c_LR.ExpiredTrial) { @@ -97,8 +110,21 @@ exports.readLicense = function*() { }; function* _getFileState() { - return yield utils.promiseRedis(redisClient, redisClient.hget, redisKeyLicense, redisKeyLicense); + const val = yield utils.promiseRedis(redisClient, redisClient.hget, redisKeyLicense, redisKeyLicense); + if (constants.PACKAGE_TYPE_OS === oPackageType) { + return val; + } + + if (null === val) { + yield* _updateFileState(); + return true; + } + + var now = new Date(); + now.setMonth(now.getMonth() - 1); + return (0 >= (now - new Date(val))); } function* _updateFileState() { - yield utils.promiseRedis(redisClient, redisClient.hset, redisKeyLicense, redisKeyLicense, redisKeyLicense); + const val = constants.PACKAGE_TYPE_OS === oPackageType ? redisKeyLicense : new Date(); + yield utils.promiseRedis(redisClient, redisClient.hset, redisKeyLicense, redisKeyLicense, val); } diff --git a/DocService/sources/DocsCoServer.js b/DocService/sources/DocsCoServer.js index 6da06bf8..df07b25c 100644 --- a/DocService/sources/DocsCoServer.js +++ b/DocService/sources/DocsCoServer.js @@ -1883,7 +1883,7 @@ exports.install = function(server, callbackFunction) { try { const c_LR = constants.LICENSE_RESULT; var licenseType = licenseInfo.type; - if (c_LR.Error === licenseType) { + if (constants.PACKAGE_TYPE_OS === licenseInfo.packageType && c_LR.Error === licenseType) { licenseType = c_LR.Success; var count = constants.LICENSE_CONNECTIONS;