Fake semantic versioning for MeshCentral version comparison / plugin update compatibility check

This commit is contained in:
Ryan Blenis 2019-11-06 20:00:09 -05:00
parent bf1e4cc91f
commit f90fe05fe0
2 changed files with 6 additions and 3 deletions

View File

@ -3130,8 +3130,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
} }
case 'addplugin': { case 'addplugin': {
if ((user.siteadmin & 0xFFFFFFFF) == 0 || parent.parent.pluginHandler == null) break; // must be full admin, plugins enabled if ((user.siteadmin & 0xFFFFFFFF) == 0 || parent.parent.pluginHandler == null) break; // must be full admin, plugins enabled
try { try {
//parent.parent.pluginHandler.addPlugin(command.url)
parent.parent.pluginHandler.getPluginConfig(command.url) parent.parent.pluginHandler.getPluginConfig(command.url)
.then(parent.parent.pluginHandler.addPlugin) .then(parent.parent.pluginHandler.addPlugin)
.then(function(docs){ .then(function(docs){

View File

@ -263,12 +263,16 @@ module.exports.pluginHandler = function (parent) {
}); });
if (curconf == null) reject('Some plugin configs could not be parsed'); if (curconf == null) reject('Some plugin configs could not be parsed');
var s = require('semver'); var s = require('semver');
// MeshCentral doesn't adhere to semantic versioning (due to the -<alpha_char> at the end of the version)
// Convert the letter to ASCII for a "true" version number comparison
var mcCurVer = parent.currentVer.replace(/-(.)$/, (m, p1) => { return p1.charCodeAt(0); });
var piCompatVer = newconf.meshCentralCompat.replace(/-(.)$/, (m, p1) => { return p1.charCodeAt(0); });
latestRet.push({ latestRet.push({
"id": curconf._id, "id": curconf._id,
"installedVersion": curconf.version, "installedVersion": curconf.version,
"version": newconf.version, "version": newconf.version,
"hasUpdate": s.gt(newconf.version, curconf.version), "hasUpdate": s.gt(newconf.version, curconf.version),
"meshCentralCompat": s.satisfies(s.coerce(parent.currentVer), newconf.meshCentralCompat), "meshCentralCompat": s.satisfies(mcCurVer, piCompatVer),
"changelogUrl": curconf.changelogUrl, "changelogUrl": curconf.changelogUrl,
"status": curconf.status "status": curconf.status
}); });