1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Used to render the header of PMA's pages |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
declare(strict_types=1); |
7
|
|
|
|
8
|
|
|
namespace PhpMyAdmin; |
9
|
|
|
|
10
|
|
|
use PhpMyAdmin\ConfigStorage\Relation; |
11
|
|
|
use PhpMyAdmin\Container\ContainerBuilder; |
12
|
|
|
use PhpMyAdmin\Html\Generator; |
13
|
|
|
use PhpMyAdmin\Navigation\Navigation; |
14
|
|
|
use PhpMyAdmin\Theme\ThemeManager; |
15
|
|
|
|
16
|
|
|
use function array_merge; |
17
|
|
|
use function defined; |
18
|
|
|
use function gmdate; |
19
|
|
|
use function header; |
|
|
|
|
20
|
|
|
use function htmlspecialchars; |
21
|
|
|
use function ini_get; |
22
|
|
|
use function json_encode; |
23
|
|
|
use function sprintf; |
24
|
|
|
use function strtolower; |
25
|
|
|
use function urlencode; |
26
|
|
|
|
27
|
|
|
use const JSON_HEX_TAG; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class used to output the HTTP and HTML headers |
31
|
|
|
*/ |
32
|
|
|
class Header |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Scripts instance |
36
|
|
|
*/ |
37
|
|
|
private Scripts $scripts; |
38
|
|
|
/** |
39
|
|
|
* Menu instance |
40
|
|
|
*/ |
41
|
|
|
private Menu $menu; |
42
|
|
|
/** |
43
|
|
|
* The page title |
44
|
|
|
*/ |
45
|
|
|
private string $title = ''; |
46
|
|
|
/** |
47
|
|
|
* The value for the id attribute for the body tag |
48
|
|
|
*/ |
49
|
|
|
private string $bodyId = ''; |
50
|
|
|
/** |
51
|
|
|
* Whether to show the top menu |
52
|
|
|
*/ |
53
|
|
|
private bool $menuEnabled; |
54
|
|
|
/** |
55
|
|
|
* Whether to show the warnings |
56
|
|
|
*/ |
57
|
|
|
private bool $warningsEnabled = true; |
58
|
|
|
/** |
59
|
|
|
* Whether we are servicing an ajax request. |
60
|
|
|
*/ |
61
|
|
|
private bool $isAjax = false; |
62
|
|
|
/** |
63
|
|
|
* Whether to display anything |
64
|
|
|
*/ |
65
|
|
|
private bool $isEnabled = true; |
66
|
|
|
/** |
67
|
|
|
* Whether the HTTP headers (and possibly some HTML) |
68
|
|
|
* have already been sent to the browser |
69
|
|
|
*/ |
70
|
|
|
private bool $headerIsSent = false; |
71
|
|
|
|
72
|
|
|
private UserPreferences $userPreferences; |
73
|
|
|
|
74
|
|
|
private bool $isTransformationWrapper = false; |
75
|
|
|
|
76
|
48 |
|
public function __construct( |
77
|
|
|
private readonly Template $template, |
78
|
|
|
private readonly Console $console, |
79
|
|
|
private readonly Config $config, |
80
|
|
|
) { |
81
|
48 |
|
$dbi = DatabaseInterface::getInstance(); |
|
|
|
|
82
|
48 |
|
$this->menuEnabled = $dbi->isConnected(); |
83
|
48 |
|
$relation = new Relation($dbi); |
84
|
48 |
|
$this->menu = new Menu($dbi, $this->template, $this->config, $relation, Current::$database, Current::$table); |
85
|
48 |
|
$this->scripts = new Scripts($this->template); |
86
|
48 |
|
$this->addDefaultScripts(); |
87
|
|
|
|
88
|
48 |
|
$this->userPreferences = new UserPreferences($dbi, $relation, $this->template); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Loads common scripts |
93
|
|
|
*/ |
94
|
48 |
|
private function addDefaultScripts(): void |
95
|
|
|
{ |
96
|
48 |
|
$this->scripts->addFile('runtime.js'); |
97
|
48 |
|
$this->scripts->addFile('vendor/jquery/jquery.min.js'); |
98
|
48 |
|
$this->scripts->addFile('vendor/jquery/jquery-migrate.min.js'); |
99
|
48 |
|
$this->scripts->addFile('vendor/sprintf.js'); |
100
|
48 |
|
$this->scripts->addFile('vendor/jquery/jquery-ui.min.js'); |
101
|
48 |
|
$this->scripts->addFile('name-conflict-fixes.js'); |
102
|
48 |
|
$this->scripts->addFile('vendor/bootstrap/bootstrap.bundle.min.js'); |
103
|
48 |
|
$this->scripts->addFile('vendor/js.cookie.min.js'); |
104
|
48 |
|
$this->scripts->addFile('vendor/jquery/jquery.validate.min.js'); |
105
|
48 |
|
$this->scripts->addFile('vendor/jquery/jquery-ui-timepicker-addon.js'); |
106
|
48 |
|
$this->scripts->addFile('index.php', ['route' => '/messages', 'l' => $GLOBALS['lang']]); |
107
|
48 |
|
$this->scripts->addFile('shared.js'); |
108
|
48 |
|
$this->scripts->addFile('menu_resizer.js'); |
109
|
48 |
|
$this->scripts->addFile('main.js'); |
110
|
|
|
|
111
|
48 |
|
$this->scripts->addCode($this->getJsParamsCode()); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Returns, as an array, a list of parameters |
116
|
|
|
* used on the client side |
117
|
|
|
* |
118
|
|
|
* @return mixed[] |
119
|
|
|
*/ |
120
|
48 |
|
public function getJsParams(): array |
121
|
|
|
{ |
122
|
48 |
|
$pftext = $_SESSION['tmpval']['pftext'] ?? ''; |
123
|
|
|
|
124
|
48 |
|
$params = [ |
125
|
|
|
// Do not add any separator, JS code will decide |
126
|
48 |
|
'common_query' => Url::getCommonRaw([], ''), |
127
|
48 |
|
'opendb_url' => Util::getScriptNameForOption($this->config->settings['DefaultTabDatabase'], 'database'), |
128
|
48 |
|
'lang' => $GLOBALS['lang'], |
129
|
48 |
|
'server' => Current::$server, |
130
|
48 |
|
'table' => Current::$table, |
131
|
48 |
|
'db' => Current::$database, |
132
|
48 |
|
'token' => $_SESSION[' PMA_token '], |
133
|
48 |
|
'text_dir' => LanguageManager::$textDir, |
134
|
48 |
|
'LimitChars' => $this->config->settings['LimitChars'], |
135
|
48 |
|
'pftext' => $pftext, |
136
|
48 |
|
'confirm' => $this->config->settings['Confirm'], |
137
|
48 |
|
'LoginCookieValidity' => $this->config->settings['LoginCookieValidity'], |
138
|
48 |
|
'session_gc_maxlifetime' => (int) ini_get('session.gc_maxlifetime'), |
139
|
48 |
|
'logged_in' => DatabaseInterface::getInstance()->isConnected(), |
|
|
|
|
140
|
48 |
|
'is_https' => $this->config->isHttps(), |
141
|
48 |
|
'rootPath' => $this->config->getRootPath(), |
142
|
48 |
|
'arg_separator' => Url::getArgSeparator(), |
143
|
48 |
|
'version' => Version::VERSION, |
144
|
48 |
|
]; |
145
|
48 |
|
if ($this->config->hasSelectedServer()) { |
146
|
|
|
$params['auth_type'] = $this->config->selectedServer['auth_type']; |
147
|
|
|
if (isset($this->config->selectedServer['user'])) { |
148
|
|
|
$params['user'] = $this->config->selectedServer['user']; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
48 |
|
return $params; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Returns, as a string, a list of parameters |
157
|
|
|
* used on the client side |
158
|
|
|
*/ |
159
|
48 |
|
public function getJsParamsCode(): string |
160
|
|
|
{ |
161
|
48 |
|
$params = $this->getJsParams(); |
162
|
|
|
|
163
|
48 |
|
return 'window.Navigation.update(window.CommonParams.setAll(' . json_encode($params, JSON_HEX_TAG) . '));'; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Disables the rendering of the header |
168
|
|
|
*/ |
169
|
4 |
|
public function disable(): void |
170
|
|
|
{ |
171
|
4 |
|
$this->isEnabled = false; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Set the ajax flag to indicate whether |
176
|
|
|
* we are servicing an ajax request |
177
|
|
|
* |
178
|
|
|
* @param bool $isAjax Whether we are servicing an ajax request |
179
|
|
|
*/ |
180
|
6 |
|
public function setAjax(bool $isAjax): void |
181
|
|
|
{ |
182
|
6 |
|
$this->isAjax = $isAjax; |
183
|
6 |
|
$this->console->setAjax($isAjax); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Returns the Scripts object |
188
|
|
|
* |
189
|
|
|
* @return Scripts object |
190
|
|
|
*/ |
191
|
4 |
|
public function getScripts(): Scripts |
192
|
|
|
{ |
193
|
4 |
|
return $this->scripts; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Returns the Menu object |
198
|
|
|
* |
199
|
|
|
* @return Menu object |
200
|
|
|
*/ |
201
|
|
|
public function getMenu(): Menu |
202
|
|
|
{ |
203
|
|
|
return $this->menu; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Setter for the ID attribute in the BODY tag |
208
|
|
|
* |
209
|
|
|
* @param string $id Value for the ID attribute |
210
|
|
|
*/ |
211
|
4 |
|
public function setBodyId(string $id): void |
212
|
|
|
{ |
213
|
4 |
|
$this->bodyId = htmlspecialchars($id); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Setter for the title of the page |
218
|
|
|
* |
219
|
|
|
* @param string $title New title |
220
|
|
|
*/ |
221
|
|
|
public function setTitle(string $title): void |
222
|
|
|
{ |
223
|
|
|
$this->title = htmlspecialchars($title); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Disables the display of the top menu |
228
|
|
|
*/ |
229
|
|
|
public function disableMenuAndConsole(): void |
230
|
|
|
{ |
231
|
|
|
$this->menuEnabled = false; |
232
|
|
|
$this->console->disable(); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Disables the display of the top menu |
237
|
|
|
*/ |
238
|
4 |
|
public function disableWarnings(): void |
239
|
|
|
{ |
240
|
4 |
|
$this->warningsEnabled = false; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Generates the header |
245
|
|
|
* |
246
|
|
|
* @return string The header |
247
|
|
|
*/ |
248
|
12 |
|
public function getDisplay(): string |
249
|
|
|
{ |
250
|
12 |
|
if ($this->headerIsSent || ! $this->isEnabled || $this->isAjax) { |
251
|
4 |
|
return ''; |
252
|
|
|
} |
253
|
|
|
|
254
|
8 |
|
$this->sendHttpHeaders(); |
255
|
|
|
|
256
|
8 |
|
$baseDir = defined('PMA_PATH_TO_BASEDIR') ? PMA_PATH_TO_BASEDIR : ''; |
257
|
|
|
|
258
|
|
|
/** @var ThemeManager $themeManager */ |
259
|
8 |
|
$themeManager = ContainerBuilder::getContainer()->get(ThemeManager::class); |
260
|
8 |
|
$theme = $themeManager->theme; |
261
|
|
|
|
262
|
8 |
|
$version = self::getVersionParameter(); |
263
|
|
|
|
264
|
|
|
// The user preferences have been merged at this point |
265
|
|
|
// so we can conditionally add CodeMirror, other scripts and settings |
266
|
8 |
|
if ($this->config->settings['CodemirrorEnable']) { |
267
|
8 |
|
$this->scripts->addFile('vendor/codemirror/lib/codemirror.js'); |
268
|
8 |
|
$this->scripts->addFile('vendor/codemirror/mode/sql/sql.js'); |
269
|
8 |
|
$this->scripts->addFile('vendor/codemirror/addon/runmode/runmode.js'); |
270
|
8 |
|
$this->scripts->addFile('vendor/codemirror/addon/hint/show-hint.js'); |
271
|
8 |
|
$this->scripts->addFile('vendor/codemirror/addon/hint/sql-hint.js'); |
272
|
8 |
|
if ($this->config->settings['LintEnable']) { |
273
|
8 |
|
$this->scripts->addFile('vendor/codemirror/addon/lint/lint.js'); |
274
|
8 |
|
$this->scripts->addFile('codemirror/addon/lint/sql-lint.js'); |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
|
278
|
8 |
|
if ($this->config->settings['SendErrorReports'] !== 'never') { |
279
|
8 |
|
$this->scripts->addFile('vendor/tracekit.js'); |
280
|
8 |
|
$this->scripts->addFile('error_report.js'); |
281
|
|
|
} |
282
|
|
|
|
283
|
8 |
|
if ($this->config->settings['enable_drag_drop_import'] === true) { |
284
|
8 |
|
$this->scripts->addFile('drag_drop_import.js'); |
285
|
|
|
} |
286
|
|
|
|
287
|
8 |
|
if (! $this->config->get('DisableShortcutKeys')) { |
288
|
8 |
|
$this->scripts->addFile('shortcuts_handler.js'); |
289
|
|
|
} |
290
|
|
|
|
291
|
8 |
|
$this->scripts->addCode($this->getVariablesForJavaScript()); |
292
|
|
|
|
293
|
8 |
|
$this->scripts->addCode( |
294
|
8 |
|
'ConsoleEnterExecutes=' . ($this->config->settings['ConsoleEnterExecutes'] ? 'true' : 'false'), |
295
|
8 |
|
); |
296
|
8 |
|
$this->scripts->addFiles($this->console->getScripts()); |
297
|
|
|
|
298
|
8 |
|
$dbi = DatabaseInterface::getInstance(); |
|
|
|
|
299
|
8 |
|
if ($this->menuEnabled && Current::$server > 0) { |
300
|
4 |
|
$navigation = (new Navigation($this->template, new Relation($dbi), $dbi, $this->config))->getDisplay(); |
301
|
|
|
} |
302
|
|
|
|
303
|
8 |
|
$customHeader = Config::renderHeader(); |
304
|
|
|
|
305
|
|
|
// offer to load user preferences from localStorage |
306
|
|
|
if ( |
307
|
8 |
|
$this->config->get('user_preferences') === 'session' |
308
|
8 |
|
&& ! isset($_SESSION['userprefs_autoload']) |
309
|
|
|
) { |
310
|
|
|
$loadUserPreferences = $this->userPreferences->autoloadGetHeader(); |
311
|
|
|
} |
312
|
|
|
|
313
|
8 |
|
if ($this->menuEnabled && Current::$server > 0) { |
314
|
4 |
|
$menu = $this->menu->getDisplay(); |
315
|
|
|
} |
316
|
|
|
|
317
|
8 |
|
$console = $this->console->getDisplay(); |
318
|
8 |
|
$messages = $this->getMessage(); |
319
|
8 |
|
$isLoggedIn = $dbi->isConnected(); |
320
|
|
|
|
321
|
8 |
|
$this->scripts->addFile('datetimepicker.js'); |
322
|
8 |
|
$this->scripts->addFile('validator-messages.js'); |
323
|
|
|
|
324
|
8 |
|
return $this->template->render('header', [ |
325
|
8 |
|
'lang' => $GLOBALS['lang'], |
326
|
8 |
|
'allow_third_party_framing' => $this->config->settings['AllowThirdPartyFraming'], |
327
|
8 |
|
'base_dir' => $baseDir, |
328
|
8 |
|
'theme_path' => $theme->getPath(), |
329
|
8 |
|
'version' => $version, |
330
|
8 |
|
'text_dir' => LanguageManager::$textDir, |
331
|
8 |
|
'server' => Current::$server, |
332
|
8 |
|
'title' => $this->getPageTitle(), |
333
|
8 |
|
'scripts' => $this->scripts->getDisplay(), |
334
|
8 |
|
'body_id' => $this->bodyId, |
335
|
8 |
|
'navigation' => $navigation ?? '', |
336
|
8 |
|
'custom_header' => $customHeader, |
337
|
8 |
|
'load_user_preferences' => $loadUserPreferences ?? '', |
338
|
8 |
|
'show_hint' => $this->config->settings['ShowHint'], |
339
|
8 |
|
'is_warnings_enabled' => $this->warningsEnabled, |
340
|
8 |
|
'is_menu_enabled' => $this->menuEnabled, |
341
|
8 |
|
'is_logged_in' => $isLoggedIn, |
342
|
8 |
|
'menu' => $menu ?? '', |
343
|
8 |
|
'console' => $console, |
344
|
8 |
|
'messages' => $messages, |
345
|
8 |
|
'theme_color_mode' => $theme->getColorMode(), |
346
|
8 |
|
'theme_color_modes' => $theme->getColorModes(), |
347
|
8 |
|
'theme_id' => $theme->getId(), |
348
|
8 |
|
'current_user' => $dbi->getCurrentUserAndHost(), |
349
|
8 |
|
'is_mariadb' => $dbi->isMariaDB(), |
350
|
8 |
|
]); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* Returns the message to be displayed at the top of |
355
|
|
|
* the page, including the executed SQL query, if any. |
356
|
|
|
*/ |
357
|
12 |
|
public function getMessage(): string |
358
|
|
|
{ |
359
|
12 |
|
$retval = ''; |
360
|
12 |
|
$message = ''; |
361
|
12 |
|
if (! empty($GLOBALS['message'])) { |
362
|
12 |
|
$message = $GLOBALS['message']; |
363
|
12 |
|
unset($GLOBALS['message']); |
364
|
|
|
} elseif (! empty($_REQUEST['message'])) { |
365
|
|
|
$message = $_REQUEST['message']; |
366
|
|
|
} |
367
|
|
|
|
368
|
12 |
|
if ($message !== '') { |
369
|
12 |
|
if (isset($GLOBALS['buffer_message'])) { |
370
|
|
|
$bufferMessage = $GLOBALS['buffer_message']; |
371
|
|
|
} |
372
|
|
|
|
373
|
12 |
|
$retval .= Generator::getMessage($message); |
374
|
12 |
|
if (isset($bufferMessage)) { |
375
|
|
|
$GLOBALS['buffer_message'] = $bufferMessage; |
376
|
|
|
} |
377
|
|
|
} |
378
|
|
|
|
379
|
12 |
|
return $retval; |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* Sends out the HTTP headers |
384
|
|
|
*/ |
385
|
8 |
|
public function sendHttpHeaders(): void |
386
|
|
|
{ |
387
|
8 |
|
if (defined('TESTSUITE')) { |
388
|
8 |
|
return; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* Sends http headers |
393
|
|
|
*/ |
394
|
|
|
$GLOBALS['now'] = gmdate('D, d M Y H:i:s') . ' GMT'; |
395
|
|
|
|
396
|
|
|
$headers = $this->getHttpHeaders(); |
397
|
|
|
|
398
|
|
|
foreach ($headers as $name => $value) { |
399
|
|
|
header(sprintf('%s: %s', $name, $value)); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
$this->headerIsSent = true; |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
/** @return array<string, string> */ |
406
|
12 |
|
public function getHttpHeaders(): array |
407
|
|
|
{ |
408
|
12 |
|
$headers = []; |
409
|
|
|
|
410
|
|
|
/* Prevent against ClickJacking by disabling framing */ |
411
|
12 |
|
if (strtolower((string) $this->config->settings['AllowThirdPartyFraming']) === 'sameorigin') { |
412
|
4 |
|
$headers['X-Frame-Options'] = 'SAMEORIGIN'; |
413
|
8 |
|
} elseif ($this->config->settings['AllowThirdPartyFraming'] !== true) { |
414
|
4 |
|
$headers['X-Frame-Options'] = 'DENY'; |
415
|
|
|
} |
416
|
|
|
|
417
|
12 |
|
$headers['Referrer-Policy'] = 'same-origin'; |
418
|
|
|
|
419
|
12 |
|
$headers = array_merge($headers, $this->getCspHeaders()); |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* Re-enable possible disabled XSS filters. |
423
|
|
|
* |
424
|
|
|
* @see https://developer.mozilla.org/docs/Web/HTTP/Headers/X-XSS-Protection |
425
|
|
|
*/ |
426
|
12 |
|
$headers['X-XSS-Protection'] = '1; mode=block'; |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* "nosniff", prevents Internet Explorer and Google Chrome from MIME-sniffing |
430
|
|
|
* a response away from the declared content-type. |
431
|
|
|
* |
432
|
|
|
* @see https://developer.mozilla.org/docs/Web/HTTP/Headers/X-Content-Type-Options |
433
|
|
|
*/ |
434
|
12 |
|
$headers['X-Content-Type-Options'] = 'nosniff'; |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Adobe cross-domain-policies. |
438
|
|
|
* |
439
|
|
|
* @see https://www.sentrium.co.uk/labs/application-security-101-http-headers |
440
|
|
|
*/ |
441
|
12 |
|
$headers['X-Permitted-Cross-Domain-Policies'] = 'none'; |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* Robots meta tag. |
445
|
|
|
* |
446
|
|
|
* @see https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag |
447
|
|
|
*/ |
448
|
12 |
|
$headers['X-Robots-Tag'] = 'noindex, nofollow'; |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* The HTTP Permissions-Policy header provides a mechanism to allow and deny |
452
|
|
|
* the use of browser features in a document |
453
|
|
|
* or within any <iframe> elements in the document. |
454
|
|
|
* |
455
|
|
|
* @see https://developer.mozilla.org/docs/Web/HTTP/Headers/Permissions-Policy |
456
|
|
|
*/ |
457
|
12 |
|
$headers['Permissions-Policy'] = 'fullscreen=(self), oversized-images=(self), interest-cohort=()'; |
458
|
|
|
|
459
|
12 |
|
$headers = array_merge($headers, Core::getNoCacheHeaders()); |
460
|
|
|
|
461
|
|
|
/** |
462
|
|
|
* A different Content-Type is set in {@see \PhpMyAdmin\Controllers\Transformation\WrapperController}. |
463
|
|
|
*/ |
464
|
12 |
|
if (! $this->isTransformationWrapper) { |
465
|
|
|
// Define the charset to be used |
466
|
12 |
|
$headers['Content-Type'] = 'text/html; charset=utf-8'; |
467
|
|
|
} |
468
|
|
|
|
469
|
12 |
|
return $headers; |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* If the page is missing the title, this function |
474
|
|
|
* will set it to something reasonable |
475
|
|
|
*/ |
476
|
8 |
|
public function getPageTitle(): string |
477
|
|
|
{ |
478
|
8 |
|
if ($this->title === '') { |
479
|
8 |
|
if (Current::$server > 0) { |
480
|
4 |
|
if (Current::$table !== '') { |
481
|
|
|
$tempTitle = $this->config->settings['TitleTable']; |
482
|
4 |
|
} elseif (Current::$database !== '') { |
483
|
4 |
|
$tempTitle = $this->config->settings['TitleDatabase']; |
484
|
|
|
} elseif ($this->config->selectedServer['host'] !== '') { |
485
|
|
|
$tempTitle = $this->config->settings['TitleServer']; |
486
|
|
|
} else { |
487
|
|
|
$tempTitle = $this->config->settings['TitleDefault']; |
488
|
|
|
} |
489
|
|
|
|
490
|
4 |
|
$this->title = htmlspecialchars( |
491
|
4 |
|
Util::expandUserString($tempTitle), |
492
|
4 |
|
); |
493
|
|
|
} else { |
494
|
4 |
|
$this->title = 'phpMyAdmin'; |
495
|
|
|
} |
496
|
|
|
} |
497
|
|
|
|
498
|
8 |
|
return $this->title; |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
/** |
502
|
|
|
* Get all the CSP allow policy headers |
503
|
|
|
* |
504
|
|
|
* @return array<string, string> |
505
|
|
|
*/ |
506
|
12 |
|
private function getCspHeaders(): array |
507
|
|
|
{ |
508
|
12 |
|
$mapTileUrl = ' tile.openstreetmap.org'; |
509
|
12 |
|
$captchaUrl = ''; |
510
|
12 |
|
$cspAllow = $this->config->settings['CSPAllow']; |
511
|
|
|
|
512
|
|
|
if ( |
513
|
12 |
|
! empty($this->config->settings['CaptchaLoginPrivateKey']) |
514
|
12 |
|
&& ! empty($this->config->settings['CaptchaLoginPublicKey']) |
515
|
12 |
|
&& ! empty($this->config->settings['CaptchaApi']) |
516
|
12 |
|
&& ! empty($this->config->settings['CaptchaRequestParam']) |
517
|
12 |
|
&& ! empty($this->config->settings['CaptchaResponseParam']) |
518
|
|
|
) { |
519
|
8 |
|
$captchaUrl = ' ' . $this->config->settings['CaptchaCsp'] . ' '; |
520
|
|
|
} |
521
|
|
|
|
522
|
12 |
|
$headers = []; |
523
|
|
|
|
524
|
12 |
|
$headers['Content-Security-Policy'] = sprintf( |
525
|
12 |
|
'default-src \'self\' %s%s;script-src \'self\' \'unsafe-inline\' \'unsafe-eval\' %s%s;' |
526
|
12 |
|
. 'style-src \'self\' \'unsafe-inline\' %s%s;img-src \'self\' data: %s%s%s;object-src \'none\';', |
527
|
12 |
|
$captchaUrl, |
528
|
12 |
|
$cspAllow, |
529
|
12 |
|
$captchaUrl, |
530
|
12 |
|
$cspAllow, |
531
|
12 |
|
$captchaUrl, |
532
|
12 |
|
$cspAllow, |
533
|
12 |
|
$cspAllow, |
534
|
12 |
|
$mapTileUrl, |
535
|
12 |
|
$captchaUrl, |
536
|
12 |
|
); |
537
|
|
|
|
538
|
12 |
|
$headers['X-Content-Security-Policy'] = sprintf( |
539
|
12 |
|
'default-src \'self\' %s%s;options inline-script eval-script;' |
540
|
12 |
|
. 'referrer no-referrer;img-src \'self\' data: %s%s%s;object-src \'none\';', |
541
|
12 |
|
$captchaUrl, |
542
|
12 |
|
$cspAllow, |
543
|
12 |
|
$cspAllow, |
544
|
12 |
|
$mapTileUrl, |
545
|
12 |
|
$captchaUrl, |
546
|
12 |
|
); |
547
|
|
|
|
548
|
12 |
|
$headers['X-WebKit-CSP'] = sprintf( |
549
|
12 |
|
'default-src \'self\' %s%s;script-src \'self\' %s%s \'unsafe-inline\' \'unsafe-eval\';' |
550
|
12 |
|
. 'referrer no-referrer;style-src \'self\' \'unsafe-inline\' %s;' |
551
|
12 |
|
. 'img-src \'self\' data: %s%s%s;object-src \'none\';', |
552
|
12 |
|
$captchaUrl, |
553
|
12 |
|
$cspAllow, |
554
|
12 |
|
$captchaUrl, |
555
|
12 |
|
$cspAllow, |
556
|
12 |
|
$captchaUrl, |
557
|
12 |
|
$cspAllow, |
558
|
12 |
|
$mapTileUrl, |
559
|
12 |
|
$captchaUrl, |
560
|
12 |
|
); |
561
|
|
|
|
562
|
12 |
|
return $headers; |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
/** |
566
|
|
|
* Returns the phpMyAdmin version to be appended to the url to avoid caching |
567
|
|
|
* between versions |
568
|
|
|
* |
569
|
|
|
* @return string urlencoded pma version as a parameter |
570
|
|
|
*/ |
571
|
8 |
|
public static function getVersionParameter(): string |
572
|
|
|
{ |
573
|
8 |
|
return 'v=' . urlencode(Version::VERSION); |
574
|
|
|
} |
575
|
|
|
|
576
|
8 |
|
private function getVariablesForJavaScript(): string |
577
|
|
|
{ |
578
|
8 |
|
$maxInputVars = ini_get('max_input_vars'); |
579
|
8 |
|
$maxInputVarsValue = $maxInputVars === false || $maxInputVars === '' ? 'false' : (int) $maxInputVars; |
580
|
|
|
|
581
|
8 |
|
return $this->template->render('javascript/variables', [ |
582
|
8 |
|
'first_day_of_calendar' => $this->config->settings['FirstDayOfCalendar'] ?? 0, |
583
|
8 |
|
'max_input_vars' => $maxInputVarsValue, |
584
|
8 |
|
]); |
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
public function setIsTransformationWrapper(bool $isTransformationWrapper): void |
588
|
|
|
{ |
589
|
|
|
$this->isTransformationWrapper = $isTransformationWrapper; |
590
|
|
|
} |
591
|
|
|
} |
592
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: