Skip to content

Commit

Permalink
Merge pull request #1667 from hollaex/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
abeikverdi authored Sep 20, 2022
2 parents 4c97b7e + 73f8887 commit 86c3430
Show file tree
Hide file tree
Showing 148 changed files with 859 additions and 564 deletions.
2 changes: 1 addition & 1 deletion server/api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
swagger: "2.0"
info:
version: "2.4.1"
version: "2.4.2"
title: HollaEx Kit
host: api.hollaex.com
basePath: /v2
Expand Down
2 changes: 1 addition & 1 deletion server/mail/strings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"title": "KYC Documents Approved"
},
"CONFIRM_EMAIL": {
"html": "<div><p><p>Dear ${name} </p></p><p>You have made sensitive request related to your accounts security. To verify the operation you would require to use to code below to authorize this operation.<br /><p style=\"font-size: 1.2rem; text-align: center;\">${code}</p>If you did not make this request, report this immidiately and proceed to change your crendetials as soon as possible.</p><p> Regards<br> ${api_name} team </p></div>",
"html": "<div><p><p>Dear ${name} </p></p><p>You have made sensitive request related to your accounts security. To verify the operation you would require to use to code below to authorize this operation.<br /><p style=\"font-size: 1.2rem; text-align: center;\">${code}</p>If you did not make this request, report this immediately and proceed to change your credentials as soon as possible.</p><p> Regards<br> ${api_name} team </p></div>",
"title": "Security Verification"
},
"LOGIN": {
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.4.1",
"version": "2.4.2",
"private": false,
"description": "HollaEx Kit",
"keywords": [
Expand Down
29 changes: 21 additions & 8 deletions server/plugins/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const getPlugins = async (req, res) => {
'postscript'
]
},
order: [[ 'id', 'asc' ]]
order: [['id', 'asc']]
};

if (name) {
Expand All @@ -59,7 +59,7 @@ const getPlugins = async (req, res) => {
count: data.count,
data: data.rows.map((plugin) => {
plugin.enabled_admin_view = !!plugin.admin_view;
return lodash.omit(plugin, [ 'admin_view' ]);
return lodash.omit(plugin, ['admin_view']);
})
};

Expand Down Expand Up @@ -124,7 +124,10 @@ const deletePlugin = async (req, res) => {
'restarting plugin process'
);

process.exit();
const { stopPlugin } = require('./index');

stopPlugin(plugin);
// process.exit();
}
} catch (err) {
loggerPlugin.error(
Expand Down Expand Up @@ -225,7 +228,7 @@ const postPlugin = async (req, res) => {
throw new Error(`Error while minifying script: ${minifiedScript.error.message}`);
}

pluginConfig[field] = minifiedScript.code;
pluginConfig[field] = minifiedScript.code;
}
break;
case 'description':
Expand Down Expand Up @@ -281,7 +284,10 @@ const postPlugin = async (req, res) => {
);

if (plugin.enabled && plugin.script) {
process.exit();
const { startPlugin } = require('./index');

startPlugin(plugin);
// process.exit();
}
} catch (err) {
loggerPlugin.error(
Expand Down Expand Up @@ -411,7 +417,7 @@ const putPlugin = async (req, res) => {
if (
lodash.isPlainObject(plugin[field])
&& plugin[field][key].overwrite === false
&& (!value[key] || value[key].overwrite === false)
&& (!value[key] || value[key].overwrite === false)
) {
value[key] = plugin[field][key];
}
Expand Down Expand Up @@ -709,7 +715,10 @@ const disablePlugin = async (req, res) => {
res.json({ message: 'Success' });

if (plugin.script) {
process.exit();
// process.exit();
const { stopPlugin } = require('./index');

stopPlugin(plugin);
}
} catch (err) {
loggerPlugin.error(
Expand Down Expand Up @@ -764,7 +773,11 @@ const enablePlugin = async (req, res) => {
res.json({ message: 'Success' });

if (plugin.script) {
process.exit();
//process.exit();

const { startPlugin } = require('./index');

startPlugin(plugin);
}
} catch (err) {
loggerPlugin.error(
Expand Down
219 changes: 130 additions & 89 deletions server/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const tripleBeam = require('triple-beam');
const uglifyEs = require('uglify-es');
const bodyParser = require('body-parser');

let app;
let disabledPlugins = {};

const getInstalledLibrary = async (name, version) => {
const jsonFilePath = path.resolve(__dirname, '../node_modules', name, 'package.json');

Expand Down Expand Up @@ -102,14 +105,123 @@ const installLibrary = async (library) => {
}
};

const stopPlugin = async (plugin) => {

try {
const subStr = plugin.script.match(/\"\/plugins(.*?)\"/g);
disabledPlugins[plugin.name] = subStr || [];

} catch (err) {
loggerPlugin.error(
'plugins/index/kill_plugin',
`error while stopping plugin ${plugin.name}`,
err.message
);
}
}

const startPlugin = async (plugin) => {
try {
loggerPlugin.verbose(
'plugins/index/initialization',
`starting plugin ${plugin.name}`
);

const context = {
configValues: {
publicMeta: plugin.public_meta,
meta: plugin.meta
},
pluginLibraries: {
app,
loggerPlugin,
toolsLib
},
app,
toolsLib,
lodash,
expressValidator,
loggerPlugin,
multer,
moment,
mathjs,
bluebird,
umzug,
rp,
sequelize,
uuid,
jwt,
momentTz,
json2csv,
flat,
ws,
cron,
randomString,
bcryptjs,
expectCt,
validator,
uglifyEs,
otp,
latestVersion,
geoipLite,
nodemailer,
wsHeartbeatServer,
wsHeartbeatClient,
cors,
winston,
elasticApmNode,
winstonElasticsearchApm,
tripleBeam,
bodyParser,
morgan,
meta: plugin.meta,
publicMeta: plugin.public_meta,
installedLibraries: {}
};

if (plugin.prescript && lodash.isArray(plugin.prescript.install) && !lodash.isEmpty(plugin.prescript.install)) {
loggerPlugin.verbose(
'plugins/index/initialization',
`Installing packages for plugin ${plugin.name}`
);

for (const library of plugin.prescript.install) {
context.installedLibraries[library] = await installLibrary(library);
}

loggerPlugin.verbose(
'plugins/index/initialization',
`Plugin ${plugin.name} packages installed`
);
}

_eval(plugin.script, plugin.name, context, true);

if (disabledPlugins[plugin.name]) delete disabledPlugins[plugin.name];


loggerPlugin.verbose(
'plugins/index/initialization',
`Plugin ${plugin.name} running`
);
} catch (err) {
loggerPlugin.error(
'plugins/index/initialization',
`error while starting plugin ${plugin.name}`,
err.message
);
}
}


checkStatus()
.then(async () => {
loggerPlugin.info(
'/plugins/index/initialization',
'Initializing Plugin Server...'
);

const app = express();
app = express();

app.use(morgan(morganType, { stream }));
app.listen(PORT);
Expand All @@ -120,6 +232,16 @@ checkStatus()
app.use(domainMiddleware);
helmetMiddleware(app);

app.use((req, res, next) => {
if (req.path.length > 1 && req.path.includes('/plugins/')) {
//Check if plugin is disabled
for (let endpoints of Object.values(disabledPlugins)) {
if (endpoints.some(endpoint => endpoint.includes(req.path))) { return res.status(404).send() }
}
}
next();
})

app.use('/plugins', routes);

const plugins = await Plugin.findAll({
Expand All @@ -133,93 +255,7 @@ checkStatus()
});

for (const plugin of plugins) {
try {
loggerPlugin.verbose(
'plugins/index/initialization',
`starting plugin ${plugin.name}`
);

const context = {
configValues: {
publicMeta: plugin.public_meta,
meta: plugin.meta
},
pluginLibraries: {
app,
loggerPlugin,
toolsLib
},
app,
toolsLib,
lodash,
expressValidator,
loggerPlugin,
multer,
moment,
mathjs,
bluebird,
umzug,
rp,
sequelize,
uuid,
jwt,
momentTz,
json2csv,
flat,
ws,
cron,
randomString,
bcryptjs,
expectCt,
validator,
uglifyEs,
otp,
latestVersion,
geoipLite,
nodemailer,
wsHeartbeatServer,
wsHeartbeatClient,
cors,
winston,
elasticApmNode,
winstonElasticsearchApm,
tripleBeam,
bodyParser,
morgan,
meta: plugin.meta,
publicMeta: plugin.public_meta,
installedLibraries: {}
};

if (plugin.prescript && lodash.isArray(plugin.prescript.install) && !lodash.isEmpty(plugin.prescript.install)) {
loggerPlugin.verbose(
'plugins/index/initialization',
`Installing packages for plugin ${plugin.name}`
);

for (const library of plugin.prescript.install) {
context.installedLibraries[library] = await installLibrary(library);
}

loggerPlugin.verbose(
'plugins/index/initialization',
`Plugin ${plugin.name} packages installed`
);
}

_eval(plugin.script, plugin.name, context, true);

loggerPlugin.verbose(
'plugins/index/initialization',
`Plugin ${plugin.name} running`
);
} catch (err) {
loggerPlugin.error(
'plugins/index/initialization',
`error while starting plugin ${plugin.name}`,
err.message
);
}
startPlugin(plugin);
}

loggerPlugin.info(
Expand All @@ -244,4 +280,9 @@ checkStatus()
);

setTimeout(() => { process.exit(1); }, 5000);
});
});

module.exports = {
startPlugin,
stopPlugin
}
Loading

0 comments on commit 86c3430

Please sign in to comment.