mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
SYNC: better handling of expired license in electron app
This commit is contained in:
committed by
Diflow
parent
6f4173650a
commit
3cc2abf8b9
@@ -16,7 +16,7 @@ const connections = require('../controllers/connections');
|
|||||||
const { getAuthProviderFromReq } = require('../auth/authProvider');
|
const { getAuthProviderFromReq } = require('../auth/authProvider');
|
||||||
const { checkLicense, checkLicenseKey } = require('../utility/checkLicense');
|
const { checkLicense, checkLicenseKey } = require('../utility/checkLicense');
|
||||||
const storage = require('./storage');
|
const storage = require('./storage');
|
||||||
const { getAuthProxyUrl } = require('../utility/authProxy');
|
const { getAuthProxyUrl, tryToGetRefreshedLicense } = require('../utility/authProxy');
|
||||||
const { getPublicHardwareFingerprint } = require('../utility/hardwareFingerprint');
|
const { getPublicHardwareFingerprint } = require('../utility/hardwareFingerprint');
|
||||||
const { extractErrorMessage } = require('dbgate-tools');
|
const { extractErrorMessage } = require('dbgate-tools');
|
||||||
const {
|
const {
|
||||||
@@ -191,6 +191,7 @@ module.exports = {
|
|||||||
return {
|
return {
|
||||||
...this.fillMissingSettings(JSON.parse(settingsText)),
|
...this.fillMissingSettings(JSON.parse(settingsText)),
|
||||||
'other.licenseKey': platformInfo.isElectron ? await this.loadLicenseKey() : undefined,
|
'other.licenseKey': platformInfo.isElectron ? await this.loadLicenseKey() : undefined,
|
||||||
|
// 'other.licenseKey': await this.loadLicenseKey(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -208,21 +209,23 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
saveLicenseKey_meta: true,
|
saveLicenseKey_meta: true,
|
||||||
async saveLicenseKey({ licenseKey }) {
|
async saveLicenseKey({ licenseKey, forceSave = false }) {
|
||||||
const decoded = jwt.decode(licenseKey?.trim());
|
if (!forceSave) {
|
||||||
if (!decoded) {
|
const decoded = jwt.decode(licenseKey?.trim());
|
||||||
return {
|
if (!decoded) {
|
||||||
status: 'error',
|
return {
|
||||||
errorMessage: 'Invalid license key',
|
status: 'error',
|
||||||
};
|
errorMessage: 'Invalid license key',
|
||||||
}
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const { exp } = decoded;
|
const { exp } = decoded;
|
||||||
if (exp * 1000 < Date.now()) {
|
if (exp * 1000 < Date.now()) {
|
||||||
return {
|
return {
|
||||||
status: 'error',
|
status: 'error',
|
||||||
errorMessage: 'License key is expired',
|
errorMessage: 'License key is expired',
|
||||||
};
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -297,7 +300,7 @@ module.exports = {
|
|||||||
// this.settingsValue = updated;
|
// this.settingsValue = updated;
|
||||||
|
|
||||||
if (currentValue['other.licenseKey'] != values['other.licenseKey']) {
|
if (currentValue['other.licenseKey'] != values['other.licenseKey']) {
|
||||||
await this.saveLicenseKey({ licenseKey: values['other.licenseKey'] });
|
await this.saveLicenseKey({ licenseKey: values['other.licenseKey'], forceSave: true });
|
||||||
socket.emitChanged(`config-changed`);
|
socket.emitChanged(`config-changed`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -327,6 +330,16 @@ module.exports = {
|
|||||||
return resp;
|
return resp;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getNewLicense_meta: true,
|
||||||
|
async getNewLicense({ oldLicenseKey }) {
|
||||||
|
const newLicenseKey = await tryToGetRefreshedLicense(oldLicenseKey);
|
||||||
|
const res = await checkLicenseKey(newLicenseKey.token);
|
||||||
|
if (res.status == 'ok') {
|
||||||
|
res.licenseKey = newLicenseKey.token;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
|
||||||
recryptDatabaseForExport(db) {
|
recryptDatabaseForExport(db) {
|
||||||
const encryptionKey = generateTransportEncryptionKey();
|
const encryptionKey = generateTransportEncryptionKey();
|
||||||
const transportEncryptor = createTransportEncryptor(encryptionKey);
|
const transportEncryptor = createTransportEncryptor(encryptionKey);
|
||||||
|
|||||||
@@ -528,7 +528,27 @@ ORDER BY
|
|||||||
<div>License key expiration: <b>{safeFormatDate(licenseKeyCheckResult.expiration)}</b></div>
|
<div>License key expiration: <b>{safeFormatDate(licenseKeyCheckResult.expiration)}</b></div>
|
||||||
{/if}
|
{/if}
|
||||||
{:else if licenseKeyCheckResult.status == 'error'}
|
{:else if licenseKeyCheckResult.status == 'error'}
|
||||||
<FontIcon icon="img error" /> License key is invalid
|
<div>
|
||||||
|
<FontIcon icon="img error" />
|
||||||
|
{licenseKeyCheckResult.errorMessage ?? 'License key is invalid'}
|
||||||
|
{#if licenseKeyCheckResult.expiration}
|
||||||
|
<div>License key expiration: <b>{safeFormatDate(licenseKeyCheckResult.expiration)}</b></div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{#if licenseKeyCheckResult.isExpired}
|
||||||
|
<div class="mt-2">
|
||||||
|
<FormStyledButton
|
||||||
|
value="Check for new license key"
|
||||||
|
skipWidth
|
||||||
|
on:click={async () => {
|
||||||
|
licenseKeyCheckResult = await apiCall('config/get-new-license', { oldLicenseKey: licenseKey });
|
||||||
|
if (licenseKeyCheckResult.licenseKey) {
|
||||||
|
apiCall('config/update-settings', { 'other.licenseKey': licenseKeyCheckResult.licenseKey });
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user