Location: PHPKode > scripts > KubeStats > install/index.php
<?php
// Include the current config file
require_once("../includes/config.php");

$install_version = '0.3';

// Check to see if the script is already installed
if(isset($config['installed']))
{
	if($config['version'] == $install_version)
	{
		// Exit the script
		exit('KubeStats is already installed.');
	}
	else
	{
		header('Location: upgrade_'.$config['version'].'.php');
		exit;
	}
}

// If they have submitted the form
if(isset($_POST['DBName']))
{
	// Check that their config file is writtable
	if(is_writable('../includes/config.php'))
	{
		// Try to connect to the database details they provided
		if(mysql_connect($_POST['DBHost'], $_POST['DBUser'], $_POST['DBPass']))
		{
			// Try to select the database specified
			if(mysql_select_db($_POST['DBName']))
			{
				$site_path = str_replace('\\','/',ereg_replace('install', '', dirname(__FILE__)));
				$site_url = "http://" . $_SERVER['HTTP_HOST'] . ereg_replace ("index.php", "", ereg_replace ("install/", "", $_SERVER['PHP_SELF']));
			
				// Content that will be written to the config file
				$content = "<?php\n";
				$content.= "\$config['db']['host'] = '".addslashes($_POST['DBHost'])."';\n";
				$content.= "\$config['db']['name'] = '".addslashes($_POST['DBName'])."';\n";
				$content.= "\$config['db']['user'] = '".addslashes($_POST['DBUser'])."';\n";
				$content.= "\$config['db']['pass'] = '".addslashes($_POST['DBPass'])."';\n";
				$content.= "\$config['db']['pre'] = '".addslashes($_POST['DBPre'])."';\n";
				$content.= "\n";
				$content.= "\$config['demo'] = '".addslashes($config['demo'])."';\n";
				$content.= "\$config['site_url'] = '".addslashes($site_url)."';\n";
				$content.= "\$config['version'] = '".$config['version']."';\n";
				$content.= "\$config['installed'] = '1';\n";
				$content.= "?>";
			
				// Open the includes/config.php for writting
				$handle = fopen('../includes/config.php', 'w');
				// Write the config file
				fwrite($handle, $content);
				// Close the file
				fclose($handle);
			
				mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."browsers` (  `browser_id` mediumint(8) unsigned NOT NULL default '0', `site_id` int(11) unsigned NOT NULL default '0',  `count` int(11) unsigned NOT NULL default '0',  PRIMARY KEY  (`browser_id`,`site_id`))");
				mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."days` (  `site_id` mediumint(8) unsigned NOT NULL default '0',  `day` smallint(2) unsigned NOT NULL default '0',  `month` smallint(2) unsigned NOT NULL default '0',  `year` mediumint(4) unsigned NOT NULL default '0',  `stamp` int(11) unsigned NOT NULL default '0',  `visits` int(11) unsigned NOT NULL default '0',  `unique` int(11) unsigned NOT NULL default '0',  PRIMARY KEY  (`site_id`,`day`,`month`,`year`)) ENGINE=MyISAM");			
				mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."ips` ( `IP_FROM` double NOT NULL default '0',  `IP_TO` double NOT NULL default '0',  `COUNTRY_CODE2` char(2) NOT NULL default '',  `COUNTRY_CODE3` char(3) NOT NULL default '',  `COUNTRY_NAME` varchar(50) NOT NULL default '',  KEY `CODE` (`IP_FROM`,`IP_TO`,`COUNTRY_CODE2`)) ENGINE=MyISAM");
				mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."months` (  `site_id` mediumint(8) unsigned NOT NULL default '0',  `month` smallint(2) unsigned NOT NULL default '0',  `year` mediumint(4) unsigned NOT NULL default '0',  `visits` int(11) unsigned NOT NULL default '0',  `unique` int(11) unsigned NOT NULL default '0',  PRIMARY KEY  (`site_id`,`month`,`year`)) ENGINE=MyISAM");
				mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."recent` (  `recent_id` int(11) unsigned NOT NULL auto_increment,  `site_id` mediumint(8) unsigned NOT NULL default '0',  `time` int(11) unsigned NOT NULL default '0',  `ip` varchar(20) NOT NULL default '',  `host` varchar(50) NOT NULL default '',  `referrer` varchar(200) NOT NULL default '',  `page` varchar(200) NOT NULL default '',  PRIMARY KEY  (`recent_id`)) ENGINE=MyISAM AUTO_INCREMENT=1 ;");
				mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."referer` (  `refer_id` int(11) unsigned NOT NULL auto_increment,  `site_id` mediumint(8) unsigned NOT NULL default '0',  `url` varchar(200) NOT NULL default '',  `count` mediumint(8) unsigned NOT NULL default '0',  PRIMARY KEY  (`refer_id`)) ENGINE=MyISAM AUTO_INCREMENT=1;");
				mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."searches` (  `site_id` mediumint(8) unsigned NOT NULL default '0',  `search_word` varchar(50) NOT NULL default '',  `search_engine` mediumint(5) unsigned NOT NULL default '0',  `search_count` int(11) unsigned NOT NULL default '0',  PRIMARY KEY  (`site_id`,`search_word`,`search_engine`)) ENGINE=MyISAM");
				mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."sites` (  `site_id` mediumint(8) unsigned NOT NULL auto_increment,  `site_title` varchar(100) NOT NULL default '',  `site_url` varchar(200) NOT NULL default '',  PRIMARY KEY  (`site_id`)) ENGINE=MyISAM AUTO_INCREMENT=1;");
				mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."users` (  `user_id` int(11) unsigned NOT NULL auto_increment,  `username` varchar(40) NOT NULL default '',  `password` varchar(40) NOT NULL default '',  `rem` varchar(40) NOT NULL default '',  PRIMARY KEY  (`user_id`)) ENGINE=MyISAM AUTO_INCREMENT=1;");
				mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."users` VALUES (1, '".addslashes($_POST['adminuser'])."', '".addslashes(md5($_POST['adminpass']))."','".addslashes(md5(mt_rand(0,56)*time()))."');");
			
				header("Location: installed.php");
				exit;
			}
			else
			{
				// The database doesn't exist
				echo '<script>alert(\'Could not find database '.$_POST['DBName'].'\r\n\r\n'.addslashes(mysql_error()).'\');</script>';
			}
		}
		else
		{
			// The username/password does not have access to that database
			echo '<script>alert(\'Could not connect to MySQL using these details.\r\n\r\n'.addslashes(mysql_error()).'\');</script>';
		}
	}
	else
	{
		// Can't write to the includes/config.php file
		echo '<script>alert(\'Could not write to your includes/config.php file.\r\n\r\nPlease check that you have set the chmod/permisions to 0777\');</script>';
	}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>KubeStats - Install</title>
<style type="text/css">
<!--
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
}
.style12 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; }
.style15 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; }
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
-->
</style>
</head>

<body>
<div align="center">
 <br>
  <form name="form1" method="post" action="index.php">
  <table border="0" cellpadding="0" cellspacing="0">
    <tr><td>  Welcome to the KubeStats installation, Please fill in the details<br>
  below and then click &quot;Install&quot;<br>
  <br>
  <Br>
    <table border="0" cellspacing="0" cellpadding="3">
      <tr>
        <td colspan="3"><span class="style15">MySQL Details</span></td>
      </tr>
      <tr>
        <td><span class="style12">MySQL Host: </span></td>
        <td><input style="width:150px;" name="DBHost" type="text" id="DBHost" value="<? if(isset($_POST['DBHost'])){ echo $_POST['DBHost']; } ELSE { echo 'localhost'; } ?>"></td>
        <td><span class="style12">&nbsp;<a href="javascript:alert('The host address of your MySQL database, usually localhost');">(?)</a> </span></td>
      </tr>
      <tr>
        <td><span class="style12">MySQL Username:</span></td>
        <td><input style="width:150px;" name="DBUser" type="text" id="DBUser" value="<? if(isset($_POST['DBUser'])){ echo $_POST['DBUser']; } ?>"></td>
        <td><span class="style12">&nbsp;<a href="javascript:alert('The username used to access your MySQL database');">(?)</a> </span></td>
      </tr>
      <tr>
        <td><span class="style12">MySQL Password:</span></td>
        <td><input style="width:150px;" name="DBPass" type="password" id="DBPass" value="<? if(isset($_POST['DBPass'])){ echo $_POST['DBPass']; } ?>"></td>
        <td><span class="style12">&nbsp;<a href="javascript:alert('The password used to access your MySQL database');">(?)</a> </span></td>
      </tr>
      <tr>
        <td><span class="style12">MySQL Database Name: </span></td>
        <td><input style="width:150px;" name="DBName" type="text" id="DBName" value="<? if(isset($_POST['DBName'])){ echo $_POST['DBName']; } ?>"></td>
        <td><span class="style12">&nbsp;<a href="javascript:alert('The name of your database, you must have first created this.');">(?)</a> </span></td>
      </tr>
      <tr>
        <td><span class="style12">MySQL Table Prefix: </span></td>
        <td><input style="width:150px;" name="DBPre" type="text" id="DBPre" value="<? if(isset($_POST['DBPre'])){ echo $_POST['DBPre']; } else { echo 'stat_'; } ?>"></td>
        <td><span class="style12">&nbsp;<a href="javascript:alert('The text that follows the table names, not required');">(?)</a> </span></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="3"><span class="style15">Admin Details </span></td>
      </tr>
      <tr>
        <td><span class="style12">Admin Username: </span></td>
        <td><input style="width:150px;" name="adminuser" type="text" id="adminuser" value="<? if(isset($_POST['adminuser'])){ echo $_POST['adminuser']; } ?>"></td>
        <td><span class="style12">&nbsp;<a href="javascript:alert('The username that will be used when managing the site');">(?)</a> </span></td>
      </tr>
      <tr>
        <td><span class="style12">Admin Password: </span></td>
        <td><input style="width:150px;" name="adminpass" type="password" id="adminpass" value="<? if(isset($_POST['adminpass'])){ echo $_POST['adminpass']; } ?>"></td>
        <td><span class="style12">&nbsp;<a href="javascript:alert('The password that will be used when managing the site');">(?)</a> </span></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input style="width:150px;" name="Submit" type="submit" value="Install"></td>
        <td>&nbsp;</td>
      </tr>
    </table>
	</td></tr></table>
  </form>
  <span class="footer style1">  <br>
  <br>
  &copy; 2007 <a href="http://www.kubelabs.com/kubestats.php">Kubelabs.com</a></span>
</div>
</body>
</html>
Return current item: KubeStats