<?php
#CMS - CMS Made Simple
#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#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
//Where are we?
$dirname = dirname(__FILE__);
$DONT_LOAD_DB = true;
//All systems are go... let's include all the good stuff
require_once($dirname.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'include.php');
function return_bytes($val) {
$val = trim($val);
$last = strtolower($val{strlen($val)-1});
switch($last)
{
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
return $val;
}
function test_cfg_var_bool( $name, $desc, $success, $row = 'row2', $warning_message = '' )
{
$icon = 'false.gif';
$alt = 'Failure';
$ret = false;
$str = (bool) ini_get( $name );
$str = ($str) ? 1 : 0;
if( $success == $str )
{
$icon = 'true.gif';
$alt = 'Success';
$ret = true;
}
echo "<tr class=\"$row\"><td>$desc";
if ($warning_message != '' && $ret == false)
{
echo "<br/><br /><em>$warning_message</em>";
}
echo " </td><td class=\"col2\">";
echo "<img src=\"../images/cms/install/$icon\" alt=\"$alt\" height=\"16\" width=\"16\" border=\"0\" />";
echo "</td></tr>\n";
return $ret;
}
function test_cfg_var_range( $name, $desc, $yellowlimit, $greenlimit, $row = 'row2', $compare_as_bytes = FALSE, $warning_message = '' )
{
$icon = 'red.gif';
$alt="Failure";
$ret = false;
if (! is_int( $yellowlimit ) && ! is_int( $greenlimit ) && $compare_as_bytes == TRUE)
{
$yellowlimit_org = $yellowlimit;
$yellowlimit = return_bytes( $yellowlimit );
$greenlimit = return_bytes( $greenlimit );
}
if( is_int( $yellowlimit ) && is_int( $greenlimit ) )
{
if ($compare_as_bytes)
{
$str = ini_get( $name );
if ( $str == '' )
{
$warning = "Could not retrieve a value.... passing anyways";
$str = $yellowlimit;
$show_value = $yellowlimit_org;
}
else
{
$show_value = $str;
$str = return_bytes($str);
}
}
else
{
$str = (int) ini_get( $name );
}
if( $str < 0 )
{
$alt = 'Success (unlimited)';
$icon = 'green.gif';
$ret = true;
}
else if( $str >= $greenlimit )
{
$alt = 'Success';
$icon = 'green.gif';
$ret = true;
}
else if( $str >= $yellowlimit )
{
$alt = 'Caution';
$icon = 'yellow.gif';
$ret = true;
}
if ($compare_as_bytes)
{
$str = $show_value;
}
}
else
{
$warning = "";
$str = strtoupper(ini_get( $name ));
if( $str == "" )
{
$str = $yellowlimit;
$warning = "Could not retrieve a value.... passing anyways";
}
if( strcmp( $str, $yellowlimit ) >= 0 )
{
$alt = 'Caution';
$icon = 'yellow.gif';
$ret = true;
}
if( strcmp( $str, $greenlimit ) >= 0 )
{
$alt = 'Success';
$icon = 'green.gif';
$ret = true;
}
}
echo "<tr class=\"$row\"><td><span class=\"have\">You have \"$str\"</span>$desc";
if ($warning_message != '') {
$warning = '<br /><em>' . $warning_message . '</em>';
}
if( isset( $warning ) && $warning != "" )
{
echo "<br/>$warning";
}
echo "</td><td class=\"col2\">";
echo "<img src=\"../images/cms/install/$icon\" alt=\"$alt\" height=\"16\" width=\"16\" border=\"0\" />";
echo "</td></tr>\n";
return $ret;
}
$LOAD_ALL_MODULES=1;
require_once(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'fileloc.php');
$config = CONFIG_FILE_LOCATION;
if (!file_exists($config)) {
$file = @fopen($config, "w");
if ($file != 0) {
$cwd = dirname(dirname(__FILE__));
fwrite($file,"<?php\n".'$config[\'root_path\'] = "'.$cwd.'";'."\n?>\n");
fclose($file);
} else {
echo "Cannot create $config, please change permissions to allow this\n";
exit;
} ## if
} ## if
else if (filesize($config) == 0) {
$file = @fopen($config, "w");
if ($file != 0) {
$cwd = addslashes(dirname(dirname(__FILE__)));
fwrite($file,"<?php\n".'$config[\'root_path\'] = "'.$cwd.'";'."\n?>\n");
fclose($file);
} else {
echo "Cannot modify $config, please change permissions to allow this\n";
exit;
} ## if
}
$pages = 4;
if (isset($_POST["page"])) {
$currentpage = $_POST["page"];
} elseif (isset($_GET["page"])) {
$currentpage = $_GET["page"];
} else {
$currentpage = 1;
} ## if
// Test for sessions if this is the first page of the install
if (1 == $currentpage)
{
@session_start();
if (!isset($_GET['sessiontest']))
{
$_SESSION['test'] = TRUE;
$scheme = ((! isset($_SERVER['HTTPS'])) || strtolower($_SERVER['HTTPS']) != 'on') ? 'http' : 'https';
$redirect = $scheme . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?sessiontest=1&' . SID;
header("Location: $redirect");
}
}
$DONT_LOAD_DB = true;
// if ($currentpage > 4) { require_once(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."include.php"); }
?>
<!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" xml:lang="en" lang="en">
<head>
<title>CMS Made Simple Install</title>
<link rel="stylesheet" type="text/css" href="install.css" />
<script src="../admin/themes/default/includes/standard.js" type="text/javascript"></script>
</head>
<body>
<div class="body">
<img src="../images/cms/cmsbanner.jpg" width="800" height="100" alt="CMS Banner Logo" />
<div class="headerish">
<h1>Install System</h1>
</div>
<div class="main">
<?php
echo "<h2>Thanks for installing CMS Made Simple</h2>\n";
echo "<table class=\"countdown\" cellspacing=\"2\" cellpadding=\"2\"><tr>";
echo "<td><img src=\"../images/cms/install/".($currentpage==1?"1":"1off").".gif\" alt=\"Step 1\" /></td>";
echo "<td><img src=\"../images/cms/install/".($currentpage==2?"2":"2off").".gif\" alt=\"Step 2\" /></td>";
echo "<td><img src=\"../images/cms/install/".($currentpage==3?"3":"3off").".gif\" alt=\"Step 3\" /></td>";
echo "<td><img src=\"../images/cms/install/".($currentpage==4?"4":"4off").".gif\" alt=\"Step 4\" /></td>";
echo "<td><img src=\"../images/cms/install/".($currentpage==5?"5":"5off").".gif\" alt=\"Step 5\" /></td>";
echo "</tr></table>\n";
echo "<br />";
switch ($currentpage) {
case 1:
showPageOne();
break;
case 2:
showPageTwo();
break;
case 3:
showPageThree();
break;
case 4:
showPageFour();
break;
case 5:
showPageFive();
break;
default:
echo "You were supposed to turn <a href=\"install.php\">right</a> at Alberquerque.<p>\n";
break;
} ## switch
function showPageOne() {
## test file permissions
## apache (or other webserver) user needs to have write access to the cache and template_c dirs
## as well as the cms root for config.php to be created.
## find the user running this script
#$userid = posix_getuid();
#$userdata = posix_getpwuid($userid);
#$username = $userdata['name'];
## echo "Userid ($userid) is named $username is running this script<p>\n";
## check file perms
$continueon = true;
echo '<p class="important">Please read the <a href="http://wiki.cmsmadesimple.org/index.php/User_Handbook/Installation/Troubleshooting">Installation Troubleshooting</a> page in the CMS Made Simple Documentation Wiki.</p>';
echo "<h3>Checking permissions and PHP settings</h3>\n";
#$files = array(TMP_CACHE_LOCATION, TMP_TEMPLATES_C_LOCATION, dirname(dirname(__FILE__)).'/uploads', CONFIG_FILE_LOCATION);
$files = array(TMP_CACHE_LOCATION, TMP_TEMPLATES_C_LOCATION, CONFIG_FILE_LOCATION);
// body
echo "<table class=\"settings\" border=\"0\">\n";
echo "<caption class=\"tbcaption\">Required settings</caption>\n";
echo "<thead class=\"tbhead\"><tr><th>Test</th><th>Result</th></tr></thead><tbody>\n";
echo "<tr class=\"row1\"><td>Checking for PHP version 5+</td><td class=\"col2\">";
$version = explode('.', phpversion());
if ((int) $version[0] < 5) {
echo '<img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" />';
$continueon = false;
} else {
echo '<img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" />';
}
echo "</td></tr>\n";
echo "<tr class=\"row2\"><td>Checking for Session Functions</td><td class=\"col2\">";
if (function_exists("session_start"))
{
echo '<img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" />';
}
else
{
echo '<img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" />';
$continueon = false;
}
echo "</td></tr>\n";
echo "<tr class=\"row1\"><td>Checking for md5 Function</td><td class=\"col2\">";
if (function_exists("md5"))
{
echo '<img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" />';
}
else
{
echo '<img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" />';
$continueon = false;
}
echo "</td></tr>\n";
$currow = 'row2';
foreach ($files as $f) {
#echo "<tr><td>\n";
## check if we can write to the this file
echo "<tr class=\"$currow\"><td>Checking write permission on $f";
echo "</td><td class=\"col2\">";
if (is_writable($f))
{
echo '<img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" />';
}
else
{
$continueon=false;
echo '<img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" />';
} ## if
echo "</td></tr>\n";
($currow=="row1"?$currow="row2":$currow="row1");
} ## foreach
echo "<tr class=\"row1\"><td>Checking for basic XML (expat) support";
if( !function_exists( "xml_parser_create" ) )
{
echo '<br /><br /><em>XML support is not compiled into your php install. You can still use the system, but will not be able to use any of the remote module installation functions.</em>';
echo '</td><td class="col2"><img src="../images/cms/install/yellow.gif" alt="Caution" height="16" width="16" border="0" />';
$special_failed=true;
}
else
{
echo '</td><td class="col2"><img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" />';
}
echo "</td></tr>\n";
echo "</tbody></table>\n";
echo "<br /><br />\n";
// Checking for recommended settings
echo "<table class=\"settings\" border=\"0\">\n";
echo "<caption class=\"tbcaption\">Recommended settings</caption>\n";
echo "<thead class=\"tbhead\"><tr><th>Test</th><th>Result</th></tr></thead><tbody>\n";
($currow=="row1"?$currow="row2":$currow="row1");
if (!test_cfg_var_bool( "file_uploads", "Checking file uploads", 1, $currow, 'You will not be able to use any of the file uploading facilities included in CMS Made Simple. If possible, this restriction should be lifted by your system admin to properly use all file management features of the system. Proceed with caution.' ))
{
$special_failed=true;
}
$currow = ($currow == 'row1') ? 'row2' : 'row1';
if(!test_cfg_var_range( "memory_limit", "Checking PHP memory limit (min 8M, recommend 16M)", "8M", "16M", $currow, TRUE, 'You may not have enough memory to run CMSMS correctly. If possible, you should try to get your system admin to raise this value to the minimum 8M or great. Proceed with caution.'))
{
$special_failed=true;
}
$currow = ($currow == 'row1') ? 'row2' : 'row1';
if