Example #1
0
 /**
  * Returns the filename logs for a WBXML debug log user should be saved to
  *
  * @access private
  * @return string
  */
 private static function logToUserFile()
 {
     global $specialLogUsers;
     if (self::$authUser === false) {
         if (RequestProcessor::isUserAuthenticated()) {
             $authuser = Request::GetAuthUser();
             if ($authuser && in_array($authuser, $specialLogUsers)) {
                 self::$authUser = preg_replace('/[^a-z0-9]/', '_', strtolower($authuser));
             }
         }
     }
     return self::$authUser;
 }
 /**
  * Called at the end of the request
  * Statistics about received/sent data is saved here
  *
  * @access public
  * @return boolean
  */
 public function Save()
 {
     // TODO save other stuff
     // check if previousily ignored messages were synchronized for the current folder
     // on multifolder operations of AS14 this is done by setLatestFolder()
     if ($this->latestFolder !== false) {
         $this->checkBrokenMessages($this->latestFolder);
     }
     // update the user agent and AS version on the device
     $this->device->SetUserAgent(Request::GetUserAgent());
     $this->device->SetASVersion(Request::GetProtocolVersion());
     // data to be saved
     $data = $this->device->GetData();
     if ($data && Request::IsValidDeviceID()) {
         ZLog::Write(LOGLEVEL_DEBUG, "DeviceManager->Save(): Device data changed");
         try {
             // check if this is the first time the device data is saved and it is authenticated. If so, link the user to the device id
             if ($this->device->IsNewDevice() && RequestProcessor::isUserAuthenticated()) {
                 ZLog::Write(LOGLEVEL_INFO, sprintf("Linking device ID '%s' to user '%s'", $this->devid, $this->device->GetDeviceUser()));
                 $this->statemachine->LinkUserDevice($this->device->GetDeviceUser(), $this->devid);
             }
             if (RequestProcessor::isUserAuthenticated() || $this->device->GetForceSave()) {
                 $this->statemachine->SetState($data, $this->devid, IStateMachine::DEVICEDATA);
                 ZLog::Write(LOGLEVEL_DEBUG, "DeviceManager->Save(): Device data saved");
             }
         } catch (StateNotFoundException $snfex) {
             ZLog::Write(LOGLEVEL_ERROR, "DeviceManager->Save(): Exception: " . $snfex->getMessage());
         }
     }
     // remove old search data
     $oldpid = $this->loopdetection->ProcessLoopDetectionGetOutdatedSearchPID();
     if ($oldpid) {
         ZPush::GetBackend()->GetSearchProvider()->TerminateSearch($oldpid);
     }
     // we terminated this process
     if ($this->loopdetection) {
         $this->loopdetection->ProcessLoopDetectionTerminate();
     }
     return true;
 }
Example #3
0
 /**
  * @param int $loglevel
  * @param string $message
  */
 public function Log($loglevel, $message)
 {
     if ($loglevel <= LOGLEVEL) {
         $this->Write($loglevel, $message);
     }
     if ($loglevel <= LOGUSERLEVEL && $this->IsAuthUserInSpecialLogUsers()) {
         if (RequestProcessor::isUserAuthenticated()) {
             // something was logged before the user was authenticated, write this to the log
             if (!empty($this->unauthMessageCache)) {
                 foreach ($this->unauthMessageCache as $authcache) {
                     $this->WriteForUser($authcache[0], $authcache[1]);
                 }
                 $this->unauthMessageCache = array();
             }
             $this->WriteForUser($loglevel, $message);
         } else {
             $this->unauthMessageCache[] = array($loglevel, $message);
         }
     }
     $this->afterLog($loglevel, $message);
 }
Example #4
0
 // check the provisioning information
 if (PROVISIONING === true && Request::IsMethodPOST() && ZPush::CommandNeedsProvisioning(Request::GetCommandCode()) && (Request::WasPolicyKeySent() && Request::GetPolicyKey() == 0 || ZPush::GetDeviceManager()->ProvisioningRequired(Request::GetPolicyKey())) && (LOOSE_PROVISIONING === false || LOOSE_PROVISIONING === true && Request::WasPolicyKeySent())) {
     //TODO for AS 14 send a wbxml response
     throw new ProvisioningRequiredException();
 }
 // most commands require an authenticated user
 if (ZPush::CommandNeedsAuthentication(Request::GetCommandCode())) {
     RequestProcessor::Authenticate();
 }
 // Do the actual processing of the request
 if (Request::IsMethodGET()) {
     throw new NoPostRequestException("This is the Z-Push location and can only be accessed by Microsoft ActiveSync-capable devices", NoPostRequestException::GET_REQUEST);
 }
 // Do the actual request
 header(ZPush::GetServerHeader());
 if (RequestProcessor::isUserAuthenticated()) {
     header("X-Z-Push-Version: " . @constant('ZPUSH_VERSION'));
 }
 // announce the supported AS versions (if not already sent to device)
 if (ZPush::GetDeviceManager()->AnnounceASVersion()) {
     $versions = ZPush::GetSupportedProtocolVersions(true);
     ZLog::Write(LOGLEVEL_INFO, sprintf("Announcing latest AS version to device: %s", $versions));
     header("X-MS-RP: " . $versions);
 }
 RequestProcessor::Initialize();
 RequestProcessor::HandleRequest();
 // eventually the RequestProcessor wants to send other headers to the mobile
 foreach (RequestProcessor::GetSpecialHeaders() as $header) {
     header($header);
 }
 // stream the data