$script_info = 'phpMyAdmin simple setup script by Michal Čihař '; $script_version = '$Id$'; function remove_slashes($val) { if (get_magic_quotes_gpc()) { return stripslashes($val); } return $val; } // Grab some variables if (isset($_POST['action'])) { $action = $_POST['action']; } else { $action = ''; } if (isset($_POST['cfg'])) { $cfg = unserialize(remove_slashes($_POST['cfg'])); } else { $cfg = array(); } if (!isset($cfg['Servers']) || !is_array($cfg['Servers'])) { $cfg['Servers'] = array(); } // whether to show html header? if ($action != 'download') { // this needs to be echoed otherwise php with short tags complains echo '' . "\n"; ?> phpMyAdmin setup

phpMyAdmin setup

' . "\n"; if (!empty($title)) { echo '

'; echo $title; echo '

' . "\n"; } echo $text . "\n"; echo '' . "\n"; } function show_hidden_cfg() { global $cfg; echo ''; } function show_action($name, $title, $added = '') { echo '
'; echo ''; echo $added; echo ''; show_hidden_cfg(); echo '
'; echo "\n"; } function footer() { echo ''; exit; } function get_cfg_string() { global $cfg, $script_info, $script_version; $c = $cfg; $ret = " 0) { $ret .= "/* Servers configuration */\n\$i = 0;\n\n"; $cnt = 1; foreach($c['Servers'] as $srv) { $ret .= "/* Server $cnt */\n\$i++;\n"; foreach($srv as $key => $val) { $ret .= "\$cfg['Servers'][\$i][$key] = '$val';\n"; } $cnt++; } $ret .= "/* End of servers configration */\n\n"; } unset($c['Servers']); foreach($c as $key => $val) { $ret .= "\$cfg['$key'] = " . var_export($val, TRUE) . ";\n"; } $ret .= "?>\n"; return $ret; } function grab_values($list) { $a = split(';', $list); $res = array(); foreach($a as $val) { $v = split(':', $val); if (!isset($v[1])) $v[1] = ''; switch($v[1]) { case 'bool': $res[$v[0]] = isset($_POST[$v[0]]); break; default: $res[$v[0]] = remove_slashes($_POST[$v[0]]); break; } } return $res; } function show_config_form($list, $defaults = array(), $save = 'Add') { foreach($list as $val) { $type = 'text'; if (isset($val[3])) { if (is_array($val[3])) $type = 'select'; elseif (is_bool($val[3])) $type = 'check'; elseif ($val[3] == 'password') $type = 'password'; } switch ($type) { case 'text': case 'password': echo ''; echo ''; break; case 'check': echo ''; echo ''; break; case 'select': echo ''; echo ''; break; } echo '
' . "\n"; } echo '
Actions:
'; echo ''; echo ''; echo "\n"; } function show_server_form($defaults = array(), $number = FALSE) { ?>
'; } show_config_form(array( array('Server hostname', 'host', 'Hostname where MySQL server is running'), array('Server port', 'port', 'Port on which MySQL server is listening, leave empty if don\'t know'), array('Server socked', 'socket', 'Socket on which MySQL server is listening, leave empty if don\'t know'), array('Connection type', 'connect_type', 'How to connect to server, keep tcp if don\'t know', array('tcp', 'socket')), array('PHP extension to use', 'extension', 'What PHP extension to use, use mysqli if supported', array('mysql', 'mysqli')), array('Compress connection', 'compress', 'Whether to compress connection to MySQL server', FALSE), array('phpMyAdmin control user', 'controluser', 'User which phpMyAdmin can use for various actions'), array('phpMyAdmin control user password', 'controlpass', 'Password for user which phpMyAdmin can use for various actions', 'password'), array('Authentication type', 'auth_type', 'Authentication method to use', array('cookie', 'http', 'config')), array('User for config auth', 'user', 'Leave empty if not using config auth'), array('Password for config auth', 'password', 'Leave empty if not using config auth', 'password'), array('Only database to show', 'only_db', 'Limit listing of databases in left frame to this one'), array('Verbose name of this server', 'verbose', 'Name to display in server selection'), array('phpMyAdmin database for advanced features', 'pmadb', 'phpMyAdmin will allow much more when you enable this'), ), $defaults, $number === FALSE ? 'Add' : 'Save'); ?>
'; foreach ($cfg['Servers'] as $key => $val) { $ret .= ''; } $ret .= ''; return $ret; } if ($action != 'download') { // Check whether we can write to configuration $fail_dir = FALSE; $fail_dir = $fail_dir || !is_dir('../config/'); $fail_dir = $fail_dir || !is_writable('../config/config.inc.php'); $config = @fopen('../config/config.inc.php', 'a'); $fail_dir = $fail_dir || ($config === FALSE); @fclose($config); if ($fail_dir) { message('warning', 'Please create web server writable folder config in phpMyAdmin toplevel directory as described in documentation. Otherwise you will be only able to download or display it.', 'Can not write configuration'); } } if (empty($action)) { message('notice', 'You want to configure phpMyAdmin using web interface. Please note that this only allows basic setup, please read documentation to see full description of all configuration directives.', 'Welcome'); if (empty($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) == 'off') { message('warning', 'You are not using secure connection, all data (including sensitive ones, like passwords) are transfered unencrypted!'); } } $show_info = FALSE; switch ($action) { case 'download': header('Content-Type: text/plain'); header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Content-Disposition: attachment; filename="config.inc.php"'); header('Pragma: no-cache'); echo get_cfg_string(); exit; break; case 'display': echo '
' . "\n"; ?> ' . file_get_contents( $config_file ) ); } else { $success_apply_user_config = eval( '?>' . implode( '\n', file( $config_file ) ) ); } error_reporting( $old_error_reporting ); unset( $old_error_reporting ); if ($success_apply_user_config === FALSE) { message('error', 'Error while parsing configuraton file!'); $cfg = $bck_cfg; } elseif (count($cfg) == 0 || (isset($cfg['Servers']) && count($cfg) == 1 || count($cfg['Servers']) == 0)) { message('error', 'Config file seems to contain no configuration!'); $cfg = $bck_cfg; } else { message('notice', 'Configuration loaded'); } } else { message('error', 'Configuration file not found!'); $cfg = $bck_cfg; } $show_info = TRUE; break; case 'addserver_real': if (isset($_POST['submit_save'])) { $new_server = grab_values('host;port;socket;connect_type;compress:bool;controluser;controlpass;auth_type;user;password;only_db;verbose;pmadb'); // Just use defaults, should be okay for most users if (!empty($new_server['pma_db'])) { $new_server['bookmarktable'] = 'pma_bookmark'; $new_server['relation'] = 'pma_relation'; $new_server['table_info'] = 'pma_table_info'; $new_server['table_coords'] = 'pma_table_coords'; $new_server['pdf_pages'] = 'pma_pdf_pages'; $new_server['column_info'] = 'pma_column_info'; $new_server['history'] = 'pma_history'; } $err = FALSE; if (empty($new_server['host'])) { message('error', 'Empty hostname!'); $err = TRUE; } if ($new_server['socket'] && empty($new_server['socket'])) { message('error', 'Empty socket with socket connection seleted!'); $err = TRUE; } if ($new_server['auth_type'] == 'config' && empty($new_server['user'])) { message('error', 'Empty username while using config authentication method!'); $err = TRUE; } if ($new_server['auth_type'] == 'config') { message('warning', 'Remember to protect your installation while using config authentication method!'); } if ($err) { show_server_form($new_server, isset($_POST['server']) ? $_POST['server'] : FALSE); } else { if (isset($_POST['server'])) { $cfg['Servers'][$_POST['server']] = $new_server; message('notice', 'Changed server number ' . $_POST['server']); } else { $cfg['Servers'][] = $new_server; message('notice', 'New server added'); } $show_info = TRUE; } } else { message('notice', 'Adding of server canceled'); $show_info = TRUE; } break; case 'addserver': if (count($cfg['Servers']) == 0) { show_server_form(array('host' => 'localhost', 'auth_type' => 'config', 'user' => 'root')); } else { show_server_form(); } break; case 'editserver': message('notice', 'Editing server number ' . $_POST['server']); show_server_form($cfg['Servers'][$_POST['server']], $_POST['server']); break; case 'deleteserver': message('notice', 'Deleted server number ' . $_POST['server']); unset($cfg['Servers'][$_POST['server']]); // FIXME: compress array here (maybe not needed) $show_info = TRUE; break; case 'servers': if (count($cfg['Servers']) == 0) { message('notice', 'No servers defined, so none can not be shown'); } else { foreach($cfg['Servers'] as $srv) { // FIXME: more human friendly output echo '
';
                print_r($srv);
                echo '
'; } } break; case 'main': case '': $show_info = TRUE; break; } if ($show_info) { echo '

Current configuration overview:

' . "\n"; echo '

You have defined ' . count($cfg['Servers']) . ' servers:'; $sep = ' '; foreach ($cfg['Servers'] as $val) { echo $sep; $sep = ', '; echo get_server_name($val); } unset($sep); echo '

' . "\n"; } echo '

Available global actions (please note that these will delete any changes you could have done above):

'; show_action('display', 'Display current configuration'); show_action('download', 'Download current configuration'); if (!$fail_dir) { show_action('save', 'Save current configuration'); show_action('load', 'Load saved configuration'); } echo '
'; show_action('addserver', 'Add server configuration'); $servers = get_server_selection(); if (!empty($servers)) { show_action('deleteserver', 'Delete this server', $servers); show_action('editserver', 'Edit this server', $servers); } echo '
'; show_action('main', 'Display overview'); show_action('servers', 'Display servers'); echo '

'; footer(); ?>