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