virtualbox
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -0,0 +0,0 @@ # Contributor Covenant Code of Conduct |
var log4js = require('log4js'), | ||
logger = log4js.getLogger('VirtualBox'); | ||
logger; | ||
logger.setLevel('INFO'); | ||
log4js.configure({ | ||
appenders: { | ||
out: { | ||
type: 'stdout', | ||
layout: { | ||
type: 'pattern', | ||
pattern: "%[[%d{yyyy-MM-dd hh:mm:ss.SSS}] [%p] %c - %]%m", | ||
} | ||
} | ||
}, | ||
categories: { default: { appenders: ['out'], level: 'info' } } | ||
}); | ||
logger = log4js.getLogger("VirtualBox"); | ||
module.exports = logger; | ||
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -5,3 +5,3 @@ "use strict"; | ||
var exec = require('child_process').exec, | ||
var execFile = require('child_process').execFile, | ||
host_platform = process.platform, | ||
@@ -15,5 +15,7 @@ logging = require('./logging'), | ||
LINUX: 'linux' | ||
}; | ||
}, | ||
allowedBinaries = ["VBoxControl", vBoxManageBinary]; | ||
// Host operating system | ||
@@ -38,3 +40,3 @@ if (/^win/.test(host_platform)) { | ||
exec(vBoxManageBinary + ' --version', function(error, stdout, stderr) { | ||
execFile(vBoxManageBinary, ["--version"], function(error, stdout, stderr) { | ||
// e.g., "4.3.38r106717" or "5.0.20r106931" | ||
@@ -45,5 +47,9 @@ vbox_version = stdout.split(".")[0]; | ||
function command(cmd, callback) { | ||
exec(cmd, function(err, stdout, stderr) { | ||
function command(bin, cmd, callback) { | ||
if(!allowedBinaries.includes(bin)) { | ||
throw new Error("Not an allowed binary"); | ||
} | ||
execFile(bin, cmd, function(err, stdout, stderr) { | ||
if (!err && stderr && cmd.indexOf("pause") !== -1 && cmd.indexOf("savestate") !== -1) { | ||
@@ -58,7 +64,7 @@ err = new Error(stderr); | ||
function vboxcontrol(cmd, callback) { | ||
command('VBoxControl ' + cmd, callback); | ||
command("VBoxControl", cmd, callback); | ||
} | ||
function vboxmanage(cmd, callback) { | ||
command(vBoxManageBinary + cmd, callback); | ||
command(vBoxManageBinary, cmd, callback); | ||
} | ||
@@ -68,3 +74,3 @@ | ||
logging.info('Pausing VM "%s"', vmname); | ||
vboxmanage('controlvm "' + vmname + '" pause', function(error, stdout) { | ||
vboxmanage(["controlvm", vmname, "pause"], function(error, stdout) { | ||
callback(error); | ||
@@ -76,7 +82,7 @@ }); | ||
logging.info('Listing VMs'); | ||
vboxmanage('list "runningvms"', function(error, stdout) { | ||
vboxmanage(['list', 'runningvms'], function(error, stdout) { | ||
var _list = {}; | ||
var _runningvms = parse_listdata(stdout); | ||
vboxmanage('list "vms"', function(error, full_stdout) { | ||
var _all = parse_listdata(full_stdout); | ||
vboxmanage(["list", "vms"], function(error, fullStdout) { | ||
var _all = parse_listdata(fullStdout); | ||
var _keys = Object.keys(_all); | ||
@@ -121,3 +127,3 @@ for (var _i = 0; _i < _keys.length; _i += 1) { | ||
logging.info('Resetting VM "%s"', vmname); | ||
vboxmanage('controlvm "' + vmname + '" reset', function(error, stdout) { | ||
vboxmanage(["controlvm", vmname, "reset"], function(error, stdout) { | ||
callback(error); | ||
@@ -129,3 +135,3 @@ }); | ||
logging.info('Resuming VM "%s"', vmname); | ||
vboxmanage('controlvm "' + vmname + '" resume', function(error, stdout) { | ||
vboxmanage(["controlvm", vmname, "resume"], function(error, stdout) { | ||
callback(error); | ||
@@ -135,13 +141,12 @@ }); | ||
function start(vmname, use_gui, callback) { | ||
var start_opts = ' --type '; | ||
if ((typeof use_gui) === 'function') { | ||
callback = use_gui; | ||
use_gui = false; | ||
function start(vmname, useGui, callback) { | ||
if ((typeof useGui) === 'function') { | ||
callback = useGui; | ||
useGui = false; | ||
} | ||
start_opts += (use_gui ? 'gui' : 'headless'); | ||
var vmType = (useGui ? "gui" : "headless"); | ||
logging.info('Starting VM "%s" with options: ', vmname, start_opts); | ||
logging.info('Starting VM "%s" with options: ', vmname, vmType); | ||
vboxmanage('-nologo startvm "' + vmname + '"' + start_opts, function(error, stdout) { | ||
vboxmanage(["-nologo", "startvm", vmname, "--type", vmType], function(error, stdout) { | ||
if (error && /VBOX_E_INVALID_OBJECT_STATE/.test(error.message)) { | ||
@@ -156,3 +161,3 @@ error = undefined; | ||
logging.info('Stopping VM "%s"', vmname); | ||
vboxmanage('controlvm "' + vmname + '" savestate', function(error, stdout) { | ||
vboxmanage(["controlvm", vmname, "savestate"], function(error, stdout) { | ||
callback(error); | ||
@@ -169,3 +174,3 @@ }); | ||
logging.info('Exporting VM "%s"', vmname); | ||
vboxmanage('export "' + vmname + '" --output "' + output + '"', function(error, stdout) { | ||
vboxmanage(['export', vmname, '--output', output], function(error, stdout) { | ||
callback(error); | ||
@@ -177,3 +182,3 @@ }); | ||
logging.info('Powering off VM "%s"', vmname); | ||
vboxmanage('controlvm "' + vmname + '" poweroff', function(error, stdout) { | ||
vboxmanage(['controlvm', vmname, 'poweroff'], function(error, stdout) { | ||
callback(error); | ||
@@ -185,3 +190,3 @@ }); | ||
logging.info('ACPI power button VM "%s"', vmname); | ||
vboxmanage('controlvm "' + vmname + '" acpipowerbutton', function(error, stdout) { | ||
vboxmanage(['controlvm', vmname, 'acpipowerbutton'], function(error, stdout) { | ||
callback(error); | ||
@@ -193,3 +198,3 @@ }); | ||
logging.info('ACPI sleep button VM "%s"', vmname); | ||
vboxmanage('controlvm "' + vmname + '" acpisleepbutton', function(error, stdout) { | ||
vboxmanage(['controlvm', vmname, 'acpisleepbutton'], function(error, stdout) { | ||
callback(error); | ||
@@ -217,7 +222,3 @@ }); | ||
var cmd = 'modifyvm ' + args.map(function (arg) { | ||
return '"' + arg + '"'; | ||
}).join(' '); | ||
vboxmanage(cmd, function (error, stdout) { | ||
vboxmanage(['modifyvm', ...args], function (error, stdout) { | ||
callback(error); | ||
@@ -229,3 +230,3 @@ }); | ||
logging.info('Listing snapshots for VM "%s"', vmname); | ||
vboxmanage('snapshot "' + vmname + '" list --machinereadable', function(error, stdout) { | ||
vboxmanage(['snapshot', vmname, 'list', '--machinereadable'], function(error, stdout) { | ||
@@ -275,10 +276,11 @@ if (error) { | ||
var cmd = 'snapshot ' + JSON.stringify(vmname) + ' take ' + JSON.stringify(name); | ||
var cmd = ['snapshot', vmname, 'take', name]; | ||
if(description) { | ||
cmd += ' --description ' + JSON.stringify(description); | ||
cmd.push('--description'); | ||
cmd.push(description); | ||
} | ||
if(live === true) { | ||
cmd += ' --live'; | ||
cmd.push('--live'); | ||
} | ||
@@ -297,4 +299,3 @@ | ||
logging.info('Deleting snapshot "%s" for VM "%s"', uuid, vmname); | ||
var cmd = 'snapshot ' + JSON.stringify(vmname) + ' delete ' + JSON.stringify(uuid); | ||
vboxmanage(cmd, callback); | ||
vboxmanage(['snapshot', vmname, 'delete', uuid], callback); | ||
} | ||
@@ -304,9 +305,7 @@ | ||
logging.info('Restoring snapshot "%s" for VM "%s"', uuid, vmname); | ||
var cmd = 'snapshot ' + JSON.stringify(vmname) + ' restore ' + JSON.stringify(uuid); | ||
vboxmanage(cmd, callback); | ||
vboxmanage(['snapshot', vmname, 'restore', uuid], callback); | ||
} | ||
function isRunning(vmname, callback) { | ||
var cmd = 'list runningvms'; | ||
vboxmanage(cmd, function (error, stdout) { | ||
vboxmanage(['list', 'runningvms'], function (error, stdout) { | ||
logging.info('Checking virtual machine "%s" is running or not', vmname); | ||
@@ -331,3 +330,3 @@ if (stdout.indexOf(vmname) === -1) { | ||
logging.info('Sending VM "%s" keyboard scan codes "%s"', vmname, codeStr); | ||
vboxmanage('controlvm "' + vmname + '" keyboardputscancode ' + codeStr, function(error, stdout) { | ||
vboxmanage(['controlvm', vmname, 'keyboardputscancode', codeStr], function(error, stdout) { | ||
callback(error, stdout); | ||
@@ -356,19 +355,15 @@ }); | ||
function getOSTypeCb(os_type) { | ||
var cmd = 'guestcontrol "' + vm + '"'; | ||
var runcmd = ' execute --image '; | ||
if (vbox_version == 5) { | ||
runcmd = ' run '; | ||
} | ||
var cmd = ['guestcontrol', vm]; | ||
var runcmd = vbox_version === 5 ? ['run'] : ['execute', '--image']; | ||
cmd.push(runcmd); | ||
switch (os_type) { | ||
case known_OS_types.WINDOWS: | ||
path = path.replace(/\\/g, '\\\\'); | ||
cmd += runcmd + ' "cmd.exe" --username ' + username + (password ? ' --password ' + password : '') + ' -- "/c" "' + path + '" "' + params + '"'; | ||
cmd.push('cmd.exe', '--username', username); | ||
break; | ||
case known_OS_types.MAC: | ||
cmd += runcmd + ' "/usr/bin/open -a" --username ' + username + (password ? ' --password ' + password : '') + ' -- "/c" "' + path + '" "' + params + '"'; | ||
cmd.push('/usr/bin/open', '-a', '--username', username); | ||
break; | ||
case known_OS_types.LINUX: | ||
cmd += runcmd + ' "/bin/sh" --username ' + username + (password ? ' --password ' + password : '') + ' -- "/c" "' + path + '" "' + params + '"'; | ||
cmd.push('/bin/sh', '--username', username); | ||
break; | ||
@@ -379,2 +374,7 @@ default: | ||
if (password) { | ||
cmd.push('--password', password); | ||
} | ||
cmd.push('--', '/c', path, params); | ||
logging.info('Executing command "vboxmanage %s" on VM "%s" detected OS type "%s"', cmd, vm, os_type); | ||
@@ -393,4 +393,3 @@ | ||
path = options.path || options.cmd || options.command || options.exec || options.execute || options.run, | ||
image_name = options.image_name || path, | ||
cmd = 'guestcontrol "' + vm + '" process kill'; | ||
image_name = options.image_name || path; | ||
@@ -432,4 +431,3 @@ guestproperty.os(vm, function(os_type) { | ||
function getOSTypeCallback(os_type) { | ||
var cmd = 'guestproperty get "' + vm + '" ' + key; | ||
vboxmanage(cmd, function(error, stdout) { | ||
vboxmanage(['guestproperty', 'get', vm, key], function(error, stdout) { | ||
if (error) { | ||
@@ -473,3 +471,3 @@ throw error; | ||
try { | ||
exec(vBoxManageBinary + 'showvminfo -machinereadable "' + vmname + '"', getOSTypeCallback); | ||
vboxmanage('showvminfo', '--machinereadable', vmname, getOSTypeCallback); | ||
} catch (e) { | ||
@@ -488,4 +486,3 @@ logging.info('Could not showvminfo for %s', vmname); | ||
var cmd = 'getextradata "' + vm + '" "' + key + '"'; | ||
vboxmanage(cmd, function(error, stdout) { | ||
vboxmanage(['getextradata', vm, key], function(error, stdout) { | ||
if (error) { | ||
@@ -492,0 +489,0 @@ callback(error); |
{ | ||
"name": "virtualbox", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A library to interact with VirtualBox.", | ||
@@ -19,2 +19,6 @@ "author": "Azer Koculu <azer@kodfabrik.com>", | ||
{ | ||
"name": "Jonathan Ling", | ||
"url": "https://jonathanling.net" | ||
}, | ||
{ | ||
"name": "Steffen Roegner", | ||
@@ -65,8 +69,7 @@ "url": "http://www.sroegner.org" | ||
"dependencies": { | ||
"log4js": "1.x" | ||
"log4js": "^4.0.2" | ||
}, | ||
"devDependencies": { | ||
"async": "^2.1.4", | ||
"jshint": "^2.9.6", | ||
"nodeunit": "^0.11.3" | ||
"jshint": "^2.10.2" | ||
}, | ||
@@ -73,0 +76,0 @@ "engines": { |
# node-virtualbox | ||
![NPM version](https://badge.fury.io/js/virtualbox.svg) | ||
[![david-dm badge](https://david-dm.org/Node-Virtualization/node-virtualbox/status.svg)](https://github.com/Node-Virtualization/node-virtualbox/blob/master/package.json) | ||
[![Build Status](https://travis-ci.org/Node-Virtualization/node-virtualbox.svg?branch=master)](https://travis-ci.org/Node-Virtualization/node-virtualbox) | ||
[![DepShield Badge](https://depshield.sonatype.org/badges/Node-Virtualization/node-virtualbox/depshield.svg)](https://depshield.github.io) | ||
[![david-dm badge](https://david-dm.org/Node-Virtualization/node-virtualbox/status.svg)](https://github.com/Node-Virtualization/node-virtualbox/blob/master/package.json) | ||
A JavaScript library to interact with [VirtualBox](https://www.virtualbox.org/) virtual machines. | ||
@@ -8,0 +10,0 @@ |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
2
31
834
407
47918
2
+ Addedasync@2.6.4(transitive)
+ Addeddate-format@2.1.0(transitive)
+ Addeddebug@3.2.74.3.4(transitive)
+ Addedflatted@2.0.2(transitive)
+ Addedfs-extra@7.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedjsonfile@4.0.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlog4js@4.5.1(transitive)
+ Addedms@2.1.2(transitive)
+ Addedrfdc@1.3.1(transitive)
+ Addedstreamroller@1.0.6(transitive)
+ Addeduniversalify@0.1.2(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddate-format@0.0.0(transitive)
- Removeddebug@0.7.42.6.9(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@0.0.1(transitive)
- Removedlog4js@1.1.1(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedms@2.0.0(transitive)
- Removedreadable-stream@1.1.14(transitive)
- Removedsemver@5.7.2(transitive)
- Removedstreamroller@0.4.1(transitive)
- Removedstring_decoder@0.10.31(transitive)
Updatedlog4js@^4.0.2