mirror of
https://github.com/strapi/strapi.git
synced 2025-09-06 15:22:59 +00:00
Add check
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
f424bdfeb3
commit
5b4b95dc49
@ -101,4 +101,5 @@ node_modules
|
||||
test
|
||||
testApp
|
||||
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) {
|
||||
const adminConfigPath = path.join(dir, 'admin', 'admin.config.js');
|
||||
let webpackConfig = getWebpackConfig(config);
|
||||
let webpackConfig = getWebpackConfig({ dir, ...config });
|
||||
|
||||
if (fs.existsSync(adminConfigPath)) {
|
||||
const adminConfig = require(path.resolve(adminConfigPath));
|
||||
|
@ -4,4 +4,7 @@ const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
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 isWsl = require('is-wsl');
|
||||
const alias = require('./webpack.alias.js');
|
||||
const IS_EE = require('./is_ee_env');
|
||||
const loadEE = require('./is_ee_env');
|
||||
|
||||
// TODO: parametrize
|
||||
const URLs = {
|
||||
mode: 'host',
|
||||
};
|
||||
|
||||
module.exports = ({
|
||||
dir,
|
||||
entry,
|
||||
dest,
|
||||
env,
|
||||
@ -26,6 +28,7 @@ module.exports = ({
|
||||
publicPath: '/admin/',
|
||||
},
|
||||
}) => {
|
||||
const isEE = loadEE(dir);
|
||||
const isProduction = env === 'production';
|
||||
const webpackPlugins = isProduction
|
||||
? [
|
||||
@ -192,7 +195,7 @@ module.exports = ({
|
||||
const wantedPath =
|
||||
containerPathName.length === 1 ? componentPathName[0] : containerPathName[0];
|
||||
|
||||
if (IS_EE) {
|
||||
if (isEE) {
|
||||
resource.request = resource.request.replace(
|
||||
/ee_else_ce/,
|
||||
path.join(wantedPath, '..', 'ee')
|
||||
|
@ -26,6 +26,7 @@ const { createCoreStore, coreStoreModel } = require('./services/core-store');
|
||||
const createEntityService = require('./services/entity-service');
|
||||
const createEntityValidator = require('./services/entity-validator');
|
||||
const createTelemetry = require('./services/metrics');
|
||||
const ee = require('./utils/ee');
|
||||
|
||||
/**
|
||||
* Construct an Strapi instance.
|
||||
@ -50,11 +51,13 @@ class Strapi {
|
||||
};
|
||||
|
||||
this.dir = opts.dir || process.cwd();
|
||||
|
||||
this.admin = {};
|
||||
this.plugins = {};
|
||||
this.config = loadConfiguration(this.dir, opts);
|
||||
this.isLoaded = false;
|
||||
|
||||
this.EE = ee({ dir: this.dir, logger });
|
||||
// internal services.
|
||||
this.fs = createStrapiFs(this);
|
||||
this.eventHub = createEventHub();
|
||||
|
@ -23,7 +23,8 @@ module.exports = async strapi => {
|
||||
// load ee files if they exist
|
||||
let eeFiles = {};
|
||||
let eeConfig = {};
|
||||
if (process.env.STRAPI_DISABLE_EE !== 'true') {
|
||||
|
||||
if (process.env.STRAPI_DISABLE_EE !== 'true' && strapi.EE) {
|
||||
const eeAdminPath = `${adminPath}/ee`;
|
||||
[eeFiles, eeConfig] = await Promise.all([
|
||||
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