forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs_manage.php
399 lines (387 loc) · 14.9 KB
/
prefs_manage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* User preferences management page
*
* @package PhpMyAdmin
*/
use PhpMyAdmin\Config\ConfigFile;
use PhpMyAdmin\Config\FormDisplay;
use PhpMyAdmin\Core;
use PhpMyAdmin\File;
use PhpMyAdmin\Message;
use PhpMyAdmin\Response;
use PhpMyAdmin\Util;
use PhpMyAdmin\Url;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\ThemeManager;
/**
* Gets some core libraries and displays a top message if required
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/user_preferences.lib.php';
require_once 'libraries/config/config_functions.lib.php';
require_once 'libraries/config/messages.inc.php';
require 'libraries/config/user_preferences.forms.php';
$cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
PMA_userprefsPageInit($cf);
$response = Response::getInstance();
$error = '';
if (isset($_POST['submit_export'])
&& isset($_POST['export_type'])
&& $_POST['export_type'] == 'text_file'
) {
// export to JSON file
$response->disable();
$filename = 'phpMyAdmin-config-' . urlencode(Core::getenv('HTTP_HOST')) . '.json';
Core::downloadHeader($filename, 'application/json');
$settings = PMA_loadUserprefs();
echo json_encode($settings['config_data'], JSON_PRETTY_PRINT);
exit;
} elseif (isset($_POST['submit_export'])
&& isset($_POST['export_type'])
&& $_POST['export_type'] == 'php_file'
) {
// export to JSON file
$response->disable();
$filename = 'phpMyAdmin-config-' . urlencode(Core::getenv('HTTP_HOST')) . '.php';
Core::downloadHeader($filename, 'application/php');
$settings = PMA_loadUserprefs();
echo '/* ' . _('phpMyAdmin configuration snippet') . " */\n\n";
echo '/* ' . _('Paste it to your config.inc.php') . " */\n\n";
foreach ($settings['config_data'] as $key => $val) {
echo '$cfg[\'' . str_replace('/', '\'][\'', $key) . '\'] = ';
echo var_export($val, true) . ";\n";
}
exit;
} else if (isset($_POST['submit_get_json'])) {
$settings = PMA_loadUserprefs();
$response->addJSON('prefs', json_encode($settings['config_data']));
$response->addJSON('mtime', $settings['mtime']);
exit;
} else if (isset($_POST['submit_import'])) {
// load from JSON file
$json = '';
if (isset($_POST['import_type'])
&& $_POST['import_type'] == 'text_file'
&& isset($_FILES['import_file'])
&& $_FILES['import_file']['error'] == UPLOAD_ERR_OK
&& is_uploaded_file($_FILES['import_file']['tmp_name'])
) {
$import_handle = new File($_FILES['import_file']['tmp_name']);
$import_handle->checkUploadedFile();
if ($import_handle->isError()) {
$error = $import_handle->getError();
} else {
// read JSON from uploaded file
$json = $import_handle->getRawContent();
}
} else {
// read from POST value (json)
$json = isset($_POST['json']) ? $_POST['json'] : null;
}
// hide header message
$_SESSION['userprefs_autoload'] = true;
$config = json_decode($json, true);
$return_url = isset($_POST['return_url']) ? $_POST['return_url'] : null;
if (! is_array($config)) {
if (! isset($error)) {
$error = __('Could not import configuration');
}
} else {
// sanitize input values: treat them as though
// they came from HTTP POST request
$form_display = new FormDisplay($cf);
foreach ($forms as $formset_id => $formset) {
foreach ($formset as $form_name => $form) {
$form_display->registerForm($formset_id . ': ' . $form_name, $form);
}
}
$new_config = $cf->getFlatDefaultConfig();
if (!empty($_POST['import_merge'])) {
$new_config = array_merge($new_config, $cf->getConfigArray());
}
$new_config = array_merge($new_config, $config);
$_POST_bak = $_POST;
foreach ($new_config as $k => $v) {
$_POST[str_replace('/', '-', $k)] = $v;
}
$cf->resetConfigData();
$all_ok = $form_display->process(true, false);
$all_ok = $all_ok && !$form_display->hasErrors();
$_POST = $_POST_bak;
if (!$all_ok && isset($_POST['fix_errors'])) {
$form_display->fixErrors();
$all_ok = true;
}
if (!$all_ok) {
// mimic original form and post json in a hidden field
include 'libraries/user_preferences.inc.php';
$msg = Message::error(
__('Configuration contains incorrect data for some fields.')
);
$msg->display();
echo '<div class="config-form">';
echo $form_display->displayErrors();
echo '</div>';
echo '<form action="prefs_manage.php" method="post">';
echo Url::getHiddenInputs() , "\n";
echo '<input type="hidden" name="json" value="'
, htmlspecialchars($json) , '" />';
echo '<input type="hidden" name="fix_errors" value="1" />';
if (! empty($_POST['import_merge'])) {
echo '<input type="hidden" name="import_merge" value="1" />';
}
if ($return_url) {
echo '<input type="hidden" name="return_url" value="'
, htmlspecialchars($return_url) , '" />';
}
echo '<p>';
echo __('Do you want to import remaining settings?');
echo '</p>';
echo '<input type="submit" name="submit_import" value="'
, __('Yes') , '" />';
echo '<input type="submit" name="submit_ignore" value="'
, __('No') , '" />';
echo '</form>';
exit;
}
// check for ThemeDefault and fontsize
$params = array();
$tmanager = ThemeManager::getInstance();
if (isset($config['ThemeDefault'])
&& $tmanager->theme->getId() != $config['ThemeDefault']
&& $tmanager->checkTheme($config['ThemeDefault'])
) {
$tmanager->setActiveTheme($config['ThemeDefault']);
$tmanager->setThemeCookie();
}
if (isset($config['fontsize'])
&& $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize')
) {
$params['set_fontsize'] = $config['fontsize'];
}
if (isset($config['lang'])
&& $config['lang'] != $GLOBALS['lang']
) {
$params['lang'] = $config['lang'];
}
if (isset($config['collation_connection'])
&& $config['collation_connection'] != $GLOBALS['collation_connection']
) {
$params['collation_connection'] = $config['collation_connection'];
}
// save settings
$result = PMA_saveUserprefs($cf->getConfigArray());
if ($result === true) {
if ($return_url) {
$query = PhpMyAdmin\Util::splitURLQuery($return_url);
$return_url = parse_url($return_url, PHP_URL_PATH);
foreach ($query as $q) {
$pos = mb_strpos($q, '=');
$k = mb_substr($q, 0, $pos);
if ($k == 'token') {
continue;
}
$params[$k] = mb_substr($q, $pos + 1);
}
} else {
$return_url = 'prefs_manage.php';
}
// reload config
$GLOBALS['PMA_Config']->loadUserPreferences();
PMA_userprefsRedirect($return_url, $params);
exit;
} else {
$error = $result;
}
}
} else if (isset($_POST['submit_clear'])) {
$result = PMA_saveUserprefs(array());
if ($result === true) {
$params = array();
if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
$GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
}
$GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
$GLOBALS['PMA_Config']->removeCookie('pma_lang');
PMA_userprefsRedirect('prefs_manage.php', $params);
exit;
} else {
$error = $result;
}
exit;
}
$response = Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('config.js');
require 'libraries/user_preferences.inc.php';
if ($error) {
if (!$error instanceof Message) {
$error = Message::error($error);
}
$error->display();
}
?>
<script type="text/javascript">
<?php
Sanitize::printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
?>
</script>
<div id="maincontainer">
<div id="main_pane_left">
<div class="group">
<?php
echo '<h2>' , __('Import') , '</h2>'
, '<form class="group-cnt prefs-form disableAjax" name="prefs_import"'
, ' action="prefs_manage.php" method="post" enctype="multipart/form-data">'
, Util::generateHiddenMaxFileSize($GLOBALS['max_upload_size'])
, Url::getHiddenInputs()
, '<input type="hidden" name="json" value="" />'
, '<input type="radio" id="import_text_file" name="import_type"'
, ' value="text_file" checked="checked" />'
, '<label for="import_text_file">' . __('Import from file') . '</label>'
, '<div id="opts_import_text_file" class="prefsmanage_opts">'
, '<label for="input_import_file">' , __('Browse your computer:') , '</label>'
, '<input type="file" name="import_file" id="input_import_file" />'
, '</div>'
, '<input type="radio" id="import_local_storage" name="import_type"'
, ' value="local_storage" disabled="disabled" />'
, '<label for="import_local_storage">'
, __('Import from browser\'s storage') , '</label>'
, '<div id="opts_import_local_storage" class="prefsmanage_opts disabled">'
, '<div class="localStorage-supported">'
, __('Settings will be imported from your browser\'s local storage.')
, '<br />'
, '<div class="localStorage-exists">'
, __('Saved on: @DATE@')
, '</div>'
, '<div class="localStorage-empty">';
Message::notice(__('You have no saved settings!'))->display();
echo '</div>'
, '</div>'
, '<div class="localStorage-unsupported">';
Message::notice(
__('This feature is not supported by your web browser')
)->display();
echo '</div>'
, '</div>'
, '<input type="checkbox" id="import_merge" name="import_merge" />'
, '<label for="import_merge">'
, __('Merge with current configuration') . '</label>'
, '<br /><br />'
, '<input type="submit" name="submit_import" value="'
, __('Go') . '" />'
, '</form>'
, '</div>';
if (@file_exists('setup/index.php') && ! @file_exists(CONFIG_FILE)) {
// show only if setup script is available, allows to disable this message
// by simply removing setup directory
// Also do not show in config exists (and setup would refuse to work)
?>
<div class="group">
<h2><?php echo __('More settings') ?></h2>
<div class="group-cnt">
<?php
echo sprintf(
__(
'You can set more settings by modifying config.inc.php, eg. '
. 'by using %sSetup script%s.'
), '<a href="setup/index.php" target="_blank">', '</a>'
) , PhpMyAdmin\Util::showDocu('setup', 'setup-script');
?>
</div>
</div>
<?php
}
?>
</div>
<div id="main_pane_right">
<div class="group">
<h2><?php echo __('Export'); ?></h2>
<div class="click-hide-message group-cnt hide">
<?php
Message::rawSuccess(
__('Configuration has been saved.')
)->display();
?>
</div>
<form class="group-cnt prefs-form disableAjax" name="prefs_export"
action="prefs_manage.php" method="post">
<?php echo Url::getHiddenInputs(); ?>
<div style="padding-bottom:0.5em">
<input type="radio" id="export_text_file" name="export_type"
value="text_file" checked="checked" />
<label for="export_text_file">
<?php echo __('Save as file'); ?>
</label><br />
<input type="radio" id="export_php_file" name="export_type"
value="php_file" />
<label for="export_php_file">
<?php echo __('Save as PHP file'); ?>
</label><br />
<input type="radio" id="export_local_storage" name="export_type"
value="local_storage" disabled="disabled" />
<label for="export_local_storage">
<?php echo __('Save to browser\'s storage'); ?></label>
</div>
<div id="opts_export_local_storage"
class="prefsmanage_opts disabled">
<span class="localStorage-supported">
<?php
echo __(
'Settings will be saved in your browser\'s local '
. 'storage.'
);
?>
<div class="localStorage-exists">
<b>
<?php
echo __(
'Existing settings will be overwritten!'
);
?>
</b>
</div>
</span>
<div class="localStorage-unsupported">
<?php
Message::notice(
__('This feature is not supported by your web browser')
)->display();
?>
</div>
</div>
<br />
<?php
echo '<input type="submit" name="submit_export" value="' , __(
'Go'
) , '" />';
?>
</form>
</div>
<div class="group">
<h2><?php echo __('Reset'); ?></h2>
<form class="group-cnt prefs-form disableAjax" name="prefs_reset"
action="prefs_manage.php" method="post">
<?php
echo Url::getHiddenInputs() , __(
'You can reset all your settings and restore them to default '
. 'values.'
);
?>
<br /><br />
<input type="submit" name="submit_clear"
value="<?php echo __('Reset'); ?>"/>
</form>
</div>
</div>
<br class="clearfloat" />
</div>
<?php
if ($response->isAjax()) {
$response->addJSON('_disableNaviSettings', true);
} else {
define('PMA_DISABLE_NAVI_SETTINGS', true);
}