First CVS update in a long time - see the top of changelog. In particular the foundat...
[Packages/TYPO3.CMS.git] / typo3 / index.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 * Login-screen of TYPO3.
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 December/2003 by Kasper Skaarhoj
32 * XHTML compliant
33 *
34 * @author Kasper Skaarhoj <kasper@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 87: class SC_index
42 * 120: function init()
43 * 151: function main()
44 * 237: function printContent()
45 *
46 * SECTION: Various functions
47 * 261: function makeLoginForm()
48 * 304: function makeLogoutForm()
49 * 346: function wrapLoginForm($content)
50 * 406: function checkRedirect()
51 * 449: function makeInterfaceSelectorBox()
52 * 503: function makeCopyrightNotice()
53 * 536: function makeLoginBoxImage()
54 * 575: function makeLoginNews()
55 *
56 * TOTAL FUNCTIONS: 11
57 * (This index is automatically created/updated by the extension "extdeveval")
58 *
59 */
60
61
62 define('TYPO3_PROCEED_IF_NO_USER', 1);
63 require ('init.php');
64 require ('template.php');
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 /**
81 * Script Class for rendering the login form
82 *
83 * @author Kasper Skaarhoj <kasper@typo3.com>
84 * @package TYPO3
85 * @subpackage core
86 */
87 class SC_index {
88
89 // Internal, GPvars:
90 var $redirect_url; // GPvar: redirect_url; The URL to redirect to after login.
91 var $GPinterface; // GPvar: Defines which interface to load (from interface selector)
92 var $u; // GPvar: preset username
93 var $p; // GPvar: preset password
94 var $L; // GPvar: If "L" is "OUT", then any logged in used is logged out. If redirect_url is given, we redirect to it
95 var $loginRefresh; // Login-refresh boolean; The backend will call this script with this value set when the login is close to being expired and the form needs to be redrawn.
96 var $commandLI; // Value of forms submit button for login.
97
98 // Internal, static:
99 var $redirectToURL; // Set to the redirect URL of the form (may be redirect_url or "alt_main.php")
100 var $L_vars; // Set to the labels used for the login screen.
101
102 // Internal, dynamic:
103 var $interfaceSelector; // If set tru, if there is a redirect URL
104 var $content; // Content accumulation
105
106 var $interfaceSelector; // A selector box for selecting value for "interface" may be rendered into this variable
107 var $interfaceSelector_jump; // A selector box for selecting value for "interface" may be rendered into this variable - this will have an onchange action which will redirect the user to the selected interface right away
108 var $interfaceSelector_hidden; // A hidden field, if the interface is not set.
109
110
111
112
113
114
115 /**
116 * Initialize the login box. Will also react on a &L=OUT flag and exit.
117 *
118 * @return void
119 */
120 function init() {
121 global $BE_USER,$TYPO3_CONF_VARS;
122
123 // GPvars:
124 $this->redirect_url = t3lib_div::_GP('redirect_url');
125 $this->GPinterface = t3lib_div::_GP('interface');
126 $this->u = t3lib_div::_GP('u'); // preset username
127 $this->p = t3lib_div::_GP('p'); // preset password
128 $this->L = t3lib_div::_GP('L'); // If "L" is "OUT", then any logged in used is logged out. If redirect_url is given, we redirect to it
129 $this->loginRefresh = t3lib_div::_GP('loginRefresh'); // Login
130 $this->commandLI = t3lib_div::_GP('commandLI'); // Value of "Login" button. If set, the login button was pressed.
131
132 // Getting login labels:
133 $this->L_vars = explode('|',$TYPO3_CONF_VARS['BE']['loginLabels']);
134
135 // Setting the redirect URL to "alt_main.php" if no alternative input is given:
136 $this->redirectToURL = $this->redirect_url ? $this->redirect_url : 'alt_main.php';
137
138 // Logout?
139 if ($this->L=='OUT' && is_object($BE_USER)) {
140 $BE_USER->logoff();
141 if ($this->redirect_url) header('Location: '.t3lib_div::locationHeaderUrl($this->redirect_url));
142 exit;
143 }
144 }
145
146 /**
147 * Main function - creating the login/logout form
148 *
149 * @return void
150 */
151 function main() {
152 global $TBE_TEMPLATE, $TYPO3_CONF_VARS, $BE_USER;
153
154 // Initialize template object:
155 $TBE_TEMPLATE->docType='xhtml_trans';
156
157 // Set JavaScript for creating a MD5 hash of the password:
158 $TBE_TEMPLATE->JScode.='
159 <script type="text/javascript" src="md5.js"></script>
160 '.$TBE_TEMPLATE->wrapScriptTags('
161 function doChallengeResponse() { //
162 password = document.loginform.p_field.value;
163 if (password) {
164 password = MD5(password); // this makes it superchallenged!!
165 str = document.loginform.username.value+":"+password+":"+document.loginform.challenge.value;
166 document.loginform.userident.value = MD5(str);
167 document.loginform.p_field.value = "";
168 return true;
169 }
170 }
171 ');
172
173
174 // Checking, if we should make a redirect.
175 // Might set JavaScript in the header to close window.
176 $this->checkRedirect();
177
178 // Initialize interface selectors:
179 $this->makeInterfaceSelectorBox();
180
181 // Creating form based on whether there is a login or not:
182 if (!$BE_USER->user['uid']) {
183 $TBE_TEMPLATE->form = '
184 <form action="index.php" method="post" name="loginform" onsubmit="doChallengeResponse();">
185 <input type="hidden" name="login_status" value="login" />
186 ';
187 $loginForm = $this->makeLoginForm();
188 } else {
189 $TBE_TEMPLATE->form = '
190 <form action="index.php" method="post" name="loginform">
191 <input type="hidden" name="login_status" value="logout" />
192 ';
193 $loginForm = $this->makeLogoutForm();
194 }
195
196
197 // Starting page:
198 $this->content.=$TBE_TEMPLATE->startPage('TYPO3 Login: '.$TYPO3_CONF_VARS['SYS']['sitename']);
199
200 // Add login form:
201 $this->content.=$this->wrapLoginForm($loginForm);
202
203 // Ending form:
204 $this->content.= '
205 <input type="hidden" name="userident" value="" />
206 <input type="hidden" name="challenge" value="'.md5(uniqid('')).'" />
207 <input type="hidden" name="redirect_url" value="'.htmlspecialchars($this->redirectToURL).'" />
208 <input type="hidden" name="loginRefresh" value="'.htmlspecialchars($this->loginRefresh).'" />
209 '.$this->interfaceSelector_hidden.'
210 ';
211
212 // This moves focus to the right input field:
213 $this->content.=$TBE_TEMPLATE->wrapScriptTags('
214
215 // If the login screen is shown in the login_frameset window for re-login, then try to get the username of the current/former login from opening windows main frame:
216 if (parent.opener && parent.opener.TS && parent.opener.TS.username && document.loginform && document.loginform.username) {
217 document.loginform.username.value = parent.opener.TS.username;
218 }
219
220 // If for some reason there already is a username in the username for field, move focus to the password field:
221 if (document.loginform.username && document.loginform.username.value == "") {
222 document.loginform.username.focus();
223 } else if (document.loginform.p_field && document.loginform.p_field.type!="hidden") {
224 document.loginform.p_field.focus();
225 }
226 ');
227
228 // End page:
229 $this->content.=$TBE_TEMPLATE->endPage();
230 }
231
232 /**
233 * Outputting the accumulated content to screen
234 *
235 * @return void
236 */
237 function printContent() {
238
239 echo $this->content;
240 }
241
242
243
244
245
246
247
248
249 /*****************************
250 *
251 * Various functions
252 *
253 ******************************/
254
255 /**
256 * Creates the login form
257 * This is drawn when NO login exists.
258 *
259 * @return string HTML output
260 */
261 function makeLoginForm() {
262
263 $content.='
264
265 <!--
266 Login form:
267 -->
268 <table cellspacing="0" cellpadding="0" border="0" id="logintable">
269 <tr>
270 <td colspan="2"><h2>'.htmlspecialchars($this->L_vars[6]).'</h2></td>
271 </tr>
272 <tr class="c-username">
273 <td><p class="c-username">'.htmlspecialchars($this->L_vars[0]).':</p></td>
274 <td><input type="text" name="username" value="'.htmlspecialchars($this->u).'" class="c-username" /></td>
275 </tr>
276 <tr class="c-password">
277 <td><p class="c-password">'.htmlspecialchars($this->L_vars[1]).':</p></td>
278 <td><input type="password" name="p_field" value="'.htmlspecialchars($this->p).'" class="c-password" /></td>
279 </tr>'.($this->interfaceSelector && !$this->loginRefresh ? '
280 <tr class="c-interfaceselector">
281 <td><p class="c-interfaceselector">'.htmlspecialchars($this->L_vars[2]).':</p></td>
282 <td>'.$this->interfaceSelector.'</td>
283 </tr>' : '' ).'
284 <tr class="c-submit">
285 <td></td>
286 <td><input type="submit" name="commandLI" value="'.htmlspecialchars($this->L_vars[3]).'" class="c-submit" /></td>
287 </tr>
288 <tr class="c-info">
289 <td></td>
290 <td><p class="c-info">'.htmlspecialchars($this->L_vars[7]).'</p></td>
291 </tr>
292 </table>';
293
294 // Return content:
295 return $content;
296 }
297
298 /**
299 * Creates the logout form
300 * This is drawn if a user login already exists.
301 *
302 * @return string HTML output
303 */
304 function makeLogoutForm() {
305 global $BE_USER;
306
307
308 $content.='
309
310 <!--
311 Login form:
312 -->
313 <table cellspacing="0" cellpadding="0" border="0" id="logintable">
314 <tr>
315 <td></td>
316 <td><h2>'.htmlspecialchars($this->L_vars[6]).'</h2></td>
317 </tr>
318 <tr class="c-username">
319 <td><p class="c-username">'.htmlspecialchars($this->L_vars[0]).':</p></td>
320 <td><p class="c-username-current">'.htmlspecialchars($BE_USER->user['username']).'</p></td>
321 </tr>'.($this->interfaceSelector_jump ? '
322 <tr class="c-interfaceselector">
323 <td><p class="c-interfaceselector">'.htmlspecialchars($this->L_vars[2]).':</p></td>
324 <td>'.$this->interfaceSelector_jump.'</td>
325 </tr>' : '' ).'
326 <tr class="c-submit">
327 <td><input type="hidden" name="p_field" value="" /></td>
328 <td><input type="submit" name="commandLO" value="'.htmlspecialchars($this->L_vars[4]).'" class="c-submit" /></td>
329 </tr>
330 <tr class="c-info">
331 <td></td>
332 <td><p class="c-info">'.htmlspecialchars($this->L_vars[7]).'</p></td>
333 </tr>
334 </table>';
335
336 // Return content:
337 return $content;
338 }
339
340 /**
341 * Wrapping the login form table in another set of tables etc:
342 *
343 * @param string HTML content for the login form
344 * @return string The HTML for the page.
345 */
346 function wrapLoginForm($content) {
347
348 // Logo:
349 $logo = $GLOBALS['TBE_STYLES']['logo_login'] ?
350 '<img src="'.htmlspecialchars($GLOBALS['BACK_PATH'].$GLOBALS['TBE_STYLES']['logo_login']).'" alt="" />' :
351 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/typo3logo.gif','width="333" height="43"').' alt="" />';
352
353 // Login box image:
354 $loginboxImage = $this->makeLoginBoxImage();
355
356 // Compile the page content:
357 $content='
358
359 <!--
360 Wrapper table for the login form:
361 -->
362 <table cellspacing="0" cellpadding="0" border="0" id="wrapper">
363 <tr>
364 <td class="c-wrappercell" align="center">
365
366 <!--
367 Login form image:
368 -->
369 <div id="loginimage">
370 '.$logo.'
371 </div>
372
373 <!--
374 Login form wrapper:
375 -->
376 <table cellspacing="0" cellpadding="0" border="0" id="loginwrapper">
377 <tr>
378 <td>'.$loginboxImage.'</td>
379 <td>
380 '.$content.'
381 </td>
382 </tr>
383 </table>
384
385 <!--
386 Copy right notice:
387 -->
388 <div id="copyrightnotice">
389 '.$this->makeCopyrightNotice().'
390 </div>
391
392 '.$this->makeLoginNews().'
393 </td>
394 </tr>
395 </table>';
396
397 // Return content:
398 return $content;
399 }
400
401 /**
402 * Checking, if we should perform some sort of redirection OR closing of windows.
403 *
404 * @return void
405 */
406 function checkRedirect() {
407 global $BE_USER,$TBE_TEMPLATE;
408
409 // Do redirect:
410 // If a user is logged in AND a) if either the login is just done (commandLI) or b) a loginRefresh is done or c) the interface-selector is NOT enabled (If it is on the other hand, it should not just load an interface, because people has to choose then...)
411 if ($BE_USER->user['uid'] && ($this->commandLI || $this->loginRefresh || !$this->interfaceSelector)) {
412
413 // If no cookie has been set previously we tell people that this is a problem. This assumes that a cookie-setting script (like this one) has been hit at least once prior to this instance.
414 if (!$GLOBALS['HTTP_COOKIE_VARS'][$BE_USER->name]) {
415 t3lib_BEfunc::typo3PrintError ('Login-error',"Yeah, that's a classic. No cookies, no TYPO3.<br /><br />Please accept cookies from TYPO3 - otherwise you'll not be able to use the system.",0);
416 exit;
417 }
418
419 // Based on specific setting of interface we set the redirect script:
420 switch ($this->GPinterface) {
421 case 'backend':
422 $this->redirectToURL = 'alt_main.php';
423 break;
424 case 'frontend':
425 $this->redirectToURL = '../';
426 break;
427 }
428
429 // If there is a redirect URL AND if loginRefresh is not set...
430 if (!$this->loginRefresh) {
431 header('Location: '.t3lib_div::locationHeaderUrl($this->redirectToURL));
432 exit;
433 } else {
434 $TBE_TEMPLATE->JScode.=$TBE_TEMPLATE->wrapScriptTags('
435 if (parent.opener && parent.opener.busy) {
436 parent.opener.busy.loginRefreshed();
437 parent.close();
438 }
439 ');
440 }
441 }
442 }
443
444 /**
445 * Making interface selector:
446 *
447 * @return void
448 */
449 function makeInterfaceSelectorBox() {
450 global $TYPO3_CONF_VARS;
451
452 // Reset variables:
453 $this->interfaceSelector = '';
454 $this->interfaceSelector_hidden='';
455 $this->interfaceSelector_jump = '';
456 #debug($this->redirect_url);
457 // If interfaces are defined AND no input redirect URL in GET vars:
458 if ($TYPO3_CONF_VARS['BE']['interfaces'] && !$this->redirect_url) {
459 $parts = t3lib_div::trimExplode(',',$TYPO3_CONF_VARS['BE']['interfaces']);
460 if (count($parts)>1) { // Only if more than one interface is defined will we show the selector:
461
462 // Initialize:
463 $tempLabels=explode(',',$this->L_vars[5]);
464 $labels=array();
465 $labels['backend']=$tempLabels[0];
466 $labels['frontend']=$tempLabels[1];
467
468 $jumpScript=array();
469 $jumpScript['backend']='alt_main.php';
470 $jumpScript['frontend']='../';
471
472 // Traverse the interface keys:
473 foreach($parts as $valueStr) {
474 $this->interfaceSelector.='
475 <option value="'.htmlspecialchars($valueStr).'">'.htmlspecialchars($labels[$valueStr]).'</option>';
476 $this->interfaceSelector_jump.='
477 <option value="'.htmlspecialchars($jumpScript[$valueStr]).'">'.htmlspecialchars($labels[$valueStr]).'</option>';
478 }
479 $this->interfaceSelector='
480 <select name="interface" class="c-interfaceselector">'.$this->interfaceSelector.'
481 </select>';
482 $this->interfaceSelector_jump='
483 <select name="interface" class="c-interfaceselector" onchange="document.location=this.options[this.selectedIndex].value;">'.$this->interfaceSelector_jump.'
484 </select>';
485
486 } else { // If there is only ONE interface value set:
487
488 $this->interfaceSelector_hidden='<input type="hidden" name="interface" value="'.trim($TYPO3_CONF_VARS['BE']['interfaces']).'" />';
489 }
490 }
491 }
492
493 /**
494 * COPYRIGHT notice
495 *
496 * Warning:
497 * DO NOT prevent this notice from being shown in ANY WAY.
498 * According to the GPL license an interactive application must show such a notice on start-up ('If the program is interactive, make it output a short notice... ' - see GPL.txt)
499 * Therefore preventing this notice from being properly shown is a violation of the license, regardless of whether you remove it or use a stylesheet to obstruct the display.
500 *
501 * @return string Text/Image (HTML) for copyright notice.
502 */
503 function makeCopyrightNotice() {
504
505 // Get values from TYPO3_CONF_VARS:
506 $loginCopyrightWarrantyProvider = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyProvider']));
507 $loginCopyrightWarrantyURL = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyURL']));
508
509 // Make warranty note:
510 if (strlen($loginCopyrightWarrantyProvider)>=2 && strlen($loginCopyrightWarrantyURL)>=10) {
511 $warrantyNote='Warranty is supplied by '.htmlspecialchars($loginCopyrightWarrantyProvider).'; <a href="'.htmlspecialchars($loginCopyrightWarrantyURL).'" target="_blank">click for details.</a>';
512 } else {
513 $warrantyNote='TYPO3 comes with ABSOLUTELY NO WARRANTY; <a href="http://typo3.com/1316.0.html" target="_blank">click for details.</a>';
514 }
515
516 // Compile full copyright notice:
517 $copyrightNotice = '<a href="http://typo3.com/" target="_blank">'.
518 '<img src="gfx/loginlogo_transp.gif" width="75" height="19" alt="TYPO3 logo" align="left" />'.
519 'TYPO3 CMS'.($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightShowVersion']?' ver. '.htmlspecialchars($GLOBALS['TYPO_VERSION']):'').
520 '</a>. '.
521 'Copyright &copy; 1998-2004 Kasper Sk&#229;rh&#248;j. Extensions are copyright of their respective owners. '.
522 'Go to <a href="http://typo3.com/" target="_blank">http://typo3.com/</a> for details. '.
523 $warrantyNote.' '.
524 'This is free software, and you are welcome to redistribute it under certain conditions; <a href="http://typo3.com/1316.0.html" target="_blank">click for details</a>. '.
525 'Obstructing the appearance of this notice is prohibited by law.';
526
527 // Return notice:
528 return $copyrightNotice;
529 }
530
531 /**
532 * Returns the login box image, whether the default or an image from the rotation folder.
533 *
534 * @return string HTML image tag.
535 */
536 function makeLoginBoxImage() {
537 $loginboxImage = '';
538 if ($GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder']) { // Look for rotation image folder:
539 $absPath = t3lib_div::resolveBackPath(PATH_typo3.$GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder']);
540
541 // Get rotation folder:
542 $dir = t3lib_div::getFileAbsFileName($absPath);
543 if ($dir && @is_dir($dir)) {
544
545 // Get files for rotation into array:
546 $files = t3lib_div::getFilesInDir($dir,'png,jpg,gif');
547
548 // Pick random file:
549 srand((float) microtime() * 10000000);
550 $randImg = array_rand($files, 1);
551
552 // Get size of random file:
553 $imgSize = @getimagesize($dir.$files[$randImg]);
554
555 // Create image tag:
556 if (is_array($imgSize)) {
557 $loginboxImage = '<img src="'.htmlspecialchars($GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder'].$files[$randImg]).'" '.$imgSize[3].' id="loginbox-image" alt="" />';
558 }
559 }
560 } else { // If no rotation folder configured, print default image:
561 $imagecopy = 'Photo: &copy; 2004 Kasper Sk&#229;rh&#248;j'; // Directly outputted in image attributes...
562 $loginboxImage = '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/loginbox_image_360rc2.jpg','width="200" height="133"').' id="loginbox-image" alt="'.$imagecopy.'" title="'.$imagecopy.'" />';
563 }
564
565 // Return image tag:
566 return $loginboxImage;
567 }
568
569 /**
570 * Make login news - renders the HTML content for a list of news shown under the login form. News data is added through $TYPO3_CONF_VARS
571 *
572 * @return string HTML content
573 * @credits Idea by Jan-Hendrik Heuing
574 */
575 function makeLoginNews() {
576
577 // Reset output variable:
578 $newsContent= '';
579
580 // Traverse news array IF there are records in it:
581 if (is_array($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews']) && count($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'])) {
582 foreach($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'] as $newsItem) {
583 $newsContent.='
584 <tr>
585 <td class="c-date">'.htmlspecialchars($newsItem['date']).'</td>
586 <td class="c-header">'.htmlspecialchars($newsItem['header']).'</td>
587 </tr>
588 <tr>
589 <td></td>
590 <td class="c-content">'.trim($newsItem['content']).'</td>
591 </tr>
592 <tr class="c-spacer">
593 <td colspan="2"></td>
594 </tr>
595 ';
596 }
597
598 // Wrap in a table:
599 $newsContent= '
600
601 <!--
602 Login screen news:
603 -->
604 <div id="loginNews">
605 <h2>'.htmlspecialchars($this->L_vars[8]).'</h2>
606 <table border="0" cellpadding="0" cellspacing="0">
607 '.$newsContent.'
608 </table>
609 </div>
610 ';
611 }
612
613 // Return content:
614 return $newsContent;
615 }
616 }
617
618 // Include extension?
619 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/index.php']) {
620 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/index.php']);
621 }
622
623
624
625
626
627
628
629
630
631
632 // Make instance:
633 $SOBE = t3lib_div::makeInstance('SC_index');
634 $SOBE->init();
635 $SOBE->main();
636 $SOBE->printContent();
637 ?>