* Added Bernhard Krafts security improvement for server validated challenge value.
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_userauth.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Contains a base class for authentication of users in TYPO3, both frontend and backend.
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
32 *
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 89: class t3lib_userAuth
41 * 159: function start()
42 * 261: function check_authentication()
43 * 413: function redirect()
44 * 426: function logoff()
45 * 441: function gc()
46 * 455: function user_where_clause()
47 * 469: function ipLockClause()
48 * 487: function ipLockClause_remoteIPNumber($parts)
49 * 508: function hashLockClause()
50 * 519: function hashLockClause_getHashInt()
51 * 535: function writeUC($variable='')
52 * 558: function writelog($type,$action,$error,$details_nr,$details,$data,$tablename,$recuid,$recpid)
53 * 567: function checkLogFailures()
54 * 576: function unpack_uc($theUC='')
55 * 592: function pushModuleData($module,$data,$noSave=0)
56 * 605: function getModuleData($module,$type='')
57 * 618: function getSessionData($key)
58 * 631: function setAndSaveSessionData($key,$data)
59 * 650: function setBeUserByUid($uid)
60 * 663: function setBeUserByName($name)
61 *
62 * TOTAL FUNCTIONS: 20
63 * (This index is automatically created/updated by the extension "extdeveval")
64 *
65 */
66
67
68
69
70
71
72
73
74
75
76
77 /**
78 * Authentication of users in TYPO3
79 *
80 * This class is used to authenticate a login user.
81 * The class is used by both the frontend and backend. In both cases this class is a parent class to beuserauth and feuserauth
82 *
83 * See Inside TYPO3 for more information about the API of the class and internal variables.
84 *
85 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
86 * @package TYPO3
87 * @subpackage t3lib
88 */
89 class t3lib_userAuth {
90 var $global_database = ''; // Which global database to connect to
91 var $session_table = ''; // Table to use for session data.
92 var $name = ''; // Session/Cookie name
93 var $get_name = ''; // Session/GET-var name
94
95 var $user_table = ''; // Table in database with userdata
96 var $username_column = ''; // Column for login-name
97 var $userident_column = ''; // Column for password
98 var $userid_column = ''; // Column for user-id
99 var $lastLogin_column = '';
100
101 var $enablecolumns = Array (
102 'rootLevel' => '', // Boolean: If true, 'AND pid=0' will be a part of the query...
103 'disabled' => '',
104 'starttime' => '',
105 'endtime' => '',
106 'deleted' => ''
107 );
108
109 var $formfield_uname = ''; // formfield with login-name
110 var $formfield_uident = ''; // formfield with password
111 var $formfield_chalvalue = ''; // formfield with a unique value which is used to encrypt the password and username
112 var $formfield_status = ''; // formfield with status: *'login', 'logout'. If empty login is not verified.
113 var $security_level = ''; // sets the level of security. *'normal' = clear-text. 'challenged' = hashed password/username from form in $formfield_uident. 'superchallenged' = hashed password hashed again with username.
114
115 var $auth_include = ''; // this is the name of the include-file containing the login form. If not set, login CAN be anonymous. If set login IS needed.
116
117 var $auth_timeout_field = 0; // if > 0 : session-timeout in seconds. if string: The string is fieldname from the usertable where the timeout can be found.
118 var $lifetime = 0; // 0 = Session-cookies. If session-cookies, the browser will stop session when the browser is closed. Else it keeps the session for $lifetime seconds.
119 var $gc_time = 24; // GarbageCollection. Purge all session data older than $gc_time hours.
120 var $gc_probability = 1; // Possibility (in percent) for GarbageCollection to be run.
121 var $writeStdLog = 0; // Decides if the writelog() function is called at login and logout
122 var $writeAttemptLog = 0; // If the writelog() functions is called if a login-attempt has be tried without success
123 var $sendNoCacheHeaders = 1; // If this is set, headers is sent to assure, caching is NOT done
124 var $getFallBack = 0; // If this is set, authentication is also accepted by the $_GET. Notice that the identification is NOT 128bit MD5 hash but reduced. This is done in order to minimize the size for mobile-devices, such as WAP-phones
125 var $hash_length = 32; // The ident-hash is normally 32 characters and should be! But if you are making sites for WAP-devices og other lowbandwidth stuff, you may shorten the length. Never let this value drop below 6. A length of 6 would give you more than 16 mio possibilities.
126 var $getMethodEnabled = 0; // Setting this flag true lets user-authetication happen from GET_VARS if POST_VARS are not set. Thus you may supply username/password from the URL.
127 var $lockIP = 4; // If set, will lock the session to the users IP address (all four numbers. Reducing to 1-3 means that only first, second or third part of the IP address is used).
128 var $lockHashKeyWords = 'useragent'; // Keyword list (commalist with no spaces!): "useragent". Each keyword indicates some information that can be included in a integer hash made to lock down usersessions.
129
130 var $warningEmail = ''; // warning -emailaddress:
131 var $warningPeriod = 3600; // Period back in time (in seconds) in which number of failed logins are collected
132 var $warningMax = 3; // The maximum accepted number of warnings before an email is sent
133 var $checkPid=1; // If set, the user-record must $checkPid_value as pid
134 var $checkPid_value=0; // The pid, the user-record must have as page-id
135
136 // Internals
137 var $id; // Internal: Will contain session_id (MD5-hash)
138 var $cookieId; // Internal: Will contain the session_id gotten from cookie or GET method. This is used in statistics as a reliable cookie (one which is known to come from $_COOKIE).
139 var $loginSessionStarted = 0; // Will be set to 1 if the login session is actually written during auth-check.
140
141 var $user; // Internal: Will contain user- AND session-data from database (joined tables)
142 var $get_URL_ID = ''; // Internal: Will will be set to the url--ready (eg. '&login=ab7ef8d...') GET-auth-var if getFallBack is true. Should be inserted in links!
143
144 var $forceSetCookie=0; // Will force the session cookie to be set everytime (lifetime must be 0)
145 var $dontSetCookie=0; // Will prevent the setting of the session cookie (takes precedence over forceSetCookie)
146 var $challengeStoredInCookie=0; // If set, the challenge value will be stored in a session as well so the server can check that is was not forged.
147
148
149 /**
150 * Starts a user session
151 * Typical configurations will:
152 * a) check if session cookie was set and if not, set one,
153 * b) check if a password/username was sent and if so, try to authenticate the user
154 * c) Lookup a session attached to a user and check timeout etc.
155 * d) Garbage collection, setting of no-cache headers.
156 * If a user is authenticated the database record of the user (array) will be set in the ->user internal variable.
157 *
158 * @return void
159 */
160 function start() {
161
162 // Init vars.
163 $mode='';
164 $new_id = false; // Default: not a new session
165 $id = isset($_COOKIE[$this->name]) ? stripslashes($_COOKIE[$this->name]) : ''; // $id is set to ses_id if cookie is present. Else set to false, which will start a new session
166 $this->hash_length = t3lib_div::intInRange($this->hash_length,6,32);
167
168 // If fallback to get mode....
169 if (!$id && $this->getFallBack && $this->get_name) {
170 $id = isset($_GET[$this->get_name]) ? t3lib_div::_GET($this->get_name) : '';
171 if (strlen($id)!=$this->hash_length) $id='';
172 $mode='get';
173 }
174 $this->cookieId = $id;
175
176 if (!$id) { // If new session...
177 $id = substr(md5(uniqid('')),0,$this->hash_length); // New random session-$id is made
178 $new_id = true; // New session
179 }
180 // Internal var 'id' is set
181 $this->id = $id;
182 if ($mode=='get' && $this->getFallBack && $this->get_name) { // If fallback to get mode....
183 $this->get_URL_ID = '&'.$this->get_name.'='.$id;
184 }
185 $this->user = ''; // Make certain that NO user is set initially
186
187 // Setting cookies
188 if (($new_id || $this->forceSetCookie) && $this->lifetime==0 ) { // If new session and the cookie is a sessioncookie, we need to set it only once!
189 if (!$this->dontSetCookie) SetCookie($this->name, $id, 0, '/'); // Cookie is set
190 }
191 if ($this->lifetime > 0) { // If it is NOT a session-cookie, we need to refresh it.
192 if (!$this->dontSetCookie) SetCookie($this->name, $id, time()+$this->lifetime, '/');
193 }
194
195 // Check to see if anyone has submitted login-information and if so register the user with the session. $this->user[uid] may be used to write log...
196 if ($this->formfield_status) {
197 $this->check_authentication();
198 }
199 unset($this->user); // Make certain that NO user is set initially. ->check_authentication may have set a session-record which will provide us with a user record in the next section:
200
201
202 // The session_id is used to find user in the database. Two tables are joined: The session-table with user_id of the session and the usertable with its primary key
203 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
204 '*',
205 $this->session_table.','.$this->user_table,
206 $this->session_table.'.ses_id = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
207 AND '.$this->session_table.'.ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table).'
208 AND '.$this->session_table.'.ses_userid = '.$this->user_table.'.'.$this->userid_column.'
209 '.$this->ipLockClause().'
210 '.$this->hashLockClause().'
211 '.$this->user_where_clause()
212 );
213
214 if ($this->user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres)) {
215 // A user was found
216 if (is_string($this->auth_timeout_field)) {
217 $timeout = intval($this->user[$this->auth_timeout_field]); // Get timeout-time from usertable
218 } else {
219 $timeout = intval($this->auth_timeout_field); // Get timeout from object
220 }
221 // If timeout > 0 (true) and currenttime has not exceeded the latest sessions-time plus the timeout in seconds then accept user
222 // Option later on: We could check that last update was at least x seconds ago in order not to update twice in a row if one script redirects to another...
223 if ($timeout>0 && ($GLOBALS['EXEC_TIME'] < ($this->user['ses_tstamp']+$timeout))) {
224 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
225 $this->session_table,
226 'ses_id='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
227 AND ses_name='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table),
228 array('ses_tstamp' => $GLOBALS['EXEC_TIME'])
229 );
230 $this->user['ses_tstamp'] = $GLOBALS['EXEC_TIME']; // Make sure that the timestamp is also updated in the array
231 } else {
232 $this->user = '';
233 $this->logoff(); // delete any user set...
234 }
235 } else {
236 $this->logoff(); // delete any user set...
237 }
238
239 $this->redirect(); // If any redirection (inclusion of file) then it will happen in this function
240
241 // Set all posible headers that could ensure that the script is not cached on the client-side
242 if ($this->sendNoCacheHeaders) {
243 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
244 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
245 header('Expires: 0');
246 header('Cache-Control: no-cache, must-revalidate');
247 header('Pragma: no-cache');
248 }
249
250 // If we're lucky we'll get to clean up old sessions....
251 if ((rand()%100) <= $this->gc_probability) {
252 $this->gc();
253 }
254 }
255
256 /**
257 * Checks if a submission of username and password is present
258 *
259 * @return string Returns "login" if login, "logout" if logout, or empty if $F_status was none of these values.
260 * @internal
261 */
262 function check_authentication() {
263
264 // The values fetched from input variables here are supposed to already BE slashed...
265 if ($this->getMethodEnabled) {
266 $F_status = t3lib_div::_GP($this->formfield_status);
267 $F_uname = t3lib_div::_GP($this->formfield_uname);
268 $F_uident = t3lib_div::_GP($this->formfield_uident);
269 $F_chalvalue = t3lib_div::_GP($this->formfield_chalvalue);
270 } else {
271 $F_status = t3lib_div::_POST($this->formfield_status);
272 $F_uname = t3lib_div::_POST($this->formfield_uname);
273 $F_uident = t3lib_div::_POST($this->formfield_uident);
274 $F_chalvalue = t3lib_div::_POST($this->formfield_chalvalue);
275 }
276
277 switch ($F_status) {
278 case 'login':
279 $refInfo=parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
280 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
281 if (!$this->getMethodEnabled && ($httpHost!=$refInfo['host'] && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer'])) {
282 die('Error: This host address ("'.$httpHost.'") and the referer host ("'.$refInfo['host'].'") mismatches!<br />
283 It\'s possible that the environment variable HTTP_REFERER is not passed to the script because of a proxy.<br />
284 The site administrator can disable this check in the "All Configuration" section of the Install Tool (flag: TYPO3_CONF_VARS[SYS][doNotCheckReferer]).');
285 }
286 if ($F_uident && $F_uname) {
287
288 // Reset this flag
289 $loginFailure=0;
290
291 // delete old user session if any
292 $this->logoff();
293
294 // Look up the new user by the username:
295 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
296 '*',
297 $this->user_table,
298 ($this->checkPid ? 'pid IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($this->checkPid_value).') AND ' : '').
299 $this->username_column.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($F_uname, $this->user_table).' '.
300 $this->user_where_clause()
301 );
302
303 // Enter, if a user was found:
304 if ($tempuser = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres)) {
305 // Internal user record set (temporarily)
306 $this->user = $tempuser;
307
308 // Default: not OK - will be set true if password matches in the comparison hereafter
309 $OK = false;
310
311 // check the password
312 switch ($this->security_level) {
313 case 'superchallenged': // If superchallenged the password in the database ($tempuser[$this->userident_column]) must be a md5-hash of the original password.
314 case 'challenged':
315
316 if ($this->challengeStoredInCookie) {
317 session_start();
318 if ($_SESSION['login_challenge'] !== $F_chalvalue) {
319 $this->logoff();
320 return 'login';
321 }
322 }
323
324 if (!strcmp($F_uident,md5($tempuser[$this->username_column].':'.$tempuser[$this->userident_column].':'.$F_chalvalue))) {
325 $OK = true;
326 };
327 break;
328 default: // normal
329 if (!strcmp($F_uident,$tempuser[$this->userident_column])) {
330 $OK = true;
331 };
332 break;
333 }
334
335 // Write session-record in case user was verified OK
336 if ($OK) {
337 // Checking the domain (lockToDomain)
338 if ($this->user['lockToDomain'] && $this->user['lockToDomain']!=t3lib_div::getIndpEnv('HTTP_HOST')) {
339 // Lock domain didn't match, so error:
340 if ($this->writeAttemptLog) {
341 $this->writelog(255,3,3,1,
342 "Login-attempt from %s (%s), username '%s', locked domain '%s' did not match '%s'!",
343 Array(t3lib_div::getIndpEnv('REMOTE_ADDR'),t3lib_div::getIndpEnv('REMOTE_HOST'),$F_uname,$this->user['lockToDomain'],t3lib_div::getIndpEnv('HTTP_HOST')));
344 }
345 $loginFailure=1;
346 } else {
347 // The loginsession is started.
348 $this->loginSessionStarted = 1;
349
350 // Inserting session record:
351 $insertFields = array(
352 'ses_id' => $this->id,
353 'ses_name' => $this->name,
354 'ses_iplock' => $this->user['disableIPlock'] ? '[DISABLED]' : $this->ipLockClause_remoteIPNumber($this->lockIP),
355 'ses_hashlock' => $this->hashLockClause_getHashInt(),
356 'ses_userid' => $tempuser[$this->userid_column],
357 'ses_tstamp' => $GLOBALS['EXEC_TIME']
358 );
359 $GLOBALS['TYPO3_DB']->exec_INSERTquery($this->session_table, $insertFields);
360
361 // Updating column carrying information about last login.
362 if ($this->lastLogin_column) {
363 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
364 $this->user_table,
365 $this->userid_column.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($tempuser[$this->userid_column], $this->user_table),
366 array($this->lastLogin_column => $GLOBALS['EXEC_TIME'])
367 );
368 }
369 // User logged in - write that to the log!
370 if ($this->writeStdLog) {
371 $this->writelog(255,1,0,1,
372 'User %s logged in from %s (%s)',
373 Array($this->user['username'],t3lib_div::getIndpEnv('REMOTE_ADDR'),t3lib_div::getIndpEnv('REMOTE_HOST')));
374 }
375 }
376 } else {
377 // Failed login attempt (wrong password) - write that to the log!
378 if ($this->writeAttemptLog) {
379 $this->writelog(255,3,3,1,
380 "Login-attempt from %s (%s), username '%s', password not accepted!",
381 Array(t3lib_div::getIndpEnv('REMOTE_ADDR'),t3lib_div::getIndpEnv('REMOTE_HOST'),$F_uname));
382 }
383 $loginFailure=1;
384 }
385 // Make sure to clear the user again!!
386 unset($this->user);
387 } else {
388 // Failed login attempt (no username found)
389 if ($this->writeAttemptLog) {
390 $this->writelog(255,3,3,2,
391 "Login-attempt from %s (%s), username '%s' not found!!",
392 Array(t3lib_div::getIndpEnv('REMOTE_ADDR'),t3lib_div::getIndpEnv('REMOTE_HOST'),$F_uname)); // Logout written to log
393 }
394 $loginFailure=1;
395 }
396
397 // If there were a login failure, check to see if a warning email should be sent:
398 if ($loginFailure) {
399 $this->checkLogFailures($this->warningEmail, $this->warningPeriod, $this->warningMax);
400 }
401 }
402
403 // Return "login" - since this was the $F_status
404 return 'login';
405 break;
406 case 'logout':
407 // Just logout:
408 if ($this->writeStdLog) $this->writelog(255,2,0,2,'User %s logged out',Array($this->user['username'])); // Logout written to log
409 $this->logoff();
410
411 // Return "logout" - since this was the $F_status
412 return 'logout';
413 break;
414 }
415 }
416
417 /**
418 * Redirect to somewhere. Obsolete, depreciated etc.
419 *
420 * @return void
421 * @ignore
422 */
423 function redirect() {
424 if (!$this->userid && $this->auth_url) { // if no userid AND an include-document for login is given
425 include ($this->auth_include);
426 exit;
427 }
428 }
429
430 /**
431 * Log out current user!
432 * Removes the current session record, sets the internal ->user array to a blank string; Thereby the current user (if any) is effectively logged out!
433 *
434 * @return void
435 */
436 function logoff() {
437 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
438 $this->session_table,
439 'ses_id = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
440 AND ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table)
441 );
442 $this->user = "";
443 }
444
445 /**
446 * Garbage collector, removing old expired sessions.
447 *
448 * @return void
449 * @internal
450 */
451 function gc() {
452 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
453 $this->session_table,
454 'ses_tstamp < '.intval(time()-($this->gc_time*60*60)).'
455 AND ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table)
456 );
457 }
458
459 /**
460 * This returns the where-clause needed to select the user with respect flags like deleted, hidden, starttime, endtime
461 *
462 * @return string
463 * @access private
464 */
465 function user_where_clause() {
466 return (($this->enablecolumns['rootLevel']) ? 'AND '.$this->user_table.'.pid=0 ' : '').
467 (($this->enablecolumns['disabled']) ? ' AND '.$this->user_table.'.'.$this->enablecolumns['disabled'].'=0' : '').
468 (($this->enablecolumns['deleted']) ? ' AND '.$this->user_table.'.'.$this->enablecolumns['deleted'].'=0' : '').
469 (($this->enablecolumns['starttime']) ? ' AND ('.$this->user_table.'.'.$this->enablecolumns['starttime'].'<='.time().')' : '').
470 (($this->enablecolumns['endtime']) ? ' AND ('.$this->user_table.'.'.$this->enablecolumns['endtime'].'=0 OR '.$this->user_table.'.'.$this->enablecolumns['endtime'].'>'.time().')' : '');
471 }
472
473 /**
474 * This returns the where-clause needed to lock a user to the IP address
475 *
476 * @return string
477 * @access private
478 */
479 function ipLockClause() {
480 if ($this->lockIP) {
481 $wherePart = 'AND (
482 '.$this->session_table.'.ses_iplock='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->ipLockClause_remoteIPNumber($this->lockIP),$this->session_table).'
483 OR '.$this->session_table.'.ses_iplock=\'[DISABLED]\'
484 )';
485 return $wherePart;
486 }
487 }
488
489 /**
490 * Returns the IP address to lock to.
491 * The IP address may be partial based on $parts.
492 *
493 * @param integer 1-4: Indicates how many parts of the IP address to return. 4 means all, 1 means only first number.
494 * @return string (Partial) IP address for REMOTE_ADDR
495 * @access private
496 */
497 function ipLockClause_remoteIPNumber($parts) {
498 $IP = t3lib_div::getIndpEnv('REMOTE_ADDR');
499
500 if ($parts>=4) {
501 return $IP;
502 } else {
503 $parts = t3lib_div::intInRange($parts,1,3);
504 $IPparts = explode('.',$IP);
505 for($a=4;$a>$parts;$a--) {
506 unset($IPparts[$a-1]);
507 }
508 return implode('.',$IPparts);
509 }
510 }
511
512 /**
513 * This returns the where-clause needed to lock a user to a hash integer
514 *
515 * @return string
516 * @access private
517 */
518 function hashLockClause() {
519 $wherePart = 'AND '.$this->session_table.'.ses_hashlock='.intval($this->hashLockClause_getHashInt());
520 return $wherePart;
521 }
522
523 /**
524 * Creates hash integer to lock user to. Depends on configured keywords
525 *
526 * @return integer Hash integer
527 * @access private
528 */
529 function hashLockClause_getHashInt() {
530 $hashStr = '';
531
532 if (t3lib_div::inList($this->lockHashKeyWords,'useragent')) $hashStr.=':'.t3lib_div::getIndpEnv('HTTP_USER_AGENT');
533
534 return t3lib_div::md5int($hashStr);
535 }
536
537 /**
538 * This writes $variable to the user-record. This is a way of providing session-data.
539 * You can fetch the data again through $this->uc in this class!
540 * If $variable is not an array, $this->uc is saved!
541 *
542 * @param array An array you want to store for the user as session data. If $variable is not supplied (is blank string), the internal variable, ->uc, is stored by default
543 * @return void
544 */
545 function writeUC($variable='') {
546 if (is_array($this->user) && $this->user['uid']) {
547 if (!is_array($variable)) { $variable = $this->uc; }
548
549 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($this->user_table, 'uid='.intval($this->user['uid']), array('uc' => serialize($variable)));
550 }
551 }
552
553 /**
554 * DUMMY: Writes to log database table (in some extension classes)
555 *
556 * @param integer $type: denotes which module that has submitted the entry. This is the current list: 1=tce_db; 2=tce_file; 3=system (eg. sys_history save); 4=modules; 254=Personal settings changed; 255=login / out action: 1=login, 2=logout, 3=failed login (+ errorcode 3), 4=failure_warning_email sent
557 * @param integer $action: denotes which specific operation that wrote the entry (eg. 'delete', 'upload', 'update' and so on...). Specific for each $type. Also used to trigger update of the interface. (see the log-module for the meaning of each number !!)
558 * @param integer $error: flag. 0 = message, 1 = error (user problem), 2 = System Error (which should not happen), 3 = security notice (admin)
559 * @param integer $details_nr: The message number. Specific for each $type and $action. in the future this will make it possible to translate errormessages to other languages
560 * @param string $details: Default text that follows the message
561 * @param array $data: Data that follows the log. Might be used to carry special information. If an array the first 5 entries (0-4) will be sprintf'ed the details-text...
562 * @param string $tablename: Special field used by tce_main.php. These ($tablename, $recuid, $recpid) holds the reference to the record which the log-entry is about. (Was used in attic status.php to update the interface.)
563 * @param integer $recuid: Special field used by tce_main.php. These ($tablename, $recuid, $recpid) holds the reference to the record which the log-entry is about. (Was used in attic status.php to update the interface.)
564 * @param integer $recpid: Special field used by tce_main.php. These ($tablename, $recuid, $recpid) holds the reference to the record which the log-entry is about. (Was used in attic status.php to update the interface.)
565 * @return void
566 * @see t3lib_userauthgroup::writelog()
567 */
568 function writelog($type,$action,$error,$details_nr,$details,$data,$tablename,$recuid,$recpid) {
569 }
570
571 /**
572 * DUMMY: Check login failures (in some extension classes)
573 *
574 * @return void
575 * @ignore
576 */
577 function checkLogFailures() {
578 }
579
580 /**
581 * Sets $theUC as the internal variable ->uc IF $theUC is an array. If $theUC is false, the 'uc' content from the ->user array will be unserialized and restored in ->uc
582 *
583 * @param mixed If an array, then set as ->uc, otherwise load from user record
584 * @return void
585 */
586 function unpack_uc($theUC='') {
587 if (!$theUC) $theUC=unserialize($this->user['uc']);
588 if (is_array($theUC)) {
589 $this->uc=$theUC;
590 }
591 }
592
593 /**
594 * Stores data for a module.
595 * The data is stored with the session id so you can even check upon retrieval if the module data is from a previous session or from the current session.
596 *
597 * @param string $module is the name of the module ($MCONF['name'])
598 * @param mixed $data is the data you want to store for that module (array, string, ...)
599 * @param boolean If $noSave is set, then the ->uc array (which carries all kinds of user data) is NOT written immediately, but must be written by some subsequent call.
600 * @return void
601 */
602 function pushModuleData($module,$data,$noSave=0) {
603 $this->uc['moduleData'][$module] = $data;
604 $this->uc['moduleSessionID'][$module] = $this->id;
605 if (!$noSave) $this->writeUC();
606 }
607
608 /**
609 * Gets module data for a module (from a loaded ->uc array)
610 *
611 * @param string $module is the name of the module ($MCONF['name'])
612 * @param string If $type = 'ses' then module data is returned only if it was stored in the current session, otherwise data from a previous session will be returned (if available).
613 * @return mixed The module data if available: $this->uc['moduleData'][$module];
614 */
615 function getModuleData($module,$type='') {
616 if ($type!='ses' || $this->uc['moduleSessionID'][$module]==$this->id) {
617 return $this->uc['moduleData'][$module];
618 }
619 }
620
621 /**
622 * Returns the session data stored for $key.
623 * The data will last only for this login session since it is stored in the session table.
624 *
625 * @param string Pointer to an associative key in the session data array which is stored serialized in the field "ses_data" of the session table.
626 * @return mixed
627 */
628 function getSessionData($key) {
629 $sesDat = unserialize($this->user['ses_data']);
630 return $sesDat[$key];
631 }
632
633 /**
634 * Sets the session data ($data) for $key and writes all session data (from ->user['ses_data']) to the database.
635 * The data will last only for this login session since it is stored in the session table.
636 *
637 * @param string Pointer to an associative key in the session data array which is stored serialized in the field "ses_data" of the session table.
638 * @param mixed The variable to store in index $key
639 * @return void
640 */
641 function setAndSaveSessionData($key,$data) {
642 $sesDat = unserialize($this->user['ses_data']);
643 $sesDat[$key] = $data;
644 $this->user['ses_data'] = serialize($sesDat);
645
646 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($this->session_table, 'ses_id='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->user['ses_id'], $this->session_table), array('ses_data' => $this->user['ses_data']));
647 }
648
649 /**
650 * Raw initialization of the be_user with uid=$uid
651 * This will circumvent all login procedures and select a be_users record from the database and set the content of ->user to the record selected. Thus the BE_USER object will appear like if a user was authenticated - however without a session id and the fields from the session table of course.
652 * Will check the users for disabled, start/endtime, etc. ($this->user_where_clause())
653 *
654 * @param integer The UID of the backend user to set in ->user
655 * @return void
656 * @params integer 'uid' of be_users record to select and set.
657 * @internal
658 * @see SC_mod_tools_be_user_index::compareUsers(), SC_mod_user_setup_index::simulateUser(), freesite_admin::startCreate()
659 */
660 function setBeUserByUid($uid) {
661 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->user_table, 'uid='.intval($uid).' '.$this->user_where_clause());
662 $this->user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
663 }
664
665 /**
666 * Raw initialization of the be_user with username=$name
667 *
668 * @param string The username to look up.
669 * @return void
670 * @see t3lib_userAuth::setBeUserByUid()
671 * @internal
672 */
673 function setBeUserByName($name) {
674 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->user_table, 'username='.$GLOBALS['TYPO3_DB']->fullQuoteStr($name, $this->user_table).' '.$this->user_where_clause());
675 $this->user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
676 }
677 }
678
679
680
681 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauth.php']) {
682 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauth.php']);
683 }
684 ?>