Code: Select all
<?php
if (!isset($_POST['submit'])) {
?>
<html>
<b>Train Installation</b><br><br>
Make sure you perform the following before running this installer:
<ul>
<li>CHMOD config.php to 0777</li>
</ul><br>
<form name="install" method="post" action="installer.php"><br>
MySQL Server: <input type="text" name="dbserver" value="localhost"><br>
MySQL Database: <input type="text" name="dbname"><br>
MySQL Usename: <input type="text" name="dbuser"><br>
MySQL Password: <input type="text" name="dbpass"><br>
Admin CP Password: <input type="text" name="admincp"><br>
<input type="submit" name="submit" value="Install Script">
</form>
</html>
<?php
}
else
{
if (!is_writable("config.php")) {
echo "<B>The config.php is not writable (CHMOD to 0777)</B>";
exit;
}
if (!is_readable("mysql.sql")) {
echo "<b>The mysql.sql file cannot be read! Check permission settings</B>";
exit;
}
if (!is_readable("config_class.txt")) {
echo "<B>Config_class.txt cannot be read! Check permission settings</B>";
exit;
}
}
$file = file_get_contents("config_class.txt");
$f = fopen("config.php","w");
$str = '<?
';
$str = $str.'$mysql["server"] = "'.$_POST["dbserver"].'";
';
$str = $str.'$mysql["user"] = "'.$_POST["dbuser"].'";
';
$str = $str.'$mysql["pass"] = "'.$_POST["dbpass"].'";
';
$str = $str.'$mysql["db"] = "'.$_POST['dbname'].'";
';
$str = $str.'$admin_pass = "'.$_POST['admincp'].'";
';
$str = $str.$file;
$str = $str.'
?>';
if (fwrite($f,$str)) {
echo "Config file updated...<br>";
}
else
{
echo "<B>Error - Unable to write to config file!</B>";
exit;
}
fclose($f);
if (!mysql_connect($_POST['dbserver'],$_POST['dbuser'],$_POST['dbpass'])) {
echo "MySQL connection failed - check inputted settings";
exit;
}
if (!mysql_select_db($_POST['dbname'])) {
echo "Unable to select MySQL Database!";
exit;
}
$file = file_get_contents("mysql.sql");
$file = str_replace("'", "\'", $file);
$lines = explode(";", $file);
foreach ($lines as $line) {
if (trim($line)!="") {
$line = str_replace("%time%", time(), $line);
mysql_query($line) or die("<b>".$line." - ".mysql_error()."</b>");
}
}
?>
MySQL database setup...<br>
<font color="green"><b>Installation Complete!</b></font><br><br>
<font color="red"><B>IMPORTANT:</B></font> DELETE THIS INSTALLER.PHP & CONFIG_CLASS.TXT FILEs IF SITE IS INSTALLED CORECTLY!