3 * Front controller for config view / download and clear
5 * @package phpMyAdmin-setup
6 * @author Piotr Przybylski <piotrprz@gmail.com>
7 * @license http://www.gnu.org/licenses/gpl.html GNU GPL 2.0
14 require './lib/common.inc.php';
15 require_once './setup/lib/Form.class.php';
16 require_once './setup/lib/FormDisplay.class.php';
19 * Returns config file contents depending on GET type value:
20 * o session - uses ConfigFile::getConfigFile()
21 * o post - uses POST textconfig value
25 function get_config() {
26 $type = PMA_ifSetOr($_GET['type'], 'session');
28 if ($type == 'session') {
29 $config = ConfigFile
::getInstance()->getConfigFile();
31 $config = PMA_ifSetOr($_POST['textconfig'], '');
32 // make sure our eol is \n
33 $config = str_replace("\r\n", "\n", $config);
34 if ($_SESSION['eol'] == 'win') {
35 $config = str_replace("\n", "\r\n", $config);
43 $form_display = new FormDisplay();
44 $form_display->registerForm('_config.php');
45 $form_display->save('_config.php');
46 $config_file_path = ConfigFile
::getInstance()->getFilePath();
48 if (isset($_POST['eol'])) {
49 $_SESSION['eol'] = ($_POST['eol'] == 'unix') ?
'unix' : 'win';
52 if (PMA_ifSetOr($_POST['submit_clear'], '')) {
54 // Clear current config and return to main page
56 $_SESSION['ConfigFile'] = array();
58 header('HTTP/1.1 303 See Other');
59 header('Location: index.php');
61 } elseif (PMA_ifSetOr($_POST['submit_download'], '')) {
63 // Output generated config file
65 header('Content-Type: text/plain');
66 header('Content-Disposition: attachment; filename="config.inc.php"');
69 } elseif (PMA_ifSetOr($_POST['submit_save'], '')) {
71 // Save generated config file on the server
73 file_put_contents($config_file_path, get_config());
74 header('HTTP/1.1 303 See Other');
75 header('Location: index.php');
77 } elseif (PMA_ifSetOr($_POST['submit_load'], '')) {
79 // Load config file from the server
82 require_once $config_file_path;
83 $_SESSION['ConfigFile'] = $cfg;
84 header('HTTP/1.1 303 See Other');
85 header('Location: index.php');
87 } elseif (PMA_ifSetOr($_POST['submit_delete'], '')) {
89 // Delete config file on the server
91 @unlink
($config_file_path);
92 header('HTTP/1.1 303 See Other');
93 header('Location: index.php');
97 // Show generated config file in a <textarea>
99 header('HTTP/1.1 303 See Other');
100 header('Location: index.php?page=config');