mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 19:36:00 +00:00
license refactor WIP
This commit is contained in:
@@ -12,6 +12,8 @@ const currentVersion = require('../currentVersion');
|
||||
const platformInfo = require('../utility/platformInfo');
|
||||
const connections = require('../controllers/connections');
|
||||
const { getAuthProviderFromReq } = require('../auth/authProvider');
|
||||
const isElectron = require('is-electron');
|
||||
const { checkLicenseApp, checkLicenseWeb } = require('../utility/checkLicense');
|
||||
|
||||
const lock = new AsyncLock();
|
||||
|
||||
@@ -45,6 +47,9 @@ module.exports = {
|
||||
'Basic authentization is not allowed, when using storage. Cannot use both STORAGE_DATABASE and BASIC_AUTH';
|
||||
}
|
||||
|
||||
const checkedLicense = isElectron() ? checkLicenseApp() : checkLicenseWeb();
|
||||
const isLicenseValid = checkedLicense?.status == 'ok';
|
||||
|
||||
return {
|
||||
runAsPortal: !!connections.portalConnections,
|
||||
singleDbConnection: connections.singleDbConnection,
|
||||
@@ -55,8 +60,8 @@ module.exports = {
|
||||
allowShellScripting: platformInfo.allowShellScripting,
|
||||
isDocker: platformInfo.isDocker,
|
||||
isElectron: platformInfo.isElectron,
|
||||
isLicenseValid: platformInfo.isLicenseValid,
|
||||
checkedLicense: platformInfo.checkedLicense,
|
||||
isLicenseValid,
|
||||
checkedLicense,
|
||||
configurationError,
|
||||
logoutUrl: await authProvider.getLogoutUrl(),
|
||||
permissions,
|
||||
@@ -125,6 +130,24 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
async loadLicenseKey() {
|
||||
try {
|
||||
const licenseKey = await fs.readFile(path.join(datadir(), 'license.key'), { encoding: 'utf-8' });
|
||||
return licenseKey;
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
saveLicenseKey_meta: true,
|
||||
async saveLicenseKey({ licenseKey }) {
|
||||
try {
|
||||
await fs.writeFile(path.join(datadir(), 'license.key'), licenseKey);
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
updateSettings_meta: true,
|
||||
async updateSettings(values, req) {
|
||||
if (!hasPermission(`settings/change`, req)) return false;
|
||||
|
||||
Reference in New Issue
Block a user