From 5d95d9e852f1472e94d882ae20915a15b8ef23a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 25 Nov 2005 15:49:30 +0000 Subject: [PATCH] Setup script (RFE #601016). --- .cvsignore | 1 + ChangeLog | 2 + Documentation.html | 45 +++- scripts/setup.php | 542 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 580 insertions(+), 10 deletions(-) create mode 100644 scripts/setup.php diff --git a/.cvsignore b/.cvsignore index 7554d7a20..c5dacdf7f 100644 --- a/.cvsignore +++ b/.cvsignore @@ -9,3 +9,4 @@ save .vimrc .project .settings +config diff --git a/ChangeLog b/ChangeLog index 9f14b64d2..38a82d2e4 100755 --- a/ChangeLog +++ b/ChangeLog @@ -38,6 +38,8 @@ $Source$ * libraries/footer.inc.php, lang/*: Better message for new window, thanks to Sebastian and Marc. * libraries/auth/cookie.auth.lib.php: Do not create URLs like index.php?&. + * scripts/setup.php, Documentation.html, .cvsignore: Setup script (RFE + #601016). 2005-11-24 Marc Delisle * js/querywindow.js: bug #1365503, "do not overwrite this query" diff --git a/Documentation.html b/Documentation.html index 70d401aa4..6120a4535 100755 --- a/Documentation.html +++ b/Documentation.html @@ -22,6 +22,7 @@ Requirements  -  Introduction  -  Installation  -  + Setup script  -  Configuration
Transformations  -  @@ -164,17 +165,22 @@ running in safe mode, having some scripts with an owner different from the owner of other scripts will be a problem). See FAQ 4.2 for suggestions. -
  • Create the file config.inc.php in your favorite editor and - fill in there values for host, user, password and authentication mode - to fit your environment. Look at config.default.php how - these fields should be defined. Here, "host" means the - MySQL server. Have a look at - Configuration section for an +
  • Create the file config.inc.php. You can use setup script + provided in distribution (scripts/setup.php) to create basics of + config file. See Setup chapter for + details. If you don't like setup or want to fine tune resulting + configuration, open (or create in case of starting from scratch) + config.inc.php in your favorite editor and fill in there + values for host, user, password and authentication mode to fit your + environment. Look at config.default.php how these fields + should be defined. Here, "host" means the MySQL server. + Have a look at Configuration section for an explanation of all values. Please also read the remaining of this - Installation section for information about authentication modes - and the linked-tables infrastructure.
  • -
  • If you are using the config auth_type, it is suggested that you protect the - phpMyAdmin installation directory, for example with HTTP–AUTH in a + Installation section for information about authentication modes and + the linked-tables infrastructure.
  • If you are using the + config auth_type, it is suggested that you protect the phpMyAdmin + installation directory, for example with HTTP–AUTH in a .htaccess file. See the multi–user sub–section of this FAQ for additional information, especially FAQ 4.4.
  • @@ -190,6 +196,25 @@ side scripting vulnerabilities that might happen to be found in that code. + +

    Setup script usage

    +

    + Since 2.7.1 phpMyAdmin comes with setup script that can help you with + creating configuration. Script is located in scripts folder: scripts/setup.php. It's usage is quite + simple. In case you want just donwload configuration, you don't have to + preform any additional actions. For saving file on webserver, or loading + previous configuration you have to create config directory in + phpMyAdmins top level directory and make it writable to web server. For + loading previous configuration, place it there (and make sure it has write + permissions for webserver). Then you can open setup.php in + your browser and perform setup. +

    +

    + Please note that it doesn not allow to configure everything, so for some + additional features you still need to manually edit configuration file. +

    +

    Linked-tables infrastructure

    diff --git a/scripts/setup.php b/scripts/setup.php new file mode 100644 index 000000000..1982bf4c3 --- /dev/null +++ b/scripts/setup.php @@ -0,0 +1,542 @@ + + +$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(); +?>