Location: PHPKode > scripts > Ramui web hosting directory script > Ramui web hosting directory script/gb/admin/install/index.php
<?php
/*
Copyright (c) 2011 http://ramui.com. All right reserved.
This product is protected by copyright and distributed under licenses restricting copying, distribution. Permission is granted to the public to download and use this script provided that this Notice and any statement of authorship are reproduced in every page on all copies of the script.
*/
include "../../include/functions.php";
class install
{
private function install_now(&$message)
{
		$dbname=fw_strip_slashes(trim($_POST['dbname']));
		$dbuser=fw_strip_slashes(trim($_POST['dbuser']));
		$dbpw=fw_strip_slashes(trim($_POST['dbpw']));
		$savedpw=fw_strip_slashes(trim($_POST['password']));
		$pw=md5($savedpw);
		$admin=fw_strip_slashes(trim($_POST['admin']));
		$email=fw_strip_slashes(trim($_POST['email']));
		$prefix=fw_strip_slashes(trim($_POST['prefix']));
		$dbhost='localhost';
		$dt=time();
		if (!(empty($_POST['dbhost']))){$dbhost=fw_strip_slashes(trim($_POST['dbhost']));}
		if(!(@mysql_connect($dbhost, $dbuser, $dbpw))){$message=mysql_error();return false;}
		if(!(@mysql_selectdb($dbname))){$message='Database not found';return false;}
		if(version_compare(phpversion(),'5.2.1')===-1){$message='Inadequate system: PHP version requirement is 5.2.1 or higher. Your server php version is '.phpversion().'<br />Please contact with your hosting provider.';return false;}
		$result=@mysql_query("select version() as ve");
		if($result!==false){
			$r=mysql_fetch_object($result);
			if(substr($r->ve,0,1)<5){$message='Inadequate system: MYSQL version requirement is 5.0 or higher. Your MYSQL server version is '.$r->ve.'<br />Please contact with your hosting provider.';return false;}}

		if(mysql_num_rows(mysql_query("SHOW TABLES LIKE \"$prefix%\""))) {$message='Table already exist. Please use different table prefix.';return false;}

		$filename="../../database/config.php";
		$handle=@fopen($filename,'w');
		if (!(@fwrite($handle,"<?php\n"))){
			@fclose($handle);
			$message='Error in file permission Please set chmod to &quot;777&quot; or &quot;0777&quot; of the file &quot;admin/database/config.php&quot;. Start installation again.';return false;
		}
		fwrite($handle,'$dbhost=');
		fwrite($handle,"'$dbhost';\n");
		fwrite($handle,'$dbuser=');
		fwrite($handle,"'$dbuser';\n");
		fwrite($handle,'$dbpw=');
		fwrite($handle,"'$dbpw';\n");
		fwrite($handle,'$dbname=');
		fwrite($handle,"'$dbname';\n");
		fwrite($handle,'$prefix=');
		fwrite($handle,"'$prefix';\n");
		fwrite($handle,'?>');
		fclose($handle);

		$selfurl = str_replace("www.","", strtolower(getenv("HTTP_HOST")));
		$str=file("query.txt");
		for($i=0; $i<count($str); $i++){
			$query=str_replace("prefix_",$prefix,str_replace('__SELFURL__',$selfurl,trim($str[$i])));
			$query=str_replace('__DATE__',$dt,str_replace('__EMAIL__',$email,$query));
			$result = @mysql_query($query);
			if(!($result)){$message="Error executing query string => ".($i+1).'<br />'.mysql_error();$this->clear_install($prefix);return false;}
		}

		$query = sprintf("INSERT INTO ".$prefix."admin (user, password, email) VALUES ('%s', '%s', '%s')",mysql_real_escape_string($admin),mysql_real_escape_string($pw),mysql_real_escape_string($email));
		$result = @mysql_query($query);
		if(!($result)){$message=mysql_error();$this->clear_install($prefix);return false;}
		//Confirmation
		$from='hide@address.com';
		$subject='Ramui web hosting directory has been successfully installed';
		$headers="From: hide@address.com\r\n";
		$message="Congratulations! Your Ramui web hosting directory script has been successfully installed.\r\n\r\nLogin information:\r\n------------------------------------------\r\n";
		$message.="User name: $admin";
		$message.="\r\nPassword: $savedpw";
		$message.="\r\nLogin url: http://".getenv('HTTP_HOST').fw_get_docroot()."gb/admin/index.php";
		$message.="\r\n------------------------------------------\r\n\r\nThank you.\r\nArchan Ghosal.(http://ramui.com)";
		@mail($email,$subject,$message,$headers);
		
		$str="<?php exit;?><html><head><title>Installation form</title>\r\n";
		$str.="<style>\r\nbody{background:#cee7ff;font:500 12px tahoma;}\r\ndiv{margin:20px;padding:10px;border:1px solid #5284ce;background:#ffffff;text-align:left;width:600px;}\r\ntd{font:500 12px tahoma;padding:3px;border:1px solid #c0c0c0;}\r\nh1{font:500 18px tahoma;color:#333333;}\r\n</style>\r\n";
		$str.="</head><body><center><div><h1>Ramui web hosting directory has been successfully installed</h1><table><tr><td>Database name:</td><td>$dbname</td></tr><tr><td>Database user name:</td><td>$dbuser</td></tr><tr><td>Database password:</td><td>$dbpw</td></tr><tr><td>Database host name:</td><td>$dbhost</td></tr><tr><td>Table prefix:</td><td>$prefix</td></tr><tr><td>User name:</td><td>$admin</td></tr><tr><td>Password:</td><td>$savedpw</td></tr><tr><td>Email address:</td><td>$email</td></tr></table><hr/><p style='color:#808080;font-size:10px;'>**Please keep a hard copy of this document.</p></div></center></body></html>";
		$random=fw_random();
		$filename='../backup/'.md5($random).'.php';
		$handle=@fopen($filename,'w');
		$self_path='http://'.getenv("HTTP_HOST").fw_get_docroot().'gb/admin/index.php';
		if($handle!==false){
			fwrite($handle,$str);
			fclose($handle);
			$script_path='http://'.getenv("HTTP_HOST").fw_get_docroot().'gb/admin/install/index.php?download='.urlencode($random);}
		$this->build_head('Installation complete','');
		echo '<div style="padding:10px;"><h1>Ramui web hosting directory has been successfully installed</h1><p>Your Ramui web hosting directory version-1 has been successfully installed. An email has been sent to your email address describing all detail about installation.</p>';
		echo '<p>Please <a href="'.$self_path.'">click here</a> to login to your control panel</p></div></div>';
		echo '<div id="bottom">Web hosting directory &copy;&nbsp<a target="_blank" href="http://ramui.com">http://ramui.com</a>. All rights reserved.</div></div></center></body></html>';
		if(!empty($script_path)){echo '<script>location.href="index.php?download='.urlencode($random).'";</script>';}
		exit;
}

private function build_head($title, $script)
{
		$leftmenu="";
		include "../include/head.php";
}

private function build_footer()
{
		include "../include/footer.html";
		exit;
}
private function clear_install($prefix)
{
		$query='DROP TABLE IF EXISTS '.$prefix.'admin, '.$prefix.'user, '.$prefix.'comments, '.$prefix.'post, '.$prefix.'settings, '.$prefix.'searchkey, '.$prefix.'inbox, '.$prefix.'report, '.$prefix.'mailsettings, '.$prefix.'search, '.$prefix.'tmpuser';
		@mysql_query($query);
		$filename="../../database/config.php";
		@file_put_contents($filename,'');
}

public function get_install()
{
		if(!empty($_GET['download'])){
			$download=$_GET['download'];
			$filename='../backup/'.md5($download).'.php';
			$str=file_get_contents($filename);
			$str=str_replace('<?php exit;?>','',$str);
			@unlink($filename);
			@header("Content-type: application/text");
			@header("Content-Disposition: attachment; filename=Installation_form.html");
			echo $str;
			exit;
		}
		if(filesize("../../database/config.php")>10){
			$self_path='http://'.getenv("HTTP_HOST").fw_get_docroot().'gb/admin/index.php';
			@header("Location: $self_path");
			exit;}
		if(!((empty($_POST['dbname']))||(empty($_POST['dbuser']))||(empty($_POST['dbpw'])))){
			$message='';
			$success=$this->install_now($message);}
		$this->build_head("Install",'<script type="text/javascript" src="../script/install.js"></script>');
		include "frminstall.php";
		$this->build_footer();
}
}
$obj=new install();
$obj->get_install();
?>
Return current item: Ramui web hosting directory script