Location: PHPKode > projects > Cynus > cynus/load_cynus.php
<?php
/**
 * @file load_cynus.php -- Loads Cynus
 * @Id $Id: load_cynus.php,v 1.34.2.1 2004/08/01 19:21:30 brett Exp $
 *
 * Cynus - a web-based content manager
 * Copyright (C) 2003 Brett and Jason Profitt
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
#define (IGNORE_PERMS, 1);

define (DEBUG_LEVEL, 0);
require_once ("debug.php");
cynus_debug ("Loaded load_cynus.php", 3);
cynus_debug ("Starting cynus.", 3);
cynus_debug ("Sent variables:", 5);

if (count ($_GET) > 0) {
	cynus_debug ('$_GET', 5);
	cynus_debug ($_GET, 5);
}
if (count ($_POST) > 0) {
	cynus_debug ('$_POST', 5);
	cynus_debug ($_POST, 5);
}
if (count ($_COOKIE) > 0) {
	cynus_debug ('$_COOKIE', 5);
	cynus_debug ($_COOKIE, 5);
}


# checking for config settings.
# forming the right error if we are a
# new installation.
if(!file_exists('config.php') || (@filesize ('config.php')<1)) {
	$dir_perms = base_convert(@fileperms('./install/'), 10, 8);
	$dir_perms = substr($dir_perms, (strlen($dir_perms) - 3)); 
	
	$conf_perms = base_convert(@fileperms('./config.php'), 10, 8);
	$conf_perms = substr($conf_perms, (strlen($conf_perms) - 3)); 

	if ($dir_perms != '777') {
		#$msg = '<a style="color:#ff0000">Directory permissions are incorrect.  Please correct them and rerun this script.</a><br />';
		$msg = '<a style="color:#ff0000">Fatal Error!</a><br />' .
			'Directory permissions are incorrect.  Please run the installation script or manually ' .
			'correct the permissions.  See the documentation for more information.';
	}
	else if ($conf_perms != '666') {
		$msg = '<a style="color:#ff0000">Fatal Error!</a><br />' .
			'File permissions are incorrect.  Please run the installation script or manually ' .
			'correct the permissions.  See the documentation for more information.';
	}
	
	else {
		$msg = '<a href="install/install.php">Continue...</a>';
	}
	
	
	print <<<___eofh
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Cynus: Installation</title>
<link rel="stylesheet" type="text/css" href="themes/blue/style.css" />

</head>

<body>
<div class="logo-area">
<a href="/brett/devel/cynus/"><img src="themes/blue/images/crest_logo.png" class="logo" /></a>
Cynus Installation
</div>

<table cellspacing="0" cellpadding="0" class="table">
	<tr>
		<td class="table-top-left-corner">&nbsp;</td>
		<td class="table-top">&nbsp;</td>
		<td class="table-top-right-corner">&nbsp;</td>
	</tr>
	<tr>
		<td class="table-left">&nbsp;</td>
		<td class="table-content">
	Welcome to Cynus!<br /><br />

	This installation wizard will help you install and configure a base 
	Cynus system.  This process should take less than 10 minutes.
	<br /><br />
	
	Click below to continue installation.<br /><br />
	
	$msg
	<br /><br />

	Thank you for choosing Cynus!
			</div>
		</td>
		<td class="table-right">&nbsp;</td>
	</tr>
	<tr>
		<td class="table-bottom-left-corner">&nbsp;</td>
		<td class="table-bottom">&nbsp;</td>
		<td class="table-bottom-right-corner">&nbsp;</td>
	</tr>
</table>
</body>
</html>
___eofh;
	exit;
}

# performing some security checks.
# not running if the config dir is 777d
# note that this returns 0XXX...somehow..its magic.
#
#$decperms = @fileperms("./install/");
#$octalperms = @sprintf("%o",$decperms);
#$dir_perms=@(substr($octalperms,1));

#$conf_perms=@substr(base_convert(fileperms('./config.php'), 10, 8), 3);
#$decperms = @fileperms("./config.php");
#$octalperms = @sprintf("%o",$decperms);
#$conf_perms=@(substr($octalperms,1));

# did any one know that php's fileperms functions suck taint?

$install_perms = base_convert(@fileperms('./install/'), 10, 8);
$install_perms = substr($install_perms, (strlen($install_perms) - 3)); 

$conf_perms = base_convert(@fileperms('./config.php'), 10, 8);
$conf_perms = substr($conf_perms, (strlen($conf_perms) - 3)); 

$dir_perms = base_convert(@fileperms(getcwd()), 10, 8);
$dir_perms = substr($dir_perms, (strlen($dir_perms) - 3)); 

if ( (($install_perms=='777') || ($conf_perms=='666') || ($dir_perms=='777')) && IGNORE_PERMS!=1) {
	print <<<___eofh
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Cynus: Fatal Error</title>
<link rel="stylesheet" type="text/css" href="themes/blue/style.css" />

</head>

<body>
<div class="logo-area">
<a href="/brett/devel/cynus/"><img src="themes/blue/images/crest_logo.png" class="logo" /></a>
Cynus Error
</div>

<table cellspacing="0" cellpadding="0" class="table">
	<tr>
		<td class="table-top-left-corner">&nbsp;</td>
		<td class="table-top">&nbsp;</td>
		<td class="table-top-right-corner">&nbsp;</td>
	</tr>
	<tr>
		<td class="table-left">&nbsp;</td>
		<td class="table-content">
			<div class="cynus-error">
				<img src="themes/blue/images/cynus_error.png">
	<br />
	Your current configuration is very insecure, and because of
	securities risks, Cynus will not continue. <br /><br />

	To correct this security problem, please run the "secure.sh" script
	in the cynus root directory.<br /><br />

	You can also manually correct the permissions of the config directory
	by FTP.  Ftp to the server upon which Cynus is installed, and used the
	chmod command to change the permissions of the config directory to
	755 or 775.
			
			</div>
		</td>
		<td class="table-right">&nbsp;</td>
	</tr>
	<tr>
		<td class="table-bottom-left-corner">&nbsp;</td>
		<td class="table-bottom">&nbsp;</td>
		<td class="table-bottom-right-corner">&nbsp;</td>
	</tr>
</table>
</body>
</html>
___eofh;

	exit;
}


#we passed
cynus_debug ('Passed config file and permissions check.');

#creating the cache
$cache=array();

#files we need to load cynus!
require_once('config.php');
require_once('main_func.php');

#this is going to be moved...
if($_GET['style'] != '') {$config['style']= $_GET['style'];}
else{$config['style']= 'blue';}

#connect to the mysql server
$sql_con=@mysql_connect("$config[sql_server]", "$config[sql_user]", "$config[sql_pass]") or
	cynus_error('Could not connect to MySQL server, exitting.');
#select the right database
@mysql_select_db("$config[sql_db]", $sql_con) or 
	cynus_error('Could not select the MySQL database, exitting.');

#Load the config table
$query="SELECT * from `$config[sql_prefix]config`";
$result=mysql_query($query);
while($each_variable = mysql_fetch_assoc($result)) {
	$var_name=$each_variable['name'];
	if($each_variable['section']!='base' && $each_variable['section'] != 'view_only') {
		$section=$each_variable['section'];
		$mod_conf[$section][$var_name]=$each_variable['value'];
	}
	else{
		$config[$var_name] = $each_variable['value'];
	}
}
cynus_debug ('Loaded config from MySQL');

$time=time();
$config['this_month']=date('n', $time);
$config['this_day']=date('j', $time);
$config['this_year']=date('Y', $time);
$config['month_array']=	array(1 => 'January',2 => 'February',3 => 'March',4 => 'April',
				5 => 'May',6 => 'June',7 => 'July',8 => 'August',
				9 => 'September',10 => 'October',11 => 'November',12 => 'December');


cynus_debug ('Loaded config from load_cynus.php');


#So, now we can go ahead and require the right files for just the base. other 
#modules can include files they need when they're called. this should help
#speed up the parsing

#for login functions
require_once('login_func.php');
#for the menu functions
require_once('menu_func.php');
#for the messages functions
require_once('messages_func.php');
#signal functions
require_once('signal_func.php');
#for startup function goodness
require_once('startup_func.php');


#If we try to check the login while the user is trying to log in, 
#Bad Things happen...
if($_GET['action'] != 'login') {$user_config = check_login();}

#now we call startup() in case we needed something from the
#user's info...stuff...yeah
$startup_content=startup();


?>
Return current item: Cynus