2 /***************************************************************
5 * (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Login-screen of TYPO3.
31 * Revised for TYPO3 3.6 December/2003 by Kasper Skaarhoj
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
37 * [CLASS/FUNCTION INDEX of SCRIPT]
42 * 120: function init()
43 * 159: function main()
44 * 268: function printContent()
46 * SECTION: Various functions
47 * 292: function makeLoginForm()
48 * 337: function makeLogoutForm()
49 * 379: function wrapLoginForm($content)
50 * 438: function checkRedirect()
51 * 495: function makeInterfaceSelectorBox()
52 * 549: function makeCopyrightNotice()
53 * 582: function makeLoginBoxImage()
54 * 622: function makeLoginNews()
57 * (This index is automatically created/updated by the extension "extdeveval")
62 define('TYPO3_PROCEED_IF_NO_USER', 1);
64 require ('template.php');
81 * Script Class for rendering the login form
83 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
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.
99 var $redirectToURL; // Set to the redirect URL of the form (may be redirect_url or "backend.php")
100 var $L_vars; // Set to the labels used for the login screen.
102 // Internal, dynamic:
103 var $content; // Content accumulation
105 var $interfaceSelector; // A selector box for selecting value for "interface" may be rendered into this variable
106 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
107 var $interfaceSelector_hidden; // A hidden field, if the interface is not set.
108 var $addFields_hidden = ''; // Additional hidden fields to be placed at the login form
110 // sets the level of security. *'normal' = clear-text. 'challenged' = hashed password/username from form in $formfield_uident. 'superchallenged' = hashed password hashed again with username.
111 var $loginSecurityLevel = 'superchallenged';
117 * Initialize the login box. Will also react on a &L=OUT flag and exit.
122 global $BE_USER,$TYPO3_CONF_VARS;
125 $this->redirect_url
= t3lib_div
::_GP('redirect_url');
126 $this->GPinterface
= t3lib_div
::_GP('interface');
128 if(t3lib_div
::getIndpEnv('TYPO3_SSL')) { // For security reasons this feature only works if SSL is used
129 $this->u
= t3lib_div
::_GP('u'); // preset username
130 $this->p
= t3lib_div
::_GP('p'); // preset password
132 $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
133 $this->loginRefresh
= t3lib_div
::_GP('loginRefresh'); // Login
134 $this->commandLI
= t3lib_div
::_GP('commandLI'); // Value of "Login" button. If set, the login button was pressed.
136 // sets the level of security from conf vars
137 if ($TYPO3_CONF_VARS['BE']['loginSecurityLevel']) {
138 $this->loginSecurityLevel
= $TYPO3_CONF_VARS['BE']['loginSecurityLevel'];
141 // Getting login labels:
142 $this->L_vars
= explode('|',$TYPO3_CONF_VARS['BE']['loginLabels']);
144 // Setting the redirect URL to "backend.php" if no alternative input is given:
145 $this->redirectToURL
= $this->redirect_url ?
$this->redirect_url
: 'backend.php';
148 if ($this->L
=='OUT' && is_object($BE_USER)) {
150 if ($this->redirect_url
) header('Location: '.t3lib_div
::locationHeaderUrl($this->redirect_url
));
156 * Main function - creating the login/logout form
161 global $TBE_TEMPLATE, $TYPO3_CONF_VARS, $BE_USER;
163 // Initialize template object:
164 $TBE_TEMPLATE->docType
='xhtml_trans';
165 $TBE_TEMPLATE->bodyTagAdditions
= ' onload="startUp();"';
167 // Set JavaScript for creating a MD5 hash of the password:
168 $TBE_TEMPLATE->JScode
.= $this->getJScode();
170 // Checking, if we should make a redirect.
171 // Might set JavaScript in the header to close window.
172 $this->checkRedirect();
174 // Initialize interface selectors:
175 $this->makeInterfaceSelectorBox();
177 // Replace an optional marker in the "Administration Login" label
178 $this->L_vars
[6] = str_replace("###SITENAME###",$TYPO3_CONF_VARS['SYS']['sitename'],$this->L_vars
[6]);
180 // Creating form based on whether there is a login or not:
181 if (!$BE_USER->user
['uid']) {
182 $TBE_TEMPLATE->form
= $this->startForm();
183 $loginForm = $this->makeLoginForm();
185 $TBE_TEMPLATE->form
= '
186 <form action="index.php" method="post" name="loginform">
187 <input type="hidden" name="login_status" value="logout" />
189 $loginForm = $this->makeLogoutForm();
193 $this->content
.=$TBE_TEMPLATE->startPage('TYPO3 Login: '.$TYPO3_CONF_VARS['SYS']['sitename']);
196 $this->content
.=$this->wrapLoginForm($loginForm);
198 // Create a random challenge string
199 $challenge = $this->getChallenge();
201 // Save challenge value in session data (thanks to Bernhard Kraft for providing code):
203 $_SESSION['login_challenge'] = $challenge;
205 // Add hidden fields:
206 $this->content
.= $this->getHiddenFields($challenge);
209 $this->content
.=$TBE_TEMPLATE->endPage();
213 * Outputting the accumulated content to screen
217 function printContent() {
228 /*****************************
232 ******************************/
235 * Creates the login form
236 * This is drawn when NO login exists.
238 * @return string HTML output
240 function makeLoginForm() {
242 // There must be no white-spaces outside of the tags (needed for buggy IE)
245 --><table cellspacing="0" cellpadding="0" border="0" id="logintable">
247 <td colspan="2"><h2>'.htmlspecialchars($this->L_vars
[6]).'</h2></td>
248 </tr>'.($this->commandLI ?
'
250 <td colspan="2"><p class="c-wrong">'.htmlspecialchars($this->L_vars
[9]).'</p></td>
252 <tr class="c-username">
253 <td><label for="username" class="c-username">'.htmlspecialchars($this->L_vars
[0]).':</label></td>
254 <td><input type="text" id="username" name="username" value="'.htmlspecialchars($this->u
).'" class="c-username" /></td>
256 <tr class="c-password">
257 <td><label for="password" class="c-password">'.htmlspecialchars($this->L_vars
[1]).':</label></td>
258 <td><input type="password" id="password" name="p_field" value="'.htmlspecialchars($this->p
).'" class="c-password" /></td>
259 </tr>'.($this->interfaceSelector
&& !$this->loginRefresh ?
'
260 <tr class="c-interfaceselector">
261 <td><label for="interfaceselector" class="c-interfaceselector">'.htmlspecialchars($this->L_vars
[2]).':</label></td>
262 <td>'.$this->interfaceSelector
.'</td>
264 <tr class="c-submit">
266 <td><input type="submit" name="commandLI" value="'.htmlspecialchars($this->L_vars
[3]).'" class="c-submit" /></td>
269 <td colspan="2"><p class="c-info">'.htmlspecialchars($this->L_vars
[7]).'</p></td>
278 * Creates the logout form
279 * This is drawn if a user login already exists.
281 * @return string HTML output
283 function makeLogoutForm() {
291 <table cellspacing="0" cellpadding="0" border="0" id="logintable">
294 <td><h2>'.htmlspecialchars($this->L_vars
[6]).'</h2></td>
296 <tr class="c-username">
297 <td><p class="c-username">'.htmlspecialchars($this->L_vars
[0]).':</p></td>
298 <td><p class="c-username-current">'.htmlspecialchars($BE_USER->user
['username']).'</p></td>
299 </tr>'.($this->interfaceSelector_jump ?
'
300 <tr class="c-interfaceselector">
301 <td><p class="c-interfaceselector">'.htmlspecialchars($this->L_vars
[2]).':</p></td>
302 <td>'.$this->interfaceSelector_jump
.'</td>
304 <tr class="c-submit">
305 <td><input type="hidden" name="p_field" value="" /></td>
306 <td><input type="submit" name="commandLO" value="'.htmlspecialchars($this->L_vars
[4]).'" class="c-submit" /></td>
310 <td><p class="c-info">'.htmlspecialchars($this->L_vars
[7]).'</p></td>
319 * Wrapping the login form table in another set of tables etc:
321 * @param string HTML content for the login form
322 * @return string The HTML for the page.
324 function wrapLoginForm($content) {
327 $logo = $GLOBALS['TBE_STYLES']['logo_login'] ?
328 '<img src="'.htmlspecialchars($GLOBALS['BACK_PATH'].$GLOBALS['TBE_STYLES']['logo_login']).'" alt="" />' :
329 '<img'.t3lib_iconWorks
::skinImg($GLOBALS['BACK_PATH'],'gfx/typo3logo.gif','width="123" height="34"').' alt="" />';
332 $loginboxImage = $this->makeLoginBoxImage();
334 // Compile the page content:
338 Wrapper table for the login form:
340 <table cellspacing="0" cellpadding="0" border="0" id="wrapper">
342 <td class="c-wrappercell" align="center">
347 <div id="loginimage">
354 <table cellspacing="0" cellpadding="0" border="0" id="loginwrapper">
356 <td'.($this->commandLI ?
' class="error"' : '').'>'.$loginboxImage.
362 '.$this->makeLoginNews().'
366 <div id="copyrightnotice">
367 '.$this->makeCopyrightNotice().'
380 * Checking, if we should perform some sort of redirection OR closing of windows.
384 function checkRedirect() {
385 global $BE_USER,$TBE_TEMPLATE;
388 // 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...)
389 if ($BE_USER->user
['uid'] && ($this->commandLI ||
$this->loginRefresh ||
!$this->interfaceSelector
)) {
391 // 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.
392 if (!$_COOKIE[$BE_USER->name
]) {
393 if ($this->commandLI
=='setCookie') {
394 // we tried it a second time but still no cookie
395 // 26/4 2005: This does not work anymore, because the saving of challenge values in $_SESSION means the system will act as if the password was wrong.
396 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);
399 // try it once again - that might be needed for auto login
400 $this->redirectToURL
= 'index.php?commandLI=setCookie';
404 if ($redirectToURL = (string)$BE_USER->getTSConfigVal('auth.BE.redirectToURL')) {
405 $this->redirectToURL
= $redirectToURL;
406 $this->GPinterface
= '';
410 $BE_USER->uc
['interfaceSetup'] = $this->GPinterface
;
413 // Based on specific setting of interface we set the redirect script:
414 switch ($this->GPinterface
) {
416 $this->redirectToURL
= 'backend.php';
419 $this->redirectToURL
= 'alt_main.php';
422 $this->redirectToURL
= '../';
426 // If there is a redirect URL AND if loginRefresh is not set...
427 if (!$this->loginRefresh
) {
428 header('Location: '.t3lib_div
::locationHeaderUrl($this->redirectToURL
));
431 $TBE_TEMPLATE->JScode
.=$TBE_TEMPLATE->wrapScriptTags('
432 if (parent.opener && parent.opener.busy) {
433 parent.opener.busy.loginRefreshed();
439 } elseif (!$BE_USER->user
['uid'] && $this->commandLI
) {
440 sleep(5); // Wrong password, wait for 5 seconds
445 * Making interface selector:
449 function makeInterfaceSelectorBox() {
450 global $TYPO3_CONF_VARS;
453 $this->interfaceSelector
= '';
454 $this->interfaceSelector_hidden
='';
455 $this->interfaceSelector_jump
= '';
457 // If interfaces are defined AND no input redirect URL in GET vars:
458 if ($TYPO3_CONF_VARS['BE']['interfaces'] && ($this->commandLI ||
!$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:
463 $tempLabels=explode(',', $this->L_vars
[5]);
466 $labels['backend'] = $tempLabels[0];
467 $labels['backend_old'] = $tempLabels[2];
468 $labels['frontend'] = $tempLabels[1];
471 $jumpScript['backend'] = 'backend.php';
472 $jumpScript['backend_old'] = 'alt_main.php';
473 $jumpScript['frontend'] = '../';
475 // Traverse the interface keys:
476 foreach($parts as $valueStr) {
477 $this->interfaceSelector
.='
478 <option value="'.htmlspecialchars($valueStr).'"'.(t3lib_div
::_GP('interface')==htmlspecialchars($valueStr) ?
' selected="selected"' : '').'>'.htmlspecialchars($labels[$valueStr]).'</option>';
479 $this->interfaceSelector_jump
.='
480 <option value="'.htmlspecialchars($jumpScript[$valueStr]).'">'.htmlspecialchars($labels[$valueStr]).'</option>';
482 $this->interfaceSelector
='
483 <select id="interfaceselector" name="interface" class="c-interfaceselector">'.$this->interfaceSelector
.'
485 $this->interfaceSelector_jump
='
486 <select id="interfaceselector" name="interface" class="c-interfaceselector" onchange="window.location.href=this.options[this.selectedIndex].value;">'.$this->interfaceSelector_jump
.'
489 } else { // If there is only ONE interface value set:
491 $this->interfaceSelector_hidden
='<input type="hidden" name="interface" value="'.trim($TYPO3_CONF_VARS['BE']['interfaces']).'" />';
500 * DO NOT prevent this notice from being shown in ANY WAY.
501 * 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)
502 * 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.
504 * @return string Text/Image (HTML) for copyright notice.
506 function makeCopyrightNotice() {
508 // Get values from TYPO3_CONF_VARS:
509 $loginCopyrightWarrantyProvider = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyProvider']));
510 $loginCopyrightWarrantyURL = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyURL']));
511 $loginImageSmall = (trim($GLOBALS['TBE_STYLES']['loginBoxImageSmall'])) ?
trim($GLOBALS['TBE_STYLES']['loginBoxImageSmall']) : 'gfx/loginlogo_transp.gif';
513 // Make warranty note:
514 if (strlen($loginCopyrightWarrantyProvider)>=2 && strlen($loginCopyrightWarrantyURL)>=10) {
515 $warrantyNote='Warranty is supplied by '.htmlspecialchars($loginCopyrightWarrantyProvider).'; <a href="'.htmlspecialchars($loginCopyrightWarrantyURL).'" target="_blank">click for details.</a>';
517 $warrantyNote='TYPO3 comes with ABSOLUTELY NO WARRANTY; <a href="http://typo3.com/1316.0.html" target="_blank">click for details.</a>';
520 // Compile full copyright notice:
521 $copyrightNotice = '<a href="http://typo3.com/" target="_blank">'.
522 '<img src="'.$loginImageSmall.'" alt="TYPO3 logo" align="left" />'.
523 'TYPO3 CMS'.($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightShowVersion']?
' ver. '.htmlspecialchars($GLOBALS['TYPO_VERSION']):'').
525 'Copyright © '.TYPO3_copyright_year
.' Kasper Skårhøj. Extensions are copyright of their respective owners. '.
526 'Go to <a href="http://typo3.com/" target="_blank">http://typo3.com/</a> for details. '.
528 '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>. '.
529 'Obstructing the appearance of this notice is prohibited by law.';
532 return $copyrightNotice;
536 * Returns the login box image, whether the default or an image from the rotation folder.
538 * @return string HTML image tag.
540 function makeLoginBoxImage() {
542 if ($GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder']) { // Look for rotation image folder:
543 $absPath = t3lib_div
::resolveBackPath(PATH_typo3
.$GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder']);
545 // Get rotation folder:
546 $dir = t3lib_div
::getFileAbsFileName($absPath);
547 if ($dir && @is_dir
($dir)) {
549 // Get files for rotation into array:
550 $files = t3lib_div
::getFilesInDir($dir,'png,jpg,gif');
553 srand((float) microtime() * 10000000);
554 $randImg = array_rand($files, 1);
556 // Get size of random file:
557 $imgSize = @getimagesize
($dir.$files[$randImg]);
559 $imgAuthor = is_array($GLOBALS['TBE_STYLES']['loginBoxImage_author'])&&$GLOBALS['TBE_STYLES']['loginBoxImage_author'][$files[$randImg]] ?
htmlspecialchars($GLOBALS['TBE_STYLES']['loginBoxImage_author'][$files[$randImg]]) : '';
562 if (is_array($imgSize)) {
563 $loginboxImage = '<img src="'.htmlspecialchars($GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder'].$files[$randImg]).'" '.$imgSize[3].' id="loginbox-image" alt="'.$imgAuthor.'" title="'.$imgAuthor.'" />';
566 } else { // If no rotation folder configured, print default image:
568 if (strstr(TYPO3_version
,'-dev')) { // development version
569 $loginImage = 'loginbox_image_dev.png';
570 $imagecopy = 'You are running a development version of TYPO3 '.TYPO3_branch
;
572 $loginImage = 'loginbox_image.jpg';
573 $imagecopy = 'Photo by J.C. Franca (www.digitalphoto.com.br)';
575 $loginboxImage = '<img'.t3lib_iconWorks
::skinImg($GLOBALS['BACK_PATH'],'gfx/'.$loginImage,'width="200" height="133"').' id="loginbox-image" alt="'.$imagecopy.'" title="'.$imagecopy.'" />';
579 return $loginboxImage;
583 * 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
585 * @return string HTML content
586 * @credits Idea by Jan-Hendrik Heuing
588 function makeLoginNews() {
590 // Reset output variable:
593 // Traverse news array IF there are records in it:
594 if (is_array($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews']) && count($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'])) {
595 foreach($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'] as $newsItem) {
596 $newsContent .= '<dt>'.htmlspecialchars($newsItem['header']).' <span>'.htmlspecialchars($newsItem['date']).'</span></dt>';
597 $newsContent .= '<dd>'.trim($newsItem['content']).'</dd>';
600 $title = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginNewsTitle'] ?
htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNewsTitle']) : htmlspecialchars($this->L_vars
[8]);
607 <h2 id="loginNewsTitle">'.$title.'</h2>
619 * Returns the form tag
621 * @return string Opening form tag string
623 function startForm() {
626 if ($this->loginSecurityLevel
== 'challenged') {
628 <form action="index.php" method="post" name="loginform" onsubmit="doChallengeResponse(0);">
630 } elseif ($this->loginSecurityLevel
== 'normal') {
632 <form action="index.php" method="post" name="loginform" onsubmit="document.loginform.userident.value=document.loginform.p_field.value;document.loginform.p_field.value=\'\';return true;">
634 } else { // if ($this->loginSecurityLevel == 'superchallenged') {
636 <form action="index.php" method="post" name="loginform" onsubmit="doChallengeResponse(1);">
641 <input type="hidden" name="login_status" value="login" />
648 * Output some hidden fields at the end of the login form
650 * @param string The challenge string to be included in the output
651 * @return string HTML output
653 function getHiddenFields($challenge) {
655 <input type="hidden" name="userident" value="" />
656 <input type="hidden" name="challenge" value="'.$challenge.'" />
657 <input type="hidden" name="redirect_url" value="'.htmlspecialchars($this->redirectToURL
).'" />
658 <input type="hidden" name="loginRefresh" value="'.htmlspecialchars($this->loginRefresh
).'" />
659 '.$this->interfaceSelector_hidden
.'
660 '.$this->addFields_hidden
.'
667 * Set JavaScript for creating a MD5 hash of the password
669 * @return string JavaScript code
671 function getJScode() {
672 global $TBE_TEMPLATE;
675 <script type="text/javascript" src="md5.js"></script>
676 '.$TBE_TEMPLATE->wrapScriptTags('
677 function doChallengeResponse(superchallenged) { //
678 password = document.loginform.p_field.value;
680 if (superchallenged) {
681 password = MD5(password); // this makes it superchallenged!!
683 str = document.loginform.username.value+":"+password+":"+document.loginform.challenge.value;
684 document.loginform.userident.value = MD5(str);
685 document.loginform.p_field.value = "";
691 // 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:
692 if (parent.opener && parent.opener.TS && parent.opener.TS.username && document.loginform && document.loginform.username) {
693 document.loginform.username.value = parent.opener.TS.username;
696 // Wait a few millisecons before calling checkFocus(). This might be necessary because some browsers need some time to auto-fill in the form fields
697 window.setTimeout("checkFocus()", 50);
700 // This moves focus to the right input field:
701 function checkFocus() {
702 // If for some reason there already is a username in the username form field, move focus to the password field:
703 if (document.loginform.username && document.loginform.username.value == "") {
704 document.loginform.username.focus();
705 } else if (document.loginform.p_field && document.loginform.p_field.type!="hidden") {
706 document.loginform.p_field.focus();
715 * Create a random challenge string
717 * @return string Challenge value
719 function getChallenge() {
720 $challenge = md5(uniqid('').getmypid());
725 // Include extension?
726 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/index.php']) {
727 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/index.php']);
740 $SOBE = t3lib_div
::makeInstance('SC_index');
743 $SOBE->printContent();