コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * Obtain configuration settings and set object vars
  * @param boolean $useAuthMaster use the authentication master obtained from configuration class
  * @see phpVBoxConfigClass
  */
 public function __construct($useAuthMaster = false)
 {
     require_once dirname(__FILE__) . '/language.php';
     require_once dirname(__FILE__) . '/vboxServiceWrappers.php';
     /* Set up.. .. settings */
     /** @var phpVBoxConfigClass */
     $this->settings = new phpVBoxConfigClass();
     // Are default settings being used?
     if (@$this->settings->warnDefault) {
         throw new Exception("No configuration found. Rename the file <b>config.php-example</b> in phpVirtualBox's folder to <b>config.php</b> and edit as needed.<p>For more detailed instructions, please see the installation wiki on phpVirtualBox's web site. <p><a href='http://code.google.com/p/phpvirtualbox/w/list' target=_blank>http://code.google.com/p/phpvirtualbox/w/list</a>.</p>", vboxconnector::PHPVB_ERRNO_FATAL);
     }
     // Check for SoapClient class
     if (!class_exists('SoapClient')) {
         throw new Exception('PHP does not have the SOAP extension enabled.', vboxconnector::PHPVB_ERRNO_FATAL);
     }
     // use authentication master server?
     if (@$useAuthMaster) {
         $this->settings->setServer($this->settings->getServerAuthMaster());
     }
 }