Fixed bug #17665: Remove deprecated method redirect() from t3lib_userAuth
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tsfebeuserauth.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@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 * Class for TYPO3 backend user authentication in the TSFE frontend
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
32 * XHTML compliant
33 *
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 103: class t3lib_tsfeBeUserAuth extends t3lib_beUserAuth
42 * 129: function extInitFeAdmin()
43 * 154: function extPrintFeAdminDialog()
44 *
45 * SECTION: Creating sections of the Admin Panel
46 * 250: function extGetCategory_preview($out='')
47 * 283: function extGetCategory_cache($out='')
48 * 321: function extGetCategory_publish($out='')
49 * 356: function extGetCategory_edit($out='')
50 * 400: function extGetCategory_tsdebug($out='')
51 * 433: function extGetCategory_info($out='')
52 *
53 * SECTION: Admin Panel Layout Helper functions
54 * 506: function extGetHead($pre)
55 * 526: function extItemLink($pre,$str)
56 * 542: function extGetItem($pre,$element)
57 * 559: function extFw($str)
58 * 568: function ext_makeToolBar()
59 *
60 * SECTION: TSFE BE user Access Functions
61 * 637: function checkBackendAccessSettingsFromInitPhp()
62 * 682: function extPageReadAccess($pageRec)
63 * 693: function extAdmModuleEnabled($key)
64 * 709: function extSaveFeAdminConfig()
65 * 741: function extGetFeAdminValue($pre,$val='')
66 * 783: function extIsAdmMenuOpen($pre)
67 *
68 * SECTION: TSFE BE user Access Functions
69 * 818: function extGetTreeList($id,$depth,$begin=0,$perms_clause)
70 * 849: function extGetNumberOfCachedPages($page_id)
71 *
72 * SECTION: Localization handling
73 * 888: function extGetLL($key)
74 *
75 * SECTION: Frontend Editing
76 * 932: function extIsEditAction()
77 * 954: function extIsFormShown()
78 * 970: function extEditAction()
79 *
80 * TOTAL FUNCTIONS: 25
81 * (This index is automatically created/updated by the extension "extdeveval")
82 *
83 */
84
85
86 /**
87 * TYPO3 backend user authentication in the TSFE frontend.
88 * This includes mainly functions related to the Admin Panel
89 *
90 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
91 * @package TYPO3
92 * @subpackage t3lib
93 */
94 class t3lib_tsfeBeUserAuth extends t3lib_beUserAuth {
95 /**
96 * Form field with login name.
97 *
98 * @var string
99 */
100 public $formfield_uname = '';
101
102 /**
103 * Form field with password.
104 *
105 * @var string
106 */
107 public $formfield_uident = '';
108
109 /**
110 * Form field with a unique value which is used to encrypt the password and username.
111 *
112 * @var string
113 */
114 public $formfield_chalvalue = '';
115
116 /**
117 * Sets the level of security. *'normal' = clear-text. 'challenged' = hashed password/username.
118 * from form in $formfield_uident. 'superchallenged' = hashed password hashed again with username.
119 *
120 * @var string
121 */
122 public $security_level = '';
123
124 /**
125 * Decides if the writelog() function is called at login and logout.
126 *
127 * @var boolean
128 */
129 public $writeStdLog = FALSE;
130
131 /**
132 * If the writelog() functions is called if a login-attempt has be tried without success.
133 *
134 * @var boolean
135 */
136 public $writeAttemptLog = FALSE;
137
138 /**
139 * Array of page related information (uid, title, depth).
140 *
141 * @var array
142 */
143 public $extPageInTreeInfo = array();
144
145 /**
146 * General flag which is set if the adminpanel should be displayed at all.
147 *
148 * @var boolean
149 */
150 public $extAdmEnabled = FALSE;
151
152 /**
153 * Instance of the admin panel
154 *
155 * @var tslib_AdminPanel
156 */
157 public $adminPanel = NULL;
158
159 /**
160 * Class for frontend editing.
161 *
162 * @var t3lib_frontendedit
163 */
164 public $frontendEdit = NULL;
165
166 /**
167 * Initializes the admin panel.
168 *
169 * @return void
170 */
171 public function initializeAdminPanel() {
172 $this->extAdminConfig = $this->getTSConfigProp('admPanel');
173
174 if (isset($this->extAdminConfig['enable.'])) {
175 foreach ($this->extAdminConfig['enable.'] as $key => $value) {
176 if ($value) {
177 $this->adminPanel = t3lib_div::makeInstance('tslib_AdminPanel');
178 $this->extAdmEnabled = TRUE;
179
180 break;
181 }
182 }
183 }
184 }
185
186 /**
187 * Initializes frontend editing.
188 *
189 * @return void
190 */
191 public function initializeFrontendEdit() {
192 if (isset($this->extAdminConfig['enable.']) && $this->isFrontendEditingActive()) {
193 foreach ($this->extAdminConfig['enable.'] as $key => $value) {
194 if ($value) {
195 if ($GLOBALS['TSFE'] instanceof tslib_fe) {
196 // Grab the Page TSConfig property that determines which controller to use.
197 $pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
198 $controllerKey = isset($pageTSConfig['TSFE.']['frontendEditingController']) ? $pageTSConfig['TSFE.']['frontendEditingController'] : 'default';
199 } else {
200 $controllerKey = 'default';
201 }
202
203 $controllerClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController'][$controllerKey];
204 if ($controllerClass) {
205 $this->frontendEdit = t3lib_div::getUserObj($controllerClass, FALSE);
206 }
207
208 break;
209 }
210 }
211 }
212 }
213
214 /**
215 * Determines whether frontend editing is currently active.
216 *
217 * @return boolean Wheter frontend editing is active
218 */
219 public function isFrontendEditingActive() {
220 return ($this->extAdmEnabled
221 && ($this->adminPanel->isAdminModuleEnabled('edit') && $this->adminPanel->isAdminModuleOpen('edit')
222 || $GLOBALS['TSFE']->displayEditIcons == 1)
223 );
224 }
225
226 /**
227 * Delegates to the appropriate view and renders the admin panel content.
228 *
229 * @return string.
230 */
231 public function displayAdminPanel() {
232 $content = $this->adminPanel->display();
233
234 return $content;
235 }
236
237 /**
238 * Determines whether the admin panel is enabled and visible.
239 *
240 * @return boolean Whether the admin panel is enabled and visible
241 */
242 public function isAdminPanelVisible() {
243 return ($this->extAdmEnabled && !$this->extAdminConfig['hide'] && $GLOBALS['TSFE']->config['config']['admPanel']);
244 }
245
246 /*****************************************************
247 *
248 * TSFE BE user Access Functions
249 *
250 ****************************************************/
251
252 /**
253 * Implementing the access checks that the typo3/init.php script does before a user is ever logged in.
254 * Used in the frontend.
255 *
256 * @return boolean Returns true if access is OK
257 * @see typo3/init.php, t3lib_beuserauth::backendCheckLogin()
258 */
259 public function checkBackendAccessSettingsFromInitPhp() {
260 global $TYPO3_CONF_VARS;
261
262 // **********************
263 // Check Hardcoded lock on BE:
264 // **********************
265 if ($TYPO3_CONF_VARS['BE']['adminOnly'] < 0) {
266 return FALSE;
267 }
268
269 // **********************
270 // Check IP
271 // **********************
272 if (trim($TYPO3_CONF_VARS['BE']['IPmaskList'])) {
273 if (!t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['BE']['IPmaskList'])) {
274 return FALSE;
275 }
276 }
277
278
279 // **********************
280 // Check SSL (https)
281 // **********************
282 if (intval($TYPO3_CONF_VARS['BE']['lockSSL']) && $TYPO3_CONF_VARS['BE']['lockSSL'] != 3) {
283 if (!t3lib_div::getIndpEnv('TYPO3_SSL')) {
284 return FALSE;
285 }
286 }
287
288 // Finally a check from t3lib_beuserauth::backendCheckLogin()
289 if ($this->isUserAllowedToLogin()) {
290 return TRUE;
291 } else {
292 return FALSE;
293 }
294 }
295
296
297 /**
298 * Evaluates if the Backend User has read access to the input page record.
299 * The evaluation is based on both read-permission and whether the page is found in one of the users webmounts. Only if both conditions are true will the function return true.
300 * Read access means that previewing is allowed etc.
301 * Used in index_ts.php
302 *
303 * @param array The page record to evaluate for
304 * @return boolean True if read access
305 */
306 public function extPageReadAccess($pageRec) {
307 return $this->isInWebMount($pageRec['uid']) && $this->doesUserHaveAccess($pageRec, 1);
308 }
309
310 /*****************************************************
311 *
312 * TSFE BE user Access Functions
313 *
314 ****************************************************/
315
316 /**
317 * Generates a list of Page-uid's from $id. List does not include $id itself
318 * The only pages excluded from the list are deleted pages.
319 *
320 * @param integer Start page id
321 * @param integer Depth to traverse down the page tree.
322 * @param integer $begin is an optional integer that determines at which level in the tree to start collecting uid's. Zero means 'start right away', 1 = 'next level and out'
323 * @param string Perms clause
324 * @return string Returns the list with a comma in the end (if any pages selected!)
325 */
326 public function extGetTreeList($id, $depth, $begin = 0, $perms_clause) {
327 $depth = intval($depth);
328 $begin = intval($begin);
329 $id = intval($id);
330 $theList = '';
331
332 if ($id && $depth > 0) {
333 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
334 'uid,title',
335 'pages',
336 'pid=' . $id . ' AND doktype IN (' . $GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'] . ') AND deleted=0 AND ' . $perms_clause
337 );
338 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
339 if ($begin <= 0) {
340 $theList .= $row['uid'] . ',';
341 $this->extPageInTreeInfo[] = array($row['uid'], htmlspecialchars($row['title'], $depth));
342 }
343 if ($depth > 1) {
344 $theList .= $this->extGetTreeList($row['uid'], $depth - 1, $begin - 1, $perms_clause);
345 }
346 }
347 }
348 return $theList;
349 }
350
351 /**
352 * Returns the number of cached pages for a page id.
353 *
354 * @param integer The page id.
355 * @return integer The number of pages for this page in the table "cache_pages"
356 */
357 public function extGetNumberOfCachedPages($pageId) {
358 if (TYPO3_UseCachingFramework) {
359 $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
360 $pageCacheEntries = $pageCache->getByTag('pageId_' . (int) $pageId);
361 $count = count($pageCacheEntries);
362 } else {
363 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'cache_pages', 'page_id=' . intval($pageId));
364 list($count) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
365 }
366 return $count;
367 }
368
369
370 /*****************************************************
371 *
372 * Localization handling
373 *
374 ****************************************************/
375
376 /**
377 * Returns the label for key, $key. If a translation for the language set in $this->uc['lang'] is found that is returned, otherwise the default value.
378 * IF the global variable $LOCAL_LANG is NOT an array (yet) then this function loads the global $LOCAL_LANG array with the content of "sysext/lang/locallang_tsfe.php" so that the values therein can be used for labels in the Admin Panel
379 *
380 * @param string Key for a label in the $LOCAL_LANG array of "sysext/lang/locallang_tsfe.php"
381 * @return string The value for the $key
382 */
383 public function extGetLL($key) {
384 global $LOCAL_LANG;
385 if (!is_array($LOCAL_LANG)) {
386 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_tsfe.php');
387 #include('./'.TYPO3_mainDir.'sysext/lang/locallang_tsfe.php');
388 if (!is_array($LOCAL_LANG)) {
389 $LOCAL_LANG = array();
390 }
391 }
392
393 $labelStr = htmlspecialchars($GLOBALS['LANG']->getLL($key)); // Label string in the default backend output charset.
394
395 // Convert to utf-8, then to entities:
396 if ($GLOBALS['LANG']->charSet != 'utf-8') {
397 $labelStr = $GLOBALS['LANG']->csConvObj->utf8_encode($labelStr, $GLOBALS['LANG']->charSet);
398 }
399 $labelStr = $GLOBALS['LANG']->csConvObj->utf8_to_entities($labelStr);
400
401 // Return the result:
402 return $labelStr;
403 }
404
405 }
406
407
408 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsfebeuserauth.php'])) {
409 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsfebeuserauth.php']);
410 }
411
412 ?>