Added more comments, $Id$ keywords etc for the whole core of TYPO3.
[Packages/TYPO3.CMS.git] / typo3 / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 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 *
32 * @author Kasper Skaarhoj <kasper@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 89: class SC_index
40 * 107: function init()
41 * 141: function main()
42 * 152: function makeLoginLogoutForm()
43 * 294: function makeStartHTML()
44 * 359: function printContent()
45 * 366: function doChallengeResponse()
46 *
47 * TOTAL FUNCTIONS: 6
48 * (This index is automatically created/updated by the extension "extdeveval")
49 *
50 */
51
52
53 define('TYPO3_PROCEED_IF_NO_USER', 1);
54 require ('init.php');
55 require ('template.php');
56 require_once (PATH_t3lib.'class.t3lib_loadmodules.php');
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 /**
73 * Script Class
74 *
75 * GET vars:
76 * u= default username
77 * p= default password
78 * L= 'OUT' = logout
79 * redirect_url= URL to redirect to instead of starting the TBE
80 *
81 * commandLI
82 * loginRefresh
83 * interface
84 *
85 * @author Kasper Skaarhoj <kasper@typo3.com>
86 * @package TYPO3
87 * @subpackage core
88 */
89 class SC_index {
90 var $content;
91
92 var $loadModules;
93 var $redirect_url;
94 var $redirect_url_input;
95 var $GPinterface;
96 var $u;
97 var $p;
98 var $L;
99 var $L_vars;
100 var $interfaceSelector;
101
102 /**
103 * Initialize the login box. Will also react on a &L=OUT flag and exit.
104 *
105 * @return [type] ...
106 */
107 function init() {
108 global $BE_USER,$TYPO3_CONF_VARS;
109
110 // ******************************
111 // Registering Global Vars
112 // ******************************
113 // URL to redirect to.
114 $this->redirect_url = t3lib_div::GPvar("redirect_url");
115 $this->redirect_url_input = $this->redirect_url ? 1 : 0;
116 $this->GPinterface = t3lib_div::GPvar("interface");
117 $this->L_vars = explode("|",$TYPO3_CONF_VARS["BE"]["loginLabels"]);
118
119 // Only change redirect_url if it has not been set from outside...
120 if (!$this->redirect_url_input) {$this->redirect_url="alt_main.php";}
121
122 $this->u = t3lib_div::GPvar("u"); // preset username
123 $this->p = t3lib_div::GPvar("p"); // preset password
124 $this->L = t3lib_div::GPvar("L"); // If "L" is "OUT", then any logged in used is logged out. If redirect_url is given, we redirect to it
125
126 // *********
127 // Logout?
128 // *********
129 if ($this->L=="OUT" && is_object($BE_USER)) {
130 $BE_USER->logoff();
131 if ($this->redirect_url) header("Location: ".t3lib_div::locationHeaderUrl($this->redirect_url));
132 exit;
133 }
134 }
135
136 /**
137 * Main function - just calling subfunctions.
138 *
139 * @return [type] ...
140 */
141 function main() {
142 $this->content="";
143 $this->content.=$this->makeLoginLogoutForm();
144 $this->content.=$this->makeStartHTML();
145 }
146
147 /**
148 * Making the login/logout form
149 *
150 * @return [type] ...
151 */
152 function makeLoginLogoutForm() {
153 global $BE_USER,$TYPO3_CONF_VARS,$TBE_TEMPLATE;
154
155 $TBE_TEMPLATE->bgColor="#CCCCCC";
156
157 // Code for the challenged form.
158 $challenge = md5(uniqid(""));
159
160 $content='
161 <div align="center">
162 <form action="index.php" method="POST" name="loginform" autocomplete="off">
163 <table border=0 cellspacing=2 cellpadding=10 width="100%">
164 <tr>
165 <td bgcolor="'.$TBE_TEMPLATE->bgColor2.'" align="center">
166 <table border=0 cellspacing=0 cellpadding=2>
167 <tr>
168 <td><img src="clear.gif" width=1 height=1 hspace=35></td>
169 <td><img src="clear.gif" width=1 height=1 hspace=5></td>
170 <td><img src="clear.gif" width=1 height=1 hspace=25></td>
171 </tr>
172 ';
173
174 // MAKING interface selector:
175 $this->interfaceSelector = "";
176 $interfaceHidden="";
177 $interfaceSelector_jump = "";
178 if ($TYPO3_CONF_VARS["BE"]["interfaces"] && !$this->redirect_url_input) {
179 $parts = t3lib_div::trimExplode(",",$TYPO3_CONF_VARS["BE"]["interfaces"]);
180 if (count($parts)>1) {
181 $tempLabels=explode(",",$this->L_vars[5]);
182 $labels=array();
183 $labels["backend"]=$tempLabels[0];
184 $labels["frontend"]=$tempLabels[1];
185
186 $jumpScript=array();
187 $jumpScript["backend"]="alt_main.php";
188 $jumpScript["frontend"]="../";
189
190 reset($parts);
191 while(list(,$valueStr)=each($parts)) {
192 $this->interfaceSelector.='<option value="'.$valueStr.'">'.htmlspecialchars($labels[$valueStr]).'</option>';
193 $interfaceSelector_jump.='<option value="'.$jumpScript[$valueStr].'">'.htmlspecialchars($labels[$valueStr]).'</option>';
194 }
195 $this->interfaceSelector='<select name="interface">'.$this->interfaceSelector.'</select>';
196 $interfaceSelector_jump='<select name="interface" onChange="document.location=this.options[this.selectedIndex].value;">'.$interfaceSelector_jump.'</select>';
197 } elseif (!$this->redirect_url_input) {
198 $interfaceHidden='<input type="hidden" name="interface" value="'.trim($TYPO3_CONF_VARS["BE"]["interfaces"]).'">';
199 $this->GPinterface=trim($TYPO3_CONF_VARS["BE"]["interfaces"]);
200 }
201 }
202
203 // COPYRIGHT notice
204 $loginCopyrightWarrantyProvider = strip_tags(trim($GLOBALS["TYPO3_CONF_VARS"]["SYS"]["loginCopyrightWarrantyProvider"]));
205 $loginCopyrightWarrantyURL = strip_tags(trim($GLOBALS["TYPO3_CONF_VARS"]["SYS"]["loginCopyrightWarrantyURL"]));
206
207 if (strlen($loginCopyrightWarrantyProvider)>=2 && strlen($loginCopyrightWarrantyURL)>=10) {
208 $warrantyNote='Warranty is supplied by '.$loginCopyrightWarrantyProvider.'; <a href="'.$loginCopyrightWarrantyURL.'" target="_blank">click for details.</a>';
209 } else {
210 $warrantyNote='TYPO3 comes with ABSOLUTELY NO WARRANTY; <a href="http://typo3.com/1316.0.html" target="_blank">click for details.</a>';
211 }
212
213 // No user session:
214 if (!$BE_USER->user["uid"]) {
215 $content.='
216 <tr>
217 <td nowrap="nowrap"><font face="VERDANA,ARIAL,SANS-SERIF" size="2"><b>'.$this->L_vars[0].':</b></font></td>
218 <td></td>
219 <td nowrap="nowrap"><input type="Text" name="username" value="'.$this->u.'"'.$TBE_TEMPLATE->formWidth(10).' onBlur="if(parent.typoWin && parent.typoWin.TS){this.value=parent.typoWin.TS.username;}"></td>
220 </tr>
221 <tr>
222 <td nowrap="nowrap"><font face="VERDANA,ARIAL,SANS-SERIF" size="2"><b>'.$this->L_vars[1].':</b></font></td>
223 <td></td>
224 <td nowrap="nowrap"><input type="password" name="p_field" value="'.$this->p.'"'.$TBE_TEMPLATE->formWidth(10).'></td>
225 </tr>';
226 if ($this->interfaceSelector && !t3lib_div::GPvar("loginRefresh")) {
227 $content.='<tr>
228 <td nowrap="nowrap"><font face="VERDANA,ARIAL,SANS-SERIF" size="2"><b>'.$this->L_vars[2].':</b></font></td>
229 <td></td>
230 <td nowrap="nowrap">'.$this->interfaceSelector.'</td>
231 </tr>';
232 }
233 $content.='<tr>
234 <td nowrap="nowrap"></td>
235 <td></td>
236 <td nowrap="nowrap"><input type="submit" name="commandLI" value="'.$this->L_vars[3].'" onClick="document.loginform.login_status.value=\'login\';doChallengeResponse();"></td>
237 </tr>
238 ';
239 $content.='<tr>
240 <td colspan=3 align="center"><font face="VERDANA,ARIAL,SANS-SERIF" size="1" color="#666666">'.$this->L_vars[7].'</font></td>
241 </tr>
242 ';
243 } else { // If there is a user session already:
244 if ($interfaceSelector_jump) {
245 $content.='<tr>
246 <td nowrap="nowrap"><font face="VERDANA,ARIAL,SANS-SERIF" size="2"><b>'.$this->L_vars[2].':</b></font></td>
247 <td></td>
248 <td nowrap="nowrap">'.$interfaceSelector_jump.'</td>
249 </tr>';
250 $content.='<tr>
251 <td colspan=3>&nbsp;</td>
252 </tr>';
253 }
254 $content.='
255 <tr>
256 <td nowrap="nowrap"><B><font face="VERDANA,ARIAL,SANS-SERIF" size="2">&nbsp;&nbsp;'.$BE_USER->user["username"].'&nbsp;&nbsp;</font></b></td>
257 <td></td>
258 <td nowrap="nowrap"><input type="hidden" name="p_field" value=""><input type="Submit" name="commandLO" value="'.$this->L_vars[4].'" onClick="document.loginform.p_field.value=\'\'; document.loginform.login_status.value=\'logout\';"></td>
259 </tr>
260 ';
261 }
262
263 // Ending form:
264 $content.='
265 </table>
266 </td>
267 </tr>
268 </table>
269
270
271 <div align="left" style="text-align:left;font-family: verdana,arial,helvetica; font-size:10px; margin-top:10px; width:500px;"><a href="http://typo3.com/" target="_blank"><img src="gfx/loginlogo_transp.gif" width="75" vspace=2 height="19" alt="TYPO3 logo" border="0" align="left">TYPO3 CMS'.($GLOBALS["TYPO3_CONF_VARS"]["SYS"]["loginCopyrightShowVersion"]?' ver. '.htmlspecialchars($GLOBALS["TYPO_VERSION"]):'').'</a>. Copyright &copy; 1998-2003 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.
272 '.strip_tags($warrantyNote,'<a>').' 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>. Obstructing the appearance of this notice is prohibited by law.
273 </div>
274
275 <input type="Hidden" name="userident" value="">
276 <input type="Hidden" name="challenge" value="'.$challenge.'">
277 <input type="Hidden" name="redirect_url" value="'.htmlspecialchars($this->redirect_url).'">
278 <input type="Hidden" name="loginRefresh" value="'.t3lib_div::GPvar("loginRefresh").'">
279 <input type="Hidden" name="login_status" value="">
280 '.$interfaceHidden.'
281 </form>
282 </div>
283 ';
284
285 // This returns the login form.
286 return $content;
287 }
288
289 /**
290 * Make the HTML which will start the BE:
291 *
292 * @return [type] ...
293 */
294 function makeStartHTML() {
295 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
296 global $TBE_MODULES,$TBE_TEMPLATE;
297
298 $content="";;
299
300 // This should output the username by default into the re-login form
301 if (!$BE_USER->user["uid"]) {
302 $content.='
303 <script language="javascript" type="text/javascript">
304 if (parent.typoWin && parent.typoWin.TS) {
305 document.loginform.username.value = parent.typoWin.TS.username;
306 }
307 if (document.loginform.username.value == "") {
308 document.loginform.username.focus();
309 } else {
310 document.loginform.p_field.focus();
311 }
312 </script>
313 ';
314 }
315
316 // If a users is logged in:
317 // AND if either the login is just done (commandLI) or a loginRefresh is done or 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...)
318 if ($BE_USER->user["uid"] && (t3lib_div::GPvar("commandLI") || t3lib_div::GPvar("loginRefresh") || !$this->interfaceSelector)) {
319
320 // 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.
321 if (!$GLOBALS["HTTP_COOKIE_VARS"][$BE_USER->name]) {
322 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);
323 exit;
324 }
325
326 // based on specific setting of interface we set the redirect script:
327 switch ($this->GPinterface) {
328 case "backend":
329 $this->redirect_url = "alt_main.php";
330 break;
331 case "frontend":
332 $this->redirect_url = "../";
333 break;
334 }
335
336 // If there is a redirect URL AND if loginRefresh is not set...
337 if ($this->redirect_url && !t3lib_div::GPvar("loginRefresh")) {
338 header("Location: ".t3lib_div::locationHeaderUrl($this->redirect_url));
339 exit;
340 } else {
341 $content.='
342 <script language="javascript" type="text/javascript">
343 if (parent.typoWin && parent.typoWin.busy) {
344 parent.typoWin.busy.loginRefreshed();
345 parent.close();
346 }
347 </script>
348 ';
349 }
350 }
351 return $content;
352 }
353
354 /**
355 * Output it all...
356 *
357 * @return [type] ...
358 */
359 function printContent() {
360 global $TBE_TEMPLATE;
361
362 echo $TBE_TEMPLATE->startPage("TYPO3 Login");
363 echo '
364 <script language="javascript" type="text/javascript" src="md5.js"></script>
365 <script language="javascript" type="text/javascript">
366 function doChallengeResponse() {
367 password = document.loginform.p_field.value;
368 if (password) {
369 password = MD5(password); // this makes it superchallenged!!
370 str = document.loginform.username.value+":"+password+":"+document.loginform.challenge.value;
371 document.loginform.userident.value = MD5(str);
372 document.loginform.p_field.value = "";
373 document.loginform.submit();
374 }
375 }
376 </script>';
377
378 t3lib_BEfunc::typo3PrintError ($this->L_vars[6],$this->content,"",0);
379 echo $TBE_TEMPLATE->endPage();
380 }
381 }
382
383 // Include extension?
384 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/index.php']) {
385 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/index.php']);
386 }
387
388
389
390
391
392
393
394
395
396
397 // Make instance:
398 $SOBE = t3lib_div::makeInstance('SC_index');
399 $SOBE->init();
400 $SOBE->main();
401 $SOBE->printContent();
402 ?>