mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-07 11:50:15 +00:00
Aks for permission when installing Wireshark
This commit is contained in:
parent
f46caaf5e0
commit
fecc81badf
@ -10,53 +10,78 @@ const { ipcMain } = require('electron')
|
|||||||
|
|
||||||
var pipeline = util.promisify(stream.pipeline);
|
var pipeline = util.promisify(stream.pipeline);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exports.getInstalledSoftware = (softwareList) => {
|
exports.getInstalledSoftware = (softwareList) => {
|
||||||
const installed = {};
|
const installed = {};
|
||||||
for(var software of softwareList) {
|
for(var software of softwareList) {
|
||||||
var name = software.name;
|
var name = software.name;
|
||||||
var commands = software.commands;
|
var locations = software.locations;
|
||||||
|
|
||||||
installed[name] = [];
|
installed[name] = [];
|
||||||
|
|
||||||
for(var command of commands) {
|
for(var location of locations) {
|
||||||
var exists = commandExistsSync(command);
|
// var exists = commandExistsSync(command);
|
||||||
|
var exists = fs.existsSync(location);
|
||||||
if(exists) {
|
if(exists) {
|
||||||
installed[name].push(command);
|
installed[name].push(location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return installed;
|
return installed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function downloadFile(resource, softwarePath) {
|
||||||
|
var response = await fetch(resource);
|
||||||
|
if (response.status != 200) {
|
||||||
|
throw new Error(`Cannot download file ${resource}, response status = ${response.status}`);
|
||||||
|
}
|
||||||
|
await pipeline(
|
||||||
|
response.body,
|
||||||
|
fs.createWriteStream(softwarePath)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
ipcMain.on('installed-software-install', async function (event, software) {
|
ipcMain.on('installed-software-install', async function (event, software) {
|
||||||
const softwarePath = path.join(app.getAppPath(), software.binary);
|
const softwarePath = path.join(app.getAppPath(), software.binary);
|
||||||
|
|
||||||
if (software.type == 'web') {
|
if (software.type == 'web') {
|
||||||
try {
|
const exists = fs.existsSync(softwarePath);
|
||||||
var response = await fetch(software.resource);
|
if (exists) {
|
||||||
if (response.status != 200) {
|
console.log(`Skipping downloading file due to '${softwarePath}' path exists`);
|
||||||
throw new Error(`Cannot download file ${software.resource}, response status = ${response.status}`);
|
|
||||||
}
|
|
||||||
await pipeline(
|
|
||||||
response.body,
|
|
||||||
fs.createWriteStream(softwarePath)
|
|
||||||
);
|
|
||||||
} catch(error) {
|
|
||||||
event.sender.send('installed-software-installed', {
|
|
||||||
success: false,
|
|
||||||
message: error.message
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
console.log(`File '${softwarePath}' doesn't exist. Downloading file.`);
|
||||||
|
try {
|
||||||
|
await downloadFile(software.resource, softwarePath);
|
||||||
|
} catch(error) {
|
||||||
|
event.sender.send('installed-software-installed', {
|
||||||
|
success: false,
|
||||||
|
message: error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
let child;
|
||||||
|
|
||||||
|
if (software.sudo) {
|
||||||
|
child = spawn('powershell.exe', ['Start-Process', '-FilePath', `"${softwarePath}"`]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
child = spawn(softwarePath, software.installation_arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
const command = `${softwarePath}`;
|
|
||||||
const child = spawn(command, software.installation_arguments);
|
|
||||||
child.on('exit', () => {
|
child.on('exit', () => {
|
||||||
console.log("exited");
|
console.log("exited");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
child.on('error', (err) => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
child.stdin.end();
|
||||||
|
|
||||||
event.sender.send('installed-software-installed', {
|
event.sender.send('installed-software-installed', {
|
||||||
success: true
|
success: true
|
||||||
});
|
});
|
||||||
|
@ -6,31 +6,25 @@ import { ElectronService } from 'ngx-electron';
|
|||||||
})
|
})
|
||||||
export class InstalledSoftwareService {
|
export class InstalledSoftwareService {
|
||||||
private software = [{
|
private software = [{
|
||||||
name: 'ls',
|
|
||||||
commands: ['ls'],
|
|
||||||
installed: false
|
|
||||||
}, {
|
|
||||||
name: 'telnet',
|
|
||||||
commands: ['telnet'],
|
|
||||||
installed: false
|
|
||||||
}, {
|
|
||||||
name: 'SolarPuTTY',
|
name: 'SolarPuTTY',
|
||||||
commands: [
|
locations: [
|
||||||
'SolarPuTTY.exe'
|
'SolarPuTTY.exe'
|
||||||
],
|
],
|
||||||
type: 'web',
|
type: 'web',
|
||||||
resource: '.exe',
|
resource: '.exe',
|
||||||
binary: 'SolarPuTTY.exe',
|
binary: 'SolarPuTTY.exe',
|
||||||
|
sudo: false,
|
||||||
installation_arguments: ['--only-ask'],
|
installation_arguments: ['--only-ask'],
|
||||||
installed: false
|
installed: false
|
||||||
}, {
|
}, {
|
||||||
name: 'Wireshark',
|
name: 'Wireshark',
|
||||||
commands: [
|
locations: [
|
||||||
'Wireshark.exe'
|
'C:\\Program Files\\Wireshark\\Wireshark.exe'
|
||||||
],
|
],
|
||||||
type: 'web',
|
type: 'web',
|
||||||
resource: 'https://1.na.dl.wireshark.org/win64/all-versions/Wireshark-win64-2.6.3.exe',
|
resource: 'https://1.na.dl.wireshark.org/win64/all-versions/Wireshark-win64-2.6.3.exe',
|
||||||
binary: 'Wireshark.exe',
|
binary: 'Wireshark.exe',
|
||||||
|
sudo: true,
|
||||||
installation_arguments: [],
|
installation_arguments: [],
|
||||||
installed: false
|
installed: false
|
||||||
}];
|
}];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user