VirtualBox

source: vbox/trunk/src/VBox/Main/webservice/samples/php/clienttest.php@ 75040

最後變更 在這個檔案從75040是 69500,由 vboxsync 提交於 7 年 前

*: scm --update-copyright-year

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 3.8 KB
 
1<?php
2/* $Id: clienttest.php 69500 2017-10-28 15:14:05Z vboxsync $ */
3/*!file
4 * Sample client for the VirtualBox webservice, written in PHP.
5 *
6 * Run the VirtualBox web service server first; see the VirtualBox
7 * SDK reference for details.
8 *
9 * The following license applies to this file only:
10 */
11
12/*
13 * Contributed by James Lucas (mjlucas at eng.uts.edu.au).
14 *
15 * Copyright (C) 2009-2017 Oracle Corporation
16 *
17 * Permission is hereby granted, free of charge, to any person
18 * obtaining a copy of this software and associated documentation
19 * files (the "Software"), to deal in the Software without
20 * restriction, including without limitation the rights to use,
21 * copy, modify, merge, publish, distribute, sublicense, and/or sell
22 * copies of the Software, and to permit persons to whom the
23 * Software is furnished to do so, subject to the following
24 * conditions:
25 *
26 * The above copyright notice and this permission notice shall be
27 * included in all copies or substantial portions of the Software.
28 *
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
31 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
33 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
34 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
35 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
36 * OTHER DEALINGS IN THE SOFTWARE.
37 */
38
39require_once('./vboxServiceWrappers.php');
40
41//Connect to webservice
42$connection = new SoapClient("vboxwebService.wsdl", array('location' => "http://localhost:18083/"));
43
44//Logon to webservice
45$websessionManager = new IWebsessionManager($connection);
46// Dummy username and password (change to appropriate values or set authentication method to null)
47$virtualbox = $websessionManager->logon("username","password");
48
49//Get a list of registered machines
50$machines = $virtualbox->machines;
51
52//Take a screenshot of the first vm we find that is running
53foreach ($machines as $machine)
54{
55 if ( 'Running' == $machine->state )
56 {
57 $session = $websessionManager->getSessionObject($virtualbox->handle);
58 $uuid = $machine->id;
59 $machine->lockMachine($session->handle, "Shared");
60 try
61 {
62 $console = $session->console;
63 $display = $console->display;
64 list($screenWidth, $screenHeight, $screenBpp, $screenX, $screenY, $screenStatus) = $display->getScreenResolution(0 /* First screen */);
65
66 $imageraw = $display->takeScreenShotToArray(0 /* First screen */, $screenWidth, $screenHeight, "RGBA");
67 echo "Screenshot size: " . sizeof($imageraw) . "\n";
68
69 $filename = 'screenshot.png';
70 echo "Saving screenshot of " . $machine->name . " (${screenWidth}x${screenHeight}, ${screenBpp}BPP) to $filename\n";
71 $image = imagecreatetruecolor($screenWidth, $screenHeight);
72
73 for ($height = 0; $height < $screenHeight; $height++)
74 {
75 for ($width = 0; $width < $screenWidth; $width++)
76 {
77 $start = ($height*$screenWidth + $width)*4;
78 $red = $imageraw[$start];
79 $green = $imageraw[($start+1)];
80 $blue = $imageraw[($start+2)];
81 //$alpha = $image[$start+3];
82
83 $colour = imagecolorallocate($image, $red, $green, $blue);
84
85 imagesetpixel($image, $width, $height, $colour);
86 }
87 }
88
89 imagepng($image, $filename);
90 }
91 catch (Exception $ex)
92 {
93 echo $ex->getMessage();
94 }
95
96 $session->unlockMachine();
97
98 $machine->releaseRemote();
99 $session->releaseRemote();
100
101 break;
102 }
103}
104
105$websessionManager->logoff($virtualbox->handle);
106
107?>
108
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette