<?php /* phpCache v1.4 - PHP caching engine Copyright (C) 2001 Nathan <*****@*****.**> 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. */ /* This script should be run periodically via a cron job or by hand. phpCache *WILL* try to clean up the cache on its own, but it does not do a full pass of the entire cache structure like this does. Running this once a day is recommended. */ set_time_limit(0); include "phpCache.inc"; $ret = cache_gc(); print "cache_gc(): {$ret}\n";
/** * Entry point for SimpleID. * * @see user_init() */ function simpleid_start() { global $xtpl, $GETPOST; $xtpl = new XTemplate('html/template.xtpl'); $xtpl->assign('version', SIMPLEID_VERSION); $xtpl->assign('base_path', get_base_path()); // Check if the configuration file has been defined if (!defined('SIMPLEID_BASE_URL')) { log_fatal('No configuration file found.'); indirect_fatal_error('No configuration file found. See the <a href="http://simpleid.koinic.net/documentation/getting-started">manual</a> for instructions on how to set up a configuration file.'); } if (!is_dir(SIMPLEID_IDENTITIES_DIR)) { log_fatal('Identities directory not found.'); indirect_fatal_error('Identities directory not found. See the <a href="http://simpleid.koinic.net/documentation/getting-started">manual</a> for instructions on how to set up SimpleID.'); } if (!is_dir(SIMPLEID_CACHE_DIR) || !is_writeable(SIMPLEID_CACHE_DIR)) { log_fatal('Cache directory not found or not writeable.'); indirect_fatal_error('Cache directory not found or not writeable. See the <a href="http://simpleid.koinic.net/documentation/getting-started">manual</a> for instructions on how to set up SimpleID.'); } if (!is_dir(SIMPLEID_STORE_DIR) || !is_writeable(SIMPLEID_STORE_DIR)) { log_fatal('Store directory not found or not writeable.'); indirect_fatal_error('Store directory not found or not writeable. See the <a href="http://simpleid.koinic.net/documentation/getting-started">manual</a> for instructions on how to set up SimpleID.'); } if (@ini_get('register_globals') === 1 || @ini_get('register_globals') === '1' || strtolower(@ini_get('register_globals')) == 'on') { log_fatal('register_globals is enabled in PHP configuration.'); indirect_fatal_error('register_globals is enabled in PHP configuration, which is not supported by SimpleID. See the <a href="http://simpleid.koinic.net/documentation/getting-started/system-requirements">manual</a> for further information.'); } if (!bignum_loaded()) { log_fatal('gmp/bcmath PHP extension not loaded.'); indirect_fatal_error('One or more required PHP extensions (gmp/bcmath) is not loaded. See the <a href="http://simpleid.koinic.net/documentation/getting-started/system-requirements">manual</a> for further information on system requirements.'); } if (!function_exists('preg_match')) { log_fatal('pcre PHP extension not loaded.'); indirect_fatal_error('One or more required PHP extensions (pcre) is not loaded. See the <a href="http://simpleid.koinic.net/documentation/getting-started/system-requirements">manual</a> for further information on system requirements.'); } if (!function_exists('session_start')) { log_fatal('session PHP extension not loaded.'); indirect_fatal_error('One or more required PHP extensions (session) is not loaded. See the <a href="http://simpleid.koinic.net/documentation/getting-started/system-requirements">manual</a> for further information on system requirements.'); } if (@ini_get('suhosin.get.max_value_length') !== false && @ini_get('suhosin.get.max_value_length') < 1024) { log_fatal('suhosin.get.max_value_length < 1024'); indirect_fatal_error('suhosin.get.max_value_length is less than 1024, which will lead to problems. See the <a href="http://simpleid.koinic.net/documentation/getting-started/system-requirements">manual</a> for further information on system requirements.'); } openid_fix_request(); $GETPOST = array_merge($_GET, $_POST); $q = isset($GETPOST['q']) ? $GETPOST['q'] : ''; extension_init(); user_init($q); log_info('Session opened for "' . $q . '" [' . $_SERVER['REMOTE_ADDR'] . ', ' . gethostbyaddr($_SERVER['REMOTE_ADDR']) . ']'); // Clean stale assocations cache_gc(SIMPLEID_ASSOC_EXPIRES_IN, 'association'); cache_gc(300, 'stateless'); simpleid_route($q); }
function cache_gc($dir = NULL, $start = 1, $purgeall = FALSE) { static $dirs = 0, $files = 0, $deleted = 0, $ignored = 0, $faileddelete = 0, $empty = 0; if ($start == 1) { cache_debug("Running GC on {$dir}"); if (!function_exists("getcwd")) { $cwd = substr(`pwd`, 0, -1); } else { $cwd = getcwd(); } $dirs = $files = $deleted = $ignored = $faileddelete = $empty = 0; } if (cache_iftype($dir, NULL)) { $dir = THIS_CACHE_DIR; } $dp = opendir($dir); if (!$dp) { cache_debug("Error opening {$dir} for cleanup"); return FALSE; } chdir($dir); $dirs++; while (!cache_iftype($de = readdir($dp), FALSE)) { if (is_dir($de)) { if ($de == '.' || $de == '..') { continue; } cache_gc($de, 0, $purgeall); chdir('..'); continue; } if (preg_match("/^phpCache./i", $de)) { $files++; $absfile = $de; $cachestuff = cache_read($absfile); $thecache = unserialize($cachestuff); if (is_array($thecache)) { if ($purgeall || $cdata["cachetime"] != "0" && $thecache["expire"] <= time()) { cache_lock($absfile, TRUE); if (@unlink($absfile)) { $deleted++; cache_debug("{$dir} Deleted {$absfile}"); } else { $faileddelete++; cache_debug("{$dir} Failed to delete {$absfile}"); } cache_lock($absfile, FALSE); } else { cache_debug("{$dir} {$absfile} expires in " . ($thecache["expire"] - time())); } } else { cache_debug("{$dir} {$absfile} is empty, being processed in another process?"); $empty++; } } else { $ignored++; } } closedir($dp); if ($start == 1) { $str = "{$dir} GC Processed: {$dirs}/dirs\t{$files}/files\t{$deleted}/deleted\t{$ignored}/ignored\t{$faileddelete}/faileddelete\t{$empty}/empty"; cache_debug($str); chdir($cwd); return $str; } }
$errors[] = '<strong>' . $content_dir . '/theme</strong> directory is not writable.'; } } //////////////////////// echo '<br />'; if (isset($progress)) { print_feedback($progress); } if (isset($errors)) { print_errors($errors); } if ($_POST['step1']['cache_dir'] != '') { define('CACHE_DIR', urldecode($_POST['step1']['cache_dir'])); define('CACHE_ON', 1); require '../include/phpCache/phpCache.inc.php'; cache_gc(NULL, 1, true); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?> " method="post" name="form"> <input type="hidden" name="step" value="<?php echo $step; ?> " /> <?php print_hidden($step); ?> <br /><br /><p align="center"><input type="submit" class="button" value=" Next »" name="submit" /></p>
/** * Applies the upgrade. */ function upgrade_apply() { global $xtpl, $upgrade_access_check; if (!validate_form_token($_POST['tk'], 'upgrade_selection')) { set_message('SimpleID detected a potential security attack. Please try again.'); upgrade_selection(); return; } $results = ''; $functions = cache_get('upgrade', $_POST['handle']); foreach ($functions as $function) { $results .= call_user_func($function); } if (!$upgrade_access_check) { $xtpl->parse('main.upgrade_results.upgrade_access_check'); } $xtpl->assign('results', $results); $xtpl->parse('main.upgrade_results'); cache_gc(0, 'upgrade'); $xtpl->assign('title', 'Upgrade'); $xtpl->parse('main'); $xtpl->out('main'); }