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