<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#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
function test_cfg_var_bool( $name, $desc, $success, $row = 'row2' )
{
$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 have $str</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' )
{
$icon = 'red.gif';
$alt="Failure";
$ret = false;
if( is_int( $yellowlimit ) && is_int( $greenlimit ) )
{
$str = (int) ini_get( $name );
if( $str >= $greenlimit )
{
$alt = 'Success';
$icon = 'green.gif';
$ret = true;
}
else if( $str >= $yellowlimit )
{
$alt = 'Caution';
$icon = 'yellow.gif';
$ret = true;
}
}
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>$desc have \"$str\"";
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(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'fileloc.php');
$config = CONFIG_FILE_LOCATION;
if (!file_exists($config)) {
$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 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
$DONT_LOAD_DB = true;
if ($currentpage > 1) { 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 "<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, dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'modules', dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'uploads' );
// legend
echo "<table class=\"regtable\" border=\"1\">\n";
echo "<thead class=\"tbhead\"><tr><th>Symbol</th><th>Definition</th><tr></thead>\n";
echo "<tbody>\n";
echo '<tr><td><img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" /></td><td>A required test passed</td></tr>';
echo '<tr><td><img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" /></td><td>A required test failed</td></tr>';
echo '<tr><td><img src="../images/cms/install/red.gif" alt="Failure" height="16" width="16" border="0" /></td><td>A setting is below a required minumum value</td></tr>';
echo '<tr><td><img src="../images/cms/install/yellow.gif" alt="Caution" height="16" width="16" border="0" /></td><td>A setting is above the required value, but below the recommended value<br /><br />or... A capability that <em>may</em> be required for some optional functionality is unavailable</p></td></tr>';
echo '<tr><td><img src="../images/cms/install/green.gif" alt="Success" height="16" width="16" border="0" /></td><td>A setting meets or exceeds the recommended threshhold<br /><br />or... A capability that <em>may</em> be required for some optional functionality is available</td></tr>';
echo "</tbody>\n";
echo "</table><br/>\n";
// body
echo "<table class=\"regtable\" border=\"1\">\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 4.2+</td><td class=\"col2\">";
echo (@version_compare(phpversion(),"4.2.0") > -1?'<img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" />':'<img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" />');
(@version_compare(phpversion(),"4.2.0") > -1?null:$continueon=false);
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";
echo "<tr class=\"row2\"><td>Checking for tokenizer functions</td><td class=\"col2\">";
if (function_exists("token_get_all"))
{
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 = "row1";
$continueon &= test_cfg_var_range( "memory_limit", "Checking PHP memory limit (min 12M, recommend 16M)", "12M", "16M", $currow );
$currow = ($currow == 'row1') ? 'row2' : 'row1';
$continueon &= test_cfg_var_range( "max_input_time", "Checking max input time (min 45s, recommend 60s)", 45, 60, $currow );
$currow = ($currow == 'row1') ? 'row2' : 'row1';
$continueon &= test_cfg_var_range( "max_execution_time", "Checking max execution time (min 30s, recommend 45s)", 30, 45, $currow );
$currow = ($currow == 'row1') ? 'row2' : 'row1';
$continueon &= test_cfg_var_bool( "file_uploads", "Checking file uploads (require on)", 1, $currow );
$currow = ($currow == 'row1') ? 'row2' : 'row1';
$continueon &= test_cfg_var_range( "upload_max_filesize", "Checking max upload file size (min 2M)", "2M", "10M", $currow );
$currow = ($currow == 'row1') ? 'row2' : 'row1';
// do we have the file_get_contents function
echo "<tr class=\"$currow\"><td>Checking for file_get_contents<br/><br/>
<em>The file_get_contents function was added in PHP 4.3 and although a workaround has been added that should allow most functionality that uses this function to work properly in PHP 4.2, it may be advisable to upgrade to PHP 4.3 or greater.</em>
</td><td class=\"col2\">";
if (function_exists("file_get_contents"))
{
echo '<img src="../images/cms/install/green.gif" alt="Success" height="16" width="16" border="0" />';
}
else
{
echo '<img src="../images/cms/install/yellow.gif" alt="Caution" height="16" width="16" border="0" />';
}
echo "</td></tr>\n";
$currow = ($currow == 'row1') ? 'row2' : 'row1';
// can we set a php ini variable
echo "<tr class=\"$currow\"><td>Checking if ini_set works<br/><br/>
<em>Although the ability to override php ini settings is not mandatory, some addon (optional) functionality uses ini_set to extend timeouts, and allow uploading of larger files, etc. You may have difficulty with some addon functionality without this capability.</em>
</td><td class=\"col2\">";
ini_set( 'max_execution_time', '123' );
if( ini_get('max_execution_time') == 123 )
{
echo '<img src="../images/cms/install/green.gif" alt="Success" height="16" width="16" border="0" />';
}
else
{
echo '<img src="../images/cms/install/yellow.gif" alt="Caution" height="16" width="16" border="0" />';
}
echo "</td></tr>\n";
$currow = ($currow == 'row1') ? 'row2' : 'row1';
$special_failed=false;
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";
//special check for modules dir
if ($f == dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'modules' && !is_writable($f))
{
echo '<br /><br /><em>Modules is not writable. You can still install the system, but you will not be able to install modules via the admin panel.</em>';
$special_failed=true;
}
//special check for uploads dir
if ($f == dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'uploads' && !is_writable($f))
{
echo '<br /><br /><em>Uploads is not writable. You can still install the system, but you will not be able to upload files via the admin panel.</em>';
$special_failed=true;
}
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 {
//special check for modules dir
if (!(($f == dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'modules') || ($f == dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'uploads')))
{
$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=\"$currow\"><td>Checking if session.save_path is set and writable";
if (session_save_path() == '')
{
echo '<br /><br /><em>session.save_path is not set. Not having a session.save_path disallows any logins to the admin panel. Please adjust before continuing..</em>';
echo '</td><td class=\"col2\"><img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" />';
$continueon = false;
}
else
{
if (is_writable(session_save_path()))
{
echo '</td><td class="col2"><img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" />';
}
else
{
echo '<br /><br /><em>session.save_path("'.session_save_path().'") is not writable. Not having this as writable disallows any logins to the admin panel. Please adjust before continuing..</em>';
echo '</td><td class="col2"><img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" />';
$continueon = false;
}
}
echo "</td></tr>\n";
echo "</tbody></table>\n";
echo '<form method="post" action="install.php">';
if ($continueon)
{
if($special_failed) {
echo '<p class="failure" align="center">One or more tests have failed. You can still install the system but some functions may not work correctly. Please click the Continue button.</p>';
} else {
echo '<p class="success" align="center">All tests passed (at least at a minimum level). Please click the Continue button.</p>';
}
echo '<p class="continue" align="center"><input type="hidden" name="page" value="2" /><input class="defaultfocus" type="submit" value="Continue" /></p>';
}
else
{
echo '<p class="failure" align="center">One or more tests have failed. Please correct the problem and click the button below to recheck.</p>';
echo '<p class="continue" align="center"><input class="defaultfocus" type="Submit" value="Try Again" /></p>';
}
echo '</form>';
} ## showPageOne
function showPageTwo($errorMessage='',$username='',$email='')
{
if ($errorMessage != '')
{
echo "<p class=\"error\">$errorMessage</p>";
}
?>
<h3>Admin Account Information</h3>
<p>
Select the username, password and email address for your admin account. Please make sure you record this password somewhere, as
there will be no other way to login to your CMS Made Simple admin system without it.
</p>
<form action="install.php" method="post" name="page2form" id="page2form">
<table cellpadding="2" border="1" class="regtable">
<tr class="row1">
<td>Username</td>
<td><input class="defaultfocus" type="text" name="adminusername" value="<?php echo $username?>" size="20" maxlength="50" /></td>
</tr>
<tr class="row2">
<td>Email Address</td>
<td><input type="text" name="adminemail" value="<?php echo $email?>" size="20" maxlength="50" /></td>
</tr>
<tr class="row1">
<td>Password</td>
<td><input type="password" name="adminpassword" value="" size="20" maxlength="50" /></td>
</tr>
<tr class="row2">
<td>Password Again</td>
<td><input type="password" name="adminpasswordagain" value="" size="20" maxlength="50" /></td>