mirror of
https://github.com/strapi/strapi.git
synced 2025-09-07 15:49:24 +00:00
Add check
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
f424bdfeb3
commit
5b4b95dc49
@ -102,3 +102,4 @@ test
|
|||||||
testApp
|
testApp
|
||||||
coverage
|
coverage
|
||||||
ee
|
ee
|
||||||
|
webpack.config.dev.js
|
@ -12,7 +12,7 @@ const getPkgPath = name => path.dirname(require.resolve(`${name}/package.json`))
|
|||||||
|
|
||||||
function getCustomWebpackConfig(dir, config) {
|
function getCustomWebpackConfig(dir, config) {
|
||||||
const adminConfigPath = path.join(dir, 'admin', 'admin.config.js');
|
const adminConfigPath = path.join(dir, 'admin', 'admin.config.js');
|
||||||
let webpackConfig = getWebpackConfig(config);
|
let webpackConfig = getWebpackConfig({ dir, ...config });
|
||||||
|
|
||||||
if (fs.existsSync(adminConfigPath)) {
|
if (fs.existsSync(adminConfigPath)) {
|
||||||
const adminConfig = require(path.resolve(adminConfigPath));
|
const adminConfig = require(path.resolve(adminConfigPath));
|
||||||
|
@ -4,4 +4,7 @@ const fs = require('fs-extra');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const appAdminPath = path.join(__dirname, 'admin');
|
const appAdminPath = path.join(__dirname, 'admin');
|
||||||
|
|
||||||
module.exports = fs.existsSync(path.join(appAdminPath, 'ee'));
|
// eslint-disable-next-line node/no-extraneous-require
|
||||||
|
const hasEE = require('strapi/lib/utils/ee');
|
||||||
|
|
||||||
|
module.exports = dir => dir && hasEE({ dir }) && fs.existsSync(path.join(appAdminPath, 'ee'));
|
||||||
|
@ -10,13 +10,15 @@ const TerserPlugin = require('terser-webpack-plugin');
|
|||||||
const WebpackBar = require('webpackbar');
|
const WebpackBar = require('webpackbar');
|
||||||
const isWsl = require('is-wsl');
|
const isWsl = require('is-wsl');
|
||||||
const alias = require('./webpack.alias.js');
|
const alias = require('./webpack.alias.js');
|
||||||
const IS_EE = require('./is_ee_env');
|
const loadEE = require('./is_ee_env');
|
||||||
|
|
||||||
// TODO: parametrize
|
// TODO: parametrize
|
||||||
const URLs = {
|
const URLs = {
|
||||||
mode: 'host',
|
mode: 'host',
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = ({
|
module.exports = ({
|
||||||
|
dir,
|
||||||
entry,
|
entry,
|
||||||
dest,
|
dest,
|
||||||
env,
|
env,
|
||||||
@ -26,6 +28,7 @@ module.exports = ({
|
|||||||
publicPath: '/admin/',
|
publicPath: '/admin/',
|
||||||
},
|
},
|
||||||
}) => {
|
}) => {
|
||||||
|
const isEE = loadEE(dir);
|
||||||
const isProduction = env === 'production';
|
const isProduction = env === 'production';
|
||||||
const webpackPlugins = isProduction
|
const webpackPlugins = isProduction
|
||||||
? [
|
? [
|
||||||
@ -192,7 +195,7 @@ module.exports = ({
|
|||||||
const wantedPath =
|
const wantedPath =
|
||||||
containerPathName.length === 1 ? componentPathName[0] : containerPathName[0];
|
containerPathName.length === 1 ? componentPathName[0] : containerPathName[0];
|
||||||
|
|
||||||
if (IS_EE) {
|
if (isEE) {
|
||||||
resource.request = resource.request.replace(
|
resource.request = resource.request.replace(
|
||||||
/ee_else_ce/,
|
/ee_else_ce/,
|
||||||
path.join(wantedPath, '..', 'ee')
|
path.join(wantedPath, '..', 'ee')
|
||||||
|
@ -26,6 +26,7 @@ const { createCoreStore, coreStoreModel } = require('./services/core-store');
|
|||||||
const createEntityService = require('./services/entity-service');
|
const createEntityService = require('./services/entity-service');
|
||||||
const createEntityValidator = require('./services/entity-validator');
|
const createEntityValidator = require('./services/entity-validator');
|
||||||
const createTelemetry = require('./services/metrics');
|
const createTelemetry = require('./services/metrics');
|
||||||
|
const ee = require('./utils/ee');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an Strapi instance.
|
* Construct an Strapi instance.
|
||||||
@ -50,11 +51,13 @@ class Strapi {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.dir = opts.dir || process.cwd();
|
this.dir = opts.dir || process.cwd();
|
||||||
|
|
||||||
this.admin = {};
|
this.admin = {};
|
||||||
this.plugins = {};
|
this.plugins = {};
|
||||||
this.config = loadConfiguration(this.dir, opts);
|
this.config = loadConfiguration(this.dir, opts);
|
||||||
this.isLoaded = false;
|
this.isLoaded = false;
|
||||||
|
|
||||||
|
this.EE = ee({ dir: this.dir, logger });
|
||||||
// internal services.
|
// internal services.
|
||||||
this.fs = createStrapiFs(this);
|
this.fs = createStrapiFs(this);
|
||||||
this.eventHub = createEventHub();
|
this.eventHub = createEventHub();
|
||||||
|
@ -23,7 +23,8 @@ module.exports = async strapi => {
|
|||||||
// load ee files if they exist
|
// load ee files if they exist
|
||||||
let eeFiles = {};
|
let eeFiles = {};
|
||||||
let eeConfig = {};
|
let eeConfig = {};
|
||||||
if (process.env.STRAPI_DISABLE_EE !== 'true') {
|
|
||||||
|
if (process.env.STRAPI_DISABLE_EE !== 'true' && strapi.EE) {
|
||||||
const eeAdminPath = `${adminPath}/ee`;
|
const eeAdminPath = `${adminPath}/ee`;
|
||||||
[eeFiles, eeConfig] = await Promise.all([
|
[eeFiles, eeConfig] = await Promise.all([
|
||||||
loadFiles(eeAdminPath, '!(config|test)/*.*(js|json)'),
|
loadFiles(eeAdminPath, '!(config|test)/*.*(js|json)'),
|
||||||
|
54
packages/strapi/lib/utils/ee.js
Normal file
54
packages/strapi/lib/utils/ee.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
const publicKey = fs.readFileSync(path.join(__dirname, '../utils/resources/key.pub'));
|
||||||
|
|
||||||
|
const defaultLogger = {
|
||||||
|
warn: console.warn.bind(console),
|
||||||
|
info: console.log.bind(console),
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = ({ dir, logger = defaultLogger }) => {
|
||||||
|
const warnAndReturn = (msg = 'Invalid license. Starting in CE.') => {
|
||||||
|
logger.warn(msg);
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const licensePath = path.join(dir, 'license.txt');
|
||||||
|
|
||||||
|
let license;
|
||||||
|
if (process.env.STRAPI_LICENSE) {
|
||||||
|
license = process.env.STRAPI_LICENSE;
|
||||||
|
} else if (fs.existsSync(licensePath)) {
|
||||||
|
license = fs.readFileSync(licensePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!license) return false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const plainLicense = Buffer.from(license, 'base64').toString();
|
||||||
|
const [signatureb64, contentb64] = plainLicense.split('\n');
|
||||||
|
|
||||||
|
const signature = Buffer.from(signatureb64, 'base64');
|
||||||
|
const content = Buffer.from(contentb64, 'base64').toString();
|
||||||
|
|
||||||
|
const verifier = crypto.createVerify('RSA-SHA256');
|
||||||
|
verifier.update(content);
|
||||||
|
verifier.end();
|
||||||
|
|
||||||
|
const isValid = verifier.verify(publicKey, signature);
|
||||||
|
if (!isValid) return warnAndReturn();
|
||||||
|
|
||||||
|
const ctx = JSON.parse(content);
|
||||||
|
|
||||||
|
if (ctx.expireAt < new Date().getTime()) {
|
||||||
|
return warnAndReturn('License expired');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
return warnAndReturn();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info('License checked. Starting in EE.');
|
||||||
|
return true;
|
||||||
|
};
|
9
packages/strapi/lib/utils/resources/key.pub
Normal file
9
packages/strapi/lib/utils/resources/key.pub
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
-----BEGIN PUBLIC KEY-----
|
||||||
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApuI1XlPkYos3WsSeVPtS
|
||||||
|
l1Q2k8GnLEO5vFZ4EuSghMbqI+yE0tWVEaiptdV3KgERaALRXmH+IFrHqvSRjKQC
|
||||||
|
1ORUarBU5ntWbNEr713R3K0BPOzz9OOoWHdk+Wmr4ViOTk0iD1u4bw/97RpyMoBm
|
||||||
|
+pXeBLHbEESK2kelk+LEmKUoY5nXp6KzZV5wxgD5QweZheU7mjXL5WMpIBJva8kp
|
||||||
|
RZMYXEF+uSZIep0q5FHEo2AazGUMAU3GjY/dpXisLmtleOa1xlKZmkvaXl/D2Mhb
|
||||||
|
BBqPbDMa72ToZg2J8K5UP9zXUP41FHr7o9rwSJ2uOkuZPg5nhDXeoVbrJwxP/U1M
|
||||||
|
nQIDAQAB
|
||||||
|
-----END PUBLIC KEY-----
|
Loading…
x
Reference in New Issue
Block a user