Beispiel #1
0
 /**
  * Validates a username and password
  *
  * This method should return true or false depending on if login
  * succeeded.
  *
  * @return bool
  */
 protected function validateUserPass($sUserName, $sPassword)
 {
     if (class_exists('CApi') && \CApi::IsValid()) {
         /* @var $oApiCalendarManager \CApiCalendarManager */
         $oApiCalendarManager = \CApi::Manager('calendar');
         /* @var $oApiCapabilityManager \CApiCapabilityManager */
         $oApiCapabilityManager = \CApi::Manager('capability');
         if ($oApiCalendarManager && $oApiCapabilityManager) {
             $oAccount = \afterlogic\DAV\Utils::GetAccountByLogin($sUserName);
             if ($oAccount && $oAccount->IsDisabled) {
                 return false;
             }
             $bIsOutlookSyncClient = \afterlogic\DAV\Utils::ValidateClient('outlooksync');
             $bIsMobileSync = false;
             $bIsOutlookSync = false;
             $bIsDemo = false;
             if ($oAccount) {
                 $bIsMobileSync = $oApiCapabilityManager->IsMobileSyncSupported($oAccount);
                 $bIsOutlookSync = $oApiCapabilityManager->IsOutlookSyncSupported($oAccount);
                 \CApi::Plugin()->RunHook('plugin-is-demo-account', array(&$oAccount, &$bIsDemo));
             }
             if ($oAccount && $oAccount->IncomingMailPassword === $sPassword && ($bIsMobileSync && !$bIsOutlookSyncClient || $bIsOutlookSync && $bIsOutlookSyncClient) || $bIsDemo || $sUserName === $oApiCalendarManager->GetPublicUser()) {
                 \afterlogic\DAV\Utils::CheckPrincipals($sUserName);
                 return true;
             }
         }
     }
     return false;
 }
 public function getAccount()
 {
     if (null === $this->oAccount) {
         $this->oAccount = \afterlogic\DAV\Utils::GetAccountByLogin(basename($this->principalUri));
     }
     return $this->oAccount;
 }
Beispiel #3
0
 public function getDigestHash($sRealm, $sUserName)
 {
     if (class_exists('CApi') && \CApi::IsValid()) {
         /* @var $oApiCapabilityManager \CApiCapabilityManager */
         $oApiCapabilityManager = \CApi::GetSystemManager('capability');
         if ($oApiCapabilityManager) {
             $oAccount = \Afterlogic\DAV\Utils::GetAccountByLogin($sUserName);
             if ($oAccount && $oAccount->IsDisabled) {
                 return null;
             }
             $bIsOutlookSyncClient = \Afterlogic\DAV\Utils::ValidateClient('outlooksync');
             $bIsMobileSync = false;
             $bIsOutlookSync = false;
             $bIsDemo = false;
             if ($oAccount) {
                 $bIsMobileSync = $oApiCapabilityManager->isMobileSyncSupported($oAccount);
                 $bIsOutlookSync = $oApiCapabilityManager->isOutlookSyncSupported($oAccount);
                 \CApi::Plugin()->RunHook('plugin-is-demo-account', array(&$oAccount, &$bIsDemo));
             }
             if ($oAccount && ($bIsMobileSync && !$bIsOutlookSyncClient || $bIsOutlookSync && $bIsOutlookSyncClient) || $bIsDemo || $sUserName === \CApi::ExecuteMethod('Dav::GetPublicUser')) {
                 return md5($sUserName . ':' . $sRealm . ':' . ($bIsDemo ? 'demo' : $oAccount->IncomingMailPassword));
             }
         }
     }
     return null;
 }
Beispiel #4
0
 public function getUser()
 {
     if (null === $this->iUserId) {
         $this->iUserId = \Afterlogic\DAV\Utils::GetAccountByLogin(basename($this->principalUri));
     }
     return $this->iUserId;
 }
Beispiel #5
0
 public function getAccount()
 {
     if ($this->oAccount == null) {
         $sUser = \afterlogic\DAV\Auth\Backend::getInstance()->getCurrentUser();
         $this->oAccount = \afterlogic\DAV\Utils::GetAccountByLogin($sUser);
     }
     return $this->oAccount;
 }
Beispiel #6
0
 public static function getTenantPrincipalUri($principalUri)
 {
     $sTenantPrincipalUri = null;
     $oAccount = \afterlogic\DAV\Utils::GetAccountByLogin(basename($principalUri));
     if ($oAccount) {
         $sTenantEmail = self::getTenantUser($oAccount);
         $sTenantPrincipalUri = \afterlogic\DAV\Constants::PRINCIPALS_PREFIX . '/' . $sTenantEmail;
     }
     return $sTenantPrincipalUri;
 }
Beispiel #7
0
 public function initPath()
 {
     if ($this->rootPath === null) {
         $sUserName = \afterlogic\DAV\Auth\Backend::getInstance()->getCurrentUser();
         if (isset($sUserName)) {
             $oAccount = \afterlogic\DAV\Utils::GetAccountByLogin($sUserName);
             if ($oAccount) {
                 $this->rootPath = $this->path . '/' . $oAccount->IdTenant;
                 if (!file_exists($this->rootPath)) {
                     mkdir($this->rootPath, 0777, true);
                 }
             }
         }
     }
     $this->path = $this->rootPath;
 }
Beispiel #8
0
 /**
  * This method is used to search for principals matching a set of
  * properties.
  *
  * @param string $prefixPath
  * @param array $searchProperties
  * @return array
  */
 public function searchPrincipals($prefixPath, array $searchProperties)
 {
     $oAccount = null;
     foreach ($searchProperties as $property => $value) {
         switch ($property) {
             case '{http://sabredav.org/ns}email-address':
                 $oAccount = \afterlogic\DAV\Utils::GetAccountByLogin($value);
                 break;
             default:
                 // Unsupported property
                 return array();
         }
     }
     $principals = array();
     if ($oAccount) {
         $principals[] = \afterlogic\DAV\Constants::PRINCIPALS_PREFIX . '/' . $oAccount->Email;
     }
     return $principals;
 }
Beispiel #9
0
 /**
  * Returns the list of people whom this calendar is shared with.
  *
  * Every element in this array should have the following properties:
  *   * href - Often a mailto: address
  *   * commonname - Optional, for example a first + last name
  *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
  *   * readOnly - boolean
  *   * summary - Optional, a description for the share
  *
  * @return array
  */
 public function getShares($mCalendarId)
 {
     //		$fields = implode(', ', $this->sharesProperties);
     $stmt = $this->pdo->prepare("SELECT * FROM " . $this->calendarSharesTableName . " AS calendarShares  WHERE calendarShares.calendarid = ? ORDER BY calendarShares.calendarid ASC");
     $stmt->execute(array($mCalendarId));
     $aShares = array();
     $oUsersManager = \CApi::GetSystemManager('users');
     while ($aRow = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $sCommonName = basename($aRow['principaluri']);
         $oAccount = \Afterlogic\DAV\Utils::GetAccountByLogin($sCommonName);
         if ($oAccount instanceof \CAccount) {
             $sCommonName = $oAccount->FriendlyName;
         }
         $aShare = array('calendarid' => $aRow['calendarid'], 'principalpath' => $aRow['principaluri'], 'readOnly' => $aRow['readonly'], 'summary' => $aRow['summary'], 'href' => basename($aRow['principaluri']), 'commonName' => $sCommonName, 'displayname' => $aRow['displayname'], 'status' => $aRow['status'], 'color' => $aRow['color']);
         // add it to main array
         $aShares[] = $aShare;
     }
     return $aShares;
 }
Beispiel #10
0
 public function updateReminder($uri, $data, $user)
 {
     if (self::isCalendar($uri) && self::isEvent($uri)) {
         $calendarUri = trim($this->getCalendarUri($uri), '/');
         $eventId = $this->getEventId($uri);
         $aReminder = $this->getReminder($eventId, $user);
         $this->deleteReminder($eventId, $user);
         $vCal = \Sabre\VObject\Reader::read($data);
         $aBaseEvents = $vCal->getBaseComponents('VEVENT');
         $bAllDay = false;
         if (isset($aBaseEvents[0])) {
             $oBaseEvent = $aBaseEvents[0];
             $oNowDT = new \DateTime('now', new \DateTimeZone('UTC'));
             $iReminderStartTS = $oNowDT->getTimestamp();
             if ($aReminder) {
                 $iReminderStartTS = $aReminder['starttime'];
             }
             $bAllDay = !$oBaseEvent->DTSTART->hasTime();
             $oStartDT = $oBaseEvent->DTSTART->getDateTime();
             $oStartDT->setTimezone(new \DateTimeZone('UTC'));
             $oEndDT = $oBaseEvent->DTEND->getDateTime();
             $oEndDT->setTimezone(new \DateTimeZone('UTC'));
             $oInterval = $oStartDT->diff($oEndDT);
             $oStartDT = \CCalendarHelper::getNextRepeat($oNowDT, $oBaseEvent);
             if ($oStartDT) {
                 $iReminderTime = \CCalendarHelper::getActualReminderTime($oBaseEvent, $oNowDT, $oStartDT);
                 if ($iReminderTime === false && isset($oBaseEvent->RRULE)) {
                     $iStartTS = $oStartDT->getTimestamp();
                     if ($iStartTS == $iReminderStartTS) {
                         $oStartDT->add($oInterval);
                         $oStartDT = \CCalendarHelper::getNextRepeat($oStartDT, $oBaseEvent);
                     }
                     $iReminderTime = \CCalendarHelper::getActualReminderTime($oBaseEvent, $oNowDT, $oStartDT);
                 }
                 if ($iReminderTime !== false) {
                     $iOffset = 0;
                     if ($bAllDay) {
                         $oAccount = \afterlogic\DAV\Utils::GetAccountByLogin($user);
                         if ($oAccount) {
                             $oClientTZ = new \DateTimeZone($oAccount->User->ClientTimeZone);
                             $oNowDTClientTZ = new \DateTime("now", $oClientTZ);
                             $iOffset = $oNowDTClientTZ->getOffset();
                         }
                     }
                     $iStartTS = $oStartDT->getTimestamp();
                     $this->addReminder($user, $calendarUri, $eventId, $iReminderTime - $iOffset, $iStartTS - $iOffset, $bAllDay);
                 }
             }
         }
     }
 }
Beispiel #11
0
 /**
  * @param string $uri 
  * @return bool
  */
 public function existsPrincipal($uri)
 {
     $bResult = false;
     $oAccount = \afterlogic\DAV\Utils::GetAccountByLogin(basename($uri));
     if ($oAccount) {
         $bResult = true;
     }
     return $bResult;
 }