* @license http://opensource.org/licenses/gpl-license.php GNU General Public License * @copyright (c)2003 Tamlyn Rhodes * @version $Id: setup.php,v 1.8 2003/09/09 17:10:36 tamlyn Exp $ */ //require config class require_once "includes/config.class.php"; //create config object $config = new sgConfig(); function doSetdown() { $success = true; setupHeader("Removing directories"); if(is_writable($GLOBALS["config"]->pathto_data_dir)) { setupMessage("Data directory is writable"); if(file_exists($GLOBALS["config"]->pathto_cache)) if(is_writable($GLOBALS["config"]->pathto_cache)) if(rmdir_all($GLOBALS["config"]->pathto_cache)) setupMessage("Cache directory deleted"); else $success = setupError("Error deleting cache directory at ".$GLOBALS["config"]->pathto_cache); else $success = setupError("Cache is not writable so cannot delete it"); else setupMessage("Cache directory not found at ".$GLOBALS["config"]->pathto_cache); if(file_exists($GLOBALS["config"]->pathto_logs)) if(is_writable($GLOBALS["config"]->pathto_logs)) if(rmdir_all($GLOBALS["config"]->pathto_logs)) setupMessage("Logs directory deleted"); else $success = setupError("Error deleting logs directory at ".$GLOBALS["config"]->pathto_logs); else $success = setupError("Logs is not writable so cannot delete it"); else setupMessage("Logs directory not found at ".$GLOBALS["config"]->pathto_logs); } else $success = setupError("Data directory (".$GLOBALS["config"]->pathto_data_dir.") is not writable. Please CHMOD to 777"); return $success; } function doSetup() { $success = true; setupHeader("Creating directories"); if(is_writable($GLOBALS["config"]->pathto_data_dir)) { setupMessage("Data directory is writable"); if(file_exists($GLOBALS["config"]->pathto_cache)) if(is_writable($GLOBALS["config"]->pathto_cache)) setupMessage("Cache directory already exists at ".$GLOBALS["config"]->pathto_cache." and is writable"); else $success = setupError("Cache directory already exists at ".$GLOBALS["config"]->pathto_cache." but is not writable. Please CHMOD to 777"); else if(mkdir($GLOBALS["config"]->pathto_cache, 0755)) setupMessage("Created cache directory at ".$GLOBALS["config"]->pathto_cache); else $success = setupError("Could not create cache directory at ".$GLOBALS["config"]->pathto_cache); if($GLOBALS["config"]->track_views) if(file_exists($GLOBALS["config"]->pathto_logs)) if(is_writable($GLOBALS["config"]->pathto_logs)) setupMessage("Logs directory already exists at ".$GLOBALS["config"]->pathto_logs." and is writable"); else $success = setupError("Logs directory already exists at ".$GLOBALS["config"]->pathto_logs." but is not writable. Please CHMOD to 777"); else if(mkdir($GLOBALS["config"]->pathto_logs, 0755)) setupMessage("Created logs directory at ".$GLOBALS["config"]->pathto_logs); else $success = setupError("Could not create logs directory at ".$GLOBALS["config"]->pathto_logs); else setupMessage("View logging disabled. Logs directory not created"); } else $success = setupError("Data directory (".$GLOBALS["config"]->pathto_data_dir.") is not writable. Please CHMOD to 777"); return $success; } //output functions function setupHeader($var) { echo "\n
\n\n\n";
}
function setupMessage($var)
{
echo "{$var}.
\n";
return true;
}
function setupError($var)
{
echo "{$var}.
\n";
return false;
}
//this function recursively deletes all subdirectories and
//files in specified directory. USE WITH EXTREME CAUTION!!
function rmdir_all($wd)
{
if(!$dp = opendir($wd)) return false;
$success = true;
while(false !== ($entry = readdir($dp))) {
if($entry == "." || $entry == "..") continue;
if(is_dir("$wd/$entry")) $success &= rmdir_all("$wd/$entry");
else $success &= unlink("$wd/$entry");
}
closedir($dp);
$success &= rmdir($wd);
return $success;
}
?>
This script will try to remove directories and files created during setup."; if(doSetdown()) { setupHeader("OK"); setupMessage("All operations completed successfully."); } else { setupHeader("Oops"); setupError("There was a problem."); } } else { echo "
This script will try to setup singapore to run on your server."; if(doSetup()) { setupHeader("OK"); setupMessage("All operations completed successfully. Before proceeding you should delete this file to prevent anyone from deleting your cache and logs directories."); } else { setupHeader("Oops"); setupError("There was a problem. Please fix it and run this script again."); } } ?>