Commit 5e5b1f95 authored by Alexander.Trofimov's avatar Alexander.Trofimov

asc_setCanLicense -> setCanLicense

asc_setCanBranding -> setCanBranding

add method asc_getLicenseType
parent eca32e0c
...@@ -37,8 +37,8 @@ AscCommon.baseEditorsApi.prototype._onEndPermissions = function() ...@@ -37,8 +37,8 @@ AscCommon.baseEditorsApi.prototype._onEndPermissions = function()
if (this.isOnFirstConnectEnd && this.isOnLoadLicense) if (this.isOnFirstConnectEnd && this.isOnLoadLicense)
{ {
var oResult = new AscCommon.asc_CAscEditorPermissions(); var oResult = new AscCommon.asc_CAscEditorPermissions();
oResult.asc_setCanLicense(true); oResult.setCanLicense(true);
oResult.asc_setCanBranding(true); oResult.setCanBranding(true);
this.sendEvent('asc_onGetEditorPermissions', oResult); this.sendEvent('asc_onGetEditorPermissions', oResult);
} }
}; };
\ No newline at end of file
...@@ -32,96 +32,15 @@ ...@@ -32,96 +32,15 @@
"use strict"; "use strict";
var g_oLicenseResult = {
Error : 1,
Expired : 2,
Success : 3,
UnknownUser : 4,
Connections : 5
};
var g_sLicenseDefaultUrl = "/license";
var g_sPublicRSAKey = '-----BEGIN CERTIFICATE-----MIIBvTCCASYCCQD55fNzc0WF7TANBgkqhkiG9w0BAQUFADAjMQswCQYDVQQGEwJKUDEUMBIGA1UEChMLMDAtVEVTVC1SU0EwHhcNMTAwNTI4MDIwODUxWhcNMjAwNTI1MDIwODUxWjAjMQswCQYDVQQGEwJKUDEUMBIGA1UEChMLMDAtVEVTVC1SU0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANGEYXtfgDRlWUSDn3haY4NVVQiKI9CzThoua9+DxJuiseyzmBBe7Roh1RPqdvmtOHmEPbJ+kXZYhbozzPRbFGHCJyBfCLzQfVos9/qUQ88u83b0SFA2MGmQWQAlRtLy66EkR4rDRwTj2DzR4EEXgEKpIvo8VBs/3+sHLF3ESgAhAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAEZ6mXFFq3AzfaqWHmCy1ARjlauYAa8ZmUFnLm0emg9dkVBJ63aEqARhtok6bDQDzSJxiLpCEF6G4b/Nv/M/MLyhP+OoOTmETMegAVQMq71choVJyOFE5BtQa6M/lCHEOya5QUfoRF2HF9EjRF44K3OK+u3ivTSj3zwjtpudY5Xo=-----END CERTIFICATE-----';
function CheckLicense(licenseUrl, customerId, userId, userFirstName, userLastName, callback) {
callback(true, g_oLicenseResult.Success);
return;
licenseUrl = licenseUrl ? licenseUrl : g_sLicenseDefaultUrl;
g_fGetJSZipUtils().getBinaryContent(licenseUrl, function(err, data) {
if (err) {
callback(true, g_oLicenseResult.Error);
return;
}
try {
var tmpSize;
var maxSize = 0x4000;
var sTextData = '';
for (var i = 0; i < data.byteLength; i += maxSize) {
tmpSize = data.byteLength - i;
sTextData += String.fromCharCode.apply(null, new Uint8Array(data, i, (tmpSize < maxSize) ? tmpSize : maxSize));
}
var oLicense = JSON.parse(sTextData);
var hSig = oLicense['signature'];
delete oLicense['signature'];
var x509 = new X509();
x509.readCertPEM(g_sPublicRSAKey);
var isValid = x509.subjectPublicKeyRSA.verifyString(JSON.stringify(oLicense), hSig);
callback(false, isValid ? CheckUserInLicense(customerId, userId, userFirstName, userLastName, oLicense) : g_oLicenseResult.Error);
} catch (e) {
callback(true, g_oLicenseResult.Error);
}
});
}
/**
*
* @param customerId
* @param userId
* @param userFirstName
* @param userLastName
* @param oLicense
* @returns {boolean}
*/
function CheckUserInLicense(customerId, userId, userFirstName, userLastName, oLicense) {
var res = g_oLicenseResult.Error;
var superuser = 'onlyoffice';
try {
if (oLicense['users']) {
var userName = (null == userFirstName ? '' : userFirstName) + (null == userLastName ? '' : userLastName);
var sUserHash = CryptoJS.SHA256(userId + userName).toString(CryptoJS.enc.Hex).toLowerCase();
var checkUserHash = false;
if (customerId === oLicense['customer_id'] || oLicense['customer_id'] === (sUserHash = superuser)) {
// users для новой версии - массив
checkUserHash = (-1 !== oLicense['users'].indexOf(sUserHash));
res = g_oLicenseResult.UnknownUser;
}
if (checkUserHash) {
var endDate = new Date(oLicense['end_date']);
res = (endDate >= new Date()) ? g_oLicenseResult.Success : g_oLicenseResult.Expired;
}
}
} catch (e) {
res = g_oLicenseResult.Error;
}
return res;
}
AscCommon.baseEditorsApi.prototype._onCheckLicenseEnd = function(err, res) {
this.licenseResult = {err: err, res: res};
this._onEndPermissions();
};
AscCommon.baseEditorsApi.prototype._onEndPermissions = function () { AscCommon.baseEditorsApi.prototype._onEndPermissions = function () {
if (this.isOnFirstConnectEnd && this.isOnLoadLicense) { if (this.isOnFirstConnectEnd && this.isOnLoadLicense) {
var oResult = new AscCommon.asc_CAscEditorPermissions(); var oResult = new AscCommon.asc_CAscEditorPermissions();
if (null !== this.licenseResult) { if (null !== this.licenseResult) {
var type = this.licenseResult['type']; var type = this.licenseResult['type'];
oResult.asc_setCanLicense(g_oLicenseResult.Success === type); oResult.setLicenseType(type);
oResult.asc_setCanBranding(g_oLicenseResult.Error !== type); // Для тех, у кого есть лицензия, branding доступен oResult.setCanLicense(Asc.c_oLicenseResult.Success === type);
oResult.asc_setCanBranding(g_oLicenseResult.Error !== type); // Для тех, у кого есть лицензия, branding доступен oResult.setCanBranding(Asc.c_oLicenseResult.Error !== type); // Для тех, у кого есть лицензия, branding доступен
oResult.asc_setIsLight(this.licenseResult['light']); oResult.setIsLight(this.licenseResult['light']);
} }
this.sendEvent('asc_onGetEditorPermissions', oResult); this.sendEvent('asc_onGetEditorPermissions', oResult);
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment