Пример #1
0
 public function getAccount()
 {
     if (null === $this->oAccount) {
         $this->oAccount = \afterlogic\DAV\Utils::GetAccountByLogin(basename($this->principalUri));
     }
     return $this->oAccount;
 }
Пример #2
0
 /**
  * Deletes the calendar.
  *
  * @return void
  */
 public function delete()
 {
     $sTenantPrincipalUri = \Afterlogic\DAV\Utils::getTenantPrincipalUri($this->principalInfo['uri']);
     if ($sTenantPrincipalUri !== $this->calendarInfo['principaluri']) {
         $this->caldavBackend->updateShares($this->calendarInfo['id'], array(), array(basename($this->principalInfo['uri'])));
     }
 }
Пример #3
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;
 }
Пример #4
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;
 }
Пример #5
0
 public function getUser()
 {
     if (null === $this->iUserId) {
         $this->iUserId = \Afterlogic\DAV\Utils::GetAccountByLogin(basename($this->principalUri));
     }
     return $this->iUserId;
 }
Пример #6
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;
 }
Пример #7
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;
 }
Пример #8
0
 /**
  * Returns the id list of shared cards
  *
  * @return array
  */
 public function getSharedChildrenIds()
 {
     $aContactIds = array();
     $oAccount = \afterlogic\DAV\Utils::getCurrentAccount();
     if ($oAccount) {
         $oContactsManager = $this->getContactsManager();
         if ($oContactsManager) {
             $aContactIds = $oContactsManager->getSharedContactIds($oAccount->IdUser, $oAccount->IdTenant);
         }
     }
     return $aContactIds;
 }
Пример #9
0
 /**
  * @param CAccount $oAccount
  */
 public function Init($oAccount)
 {
     $bResult = false;
     if ($oAccount) {
         if (!$this->initialized) {
             \afterlogic\DAV\Auth\Backend::getInstance()->setCurrentUser($oAccount->Email);
             \afterlogic\DAV\Utils::CheckPrincipals($oAccount->Email);
             $this->initialized = true;
         }
         $bResult = true;
     }
     return $bResult;
 }
Пример #10
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;
 }
Пример #11
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;
 }
Пример #12
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)
 {
     $mResult = false;
     if (class_exists('CApi') && \CApi::IsValid()) {
         /* @var $oApiCapabilityManager \CApiCapabilityManager */
         $oApiCapabilityManager = \CApi::GetSystemManager('capability');
         if ($oApiCapabilityManager) {
             $oDavDecorator = \CApi::GetModuleDecorator('Dav');
             if ($oDavDecorator) {
                 $mResult = $oDavDecorator->Login($sUserName, $sPassword);
             }
             $bIsOutlookSyncClient = \Afterlogic\DAV\Utils::ValidateClient('outlooksync');
             $bIsMobileSync = false;
             $bIsOutlookSync = false;
             $bIsDemo = false;
             //				if ($mResult !== false) {
             //					$iIdUser = isset($mResult['id']) ? $mResult['id'] : 0;
             //					return true;
             /*					
             					$bIsMobileSync = $oApiCapabilityManager->isMobileSyncSupported($iIdUser);
             					$bIsOutlookSync = $oApiCapabilityManager->isOutlookSyncSupported($iIdUser);
             					
             					\CApi::Plugin()->RunHook(
             							'plugin-is-demo-account', 
             							array(&$oAccount, &$bIsDemo)
             					);
             * 
             */
             //				}
             /*
             				if (($oAccount && $oAccount->IncomingMailPassword === $sPassword &&
             						(($bIsMobileSync && !$bIsOutlookSyncClient) || 
             						($bIsOutlookSync && $bIsOutlookSyncClient))) ||
             						$bIsDemo || $sUserName === \CApi::ExecuteMethod('Dav::GetPublicUser')) {
             					return true;
             				}
             * 
             */
         }
     }
     return $mResult;
 }
Пример #13
0
 /**
  * @param CAccount $oAccount
  */
 public function InitByAccount($oAccount)
 {
     $bResult = false;
     if ($oAccount && (!$this->Account || $this->Account->Email !== $oAccount->Email)) {
         $this->Account = $oAccount;
         $this->aAddressBooksCache = array();
         $this->aContactItemsCache = array();
         $this->aGroupItemsCache = array();
         $this->ContactsCache = array();
         $this->GroupsCache = array();
         \afterlogic\DAV\Auth\Backend::getInstance()->setCurrentUser($oAccount->Email);
         \afterlogic\DAV\Utils::CheckPrincipals($oAccount->Email);
         $aPrincipalProperties = \afterlogic\DAV\Backend::Principal()->getPrincipalByPath(\afterlogic\DAV\Constants::PRINCIPALS_PREFIX . '/' . $oAccount->Email);
         if ($aPrincipalProperties) {
             if (isset($aPrincipalProperties['uri'])) {
                 $this->Principal = $aPrincipalProperties['uri'];
             }
         }
     }
     if ($this->Account) {
         $bResult = true;
     }
     return $bResult;
 }
Пример #14
0
 protected function getSharedCalendarsForUser($sPrincipalUri, $bSharedToAll = false)
 {
     $aCalendars = array();
     $sTenantPrincipalUri = null;
     if (!$sPrincipalUri) {
         return $aCalendars;
     }
     if ($sPrincipalUri) {
         if ($bSharedToAll) {
             $sTenantPrincipalUri = $sPrincipalUri;
             $sPrincipalUri = \Afterlogic\DAV\Utils::getTenantPrincipalUri($sPrincipalUri);
         }
         $sFields = $this->getCalendarFields();
         $sShareFields = implode(', ', $this->sharesProperties);
         $oStmt = $this->pdo->prepare("SELECT " . $sShareFields . " FROM " . $this->calendarSharesTableName . " WHERE principaluri = ?");
         $oStmt->execute(array($sPrincipalUri));
         $aRows = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
         foreach ($aRows as $aRow) {
             // get the original calendar
             $oCalStmt = $this->pdo->prepare("SELECT " . $sFields . " FROM " . $this->calendarTableName . " WHERE id = ? ORDER BY id ASC LIMIT 1");
             $oCalStmt->execute(array($aRow['calendarid']));
             while ($calRow = $oCalStmt->fetch(\PDO::FETCH_ASSOC)) {
                 $aComponents = isset($aRows['components']) ? explode(',', $aRows['components']) : array();
                 $aCalendar = array('id' => $calRow['id'], 'uri' => $calRow['uri'], 'principaluri' => $bSharedToAll ? $sTenantPrincipalUri : $sPrincipalUri, '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new \Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet($aComponents), '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}schedule-calendar-transp' => new \Sabre\CalDAV\Xml\Property\ScheduleCalendarTransp($calRow['transparent'] ? 'transparent' : 'opaque'));
                 // some specific properies for shared calendars
                 $aCalendar['{http://calendarserver.org/ns/}shared-url'] = $calRow['uri'];
                 $aCalendar['{http://sabredav.org/ns}owner-principal'] = $calRow['principaluri'];
                 $aCalendar['{http://sabredav.org/ns}read-only'] = $aRow['readonly'];
                 $aCalendar['{http://calendarserver.org/ns/}summary'] = $aRow['summary'];
                 foreach ($this->propertyMap as $xmlName => $dbName) {
                     if ($xmlName == '{DAV:}displayname') {
                         $aCalendar[$xmlName] = $calRow['displayname'];
                         //$aRow['displayname'] == null ? $calRow['displayname'] : $aRow['displayname'];
                     } elseif ($xmlName == '{http://apple.com/ns/ical/}calendar-color') {
                         $aCalendar[$xmlName] = $aRow['color'] == null ? $calRow['calendarcolor'] : $aRow['color'];
                     } else {
                         $aCalendar[$xmlName] = $calRow[$dbName];
                     }
                 }
                 $aCalendars[$aCalendar['id']] = $aCalendar;
             }
         }
     }
     return $aCalendars;
 }
Пример #15
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);
                 }
             }
         }
     }
 }
Пример #16
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;
 }
Пример #17
0
 public static function getPrincipalByEmail($sEmail)
 {
     $sEmail = trim(str_ireplace("mailto:", "", $sEmail));
     $oPrincipalBackend = Backend::Principal();
     $mPrincipalPath = $oPrincipalBackend->searchPrincipals(\afterlogic\DAV\Constants::PRINCIPALS_PREFIX, array('{http://sabredav.org/ns}email-address' => $sEmail));
     if (is_array($mPrincipalPath) && count($mPrincipalPath) === 0) {
         \afterlogic\DAV\Utils::CheckPrincipals($sEmail);
         $mPrincipalPath = $oPrincipalBackend->searchPrincipals(\afterlogic\DAV\Constants::PRINCIPALS_PREFIX, array('{http://sabredav.org/ns}email-address' => $sEmail));
         if (is_array($mPrincipalPath) && count($mPrincipalPath) === 0) {
             throw new \Exception("Unknown email address");
         }
     }
     $sPrincipal = null;
     foreach ($mPrincipalPath as $aPrincipal) {
         if ($aPrincipal === \afterlogic\DAV\Constants::PRINCIPALS_PREFIX . '/' . $sEmail) {
             $sPrincipal = $aPrincipal;
             break;
         }
     }
     if (!isset($sPrincipal)) {
         throw new \Exception("Unknown email address");
     }
     return $oPrincipalBackend->getPrincipalByPath($sPrincipal);
 }