/** * getDefaultId() - get default cache id * - use user id as default cache id * * @return string */ public function getDefaultId() { $result = NULL; if (Tinebase_Core::isRegistered(Tinebase_Core::USER)) { $result = Tinebase_Core::getUser()->getId(); } return $result; }
/** * returns registry data of PersistentFilter. * * @return array */ public static function getAllPersistentFilters() { if (Tinebase_Core::isRegistered(Tinebase_Core::USER)) { $obj = new Tinebase_Frontend_Json_PersistentFilter(); // return only filters of activated apps $applicationIds = Tinebase_Application::getInstance()->getApplicationsByState(Tinebase_Application::ENABLED)->getArrayOfIds(); return $obj->searchPersistentFilter(array(array('field' => 'account_id', 'operator' => 'equals', 'value' => Tinebase_Core::getUser()->getId()), array('field' => 'application_id', 'operator' => 'in', 'value' => $applicationIds)), NULL); } }
/** * returns registry data of PersistentFilter. * * @return array */ public static function getAllPersistentFilters() { if (Tinebase_Core::isRegistered(Tinebase_Core::USER)) { $obj = new Tinebase_Frontend_Json_PersistentFilter(); // return only filters of activated apps $applicationIds = Tinebase_Application::getInstance()->getApplicationsByState(Tinebase_Application::ENABLED)->getArrayOfIds(); $filterArray = array(array('field' => 'account_id', 'operator' => 'equals', 'value' => Tinebase_Core::getUser()->getId()), array('field' => 'application_id', 'operator' => 'in', 'value' => $applicationIds)); if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Fetching all filters of user ' . Tinebase_Core::getUser()->accountLoginName); } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($filterArray, true)); } return $obj->searchPersistentFilter($filterArray, NULL); } return array(); }
/** * Returns registry data of tinebase. * @see Tinebase_Application_Json_Abstract * * @return mixed array 'variable name' => 'data' */ public function getRegistryData() { $locale = Tinebase_Core::get('locale'); $tbFrontendHttp = new Tinebase_Frontend_Http(); // default credentials if (isset(Tinebase_Core::getConfig()->login)) { $loginConfig = Tinebase_Core::getConfig()->login; $defaultUsername = isset($loginConfig->username) ? $loginConfig->username : ''; $defaultPassword = isset($loginConfig->password) ? $loginConfig->password : ''; } else { $defaultUsername = ''; $defaultPassword = ''; } $registryData = array('serviceMap' => $tbFrontendHttp->getServiceMap(), 'timeZone' => Tinebase_Core::get(Tinebase_Core::USERTIMEZONE), 'locale' => array('locale' => $locale->toString(), 'language' => Zend_Locale::getTranslation($locale->getLanguage(), 'language', $locale), 'region' => Zend_Locale::getTranslation($locale->getRegion(), 'country', $locale)), 'version' => array('buildType' => TINE20_BUILDTYPE, 'codeName' => TINE20_CODENAME, 'packageString' => TINE20_PACKAGESTRING, 'releaseTime' => TINE20_RELEASETIME, 'filesHash' => TINE20_BUILDTYPE != 'DEVELOPMENT' ? $tbFrontendHttp->getJsCssHash() : null), 'defaultUsername' => $defaultUsername, 'defaultPassword' => $defaultPassword, 'denySurveys' => Tinebase_Core::getConfig()->denySurveys, 'titlePostfix' => Tinebase_Config::getInstance()->getConfig(Tinebase_Model_Config::PAGETITLEPOSTFIX, NULL, '')->value, 'redirectUrl' => Tinebase_Config::getInstance()->getConfig(Tinebase_Model_Config::REDIRECTURL, NULL, '')->value, 'maxFileUploadSize' => convertToBytes(ini_get('upload_max_filesize')), 'maxPostSize' => convertToBytes(ini_get('post_max_size'))); if (Tinebase_Core::isRegistered(Tinebase_Core::USER)) { $user = Tinebase_Core::getUser(); $userContactArray = array(); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { try { $userContactArray = Addressbook_Controller_Contact::getInstance()->getContactByUserId($user->getId(), TRUE)->toArray(); } catch (Addressbook_Exception_NotFound $aenf) { if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' User not found in Addressbook: ' . $user->accountDisplayName); } } } $registryData += array('currentAccount' => $user->toArray(), 'userContact' => $userContactArray, 'accountBackend' => Tinebase_User::getConfiguredBackend(), 'jsonKey' => Tinebase_Core::get('jsonKey'), 'userApplications' => $user->getApplications()->toArray(), 'NoteTypes' => $this->getNoteTypes(), 'stateInfo' => Tinebase_State::getInstance()->loadStateInfo(), 'changepw' => Tinebase_User::getBackendConfiguration('changepw', true), 'mustchangepw' => $user->mustChangePassword(), 'mapPanel' => Tinebase_Config::getInstance()->getConfig(Tinebase_Config::MAPPANEL, NULL, TRUE)->value, 'confirmLogout' => Tinebase_Core::getPreference()->getValue(Tinebase_Preference::CONFIRM_LOGOUT, 1), 'persistentFilters' => Tinebase_Frontend_Json_PersistentFilter::getAllPersistentFilters(), 'messenger' => $this->getMessengerConfig()); } return $registryData; }
/** * Tine 2.0 main view * * @package Tinebase * @subpackage Views * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3 * @author Philipp Schuele <*****@*****.**> * @copyright Copyright (c) 2010 Metaways Infosystems GmbH (http://www.metaways.de) * * @todo check if build script puts the translation files in build dir $tineBuildPath */ echo "<!-- Tine 2.0 static files -->\n"; // this variable gets replaced by the buildscript $tineBuildPath = ''; $locale = Tinebase_Core::isRegistered(Tinebase_Core::LOCALE) ? Tinebase_Core::getLocale() : 'en'; switch (TINE20_BUILDTYPE) { case 'DEVELOPMENT': echo $this->jsb2tk->getHTML(); echo ' <script type="text/javascript" src="index.php?method=Tinebase.getJsTranslations&' . time() . '"></script>'; break; case 'DEBUG': case 'RELEASE': echo "\n <link rel='stylesheet' type='text/css' href='index.php?method=Tinebase.getCssFiles' />"; echo "\n <script type=\"text/javascript\" src=\"index.php?method=Tinebase.getJsFiles\"></script>"; echo "\n <script type=\"text/javascript\" src=\"index.php?method=Tinebase.getJsTranslations\"></script>"; break; } if (Tinebase_Core::getConfig()->customMainscreenHeaders) { echo "\n" . Tinebase_Core::getConfig()->customMainscreenHeaders; }
/** * logout user * * @return void */ public function logout() { if ($this->_writeAccessLog) { if (Tinebase_Core::isRegistered(Tinebase_Core::USER) && is_object(Tinebase_Core::getUser())) { Tinebase_AccessLog::getInstance()->setLogout(); } } }
/** * Returns registry data of tinebase. * @see Tinebase_Application_Json_Abstract * * @return mixed array 'variable name' => 'data' */ public function getRegistryData() { $registryData = $this->_getAnonymousRegistryData(); if (Tinebase_Core::isRegistered(Tinebase_Core::USER)) { $userRegistryData = $this->_getUserRegistryData(); $registryData += $userRegistryData; } return $registryData; }
/** * login from HTTP post * * redirects the tine main screen if authentication is successful * otherwise redirects back to login url */ public function loginFromPost($username, $password) { Tinebase_Core::startCoreSession(); if (!empty($username)) { // try to login user $success = Tinebase_Controller::getInstance()->login($username, $password, Tinebase_Core::get(Tinebase_Core::REQUEST), self::REQUEST_TYPE) === TRUE; } else { $success = FALSE; } if ($success === TRUE) { $this->_setJsonKeyCookie(); $ccAdapter = Tinebase_Auth_CredentialCache::getInstance()->getCacheAdapter(); if (Tinebase_Core::isRegistered(Tinebase_Core::USERCREDENTIALCACHE)) { $ccAdapter->setCache(Tinebase_Core::getUserCredentialCache()); } else { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Something went wrong with the CredentialCache / no CC registered.'); $success = FALSE; $ccAdapter->resetCache(); } } $request = new Sabre\HTTP\Request(); $redirectUrl = str_replace('index.php', '', $request->getAbsoluteUri()); // authentication failed if ($success !== TRUE) { $_SESSION = array(); Tinebase_Session::destroyAndRemoveCookie(); // redirect back to loginurl if needed $redirectUrl = Tinebase_Config::getInstance()->get(Tinebase_Config::REDIRECTURL, $redirectUrl); } // load the client with GET header('Location: ' . $redirectUrl); }
/** * set php memory (max) limit * * @param string $_limit * @return string old max memory limit */ public static function setMemoryLimit($_limit) { $oldMaxMemoryLimit = ini_get('memory_limit'); if (!empty($oldMaxMemoryLimit)) { if ((bool) ini_get('safe_mode') === true) { if (Tinebase_Core::isRegistered(self::LOGGER) && Tinebase_Core::isLogLevel(Zend_Log::WARN)) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' memory_limit(' . $oldMaxMemoryLimit . ') is too low. Can\'t set limit to ' . $_limit . ' because of safe mode restrictions.'); } } else { if (Tinebase_Core::isRegistered(self::LOGGER) && Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' setting memory limit to: ' . $_limit); } ini_set('memory_limit', $_limit); } } return $oldMaxMemoryLimit; }
/** * create account credentials and return new credentials id * * @param string $_username * @param string $_password * @return string */ protected function _createCredentials($_username = NULL, $_password = NULL, $_userCredentialCache = NULL) { if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { $message = 'Create new account credentials'; if ($_username !== NULL) { $message .= ' for username ' . $_username; } Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $message); } if (Tinebase_Core::isRegistered(Tinebase_Core::USERCREDENTIALCACHE)) { $userCredentialCache = Tinebase_Core::get(Tinebase_Core::USERCREDENTIALCACHE); Tinebase_Auth_CredentialCache::getInstance()->getCachedCredentials($userCredentialCache); } else { Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' Something went wrong with the CredentialsCache / use given username/password instead.'); $userCredentialCache = new Tinebase_Model_CredentialCache(array('username' => $_username, 'password' => $_password)); } $accountCredentials = Tinebase_Auth_CredentialCache::getInstance()->cacheCredentials($_username !== NULL ? $_username : $userCredentialCache->username, $_password !== NULL ? $_password : $userCredentialCache->password, $userCredentialCache->password); return $accountCredentials->getId(); }
/** * login from HTTP post * * renders the tine main screen if authentication is successfull * otherwise redirects back to login url */ public function loginFromPost($username, $password) { if (!empty($username)) { # removed this line on 09-06-2010 Lars #Tinebase_Config::getInstance()->getConfig(Tinebase_Config::USERBACKEND, null, $_SERVER["HTTP_REFERER"])->value; // try to login user $success = Tinebase_Controller::getInstance()->login($username, $password, $_SERVER['REMOTE_ADDR'], 'TineHttpPost') === TRUE; } else { $success = FALSE; } if ($success === TRUE) { $ccAdapter = Tinebase_Auth_CredentialCache::getInstance()->getCacheAdapter(); if (Tinebase_Core::isRegistered(Tinebase_Core::USERCREDENTIALCACHE)) { $ccAdapter->setCache(Tinebase_Core::get(Tinebase_Core::USERCREDENTIALCACHE)); } else { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Something went wrong with the CredentialCache / no CC registered.'); $success = FALSE; $ccAdapter->resetCache(); } } // authentication failed // redirect back to loginurl if ($success !== TRUE) { $defaultUrl = array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : ''; $redirectUrl = Tinebase_Config::getInstance()->getConfig(Tinebase_Config::REDIRECTURL, NULL, $defaultUrl)->value; if (!empty($redirectUrl)) { header('Location: ' . $redirectUrl); } return; } $this->_renderMainScreen(); }
public static function userIsRegistered() { return Tinebase_Core::isRegistered(Tinebase_Core::USER) && is_object(Tinebase_Core::getUser()); }
/** * set php execution life (max) time * * @param int $_seconds * @return int old max exexcution time in seconds */ public static function setExecutionLifeTime($_seconds) { $oldMaxExcecutionTime = ini_get('max_execution_time'); if ($oldMaxExcecutionTime > 0) { if ((bool) ini_get('safe_mode') === true) { if (Tinebase_Core::isRegistered(self::LOGGER) && Tinebase_Core::isLogLevel(Zend_Log::WARN)) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' max_execution_time(' . $oldMaxExcecutionTime . ') is too low. Can\'t set limit to ' . $_seconds . ' because of safe mode restrictions.'); } } else { if (Tinebase_Core::isRegistered(self::LOGGER) && Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' setting execution life time to: ' . $_seconds); } set_time_limit($_seconds); } } return $oldMaxExcecutionTime; }
/** * destroy session * * @return void */ public function logout($_ipAddress) { if (Tinebase_Core::isRegistered(Tinebase_Core::USER)) { $currentAccount = Tinebase_Core::getUser(); if (is_object($currentAccount)) { Tinebase_AccessLog::getInstance()->setLogout(session_id(), $_ipAddress); } } Zend_Session::destroy(); }
/** * check json key * * @param string $method * @param string $jsonKey */ protected function _checkJsonKey($method, $jsonKey) { $anonymnousMethods = array('', 'Tinebase.getRegistryData', 'Tinebase.getAllRegistryData', 'Tinebase.authenticate', 'Tinebase.login', 'Tinebase.getAvailableTranslations', 'Tinebase.getTranslations', 'Tinebase.setLocale'); // check json key for all methods but some exceptions if (!in_array($method, $anonymnousMethods) && $jsonKey !== Tinebase_Core::get('jsonKey')) { if (!Tinebase_Core::isRegistered(Tinebase_Core::USER)) { Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . ' Attempt to request a privileged Json-API method (' . $method . ') without authorisation from "' . $_SERVER['REMOTE_ADDR'] . '". (session timeout?)'); } else { Tinebase_Core::getLogger()->WARN(__METHOD__ . '::' . __LINE__ . ' Fatal: got wrong json key! (' . $jsonKey . ') Possible CSRF attempt!' . ' affected account: ' . print_r(Tinebase_Core::getUser()->toArray(), true) . ' request: ' . print_r($_REQUEST, true)); } throw new Tinebase_Exception_AccessDenied('Not Authorised', 401); } }
<?php /** * Tine 2.0 * * @package tests * @subpackage test root * @license http://www.gnu.org/licenses/agpl.html AGPL3 * @copyright Copyright (c) 2008 Metaways Infosystems GmbH (http://www.metaways.de) * @author Matthias Greiling <*****@*****.**> */ // only bootstrap once if (!Tinebase_Core::isRegistered('frameworkInitialized') || Tinebase_Core::get('frameworkInitialized') == false) { Tinebase_Session_Abstract::setSessionEnabled('TINE20SESSID'); TestServer::getInstance()->initFramework(); TestServer::getInstance()->login(); // do this after login because we need the current user TestServer::getInstance()->initTestUsers(); TestServer::getInstance()->setTestUserEmail(); // speed up tests by disabling calendar notifications Calendar_Controller_Event::getInstance()->sendNotifications(false); }