mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 12:43:58 +00:00
licence key
This commit is contained in:
@@ -13,7 +13,7 @@ const platformInfo = require('../utility/platformInfo');
|
|||||||
const connections = require('../controllers/connections');
|
const connections = require('../controllers/connections');
|
||||||
const { getAuthProviderFromReq } = require('../auth/authProvider');
|
const { getAuthProviderFromReq } = require('../auth/authProvider');
|
||||||
const isElectron = require('is-electron');
|
const isElectron = require('is-electron');
|
||||||
const { checkLicenseApp, checkLicenseWeb } = require('../utility/checkLicense');
|
const { checkLicense, checkLicenseKey } = require('../utility/checkLicense');
|
||||||
|
|
||||||
const lock = new AsyncLock();
|
const lock = new AsyncLock();
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ module.exports = {
|
|||||||
'Basic authentization is not allowed, when using storage. Cannot use both STORAGE_DATABASE and BASIC_AUTH';
|
'Basic authentization is not allowed, when using storage. Cannot use both STORAGE_DATABASE and BASIC_AUTH';
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkedLicense = isElectron() ? checkLicenseApp() : checkLicenseWeb();
|
const checkedLicense = await checkLicense();
|
||||||
const isLicenseValid = checkedLicense?.status == 'ok';
|
const isLicenseValid = checkedLicense?.status == 'ok';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -124,7 +124,10 @@ module.exports = {
|
|||||||
async loadSettings() {
|
async loadSettings() {
|
||||||
try {
|
try {
|
||||||
const settingsText = await fs.readFile(path.join(datadir(), 'settings.json'), { encoding: 'utf-8' });
|
const settingsText = await fs.readFile(path.join(datadir(), 'settings.json'), { encoding: 'utf-8' });
|
||||||
return this.fillMissingSettings(JSON.parse(settingsText));
|
return {
|
||||||
|
...this.fillMissingSettings(JSON.parse(settingsText)),
|
||||||
|
'other.licenseKey': await this.loadLicenseKey(),
|
||||||
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return this.fillMissingSettings({});
|
return this.fillMissingSettings({});
|
||||||
}
|
}
|
||||||
@@ -158,10 +161,16 @@ module.exports = {
|
|||||||
try {
|
try {
|
||||||
const updated = {
|
const updated = {
|
||||||
...currentValue,
|
...currentValue,
|
||||||
...values,
|
..._.omit(values, ['other.licenseKey']),
|
||||||
};
|
};
|
||||||
await fs.writeFile(path.join(datadir(), 'settings.json'), JSON.stringify(updated, undefined, 2));
|
await fs.writeFile(path.join(datadir(), 'settings.json'), JSON.stringify(updated, undefined, 2));
|
||||||
// this.settingsValue = updated;
|
// this.settingsValue = updated;
|
||||||
|
|
||||||
|
if (currentValue['other.licenseKey'] != values['other.licenseKey']) {
|
||||||
|
await this.saveLicenseKey({ licenseKey: values['other.licenseKey'] });
|
||||||
|
socket.emitChanged(`config-changed`);
|
||||||
|
}
|
||||||
|
|
||||||
socket.emitChanged(`settings-changed`);
|
socket.emitChanged(`settings-changed`);
|
||||||
return updated;
|
return updated;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -176,4 +185,10 @@ module.exports = {
|
|||||||
const resp = await axios.default.get('https://raw.githubusercontent.com/dbgate/dbgate/master/CHANGELOG.md');
|
const resp = await axios.default.get('https://raw.githubusercontent.com/dbgate/dbgate/master/CHANGELOG.md');
|
||||||
return resp.data;
|
return resp.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
checkLicense_meta: true,
|
||||||
|
async checkLicense({ licenseKey }) {
|
||||||
|
const resp = await checkLicenseKey(licenseKey);
|
||||||
|
return resp;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const os = require('os');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const processArgs = require('./processArgs');
|
const processArgs = require('./processArgs');
|
||||||
const isElectron = require('is-electron');
|
const isElectron = require('is-electron');
|
||||||
const { checkLicenseWeb, checkLicenseApp } = require('./checkLicense');
|
|
||||||
|
|
||||||
const platform = process.env.OS_OVERRIDE ? process.env.OS_OVERRIDE : process.platform;
|
const platform = process.env.OS_OVERRIDE ? process.env.OS_OVERRIDE : process.platform;
|
||||||
const isWindows = platform === 'win32';
|
const isWindows = platform === 'win32';
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
export let name;
|
export let name;
|
||||||
export let defaultValue = undefined;
|
export let defaultValue = undefined;
|
||||||
export let saveOnInput = false;
|
export let saveOnInput = false;
|
||||||
|
export let onChange = null;
|
||||||
|
|
||||||
const { values, setFieldValue } = getFormContext();
|
const { values, setFieldValue } = getFormContext();
|
||||||
</script>
|
</script>
|
||||||
@@ -17,5 +18,8 @@
|
|||||||
if (saveOnInput) {
|
if (saveOnInput) {
|
||||||
setFieldValue(name, e.target['value']);
|
setFieldValue(name, e.target['value']);
|
||||||
}
|
}
|
||||||
|
if (onChange) {
|
||||||
|
onChange(e.target['value']);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -33,9 +33,13 @@
|
|||||||
import ThemeSkeleton from './ThemeSkeleton.svelte';
|
import ThemeSkeleton from './ThemeSkeleton.svelte';
|
||||||
import { isProApp } from '../utility/proTools';
|
import { isProApp } from '../utility/proTools';
|
||||||
import FormTextAreaField from '../forms/FormTextAreaField.svelte';
|
import FormTextAreaField from '../forms/FormTextAreaField.svelte';
|
||||||
|
import { apiCall } from '../utility/api';
|
||||||
|
import { useSettings } from '../utility/metadataLoaders';
|
||||||
|
import { derived } from 'svelte/store';
|
||||||
|
|
||||||
const electron = getElectron();
|
const electron = getElectron();
|
||||||
let restartWarning = false;
|
let restartWarning = false;
|
||||||
|
let licenseKeyCheckResult = null;
|
||||||
|
|
||||||
export let selectedTab = 0;
|
export let selectedTab = 0;
|
||||||
|
|
||||||
@@ -60,6 +64,23 @@ ORDER BY
|
|||||||
$selectedWidget = 'plugins';
|
$selectedWidget = 'plugins';
|
||||||
$visibleWidgetSideBar = true;
|
$visibleWidgetSideBar = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const settings = useSettings();
|
||||||
|
const settingsValues = derived(settings, $settings => {
|
||||||
|
if (!$settings) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return $settings;
|
||||||
|
});
|
||||||
|
|
||||||
|
$: licenseKey = $settingsValues['other.licenseKey'];
|
||||||
|
let checkedLicenseKey = false;
|
||||||
|
$: if (licenseKey && !checkedLicenseKey) {
|
||||||
|
checkedLicenseKey = true;
|
||||||
|
apiCall('config/check-license', { licenseKey }).then(result => {
|
||||||
|
licenseKeyCheckResult = result;
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<SettingsFormProvider>
|
<SettingsFormProvider>
|
||||||
@@ -72,7 +93,7 @@ ORDER BY
|
|||||||
isInline
|
isInline
|
||||||
tabs={[
|
tabs={[
|
||||||
{ label: 'General', slot: 1 },
|
{ label: 'General', slot: 1 },
|
||||||
isProApp() && { label: 'License', slot: 7 },
|
isProApp() && electron && { label: 'License', slot: 7 },
|
||||||
{ label: 'Connection', slot: 2 },
|
{ label: 'Connection', slot: 2 },
|
||||||
{ label: 'Themes', slot: 3 },
|
{ label: 'Themes', slot: 3 },
|
||||||
{ label: 'Default Actions', slot: 4 },
|
{ label: 'Default Actions', slot: 4 },
|
||||||
@@ -325,7 +346,29 @@ ORDER BY
|
|||||||
|
|
||||||
<svelte:fragment slot="7">
|
<svelte:fragment slot="7">
|
||||||
<div class="heading">License</div>
|
<div class="heading">License</div>
|
||||||
<FormTextAreaField name="other.licenseKey" label="License key" rows={5} />
|
<FormTextAreaField
|
||||||
|
name="other.licenseKey"
|
||||||
|
label="License key"
|
||||||
|
rows={7}
|
||||||
|
onChange={async value => {
|
||||||
|
licenseKeyCheckResult = await apiCall('config/check-license', { licenseKey: value });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{#if licenseKeyCheckResult}
|
||||||
|
<div class="m-3 ml-5">
|
||||||
|
{#if licenseKeyCheckResult.status == 'ok'}
|
||||||
|
<div>
|
||||||
|
<FontIcon icon="img ok" /> License key is valid
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
License valid to: {licenseKeyCheckResult.validTo}
|
||||||
|
</div>
|
||||||
|
<div>License key expiration: {licenseKeyCheckResult.expiration}</div>
|
||||||
|
{:else if licenseKeyCheckResult.status == 'error'}
|
||||||
|
<FontIcon icon="img error" /> License key is invalid
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
</TabControl>
|
</TabControl>
|
||||||
</FormValues>
|
</FormValues>
|
||||||
|
|||||||
Reference in New Issue
Block a user