Skip to content
Snippets Groups Projects
Commit 6c2b3a4d authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[enh] #918 Controls the package URL for obvious errors

parent 419e5cb5
Branches
Tags
No related merge requests found
......@@ -23,6 +23,11 @@ module.exports = ($scope, $http, $state, $interval, $timeout, UIUtils, summary,
}
$scope.installModule = () => {
const pkg = $scope.module_to_install
if (!(pkg.match(/^file:\/\//) || pkg.match(/^https?:\/\/.+\.(tar\.gz|tgz)$/) || pkg.match(/^git(\+ssh|\+http|\+https)?:\/\/.+\.git$/))) {
UIUtils.toast('settings.modules.wrong_package_source')
return
}
$scope.modules.map(m => m.disabled = true)
co(function*() {
const res = yield Webmin.plugin.addPackage($scope.module_to_install)
......@@ -37,7 +42,13 @@ module.exports = ($scope, $http, $state, $interval, $timeout, UIUtils, summary,
$scope.checkModulesInstallation()
} else {
$scope.modules = modulesTransform(allModules)
if (res.error === 1) {
UIUtils.toast('settings.modules.already_install');
} else if (res.error === 2) {
UIUtils.toast('settings.modules.path_does_not_exist');
} else {
UIUtils.toast('settings.modules.unknown_error');
}
}
})
}
......
......@@ -193,6 +193,8 @@
"settings.modules.no_access": "This instance does not have enough system rights to install new modules on disk.",
"settings.modules.install": "Install this module",
"settings.modules.already_install": "Module already installed",
"settings.modules.path_does_not_exist": "Path does not lead to a module",
"settings.modules.wrong_package_source": "Package URL has wrong format",
"settings.modules.warning": "Please be <b>VERY CAREFUL</b> when choosing to install a module: you should have checked that this module is not a virus, nor wants to steal your informations.<br>A module has <i>a lot of power</i> and can likely access to any part of your computer in the limit of the user's access rights:<ul><li>- your node's keyring (in the computer's memory)</li><li>- your personal files (photos, unencrypted passwords, browser favorites, ...)</li><li>- your internet access</li><li>- your local network</li></ul>You could get informations about a module by looking on the Internet.",
"settings.modules.warning_light": "Please read this warning before installing a module!",
"settings.modules.warning_close": "Close this message",
......
......@@ -1767,6 +1767,11 @@ module.exports = function ($scope, $http, $state, $interval, $timeout, UIUtils,
};
$scope.installModule = function () {
var pkg = $scope.module_to_install;
if (!(pkg.match(/^file:\/\//) || pkg.match(/^https?:\/\/.+\.(tar\.gz|tgz)$/) || pkg.match(/^git(\+ssh|\+http|\+https)?:\/\/.+\.git$/))) {
UIUtils.toast('settings.modules.wrong_package_source');
return;
}
$scope.modules.map(function (m) {
return m.disabled = true;
});
......@@ -1793,7 +1798,13 @@ module.exports = function ($scope, $http, $state, $interval, $timeout, UIUtils,
$scope.checkModulesInstallation();
} else {
$scope.modules = modulesTransform(allModules);
if (res.error === 1) {
UIUtils.toast('settings.modules.already_install');
} else if (res.error === 2) {
UIUtils.toast('settings.modules.path_does_not_exist');
} else {
UIUtils.toast('settings.modules.unknown_error');
}
}
case 4:
......@@ -2302,6 +2313,8 @@ module.exports = {
"settings.modules.no_access": "This instance does not have enough system rights to install new modules on disk.",
"settings.modules.install": "Install this module",
"settings.modules.already_install": "Module already installed",
"settings.modules.path_does_not_exist": "Path does not lead to a module",
"settings.modules.wrong_package_source": "Package URL has wrong format",
"settings.modules.warning": "Please be <b>VERY CAREFUL</b> when choosing to install a module: you should have checked that this module is not a virus, nor wants to steal your informations.<br>A module has <i>a lot of power</i> and can likely access to any part of your computer in the limit of the user's access rights:<ul><li>- your node's keyring (in the computer's memory)</li><li>- your personal files (photos, unencrypted passwords, browser favorites, ...)</li><li>- your internet access</li><li>- your local network</li></ul>You could get informations about a module by looking on the Internet.",
"settings.modules.warning_light": "Please read this warning before installing a module!",
"settings.modules.warning_close": "Close this message",
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
"use strict";
const os = require('os');
const fs = require('fs');
const path = require('path');
const util = require('util');
const es = require('event-stream');
......@@ -592,9 +593,12 @@ function WebAdmin (duniterServer, startServices, stopServices, listDuniterUIPlug
const installed = listDuniterUIPlugins()
for (const module of installed) {
if (module.version.match(new RegExp(resolvedPath))) {
return { success: false }
return { success: false, error: 1 }
}
}
if (!fs.existsSync(path.join(resolvedPath, '/package.json'))) {
return { success: false, error: 2 }
}
}
// Do not wait for full installation, too long
requirePlugin().duniter.methods.npmInstall(module, null, path.resolve('./'))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment