*
* Last Modified: 17th March 2003
*
*/
error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_magic_quotes_runtime(0);
// Check if the lock file exist, i.e. the user has completed installing the script but never deleted the installer
if (file_exists("install.lock"))
{
die("You cannot run the installer whilst the lock file "install.lock" exists");
}
// Check the PHP Version
if (phpversion() < "4.0.4")
{
die("Sorry but Invision Power File Manager requires at least PHP 4.0.4 in order to run");
}
// A function to return the correct variable
function param($name, $method)
{
// Use ternary, check if the method exists in the super global area, ie _METHOD
// If so return the value from that array, otherwise use the GLOBALS array
// along with the HTTP_METHOD_VARS index to return the correct value
return @isset($_{$method}) ? $_{$method}[$name] : $GLOBALS["HTTP_{$method}_VARS"][$name];
}
// A function to build the templates drop down list
function dropdown($items, $selected = 0)
{
$list = "";
foreach ($items as $key => $var)
{
if ($key == $selected)
{
// IE uses selected, Mozilla uses checked
$list .= "";
}
else
{
$list .= "";
}
}
return $list;
}
// Cleans CRLF data to match the platform
function clean_crlf($data)
{
$server = param("SERVER_SOFTWARE", "SERVER");
// If windows isn't being used, or apache is being used, remove the \r
if (eregi("win", PHP_OS) == FALSE || eregi("apache", $server) == TRUE)
{
$data = str_replace("\r\n", "\n", $data);
}
return $data;
}
// A function to display the HTML code
function msg($msg, $title = "User Error")
{
$data = "\r\n";
$data .= "
\r\n";
$data .= "\r\n";
$data .= "\r\n";
echo $data;
}
// Get the request variables
$step = param("step", "GET");
if (empty($step) == TRUE)
{
$step = param("step", "POST");
}
$PHP_SELF = param("PHP_SELF", "SERVER");
switch ($step)
{
case 1:
/* -----------------------------------------
Test the system settings
----------------------------------------- */
// Test the PHP version
if (phpversion() >= "4.1.0")
{
$version_result = "Passed";
$version_note = "None";
}
else
{
$version_result = "Failed";
$version_note = "Although File Manager should run on your system, it has not undergone heavy testing on this build of PHP";
}
// Test that ZLIB is loaded
if (extension_loaded("zlib") == 1 || ini_get("zlib.output_compression") == TRUE)
{
$zlib = "Loaded";
$zlib_result = "Passed";
$zlib_note = "None";
}
else
{
$zlib = "Not Loaded";
$zlib_result = "Failed";
$zlib_note = "Although the ZLIB (Compression) module is not required for File Manager to operate, it is used to create zip files & to GZIP the HTML output. If you run File Manager without ZLIB loaded you will not be able to create zip archives and the output will not be sent to your browser in compressed format";
}
// Test that GD is loaded
if (extension_loaded("gd") == 1)
{
$gd = "Loaded";
$gd_result = "Passed";
$gd_note = "None";
}
else
{
$gd = "Not Loaded";
$gd_result = "Failed";
$gd_note = "Although the GD (Image Creation) module is not required for File Manager to operate, it is used to generate a pie chart showing the space usage. If you run File Manager without GD loaded you will not be able to see this pie chart, just text based figures";
}
// Test that safe mode is disabled
if (get_cfg_var("safe_mode") == 1)
{
$mode = "Enabled";
$mode_result = "Failed";
$mode_note = "Safe Mode is known to cause problems with File Managements Scripts due to the restrictions it places on file access.
You should request that your webhost disables safe mode because File Manager can not run with safe mode enabled.
Some times this setting is detected incorrectly, if you are sure it is disabled then you may continue installation.";
}
else
{
$mode = "Disabled";
$mode_result = "Passed";
$mode_note = "None";
}
// Test that file uploads are allowed
if (get_cfg_var("file_uploads") == 1)
{
$upload = "Enabled";
$upload_result = "Passed";
$upload_note = "None";
}
else
{
$upload = "Disabled";
$upload_result = "Failed";
$upload_note = "Although you will be able to edit files which already exist on the file system, as well as create new files using File Managers built in text editor, you will not be able to upload files from your computer.
You should request that your webhost re-enable file uploads";
}
$data .= "
\r\n";
$data .= "
\r\n";
$data .= "
\r\n";
$data .= "
Recommended
\r\n";
$data .= "
Actual
\r\n";
$data .= "
Status
\r\n";
$data .= "
Notes
\r\n";
$data .= "
\r\n";
$data .= "
\r\n";
$data .= "
PHP Version:
\r\n";
$data .= "
4.1.0 or above
\r\n";
$data .= "
" . phpversion() . "
\r\n";
$data .= "
" . $version_result . "
\r\n";
$data .= "
" . $version_note . "
\r\n";
$data .= "
\r\n";
$data .= "
\r\n";
$data .= "
ZLIB Extension:
\r\n";
$data .= "
Loaded
\r\n";
$data .= "
" . $zlib . "
\r\n";
$data .= "
" . $zlib_result . "
\r\n";
$data .= "
" . $zlib_note . "
\r\n";
$data .= "
\r\n";
$data .= "
\r\n";
$data .= "
GD Extension:
\r\n";
$data .= "
Loaded
\r\n";
$data .= "
" . $gd . "
\r\n";
$data .= "
" . $gd_result . "
\r\n";
$data .= "
" . $gd_note . "
\r\n";
$data .= "
\r\n";
$data .= "
\r\n";
$data .= "
"Safe Mode" Status:
\r\n";
$data .= "
Disabled
\r\n";
$data .= "
" . $mode . "
\r\n";
$data .= "
" . $mode_result . "
\r\n";
$data .= "
" . $mode_note . "
\r\n";
$data .= "
\r\n";
$data .= "
\r\n";
$data .= "
File Uploads:
\r\n";
$data .= "
Enabled
\r\n";
$data .= "
" . $upload . "
\r\n";
$data .= "
" . $upload_result . "
\r\n";
$data .= "
" . $upload_note . "
\r\n";
$data .= "
\r\n";
$data .= "
\r\n";
$data .= " \r\n";
echo msg($data, "Checking System Requirements");
break;
case 2:
/* -----------------------------------------
Test for file permissions
----------------------------------------- */
// Create a list of the files to check and give them a default permission
$file = array("languages/en-gb.lng.php" => FALSE,
"settings/users.cgi" => FALSE,
"settings/languages.inc.php" => FALSE,
"settings/settings.inc.php" => FALSE,
"settings/templates.inc.php" => FALSE,
"settings/templates/styles.css" => FALSE,
"settings/templates/admin.tpl" => FALSE,
"settings/templates/chmod.tpl" => FALSE,
"settings/templates/edit.tpl" => FALSE,
"settings/templates/global.tpl" => FALSE,
"settings/templates/index.tpl" => FALSE,
"settings/templates/lock.tpl" => FALSE,
"settings/templates/login.tpl" => FALSE,
"settings/templates/move.tpl" => FALSE,
"settings/templates/mysql.tpl" => FALSE,
"settings/templates/mysql_err.tpl" => FALSE,
"settings/templates/pwd.tpl" => FALSE,
"settings/templates/result.tpl" => FALSE,
"settings/templates/source.tpl" => FALSE,
"settings/templates/space.tpl" => FALSE,
"settings/templates/upload.tpl" => FALSE,
"settings/templates/javascript/chmod.js" => FALSE,
"settings/templates/javascript/edit.js" => FALSE,
"settings/templates/javascript/index.js" => FALSE,
"settings/templates/javascript/lock.js" => FALSE,
"settings/templates/javascript/move.js" => FALSE,
"settings/templates/javascript/pwd.js" => FALSE
);
// Check each file
foreach ($file as $key => $var)
{
if (is_readable($key) == FALSE)
{
$read_error = $key;
break;
}
else if(is_writeable($key) == FALSE)
{
$write_error = $key;
break;
}
else
{
$files[$key] = TRUE;
}
}
// See if any of the file permissions are not set correctly
if (isset($read_error) == TRUE)
{
// Display the read error message
echo msg("Sorry but the file " . $read_error . " is not readable", "File Permissions Error");
}
else if (isset($write_error) == TRUE)
{
// Display the write error message
echo msg("Sorry but the file " . $write_error . " is not writeable", "File Permissions Error");
}
else
{
// Display the success message
echo msg("Your file permissions have been checked and are correct ", "File Permission Correct");
}
break;
case 3:
/* -----------------------------------------
Show the configuration form
----------------------------------------- */
$gzip = 0;
if (extension_loaded("zlib") == 1 || ini_get("zlib.output_compression") == TRUE)
{
$gzip = 1;
}
$flock_list = dropdown(array("1" => "Lock Files", "0" => "Don't Lock Files"), 1);
$gzip_list = dropdown(array("1" => "Use GZIP Compression", "0" => "Do not use GZIP compression"), $gzip);
$http_list = dropdown(array("1" => "Output HTTP Headers", "0" => "Do not output HTTP headers"), 1);
$data .= " \r\n";
echo msg($data, "Configure the system");
break;
case 4:
/* -----------------------------------------
Update the configuration
----------------------------------------- */
// Get the form variables
$script_dir = param("script_dir", "POST");
$script_url = param("script_url", "POST");
$flock = param("flock", "POST");
$gzip = param("gzip", "POST");
$http = param("http", "POST");
$adminpass = param("adminpass", "POST");
$checkpass = param("checkpass", "POST");
// Find out the correct values
$flock = $flock == 1 ? 'TRUE' : 'FALSE';
$gzip = $gzip == 1 ? 'TRUE' : 'FALSE';
$http = $http == 1 ? 'TRUE' : 'FALSE';
if (empty($script_dir) == TRUE)
{
// The script directory value was left blank
echo msg("Sorry but you need to enter a value for the script directory « Please go back and enter a value");
}
else if (file_exists($script_dir . "/modules/common.lib.php") == FALSE)
{
// The script directory does not exist
echo msg("Sorry but the value for the script directory is not valid « Please go back and enter a valid path");
}
else if (empty($script_url) == TRUE)
{
// The script URL was left blank
echo msg("Sorry but you need to enter a value for the script URL « Please go back and enter a value");
}
else if (empty($adminpass) == TRUE || strlen($adminpass) < 5)
{
// The password was left blank or was too small
echo msg("Sorry but the admin password is too short, it needs to be a minimum of 5 characters « Please go back and type a new password");
}
else if ($adminpass != $checkpass)
{
// The passwords do not match
echo msg("Sorry but the passwords do not match « Please go back and retype the passwords");
}
else
{
// Strip slashes if needed
$safe = eregi("win", PHP_OS) == TRUE ? "\\" : "/";
if (get_magic_quotes_gpc() == TRUE)
{
$script_dir = stripslashes($script_dir);
}
$script_dir = ereg_replace("[" . $safe . "]$", "", $script_dir); // Remove the trailing slash
$adminpass = md5($adminpass);
$script_dir = str_replace("\\t", "/t", $script_dir);
$script_dir = str_replace("\\r", "/r", $script_dir);
$script_dir = str_replace("\\n", "/n", $script_dir);
$script_dir = str_replace("/R", "\\R", $script_dir);
$script_dir = str_replace("/N", "\\N", $script_dir);
$script_dir = str_replace("/T", "\\T", $script_dir);
// Build up the new settings file
$fdata = "\r\n";
$fdata .= " *\r\n";
$fdata .= " */\r\n\r\n";
$fdata .= "// Misc Settings\r\n";
$fdata .= "\$script_dir = \"" . $script_dir . "\"; // The directory the script is in\r\n";
$fdata .= "\$script_url = \"" . $script_url . "\"; // The URL to the script\r\n";
$fdata .= "\$cookie_admin = \"fm_admin\"; // The name of the admin cookie\r\n";
$fdata .= "\$cookie_user = \"fm_username\"; // The name for the username cookie\r\n";
$fdata .= "\$cookie_pass = \"fm_password\"; // The name for the password cookie\r\n";
$fdata .= "\$cookie_lang = \"fm_language\"; // The name for the language cookie\r\n";
$fdata .= "\$cookie_temp = \"htpass\"; // The name for the temporary htpasswd cookie\r\n";
$fdata .= "\$cookie_time = \"\"; // The length of time to store the cookies (leave blank for deletion upon browser closure)\r\n";
$fdata .= "\$default_lang = 1; // The default language to use\r\n";
$fdata .= "\$debug = FALSE; // Enable Debug mode (to report errors)\r\n";
$fdata .= "\$format = \"M j, Y {\\A\\\\T} g:i a\"; // The format to use for the file dates\r\n";
$fdata .= "\$hide = \".hide\"; // The name of the file used to prevent directory access\r\n";
$fdata .= "\$note = \".note\"; // The name of the file used for directory notes\r\n";
$fdata .= "\$hide_dot = TRUE; // Hide files beginning with a . dot\r\n";
$fdata .= "\$flock = " . $flock . "; // Flock files\r\n";
$fdata .= "\$upload_limit = 5; // Number of file browsers to show on multi file upload page\r\n";
$fdata .= "\$no_ext = TRUE; // Display edit for files with no extension\r\n";
$fdata .= "\$edit_lock = FALSE; // Lock files which are being edited\r\n";
$fdata .= "\$timeout = 300; // Number of seconds to keep files locked for\r\n";
$fdata .= "\$use_gzip = " . $gzip . "; // USE GZIP compression\r\n";
$fdata .= "\$http_headers = " . $http . "; // Output HTTP headers\r\n";
$fdata .= "\$anon_access = FALSE; // Anonymous access\r\n";
$fdata .= "\$new_chmod = \"755\"; // CHMOD value for new files\r\n";
$fdata .= "\$adminpass = \"" . $adminpass . "\"; // The admin password\r\n\r\n";
$fdata .= "// The file extensions and images to use for the icons\r\n";
$fdata .= "\$icons = array(\r\n";
$fdata .= " \"image.gif\" => \"bmp gif jpeg jpg png\",\r\n";
$fdata .= " \"text.gif\" => \"dat ini lib log m3u note pls tpl txt\",\r\n";
$fdata .= " \"script.gif\" => \"bat cgi js php php3 php4 phps phtml pl pm sh\",\r\n";
$fdata .= " \"zip.gif\" => \"ace gz rar tar zip\",\r\n";
$fdata .= " \"html.gif\" => \"css dtd htm html shtm shtml wml xml xsl\",\r\n";
$fdata .= " \"sound.gif\" => \"au mid mod mp3 wav\",\r\n";
$fdata .= " \"movie.gif\" => \"mov mpeg mpg rm\",\r\n";
$fdata .= " \"pdf.gif\" => \"pdf\",\r\n";
$fdata .= " \"database.gif\" => \"db mdb sql\",\r\n";
$fdata .= " \"binary.gif\" => \"com dll exe sys\"\r\n";
$fdata .= ");\r\n\r\n";
$fdata .= "// An array of extensions to ASCII files so that the script knows what can be edited\r\n";
$fdata .= "\$ascii = array(\"asp\", \"bat\", \"cfm\", \"cgi\", \"conf\", \"css\", \"dat\", \"diz\", \"dtd\", \"htm\", \"html\", \"inc\", \"inf\", \"ini\", \"js\", \"lib\", \"log\", \"mrc\", \"nfo\", \"php\", \"php3\", \"php4\", \"phps\", \"phtml\", \"pl\", \"reg\", \"sh\", \"shtm\", \"shtml\", \"sql\", \"tpl\", \"txt\", \"wml\", \"xml\", \"xsl\");\r\n\r\n";
$fdata .= "// An array of the script names (so that the scripts can be renamed)\r\n";
$fdata .= "\$scripts[\"login\"] = \"login.php\";\r\n";
$fdata .= "\$scripts[\"main\"] = \"index.php\";\r\n";
$fdata .= "\$scripts[\"edit\"] = \"edit.php\";\r\n";
$fdata .= "\$scripts[\"source\"] = \"source.php\";\r\n";
$fdata .= "\$scripts[\"space\"] = \"space.php\";\r\n";
$fdata .= "\$scripts[\"pass\"] = \"pwd.php\";\r\n";
$fdata .= "\$scripts[\"sql\"] = \"sql.php\";\r\n";
$fdata .= "\$scripts[\"chmod\"] = \"chmod.php\";\r\n";
$fdata .= "\$scripts[\"move\"] = \"move.php\";\r\n";
$fdata .= "\$scripts[\"lock\"] = \"lock.php\";\r\n";
$fdata .= "\$scripts[\"upload\"] = \"upload.php\";\r\n";
$fdata .= "\$scripts[\"userlist\"] = \"users.cgi\";\r\n\r\n";
$fdata .= "// The scripts visual settings\r\n";
$fdata .= "\$free_colour = array(\"70\", \"130\", \"180\"); // The colours to use for the free space on the pie chart\r\n";
$fdata .= "\$used_colour = array(\"255\", \"255\", \"255\"); // The colours to use for the used space on the pie chart\r\n\r\n";
$fdata .= "\$license = 0; // The license status\r\n\r\n";
$fdata .= "?" . ">";
if (($fp = fopen($script_dir . "/settings/settings.inc.php", "w")) == FALSE)
{
// The settings file could not be opened
echo msg("There was an error saving the configuration, please ensure that the /settings/settings.inc.php file exists in the script directory, and that it is writable « Go back and try again", "System Error");
}
else
{
$fdata = clean_crlf($fdata);
// The settings file was updated, display the success message
fwrite($fp, $fdata);
fclose($fp);
echo msg("Your settings were saved successfully ", "Script configuration");
}
}
break;
case 5:
/* -----------------------------------------
Show the final screen
----------------------------------------- */
include("./settings/settings.inc.php");
// Create the lock file
$fp = fopen("./install.lock", "w");
fwrite($fp, "locked!");
fclose($fp);
echo msg("Congratulations, Invision Power File Manager was successfully installed.
You should now delete the install.php file, otherwise people will be able to compromise your system, you should also delete install.lock if it exists
Once you have done that you can proceed to the Control Panel, where you will be able to further customise your system, as well as start adding users", "Installation complete");
break;
default:
/* -----------------------------------------
Show the welcome screen
----------------------------------------- */
$slash = eregi("win", PHP_OS) ? "\\" : "/";
$cwd = getcwd() . $slash;
echo msg("This program will guide you through the installation of Invision Power File Manager, and the configuration of any needed settings
Please ensure that the current directory, $cwd, is CHMOD to a suitable value for example 0755, but you may also wish to try 0777) before you begin. Also please ensure that you have read though the Install Guide included in the File Manager download", "Welcome to the Invision Power File Manager Installer");
break;
}
?>