Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-------------------------------------
5.0-1 2015-08-04
5.0-1 2015-08-05
-------------------------------------
Fix paths in recovery.php-disabled

Expand All @@ -11,6 +11,12 @@ Fix RDP link

Fix bug when changing password

Removed unused OnAdditionsStateChanged event

Change in the way Windows drive list is obtained

Fixed errors manipulating groups when $phpVboxGroups is set

-------------------------------------
5.0-0 2015-07-18
-------------------------------------
Expand Down
156 changes: 77 additions & 79 deletions endpoints/jqueryFileTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,33 @@
if(!is_array($allowed_folders))
$allowed_folders = array();

/*
* Get a list of windows drives
*/
function get_windows_drives() {
$checklist = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$drives = array();
for($i = 0; $i < strlen($d); $i++) {
if(is_dir($checklist[$i].':\\')) {
$drives[] = $checklist[$i].':\\';
}
}
return $drives;
}

/*
* Allowed folders in windows if none are set
*/
if(stripos($vbox->vbox->host->operatingSystem,'win') === 0 && !count($allowed_folders)) {

/*
* Get from WMIC. Assumes web server and vbox host are the same physical machine
* Assumes web server and vbox host are the same physical machine
*/
if($request['fullpath'] && !$settings->forceWindowsAllDriveList && !$settings->noWindowsDriveList && stripos(PHP_OS,'win') === 0) {

exec("wmic logicaldisk get caption", $out);
if(is_array($out) && count($out) > 2) {

$allowed_folders = array();

// Shift off header
array_shift($out);

// Shift off footer
array_pop($out);

// These are now restricted folders
foreach ($out as $val) {
$allowed_folders[] = $val . '\\';
}
}



$allowed_folders = get_windows_drives();

/*
* Just show all C-Z drive letters if vboxhost is windows and our web server is not...
*/
Expand All @@ -109,7 +109,7 @@
}
}
$allowed_folders = array_combine($allowed_folders,$allowed_folders);

}


Expand All @@ -124,7 +124,7 @@
$request['dir'] = str_replace(DSEP.DSEP,DSEP,$request['dir']);


/*
/*
* Check that folder restriction validates if it exists
*/
if($request['dir'] != DSEP && count($allowed_folders)) {
Expand All @@ -147,40 +147,40 @@

/* Folder Restriction with root '/' requested */
if($request['dir'] == DSEP && count($allowed_folders)) {

/* Just return restricted folders */
foreach($allowed_folders as $f) {
array_push($returnData, folder_entry($f, true));

}

} else {


/* Full, expanded path to $dir */
if($request['fullpath']) {


/* Go through allowed folders if it is set */
if(count($allowed_folders)) {


foreach($allowed_folders as $f) {

/* If this was not exactly the requested folder, but a parent,
* list everything below it.
*/
if((strtoupper($request['dir']) != strtoupper($f)) && strpos(strtoupper($request['dir']),strtoupper($f)) === 0) {


// List entries in this folder
$path = explode(DSEP,substr($request['dir'],strlen($f)));

// Folder entry
array_push($returnData, getdir($f, $request['dirsOnly'], $path));

} else {

array_push($returnData, folder_entry($f,true));
}
}
Expand All @@ -191,25 +191,23 @@
// List entries in this folder
$path = explode(DSEP,$request['dir']);
$root = array_shift($path).DSEP;

// Folder entry
$returnData = getdir($root, $request['dirsOnly'], $path);

}


} else {

/* Default action. Return dir requested */
$returnData = getdir($request['dir'], $request['dirsOnly']);

}

}

header('Content-type', 'application/json');
#echo("<pre>");
#print_r($returnData);
echo(json_encode($returnData));


Expand All @@ -221,41 +219,41 @@ function getdir($dir, $dirsOnly=false, $recurse=array()) {
if(!$dir) $dir = DSEP;

$entries = getDirEntries($dir, $dirsOnly);

if(!count($entries))
return array();

$dirents = array();
foreach($entries as $path => $type) {

if($type == 'folder' && count($recurse) && (strcasecmp($recurse[0],vbox_basename($path)) == 0)) {

$entry = folder_entry($path, false, true);

$entry['children'] = getdir($dir.DSEP.array_shift($recurse), $dirsOnly, $recurse);

array_push($dirents, $entry);

} else {

// Push folder on to stack
if($type == 'folder') {

array_push($dirents, folder_entry($path));

// Push file on to stack
} else {

$ext = strtolower(preg_replace('/^.*\./', '', $file));

if(count($allowed) && !$allowed['.'.$ext]) continue;

array_push($dirents, file_entry($path));
}
}

}

return $dirents;

}
Expand Down Expand Up @@ -288,55 +286,55 @@ function folder_entry($f,$full=false,$expanded=false) {

/**
* Rreturn a list of directory entries
*
*
* @param String $dir
* @return Array of entries
*/

function getDirEntries($dir, $foldersOnly=false) {

global $localbrowser, $allowed_exts, $vbox;

// Append trailing slash if it isn't here
if(substr($dir,-1) != DSEP)
$dir .= DSEP;
/*


/*
* Use local file / folder browser (PHP)
*/
if($localbrowser) {

// If the dir doesn't exist or we can't scan it, just return
if(!(file_exists($dir) && ($ents = @scandir($dir))))
return array();

$newtypes = array();
$newents = array();
for($i = 0; $i < count($ents); $i++) {

// Skip . and ..
if($ents[$i] == '.' || $ents[$i] == '..')
continue;

$fullpath = $dir.$ents[$i];
$isdir = @is_dir($fullpath);

if(!$isdir && $foldersOnly)
continue;

array_push($newtypes, $isdir ? 'folder' : 'file');
array_push($newents, $fullpath);
}
return array_combine($newents, $newtypes);

/*
* Use remote file / folder browser (vbox)
*/
} else {

try {


$appl = $vbox->vbox->createAppliance();
$vfs = $appl->createVFSExplorer('file://'.str_replace(DSEP.DSEP,DSEP,$dir));
Expand All @@ -346,35 +344,35 @@ function getDirEntries($dir, $foldersOnly=false) {
list($ents,$types) = $vfs->entryList();
$vfs->releaseRemote();
$appl->releaseRemote();

} catch (Exception $e) {

echo($e->getMessage());

return array();

}

// Convert types to file / folder
$newtypes = array();
$newents = array();
for($i = 0; $i < count($types); $i++) {

// Skip . and ..
if($ents[$i] == '.' || $ents[$i] == '..')
continue;

$isdir = $types[$i] == 4;

if(!$isdir && $foldersOnly)
continue;

array_push($newtypes, $isdir ? 'folder' : 'file');
array_push($newents, $dir.$ents[$i]);
}
return array_combine($newents,$newtypes);

}


}
16 changes: 9 additions & 7 deletions endpoints/lib/vboxconnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,11 +819,6 @@ private function _getEventData($event, $listenerKey) {
$data['dedupId'] .= '-'. $data['machineId'] .'-' . $data['name'];
break;

case 'OnAdditionsStateChanged':
$data['machineId'] = $eventDataObject->machineId;
$data['dedupId'] .= '-'. $data['machineId'];
break;

case 'OnCPUChanged':
$data['machineId'] = $data['sourceId'];
$data['cpu'] = $eventDataObject->cpu;
Expand Down Expand Up @@ -1297,12 +1292,12 @@ public function remote_machinesSaveGroups($args) {

$this->session = $this->websessionManager->getSessionObject($this->vbox->handle);

$machine->lockMachine($this->session->handle, 'Write');
$machine->lockMachine($this->session->handle, 'Shared');

usort($newGroups,'strnatcasecmp');

if($this->settings->phpVboxGroups) {
$machine->setExtraData(vboxconnector::phpVboxGroupKey, implode(',',$newGroups));
$this->session->machine->setExtraData(vboxconnector::phpVboxGroupKey, implode(',', $newGroups));
} else {
$this->session->machine->groups = $newGroups;
}
Expand All @@ -1318,6 +1313,13 @@ public function remote_machinesSaveGroups($args) {
$this->errors[] = $e;
$response['errored'] = true;

try {
$this->session->unlockMachine();
unset($this->session);
} catch (Exception $e) {
// pass
}

continue;

}
Expand Down