clienttest.php revision b7307c9c040a1a8aed0dbabed6574466d0bff2e4
181e56d8b348d301d615ccf5465ae600fee2867berikabele<?php
181e56d8b348d301d615ccf5465ae600fee2867berikabele
181e56d8b348d301d615ccf5465ae600fee2867berikabele/*
2bca4de967f80471d18eb768fc6911261327520eslive * Sample client for the VirtualBox webservice, written in PHP.
2bca4de967f80471d18eb768fc6911261327520eslive *
2bca4de967f80471d18eb768fc6911261327520eslive * Run the VirtualBox web service server first; see the VirtualBox
5a58787efeb02a1c3f06569d019ad81fd2efa06end * SDK reference for details.
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz *
5a58787efeb02a1c3f06569d019ad81fd2efa06end * Copyright (C) 2009-2010 Oracle Corporation
5a58787efeb02a1c3f06569d019ad81fd2efa06end * Contributed by James Lucas (mjlucas at eng.uts.edu.au).
5a58787efeb02a1c3f06569d019ad81fd2efa06end *
5a58787efeb02a1c3f06569d019ad81fd2efa06end * The following license applies to this file only:
5a58787efeb02a1c3f06569d019ad81fd2efa06end *
5a58787efeb02a1c3f06569d019ad81fd2efa06end * Permission is hereby granted, free of charge, to any person
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz * obtaining a copy of this software and associated documentation
5a58787efeb02a1c3f06569d019ad81fd2efa06end * files (the "Software"), to deal in the Software without
5a58787efeb02a1c3f06569d019ad81fd2efa06end * restriction, including without limitation the rights to use,
5a58787efeb02a1c3f06569d019ad81fd2efa06end * copy, modify, merge, publish, distribute, sublicense, and/or
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz * sell copies of the Software, and to permit persons to whom the
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd * Software is furnished to do so, subject to the following conditions:
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd *
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * The above copyright notice and this permission notice shall be
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * included in all copies or substantial portions of the Software.
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd *
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
ec878843fb39a84bac1e1c2e1a2b821b1b7882fend * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
2bca4de967f80471d18eb768fc6911261327520eslive * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2bca4de967f80471d18eb768fc6911261327520eslive * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2bca4de967f80471d18eb768fc6911261327520eslive * OTHER DEALINGS IN THE SOFTWARE.
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz */
2bca4de967f80471d18eb768fc6911261327520eslive
25d005c58102474e06fb67d748273b161d7198d0pquernarequire_once('./vboxServiceWrappers.php");
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz//Connect to webservice
25d005c58102474e06fb67d748273b161d7198d0pquerna$connection = new SoapClient("vboxwebService.wsdl", array('location" => "http://localhost:18083/"));
25d005c58102474e06fb67d748273b161d7198d0pquerna
5a58787efeb02a1c3f06569d019ad81fd2efa06end//Logon to webservice
5a58787efeb02a1c3f06569d019ad81fd2efa06end$websessionManager = new IWebsessionManager($connection);
5a58787efeb02a1c3f06569d019ad81fd2efa06end// Dummy username and password (change to appropriate values or set authentication method to null)
5a58787efeb02a1c3f06569d019ad81fd2efa06end$virtualbox = $websessionManager->logon("username","password");
5a58787efeb02a1c3f06569d019ad81fd2efa06end
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz//Get a list of registered machines
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz$machines = $virtualbox->machines;
5a58787efeb02a1c3f06569d019ad81fd2efa06end
5a58787efeb02a1c3f06569d019ad81fd2efa06end//Take a screenshot of the first vm we find that is running
5a58787efeb02a1c3f06569d019ad81fd2efa06endforeach ($machines as $machine)
2bca4de967f80471d18eb768fc6911261327520eslive{
82d4a929c9d891a758667c94e09c871358acf6ecjerenkrantz if ( 'Running" == $machine->state )
82d4a929c9d891a758667c94e09c871358acf6ecjerenkrantz {
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen $session = $websessionManager->getSessionObject($virtualbox->handle);
5a58787efeb02a1c3f06569d019ad81fd2efa06end $uuid = $machine->id;
5a58787efeb02a1c3f06569d019ad81fd2efa06end $machine->lockMachine($session->handle, "Shared");
5a58787efeb02a1c3f06569d019ad81fd2efa06end try
2bca4de967f80471d18eb768fc6911261327520eslive {
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen $console = $session->console;
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen $display = $console->display;
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen list($screenWidth, $screenHeight, $screenBpp, $screenX, $screenY, $screenStatus) = $display->getScreenResolution(0 /* First screen */);
5a58787efeb02a1c3f06569d019ad81fd2efa06end
5a58787efeb02a1c3f06569d019ad81fd2efa06end $imageraw = $display->takeScreenShotToArray(0 /* First screen */, $screenWidth, $screenHeight, "RGBA");
5a58787efeb02a1c3f06569d019ad81fd2efa06end echo "Screenshot size: " . sizeof($imageraw) . "\n";
2bca4de967f80471d18eb768fc6911261327520eslive
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen $filename = 'screenshot.png";
5a58787efeb02a1c3f06569d019ad81fd2efa06end echo "Saving screenshot of " . $machine->name . " (${screenWidth}x${screenHeight}, ${screenBpp}BPP) to $filename\n";
5a58787efeb02a1c3f06569d019ad81fd2efa06end $image = imagecreatetruecolor($screenWidth, $screenHeight);
5a58787efeb02a1c3f06569d019ad81fd2efa06end
2bca4de967f80471d18eb768fc6911261327520eslive for ($height = 0; $height < $screenHeight; $height++)
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen {
5a58787efeb02a1c3f06569d019ad81fd2efa06end for ($width = 0; $width < $screenWidth; $width++)
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd {
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd $start = ($height*$screenWidth + $width)*4;
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd $red = $imageraw[$start];
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd $green = $imageraw[($start+1)];
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd $blue = $imageraw[($start+2)];
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd //$alpha = $image[$start+3];
ec878843fb39a84bac1e1c2e1a2b821b1b7882fend
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd $colour = imagecolorallocate($image, $red, $green, $blue);
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd
b95ae799514ad86a15610ad75808d7065e9847c9kess imagesetpixel($image, $width, $height, $colour);
5a58787efeb02a1c3f06569d019ad81fd2efa06end }
5a58787efeb02a1c3f06569d019ad81fd2efa06end }
imagepng($image, $filename);
}
catch (Exception $ex)
{
echo $ex->getMessage();
}
$session->unlockMachine();
$machine->releaseRemote();
$session->releaseRemote();
break;
}
}
$websessionManager->logoff($virtualbox->handle);
?>