2 /***************************************************************************
5 * begin : Saturday, May 05, 2002
6 * copyright : (C) 2002 The phpBB Group
9 * $Id: dbinformer.php,v 1.65 2002/05/04 12:15:00 Blade Exp $
11 * Coded by AL, Techie-Micheal, Blade, and Black Fluffy Lion.
12 * http://www.phpbb.com/phpBB/groupcp.php?g=7330
14 ***************************************************************************/
15 /***************************************************************************
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 ***************************************************************************/
24 /* magic quotes, borrowed from install.php */
25 set_magic_quotes_runtime(0);
26 if (!get_magic_quotes_gpc())
28 if (is_array($HTTP_POST_VARS))
30 while (list($k, $v) = each($HTTP_POST_VARS))
32 if (is_array($HTTP_POST_VARS[$k]))
34 while (list($k2, $v2) = each($HTTP_POST_VARS[$k]))
36 $HTTP_POST_VARS[$k][$k2] = addslashes($v2);
38 @reset($HTTP_POST_VARS[$k]);
42 $HTTP_POST_VARS[$k] = addslashes($v);
45 @reset($HTTP_POST_VARS);
49 $all_connected = false;
55 function make_config($dbms, $dbhost, $dbname, $dbuser, $dbpasswd, $table_prefix)
57 $config_file = '<?php<br />' . "\n";
58 $config_file .= '<br />' . "\n";
59 $config_file .= '//<br />' . "\n";
60 $config_file .= '// phpBB 2.x auto-generated config file<br />' . "\n";
61 $config_file .= '// Do not change anything in this file!<br />' . "\n";
62 $config_file .= '//<br />' . "\n";
63 $config_file .= '<br />' . "\n";
64 $config_file .= '$dbms = \'' . $dbms . '\';<br /><br />' . "\n\n";
65 $config_file .= '$dbhost = \'' . $dbhost . '\';<br />' . "\n";
66 $config_file .= '$dbname = \'' . $dbname . '\';<br />' . "\n";
67 $config_file .= '$dbuser = \'' . $dbuser . '\';<br />' . "\n";
68 $config_file .= '$dbpasswd = \'' . $dbpasswd . '\';<br /><br />' . "\n\n";
69 $config_file .= '$table_prefix = \'' . $table_prefix . '\';<br /><br />' . "\n\n";
70 $config_file .= 'define(\'PHPBB_INSTALLED\', true);<br /><br />' . "\n\n";
76 function make_download($dbms, $dbhost, $dbname, $dbuser, $dbpasswd, $table_prefix)
78 $config_file = '<?php' . "\n\n";
79 $config_file .= '//' . "\n";
80 $config_file .= '// phpBB 2.x auto-generated config file' . "\n";
81 $config_file .= '// Do not change anything in this file!' . "\n";
82 $config_file .= '//' . "\n\n";
83 $config_file .= '$dbms = \'' . $dbms . '\';' . "\n\n";
84 $config_file .= '$dbhost = \'' . $dbhost . '\';' . "\n";
85 $config_file .= '$dbname = \'' . $dbname . '\';' . "\n";
86 $config_file .= '$dbuser = \'' . $dbuser . '\';' . "\n";
87 $config_file .= '$dbpasswd = \'' . $dbpasswd . '\';' . "\n\n";
88 $config_file .= '$table_prefix = \'' . $table_prefix . '\';' . "\n\n";
89 $config_file .= 'define(\'PHPBB_INSTALLED\', true);' . "\n\n";
95 /* make all the vars safe to display in form inputs and on the user's screen. Borrowed from usercp_register.php */
96 $check_var_list = array('dbms' => 'dbms', 'dbhost' => 'dbhost', 'dbname' => 'dbname', 'dbuser' => 'dbuser', 'dbpasswd' => 'dbpasswd', 'table_prefix' => 'table_prefix');
98 while (list($var, $param) = each($check_var_list))
100 if (!empty($HTTP_POST_VARS[$param]))
102 $$var = stripslashes(htmlspecialchars(strip_tags($HTTP_POST_VARS[$param])));
106 $available_dbms = array(
107 'mysql' => 'MySQL 3.x',
108 'mysql4' => 'MySQL 4.x',
109 'postgres' => 'PostgreSQL 7.x',
110 'mssql' => 'MS SQL Server 7/2000',
111 'msaccess' => 'MS Access [ ODBC ]',
112 'mssql-odbc' => 'MS SQL Server [ OBDC ]',
115 if (isset($HTTP_POST_VARS['download_config']) && $HTTP_POST_VARS['download_config'] == true && isset($HTTP_POST_VARS['submit_download_config']) && $HTTP_POST_VARS['submit_download_config'] == 'Download')
117 /* borrowed from install.php */
118 header('Content-Type: text/x-delimtext; name="config.php"');
119 header('Content-disposition: attachment; filename=config.php');
120 echo make_download($dbms, $dbhost, $dbname, $dbuser, $dbpasswd, $table_prefix);
125 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
128 <meta http-equiv="Content-Type" content="text/html" />
129 <meta http-equiv="Content-Style-Type" content="text/css" />
130 <title>phpBB :: dbinformer.php</title>
131 <link rel="stylesheet" href="../templates/subSilver/subSilver.css" type="text/css" />
132 <style type="text/css">
134 p,ul,td {font-size:10pt;}
135 h3 {font-size:12pt;color:blue}
140 <table width="100%" border="0" cellspacing="0" cellpadding="10" align="center">
142 <td class="bodyline"><table width="100%" border="0" cellspacing="0" cellpadding="0">
145 <table width="100%" border="0" cellspacing="0" cellpadding="0">
147 <td><img src="../templates/subSilver/images/logo_phpBB.gif" border="0" alt="phpBB2 : Creating Communities" vspace="1" /></a></td>
148 <td align="center" width="100%" valign="middle"><span class="maintitle">dbinformer.php</span>
153 <br /><b><div align="center">
154 <a href="#what">What you entered</a> |
155 <a href="#connect">Connection to database</a> |
156 <a href="#tables">Tables in database</a> |
157 <a href="#config">Config file</a>
160 <table width="100%" border="0" cellspacing="0" cellpadding="10" align="center">
162 <td align="center" width="100%" valign="middle"><span class="maintitle"></span></td>
166 <table width="100%" cellpadding="2" cellspacing="1" border="0" class="forumline">
168 <th colspan="2">Database Configuration</th>
171 <td class="row1" align="right"><span class="gen">Database type: </span></td>
173 <form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
176 /* loop through the dbms, with the correct one selected (hopefully!) */
177 while (list($var, $param) = each($available_dbms))
179 $selected = ($dbms == $var) ? ' selected="selected"' : '';
180 echo '<option value="' . $var . '"' . $selected . '>' . $param . '</option>';
186 <td class="row1" align="right"><span class="gen">Database Server Hostname / DSN: </span></td>
187 <td class="row2"><input type="text" name="dbhost" value="<?php echo @$dbhost; ?>" /></td>
190 <td class="row1" align="right"><span class="gen">Your Database Name: </span></td>
191 <td class="row2"><input type="text" name="dbname" value="<?php echo @$dbname; ?>" /></td>
194 <td class="row1" align="right"><span class="gen">Database Username: </span></td>
195 <td class="row2"><input type="text" name="dbuser" value="<?php echo @$dbuser; ?>" /></td>
198 <td class="row1" align="right"><span class="gen">Database Password: </span></td>
199 <td class="row2"><input type="password" name="dbpasswd" value="<?php echo @$dbpasswd; ?>" /></td>
202 <td class="row1" align="right"><span class="gen">Chosen Prefix: </span></td>
203 <td class="row2"><input type="text" name="table_prefix" value="<?php echo @$table_prefix; ?>" /></td>
206 <td class="row1" align="right"><span class="gen">Generate a config file: </span></td>
208 <td class="row2"><input type="checkbox" name="generate_config" value="true" <?php $checked = (isset($HTTP_POST_VARS['generate_config']) && $HTTP_POST_VARS['generate_config'] == true) ? 'checked="checked"' : ''; echo $checked; ?> /></td>
211 <td class="catbottom" align="center" colspan="2">
212 <input class="mainoption" type="submit" name="submit" value="Submit" /></td>
218 if (!isset($HTTP_POST_VARS['submit']))
220 echo '<br />Please enter your data.<br />';
224 /* dbal added by Techie-Micheal [and then obliterated by BFL]. weeeeeee! */
228 if (function_exists(@mysql_connect))
231 'choice' => 'MySQL 3.x',
232 'connect' => @mysql_connect($dbhost, $dbuser, $dbpasswd),
233 'select' => @mysql_select_db($dbname),
234 'error' => @mysql_error(),
235 'list' => @mysql_list_tables($dbname),
236 'fetch' => @mysql_fetch_row,
237 'close' => @mysql_close()
243 $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.';
248 if (function_exists(@mysql_connect))
251 'choice' => 'MySQL 4.x',
252 'connect' => @mysql_connect($dbhost, $dbuser, $dbpasswd),
253 'select' => @mysql_select_db($dbname),
254 'error' => @mysql_error(),
255 'list' => @mysql_list_tables($dbname),
256 'fetch' => @mysql_fetch_row,
257 'close' => @mysql_close()
263 $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.';
268 if (function_exists(@odbc_connect))
271 'choice' => 'MS Access [ ODBC ]',
272 'connect' => @odbc_connect($dbhost, $dbuser, $dbpasswd),
274 'error' => @odbc_errormsg(),
275 'list' => 'na', /* odbc_tables() */
276 'fetch' => 'na', /* odbc_fetch_row(), odbc_result_all() */
277 'close' => @odbc_close()
283 $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.';
288 if (function_exists(@pg_connect))
291 'choice' => 'PostgreSQL 7.x',
292 'connect' => @pg_connect('host=' . $dbhost . ' user=' . $dbuser . ' dbname=' . $dbname . ' password=' . $dbpasswd),
294 'error' => @pg_last_error(),
295 'list' => @pg_exec("SELECT relname FROM pg_class WHERE relkind = 'r' AND relname NOT LIKE 'pg\_%'"), /* provided by SuGa */
296 'fetch' => @pg_fetch_row,
297 'close' => @pg_close()
303 $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.';
307 if (function_exists(@mssql_connect))
310 'choice' => 'MS SQL Server 7/2000',
311 'connect' => @mssql_connect($dbhost, $dbuser, $dbpasswd),
312 'select' => @mssql_select_db($dbname),
313 'error' => @mssql_get_last_message(),
315 'fetch' => 'na', /* mssql_fetch_row() */
316 'close' => @mssql_close()
322 $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.';
327 if (function_exists(@odbc_connect))
330 'choice' => 'MS SQL Server [ ODBC ]',
331 'connect' => @odbc_connect($dbhost, $dbuser, $dbpasswd),
333 'error' => @odbc_errormsg(),
334 'list' => 'na', /* odbc_tables() */
335 'fetch' => 'na', /* odbc_fetch_row(), odbc_result_all() */
336 'close' => @odbc_close()
342 $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.';
348 $error_msg = 'Unrecognised DBMS.';
352 if ($error == true && $error_msg != '')
354 echo '<br /><b>ERROR:</b> ' . $error_msg . '<br />';
358 echo '<a name="what"><h3><u>What you entered</u></h3></a>';
359 echo 'Database Type: <b>' . $db['choice'] . '</b><br />';
360 echo 'Database Server Hostname / DSN: <b>' . $dbhost . '</b><br />';
361 echo 'Your Database Name: <b>' . $dbname . '</b><br />';
362 echo 'Database Username: <b>' . $dbuser . '</b><br />';
363 echo 'Database Password: <b>' . $dbpasswd . '</b><br />';
365 echo '<a name="connect"><h3><u>Connection to database</u></h3></a>';
369 echo 'You have not established a connection to <b>' . $db['choice'] . '</b>.<br />';
370 echo '<b>ERROR:</b> <i>' . $db['error'] . '</i><br /><br />';
374 echo 'You have established a connection to <b>' . $db['choice'] . '</b>.<br /><br />';
378 if ($dbms == 'msaccess' || $dbms == 'postgres' || $dbms == 'mssql-odbc')
380 /* for dbmses which have no db select function */
387 echo 'Your database was not found.<br />';
388 echo '<b>ERROR:</b> <i>' . $db['error'] . '</i><br />';
392 echo 'Your database was found.<br />';
397 if ($connect == true && $select == true)
399 echo '<a name="tables"><h3><u>Tables in database</u></h3></a>';
400 if ($dbms == 'mysql' || $dbms == 'mysql4' || $dbms == 'postgres')
402 echo '<i>Tables with the table prefix you specified are in bold.</i>';
404 while ($table = $db['fetch']($db['list']))
406 /* Highlight tables with the table_prefix specified */
407 if (preg_match("/^$HTTP_POST_VARS[table_prefix]/i", $table[0]))
409 echo '<li><b>' . $table[0] . '</b></li><br />';
413 echo '<li>' . $table[0] . '</li><br />';
420 echo 'Sorry, this feature isn\'t available with ' . $db['choice'] . '.';
423 /* defined a var which is only there if successfully connected to the database and the database is found */
424 $all_connected = true;
427 /* Create a config file if checked and if the connection went OK */
428 if (isset($HTTP_POST_VARS['generate_config']) && $HTTP_POST_VARS['generate_config'] == true)
430 echo '<a name="config"><h3><u>Config file</u></h3></a>';
431 if ($all_connected != true)
433 echo 'The database has not been successfully connected to so no config file has been generated.<br />';
437 echo 'Either copy the <b>19</b> lines below and save them as <u>config.php</u> or click on the <u>Download</u> button below. Then upload the file to your phpBB2 root directory (phpBB2/ by default). Make sure that there is nothing (this includes blank spaces) after the <u>?></u>.<br /><br />';
439 /* Create our config file */
440 echo '<form action="' . $HTTP_SERVER_VARS['PHP_SELF'] . '" method="post"><table cellspacing="1" cellpadding="3" border="0"><tr><td class="code">';
441 echo make_config($dbms, $dbhost, $dbname, $dbuser, $dbpasswd, $table_prefix);
442 echo '</td></tr></table>';
443 echo '<input type="hidden" name="dbms" value="' . $dbms . '" />';
444 echo '<input type="hidden" name="dbhost" value="' . $dbhost . '" />';
445 echo '<input type="hidden" name="dbname" value="' . $dbname . '" />';
446 echo '<input type="hidden" name="dbuser" value="' . $dbuser . '" />';
447 echo '<input type="hidden" name="dbpasswd" value="' . $dbpasswd . '" />';
448 echo '<input type="hidden" name="table_prefix" value="' . $table_prefix . '" />';
449 echo '<input type="hidden" name="download_config" value="true" />';
450 echo '<br /><input type="submit" name="submit_download_config" value="Download" class="mainoption" /><br />';
454 /* close the connection */
455 if ($all_connected == true)
462 /* And they all lived happily ever after...
466 <br /><a href="javascript:scrollTo('0','0');"><b>Return to top</b></a>
470 <div align="center"><span class="copyright">© Copyright 2002 The <a href="http://www.phpbb.com/about.php" target="_phpbb" class="copyright">phpBB Group</a></span></div>