Define for swekey defaults.
[phpmyadmin/last10db.git] / setup / config.php
blob58073b206c948d213435856139b5c10ec7cf179b
1 <?php
2 /**
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
8 * @version $Id$
9 */
11 require './lib/common.inc.php';
12 require_once './setup/lib/Form.class.php';
13 require_once './setup/lib/FormDisplay.class.php';
15 /**
16 * Returns config file contents depending on GET type value:
17 * o session - uses ConfigFile::getConfigFile()
18 * o post - uses POST textconfig value
20 * @return string
22 function get_config() {
23 $type = PMA_ifSetOr($_GET['type'], 'session');
25 if ($type == 'session') {
26 $config = ConfigFile::getInstance()->getConfigFile();
27 } else {
28 $config = PMA_ifSetOr($_POST['textconfig'], '');
29 // make sure our eol is \n
30 $config = str_replace("\r\n", "\n", $config);
31 if ($_SESSION['eol'] == 'win') {
32 $config = str_replace("\n", "\r\n", $config);
36 return $config;
40 $form_display = new FormDisplay();
41 $form_display->registerForm('_config.php');
42 $form_display->save('_config.php');
43 $config_file_path = ConfigFile::getInstance()->getFilePath();
45 if (isset($_POST['eol'])) {
46 $_SESSION['eol'] = ($_POST['eol'] == 'unix') ? 'unix' : 'win';
49 if (PMA_ifSetOr($_POST['submit_clear'], '')) {
51 // Clear current config and return to main page
53 $_SESSION['ConfigFile'] = array();
54 // drop post data
55 header('HTTP/1.1 303 See Other');
56 header('Location: index.php');
57 exit;
58 } elseif (PMA_ifSetOr($_POST['submit_download'], '')) {
60 // Output generated config file
62 header('Content-Type: text/plain');
63 header('Content-Disposition: attachment; filename="config.inc.php"');
64 echo get_config();
65 exit;
66 } elseif (PMA_ifSetOr($_POST['submit_save'], '')) {
68 // Save generated config file on the server
70 file_put_contents($config_file_path, get_config());
71 header('HTTP/1.1 303 See Other');
72 header('Location: index.php');
73 exit;
74 } elseif (PMA_ifSetOr($_POST['submit_load'], '')) {
76 // Load config file from the server
78 $cfg = array();
79 require_once $config_file_path;
80 $_SESSION['ConfigFile'] = $cfg;
81 header('HTTP/1.1 303 See Other');
82 header('Location: index.php');
83 exit;
84 } elseif (PMA_ifSetOr($_POST['submit_delete'], '')) {
86 // Delete config file on the server
88 @unlink($config_file_path);
89 header('HTTP/1.1 303 See Other');
90 header('Location: index.php');
91 exit;
92 } else {
94 // Show generated config file in a <textarea>
96 header('HTTP/1.1 303 See Other');
97 header('Location: index.php?page=config');
98 exit;