Added feature #11016: Implement RSA authentication for BE and FE -- part 2 (fix hard...
[Packages/TYPO3.CMS.git] / typo3 / index.php
old mode 100755 (executable)
new mode 100644 (file)
index bb76bd6..8728651
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  *
  *
  *   87: class SC_index
- *  119:     function init()
- *  150:     function main()
- *  243:     function printContent()
+ *  120:     function init()
+ *  159:     function main()
+ *  268:     function printContent()
  *
  *              SECTION: Various functions
- *  267:     function makeLoginForm()
- *  312:     function makeLogoutForm()
- *  354:     function wrapLoginForm($content)
- *  414:     function checkRedirect()
- *  459:     function makeInterfaceSelectorBox()
- *  513:     function makeCopyrightNotice()
- *  546:     function makeLoginBoxImage()
- *  586:     function makeLoginNews()
+ *  292:     function makeLoginForm()
+ *  337:     function makeLogoutForm()
+ *  379:     function wrapLoginForm($content)
+ *  438:     function checkRedirect()
+ *  495:     function makeInterfaceSelectorBox()
+ *  549:     function makeCopyrightNotice()
+ *  582:     function makeLoginBoxImage()
+ *  622:     function makeLoginNews()
  *
  * TOTAL FUNCTIONS: 11
  * (This index is automatically created/updated by the extension "extdeveval")
@@ -89,14 +89,14 @@ class SC_index {
                // Internal, GPvars:
        var $redirect_url;                      // GPvar: redirect_url; The URL to redirect to after login.
        var $GPinterface;                       // GPvar: Defines which interface to load (from interface selector)
-       var $u;                                         // GPvar: preset username
-       var $p;                                         // GPvar: preset password
-       var $L;                                         // GPvar: If "L" is "OUT", then any logged in used is logged out. If redirect_url is given, we redirect to it
+       var $u;                                 // GPvar: preset username
+       var $p;                                 // GPvar: preset password
+       var $L;                                 // GPvar: If "L" is "OUT", then any logged in used is logged out. If redirect_url is given, we redirect to it
        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.
        var $commandLI;                         // Value of forms submit button for login.
 
                // Internal, static:
-       var $redirectToURL;                     // Set to the redirect URL of the form (may be redirect_url or "alt_main.php")
+       var $redirectToURL;                     // Set to the redirect URL of the form (may be redirect_url or "backend.php")
        var $L_vars;                            // Set to the labels used for the login screen.
 
                // Internal, dynamic:
@@ -105,6 +105,7 @@ class SC_index {
        var $interfaceSelector;                 // A selector box for selecting value for "interface" may be rendered into this variable
        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
        var $interfaceSelector_hidden;  // A hidden field, if the interface is not set.
+       var $addFields_hidden = '';             // Additional hidden fields to be placed at the login form
 
                // sets the level of security. *'normal' = clear-text. 'challenged' = hashed password/username from form in $formfield_uident. 'superchallenged' = hashed password hashed again with username.
        var $loginSecurityLevel = 'superchallenged';
@@ -118,36 +119,49 @@ class SC_index {
         * @return      void
         */
        function init() {
-               global $BE_USER,$TYPO3_CONF_VARS;
+               // We need a PHP session session for most login levels
+               session_start();
 
-                       // GPvars:
                $this->redirect_url = t3lib_div::_GP('redirect_url');
                $this->GPinterface = t3lib_div::_GP('interface');
-               $this->u = t3lib_div::_GP('u');                                                 // preset username
-               $this->p = t3lib_div::_GP('p');                                                 // preset password
-               $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
-               $this->loginRefresh = t3lib_div::_GP('loginRefresh');           // Login
-               $this->commandLI = t3lib_div::_GP('commandLI');                 // Value of "Login" button. If set, the login button was pressed.
+
+                       // Grabbing preset username and password, for security reasons this feature only works if SSL is used
+               if (t3lib_div::getIndpEnv('TYPO3_SSL')) {
+                       $this->u = t3lib_div::_GP('u');
+                       $this->p = t3lib_div::_GP('p');
+               }
+
+                       // If "L" is "OUT", then any logged in is logged out. If redirect_url is given, we redirect to it
+               $this->L = t3lib_div::_GP('L');
+
+                       // Login
+               $this->loginRefresh = t3lib_div::_GP('loginRefresh');
+
+                       // Value of "Login" button. If set, the login button was pressed.
+               $this->commandLI = t3lib_div::_GP('commandLI');
 
                        // sets the level of security from conf vars
-               if ($TYPO3_CONF_VARS['BE']['loginSecurityLevel']) {
-                       $this->loginSecurityLevel = $TYPO3_CONF_VARS['BE']['loginSecurityLevel'];
+               if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
+                       $this->loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
                }
 
-                       // Getting login labels:
-               $this->L_vars = explode('|',$TYPO3_CONF_VARS['BE']['loginLabels']);
+                       // Getting login labels
+               $this->L_vars = explode('|', $GLOBALS['TYPO3_CONF_VARS']['BE']['loginLabels']);
 
-                       // Setting the redirect URL to "alt_main.php" if no alternative input is given:
-               $this->redirectToURL = $this->redirect_url ? $this->redirect_url : 'alt_main.php';
+                       // Setting the redirect URL to "backend.php" if no alternative input is given
+               $this->redirectToURL = $this->redirect_url ? $this->redirect_url : 'backend.php';
 
-                       // Logout?
-               if ($this->L=='OUT' && is_object($BE_USER))     {
-                       $BE_USER->logoff();
-                       if ($this->redirect_url)        header('Location: '.t3lib_div::locationHeaderUrl($this->redirect_url));
+                       // Do a logout if the command is set
+               if ($this->L == 'OUT' && is_object($GLOBALS['BE_USER'])) {
+                       $GLOBALS['BE_USER']->logoff();
+                       if ($this->redirect_url) {
+                               header('Location: '.t3lib_div::locationHeaderUrl($this->redirect_url));
+                       }
                        exit;
                }
        }
 
+
        /**
         * Main function - creating the login/logout form
         *
@@ -157,26 +171,11 @@ class SC_index {
                global $TBE_TEMPLATE, $TYPO3_CONF_VARS, $BE_USER;
 
                        // Initialize template object:
-               $TBE_TEMPLATE->docType='xhtml_trans';
+               $TBE_TEMPLATE->bodyTagAdditions = ' onload="startUp();"';
+               $TBE_TEMPLATE->moduleTemplate = $TBE_TEMPLATE->getHtmlTemplate('templates/login.html');
 
                        // Set JavaScript for creating a MD5 hash of the password:
-               $TBE_TEMPLATE->JScode.='
-                       <script type="text/javascript" src="md5.js"></script>
-                       '.$TBE_TEMPLATE->wrapScriptTags('
-                               function doChallengeResponse(superchallenged) { //
-                                       password = document.loginform.p_field.value;
-                                       if (password)   {
-                                               if (superchallenged)    {
-                                                       password = MD5(password);       // this makes it superchallenged!!
-                                               }
-                                               str = document.loginform.username.value+":"+password+":"+document.loginform.challenge.value;
-                                               document.loginform.userident.value = MD5(str);
-                                               document.loginform.p_field.value = "";
-                                               return true;
-                                       }
-                               }
-                       ');
-
+               $TBE_TEMPLATE->JScode.= $this->getJScode();
 
                        // Checking, if we should make a redirect.
                        // Might set JavaScript in the header to close window.
@@ -186,28 +185,11 @@ class SC_index {
                $this->makeInterfaceSelectorBox();
 
                        // Replace an optional marker in the "Administration Login" label
-               $this->L_vars[6] = str_replace("###SITENAME###",$TYPO3_CONF_VARS['SYS']['sitename'],$this->L_vars[6]);
+               $this->L_vars[6] = str_replace("###SITENAME###", $TYPO3_CONF_VARS['SYS']['sitename'], $this->L_vars[6]);
 
                        // Creating form based on whether there is a login or not:
                if (!$BE_USER->user['uid'])     {
-
-                       if ($this->loginSecurityLevel == 'challenged') {
-                               $TBE_TEMPLATE->form = '
-                                       <form action="index.php" method="post" name="loginform" onsubmit="doChallengeResponse(0);">
-                                       ';
-                       } elseif ($this->loginSecurityLevel == 'normal') {
-                               $TBE_TEMPLATE->form = '
-                                       <form action="index.php" method="post" name="loginform" onsubmit="document.loginform.userident.value=document.loginform.p_field.value;document.loginform.p_field.value=\'\';document.loginform.challenge.value=\'\';return true;">
-                                       ';
-                       } else { // if ($this->loginSecurityLevel == 'superchallenged') {
-                               $TBE_TEMPLATE->form = '
-                                       <form action="index.php" method="post" name="loginform" onsubmit="doChallengeResponse(1);">
-                                       ';
-                       }
-
-                       $TBE_TEMPLATE->form.= '
-                                       <input type="hidden" name="login_status" value="login" />
-                               ';
+                       $TBE_TEMPLATE->form = $this->startForm();
                        $loginForm = $this->makeLoginForm();
                } else {
                        $TBE_TEMPLATE->form = '
@@ -217,44 +199,16 @@ class SC_index {
                        $loginForm = $this->makeLogoutForm();
                }
 
-
                        // Starting page:
                $this->content.=$TBE_TEMPLATE->startPage('TYPO3 Login: '.$TYPO3_CONF_VARS['SYS']['sitename']);
 
                        // Add login form:
                $this->content.=$this->wrapLoginForm($loginForm);
 
-                       // Ending form:
-               $this->content.= '
-                       <input type="hidden" name="userident" value="" />
-                       <input type="hidden" name="challenge" value="'.($challenge = md5(uniqid('').getmypid())).'" />
-                       <input type="hidden" name="redirect_url" value="'.htmlspecialchars($this->redirectToURL).'" />
-                       <input type="hidden" name="loginRefresh" value="'.htmlspecialchars($this->loginRefresh).'" />
-                       '.$this->interfaceSelector_hidden.'
-                       ';
-
-                       // Save challenge value in session data (thanks to Bernhard Kraft for providing code):
-               session_start();
-               $_SESSION['login_challenge'] = $challenge;
-
-                       // This moves focus to the right input field:
-               $this->content.=$TBE_TEMPLATE->wrapScriptTags('
+                       // Add hidden fields and end the page
+               $this->content .= $this->getHiddenFields();
 
-                               // 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:
-                       if (parent.opener && parent.opener.TS && parent.opener.TS.username && document.loginform && document.loginform.username)        {
-                               document.loginform.username.value = parent.opener.TS.username;
-                       }
-
-                               // If for some reason there already is a username in the username for field, move focus to the password field:
-                       if (document.loginform.username && document.loginform.username.value == "") {
-                               document.loginform.username.focus();
-                       } else if (document.loginform.p_field && document.loginform.p_field.type!="hidden") {
-                               document.loginform.p_field.focus();
-                       }
-               ');
-
-                       // End page:
-               $this->content.=$TBE_TEMPLATE->endPage();
+               $this->content.= $TBE_TEMPLATE->endPage();
        }
 
        /**
@@ -263,17 +217,9 @@ class SC_index {
         * @return      void
         */
        function printContent() {
-
                echo $this->content;
        }
 
-
-
-
-
-
-
-
        /*****************************
         *
         * Various functions
@@ -287,147 +233,102 @@ class SC_index {
         * @return      string          HTML output
         */
        function makeLoginForm()        {
+               $content = t3lib_parsehtml::getSubpart($GLOBALS['TBE_TEMPLATE']->moduleTemplate, '###LOGIN_FORM###');
+               $markers = array(
+                       'HEADLINE'       => $this->L_vars[6],
+                       'LABEL_USERNAME' => $this->L_vars[0],
+                       'LABEL_PASSWORD' => $this->L_vars[1],
+                       'VALUE_USERNAME' => $this->u,
+                       'VALUE_PASSWORD' => $this->p,
+                       'VALUE_SUBMIT'   => $this->L_vars[3],
+                       'INFO'           => $this->L_vars[7],
+               );
+
+                       // show an error message if the login command was successful already
+               if (!$this->commandLI) {
+                       $content = t3lib_parsehtml::substituteSubpart($content, '###LOGIN_ERROR###', '');
+               } else {
+                       $markers['ERROR_MESSAGE'] = $this->L_vars[9];
+               }
 
-               $content.='
-
-                                                       <!--
-                                                               Login form:
-                                                       -->
-                                                       <table cellspacing="0" cellpadding="0" border="0" id="logintable">
-                                                                       <tr>
-                                                                               <td colspan="2"><h2>'.htmlspecialchars($this->L_vars[6]).'</h2></td>
-                                                                       </tr>'.($this->commandLI ? '
-                                                                       <tr class="c-wrong">
-                                                                               <td colspan="2"><p class="c-wrong">'.htmlspecialchars($this->L_vars[9]).'</p></td>
-                                                                       </tr>' : '').'
-                                                                       <tr class="c-username">
-                                                                               <td><p class="c-username">'.htmlspecialchars($this->L_vars[0]).':</p></td>
-                                                                               <td><input type="text" name="username" value="'.htmlspecialchars($this->u).'" class="c-username" /></td>
-                                                                       </tr>
-                                                                       <tr class="c-password">
-                                                                               <td><p class="c-password">'.htmlspecialchars($this->L_vars[1]).':</p></td>
-                                                                               <td><input type="password" name="p_field" value="'.htmlspecialchars($this->p).'" class="c-password" /></td>
-                                                                       </tr>'.($this->interfaceSelector && !$this->loginRefresh ? '
-                                                                       <tr class="c-interfaceselector">
-                                                                               <td><p class="c-interfaceselector">'.htmlspecialchars($this->L_vars[2]).':</p></td>
-                                                                               <td>'.$this->interfaceSelector.'</td>
-                                                                       </tr>' : '' ).'
-                                                                       <tr class="c-submit">
-                                                                               <td></td>
-                                                                               <td><input type="submit" name="commandLI" value="'.htmlspecialchars($this->L_vars[3]).'" class="c-submit" /></td>
-                                                                       </tr>
-                                                                       <tr class="c-info">
-                                                                               <td colspan="2"><p class="c-info">'.htmlspecialchars($this->L_vars[7]).'</p></td>
-                                                                       </tr>
-                                                               </table>';
+                       // HSC all output
+               foreach ($markers as &$marker) {
+                       $marker = htmlspecialchars($marker);
+               }
 
-                       // Return content:
-               return $content;
+
+                       // remove the interface selector markers if it's not available
+               if (!($this->interfaceSelector && !$this->loginRefresh)) {
+                       $content = t3lib_parsehtml::substituteSubpart($content, '###INTERFACE_SELECTOR###', '');
+               } else {
+                       $markers['LABEL_INTERFACE'] = htmlspecialchars($this->L_vars[2]);
+                       $markers['VALUE_INTERFACE'] = $this->interfaceSelector_jump;
+               }
+
+               return t3lib_parsehtml::substituteMarkerArray($content, $markers, '###|###');
        }
 
+
        /**
         * Creates the logout form
         * This is drawn if a user login already exists.
         *
         * @return      string          HTML output
         */
-       function makeLogoutForm()       {
-               global $BE_USER;
-
-
-               $content.='
-
-                                                       <!--
-                                                               Login form:
-                                                       -->
-                                                       <table cellspacing="0" cellpadding="0" border="0" id="logintable">
-                                                                       <tr>
-                                                                               <td></td>
-                                                                               <td><h2>'.htmlspecialchars($this->L_vars[6]).'</h2></td>
-                                                                       </tr>
-                                                                       <tr class="c-username">
-                                                                               <td><p class="c-username">'.htmlspecialchars($this->L_vars[0]).':</p></td>
-                                                                               <td><p class="c-username-current">'.htmlspecialchars($BE_USER->user['username']).'</p></td>
-                                                                       </tr>'.($this->interfaceSelector_jump ? '
-                                                                       <tr class="c-interfaceselector">
-                                                                               <td><p class="c-interfaceselector">'.htmlspecialchars($this->L_vars[2]).':</p></td>
-                                                                               <td>'.$this->interfaceSelector_jump.'</td>
-                                                                       </tr>' : '' ).'
-                                                                       <tr class="c-submit">
-                                                                               <td><input type="hidden" name="p_field" value="" /></td>
-                                                                               <td><input type="submit" name="commandLO" value="'.htmlspecialchars($this->L_vars[4]).'" class="c-submit" /></td>
-                                                                       </tr>
-                                                                       <tr class="c-info">
-                                                                               <td></td>
-                                                                               <td><p class="c-info">'.htmlspecialchars($this->L_vars[7]).'</p></td>
-                                                                       </tr>
-                                                               </table>';
+       function makeLogoutForm() {
+               $content = t3lib_parsehtml::getSubpart($GLOBALS['TBE_TEMPLATE']->moduleTemplate, '###LOGOUT_FORM###');
+               $markers = array(
+                       'HEADLINE'       => $this->L_vars[6],
+                       'LABEL_USERNAME' => $this->L_vars[0],
+                       'VALUE_USERNAME' => $GLOBALS['BE_USER']->user['username'],
+                       'VALUE_SUBMIT'   => $this->L_vars[4],
+                       'INFO'           => $this->L_vars[7],
+               );
+
+                       // HSC all output
+               foreach ($markers as &$marker) {
+                       $marker = htmlspecialchars($marker);
+               }
 
-                       // Return content:
-               return $content;
+                       // remove the interface selector markers if it's not available
+               if (!$this->interfaceSelector_jump) {
+                       $content = t3lib_parsehtml::substituteSubpart($content, '###INTERFACE_SELECTOR###', '');
+               } else {
+                       $markers['LABEL_INTERFACE'] = htmlspecialchars($this->L_vars[2]);
+                       $markers['VALUE_INTERFACE'] = $this->interfaceSelector_jump;
+               }
+
+               return t3lib_parsehtml::substituteMarkerArray($content, $markers, '###|###');
        }
 
+
        /**
         * Wrapping the login form table in another set of tables etc:
         *
         * @param       string          HTML content for the login form
         * @return      string          The HTML for the page.
         */
-       function wrapLoginForm($content)        {
-
-                       // Logo:
-               $logo = $GLOBALS['TBE_STYLES']['logo_login'] ?
-                                       '<img src="'.htmlspecialchars($GLOBALS['BACK_PATH'].$GLOBALS['TBE_STYLES']['logo_login']).'" alt="" />' :
-                                       '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/typo3logo.gif','width="333" height="43"').' alt="" />';
+       function wrapLoginForm($content) {
+               $mainContent = t3lib_parsehtml::getSubpart($GLOBALS['TBE_TEMPLATE']->moduleTemplate, '###PAGE###');
 
-                       // Login box image:
-               $loginboxImage = $this->makeLoginBoxImage();
-
-                       // Compile the page content:
-               $content='
-
-               <!--
-                       Wrapper table for the login form:
-               -->
-               <table cellspacing="0" cellpadding="0" border="0" id="wrapper">
-                       <tr>
-                               <td class="c-wrappercell" align="center">
-
-                                       <!--
-                                               Login form image:
-                                       -->
-                                       <div id="loginimage">
-                                                                                       '.$logo.'
-                                       </div>
-
-                                       <!--
-                                               Login form wrapper:
-                                       -->
-                                       <table cellspacing="0" cellpadding="0" border="0" id="loginwrapper">
-                                               <tr>
-                                                       <td>'.$loginboxImage.'</td>
-                                                       <td>
-                                                               '.$content.'
-                                                       </td>
-                                               </tr>
-                                       </table>
-
-                                       <!--
-                                               Copy right notice:
-                                       -->
-                                       <div id="copyrightnotice">
-                                               '.$this->makeCopyrightNotice().'
-                                       </div>
-
-                                       '.$this->makeLoginNews().'
-                               </td>
-                       </tr>
-               </table>';
+               if ($GLOBALS['TBE_STYLES']['logo_login']) {
+                       $logo = '<img src="'.htmlspecialchars($GLOBALS['BACK_PATH'] . $GLOBALS['TBE_STYLES']['logo_login']) . '" alt="" />';
+               } else {
+                       $logo = '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/typo3logo.gif','width="123" height="34"').' alt="" />';
+               }
 
-                       // Return content:
-               return $content;
+               $markers = array(
+                       'LOGO'           => $logo,
+                       'LOGINBOX_IMAGE' => $this->makeLoginBoxImage(),
+                       'FORM'           => $content,
+                       'NEWS'           => $this->makeLoginNews(),
+                       'COPYRIGHT'      => $this->makeCopyrightNotice(),
+                       'CSS_ERRORCLASS' => ($this->commandLI ? ' class="error"' : ''),
+               );
+               return t3lib_parsehtml::substituteMarkerArray($mainContent, $markers, '###|###');
        }
 
+
        /**
         * Checking, if we should perform some sort of redirection OR closing of windows.
         *
@@ -441,7 +342,7 @@ class SC_index {
                if ($BE_USER->user['uid'] && ($this->commandLI || $this->loginRefresh || !$this->interfaceSelector))    {
 
                                // 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.
-                       if (!$_COOKIE[$BE_USER->name])  {
+                       if (!$_COOKIE[$BE_USER->name]) {
                                if ($this->commandLI=='setCookie') {
                                                // we tried it a second time but still no cookie
                                                // 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.
@@ -453,14 +354,21 @@ class SC_index {
                                }
                        }
 
-                       if($redirectToURL = (string)$BE_USER->getTSConfigVal('auth.BE.redirectToURL')) {
+                       if (($redirectToURL = (string)$BE_USER->getTSConfigVal('auth.BE.redirectToURL'))) {
                                $this->redirectToURL = $redirectToURL;
                                $this->GPinterface = '';
-                       }
+                       }
+
+                               // store interface
+                       $BE_USER->uc['interfaceSetup'] = $this->GPinterface;
+                       $BE_USER->writeUC();
 
                                // Based on specific setting of interface we set the redirect script:
                        switch ($this->GPinterface)     {
                                case 'backend':
+                                       $this->redirectToURL = 'backend.php';
+                               break;
+                               case 'backend_old':
                                        $this->redirectToURL = 'alt_main.php';
                                break;
                                case 'frontend':
@@ -480,8 +388,9 @@ class SC_index {
                                        }
                                ');
                        }
-               } elseif(!$BE_USER->user['uid'] && $this->commandLI) {
-                       sleep(5);
+
+               } elseif (!$BE_USER->user['uid'] && $this->commandLI) {
+                       sleep(5);       // Wrong password, wait for 5 seconds
                }
        }
 
@@ -497,34 +406,37 @@ class SC_index {
                $this->interfaceSelector = '';
                $this->interfaceSelector_hidden='';
                $this->interfaceSelector_jump = '';
-#debug($this->redirect_url);
+
                        // If interfaces are defined AND no input redirect URL in GET vars:
-               if ($TYPO3_CONF_VARS['BE']['interfaces'] && !$this->redirect_url)       {
+               if ($TYPO3_CONF_VARS['BE']['interfaces'] && ($this->commandLI || !$this->redirect_url)) {
                        $parts = t3lib_div::trimExplode(',',$TYPO3_CONF_VARS['BE']['interfaces']);
                        if (count($parts)>1)    {       // Only if more than one interface is defined will we show the selector:
 
                                        // Initialize:
-                               $tempLabels=explode(',',$this->L_vars[5]);
+                               $tempLabels=explode(',', $this->L_vars[5]);
                                $labels=array();
-                               $labels['backend']=$tempLabels[0];
-                               $labels['frontend']=$tempLabels[1];
+
+                               $labels['backend']     = $tempLabels[0];
+                               $labels['backend_old'] = $tempLabels[2];
+                               $labels['frontend']    = $tempLabels[1];
 
                                $jumpScript=array();
-                               $jumpScript['backend']='alt_main.php';
-                               $jumpScript['frontend']='../';
+                               $jumpScript['backend']     = 'backend.php';
+                               $jumpScript['backend_old'] = 'alt_main.php';
+                               $jumpScript['frontend']    = '../';
 
                                        // Traverse the interface keys:
                                foreach($parts as $valueStr)    {
                                        $this->interfaceSelector.='
-                                                       <option value="'.htmlspecialchars($valueStr).'">'.htmlspecialchars($labels[$valueStr]).'</option>';
+                                                       <option value="'.htmlspecialchars($valueStr).'"'.(t3lib_div::_GP('interface')==htmlspecialchars($valueStr) ? ' selected="selected"' : '').'>'.htmlspecialchars($labels[$valueStr]).'</option>';
                                        $this->interfaceSelector_jump.='
                                                        <option value="'.htmlspecialchars($jumpScript[$valueStr]).'">'.htmlspecialchars($labels[$valueStr]).'</option>';
                                }
                                $this->interfaceSelector='
-                                               <select name="interface" class="c-interfaceselector">'.$this->interfaceSelector.'
+                                               <select id="interfaceselector" name="interface" class="c-interfaceselector">'.$this->interfaceSelector.'
                                                </select>';
                                $this->interfaceSelector_jump='
-                                               <select name="interface" class="c-interfaceselector" onchange="document.location=this.options[this.selectedIndex].value;">'.$this->interfaceSelector_jump.'
+                                               <select id="interfaceselector" name="interface" class="c-interfaceselector" onchange="window.location.href=this.options[this.selectedIndex].value;">'.$this->interfaceSelector_jump.'
                                                </select>';
 
                        } else {        // If there is only ONE interface value set:
@@ -549,6 +461,7 @@ class SC_index {
                        // Get values from TYPO3_CONF_VARS:
                $loginCopyrightWarrantyProvider = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyProvider']));
                $loginCopyrightWarrantyURL = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyURL']));
+               $loginImageSmall = (trim($GLOBALS['TBE_STYLES']['loginBoxImageSmall'])) ? trim($GLOBALS['TBE_STYLES']['loginBoxImageSmall']) : 'gfx/loginlogo_transp.gif';
 
                        // Make warranty note:
                if (strlen($loginCopyrightWarrantyProvider)>=2 && strlen($loginCopyrightWarrantyURL)>=10)       {
@@ -559,10 +472,10 @@ class SC_index {
 
                        // Compile full copyright notice:
                $copyrightNotice = '<a href="http://typo3.com/" target="_blank">'.
-                                       '<img src="gfx/loginlogo_transp.gif" width="75" height="19" alt="TYPO3 logo" align="left" />'.
+                                       '<img src="'.$loginImageSmall.'" alt="TYPO3 logo" align="left" />'.
                                        'TYPO3 CMS'.($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightShowVersion']?' ver. '.htmlspecialchars($GLOBALS['TYPO_VERSION']):'').
                                        '</a>. '.
-                                       'Copyright &copy; 1998-2005 Kasper Sk&#229;rh&#248;j. Extensions are copyright of their respective owners. '.
+                                       'Copyright &copy; '.TYPO3_copyright_year.' Kasper Sk&#229;rh&#248;j. Extensions are copyright of their respective owners. '.
                                        'Go to <a href="http://typo3.com/" target="_blank">http://typo3.com/</a> for details. '.
                                        $warrantyNote.' '.
                                        '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>. '.
@@ -596,14 +509,22 @@ class SC_index {
                                        // Get size of random file:
                                $imgSize = @getimagesize($dir.$files[$randImg]);
 
+                               $imgAuthor = is_array($GLOBALS['TBE_STYLES']['loginBoxImage_author'])&&$GLOBALS['TBE_STYLES']['loginBoxImage_author'][$files[$randImg]] ? htmlspecialchars($GLOBALS['TBE_STYLES']['loginBoxImage_author'][$files[$randImg]]) : '';
+
                                        // Create image tag:
                                if (is_array($imgSize)) {
-                                       $loginboxImage = '<img src="'.htmlspecialchars($GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder'].$files[$randImg]).'" '.$imgSize[3].' id="loginbox-image" alt="" />';
+                                       $loginboxImage = '<img src="'.htmlspecialchars($GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder'].$files[$randImg]).'" '.$imgSize[3].' id="loginbox-image" alt="'.$imgAuthor.'" title="'.$imgAuthor.'" />';
                                }
                        }
                } else {        // If no rotation folder configured, print default image:
-                       $loginImage = 'loginbox_image_dev.png';
-                       $imagecopy = $loginImage=='loginbox_image_dev.png' ? 'You are running the CVS version of TYPO3 '.$GLOBALS['TYPO_VERSION'] : 'Photo: &copy; 2004-2005 Kasper Sk&#229;rh&#248;j'; // Directly outputted in image attributes...
+
+                       if (strstr(TYPO3_version,'-dev'))       {       // development version
+                               $loginImage = 'loginbox_image_dev.png';
+                               $imagecopy = 'You are running a development version of TYPO3 '.TYPO3_branch;
+                       } else {
+                               $loginImage = 'loginbox_image.jpg';
+                               $imagecopy = 'Photo by J.C. Franca (www.digitalphoto.com.br)';
+                       }
                        $loginboxImage = '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/'.$loginImage,'width="200" height="133"').' id="loginbox-image" alt="'.$imagecopy.'" title="'.$imagecopy.'" />';
                }
 
@@ -625,52 +546,122 @@ class SC_index {
                        // Traverse news array IF there are records in it:
                if (is_array($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews']) && count($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews']))  {
                        foreach($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'] as $newsItem)    {
-                               $newsContent.='
-                                               <tr>
-                                                       <td class="c-date">'.htmlspecialchars($newsItem['date']).'</td>
-                                                       <td class="c-header">'.htmlspecialchars($newsItem['header']).'</td>
-                                               </tr>
-                                               <tr>
-                                                       <td></td>
-                                                       <td class="c-content">'.trim($newsItem['content']).'</td>
-                                               </tr>
-                                               <tr class="c-spacer">
-                                                       <td colspan="2"></td>
-                                               </tr>
-                               ';
+                               $newsContent .= '<dt>'.htmlspecialchars($newsItem['header']).' <span>'.htmlspecialchars($newsItem['date']).'</span></dt>';
+                               $newsContent .= '<dd>'.trim($newsItem['content']).'</dd>';
                        }
 
-                               // Wrap in a table:
-                       $newsContent= '
+                       $title = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginNewsTitle'] ? htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNewsTitle']) : htmlspecialchars($this->L_vars[8]);
+                               // Wrap
+                       $newsContent = '
 
                                        <!--
                                                Login screen news:
                                        -->
-                                       <div id="loginNews">
-                                       <h2>'.htmlspecialchars($this->L_vars[8]).'</h2>
-                                       <table border="0" cellpadding="0" cellspacing="0">
+                                       <h2 id="loginNewsTitle">'.$title.'</h2>
+                                       <dl id="loginNews">
                                                '.$newsContent.'
-                                       </table>
-                                       </div>
+                                       </dl>
                        ';
                }
 
                        // Return content:
                return $newsContent;
        }
-}
 
-// Include extension?
-if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/index.php'])        {
-       include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/index.php']);
-}
+       /**
+        * Returns the form tag
+        *
+        * @return      string          Opening form tag string
+        */
+       function startForm()    {
+               $output = '';
+
+               // The form defaults to 'no login'. This prevents plain
+               // text logins to the Backend. The 'sv' extension changes the form to
+               // use superchallenged method and rsaauth extension makes rsa authetication.
+               $form = '<form action="index.php" method="post" name="loginform" ' .
+                               'onsubmit="alert(\'No authentication methods available. Please, ' .
+                               'contact your TYPO3 administrator.\');return false">';
+
+               // Call hooks. If they do not return anything, we fail to login
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/index.php']['loginFormHook'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/index.php']['loginFormHook'] as $function) {
+                               $params = array();
+                               $formCode = t3lib_div::callUserFunction($function, $params, $this);
+                               if ($formCode) {
+                                       $form = $formCode;
+                                       break;
+                               }
+                       }
+               }
 
+               $output .= $form .
+                       '<input type="hidden" name="login_status" value="login" />' .
+                       '<input type="hidden" name="userident" value="" />' .
+                       '<input type="hidden" name="redirect_url" value="'.htmlspecialchars($this->redirectToURL).'" />' .
+                       '<input type="hidden" name="loginRefresh" value="'.htmlspecialchars($this->loginRefresh).'" />' .
+                       $this->interfaceSelector_hidden . $this->addFields_hidden;
 
+               return $output;
+       }
 
+       /**
+        * Outputs an empty string. This function is obsolete and kept for the
+        * compatibility only.
+        *
+        * @param       string  $unused Unused
+        * @return      string          HTML output
+        */
+       function getHiddenFields($unused = '') {
+               return '';
+       }
 
+       /**
+        * Creates JavaScript for the login form
+        *
+        * @return      string          JavaScript code
+        */
+       function getJScode()    {
+               $JSCode = '';
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/index.php']['loginScriptHook'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/index.php']['loginScriptHook'] as $function) {
+                               $params = array();
+                               $JSCode = t3lib_div::callUserFunction($function, $params, $this);
+                               if ($JSCode) {
+                                       break;
+                               }
+                       }
+               }
+               $JSCode .= $GLOBALS['TBE_TEMPLATE']->wrapScriptTags('
+                       function startUp() {
+                                       // 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:
+                               if (parent.opener && parent.opener.TS && parent.opener.TS.username && document.loginform && document.loginform.username)        {
+                                       document.loginform.username.value = parent.opener.TS.username;
+                               }
 
+                                       // Wait a few millisecons before calling checkFocus(). This might be necessary because some browsers need some time to auto-fill in the form fields
+                               window.setTimeout("checkFocus()", 50);
+                       }
 
+                               // This moves focus to the right input field:
+                       function checkFocus() {
+                                       // If for some reason there already is a username in the username form field, move focus to the password field:
+                               if (document.loginform.username && document.loginform.username.value == "") {
+                                       document.loginform.username.focus();
+                               } else if (document.loginform.p_field && document.loginform.p_field.type!="hidden") {
+                                       document.loginform.p_field.focus();
+                               }
+                       }
+                       ');
 
+               return $JSCode;
+       }
+}
+
+
+if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/index.php'])        {
+       include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/index.php']);
+}
 
 
 
@@ -679,4 +670,5 @@ $SOBE = t3lib_div::makeInstance('SC_index');
 $SOBE->init();
 $SOBE->main();
 $SOBE->printContent();
-?>
+
+?>
\ No newline at end of file