/** * Connect to vboxwebsrv * @see SoapClient * @see phpVBoxConfigClass * @return boolean true on success or if already connected */ public function connect() { // Already connected? if (@$this->connected) { return true; } // Valid session? if (!@$this->skipSessionCheck && !$_SESSION['valid']) { throw new Exception(trans('Not logged in.', 'UIUsers'), vboxconnector::PHPVB_ERRNO_FATAL); } // Persistent server? if (@$this->persistentRequest['vboxServer']) { $this->settings->setServer($this->persistentRequest['vboxServer']); } //Connect to webservice $pvbxver = substr(@constant('PHPVBOX_VER'), 0, strpos(@constant('PHPVBOX_VER'), '-')); $this->client = new SoapClient(dirname(__FILE__) . "/vboxwebService-" . $pvbxver . ".wsdl", array('features' => SOAP_USE_XSI_ARRAY_TYPE + SOAP_SINGLE_ELEMENT_ARRAYS, 'cache_wsdl' => WSDL_CACHE_BOTH, 'trace' => @$this->settings->debugSoap, 'connection_timeout' => @$this->settings->connectionTimeout ? $this->settings->connectionTimeout : 20, 'location' => @$this->settings->location)); // Persistent handles? if (@$this->persistentRequest['vboxHandle']) { try { // Check for existing sessioin $this->websessionManager = new IWebsessionManager($this->client); $this->vbox = new IVirtualBox($this->client, $this->persistentRequest['vboxHandle']); // force valid vbox check $ev = $this->vbox->eventSource; if ($this->vbox->handle) { return $this->connected = true; } } catch (Exception $e) { // nothing. Fall through to new login. } } /* Try / catch / throw here hides login credentials from exception if one is thrown */ try { $this->websessionManager = new IWebsessionManager($this->client); $this->vbox = $this->websessionManager->logon($this->settings->username, $this->settings->password); } catch (Exception $e) { if (!($msg = $e->getMessage())) { $msg = 'Error logging in to vboxwebsrv.'; } else { $msg .= " ({$this->settings->location})"; } throw new Exception($msg, vboxconnector::PHPVB_ERRNO_CONNECT); } // Error logging in if (!$this->vbox->handle) { throw new Exception('Error logging in or connecting to vboxwebsrv.', vboxconnector::PHPVB_ERRNO_CONNECT); } // Hold handle if (array_key_exists('vboxHandle', $this->persistentRequest)) { $this->persistentRequest['vboxHandle'] = $this->vbox->handle; } return $this->connected = true; }
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ require_once './vboxServiceWrappers.php'; //Connect to webservice $connection = new SoapClient("vboxwebService.wsdl", array('location' => "http://localhost:18083/")); //Logon to webservice $websessionManager = new IWebsessionManager($connection); // Dummy username and password (change to appropriate values or set authentication method to null) $virtualbox = $websessionManager->logon("username", "password"); //Get a list of registered machines $machines = $virtualbox->machines; //Take a screenshot of the first vm we find that is running foreach ($machines as $machine) { if ('Running' == $machine->state) { $session = $websessionManager->getSessionObject($virtualbox->handle); $uuid = $machine->id; $virtualbox->openExistingSession($session, $uuid); try { $console = $session->console; $display = $console->display; $screenWidth = $display->width; $screenHeight = $display->height; $imageraw = $display->takeScreenShotSlow($screenWidth, $screenHeight); $session->close();