+ if (!is_writable ('inc/secret.php'))
+ {
+ echo "The inc/secret.php file is not writable by web-server. Make sure it is.";
+ echo "The following commands should suffice:<pre>touch inc/secret.php\nchmod 666 inc/secret.php</pre>";
+ return FALSE;
+ }
+ if
+ (
+ !isset ($_REQUEST['save_config']) or
+ empty ($_REQUEST['mysql_host']) or
+ empty ($_REQUEST['mysql_db']) or
+ empty ($_REQUEST['mysql_username']) or
+ empty ($_REQUEST['mysql_password'])
+ )
+ {
+ echo "<input type=hidden name=save_config value=1>\n";
+ echo '<table>';
+ echo "<tr><td><label for=mysql_host>MySQL host:</label></td>";
+ echo "<td><input type=text name=mysql_host id=mysql_host value=localhost></td></tr>\n";
+ echo "<tr><td><label for=mysql_host>database:</label></td>";
+ echo "<td><input type=text name=mysql_db id=mysql_db value=racktables></td></tr>\n";
+ echo "<tr><td><label for=mysql_username>username:</label></td>";
+ echo "<td><input type=text name=mysql_username></td></tr>\n";
+ echo "<tr><td><label for=mysql_password>password:</label></td>";
+ echo "<td><input type=password name=mysql_password></td></tr>\n";
+ echo '</table>';
+ return FALSE;
+ }
+ $pdo_dsn = 'mysql:host=' . $_REQUEST['mysql_host'] . ';dbname=' . $_REQUEST['mysql_db'];
+ try
+ {
+ $dbxlink = new PDO ($pdo_dsn, $_REQUEST['mysql_username'], $_REQUEST['mysql_password']);
+ }
+ catch (PDOException $e)
+ {
+ echo "<input type=hidden name=save_config value=1>\n";
+ echo '<table>';
+ echo "<tr><td><label for=mysql_host>MySQL host:</label></td>";
+ echo "<td><input type=text name=mysql_host id=mysql_host value='" . $_REQUEST['mysql_host'] . "'></td></tr>\n";
+ echo "<tr><td><label for=mysql_host>database:</label></td>";
+ echo "<td><input type=text name=mysql_db id=mysql_db value='" . $_REQUEST['mysql_db'] . "'></td></tr>\n";
+ echo "<tr><td><label for=mysql_username>username:</label></td>";
+ echo "<td><input type=text name=mysql_username value='" . $_REQUEST['mysql_username'] . "'></td></tr>\n";
+ echo "<tr><td><label for=mysql_password>password:</label></td>";
+ echo "<td><input type=password name=mysql_password value='" . $_REQUEST['mysql_password'] . "'></td></tr>\n";
+ echo "<tr><td colspan=2>The above parameters did not work. Check and try again.</td></tr>\n";
+ echo '</table>';
+ return FALSE;
+ }
+ $conf = fopen ('inc/secret.php', 'w+');
+ if ($conf === FALSE)
+ {
+ echo "Error: failed to open inc/secret.php for writing";
+ return FALSE;
+ }
+ fwrite ($conf, "<?php\n/* This file has been generated automatically by RackTables installer.\n");
+ fwrite ($conf, " * you shouldn't normally edit it unless your database setup has changed.\n");
+ fwrite ($conf, " */\n");
+ fwrite ($conf, "\$pdo_dsn = '${pdo_dsn}';\n");
+ fwrite ($conf, "\$db_username = '" . $_REQUEST['mysql_username'] . "';\n");
+ fwrite ($conf, "\$db_password = '" . $_REQUEST['mysql_password'] . "';\n");
+ fwrite ($conf, "?>\n");
+ fclose ($conf);
+ echo "The configuration file has been written successfully.<br>";