[CLEANUP] Cleanup jumpToUrl() and unused JS in Backend
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / FrontendBackendUserAuthentication.php
1 <?php
2 namespace TYPO3\CMS\Backend;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32 /**
33 * TYPO3 backend user authentication in the TSFE frontend.
34 * This includes mainly functions related to the Admin Panel
35 *
36 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
37 */
38 class FrontendBackendUserAuthentication extends \TYPO3\CMS\Core\Authentication\BackendUserAuthentication {
39
40 /**
41 * Form field with login name.
42 *
43 * @var string
44 */
45 public $formfield_uname = '';
46
47 /**
48 * Form field with password.
49 *
50 * @var string
51 */
52 public $formfield_uident = '';
53
54 /**
55 * Form field with a unique value which is used to encrypt the password and username.
56 *
57 * @var string
58 */
59 public $formfield_chalvalue = '';
60
61 /**
62 * Decides if the writelog() function is called at login and logout.
63 *
64 * @var boolean
65 */
66 public $writeStdLog = FALSE;
67
68 /**
69 * If the writelog() functions is called if a login-attempt has be tried without success.
70 *
71 * @var boolean
72 */
73 public $writeAttemptLog = FALSE;
74
75 /**
76 * Array of page related information (uid, title, depth).
77 *
78 * @var array
79 */
80 public $extPageInTreeInfo = array();
81
82 /**
83 * General flag which is set if the adminpanel should be displayed at all.
84 *
85 * @var boolean
86 */
87 public $extAdmEnabled = FALSE;
88
89 /**
90 * @var \TYPO3\CMS\Frontend\View\AdminPanelView Instance of admin panel
91 */
92 public $adminPanel = NULL;
93
94 /**
95 * @var \TYPO3\CMS\Core\FrontendEditing\FrontendEditingController
96 */
97 public $frontendEdit = NULL;
98
99 /**
100 * Initializes the admin panel.
101 *
102 * @return void
103 */
104 public function initializeAdminPanel() {
105 $this->extAdminConfig = $this->getTSConfigProp('admPanel');
106 if (isset($this->extAdminConfig['enable.'])) {
107 foreach ($this->extAdminConfig['enable.'] as $key => $value) {
108 if ($value) {
109 $this->adminPanel = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\View\\AdminPanelView');
110 $this->extAdmEnabled = TRUE;
111 break;
112 }
113 }
114 }
115 }
116
117 /**
118 * Initializes frontend editing.
119 *
120 * @return void
121 */
122 public function initializeFrontendEdit() {
123 if (isset($this->extAdminConfig['enable.']) && $this->isFrontendEditingActive()) {
124 foreach ($this->extAdminConfig['enable.'] as $key => $value) {
125 if ($value) {
126 if ($GLOBALS['TSFE'] instanceof \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController) {
127 // Grab the Page TSConfig property that determines which controller to use.
128 $pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
129 $controllerKey = isset($pageTSConfig['TSFE.']['frontendEditingController']) ? $pageTSConfig['TSFE.']['frontendEditingController'] : 'default';
130 } else {
131 $controllerKey = 'default';
132 }
133 $controllerClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController'][$controllerKey];
134 if ($controllerClass) {
135 $this->frontendEdit = GeneralUtility::getUserObj($controllerClass, FALSE);
136 }
137 break;
138 }
139 }
140 }
141 }
142
143 /**
144 * Determines whether frontend editing is currently active.
145 *
146 * @return boolean Whether frontend editing is active
147 */
148 public function isFrontendEditingActive() {
149 return $this->extAdmEnabled && ($this->adminPanel->isAdminModuleEnabled('edit') && $this->adminPanel->isAdminModuleOpen('edit') || $GLOBALS['TSFE']->displayEditIcons == 1);
150 }
151
152 /**
153 * Delegates to the appropriate view and renders the admin panel content.
154 *
155 * @return string.
156 */
157 public function displayAdminPanel() {
158 $content = $this->adminPanel->display();
159 return $content;
160 }
161
162 /**
163 * Determines whether the admin panel is enabled and visible.
164 *
165 * @return boolean Whether the admin panel is enabled and visible
166 */
167 public function isAdminPanelVisible() {
168 return $this->extAdmEnabled && !$this->extAdminConfig['hide'] && $GLOBALS['TSFE']->config['config']['admPanel'];
169 }
170
171 /*****************************************************
172 *
173 * TSFE BE user Access Functions
174 *
175 ****************************************************/
176 /**
177 * Implementing the access checks that the typo3/init.php script does before a user is ever logged in.
178 * Used in the frontend.
179 *
180 * @return boolean Returns TRUE if access is OK
181 */
182 public function checkBackendAccessSettingsFromInitPhp() {
183 // Check Hardcoded lock on BE
184 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
185 return FALSE;
186 }
187 // Check IP
188 if (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
189 if (!GeneralUtility::cmpIP(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
190 return FALSE;
191 }
192 }
193 // Check SSL (https)
194 if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] && $GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] !== 3) {
195 if (!GeneralUtility::getIndpEnv('TYPO3_SSL')) {
196 return FALSE;
197 }
198 }
199 // Finally a check from \TYPO3\CMS\Core\Authentication\BackendUserAuthentication::backendCheckLogin()
200 if ($this->isUserAllowedToLogin()) {
201 return TRUE;
202 } else {
203 return FALSE;
204 }
205 }
206
207 /**
208 * Evaluates if the Backend User has read access to the input page record.
209 * 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.
210 * Read access means that previewing is allowed etc.
211 * Used in index_ts.php
212 *
213 * @param array $pageRec The page record to evaluate for
214 * @return boolean TRUE if read access
215 */
216 public function extPageReadAccess($pageRec) {
217 return $this->isInWebMount($pageRec['uid']) && $this->doesUserHaveAccess($pageRec, 1);
218 }
219
220 /*****************************************************
221 *
222 * TSFE BE user Access Functions
223 *
224 ****************************************************/
225 /**
226 * Generates a list of Page-uid's from $id. List does not include $id itself
227 * The only pages excluded from the list are deleted pages.
228 *
229 * @param integer $id Start page id
230 * @param integer $depth Depth to traverse down the page tree.
231 * @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'
232 * @param string $perms_clause Perms clause
233 * @return string Returns the list with a comma in the end (if any pages selected!)
234 */
235 public function extGetTreeList($id, $depth, $begin = 0, $perms_clause) {
236 $depth = (int)$depth;
237 $begin = (int)$begin;
238 $id = (int)$id;
239 $theList = '';
240 if ($id && $depth > 0) {
241 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title', 'pages', 'pid=' . $id . ' AND doktype IN (' . $GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'] . ') AND deleted=0 AND ' . $perms_clause);
242 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
243 if ($begin <= 0) {
244 $theList .= $row['uid'] . ',';
245 $this->extPageInTreeInfo[] = array($row['uid'], htmlspecialchars($row['title'], $depth));
246 }
247 if ($depth > 1) {
248 $theList .= $this->extGetTreeList($row['uid'], $depth - 1, $begin - 1, $perms_clause);
249 }
250 }
251 $GLOBALS['TYPO3_DB']->sql_free_result($res);
252 }
253 return $theList;
254 }
255
256 /**
257 * Returns the number of cached pages for a page id.
258 *
259 * @param integer $pageId The page id.
260 * @return integer The number of pages for this page in the table "cache_pages
261 */
262 public function extGetNumberOfCachedPages($pageId) {
263 $pageCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_pages');
264 $pageCacheEntries = $pageCache->getByTag('pageId_' . (int)$pageId);
265 return count($pageCacheEntries);
266 }
267
268 /*****************************************************
269 *
270 * Localization handling
271 *
272 ****************************************************/
273 /**
274 * 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.
275 * 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.xlf" so that the values therein can be used for labels in the Admin Panel
276 *
277 * @param string $key Key for a label in the $GLOBALS['LOCAL_LANG'] array of "sysext/lang/locallang_tsfe.xlf
278 * @return string The value for the $key
279 */
280 public function extGetLL($key) {
281 if (!is_array($GLOBALS['LOCAL_LANG'])) {
282 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_tsfe.xlf');
283 if (!is_array($GLOBALS['LOCAL_LANG'])) {
284 $GLOBALS['LOCAL_LANG'] = array();
285 }
286 }
287 // Label string in the default backend output charset.
288 $labelStr = htmlspecialchars($GLOBALS['LANG']->getLL($key));
289 $labelStr = $GLOBALS['LANG']->csConvObj->utf8_to_entities($labelStr);
290 // Return the result:
291 return $labelStr;
292 }
293
294 }