Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00062 define('TYPO3_PROCEED_IF_NO_USER', 1); 00063 require ('init.php'); 00064 require ('template.php'); 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00087 class SC_index { 00088 00089 // Internal, GPvars: 00090 var $redirect_url; // GPvar: redirect_url; The URL to redirect to after login. 00091 var $GPinterface; // GPvar: Defines which interface to load (from interface selector) 00092 var $u; // GPvar: preset username 00093 var $p; // GPvar: preset password 00094 var $L; // GPvar: If "L" is "OUT", then any logged in used is logged out. If redirect_url is given, we redirect to it 00095 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. 00096 var $commandLI; // Value of forms submit button for login. 00097 00098 // Internal, static: 00099 var $redirectToURL; // Set to the redirect URL of the form (may be redirect_url or "alt_main.php") 00100 var $L_vars; // Set to the labels used for the login screen. 00101 00102 // Internal, dynamic: 00103 var $content; // Content accumulation 00104 00105 var $interfaceSelector; // A selector box for selecting value for "interface" may be rendered into this variable 00106 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 00107 var $interfaceSelector_hidden; // A hidden field, if the interface is not set. 00108 00109 00110 00111 00112 00113 00119 function init() { 00120 global $BE_USER,$TYPO3_CONF_VARS; 00121 00122 // GPvars: 00123 $this->redirect_url = t3lib_div::_GP('redirect_url'); 00124 $this->GPinterface = t3lib_div::_GP('interface'); 00125 $this->u = t3lib_div::_GP('u'); // preset username 00126 $this->p = t3lib_div::_GP('p'); // preset password 00127 $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 00128 $this->loginRefresh = t3lib_div::_GP('loginRefresh'); // Login 00129 $this->commandLI = t3lib_div::_GP('commandLI'); // Value of "Login" button. If set, the login button was pressed. 00130 00131 // Getting login labels: 00132 $this->L_vars = explode('|',$TYPO3_CONF_VARS['BE']['loginLabels']); 00133 00134 // Setting the redirect URL to "alt_main.php" if no alternative input is given: 00135 $this->redirectToURL = $this->redirect_url ? $this->redirect_url : 'alt_main.php'; 00136 00137 // Logout? 00138 if ($this->L=='OUT' && is_object($BE_USER)) { 00139 $BE_USER->logoff(); 00140 if ($this->redirect_url) header('Location: '.t3lib_div::locationHeaderUrl($this->redirect_url)); 00141 exit; 00142 } 00143 } 00144 00150 function main() { 00151 global $TBE_TEMPLATE, $TYPO3_CONF_VARS, $BE_USER; 00152 00153 // Initialize template object: 00154 $TBE_TEMPLATE->docType='xhtml_trans'; 00155 00156 // Set JavaScript for creating a MD5 hash of the password: 00157 $TBE_TEMPLATE->JScode.=' 00158 <script type="text/javascript" src="md5.js"></script> 00159 '.$TBE_TEMPLATE->wrapScriptTags(' 00160 function doChallengeResponse() { // 00161 password = document.loginform.p_field.value; 00162 if (password) { 00163 password = MD5(password); // this makes it superchallenged!! 00164 str = document.loginform.username.value+":"+password+":"+document.loginform.challenge.value; 00165 document.loginform.userident.value = MD5(str); 00166 document.loginform.p_field.value = ""; 00167 return true; 00168 } 00169 } 00170 '); 00171 00172 00173 // Checking, if we should make a redirect. 00174 // Might set JavaScript in the header to close window. 00175 $this->checkRedirect(); 00176 00177 // Initialize interface selectors: 00178 $this->makeInterfaceSelectorBox(); 00179 00180 // Replace an optional marker in the "Administration Login" label 00181 $this->L_vars[6] = str_replace("###SITENAME###",$TYPO3_CONF_VARS['SYS']['sitename'],$this->L_vars[6]); 00182 00183 // Creating form based on whether there is a login or not: 00184 if (!$BE_USER->user['uid']) { 00185 $TBE_TEMPLATE->form = ' 00186 <form action="index.php" method="post" name="loginform" onsubmit="doChallengeResponse();"> 00187 <input type="hidden" name="login_status" value="login" /> 00188 '; 00189 $loginForm = $this->makeLoginForm(); 00190 } else { 00191 $TBE_TEMPLATE->form = ' 00192 <form action="index.php" method="post" name="loginform"> 00193 <input type="hidden" name="login_status" value="logout" /> 00194 '; 00195 $loginForm = $this->makeLogoutForm(); 00196 } 00197 00198 00199 // Starting page: 00200 $this->content.=$TBE_TEMPLATE->startPage('TYPO3 Login: '.$TYPO3_CONF_VARS['SYS']['sitename']); 00201 00202 // Add login form: 00203 $this->content.=$this->wrapLoginForm($loginForm); 00204 00205 // Ending form: 00206 $this->content.= ' 00207 <input type="hidden" name="userident" value="" /> 00208 <input type="hidden" name="challenge" value="'.md5(uniqid('')).'" /> 00209 <input type="hidden" name="redirect_url" value="'.htmlspecialchars($this->redirectToURL).'" /> 00210 <input type="hidden" name="loginRefresh" value="'.htmlspecialchars($this->loginRefresh).'" /> 00211 '.$this->interfaceSelector_hidden.' 00212 '; 00213 00214 // This moves focus to the right input field: 00215 $this->content.=$TBE_TEMPLATE->wrapScriptTags(' 00216 00217 // 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: 00218 if (parent.opener && parent.opener.TS && parent.opener.TS.username && document.loginform && document.loginform.username) { 00219 document.loginform.username.value = parent.opener.TS.username; 00220 } 00221 00222 // If for some reason there already is a username in the username for field, move focus to the password field: 00223 if (document.loginform.username && document.loginform.username.value == "") { 00224 document.loginform.username.focus(); 00225 } else if (document.loginform.p_field && document.loginform.p_field.type!="hidden") { 00226 document.loginform.p_field.focus(); 00227 } 00228 '); 00229 00230 // End page: 00231 $this->content.=$TBE_TEMPLATE->endPage(); 00232 } 00233 00239 function printContent() { 00240 00241 echo $this->content; 00242 } 00243 00244 00245 00246 00247 00248 00249 00250 00251 /***************************** 00252 * 00253 * Various functions 00254 * 00255 ******************************/ 00256 00263 function makeLoginForm() { 00264 00265 $content.=' 00266 00267 <!-- 00268 Login form: 00269 --> 00270 <table cellspacing="0" cellpadding="0" border="0" id="logintable"> 00271 <tr> 00272 <td colspan="2"><h2>'.htmlspecialchars($this->L_vars[6]).'</h2></td> 00273 </tr>'.($this->commandLI ? ' 00274 <tr class="c-wrong"> 00275 <td colspan="2"><p class="c-wrong">'.htmlspecialchars($this->L_vars[9]).'</p></td> 00276 </tr>' : '').' 00277 <tr class="c-username"> 00278 <td><p class="c-username">'.htmlspecialchars($this->L_vars[0]).':</p></td> 00279 <td><input type="text" name="username" value="'.htmlspecialchars($this->u).'" class="c-username" /></td> 00280 </tr> 00281 <tr class="c-password"> 00282 <td><p class="c-password">'.htmlspecialchars($this->L_vars[1]).':</p></td> 00283 <td><input type="password" name="p_field" value="'.htmlspecialchars($this->p).'" class="c-password" /></td> 00284 </tr>'.($this->interfaceSelector && !$this->loginRefresh ? ' 00285 <tr class="c-interfaceselector"> 00286 <td><p class="c-interfaceselector">'.htmlspecialchars($this->L_vars[2]).':</p></td> 00287 <td>'.$this->interfaceSelector.'</td> 00288 </tr>' : '' ).' 00289 <tr class="c-submit"> 00290 <td></td> 00291 <td><input type="submit" name="commandLI" value="'.htmlspecialchars($this->L_vars[3]).'" class="c-submit" /></td> 00292 </tr> 00293 <tr class="c-info"> 00294 <td colspan="2"><p class="c-info">'.htmlspecialchars($this->L_vars[7]).'</p></td> 00295 </tr> 00296 </table>'; 00297 00298 // Return content: 00299 return $content; 00300 } 00301 00308 function makeLogoutForm() { 00309 global $BE_USER; 00310 00311 00312 $content.=' 00313 00314 <!-- 00315 Login form: 00316 --> 00317 <table cellspacing="0" cellpadding="0" border="0" id="logintable"> 00318 <tr> 00319 <td></td> 00320 <td><h2>'.htmlspecialchars($this->L_vars[6]).'</h2></td> 00321 </tr> 00322 <tr class="c-username"> 00323 <td><p class="c-username">'.htmlspecialchars($this->L_vars[0]).':</p></td> 00324 <td><p class="c-username-current">'.htmlspecialchars($BE_USER->user['username']).'</p></td> 00325 </tr>'.($this->interfaceSelector_jump ? ' 00326 <tr class="c-interfaceselector"> 00327 <td><p class="c-interfaceselector">'.htmlspecialchars($this->L_vars[2]).':</p></td> 00328 <td>'.$this->interfaceSelector_jump.'</td> 00329 </tr>' : '' ).' 00330 <tr class="c-submit"> 00331 <td><input type="hidden" name="p_field" value="" /></td> 00332 <td><input type="submit" name="commandLO" value="'.htmlspecialchars($this->L_vars[4]).'" class="c-submit" /></td> 00333 </tr> 00334 <tr class="c-info"> 00335 <td></td> 00336 <td><p class="c-info">'.htmlspecialchars($this->L_vars[7]).'</p></td> 00337 </tr> 00338 </table>'; 00339 00340 // Return content: 00341 return $content; 00342 } 00343 00350 function wrapLoginForm($content) { 00351 00352 // Logo: 00353 $logo = $GLOBALS['TBE_STYLES']['logo_login'] ? 00354 '<img src="'.htmlspecialchars($GLOBALS['BACK_PATH'].$GLOBALS['TBE_STYLES']['logo_login']).'" alt="" />' : 00355 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/typo3logo.gif','width="333" height="43"').' alt="" />'; 00356 00357 // Login box image: 00358 $loginboxImage = $this->makeLoginBoxImage(); 00359 00360 // Compile the page content: 00361 $content=' 00362 00363 <!-- 00364 Wrapper table for the login form: 00365 --> 00366 <table cellspacing="0" cellpadding="0" border="0" id="wrapper"> 00367 <tr> 00368 <td class="c-wrappercell" align="center"> 00369 00370 <!-- 00371 Login form image: 00372 --> 00373 <div id="loginimage"> 00374 '.$logo.' 00375 </div> 00376 00377 <!-- 00378 Login form wrapper: 00379 --> 00380 <table cellspacing="0" cellpadding="0" border="0" id="loginwrapper"> 00381 <tr> 00382 <td>'.$loginboxImage.'</td> 00383 <td> 00384 '.$content.' 00385 </td> 00386 </tr> 00387 </table> 00388 00389 <!-- 00390 Copy right notice: 00391 --> 00392 <div id="copyrightnotice"> 00393 '.$this->makeCopyrightNotice().' 00394 </div> 00395 00396 '.$this->makeLoginNews().' 00397 </td> 00398 </tr> 00399 </table>'; 00400 00401 // Return content: 00402 return $content; 00403 } 00404 00410 function checkRedirect() { 00411 global $BE_USER,$TBE_TEMPLATE; 00412 00413 // Do redirect: 00414 // 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...) 00415 if ($BE_USER->user['uid'] && ($this->commandLI || $this->loginRefresh || !$this->interfaceSelector)) { 00416 00417 // 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. 00418 if (!$_COOKIE[$BE_USER->name]) { 00419 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); 00420 exit; 00421 } 00422 00423 // Based on specific setting of interface we set the redirect script: 00424 switch ($this->GPinterface) { 00425 case 'backend': 00426 $this->redirectToURL = 'alt_main.php'; 00427 break; 00428 case 'frontend': 00429 $this->redirectToURL = '../'; 00430 break; 00431 } 00432 00433 // If there is a redirect URL AND if loginRefresh is not set... 00434 if (!$this->loginRefresh) { 00435 header('Location: '.t3lib_div::locationHeaderUrl($this->redirectToURL)); 00436 exit; 00437 } else { 00438 $TBE_TEMPLATE->JScode.=$TBE_TEMPLATE->wrapScriptTags(' 00439 if (parent.opener && parent.opener.busy) { 00440 parent.opener.busy.loginRefreshed(); 00441 parent.close(); 00442 } 00443 '); 00444 } 00445 } elseif(!$BE_USER->user['uid'] && $this->commandLI) { 00446 sleep(5); 00447 } 00448 } 00449 00455 function makeInterfaceSelectorBox() { 00456 global $TYPO3_CONF_VARS; 00457 00458 // Reset variables: 00459 $this->interfaceSelector = ''; 00460 $this->interfaceSelector_hidden=''; 00461 $this->interfaceSelector_jump = ''; 00462 #debug($this->redirect_url); 00463 // If interfaces are defined AND no input redirect URL in GET vars: 00464 if ($TYPO3_CONF_VARS['BE']['interfaces'] && !$this->redirect_url) { 00465 $parts = t3lib_div::trimExplode(',',$TYPO3_CONF_VARS['BE']['interfaces']); 00466 if (count($parts)>1) { // Only if more than one interface is defined will we show the selector: 00467 00468 // Initialize: 00469 $tempLabels=explode(',',$this->L_vars[5]); 00470 $labels=array(); 00471 $labels['backend']=$tempLabels[0]; 00472 $labels['frontend']=$tempLabels[1]; 00473 00474 $jumpScript=array(); 00475 $jumpScript['backend']='alt_main.php'; 00476 $jumpScript['frontend']='../'; 00477 00478 // Traverse the interface keys: 00479 foreach($parts as $valueStr) { 00480 $this->interfaceSelector.=' 00481 <option value="'.htmlspecialchars($valueStr).'">'.htmlspecialchars($labels[$valueStr]).'</option>'; 00482 $this->interfaceSelector_jump.=' 00483 <option value="'.htmlspecialchars($jumpScript[$valueStr]).'">'.htmlspecialchars($labels[$valueStr]).'</option>'; 00484 } 00485 $this->interfaceSelector=' 00486 <select name="interface" class="c-interfaceselector">'.$this->interfaceSelector.' 00487 </select>'; 00488 $this->interfaceSelector_jump=' 00489 <select name="interface" class="c-interfaceselector" onchange="document.location=this.options[this.selectedIndex].value;">'.$this->interfaceSelector_jump.' 00490 </select>'; 00491 00492 } else { // If there is only ONE interface value set: 00493 00494 $this->interfaceSelector_hidden='<input type="hidden" name="interface" value="'.trim($TYPO3_CONF_VARS['BE']['interfaces']).'" />'; 00495 } 00496 } 00497 } 00498 00509 function makeCopyrightNotice() { 00510 00511 // Get values from TYPO3_CONF_VARS: 00512 $loginCopyrightWarrantyProvider = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyProvider'])); 00513 $loginCopyrightWarrantyURL = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyURL'])); 00514 00515 // Make warranty note: 00516 if (strlen($loginCopyrightWarrantyProvider)>=2 && strlen($loginCopyrightWarrantyURL)>=10) { 00517 $warrantyNote='Warranty is supplied by '.htmlspecialchars($loginCopyrightWarrantyProvider).'; <a href="'.htmlspecialchars($loginCopyrightWarrantyURL).'" target="_blank">click for details.</a>'; 00518 } else { 00519 $warrantyNote='TYPO3 comes with ABSOLUTELY NO WARRANTY; <a href="http://typo3.com/1316.0.html" target="_blank">click for details.</a>'; 00520 } 00521 00522 // Compile full copyright notice: 00523 $copyrightNotice = '<a href="http://typo3.com/" target="_blank">'. 00524 '<img src="gfx/loginlogo_transp.gif" width="75" height="19" alt="TYPO3 logo" align="left" />'. 00525 'TYPO3 CMS'.($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightShowVersion']?' ver. '.htmlspecialchars($GLOBALS['TYPO_VERSION']):''). 00526 '</a>. '. 00527 'Copyright © 1998-2004 Kasper Skårhøj. Extensions are copyright of their respective owners. '. 00528 'Go to <a href="http://typo3.com/" target="_blank">http://typo3.com/</a> for details. '. 00529 $warrantyNote.' '. 00530 '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>. '. 00531 'Obstructing the appearance of this notice is prohibited by law.'; 00532 00533 // Return notice: 00534 return $copyrightNotice; 00535 } 00536 00542 function makeLoginBoxImage() { 00543 $loginboxImage = ''; 00544 if ($GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder']) { // Look for rotation image folder: 00545 $absPath = t3lib_div::resolveBackPath(PATH_typo3.$GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder']); 00546 00547 // Get rotation folder: 00548 $dir = t3lib_div::getFileAbsFileName($absPath); 00549 if ($dir && @is_dir($dir)) { 00550 00551 // Get files for rotation into array: 00552 $files = t3lib_div::getFilesInDir($dir,'png,jpg,gif'); 00553 00554 // Pick random file: 00555 srand((float) microtime() * 10000000); 00556 $randImg = array_rand($files, 1); 00557 00558 // Get size of random file: 00559 $imgSize = @getimagesize($dir.$files[$randImg]); 00560 00561 // Create image tag: 00562 if (is_array($imgSize)) { 00563 $loginboxImage = '<img src="'.htmlspecialchars($GLOBALS['TBE_STYLES']['loginBoxImage_rotationFolder'].$files[$randImg]).'" '.$imgSize[3].' id="loginbox-image" alt="" />'; 00564 } 00565 } 00566 } else { // If no rotation folder configured, print default image: 00567 $loginImage = 'loginimage.jpg'; 00568 $imagecopy = $loginImage=='loginbox_image_dev.png' ? 'You are running the CVS version of TYPO3 '.$GLOBALS['TYPO_VERSION'] : 'Photo: © 2004 Kasper Skårhøj'; // Directly outputted in image attributes... 00569 $loginboxImage = '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/'.$loginImage,'width="200" height="133"').' id="loginbox-image" alt="'.$imagecopy.'" title="'.$imagecopy.'" />'; 00570 } 00571 00572 // Return image tag: 00573 return $loginboxImage; 00574 } 00575 00582 function makeLoginNews() { 00583 00584 // Reset output variable: 00585 $newsContent= ''; 00586 00587 // Traverse news array IF there are records in it: 00588 if (is_array($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews']) && count($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'])) { 00589 foreach($GLOBALS['TYPO3_CONF_VARS']['BE']['loginNews'] as $newsItem) { 00590 $newsContent.=' 00591 <tr> 00592 <td class="c-date">'.htmlspecialchars($newsItem['date']).'</td> 00593 <td class="c-header">'.htmlspecialchars($newsItem['header']).'</td> 00594 </tr> 00595 <tr> 00596 <td></td> 00597 <td class="c-content">'.trim($newsItem['content']).'</td> 00598 </tr> 00599 <tr class="c-spacer"> 00600 <td colspan="2"></td> 00601 </tr> 00602 '; 00603 } 00604 00605 // Wrap in a table: 00606 $newsContent= ' 00607 00608 <!-- 00609 Login screen news: 00610 --> 00611 <div id="loginNews"> 00612 <h2>'.htmlspecialchars($this->L_vars[8]).'</h2> 00613 <table border="0" cellpadding="0" cellspacing="0"> 00614 '.$newsContent.' 00615 </table> 00616 </div> 00617 '; 00618 } 00619 00620 // Return content: 00621 return $newsContent; 00622 } 00623 } 00624 00625 // Include extension? 00626 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/index.php']) { 00627 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/index.php']); 00628 } 00629 00630 00631 00632 00633 00634 00635 00636 00637 00638 00639 // Make instance: 00640 $SOBE = t3lib_div::makeInstance('SC_index'); 00641 $SOBE->init(); 00642 $SOBE->main(); 00643 $SOBE->printContent(); 00644 ?>