2 namespace TYPO3\CMS\Install\Service;
68 $this->typo3tempPath = PATH_site .
'typo3temp/';
72 session_set_save_handler(array($this,
'open'), array($this,
'close'), array($this,
'read'), array($this,
'write'), array($this,
'destroy'), array($this,
'gc'));
73 session_save_path($sessionSavePath);
74 session_name($this->cookieName);
77 ini_set(
'session.gc_probability', 100);
78 ini_set(
'session.gc_divisor', 100);
79 ini_set(
'session.gc_maxlifetime', $this->expireTimeInMinutes * 2 * 60);
80 if (\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSessionAutoStartEnabled()) {
81 $sessionCreationError =
'Error: session.auto-start is enabled.<br />';
82 $sessionCreationError .=
'The PHP option session.auto-start is enabled. Disable this option in php.ini or .htaccess:<br />';
83 $sessionCreationError .=
'<pre>php_value session.auto_start Off</pre>';
84 throw new \TYPO3\CMS\Install\Exception($sessionCreationError, 1294587485);
85 }
elseif (defined(
'SID')) {
86 $sessionCreationError =
'Session already started by session_start().<br />';
87 $sessionCreationError .=
'Make sure no installed extension is starting a session in its ext_localconf.php or ext_tables.php.';
88 throw new \TYPO3\CMS\Install\Exception($sessionCreationError, 1294587486);
101 if (empty(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'encryptionKey'])) {
102 throw new \TYPO3\CMS\Install\Exception(
103 'No encryption key set to secure session',
107 $sessionSavePath = sprintf(
108 $this->typo3tempPath . $this->sessionPath,
112 return $sessionSavePath;
124 if (!is_dir($sessionSavePath)) {
127 }
catch (\RuntimeException $exception) {
128 throw new \TYPO3\CMS\Install\Exception(
129 'Could not create session folder in typo3temp/. Make sure it is writeable!',
135 <IfModule !mod_authz_core.c>
142 <IfModule mod_authz_core.c>
147 $indexContent =
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">';
148 $indexContent .=
'<HTML><HEAD<TITLE></TITLE><META http-equiv=Refresh Content="0; Url=../../">';
149 $indexContent .=
'</HEAD></HTML>';
161 $_SESSION[
'active'] =
true;
180 $_SESSION[
'active'] =
false;
190 session_regenerate_id();
201 return ($_SESSION[
'active'] ===
true);
224 if (empty(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'encryptionKey'])) {
225 throw new \TYPO3\CMS\Install\Exception(
226 'No encryption key set to secure session',
233 return md5(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'encryptionKey'] .
'|' . $sessionId);
246 $_SESSION[
'authorized'] =
true;
247 $_SESSION[
'lastSessionId'] = time();
248 $_SESSION[
'tstamp'] = time();
249 $_SESSION[
'expires'] = time() + $this->expireTimeInMinutes * 60;
261 if (!$_SESSION[
'authorized']) {
264 if ($_SESSION[
'expires'] < time()) {
280 if (!$_SESSION[
'authorized']) {
284 if ($_SESSION[
'expires'] < time()) {
300 $_SESSION[
'tstamp'] = time();
301 $_SESSION[
'expires'] = time() + $this->expireTimeInMinutes * 60;
302 if (time() > $_SESSION[
'lastSessionId'] + $this->regenerateSessionIdTime * 60) {
304 $_SESSION[
'lastSessionId'] = time();
317 if (!is_array($_SESSION[
'messages'])) {
318 $_SESSION[
'messages'] = array();
320 $_SESSION[
'messages'][] = $message;
331 if (is_array($_SESSION[
'messages'])) {
332 $messages = $_SESSION[
'messages'];
334 $_SESSION[
'messages'] = array();
363 public function open($savePath, $sessionName)
387 $content = (string)(@file_get_contents($sessionFile));
391 $this->
write($id, $content);
403 public function write($id, $sessionData)
409 'Session file not writable. Please check permission on typo3temp/InstallToolSessions and its subdirectories.',
425 return @unlink($sessionFile);
434 public function gc($maxLifeTime)
437 $files = glob($sessionSavePath .
'/hash_*');
438 if (!is_array($files)) {
442 if (filemtime($filename) + $this->expireTimeInMinutes * 60 < time()) {
464 session_write_close();