Location: PHPKode > scripts > GenieGate Membership protection software > web/admin/setup.php
<?php 
function scan_up($dir){
	if(! $dir){
		return(FALSE);
	}
	$pwd = $dir;
	while($pwd){
		if(file_exists('conf/geniegate.ini')){
			$found = htmlentities($pwd);
		}
		if(file_exists('geniegate/conf/geniegate.ini')){
			chdir('geniegate');
			$found = getcwd();
			break;
		}
		chdir('..');
		$pwd = getcwd();
		if($pwd == '/'){
			break;
		}
	}
	chdir($dir);
	return($found);
}

if($_GET['PHP_DEBUG']){ 
	$scandir = scan_up(dirname(__FILE__));
	if(! $scandir){
		$scandir = scan_up(getcwd());
	}
	echo '<ul>';
	if($scandir){
		printf('<li>');
		echo "<p>Found a potential ~/geniegate directory, please ensure this directory is <b>not</b> web enabled.</p>";
		printf('<p>Detected: <b>%s</b></p>',$scandir);
		echo '</li>';
	}
	printf("<li>Directory of setup.php: %s</li>",htmlentities(dirname(__FILE__)));
	printf("<li>Present Working directory: %s</li>",getcwd());
	echo '</ul>';
	phpinfo();
	exit;
} ?>

<html>
<head>
	<style>
@import url(http://www.geniegate.com/style.php);
.error { color: red; }
.atbox { margin: 3%; 
		 border-style: solid; border-color: blue; border-width: 2px; 
		padding: 12px;
		}
.atbox h1 { color: black; text-align: center; margin-top: 0px; margin-bottom: 8px;}
code { font-family: fixed; }
blockquote { font-family: fixed; border-color: #C7C7C7; border-width: 1px; border-style: solid; }
blockquote h1 { 
		font-size: medium; text-align: center; 
		color: black;
		background-color: #C7C7C7;
		margin-top: 0px;
}
#DB_SET tr th { text-align: right; }
	</style>
</head>
<body>
<div id="banner" style="text-align: center">
<img src="http://geniegate.com/img/banner.gif" />
</div>
<h1 id="subTitle">GenieGate/Dolphin edition</h1>
<a href="?PHP_DEBUG=phpinfo">PHP Info</a> :: <a href="http://www.geniegate.com/contact.php?REF=SETUP">Support</a>
<div class="bodyArea">
<?php

function verb_no_home(){
	if(function_exists('posix_getpwuid')){
		$user = fileowner($_SERVER['SCRIPT_FILENAME']);
		$inf = posix_getpwuid($user);
		if(! is_dir($inf['dir'])){
			$inf['dir'] = '';
		}
	}
	?>

	<p>
	Welcome to GenieGate! unfortunately, we've found some (hopefully minor!) problems. If none of
	this makes sense to you, please feel free to contact us. We'll do everything we can to get
	you up and running.
	</p>

	<span class="error">Unable to find your <i>~/geniegate/</i> directory.</span>
	<?php if($inf['dir']){ ?>
		Your <b>HOME</b> directory on this machine is 
		detected as: &quot;<code><?php echo $inf['dir']; ?></code>&quot;</p> 
	<p class="atbox">
		<?php printf("Recommended <i>~/geniegate/</i> directory: <b>%s/geniegate</b>",$inf['dir']); ?>
	</p>
	<p>
		<form action="?PHP_DEBUG=phpinfo" method="GET">
			<input name="PHP_DEBUG" value="phpinfo" type="HIDDEN">
			<input type="SUBMIT" value="Diagnose &amp; Debug Problems">
		</form>
	</p>

	<p>
		In a standard installation, you should have your <i>~/geniegate</i> files
		in this directory. Please copy the ~/geniegate files to the above directory. 
	</p>

	<p>You should have a
		<?php echo $inf['dir'] . '/geniegate'; ?> directory after this step. (NOTE:
		some FTP programs may show this as &quot;/geniegate&quot;)
	</p>

	<form method="GET" action="?" style="text-align: center;">
		<p>
		<input type="SUBMIT" value="Fix above problem and try again" /> &nbsp; 
		<a href="http://www.geniegate.com/contact.php?REF=SETUP">Contact Us</a>
		</p>
		<p>
			<a href="http://www.geniegate.com/art/pdf/keep-it-off-the-web.pdf">What is this directory for? (pdf)</a>
		</p>
	</form>

	<?php }else{ ?>
		</p>
		<p>
		Unable to determine your <b>HOME</b> directory on this platform, you will probably
		need to use the alternate installation methods.
		</p>
	<?php } ?>

	<div style="background-color: #D8D0D0; margin: 3%; padding: 5px;" >
		<h3 style="text-align: center">Alternate methods</h3>
	<p>
	If the recommended directory is not suitable, there are two alternative
	ways of placing it elsewhere.
	</p>

	<dl>
		<dt>Set an environment variable</dt>
		<dd>
			<p>If your version of Apache supports the <b>SetEnv</b> directive, you
				may add this line to an .htaccess file:</p>
			<p>
			<blockquote>
				<h1>In your .htaccess file</h1>
				SetEnv GENIEGATE_HOME <i>/path/to/your/geniegate/directory/</i>
			</blockquote>
			</p>
		</dd>
		<dt>Setting the definition in <i>doconf.php</i></dt>
		<dd>
			<p>
				<blockquote>
					<h1>Setting a definition in your doconf.php file</h1>
					/* This will manually set the GENIEGATE_HOME path */
				 	define('GENIEGATE_HOME','/path/to/your/geniegate/directory/');
				</blockquote>
			</p>
		</dd>
	</dl>

		<form method="POST" action="?">
			<p>
				If you are certain you want to use an alternative method,
				you may hit the &quot;Continue&quot; button. Note that
				your database settings must be set up first. (in 
				<code>~/geniegate/conf/geniegate.ini</code>
			</p>
			<input name="RUN_SETUP" value="1" type="HIDDEN"/>
			<div style="text-align: center">
			<input type="SUBMIT" value="Enough already! Continue without nagging me about it!" />
			</div>
		</form>

	</div>

	<p><b>IMPORTANT</b> The files in your <i>~/geniegate/</i> directory should <b>NEVER</b>
	be web accessible, you should not be able to load them in a web browser, they are never
	used in that manner, only the <i>web/</i> files need to be stored in web server space.</p>

	<p>
	This directory contains sensitive files (such as your database settings) which are not to
	be made web accessible.
	</p>

	<p>
	If you have absolutely no alternative but to place them in <i>web space</i> you should contact
	your ISP and bug them about it, explain to them that you need some place to store files
	that are intended only for server-side programs and should not be served to web browsers.
	<p>
	You might also 
	<a href="http://www.geniegate.com/contact.php?REF=SETUP">contact us</a>, we have some 
	&quot;options of last resort&quot; you can use if they refuse to give you 
	an &quot;off the web&quot; storage area. This problem affects far more than
	GenieGate, this issue is a 
	<a href="http://www.geniegate.com/art/pdf/keep-it-off-the-web.pdf">
	potential problem for many server-side programs.</a>
	</p>

	<?php 
}
function verb_database_settings($file,$cfg){
	$db = $cfg['database'];
	?>
		
	<div class="atbox">
	<h1>MYSQL Database Settings</h1>
	<table cols="2" width="90%" align="center" id="DB_SET">
		<tr>
			<th width="20%">HOST</th>
			<td width="80%">
				<?php echo htmlentities($db['HOST']); ?>
			<td>
		</tr>
		<tr>
			<th width="20%">DATABASE</th>
			<td width="80%">
				<?php echo htmlentities($db['DATABASE']); ?>
			</td>
		</tr>
		<tr>
			<th width="20%">USER</th>
			<td width="80%"><?php echo htmlentities($db['USER']); ?>
			</td>
		</tr>
		<tr>
			<th width="20%">PASS</th>
			<td width="80%">***(Not Shown)***</td>
		</tr>
	</table>

	<p>
		Configuration File: <code><?php echo htmlentities($file); ?></code>
	</p>


	</div>

	<div style="text-align: center">
	<form method="POST" action="?">
		<input name="RUN_SETUP" value="1" type="HIDDEN"/>
		<input type="SUBMIT" value="These are correct, proceed with setup" />
	</form>
	</div>

	<p>
		If the information above is incorrect, please edit your
		configuration file, paying particular attention to 
		the <b>[database]</b> section. Your configuration file
		is <i><?php echo htmlentities($file); ?></i>
	</p>

	<p>
		Please confirm this is the correct information, tables will
		be created in this database.
	</p>

	<?php
}


function sanity_check(){
	if($_REQUEST['RUN_SETUP']){
		return(TRUE);
	}
	$ok = TRUE;
	if(! defined("GENIEGATE_HOME")){
		$home = getenv('GENIEGATE_HOME');
		if(! $home){
			$user = fileowner($_SERVER['SCRIPT_FILENAME']);
			if($user){
				if(function_exists('posix_getpwuid')){
					$inf = posix_getpwuid($user);
					$home = $inf['dir'] . "/geniegate";
				}
			}
		}
		if(is_dir($home)){
			define('GENIEGATE_HOME',$home);
		}
	}
	if(! defined('GENIEGATE_HOME')){
		verb_no_home();
		$ok = FALSE;
	}else{
		$file = GENIEGATE_HOME . '/conf/geniegate.ini'; 
		if(! file_exists($file)){
			$ok = FALSE;
			printf('<h1 class="error">%s</h1>',"Missing $file");
			printf('<p>Perhaps your %s directory is incorrect?',GENIEGATE_HOME);
			$ok = FALSE;
		}else{
			$cfg = parse_ini_file($file,TRUE);
		}
	}
	if($ok){
		if(! $_REQUEST['DID_EXAMINE_CONF']){
			$ok = FALSE;
			verb_database_settings($file,$cfg);
		}	
	}
	return($ok);
}

if(! sanity_check()){
	echo "</div></body></html>";
	exit;
}

require_once('doconf.php');
$conf = findConf();
require_once('GenieGate/Util/Setup.php');
class AppSetup extends GenieGate_Util_Setup {

	function set_ini_conf(&$cfo,&$log,$sect,$ini){
		foreach($ini as $k => $v){
			$ck = "$sect/$k";
			$cfo->put($ck,$v);
			$log->message("Config: " . $ck);
		}
	}

	function run(){
		parent::run();

		// The database.

		$this->run_xml_db('GenieGate/Util/Database.xml'); 

		// The "views"
		// Views for administration.
		$this->run_view_xml('GenieGate/Util/admin.xml','Admin');
		// Views for user panels.
		$this->run_view_xml('GenieGate/Util/user.xml','User');	

		// Do configuration, both User and Admin interfaces use the same "Application ID"
		$cfo = $this->getConfig('GenieGate');
		$log = new GenieGate_Util_Setup_Logger();
		$log->title("Setting up default configuration");

		$server_base = $this->get_server_base();	
		// Take a guess at where the /users directory is.
		$fn = dirname(dirname($_SERVER['SCRIPT_NAME']));
		if($fn == '/'){
			$this->assign_default_conf($cfo,'Url/UserWeb',$server_base . $fn . 'users');
		}else{
			$this->assign_default_conf($cfo,'Url/UserWeb',$server_base . $fn . '/users');
		}

		/**
		* Url/ configs of interest are: confirm - Location to confirm user account.
		*/
		foreach($this->CFG as $k => $v){
			// No need to store this.
			if($k == 'database'){
				continue;
			}
			if(is_array($v)){
				$this->set_ini_conf($cfo,$log,$k,$v);
			}else{
				$cfo->put($k,$v);
			}
		}
		array_push($this->LOGGERS,$log);
	}
	function get_server_base(){
		$host = $_SERVER['HTTP_HOST'] ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
		$http = "http://";
		if($_SERVER['SERVER_PORT']){
			$port = ($_SERVER['SERVER_PORT'] == 80) ? '' : ':' . $_SERVER['SERVER_PORT'];
			if($_SERVER['SERVER_PORT'] == 443){
				$http = 'https://';
				$port = '';
			}
		}
		return($http . $host . $port);	
	}
	function assign_default_conf(&$cf,$key,$val){
		if(! $cf->settingId($key)){
			$cf->put($key,$val);
		}
	}

}
$setup = new AppSetup($conf);
$setup->run();
?>
<div class="setUp">
<?php $setup->display(); ?>
</div>
</div>

<h2>Login Credentials</h2>

<p>
The default login credentials for geniegate are as follows:
</p>

<p>
User ID: <code>root</code>
</p>

<p>
Password: <code>geniegate</code>
</p>

<p>
If you are running setup for the first time, you may login with the above username and password. 
<strong>Important</strong> this information <i>will not be reset</i> if you run setup again, it is
essential that you change your root password as soon as possible and that you record it. 
</p>

<p>
<strong>Repeat</strong> you will not be able to simply reset the root password by re-running setup.
</p>

<p>
You may now 
<a href="index.php">Login to your control panel</a>
</p>

</body>
</html>
Return current item: GenieGate Membership protection software