* Added to user authentication that the HTTP_USER_AGENT is hashed and a part of the...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_userauth.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@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 <kasper@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 89: class t3lib_userAuth
41 * 158: function start()
42 * 260: function check_authentication()
43 * 412: function redirect()
44 * 425: function logoff()
45 * 440: function gc()
46 * 454: function user_where_clause()
47 * 468: function ipLockClause()
48 * 484: function ipLockClause_remoteIPNumber($parts)
49 * 505: function hashLockClause()
50 * 515: function hashLockClause_getHashInt()
51 * 527: function writeUC($variable='')
52 * 550: function writelog($type,$action,$error,$details_nr,$details,$data,$tablename,$recuid,$recpid)
53 * 559: function checkLogFailures()
54 * 568: function unpack_uc($theUC='')
55 * 584: function pushModuleData($module,$data,$noSave=0)
56 * 597: function getModuleData($module,$type='')
57 * 610: function getSessionData($key)
58 * 623: function setAndSaveSessionData($key,$data)
59 * 642: function setBeUserByUid($uid)
60 * 655: 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 <kasper@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 false/<0 : no timeout. 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 HTTP_GET_VARS. 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 HTTP_COOKIE_VARS).
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 (liftime must be 0)
145 var $dontSetCookie=0; // Will prevent the setting of the session cookie (takes precedence over forceSetCookie.
146
147
148 /**
149 * Starts a user session
150 * Typical configurations will:
151 * a) check if session cookie was set and if not, set one,
152 * b) check if a password/username was sent and if so, try to authenticate the user
153 * c) Lookup a session attached to a user and check timeout etc.
154 * d) Garbage collection, setting of no-cache headers.
155 * If a user is authenticated the database record of the user (array) will be set in the ->user internal variable.
156 *
157 * @return void
158 */
159 function start() {
160 global $HTTP_COOKIE_VARS, $HTTP_GET_VARS;
161
162 // Init vars.
163 $mode='';
164 $new_id = false; // Default: not a new session
165 $id = isset($HTTP_COOKIE_VARS[$this->name]) ? stripslashes($HTTP_COOKIE_VARS[$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($HTTP_GET_VARS[$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']->quoteStr($this->id, $this->session_table).'"
207 AND '.$this->session_table.'.ses_name = "'.$GLOBALS['TYPO3_DB']->quoteStr($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']->quoteStr($this->id, $this->session_table).'"
227 AND ses_name="'.$GLOBALS['TYPO3_DB']->quoteStr($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 configuration (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']->quoteStr($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 if (!strcmp($F_uident,md5($tempuser[$this->username_column].':'.$tempuser[$this->userident_column].':'.$F_chalvalue))) {
316 $OK = true;
317 };
318 break;
319 default: // normal
320 if (!strcmp($F_uident,$tempuser[$this->userident_column])) {
321 $OK = true;
322 };
323 break;
324 }
325
326 // Write session-record in case user was verified OK
327 if ($OK) {
328 // Checking the domain (lockToDomain)
329 if ($this->user['lockToDomain'] && $this->user['lockToDomain']!=t3lib_div::getIndpEnv('HTTP_HOST')) {
330 // Lock domain didn't match, so error:
331 if ($this->writeAttemptLog) {
332 $this->writelog(255,3,3,1,
333 "Login-attempt from %s (%s), username '%s', locked domain '%s' did not match '%s'!",
334 Array(t3lib_div::getIndpEnv('REMOTE_ADDR'),t3lib_div::getIndpEnv('REMOTE_HOST'),$F_uname,$this->user['lockToDomain'],t3lib_div::getIndpEnv('HTTP_HOST')));
335 }
336 $loginFailure=1;
337 } else {
338 // The loginsession is started.
339 $this->loginSessionStarted = 1;
340
341 // Inserting session record:
342 $insertFields = array(
343 'ses_id' => $this->id,
344 'ses_name' => $this->name,
345 'ses_iplock' => $this->user['disableIPlock'] ? '[DISABLED]' : $this->ipLockClause_remoteIPNumber($this->lockIP),
346 'ses_hashlock' => $this->hashLockClause_getHashInt(),
347 'ses_userid' => $tempuser[$this->userid_column],
348 'ses_tstamp' => $GLOBALS['EXEC_TIME']
349 );
350 $GLOBALS['TYPO3_DB']->exec_INSERTquery($this->session_table, $insertFields);
351
352 // Updating column carrying information about last login.
353 if ($this->lastLogin_column) {
354 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
355 $this->user_table,
356 $this->userid_column.'="'.$GLOBALS['TYPO3_DB']->quoteStr($tempuser[$this->userid_column], $this->user_table).'"',
357 array($this->lastLogin_column => $GLOBALS['EXEC_TIME'])
358 );
359 }
360 // User logged in - write that to the log!
361 if ($this->writeStdLog) {
362 $this->writelog(255,1,0,1,
363 'User %s logged in from %s (%s)',
364 Array($this->user['username'],t3lib_div::getIndpEnv('REMOTE_ADDR'),t3lib_div::getIndpEnv('REMOTE_HOST')));
365 }
366 }
367 } else {
368 // Failed login attempt (wrong password) - write that to the log!
369 if ($this->writeAttemptLog) {
370 $this->writelog(255,3,3,1,
371 "Login-attempt from %s (%s), username '%s', password not accepted!",
372 Array(t3lib_div::getIndpEnv('REMOTE_ADDR'),t3lib_div::getIndpEnv('REMOTE_HOST'),$F_uname));
373 }
374 $loginFailure=1;
375 }
376 // Make sure to clear the user again!!
377 unset($this->user);
378 } else {
379 // Failed login attempt (no username found)
380 if ($this->writeAttemptLog) {
381 $this->writelog(255,3,3,2,
382 "Login-attempt from %s (%s), username '%s' not found!!",
383 Array(t3lib_div::getIndpEnv('REMOTE_ADDR'),t3lib_div::getIndpEnv('REMOTE_HOST'),$F_uname)); // Logout written to log
384 }
385 $loginFailure=1;
386 }
387
388 // If there were a login failure, check to see if a warning email should be sent:
389 if ($loginFailure) {
390 $this->checkLogFailures($this->warningEmail, $this->warningPeriod, $this->warningMax);
391 }
392 }
393
394 // Return "login" - since this was the $F_status
395 return 'login';
396 break;
397 case 'logout':
398 // Just logout:
399 if ($this->writeStdLog) $this->writelog(255,2,0,2,'User %s logged out',Array($this->user['username'])); // Logout written to log
400 $this->logoff();
401
402 // Return "logout" - since this was the $F_status
403 return 'logout';
404 break;
405 }
406 }
407
408 /**
409 * Redirect to somewhere. Obsolete, depreciated etc.
410 *
411 * @return void
412 * @ignore
413 */
414 function redirect() {
415 if (!$this->userid && $this->auth_url) { // if no userid AND an include-document for login is given
416 include ($this->auth_include);
417 exit;
418 }
419 }
420
421 /**
422 * Log out current user!
423 * Removes the current session record, sets the internal ->user array to a blank string; Thereby the current user (if any) is effectively logged out!
424 *
425 * @return void
426 */
427 function logoff() {
428 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
429 $this->session_table,
430 'ses_id = "'.$GLOBALS['TYPO3_DB']->quoteStr($this->id, $this->session_table).'"
431 AND ses_name = "'.$GLOBALS['TYPO3_DB']->quoteStr($this->name, $this->session_table).'"'
432 );
433 $this->user = "";
434 }
435
436 /**
437 * Garbage collector, removing old expired sessions.
438 *
439 * @return void
440 * @internal
441 */
442 function gc() {
443 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
444 $this->session_table,
445 'ses_tstamp < '.intval(time()-($this->gc_time*60*60)).'
446 AND ses_name = "'.$GLOBALS['TYPO3_DB']->quoteStr($this->name, $this->session_table).'"'
447 );
448 }
449
450 /**
451 * This returns the where-clause needed to select the user with respect flags like deleted, hidden, starttime, endtime
452 *
453 * @return string
454 * @access private
455 */
456 function user_where_clause() {
457 return (($this->enablecolumns['rootLevel']) ? 'AND '.$this->user_table.'.pid=0 ' : '').
458 (($this->enablecolumns['disabled']) ? ' AND NOT '.$this->user_table.'.'.$this->enablecolumns['disabled'] : '').
459 (($this->enablecolumns['deleted']) ? ' AND NOT '.$this->user_table.'.'.$this->enablecolumns['deleted'] : '').
460 (($this->enablecolumns['starttime']) ? ' AND ('.$this->user_table.'.'.$this->enablecolumns['starttime'].'<='.time().')' : '').
461 (($this->enablecolumns['endtime']) ? ' AND ('.$this->user_table.'.'.$this->enablecolumns['endtime'].'=0 OR '.$this->user_table.'.'.$this->enablecolumns['endtime'].'>'.time().')' : '');
462 }
463
464 /**
465 * This returns the where-clause needed to lock a user to the IP address
466 *
467 * @return string
468 * @access private
469 */
470 function ipLockClause() {
471 if ($this->lockIP) {
472 $wherePart = 'AND (
473 '.$this->session_table.'.ses_iplock="'.$GLOBALS['TYPO3_DB']->quoteStr($this->ipLockClause_remoteIPNumber($this->lockIP),$this->session_table).'"
474 OR '.$this->session_table.'.ses_iplock="[DISABLED]"
475 )';
476 return $wherePart;
477 }
478 }
479
480 /**
481 * Returns the IP address to lock to.
482 * The IP address may be partial based on $parts.
483 *
484 * @param integer 1-4: Indicates how many parts of the IP address to return. 4 means all, 1 means only first number.
485 * @return string (Partial) IP address for REMOTE_ADDR
486 * @access private
487 */
488 function ipLockClause_remoteIPNumber($parts) {
489 $IP = t3lib_div::getIndpEnv('REMOTE_ADDR');
490
491 if ($parts>=4) {
492 return $IP;
493 } else {
494 $parts = t3lib_div::intInRange($parts,1,3);
495 $IPparts = explode('.',$IP);
496 for($a=4;$a>$parts;$a--) {
497 unset($IPparts[$a-1]);
498 }
499 return implode('.',$IPparts);
500 }
501 }
502
503 /**
504 * This returns the where-clause needed to lock a user to a hash integer
505 *
506 * @return string
507 * @access private
508 */
509 function hashLockClause() {
510 $wherePart = 'AND '.$this->session_table.'.ses_hashlock='.intval($this->hashLockClause_getHashInt());
511 return $wherePart;
512 }
513
514 /**
515 * Creates hash integer to lock user to. Depends on configured keywords
516 *
517 * @return integer Hash integer
518 * @access private
519 */
520 function hashLockClause_getHashInt() {
521 $hashStr = '';
522
523 if (t3lib_div::inList($this->lockHashKeyWords,'useragent')) $hashStr.=':'.t3lib_div::getIndpEnv('HTTP_USER_AGENT');
524
525 return t3lib_div::md5int($hashStr);
526 }
527
528 /**
529 * This writes $variable to the user-record. This is a way of providing session-data.
530 * You can fetch the data again through $this->uc in this class!
531 * If $variable is not an array, $this->uc is saved!
532 *
533 * @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
534 * @return void
535 */
536 function writeUC($variable='') {
537 if (is_array($this->user) && $this->user['uid']) {
538 if (!is_array($variable)) { $variable = $this->uc; }
539
540 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($this->user_table, 'uid='.intval($this->user['uid']), array('uc' => serialize($variable)));
541 }
542 }
543
544 /**
545 * DUMMY: Writes to log database table (in some extension classes)
546 *
547 * @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
548 * @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 !!)
549 * @param integer $error: flag. 0 = message, 1 = error (user problem), 2 = System Error (which should not happen), 3 = security notice (admin)
550 * @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
551 * @param string $details: Default text that follows the message
552 * @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...
553 * @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.)
554 * @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.)
555 * @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.)
556 * @return void
557 * @see t3lib_userauthgroup::writelog()
558 */
559 function writelog($type,$action,$error,$details_nr,$details,$data,$tablename,$recuid,$recpid) {
560 }
561
562 /**
563 * DUMMY: Check login failures (in some extension classes)
564 *
565 * @return void
566 * @ignore
567 */
568 function checkLogFailures() {
569 }
570
571 /**
572 * 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
573 *
574 * @param mixed If an array, then set as ->uc, otherwise load from user record
575 * @return void
576 */
577 function unpack_uc($theUC='') {
578 if (!$theUC) $theUC=unserialize($this->user['uc']);
579 if (is_array($theUC)) {
580 $this->uc=$theUC;
581 }
582 }
583
584 /**
585 * Stores data for a module.
586 * 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.
587 *
588 * @param string $module is the name of the module ($MCONF['name'])
589 * @param mixed $data is the data you want to store for that module (array, string, ...)
590 * @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.
591 * @return void
592 */
593 function pushModuleData($module,$data,$noSave=0) {
594 $this->uc['moduleData'][$module] = $data;
595 $this->uc['moduleSessionID'][$module] = $this->id;
596 if (!$noSave) $this->writeUC();
597 }
598
599 /**
600 * Gets module data for a module (from a loaded ->uc array)
601 *
602 * @param string $module is the name of the module ($MCONF['name'])
603 * @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).
604 * @return mixed The module data if available: $this->uc['moduleData'][$module];
605 */
606 function getModuleData($module,$type='') {
607 if ($type!='ses' || $this->uc['moduleSessionID'][$module]==$this->id) {
608 return $this->uc['moduleData'][$module];
609 }
610 }
611
612 /**
613 * Returns the session data stored for $key.
614 * The data will last only for this login session since it is stored in the session table.
615 *
616 * @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.
617 * @return mixed
618 */
619 function getSessionData($key) {
620 $sesDat = unserialize($this->user['ses_data']);
621 return $sesDat[$key];
622 }
623
624 /**
625 * Sets the session data ($data) for $key and writes all session data (from ->user['ses_data']) to the database.
626 * The data will last only for this login session since it is stored in the session table.
627 *
628 * @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.
629 * @param mixed The variable to store in index $key
630 * @return void
631 */
632 function setAndSaveSessionData($key,$data) {
633 $sesDat = unserialize($this->user['ses_data']);
634 $sesDat[$key] = $data;
635 $this->user['ses_data'] = serialize($sesDat);
636
637 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($this->session_table, 'ses_id="'.$GLOBALS['TYPO3_DB']->quoteStr($this->user['ses_id'], $this->session_table).'"', array('ses_data' => $this->user['ses_data']));
638 }
639
640 /**
641 * Raw initialization of the be_user with uid=$uid
642 * 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.
643 * Will check the users for disabled, start/endtime, etc. ($this->user_where_clause())
644 *
645 * @param integer The UID of the backend user to set in ->user
646 * @return void
647 * @params integer 'uid' of be_users record to select and set.
648 * @internal
649 * @see SC_mod_tools_be_user_index::compareUsers(), SC_mod_user_setup_index::simulateUser(), freesite_admin::startCreate()
650 */
651 function setBeUserByUid($uid) {
652 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->user_table, 'uid="'.intval($uid).'" '.$this->user_where_clause());
653 $this->user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
654 }
655
656 /**
657 * Raw initialization of the be_user with username=$name
658 *
659 * @param string The username to look up.
660 * @return void
661 * @see t3lib_userAuth::setBeUserByUid()
662 * @internal
663 */
664 function setBeUserByName($name) {
665 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->user_table, 'username="'.$GLOBALS['TYPO3_DB']->quoteStr($name, $this->user_table).'" '.$this->user_where_clause());
666 $this->user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
667 }
668 }
669
670
671
672 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauth.php']) {
673 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauth.php']);
674 }
675 ?>