delete constant PACKAGE_TYPE_D

trial -> mode
This commit is contained in:
Alexander.Trofimov
2017-10-25 17:44:21 +03:00
parent c137ce84f5
commit dc3c43f6b8
3 changed files with 26 additions and 6 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,7 +178,6 @@ 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 c_LM = constants.LICENSE_MODE;
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 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,8 +76,9 @@ 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 = isTrial ? new Date() : oBuildDate;
if (endDate >= checkDate && 2 <= oLicense['version']) {
res.connections = Math.max(res.count, oLicense['process'] >> 0) * 100;
res.count = resMax.count;
@ -99,7 +109,7 @@ exports.readLicense = function*() {
} else {
res.type = (yield* _getFileState()) ? c_LR.Success : c_LR.ExpiredTrial;
if (res.type === c_LR.Success) {
res.trial = (constants.PACKAGE_TYPE_D === oPackageType);
res.mode = c_LM.Trial;
res.count = resMax.count;
return res;
}
@ -119,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

@ -2528,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,