Esempio n. 1
0
 /**
  * Registers a new display
  * @param string $serverKey
  * @param string $hardwareKey
  * @param string $displayName
  * @param string $clientType
  * @param string $clientVersion
  * @param int $clientCode
  * @param string $operatingSystem
  * @param string $macAddress
  * @return string
  * @throws SoapFault
  */
 public function RegisterDisplay($serverKey, $hardwareKey, $displayName, $clientType, $clientVersion, $clientCode, $operatingSystem, $macAddress)
 {
     // Sanitize
     $serverKey = Kit::ValidateParam($serverKey, _STRING);
     $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
     $displayName = Kit::ValidateParam($displayName, _STRING);
     $clientType = Kit::ValidateParam($clientType, _STRING);
     $clientVersion = Kit::ValidateParam($clientVersion, _STRING);
     $clientCode = Kit::ValidateParam($clientCode, _INT);
     $macAddress = Kit::ValidateParam($macAddress, _STRING);
     $clientAddress = Kit::GetParam('REMOTE_ADDR', $_SERVER, _STRING);
     // Audit in
     Debug::Audit('serverKey: ' . $serverKey . ', hardwareKey: ' . $hardwareKey . ', displayName: ' . $displayName);
     // Check the serverKey matches
     if ($serverKey != Config::GetSetting('SERVER_KEY')) {
         throw new SoapFault('Sender', 'The Server key you entered does not match with the server key at this address');
     }
     // Check the Length of the hardwareKey
     if (strlen($hardwareKey) > 40) {
         throw new SoapFault('Sender', 'The Hardware Key you sent was too long. Only 40 characters are allowed (SHA1).');
     }
     // Check in the database for this hardwareKey
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('
             SELECT licensed, display, displayid, displayprofileid, client_type, version_instructions, screenShotRequested, email_alert, loggedin, isAuditing
               FROM display
             WHERE license = :hardwareKey');
         $sth->execute(array('hardwareKey' => $hardwareKey));
         $result = $sth->fetchAll();
     } catch (Exception $e) {
         Debug::Error('Error trying to check hardware key. ' . $e->getMessage());
         throw new SoapFault('Sender', 'Cannot check client key.');
     }
     // Use a display object to Add or Edit the display
     $displayObject = new Display();
     // Return an XML formatted string
     $return = new DOMDocument('1.0');
     $displayElement = $return->createElement('display');
     $return->appendChild($displayElement);
     // Is it there?
     if (count($result) == 0) {
         // Get the default layout id
         $defaultLayoutId = 4;
         // Add this display record
         if (!($displayId = $displayObject->Add($displayName, 0, $defaultLayoutId, $hardwareKey, 0, 0))) {
             throw new SoapFault('Sender', 'Error adding display');
         }
         $displayElement->setAttribute('status', 1);
         $displayElement->setAttribute('code', 'ADDED');
         $displayElement->setAttribute('message', 'Display added and is awaiting licensing approval from an Administrator.');
         // New displays don't audit
         $isAuditing = 0;
     } else {
         // We have seen this display before, so check the licensed value
         $row = $result[0];
         $displayId = Kit::ValidateParam($row['displayid'], _INT);
         $display = Kit::ValidateParam($row['display'], _STRING);
         $clientType = Kit::ValidateParam($row['client_type'], _WORD);
         $versionInstructions = Kit::ValidateParam($row['version_instructions'], _HTMLSTRING);
         $screenShotRequested = Kit::ValidateParam($row['screenShotRequested'], _INT);
         $emailAlert = Kit::ValidateParam($row['email_alert'], _INT);
         $loggedIn = Kit::ValidateParam($row['loggedin'], _INT);
         $isAuditing = Kit::ValidateParam($row['isAuditing'], _INT);
         // Determine if we are licensed or not
         if ($row['licensed'] == 0) {
             // It is not licensed
             $displayElement->setAttribute('status', 2);
             $displayElement->setAttribute('code', 'WAITING');
             $displayElement->setAttribute('message', 'Display is awaiting licensing approval from an Administrator.');
         } else {
             // It is licensed
             $displayElement->setAttribute('status', 0);
             $displayElement->setAttribute('code', 'READY');
             $displayElement->setAttribute('message', 'Display is active and ready to start.');
             $displayElement->setAttribute('version_instructions', $versionInstructions);
             // Use the display profile and type to get this clients settings
             try {
                 $displayProfile = new DisplayProfile();
                 $displayProfile->displayProfileId = empty($row['displayprofileid']) ? 0 : Kit::ValidateParam($row['displayprofileid'], _INT);
                 if ($displayProfile->displayProfileId == 0) {
                     // Load the default profile
                     $displayProfile->type = $clientType;
                     $displayProfile->LoadDefault();
                 } else {
                     // Load the specified profile
                     $displayProfile->Load();
                 }
                 // Load the config and inject the display name
                 if ($clientType == 'windows') {
                     $displayProfile->config[] = array('name' => 'DisplayName', 'value' => $display, 'type' => 'string');
                     $displayProfile->config[] = array('name' => 'ScreenShotRequested', 'value' => $screenShotRequested, 'type' => 'checkbox');
                 } else {
                     $displayProfile->config[] = array('name' => 'displayName', 'value' => $display, 'type' => 'string');
                     $displayProfile->config[] = array('name' => 'screenShotRequested', 'value' => $screenShotRequested, 'type' => 'checkbox');
                 }
                 // Create the XML nodes
                 foreach ($displayProfile->config as $arrayItem) {
                     $node = $return->createElement($arrayItem['name'], isset($arrayItem['value']) ? $arrayItem['value'] : $arrayItem['default']);
                     $node->setAttribute('type', $arrayItem['type']);
                     $displayElement->appendChild($node);
                 }
             } catch (Exception $e) {
                 Debug::Error('Error loading display config. ' . $e->getMessage());
                 throw new SoapFault('Sender', 'Error after display found');
             }
             // Send Notification if required
             $this->AlertDisplayUp($displayId, $display, $loggedIn, $emailAlert);
         }
     }
     // Touch the display record
     $displayObject->Touch($displayId, array('clientAddress' => $clientAddress, 'macAddress' => $macAddress, 'clientType' => $clientType, 'clientVersion' => $clientVersion, 'clientCode' => $clientCode, 'operatingSystem' => $operatingSystem));
     // Log Bandwidth
     $returnXml = $return->saveXML();
     $this->LogBandwidth($displayId, Bandwidth::$REGISTER, strlen($returnXml));
     // Audit our return
     if ($isAuditing == 1) {
         Debug::Audit($returnXml, $displayId);
     }
     return $returnXml;
 }
Esempio n. 2
0
 /**
  * Deletes a Group
  * @return 
  */
 function Delete()
 {
     // Check the token
     if (!Kit::CheckToken()) {
         trigger_error('Token does not match', E_USER_ERROR);
     }
     $response = new ResponseManager();
     $displayProfile = new DisplayProfile();
     $displayProfile->displayProfileId = Kit::GetParam('displayprofileid', _POST, _INT);
     if (!$displayProfile->Load()) {
         trigger_error($displayProfile->GetErrorMessage(), E_USER_ERROR);
     }
     if ($this->user->usertypeid != 1 && $this->user->userid != $displayProfile->userId) {
         trigger_error(__('You do not have permission to edit this profile'), E_USER_ERROR);
     }
     if (!$displayProfile->Delete($displayProfile->displayProfileId)) {
         trigger_error($displayProfile->GetErrorMessage(), E_USER_ERROR);
     }
     $response->SetFormSubmitResponse(__('Display Profile Deleted'), false);
     $response->Respond();
 }
Esempio n. 3
0
 private function SetConfig()
 {
     if ($this->_config == null) {
         try {
             $displayProfile = new DisplayProfile();
             $displayProfile->displayProfileId = $this->displayProfileId;
             if ($displayProfile->displayProfileId == 0) {
                 // Load the default profile
                 $displayProfile->type = $this->clientType;
                 $displayProfile->LoadDefault();
             } else {
                 // Load the specified profile
                 $displayProfile->Load();
             }
             $this->_config = $displayProfile->config;
             return true;
         } catch (Exception $e) {
             Debug::LogEntry('error', $e->getMessage(), get_class(), __FUNCTION__);
             if (!$this->IsError()) {
                 $this->SetError(1, __('Unknown Error'));
             }
             return false;
         }
     }
 }