[BUGFIX] feedit: Double encoding of labels
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / FrontendBackendUserAuthentication.php
1 <?php
2 namespace TYPO3\CMS\Backend;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Lang\LanguageService;
20
21 /**
22 * TYPO3 backend user authentication in the TSFE frontend.
23 * This includes mainly functions related to the Admin Panel
24 */
25 class FrontendBackendUserAuthentication extends \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
26 {
27 /**
28 * Form field with login name.
29 *
30 * @var string
31 */
32 public $formfield_uname = '';
33
34 /**
35 * Form field with password.
36 *
37 * @var string
38 */
39 public $formfield_uident = '';
40
41 /**
42 * Decides if the writelog() function is called at login and logout.
43 *
44 * @var bool
45 */
46 public $writeStdLog = false;
47
48 /**
49 * If the writelog() functions is called if a login-attempt has be tried without success.
50 *
51 * @var bool
52 */
53 public $writeAttemptLog = false;
54
55 /**
56 * Array of page related information (uid, title, depth).
57 *
58 * @var array
59 */
60 public $extPageInTreeInfo = array();
61
62 /**
63 * General flag which is set if the adminpanel is enabled at all.
64 *
65 * @var bool
66 */
67 public $extAdmEnabled = false;
68
69 /**
70 * @var \TYPO3\CMS\Frontend\View\AdminPanelView Instance of admin panel
71 */
72 public $adminPanel = null;
73
74 /**
75 * @var \TYPO3\CMS\Core\FrontendEditing\FrontendEditingController
76 */
77 public $frontendEdit = null;
78
79 /**
80 * @var array
81 */
82 public $extAdminConfig = array();
83
84 /**
85 * Initializes the admin panel.
86 *
87 * @return void
88 */
89 public function initializeAdminPanel()
90 {
91 $this->extAdminConfig = $this->getTSConfigProp('admPanel');
92 if (isset($this->extAdminConfig['enable.'])) {
93 foreach ($this->extAdminConfig['enable.'] as $value) {
94 if ($value) {
95 $this->adminPanel = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\View\AdminPanelView::class);
96 $this->extAdmEnabled = true;
97 break;
98 }
99 }
100 }
101 }
102
103 /**
104 * Initializes frontend editing.
105 *
106 * @return void
107 */
108 public function initializeFrontendEdit()
109 {
110 if (isset($this->extAdminConfig['enable.']) && $this->isFrontendEditingActive()) {
111 foreach ($this->extAdminConfig['enable.'] as $value) {
112 if ($value) {
113 if ($GLOBALS['TSFE'] instanceof \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController) {
114 // Grab the Page TSConfig property that determines which controller to use.
115 $pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
116 $controllerKey = isset($pageTSConfig['TSFE.']['frontendEditingController'])
117 ? $pageTSConfig['TSFE.']['frontendEditingController']
118 : 'default';
119 } else {
120 $controllerKey = 'default';
121 }
122 $controllerClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController'][$controllerKey];
123 if ($controllerClass) {
124 $this->frontendEdit = GeneralUtility::getUserObj($controllerClass);
125 }
126 break;
127 }
128 }
129 }
130 }
131
132 /**
133 * Determines whether frontend editing is currently active.
134 *
135 * @return bool Whether frontend editing is active
136 */
137 public function isFrontendEditingActive()
138 {
139 return $this->extAdmEnabled && (
140 $this->adminPanel->isAdminModuleEnabled('edit') ||
141 $GLOBALS['TSFE']->displayEditIcons == 1 ||
142 $GLOBALS['TSFE']->displayFieldEditIcons == 1
143 );
144 }
145
146 /**
147 * Delegates to the appropriate view and renders the admin panel content.
148 *
149 * @return string.
150 */
151 public function displayAdminPanel()
152 {
153 return $this->adminPanel->display();
154 }
155
156 /**
157 * Determines whether the admin panel is enabled and visible.
158 *
159 * @return bool Whether the admin panel is enabled and visible
160 */
161 public function isAdminPanelVisible()
162 {
163 return $this->extAdmEnabled && !$this->extAdminConfig['hide'] && $GLOBALS['TSFE']->config['config']['admPanel'];
164 }
165
166 /*****************************************************
167 *
168 * TSFE BE user Access Functions
169 *
170 ****************************************************/
171 /**
172 * Implementing the access checks that the TYPO3 CMS bootstrap script does before a user is ever logged in.
173 * Used in the frontend.
174 *
175 * @return bool Returns TRUE if access is OK
176 */
177 public function checkBackendAccessSettingsFromInitPhp()
178 {
179 // Check Hardcoded lock on BE
180 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
181 return false;
182 }
183 // Check IP
184 if (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
185 $remoteAddress = GeneralUtility::getIndpEnv('REMOTE_ADDR');
186 if (!GeneralUtility::cmpIP($remoteAddress, $GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
187 return false;
188 }
189 }
190 // Check SSL (https)
191 if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] && !GeneralUtility::getIndpEnv('TYPO3_SSL')) {
192 return false;
193 }
194 // Finally a check from \TYPO3\CMS\Core\Authentication\BackendUserAuthentication::backendCheckLogin()
195 if ($this->isUserAllowedToLogin()) {
196 return true;
197 } else {
198 return false;
199 }
200 }
201
202 /**
203 * Evaluates if the Backend User has read access to the input page record.
204 * The evaluation is based on both read-permission and whether the page is found in one of the users webmounts.
205 * Only if both conditions are TRUE will the function return TRUE.
206 * Read access means that previewing is allowed etc.
207 * Used in \TYPO3\CMS\Frontend\Http\RequestHandler
208 *
209 * @param array $pageRec The page record to evaluate for
210 * @return bool TRUE if read access
211 */
212 public function extPageReadAccess($pageRec)
213 {
214 return $this->isInWebMount($pageRec['uid']) && $this->doesUserHaveAccess($pageRec, 1);
215 }
216
217 /*****************************************************
218 *
219 * TSFE BE user Access Functions
220 *
221 ****************************************************/
222 /**
223 * Generates a list of Page-uid's from $id. List does not include $id itself
224 * The only pages excluded from the list are deleted pages.
225 *
226 * @param int $id Start page id
227 * @param int $depth Depth to traverse down the page tree.
228 * @param int $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'
229 * @param string $perms_clause Perms clause
230 * @return string Returns the list with a comma in the end (if any pages selected!)
231 */
232 public function extGetTreeList($id, $depth, $begin = 0, $perms_clause)
233 {
234 $depth = (int)$depth;
235 $begin = (int)$begin;
236 $id = (int)$id;
237 $theList = '';
238 if ($id && $depth > 0) {
239 $where = 'pid=' . $id . ' AND doktype IN (' . $GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes']
240 . ') AND deleted=0 AND ' . $perms_clause;
241 $res = $this->db->exec_SELECTquery('uid,title', 'pages', $where);
242 while (($row = $this->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 $this->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 int $pageId The page id.
260 * @return int The number of pages for this page in the table "cache_pages
261 */
262 public function extGetNumberOfCachedPages($pageId)
263 {
264 /** @var FrontendInterface $pageCache */
265 $pageCache = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_pages');
266 $pageCacheEntries = $pageCache->getByTag('pageId_' . (int)$pageId);
267 return count($pageCacheEntries);
268 }
269
270 /*****************************************************
271 *
272 * Localization handling
273 *
274 ****************************************************/
275 /**
276 * Returns the label for key. If a translation for the language set in $this->uc['lang']
277 * is found that is returned, otherwise the default value.
278 * If the global variable $LOCAL_LANG is NOT an array (yet) then this function loads
279 * the global $LOCAL_LANG array with the content of "sysext/lang/locallang_tsfe.xlf"
280 * such that the values therein can be used for labels in the Admin Panel
281 *
282 * @param string $key Key for a label in the $GLOBALS['LOCAL_LANG'] array of "sysext/lang/locallang_tsfe.xlf
283 * @return string The value for the $key
284 */
285 public function extGetLL($key)
286 {
287 if (!is_array($GLOBALS['LOCAL_LANG'])) {
288 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_tsfe.xlf');
289 if (!is_array($GLOBALS['LOCAL_LANG'])) {
290 $GLOBALS['LOCAL_LANG'] = array();
291 }
292 }
293 // Return the label string in the default backend output charset.
294 return htmlspecialchars($this->getLanguageService()->getLL($key));
295 }
296
297 /**
298 * @return LanguageService
299 */
300 protected function getLanguageService()
301 {
302 return $GLOBALS['LANG'];
303 }
304 }