2005-02-04 Michael Stucki <michael@typo3.org>
[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
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
161 // Init vars.
162 $mode='';
163 $new_id = false; // Default: not a new session
164 $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
165 $this->hash_length = t3lib_div::intInRange($this->hash_length,6,32);
166
167 // If fallback to get mode....
168 if (!$id && $this->getFallBack && $this->get_name) {
169 $id = isset($_GET[$this->get_name]) ? t3lib_div::_GET($this->get_name) : '';
170 if (strlen($id)!=$this->hash_length) $id='';
171 $mode='get';
172 }
173 $this->cookieId = $id;
174
175 if (!$id) { // If new session...
176 $id = substr(md5(uniqid('')),0,$this->hash_length); // New random session-$id is made
177 $new_id = true; // New session
178 }
179 // Internal var 'id' is set
180 $this->id = $id;
181 if ($mode=='get' && $this->getFallBack && $this->get_name) { // If fallback to get mode....
182 $this->get_URL_ID = '&'.$this->get_name.'='.$id;
183 }
184 $this->user = ''; // Make certain that NO user is set initially
185
186 // Setting cookies
187 if (($new_id || $this->forceSetCookie) && $this->lifetime==0 ) { // If new session and the cookie is a sessioncookie, we need to set it only once!
188 if (!$this->dontSetCookie) SetCookie($this->name, $id, 0, '/'); // Cookie is set
189 }
190 if ($this->lifetime > 0) { // If it is NOT a session-cookie, we need to refresh it.
191 if (!$this->dontSetCookie) SetCookie($this->name, $id, time()+$this->lifetime, '/');
192 }
193
194 // 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...
195 if ($this->formfield_status) {
196 $this->check_authentication();
197 }
198 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:
199
200
201 // 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
202 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
203 '*',
204 $this->session_table.','.$this->user_table,
205 $this->session_table.'.ses_id = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
206 AND '.$this->session_table.'.ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table).'
207 AND '.$this->session_table.'.ses_userid = '.$this->user_table.'.'.$this->userid_column.'
208 '.$this->ipLockClause().'
209 '.$this->hashLockClause().'
210 '.$this->user_where_clause()
211 );
212
213 if ($this->user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres)) {
214 // A user was found
215 if (is_string($this->auth_timeout_field)) {
216 $timeout = intval($this->user[$this->auth_timeout_field]); // Get timeout-time from usertable
217 } else {
218 $timeout = intval($this->auth_timeout_field); // Get timeout from object
219 }
220 // If timeout > 0 (true) and currenttime has not exceeded the latest sessions-time plus the timeout in seconds then accept user
221 // 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...
222 if ($timeout>0 && ($GLOBALS['EXEC_TIME'] < ($this->user['ses_tstamp']+$timeout))) {
223 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
224 $this->session_table,
225 'ses_id='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
226 AND ses_name='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table),
227 array('ses_tstamp' => $GLOBALS['EXEC_TIME'])
228 );
229 $this->user['ses_tstamp'] = $GLOBALS['EXEC_TIME']; // Make sure that the timestamp is also updated in the array
230 } else {
231 $this->user = '';
232 $this->logoff(); // delete any user set...
233 }
234 } else {
235 $this->logoff(); // delete any user set...
236 }
237
238 $this->redirect(); // If any redirection (inclusion of file) then it will happen in this function
239
240 // Set all posible headers that could ensure that the script is not cached on the client-side
241 if ($this->sendNoCacheHeaders) {
242 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
243 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
244 header('Expires: 0');
245 header('Cache-Control: no-cache, must-revalidate');
246 header('Pragma: no-cache');
247 }
248
249 // If we're lucky we'll get to clean up old sessions....
250 if ((rand()%100) <= $this->gc_probability) {
251 $this->gc();
252 }
253 }
254
255 /**
256 * Checks if a submission of username and password is present
257 *
258 * @return string Returns "login" if login, "logout" if logout, or empty if $F_status was none of these values.
259 * @internal
260 */
261 function check_authentication() {
262
263 // The values fetched from input variables here are supposed to already BE slashed...
264 if ($this->getMethodEnabled) {
265 $F_status = t3lib_div::_GP($this->formfield_status);
266 $F_uname = t3lib_div::_GP($this->formfield_uname);
267 $F_uident = t3lib_div::_GP($this->formfield_uident);
268 $F_chalvalue = t3lib_div::_GP($this->formfield_chalvalue);
269 } else {
270 $F_status = t3lib_div::_POST($this->formfield_status);
271 $F_uname = t3lib_div::_POST($this->formfield_uname);
272 $F_uident = t3lib_div::_POST($this->formfield_uident);
273 $F_chalvalue = t3lib_div::_POST($this->formfield_chalvalue);
274 }
275
276 switch ($F_status) {
277 case 'login':
278 $refInfo=parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
279 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
280 if (!$this->getMethodEnabled && ($httpHost!=$refInfo['host'] && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer'])) {
281 die('Error: This host address ("'.$httpHost.'") and the referer host ("'.$refInfo['host'].'") mismatches!<br />
282 It\'s possible that the environment variable HTTP_REFERER is not passed to the script because of a proxy.<br />
283 The site administrator can disable this check in the "All Configuration" section of the Install Tool (flag: TYPO3_CONF_VARS[SYS][doNotCheckReferer]).');
284 }
285 if ($F_uident && $F_uname) {
286
287 // Reset this flag
288 $loginFailure=0;
289
290 // delete old user session if any
291 $this->logoff();
292
293 // Look up the new user by the username:
294 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
295 '*',
296 $this->user_table,
297 ($this->checkPid ? 'pid IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($this->checkPid_value).') AND ' : '').
298 $this->username_column.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($F_uname, $this->user_table).' '.
299 $this->user_where_clause()
300 );
301
302 // Enter, if a user was found:
303 if ($tempuser = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres)) {
304 // Internal user record set (temporarily)
305 $this->user = $tempuser;
306
307 // Default: not OK - will be set true if password matches in the comparison hereafter
308 $OK = false;
309
310 // check the password
311 switch ($this->security_level) {
312 case 'superchallenged': // If superchallenged the password in the database ($tempuser[$this->userident_column]) must be a md5-hash of the original password.
313 case 'challenged':
314 if (!strcmp($F_uident,md5($tempuser[$this->username_column].':'.$tempuser[$this->userident_column].':'.$F_chalvalue))) {
315 $OK = true;
316 };
317 break;
318 default: // normal
319 if (!strcmp($F_uident,$tempuser[$this->userident_column])) {
320 $OK = true;
321 };
322 break;
323 }
324
325 // Write session-record in case user was verified OK
326 if ($OK) {
327 // Checking the domain (lockToDomain)
328 if ($this->user['lockToDomain'] && $this->user['lockToDomain']!=t3lib_div::getIndpEnv('HTTP_HOST')) {
329 // Lock domain didn't match, so error:
330 if ($this->writeAttemptLog) {
331 $this->writelog(255,3,3,1,
332 "Login-attempt from %s (%s), username '%s', locked domain '%s' did not match '%s'!",
333 Array(t3lib_div::getIndpEnv('REMOTE_ADDR'),t3lib_div::getIndpEnv('REMOTE_HOST'),$F_uname,$this->user['lockToDomain'],t3lib_div::getIndpEnv('HTTP_HOST')));
334 }
335 $loginFailure=1;
336 } else {
337 // The loginsession is started.
338 $this->loginSessionStarted = 1;
339
340 // Inserting session record:
341 $insertFields = array(
342 'ses_id' => $this->id,
343 'ses_name' => $this->name,
344 'ses_iplock' => $this->user['disableIPlock'] ? '[DISABLED]' : $this->ipLockClause_remoteIPNumber($this->lockIP),
345 'ses_hashlock' => $this->hashLockClause_getHashInt(),
346 'ses_userid' => $tempuser[$this->userid_column],
347 'ses_tstamp' => $GLOBALS['EXEC_TIME']
348 );
349 $GLOBALS['TYPO3_DB']->exec_INSERTquery($this->session_table, $insertFields);
350
351 // Updating column carrying information about last login.
352 if ($this->lastLogin_column) {
353 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
354 $this->user_table,
355 $this->userid_column.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($tempuser[$this->userid_column], $this->user_table),
356 array($this->lastLogin_column => $GLOBALS['EXEC_TIME'])
357 );
358 }
359 // User logged in - write that to the log!
360 if ($this->writeStdLog) {
361 $this->writelog(255,1,0,1,
362 'User %s logged in from %s (%s)',
363 Array($this->user['username'],t3lib_div::getIndpEnv('REMOTE_ADDR'),t3lib_div::getIndpEnv('REMOTE_HOST')));
364 }
365 }
366 } else {
367 // Failed login attempt (wrong password) - write that to the log!
368 if ($this->writeAttemptLog) {
369 $this->writelog(255,3,3,1,
370 "Login-attempt from %s (%s), username '%s', password not accepted!",
371 Array(t3lib_div::getIndpEnv('REMOTE_ADDR'),t3lib_div::getIndpEnv('REMOTE_HOST'),$F_uname));
372 }
373 $loginFailure=1;
374 }
375 // Make sure to clear the user again!!
376 unset($this->user);
377 } else {
378 // Failed login attempt (no username found)
379 if ($this->writeAttemptLog) {
380 $this->writelog(255,3,3,2,
381 "Login-attempt from %s (%s), username '%s' not found!!",
382 Array(t3lib_div::getIndpEnv('REMOTE_ADDR'),t3lib_div::getIndpEnv('REMOTE_HOST'),$F_uname)); // Logout written to log
383 }
384 $loginFailure=1;
385 }
386
387 // If there were a login failure, check to see if a warning email should be sent:
388 if ($loginFailure) {
389 $this->checkLogFailures($this->warningEmail, $this->warningPeriod, $this->warningMax);
390 }
391 }
392
393 // Return "login" - since this was the $F_status
394 return 'login';
395 break;
396 case 'logout':
397 // Just logout:
398 if ($this->writeStdLog) $this->writelog(255,2,0,2,'User %s logged out',Array($this->user['username'])); // Logout written to log
399 $this->logoff();
400
401 // Return "logout" - since this was the $F_status
402 return 'logout';
403 break;
404 }
405 }
406
407 /**
408 * Redirect to somewhere. Obsolete, depreciated etc.
409 *
410 * @return void
411 * @ignore
412 */
413 function redirect() {
414 if (!$this->userid && $this->auth_url) { // if no userid AND an include-document for login is given
415 include ($this->auth_include);
416 exit;
417 }
418 }
419
420 /**
421 * Log out current user!
422 * Removes the current session record, sets the internal ->user array to a blank string; Thereby the current user (if any) is effectively logged out!
423 *
424 * @return void
425 */
426 function logoff() {
427 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
428 $this->session_table,
429 'ses_id = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
430 AND ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table)
431 );
432 $this->user = "";
433 }
434
435 /**
436 * Garbage collector, removing old expired sessions.
437 *
438 * @return void
439 * @internal
440 */
441 function gc() {
442 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
443 $this->session_table,
444 'ses_tstamp < '.intval(time()-($this->gc_time*60*60)).'
445 AND ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table)
446 );
447 }
448
449 /**
450 * This returns the where-clause needed to select the user with respect flags like deleted, hidden, starttime, endtime
451 *
452 * @return string
453 * @access private
454 */
455 function user_where_clause() {
456 return (($this->enablecolumns['rootLevel']) ? 'AND '.$this->user_table.'.pid=0 ' : '').
457 (($this->enablecolumns['disabled']) ? ' AND '.$this->user_table.'.'.$this->enablecolumns['disabled'].'=0' : '').
458 (($this->enablecolumns['deleted']) ? ' AND '.$this->user_table.'.'.$this->enablecolumns['deleted'].'=0' : '').
459 (($this->enablecolumns['starttime']) ? ' AND ('.$this->user_table.'.'.$this->enablecolumns['starttime'].'<='.time().')' : '').
460 (($this->enablecolumns['endtime']) ? ' AND ('.$this->user_table.'.'.$this->enablecolumns['endtime'].'=0 OR '.$this->user_table.'.'.$this->enablecolumns['endtime'].'>'.time().')' : '');
461 }
462
463 /**
464 * This returns the where-clause needed to lock a user to the IP address
465 *
466 * @return string
467 * @access private
468 */
469 function ipLockClause() {
470 if ($this->lockIP) {
471 $wherePart = 'AND (
472 '.$this->session_table.'.ses_iplock='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->ipLockClause_remoteIPNumber($this->lockIP),$this->session_table).'
473 OR '.$this->session_table.'.ses_iplock=\'[DISABLED]\'
474 )';
475 return $wherePart;
476 }
477 }
478
479 /**
480 * Returns the IP address to lock to.
481 * The IP address may be partial based on $parts.
482 *
483 * @param integer 1-4: Indicates how many parts of the IP address to return. 4 means all, 1 means only first number.
484 * @return string (Partial) IP address for REMOTE_ADDR
485 * @access private
486 */
487 function ipLockClause_remoteIPNumber($parts) {
488 $IP = t3lib_div::getIndpEnv('REMOTE_ADDR');
489
490 if ($parts>=4) {
491 return $IP;
492 } else {
493 $parts = t3lib_div::intInRange($parts,1,3);
494 $IPparts = explode('.',$IP);
495 for($a=4;$a>$parts;$a--) {
496 unset($IPparts[$a-1]);
497 }
498 return implode('.',$IPparts);
499 }
500 }
501
502 /**
503 * This returns the where-clause needed to lock a user to a hash integer
504 *
505 * @return string
506 * @access private
507 */
508 function hashLockClause() {
509 $wherePart = 'AND '.$this->session_table.'.ses_hashlock='.intval($this->hashLockClause_getHashInt());
510 return $wherePart;
511 }
512
513 /**
514 * Creates hash integer to lock user to. Depends on configured keywords
515 *
516 * @return integer Hash integer
517 * @access private
518 */
519 function hashLockClause_getHashInt() {
520 $hashStr = '';
521
522 if (t3lib_div::inList($this->lockHashKeyWords,'useragent')) $hashStr.=':'.t3lib_div::getIndpEnv('HTTP_USER_AGENT');
523
524 return t3lib_div::md5int($hashStr);
525 }
526
527 /**
528 * This writes $variable to the user-record. This is a way of providing session-data.
529 * You can fetch the data again through $this->uc in this class!
530 * If $variable is not an array, $this->uc is saved!
531 *
532 * @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
533 * @return void
534 */
535 function writeUC($variable='') {
536 if (is_array($this->user) && $this->user['uid']) {
537 if (!is_array($variable)) { $variable = $this->uc; }
538
539 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($this->user_table, 'uid='.intval($this->user['uid']), array('uc' => serialize($variable)));
540 }
541 }
542
543 /**
544 * DUMMY: Writes to log database table (in some extension classes)
545 *
546 * @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
547 * @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 !!)
548 * @param integer $error: flag. 0 = message, 1 = error (user problem), 2 = System Error (which should not happen), 3 = security notice (admin)
549 * @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
550 * @param string $details: Default text that follows the message
551 * @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...
552 * @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.)
553 * @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.)
554 * @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.)
555 * @return void
556 * @see t3lib_userauthgroup::writelog()
557 */
558 function writelog($type,$action,$error,$details_nr,$details,$data,$tablename,$recuid,$recpid) {
559 }
560
561 /**
562 * DUMMY: Check login failures (in some extension classes)
563 *
564 * @return void
565 * @ignore
566 */
567 function checkLogFailures() {
568 }
569
570 /**
571 * 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
572 *
573 * @param mixed If an array, then set as ->uc, otherwise load from user record
574 * @return void
575 */
576 function unpack_uc($theUC='') {
577 if (!$theUC) $theUC=unserialize($this->user['uc']);
578 if (is_array($theUC)) {
579 $this->uc=$theUC;
580 }
581 }
582
583 /**
584 * Stores data for a module.
585 * 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.
586 *
587 * @param string $module is the name of the module ($MCONF['name'])
588 * @param mixed $data is the data you want to store for that module (array, string, ...)
589 * @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.
590 * @return void
591 */
592 function pushModuleData($module,$data,$noSave=0) {
593 $this->uc['moduleData'][$module] = $data;
594 $this->uc['moduleSessionID'][$module] = $this->id;
595 if (!$noSave) $this->writeUC();
596 }
597
598 /**
599 * Gets module data for a module (from a loaded ->uc array)
600 *
601 * @param string $module is the name of the module ($MCONF['name'])
602 * @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).
603 * @return mixed The module data if available: $this->uc['moduleData'][$module];
604 */
605 function getModuleData($module,$type='') {
606 if ($type!='ses' || $this->uc['moduleSessionID'][$module]==$this->id) {
607 return $this->uc['moduleData'][$module];
608 }
609 }
610
611 /**
612 * Returns the session data stored for $key.
613 * The data will last only for this login session since it is stored in the session table.
614 *
615 * @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.
616 * @return mixed
617 */
618 function getSessionData($key) {
619 $sesDat = unserialize($this->user['ses_data']);
620 return $sesDat[$key];
621 }
622
623 /**
624 * Sets the session data ($data) for $key and writes all session data (from ->user['ses_data']) to the database.
625 * The data will last only for this login session since it is stored in the session table.
626 *
627 * @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.
628 * @param mixed The variable to store in index $key
629 * @return void
630 */
631 function setAndSaveSessionData($key,$data) {
632 $sesDat = unserialize($this->user['ses_data']);
633 $sesDat[$key] = $data;
634 $this->user['ses_data'] = serialize($sesDat);
635
636 $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']));
637 }
638
639 /**
640 * Raw initialization of the be_user with uid=$uid
641 * 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.
642 * Will check the users for disabled, start/endtime, etc. ($this->user_where_clause())
643 *
644 * @param integer The UID of the backend user to set in ->user
645 * @return void
646 * @params integer 'uid' of be_users record to select and set.
647 * @internal
648 * @see SC_mod_tools_be_user_index::compareUsers(), SC_mod_user_setup_index::simulateUser(), freesite_admin::startCreate()
649 */
650 function setBeUserByUid($uid) {
651 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->user_table, 'uid='.intval($uid).' '.$this->user_where_clause());
652 $this->user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
653 }
654
655 /**
656 * Raw initialization of the be_user with username=$name
657 *
658 * @param string The username to look up.
659 * @return void
660 * @see t3lib_userAuth::setBeUserByUid()
661 * @internal
662 */
663 function setBeUserByName($name) {
664 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->user_table, 'username='.$GLOBALS['TYPO3_DB']->fullQuoteStr($name, $this->user_table).' '.$this->user_where_clause());
665 $this->user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
666 }
667 }
668
669
670
671 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauth.php']) {
672 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauth.php']);
673 }
674 ?>