public function getTenantsMan() { if ($this->oApiTenants === null) { $this->oApiTenants = \CApi::GetSystemManager('tenants'); } return $this->oApiTenants; }
public function getUsersManager() { if (!isset($this->oApiUsersManager)) { $this->oApiUsersManager = \CApi::GetSystemManager('users'); } return $this->oApiUsersManager; }
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; }
/** * @return int */ public function GetCurrentNumberOfUsers() { static $iCache = null; if (null === $iCache) { /* @var $oApiUsersManager CApiUsersManager */ $oApiUsersManager = CApi::GetSystemManager('users'); $iCache = $oApiUsersManager->getTotalUsersCount(); } return $iCache; }
public static function getTenantUser($oAccount) { $sEmail = 'default_' . Constants::DAV_TENANT_PRINCIPAL; if ($oAccount->IdTenant > 0) { $oApiTenantsMan = \CApi::GetSystemManager('tenants'); $oTenant = $oApiTenantsMan ? $oApiTenantsMan->getTenantById($oAccount->IdTenant) : null; if ($oTenant) { $sEmail = $oTenant->Login . '_' . Constants::DAV_TENANT_PRINCIPAL; } } return $sEmail; }
public function getChildForPrincipal(array $aPrincipal) { /* @var \CApiCapabilityManager */ $oApiCapabilityManager = \CApi::GetSystemManager('capability'); // $oAccount = $this->getAccount($aPrincipal['uri']); $bEmpty = false; /*!($oAccount instanceof \CAccount && $oApiCapabilityManager->isPersonalContactsSupported($oAccount));*/ $oAddressBookHome = new AddressBookHome($this->carddavBackend, $aPrincipal['uri']); $oAddressBookHome->setEmpty($bEmpty); return $oAddressBookHome; }
public static function Login($sUserName, $sPassword) { $mResult = false; $aArguments = array('Login' => $sUserName, 'Password' => $sPassword, 'SignMe' => false); \CApi::GetModuleManager()->broadcastEvent('Dav', 'Login', $aArguments, $mResult); if (isset($mResult['id'])) { $oManagerApi = \CApi::GetSystemManager('eav', 'db'); $oEntity = $oManagerApi->getEntityById((int) $mResult['id']); $mResult = $oEntity->sUUID; } else { $mResult = false; } return $mResult; }
/** * 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; }
public function __construct() { $bErrorCreateDir = false; /* Public files folder */ $publicDir = \CApi::DataPath() . Constants::FILESTORAGE_PATH_ROOT; if (!file_exists($publicDir)) { if (!@mkdir($publicDir)) { $bErrorCreateDir = true; } } $publicDir .= Constants::FILESTORAGE_PATH_CORPORATE; if (!file_exists($publicDir)) { if (!@mkdir($publicDir)) { $bErrorCreateDir = true; } } $personalDir = \CApi::DataPath() . Constants::FILESTORAGE_PATH_ROOT . Constants::FILESTORAGE_PATH_PERSONAL; if (!file_exists($personalDir)) { if (!@mkdir($personalDir)) { $bErrorCreateDir = true; } } $sharedDir = \CApi::DataPath() . Constants::FILESTORAGE_PATH_ROOT . Constants::FILESTORAGE_PATH_SHARED; if (!file_exists($sharedDir)) { if (!@mkdir($sharedDir)) { $bErrorCreateDir = true; } } if ($bErrorCreateDir) { throw new \Sabre\DAV\Exception('Can\'t create directory in ' . \CApi::DataPath() . Constants::FILESTORAGE_PATH_ROOT, 500); } $this->aTree = array(new RootPersonal($personalDir)); $oApiCapaManager = \CApi::GetSystemManager('capability'); if ($oApiCapaManager->isCollaborationSupported()) { array_push($this->aTree, new RootPublic($publicDir)); } if (\CApi::GetConf('labs.files-sharing', false)) { array_push($this->aTree, new RootShared($sharedDir)); } }
/** * @return array */ public function getChildren() { $oAccount = $this->getUser(); $aCards = array(); $oApiCapabilityManager = \CApi::GetSystemManager('capability'); if ($oAccount instanceof \CAccount && $oApiCapabilityManager->isGlobalContactsSupported($oAccount)) { $aContacts = array(); $oContactsModule = \CApi::GetModule('Contacts'); if ($oContactsModule instanceof \AApiModule) { $oGlobalContactManager = $oContactsModule->GetManager('global'); if ($oGlobalContactManager) { $aContacts = $oGlobalContactManager->getContactItems($oAccount, \EContactSortField::EMail, \ESortOrder::ASC, 0, 9999); } } foreach ($aContacts as $oContact) { $sUID = md5($oContact->Email . '-' . $oContact->Id); $vCard = new \Sabre\VObject\Component\VCard(array('VERSION' => '3.0', 'UID' => $sUID, 'FN' => $oContact->Name)); $vCard->add('EMAIL', $oContact->Email, array('type' => array('work'), 'pref' => 1)); $aCards[] = new Card(array('uri' => $sUID . '.vcf', 'carddata' => $vCard->serialize(), 'lastmodified' => $oContact->DateModified)); } } return $aCards; }
/** * Returns a list of addressbooks * * @return array */ public function getChildren() { $objs = array(); if ($this->isEmpty) { return $objs; } /* @var $oApiCapaManager \CApiCapabilityManager */ $oApiCapaManager = \CApi::GetSystemManager('capability'); $aAddressbooks = $this->carddavBackend->getAddressbooksForUser($this->principalUri); if (count($aAddressbooks) === 0) { $this->carddavBackend->createAddressBook($this->principalUri, \Afterlogic\DAV\Constants::ADDRESSBOOK_DEFAULT_NAME, ['{DAV:}displayname' => \Afterlogic\DAV\Constants::ADDRESSBOOK_DEFAULT_DISPLAY_NAME]); $this->carddavBackend->createAddressBook($this->principalUri, \Afterlogic\DAV\Constants::ADDRESSBOOK_COLLECTED_NAME, ['{DAV:}displayname' => \Afterlogic\DAV\Constants::ADDRESSBOOK_COLLECTED_DISPLAY_NAME]); $aAddressbooks = $this->carddavBackend->getAddressbooksForUser($this->principalUri); } foreach ($aAddressbooks as $addressbook) { $objs[] = new AddressBook($this->carddavBackend, $addressbook); } if ($oApiCapaManager->isCollaborationSupported()) { $sharedAddressbook = $this->carddavBackend->getSharedAddressBook($this->principalUri); $objs[] = new Shared\AddressBook($this->carddavBackend, $sharedAddressbook, $this->principalUri); } return $objs; }
/** * * @param \AEntity $oEntity */ public function updateEnabledForEntity(&$oEntity, $bEnabled = true) { $oEavManager = \CApi::GetSystemManager('eav'); if ($oEavManager) { $sDisabledModules = isset($oEntity->{'@DisabledModules'}) ? $oEntity->{'@DisabledModules'} : ''; $aDisabledModules = !empty(trim($sDisabledModules)) ? array($sDisabledModules) : array(); if ($i = substr_count($sDisabledModules, "|")) { $aDisabledModules = explode("|", $sDisabledModules); } if ($bEnabled) { if (in_array($this->GetName(), $aDisabledModules)) { $aDisabledModules = array_diff($aDisabledModules, array($this->GetName())); } } else { if (!in_array($this->GetName(), $aDisabledModules)) { $aDisabledModules[] = $this->GetName(); } } $sDisabledModules = implode('|', $aDisabledModules); $oEntity->{'@DisabledModules'} = $sDisabledModules; $oEavManager->setAttributes(array($oEntity->iId), array(new \CAttribute('@DisabledModules', $sDisabledModules, 'string'))); } }
/** * 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; }
public function __construct($baseUri = '/') { $this->debugExceptions = true; self::$exposeVersion = false; $this->setBaseUri($baseUri); date_default_timezone_set('GMT'); if (\CApi::GetPDO()) { /* Authentication Plugin */ $this->addPlugin(new \Afterlogic\DAV\Auth\Plugin(Backend::Auth(), 'SabreDAV')); /* Logs Plugin */ // $this->addPlugin(new Logs\Plugin()); /* DAV ACL Plugin */ $aclPlugin = new \Sabre\DAVACL\Plugin(); $aclPlugin->hideNodesFromListings = true; $aclPlugin->defaultUsernamePath = Constants::PRINCIPALS_PREFIX; $mAdminPrincipal = \CApi::GetConf('labs.dav.admin-principal', false); $aclPlugin->adminPrincipals = $mAdminPrincipal !== false ? array(Constants::PRINCIPALS_PREFIX . '/' . $mAdminPrincipal) : array(); $this->addPlugin($aclPlugin); $bIsOwncloud = false; /* Directory tree */ $aTree = array($bIsOwncloud ? new CardDAV\AddressBookRoot(Backend::Principal(), Backend::getBackend('carddav-owncloud')) : new CardDAV\AddressBookRoot(Backend::Principal(), Backend::Carddav()), new CalDAV\CalendarRoot(Backend::Principal(), Backend::Caldav()), new CardDAV\GAB\AddressBooks('gab', Constants::GLOBAL_CONTACTS)); $this->oApiCapaManager = \CApi::GetSystemManager('capability'); /* Files folder */ if ($this->oApiCapaManager->isFilesSupported()) { array_push($aTree, new \Afterlogic\DAV\FS\FilesRoot()); $this->addPlugin(new FS\Plugin()); // Automatically guess (some) contenttypes, based on extesion $this->addPlugin(new \Sabre\DAV\Browser\GuessContentType()); } $oPrincipalColl = new \Sabre\DAVACL\PrincipalCollection(Backend::Principal()); // $oPrincipalColl->disableListing = true; array_push($aTree, $oPrincipalColl); /* Initializing server */ parent::__construct($aTree); $this->httpResponse->setHeader("X-Server", Constants::DAV_SERVER_NAME); /* Reminders Plugin */ $this->addPlugin(new Reminders\Plugin(Backend::Reminders())); $this->addPlugin(new \Sabre\CalDAV\Schedule\Plugin()); $this->addPlugin(new \Sabre\CalDAV\Schedule\IMipPlugin('*****@*****.**')); /* Contacts Plugin */ $this->addPlugin(new Contacts\Plugin()); // if ($this->oApiCapaManager->isMobileSyncSupported()) { /* CalDAV Plugin */ $this->addPlugin(new \Sabre\CalDAV\Plugin()); /* CardDAV Plugin */ $this->addPlugin(new \Sabre\CardDAV\Plugin()); /* ICS Export Plugin */ $this->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); /* VCF Export Plugin */ $this->addPlugin(new \Sabre\CardDAV\VCFExportPlugin()); // } /* Calendar Sharing Plugin */ $this->addPlugin(new \Sabre\CalDAV\SharingPlugin()); /* DAV Sync Plugin */ $this->addPlugin(new \Sabre\DAV\Sync\Plugin()); /* HTML Frontend Plugin */ if (\CApi::GetConf('labs.dav.use-browser-plugin', false) !== false) { $this->addPlugin(new \Sabre\DAV\Browser\Plugin()); } /* Locks Plugin */ // $this->addPlugin(new \Sabre\DAV\Locks\Plugin()); $this->on('beforeGetProperties', array($this, 'beforeGetProperties'), 90); } }
public static function getAuthenticatedUser($iUserId = '') { static $oUser = null; if ($oUser === null) { if (!empty($iUserId)) { \CApi::getAuthenticatedUserId($iUserId); // called for saving in session } else { if (!empty(self::$aUserSession['UserId'])) { $iUserId = self::$aUserSession['UserId']; } } $oApiIntegrator = \CApi::GetSystemManager('integrator'); if ($oApiIntegrator) { $oUser = $oApiIntegrator->getAuthenticatedUserByIdHelper($iUserId); } } return $oUser; }
/** * @return array */ public function getThemeAndLanguage() { static $sLanguage = false; static $sTheme = false; static $sSiteName = false; if (false === $sLanguage && false === $sTheme && false === $sSiteName) { $oSettings =& CApi::GetSettings(); $sSiteName = $oSettings->GetConf('SiteName'); $sLanguage = $oSettings->GetConf('DefaultLanguage'); $sTheme = $oSettings->GetConf('DefaultSkin'); $oUser = \CApi::getAuthenticatedUser(); if ($oUser) { $sSiteName = ''; } else { } $sLanguage = $this->validatedLanguageValue($sLanguage); $this->setLoginLanguage($sLanguage); // todo: sash $sTheme = $this->validatedThemeValue($sTheme); } /*** temporary fix to the problems in mobile version in rtl mode ***/ /* @var $oApiCapability \CApiCapabilityManager */ $oApiCapability = \CApi::GetSystemManager('capability'); if (in_array($sLanguage, array('Arabic', 'Hebrew', 'Persian')) && $oApiCapability && $oApiCapability->isNotLite() && 1 === $this->isMobile()) { $sLanguage = 'English'; } /*** end of temporary fix to the problems in mobile version in rtl mode ***/ return array($sLanguage, $sTheme, $sSiteName); }
public static function GetThumbResource($oAccount, $rResource, $sFileName, $bShow = true) { $sMd5Hash = md5(rand(1000, 9999)); $oApiFileCache = \CApi::GetSystemManager('filecache'); $oApiFileCache->putFile($oAccount, 'Raw/Thumbnail/' . $sMd5Hash, $rResource, '_' . $sFileName); if ($oApiFileCache->isFileExists($oAccount, 'Raw/Thumbnail/' . $sMd5Hash, '_' . $sFileName)) { try { $oThumb = new \PHPThumb\GD($oApiFileCache->generateFullFilePath($oAccount, 'Raw/Thumbnail/' . $sMd5Hash, '_' . $sFileName)); if ($bShow) { $oThumb->adaptiveResize(120, 100)->show(); } else { return $oThumb->adaptiveResize(120, 100)->getImageAsString(); } } catch (\Exception $oE) { } } $oApiFileCache->clear($oAccount, 'Raw/Thumbnail/' . $sMd5Hash, '_' . $sFileName); }
/** * @param int $iIdTenant * @return CTenant */ private function _getCachedTenant($iIdTenant) { static $aCache = array(); $oTenant = null; if (isset($aCache[$iIdTenant])) { $oTenant = $aCache[$iIdTenant]; } else { $oApiTenants = CApi::GetSystemManager('tenants'); if ($oApiTenants) { $oTenant = 0 < $iIdTenant ? $oApiTenants->getTenantById($iIdTenant) : $oApiTenants->getDefaultGlobalTenant(); } } if ($oTenant && !isset($aCache[$iIdTenant])) { $aCache[$iIdTenant] = $oTenant; } return $oTenant; }
/** * This method is used to search for principals matching a set of * properties. * * This search is specifically used by RFC3744's principal-property-search * REPORT. * * The actual search should be a unicode-non-case-sensitive search. The * keys in searchProperties are the WebDAV property names, while the values * are the property values to search on. * * By default, if multiple properties are submitted to this method, the * various properties should be combined with 'AND'. If $test is set to * 'anyof', it should be combined using 'OR'. * * This method should simply return an array with full principal uri's. * * If somebody attempted to search on a property the backend does not * support, you should simply return 0 results. * * You can also just return 0 results if you choose to not support * searching at all, but keep in mind that this may stop certain features * from working. * * @param string $prefixPath * @param array $searchProperties * @param string $test * @return array */ function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { $aPrincipals = []; if (isset($searchProperties['{http://sabredav.org/ns}email-address'])) { $oUsersManager = \CApi::GetSystemManager('users'); $oAccount = $oUsersManager->getAccountByEmail($searchProperties['{http://sabredav.org/ns}email-address']); if ($oAccount instanceof \CAccount) { $aPrincipals[] = \Afterlogic\DAV\Constants::PRINCIPALS_PREFIX . '/' . $oAccount->Email; } } return $aPrincipals; }
/** * @param string $sHelpdeskHash = '' * @param string $sCalendarPubHash = '' * @param string $sFileStoragePubHash = '' * @return string */ private function generateHTML() { $sResult = ''; $oApiIntegrator = \CApi::GetSystemManager('integrator'); if ($oApiIntegrator) { $sModuleHash = ''; $aArgs = array(); $this->oModuleManager->broadcastEvent('System', 'GenerateHTML', $aArgs, $sModuleHash); @\header('Content-Type: text/html; charset=utf-8', true); $sUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; if (!strpos(strtolower($sUserAgent), 'firefox')) { @\header('Last-Modified: ' . \gmdate('D, d M Y H:i:s') . ' GMT'); } if (\CApi::GetConf('labs.cache-ctrl', true) && isset($_COOKIE['aft-cache-ctrl'])) { setcookie('aft-cache-ctrl', '', time() - 3600); \MailSo\Base\Http::SingletonInstance()->StatusHeader(304); exit; } $oCoreWebclientModule = \CApi::GetModule('CoreWebclient'); if ($oCoreWebclientModule instanceof \AApiModule) { $sResult = file_get_contents($oCoreWebclientModule->GetPath() . '/templates/Index.html'); if (is_string($sResult)) { $sFrameOptions = \CApi::GetConf('labs.x-frame-options', ''); if (0 < \strlen($sFrameOptions)) { @\header('X-Frame-Options: ' . $sFrameOptions); } $sResult = strtr($sResult, array('{{AppVersion}}' => AURORA_APP_VERSION, '{{IntegratorDir}}' => $oApiIntegrator->isRtl() ? 'rtl' : 'ltr', '{{IntegratorLinks}}' => $oApiIntegrator->buildHeadersLink(), '{{IntegratorBody}}' => $oApiIntegrator->buildBody($sModuleHash))); } } } return $sResult; }
/** * @return \CHelpdeskUser|null */ public static function GetHelpdeskAccount($iTenantID) { $oResult = null; $oApiCapability = \CApi::GetSystemManager('capability'); if ($oApiCapability->isHelpdeskSupported()) { $oApiIntegrator = \CApi::GetSystemManager('integrator'); $iIdHelpdeskUser = $oApiIntegrator->getAuthenticatedHelpdeskUserId(); if (0 < $iIdHelpdeskUser) { $oApiHelpdesk = \CApi::Manager('helpdesk'); $oHelpdeskUser = $oApiHelpdesk->getUserById($iTenantID, $iIdHelpdeskUser); $oResult = $oHelpdeskUser instanceof \CHelpdeskUser ? $oHelpdeskUser : null; } } return $oResult; }