mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 17:13:58 +00:00
trial
This commit is contained in:
@@ -16,7 +16,7 @@ const BrowserWindow = electron.BrowserWindow;
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
const mainMenuDefinition = require('./mainMenuDefinition');
|
const mainMenuDefinition = require('./mainMenuDefinition');
|
||||||
const { isProApp, checkLicense } = require('./proTools');
|
const { isProApp } = require('./proTools');
|
||||||
let disableAutoUpgrade = false;
|
let disableAutoUpgrade = false;
|
||||||
|
|
||||||
// require('@electron/remote/main').initialize();
|
// require('@electron/remote/main').initialize();
|
||||||
@@ -339,13 +339,11 @@ function createWindow() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const licenseOk = !isProApp() || checkLicense(licenseKey) == 'premium';
|
|
||||||
|
|
||||||
let bounds = initialConfig['winBounds'];
|
let bounds = initialConfig['winBounds'];
|
||||||
if (bounds) {
|
if (bounds) {
|
||||||
bounds = ensureBoundsVisible(bounds);
|
bounds = ensureBoundsVisible(bounds);
|
||||||
}
|
}
|
||||||
useNativeMenu = settingsJson['app.useNativeMenu'] || !licenseOk;
|
useNativeMenu = settingsJson['app.useNativeMenu'];
|
||||||
|
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 1200,
|
width: 1200,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const { hasPermission } = require('../utility/hasPermission');
|
|||||||
const socket = require('../utility/socket');
|
const socket = require('../utility/socket');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const AsyncLock = require('async-lock');
|
const AsyncLock = require('async-lock');
|
||||||
|
const jwt = require('jsonwebtoken');
|
||||||
|
|
||||||
const currentVersion = require('../currentVersion');
|
const currentVersion = require('../currentVersion');
|
||||||
const platformInfo = require('../utility/platformInfo');
|
const platformInfo = require('../utility/platformInfo');
|
||||||
@@ -151,6 +152,22 @@ module.exports = {
|
|||||||
|
|
||||||
saveLicenseKey_meta: true,
|
saveLicenseKey_meta: true,
|
||||||
async saveLicenseKey({ licenseKey }) {
|
async saveLicenseKey({ licenseKey }) {
|
||||||
|
const decoded = jwt.decode(licenseKey);
|
||||||
|
if (!decoded) {
|
||||||
|
return {
|
||||||
|
status: 'error',
|
||||||
|
errorMessage: 'Invalid license key',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const { exp } = decoded;
|
||||||
|
if (exp * 1000 < Date.now()) {
|
||||||
|
return {
|
||||||
|
status: 'error',
|
||||||
|
errorMessage: 'License key is expired',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (process.env.STORAGE_DATABASE) {
|
if (process.env.STORAGE_DATABASE) {
|
||||||
await storage.writeConfig({ group: 'license', config: { licenseKey } });
|
await storage.writeConfig({ group: 'license', config: { licenseKey } });
|
||||||
@@ -159,20 +176,32 @@ module.exports = {
|
|||||||
await fs.writeFile(path.join(datadir(), 'license.key'), licenseKey);
|
await fs.writeFile(path.join(datadir(), 'license.key'), licenseKey);
|
||||||
}
|
}
|
||||||
socket.emitChanged(`config-changed`);
|
socket.emitChanged(`config-changed`);
|
||||||
|
return { status: 'ok' };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return null;
|
return {
|
||||||
|
status: 'error',
|
||||||
|
errorMessage: err.message,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
startTrial_meta: true,
|
startTrial_meta: true,
|
||||||
async startTrial() {
|
async startTrial() {
|
||||||
try {
|
try {
|
||||||
const resp = await axios.default.post(`${getAuthProxyUrl()}/trial-license`, { type: 'premium-trial', days: 30 });
|
const ipResp = await axios.default.get('https://api.ipify.org?format=json');
|
||||||
return resp.data;
|
|
||||||
|
const resp = await axios.default.post(`${getAuthProxyUrl()}/trial-license`, {
|
||||||
|
type: 'premium-trial',
|
||||||
|
days: 30,
|
||||||
|
publicIp: ipResp.data.ip,
|
||||||
|
});
|
||||||
|
const { token } = resp.data;
|
||||||
|
|
||||||
|
return await this.saveLicenseKey({ licenseKey: token });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return {
|
return {
|
||||||
status: 'error',
|
status: 'error',
|
||||||
message: err.messa,
|
errorMessage: err.message,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
import FormSubmit from './forms/FormSubmit.svelte';
|
import FormSubmit from './forms/FormSubmit.svelte';
|
||||||
import { apiCall } from './utility/api';
|
import { apiCall } from './utility/api';
|
||||||
import FormStyledButton from './buttons/FormStyledButton.svelte';
|
import FormStyledButton from './buttons/FormStyledButton.svelte';
|
||||||
|
import getElectron from './utility/getElectron';
|
||||||
|
|
||||||
const config = useConfig();
|
const config = useConfig();
|
||||||
const values = writable({ amoid: null, databaseServer: null });
|
const values = writable({ amoid: null, databaseServer: null });
|
||||||
@@ -39,8 +40,12 @@
|
|||||||
value="Save license"
|
value="Save license"
|
||||||
on:click={async e => {
|
on:click={async e => {
|
||||||
const { licenseKey } = e.detail;
|
const { licenseKey } = e.detail;
|
||||||
await apiCall('config/save-license-key', { licenseKey });
|
const resp = await apiCall('config/save-license-key', { licenseKey });
|
||||||
internalRedirectTo('/index.html');
|
if (resp?.status == 'ok') {
|
||||||
|
internalRedirectTo('/index.html');
|
||||||
|
} else {
|
||||||
|
errorMessage = resp?.errorMessage || 'Error saving license key';
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -51,16 +56,26 @@
|
|||||||
on:click={async e => {
|
on:click={async e => {
|
||||||
errorMessage = '';
|
errorMessage = '';
|
||||||
const license = await apiCall('config/start-trial');
|
const license = await apiCall('config/start-trial');
|
||||||
if (license?.token) {
|
if (license?.status == 'ok') {
|
||||||
await apiCall('config/save-license-key', { licenseKey: license.token });
|
|
||||||
internalRedirectTo('/index.html');
|
internalRedirectTo('/index.html');
|
||||||
} else {
|
} else {
|
||||||
errorMessage = license?.message || 'Error starting trial';
|
errorMessage = license?.errorMessage || 'Error starting trial';
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if getElectron()}
|
||||||
|
<div class="submit">
|
||||||
|
<FormStyledButton
|
||||||
|
value="Exit"
|
||||||
|
on:click={e => {
|
||||||
|
getElectron().send('quit-app');
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if errorMessage}
|
{#if errorMessage}
|
||||||
<div class="error">{errorMessage}</div>
|
<div class="error">{errorMessage}</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user