Location: PHPKode > projects > WhiteCrane > install.php
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WhiteCrane Installer</title>
<link rel="stylesheet" href="themes/whitecrane/style.css" type="text/css" />
<script type="text/javascript" src="paper/common.js"></script>
</head>
<body>
<div id="maincontent">
  <h1>WhiteCrane Installer</h1>
  <?php
function genRandomString(){
	$length = 8;
	$characters = '0123456789abcdefghijklmnopqrstuvwxyz-_:^+~*';
	$string = '';    
	for($p = 0; $p < $length; $p++){
		$string .= $characters[mt_rand(0, strlen($characters))];
	}
	return $string;
}
function genSysId(){
	$id = "";
	$tag = array(
		"ARM",
		"NEC",
		"AME",
		"DEV"
	);
	if($_SERVER['HTTP_HOST'] == "dev.ameoto.com"){
		$id = $tag[2];
	}else if($_SERVER['HTTP_HOST'] != "localhost" || $_SERVER['HTTP_HOST'] != "127.0.0.1"){
		$id = $tag[rand(0, 1)];
	}else{
		$id = $tag[3];
	}
	$id .= rand(11,99);
	$id .= genRandomString();
	$id .= "-u".rand(111,998);
	return $id;
}
function sys_install($setup){
	$config = fopen('paper/config.php', 'w') or die('Unable to write config file!');
	fwrite($config, $setup);
	fclose($config);
	$log = fopen("paper/access.log", "a+");
	fwrite($log, "#".date('Y-m-d g:i:s A')." - WhiteCrane Installed");
	fclose($log);
}
function encrypt($string, $key, $raw = false){
	$result = '';
	for($i=0; $i<strlen($string); $i++){
		$char = substr($string, $i, 1);
		$keychar = substr($key, ($i % strlen($key))-1, 1);
		$char = chr(ord($char)+ord($keychar));
		$result.=$char;
	}
	if($raw == false){
		return base64_encode($result);
	}else{
		return $result;
	}
}
function passhash($user = "##$@", $pass){
	return sha1(encrypt($pass, $user, true));
}
$key = genSysId();
$setup = '<?php 
$config[\'site_title\'] = \''.@$_REQUEST['name'].'\';
$config[\'salt\'] = \''.$key.'\';
$config[\'lang\'] = \'eng\';
$config[\'theme\'] = \'whitecrane\';
$config[\'login\'] = true;
$config[\'cookies\'] = true;
$config[\'extensions\'] = false;
$config[\'inlinephp\'] = false;
$config[\'compress\'] = true;
$config[\'rewrite\'] = false;
$config[\'updates\'] = '.(function_exists("curl_init") ? 'true' : 'false').';
$config[\'debug\'] = false;
$config[\'nl\'] = false;
$config[\'autolinks\'] = true;
$config[\'smilies\'] = true;
$user["'.@$_REQUEST['user'].'"] = array(0 => "'hide@address.com($_REQUEST['user'], $_REQUEST['pass']).'", 1 => 1, 2 => "");
?>';
if(isset($_REQUEST['install'])){
	if(!$_REQUEST['name'] == '' && !$_REQUEST['user'] == '' && !$_REQUEST['pass'] == '' && $_REQUEST['pass'] == $_REQUEST['pass2']){
		sys_install($setup);
		$serial = (string)"E".substr(sha1($key), 0, 8);
		$_SESSION["logged"] = $_REQUEST['user'];
		$_SESSION[$serial] = sha1($_SERVER['HTTP_USER_AGENT'].passhash($_REQUEST['user'], $_REQUEST['pass']).$key);
		echo '<meta http-equiv="refresh" content="1; url=./index.php?act=Save Config" />';
	}else{
		echo('<p style="color:#F00">Oh noes! Something is not right, please try again.</p>');
	}
}
if(!file_exists('paper/config.php')){
	$x = @$_REQUEST['q'];
	switch ($x){
		case 'license': ?>
  <pre>

Copyright 2008-2010 Ameoto Systems. All Rights Reserved.

THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS 
CREATIVE COMMONS PUBLIC LICENCE ("CCPL" OR "LICENCE"). THE WORK IS 
PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE 
WORK OTHER THAN AS AUTHORISED UNDER THIS LICENCE AND/OR APPLICABLE 
LAW IS PROHIBITED.

BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND 
AGREE TO BE BOUND BY THE TERMS OF THIS LICENCE. THE LICENSOR GRANTS 
YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF 
SUCH TERMS AND CONDITIONS.

THIS SOFTWARE IS PROVIDED BY AMEOTO SYSTEMS ''AS IS'' AND IN NO EVENT
SHALL AMEOTO SYSTEMS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
OF THE POSSIBILITY OF SUCH DAMAGE.

<a href="http://creativecommons.org/licenses/by-nd/2.5/au/legalcode">http://creativecommons.org/licenses/by-nd/2.5/au/legalcode</a></pre>
  <div align="right"><a href="?q=install">Agree</a></div>
  <?php 
		break;
		case 'install': 
?>
  <p>WhiteCrane requires that a few directorys are accessible by php so we will now see if that's possible.</p>
  <?php 
$files = array(
	0 => './pages/',
	1 => './uploads/',
	2 => './paper/',
	3 => './paper/cache/'
);
echo '<p><strong>Checking filesystem... ';
foreach($files as $check){
	if(!is_writable($check)){
		die('<span style="color:#F00">Oh Noes!</span></strong><br />Please verify and chmod the '.$check.' directory so php can modify it. <br />You may need to set the owner to that of the webservers run name("www-data", "apache") to avoid security issues.</p></body></html>');
	}
}
echo '<span style="color:#0F0">OK!</span><br />Networking... ';
if(function_exists("curl_init")){
	echo '<span style="color:#0F0">OK!</span>';
}else{
	echo '<span style="color:#F60">Automatic updates are not posible on this server("curl_init" missing).</span>';
}
echo '</strong></p>';
?>
  <p>All you need to do now is fill out the form below and WhiteCrane will be up and running. Once installed this file will no longer function but it is still recommended that you delete it from you web server.</p>
  <form id="installer" name="install" method="post" action="install.php?q=install">
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="form-table">
      <tr>
        <td width="13%"><p>Site Name:</p></td>
        <td width="87%"><input type="text" name="name" id="textfield" /></td>
      </tr>
      <tr>
        <td><p>Username:</p></td>
        <td><input type="text" name="user" id="textfield2" /></td>
      </tr>
      <tr>
        <td><p>Password:</p></td>
        <td><input type="password" name="pass" id="textfield3" />
          <br />
          <input type="password" name="pass2" id="textfield3" />
          (again)</td>
      </tr>
    </table>
    <p align="center">
      <input name="send_data" type="checkbox" id="checkbox" checked="checked" />
      Email Installation Status to Ameoto Systems</p>
    <div id="info">
      <p>This information is purely for statistics and Ameoto Systems Inc. will in no way redistribute the data without written permission.</p>
    </div>
    <div align="center">
      <label>
        <input type="submit" name="install" id="button" value="Install" />
      </label>
    </div>
  </form>
  <?php 
		break;
		default:
?>
  <p><img src="themes/whitecrane/crane.png" /></p>
  <p>Thank you for choosing WhiteCrane, this is the fourth major release of WhiteCrane. This version faster, stronger and prettier.</p>
  <p>With the all new extension system theres no end to the features you can add or even create your self.</p>
  <h2>Requirements</h2>
  <?php
if((int)substr(phpversion(), 0, 1) < 5){
	echo '<p><strong><span style="color:#F00">WhiteCrane is incompetable with your current version.('.phpversion().')</span></strong></p>';
}
?>
  <p>Basically you need a web server with php and that's about it. The number of pages is only limited to the amount of space on your server. Also your web server must support the use of .htaccess files and have mod_rewrite enabled in order to use the pretty url's feature.</p>
  <p>Developed on Apache 2.2 running PHP   5.2.10/5.3</p>
  <h2>Release Notes</h2>
  <pre>
Lets not get into details but its a little faster and lighter then before :D</pre>
  <div align="right"><a href="?q=license">Next</a></div>
  <?php 
	} 
}else{  
?>
  <p><strong>Installation Success!!!</strong> Please remember remove this file from your web server and enjoy your new cms(logging you in, one sec...).</p>
  <?php
if(isset($_REQUEST['send_data']) && $_REQUEST['send_data'] == 'on'){
//define the receiver of the email
$to = 'hide@address.com';
//define the subject of the email
$subject = 'Installation - '.$_SERVER['SERVER_NAME']; 
//define the message to be sent. Each line should be separated with \n
$message = "WhiteCrane135 Installed\nhttp://".dirname($_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: ".$_SERVER['SERVER_NAME'];
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "<p>Feed back was sent to Ameoto Systems to help improve WhiteCrane.</p>" : "";
}
} ?>
</div>
</body>
</html>
<?php session_write_close(); ?>
Return current item: WhiteCrane