~ubuntu-branches/ubuntu/trusty/virtualbox-ose/trusty

« back to all changes in this revision

Viewing changes to src/VBox/Main/webservice/samples/php/clienttest.php

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/*
 
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
 * Copyright (C) 2009 Sun Microsystems, Inc.
 
10
 * Contributed by James Lucas (mjlucas at eng.uts.edu.au).
 
11
 *
 
12
 * The following license applies to this file only:
 
13
 *
 
14
 * Permission is hereby granted, free of charge, to any person
 
15
 * obtaining a copy of this software and associated documentation
 
16
 * files (the "Software"), to deal in the Software without
 
17
 * restriction, including without limitation the rights to use,
 
18
 * copy, modify, merge, publish, distribute, sublicense, and/or
 
19
 * sell copies of the Software, and to permit persons to whom the
 
20
 * Software is furnished to do so, subject to the following conditions:
 
21
 *
 
22
 * The above copyright notice and this permission notice shall be
 
23
 * included in all copies or substantial portions of the Software.
 
24
 *
 
25
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
26
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 
27
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
28
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 
29
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 
30
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
31
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
32
 * OTHER DEALINGS IN THE SOFTWARE.
 
33
 */
 
34
 
 
35
require_once('./vboxServiceWrappers.php');
 
36
 
 
37
//Connect to webservice
 
38
$connection = new SoapClient("vboxwebService.wsdl", array('location' => "http://localhost:18083/"));
 
39
 
 
40
//Logon to webservice
 
41
$websessionManager = new IWebsessionManager($connection);
 
42
// Dummy username and password (change to appropriate values or set authentication method to null)
 
43
$virtualbox = $websessionManager->logon("username","password");
 
44
 
 
45
//Get a list of registered machines
 
46
$machines = $virtualbox->machines;
 
47
 
 
48
//Take a screenshot of the first vm we find that is running
 
49
foreach ($machines as $machine)
 
50
{
 
51
    if ( 'Running' == $machine->state )
 
52
    {
 
53
        $session = $websessionManager->getSessionObject($virtualbox->handle);
 
54
        $uuid = $machine->id;
 
55
        $virtualbox->openExistingSession($session, $uuid);
 
56
        try
 
57
        {
 
58
            $console = $session->console;
 
59
            $display = $console->display;
 
60
            $screenWidth = $display->width;
 
61
            $screenHeight = $display->height;
 
62
            $imageraw = $display->takeScreenShotSlow($screenWidth, $screenHeight);
 
63
            $session->close();
 
64
            $filename = './screenshot.png';
 
65
            echo "Saving screenshot of " . $machine->name . " (${screenWidth}x${screenHeight}) to $filename\n";
 
66
            $image = imagecreatetruecolor($screenWidth, $screenHeight);
 
67
 
 
68
            for ($height = 0; $height < $screenHeight; $height++)
 
69
            {
 
70
                for ($width = 0; $width < $screenWidth; $width++)
 
71
                {
 
72
                    $start = ($height*$screenWidth + $width)*4;
 
73
                    $red = $imageraw[$start];
 
74
                    $green = $imageraw[$start+1];
 
75
                    $blue = $imageraw[$start+2];
 
76
                    //$alpha = $imageraw[$start+3];
 
77
 
 
78
                    $colour = imagecolorallocate($image, $red, $green, $blue);
 
79
 
 
80
                    imagesetpixel($image, $width, $height, $colour);
 
81
                }
 
82
            }
 
83
 
 
84
            imagepng($image, $filename);
 
85
        }
 
86
        catch (Exception $ex)
 
87
        {
 
88
            // Ensure we close the VM Session if we hit a error, ensure we don't have a aborted VM
 
89
            echo $ex->getMessage();
 
90
            $session->close();
 
91
        }
 
92
        break;
 
93
    }
 
94
}
 
95
 
 
96
$websessionManager->logoff($virtualbox->handle);