mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-14 04:58:07 +00:00
Basic OS Console executor
This commit is contained in:
33
console-executor.js
Normal file
33
console-executor.js
Normal file
@ -0,0 +1,33 @@
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
exports.openConsole = async (consoleRequest) => {
|
||||
const genericConsoleCommand = 'xfce4-terminal --tab -T "%d" -e "telnet %h %p"';
|
||||
const command = prepareCommand(genericConsoleCommand, consoleRequest);
|
||||
console.log(`Starting console with command: '${command}'`);
|
||||
|
||||
let consoleProcess = spawn(command, [], {
|
||||
shell :true
|
||||
});
|
||||
|
||||
consoleProcess.stdout.on('data', (data) => {
|
||||
console.log(`Console is producing: ${data.toString()}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function prepareCommand(consoleCommand, consoleRequest) {
|
||||
const mapping = {
|
||||
h: consoleRequest.host,
|
||||
p: consoleRequest.port,
|
||||
d: consoleRequest.name,
|
||||
i: consoleRequest.project_id,
|
||||
n: consoleRequest.node_id,
|
||||
c: consoleRequest.server_url
|
||||
};
|
||||
|
||||
for(var key in mapping) {
|
||||
const regExp = new RegExp(`%${key}`, 'g');
|
||||
consoleCommand = consoleCommand.replace(regExp, mapping[key]);
|
||||
}
|
||||
return consoleCommand;
|
||||
}
|
Reference in New Issue
Block a user