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