diff --git a/app/src/electron.js b/app/src/electron.js index 420e4bda..04b9d47e 100644 --- a/app/src/electron.js +++ b/app/src/electron.js @@ -16,7 +16,7 @@ const BrowserWindow = electron.BrowserWindow; const path = require('path'); const url = require('url'); const mainMenuDefinition = require('./mainMenuDefinition'); -const { isProApp, checkLicense } = require('./proTools'); +const { isProApp } = require('./proTools'); let disableAutoUpgrade = false; // require('@electron/remote/main').initialize(); @@ -339,13 +339,11 @@ function createWindow() { } } - const licenseOk = !isProApp() || checkLicense(licenseKey) == 'premium'; - let bounds = initialConfig['winBounds']; if (bounds) { bounds = ensureBoundsVisible(bounds); } - useNativeMenu = settingsJson['app.useNativeMenu'] || !licenseOk; + useNativeMenu = settingsJson['app.useNativeMenu']; mainWindow = new BrowserWindow({ width: 1200, diff --git a/packages/api/src/controllers/config.js b/packages/api/src/controllers/config.js index 3ec18a0d..3b36d4df 100644 --- a/packages/api/src/controllers/config.js +++ b/packages/api/src/controllers/config.js @@ -7,6 +7,7 @@ const { hasPermission } = require('../utility/hasPermission'); const socket = require('../utility/socket'); const _ = require('lodash'); const AsyncLock = require('async-lock'); +const jwt = require('jsonwebtoken'); const currentVersion = require('../currentVersion'); const platformInfo = require('../utility/platformInfo'); @@ -151,6 +152,22 @@ module.exports = { saveLicenseKey_meta: true, 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 { if (process.env.STORAGE_DATABASE) { await storage.writeConfig({ group: 'license', config: { licenseKey } }); @@ -159,20 +176,32 @@ module.exports = { await fs.writeFile(path.join(datadir(), 'license.key'), licenseKey); } socket.emitChanged(`config-changed`); + return { status: 'ok' }; } catch (err) { - return null; + return { + status: 'error', + errorMessage: err.message, + }; } }, startTrial_meta: true, async startTrial() { try { - const resp = await axios.default.post(`${getAuthProxyUrl()}/trial-license`, { type: 'premium-trial', days: 30 }); - return resp.data; + const ipResp = await axios.default.get('https://api.ipify.org?format=json'); + + 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) { return { status: 'error', - message: err.messa, + errorMessage: err.message, }; } }, diff --git a/packages/web/src/EnterLicensePage.svelte b/packages/web/src/EnterLicensePage.svelte index b0f428ec..85ee885b 100644 --- a/packages/web/src/EnterLicensePage.svelte +++ b/packages/web/src/EnterLicensePage.svelte @@ -11,6 +11,7 @@ import FormSubmit from './forms/FormSubmit.svelte'; import { apiCall } from './utility/api'; import FormStyledButton from './buttons/FormStyledButton.svelte'; + import getElectron from './utility/getElectron'; const config = useConfig(); const values = writable({ amoid: null, databaseServer: null }); @@ -39,8 +40,12 @@ value="Save license" on:click={async e => { const { licenseKey } = e.detail; - await apiCall('config/save-license-key', { licenseKey }); - internalRedirectTo('/index.html'); + const resp = await apiCall('config/save-license-key', { licenseKey }); + if (resp?.status == 'ok') { + internalRedirectTo('/index.html'); + } else { + errorMessage = resp?.errorMessage || 'Error saving license key'; + } }} /> @@ -51,16 +56,26 @@ on:click={async e => { errorMessage = ''; const license = await apiCall('config/start-trial'); - if (license?.token) { - await apiCall('config/save-license-key', { licenseKey: license.token }); + if (license?.status == 'ok') { internalRedirectTo('/index.html'); } else { - errorMessage = license?.message || 'Error starting trial'; + errorMessage = license?.errorMessage || 'Error starting trial'; } }} /> + {#if getElectron()} +