Use PMA_backquote where applicable.
[phpmyadmin/crack.git] / setup / config.php
blobb32318fa0506ab173bb3a8ddcd30536e11fa4c23
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 /**
12 * Core libraries.
14 require './lib/common.inc.php';
15 require_once './setup/lib/Form.class.php';
16 require_once './setup/lib/FormDisplay.class.php';
18 /**
19 * Returns config file contents depending on GET type value:
20 * o session - uses ConfigFile::getConfigFile()
21 * o post - uses POST textconfig value
23 * @return string
25 function get_config() {
26 $type = PMA_ifSetOr($_GET['type'], 'session');
28 if ($type == 'session') {
29 $config = ConfigFile::getInstance()->getConfigFile();
30 } else {
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);
39 return $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();
57 // drop post data
58 header('HTTP/1.1 303 See Other');
59 header('Location: index.php');
60 exit;
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"');
67 echo get_config();
68 exit;
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');
76 exit;
77 } elseif (PMA_ifSetOr($_POST['submit_load'], '')) {
79 // Load config file from the server
81 $cfg = array();
82 require_once $config_file_path;
83 $_SESSION['ConfigFile'] = $cfg;
84 header('HTTP/1.1 303 See Other');
85 header('Location: index.php');
86 exit;
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');
94 exit;
95 } else {
97 // Show generated config file in a <textarea>
99 header('HTTP/1.1 303 See Other');
100 header('Location: index.php?page=config');
101 exit;