Browse Source

improve config handling

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@902 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.0
Xuefer 10 years ago
parent
commit
8f609d4f2f
  1. 1
      ChangeLog
  2. 1
      NEWS
  3. 2
      admin/common-en.lang.php
  4. 40
      admin/common.php
  5. 48
      admin/config.default.php
  6. 4
      admin/edit.php
  7. 6
      admin/header.tpl.php
  8. 6
      admin/help.php
  9. 10
      admin/xcache.php
  10. 18
      admin/xcache.tpl.php

1
ChangeLog

@ -2,6 +2,7 @@
ChangeLog
========
* fixed #279: segv when cache is full (since 2.0)
* admin/ config changed. please update accordingly
2.0.0 2012-04-20
Ini Settings Changes

1
NEWS

@ -1,6 +1,7 @@
2.0.1 2012-??-??
========
* improve stability
* admin/ config changed. please update accordingly
2.0.0 2012-04-20
========

2
admin/common-en.lang.php

@ -1,5 +1,5 @@
<?php
$GLOBALS['show_todo_strings'] = false;
$GLOBALS['config']['show_todo_strings'] = false;
?>

40
admin/common.php

@ -40,10 +40,10 @@ function get_language_file_ex($name, $l, $s)
function get_language_file($name)
{
global $charset, $lang;
$s = strtolower($charset);
if (isset($lang)) {
$l = strtolower($lang);
global $config;
$s = strtolower($config['charset']);
if (!empty($config['lang'])) {
$l = strtolower($config['lang']);
$file = get_language_file_ex($name, $l, $s);
if (!isset($file)) {
$l = strtok($l, ':-');
@ -55,14 +55,14 @@ function get_language_file($name)
$l = strtok($l, ':;');
$file = get_language_file_ex($name, $l, $s);
if (isset($file)) {
$lang = $l;
$config['lang'] = $l;
break;
}
if (strpos($l, '-') !== false) {
$ll = strtok($l, ':-');
$file = get_language_file_ex($name, $ll, $s);
if (isset($file)) {
$lang = $l;
$config['lang'] = $l;
break;
}
}
@ -76,7 +76,7 @@ function _T($str)
if (isset($GLOBALS['strings'][$str])) {
return $GLOBALS['strings'][$str];
}
if (!empty($GLOBALS['show_todo_strings'])) {
if (!empty($GLOBALS['config']['show_todo_strings'])) {
return '<span style="color:red">' . htmlspecialchars($str) . '</span>';
}
return $str;
@ -95,6 +95,20 @@ function stripaddslashes_array($value, $mqs = false)
return $value;
}
function ob_filter_path_nicer_default($list_html)
{
$sep = DIRECTORY_SEPARATOR;
$docRoot = $_SERVER['DOCUMENT_ROOT'];
$list_html = str_replace($docRoot, "{DOCROOT}" . (substr($docRoot, -1) == $sep ? $sep : ""), $list_html);
$xcachedir = realpath(dirname(__FILE__) . "$sep..$sep");
$list_html = str_replace($xcachedir . $sep, "{XCache}$sep", $list_html);
if ($sep == '/') {
$list_html = str_replace("/home/", "{H}/", $list_html);
}
return $list_html;
}
error_reporting(E_ALL);
ini_set('display_errors', 'On');
define('REQUEST_TIME', time());
@ -104,21 +118,19 @@ if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc()) {
$_GET = stripaddslashes_array($_GET, $mqs);
$_POST = stripaddslashes_array($_POST, $mqs);
$_REQUEST = stripaddslashes_array($_REQUEST, $mqs);
unset($mqs);
}
ini_set('magic_quotes_runtime', '0');
$charset = "UTF-8";
$config = array();
include("./config.default.php");
if (file_exists("./config.php")) {
include("./config.php");
}
include(get_language_file("common"));
if (!isset($lang)) {
$lang = 'en-us';
}
if (!isset($usage_graph_width) && !isset($free_graph_width)) {
$usage_graph_width = 120;
if (empty($config['lang'])) {
$config['lang'] = 'en-us';
}
$graph_width = isset($free_graph_width) ? $free_graph_width : $usage_graph_width;
?>

48
admin/config.php.example → admin/config.default.php

@ -1,44 +1,41 @@
<?php
// this is an example only
// write your own config and name it as config.php
// this is default config, DO NOT modify this file
// copy this file and write your own config and name it as config.php
// detected by browser
// $lang = 'en-us';
// $config['lang'] = 'en-us';
$charset = "UTF-8";
$config['charset'] = "UTF-8";
// developers only
$show_todo_strings = false;
// translators only
$config['show_todo_strings'] = false;
// width of graph for free or usage blocks
$usage_graph_width = 120;
// do not define both with
// $free_graph_width = 120;
$config['percent_graph_width'] = 120;
$config['percent_graph_type'] = 'used'; // either 'used' or 'free'
// only enable if you have password protection for admin page
// enabling this option will cause user to eval() whatever code they want
$enable_eval = false;
$config['enable_eval'] = false;
// this function is detected by xcache.tpl.php, and enabled if function_exists
// this ob filter is applied for the cache list, not the whole page
function ob_filter_path_nicer($o)
$config['path_nicer'] = 'ob_filter_path_nicer_default';
/*
function custom_ob_filter_path_nicer($list_html)
{
$sep = DIRECTORY_SEPARATOR;
$d = $_SERVER['DOCUMENT_ROOT'];
$o = str_replace($d, "{DOCROOT}" . (substr($d, -1) == $sep ? $sep : ""), $o);
$xcachedir = realpath(dirname(__FILE__) . "$sep..$sep");
$o = str_replace($xcachedir . $sep, "{XCache}$sep", $o);
if ($sep == '/') {
$o = str_replace("/home/", "{H}/", $o);
}
return $o;
$list_html = ob_filter_path_nicer_default($list_html); // this function is from common.php
return $list_html;
}
$config['path_nicer'] = 'custom_ob_filter_path_nicer';
*/
// you can simply let xcache to do the http auth
// but if you have your home made login/permission system, you can implement the following
// {{{ home made login example
// this is an example only, it's won't work for you without your implemention.
/*
function check_admin_and_by_pass_xcache_http_auth()
{
require("/path/to/user-login-and-permission-lib.php");
@ -62,8 +59,13 @@ function check_admin_and_by_pass_xcache_http_auth()
return true;
}
// uncomment:
// check_admin_and_by_pass_xcache_http_auth();
check_admin_and_by_pass_xcache_http_auth();
*/
// }}}
/* by pass XCache http auth
$_SERVER["PHP_AUTH_USER"] = "moo";
$_SERVER["PHP_AUTH_PW"] = "your-xcache-password";
*/
?>

4
admin/edit.php

@ -11,7 +11,7 @@ $name = $_GET['name'];
$vcnt = xcache_count(XC_TYPE_VAR);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($enable_eval) {
if (!empty($config['enable_eval'])) {
eval('$value = ' . $_POST['value']);
}
else {
@ -22,7 +22,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
exit;
}
$value = xcache_get($name);
if ($enable_eval) {
if (!empty($enable['enable_eval'])) {
$value = var_export($value, true);
$editable = true;
}

6
admin/header.tpl.php

@ -3,9 +3,9 @@
<head>
<?php
echo <<<HEAD
<meta http-equiv="Content-Type" content="text/html; charset=$charset" />
<meta http-equiv="Content-Language" content="$lang" />
<script type="text/javascript" src="tablesort.js" charset="$charset"></script>
<meta http-equiv="Content-Type" content="text/html; charset=$config[charset]" />
<meta http-equiv="Content-Language" content="$config[lang]" />
<script type="text/javascript" src="tablesort.js" charset="$config[charset]"></script>
HEAD;
?>

6
admin/help.php

@ -6,9 +6,9 @@ include("./common.php");
<head>
<?php
echo <<<HEAD
<meta http-equiv="Content-Type" content="text/html; charset=$charset" />
<meta http-equiv="Content-Language" content="$lang" />
<script type="text/javascript" src="tablesort.js" charset="$charset"></script>
<meta http-equiv="Content-Type" content="text/html; charset=$config[charset]" />
<meta http-equiv="Content-Language" content="$config[lang]" />
<script type="text/javascript" src="tablesort.js" charset="$config[charset]"></script>
HEAD;
?>

10
admin/xcache.php

@ -76,17 +76,17 @@ function age($time)
function freeblock_to_graph($freeblocks, $size)
{
global $graph_width, $usage_graph_width, $free_graph_width;
global $config;
// cached in static variable
static $graph_initial;
if (!isset($graph_initial)) {
$graph_initial = array_fill(0, $graph_width, 0);
$graph_initial = array_fill(0, $config['percent_graph_width'], 0);
}
$graph = $graph_initial;
foreach ($freeblocks as $b) {
$begin = $b['offset'] / $size * $graph_width;
$end = ($b['offset'] + $b['size']) / $size * $graph_width;
$begin = $b['offset'] / $size * $config['percent_graph_width'];
$end = ($b['offset'] + $b['size']) / $size * $config['percent_graph_width'];
if ((int) $begin == (int) $end) {
$v = $end - $begin;
@ -103,7 +103,7 @@ function freeblock_to_graph($freeblocks, $size)
$html = array();
$c = 255;
foreach ($graph as $k => $v) {
if (!isset($free_graph_width)) {
if ($config['percent_graph_type'] != 'free') {
$v = 1 - $v;
}
$v = (int) ($v * $c);

18
admin/xcache.tpl.php

@ -32,7 +32,7 @@ $b = new Cycle('class="col1"', 'class="col2"');
<th><?php echo _T('Slots'); ?></th>
<th><?php echo _T('Size'); ?></th>
<th><?php echo _T('Avail'); ?></th>
<th><?php echo _T(isset($free_graph_width) ? '% Free' : '% Used'); ?></th>
<th><?php echo _T($config['percent_graph_type'] == 'free' ? '% Free' : '% Used'); ?></th>
<th><?php echo _T('Clear'); ?></th>
<th><?php echo _T('Compiling'); ?></th>
<th><?php echo _T('Hits'); ?></th>
@ -57,14 +57,14 @@ $b = new Cycle('class="col1"', 'class="col2"');
<tr ", $a->next(), ">";
$pvalue = (int) ($ci['avail'] / $ci['size'] * 100);
$pempty = 100 - $pvalue;
if (!isset($free_graph_width)) {
if ($config['percent_graph_type'] == 'used') {
// swap
$tmp = $pvalue;
$pvalue = $pempty;
$pempty = $tmp;
}
$w = $graph_width;
$w = $config['percent_graph_width'];
if (empty($ci['istotal'])) {
$graph = freeblock_to_graph($ci['free_blocks'], $ci['size']);
$blocksgraph = "<div class=\"blocksgraph\" style=\"width: {$w}px\">{$graph}</div>";
@ -134,9 +134,9 @@ EOS;
<div class="blockarea legends">
<div class="legendtitle"><?php echo _T('Legends:'); ?></div>
<div class="legend pvalue">&nbsp;&nbsp;</div>
<div class="legendtitle"><?php echo _T(isset($free_graph_width) ? '% Free' : '% Used'); ?></div>
<div class="legendtitle"><?php echo _T($config['percent_graph_type'] == 'free' ? '% Free' : '% Used'); ?></div>
<div class="legend" style="background: rgb(0,0,255)">&nbsp;&nbsp;</div>
<div class="legendtitle"><?php echo _T(isset($free_graph_width) ? 'Free Blocks' : 'Used Blocks'); ?></div>
<div class="legendtitle"><?php echo _T($config['percent_graph_type'] == 'free' ? 'Free Blocks' : 'Used Blocks'); ?></div>
<div class="legend" style="background: rgb(255,0,0)">&nbsp;&nbsp;</div>
<div class="legendtitle"><?php echo _T('Hits'); ?></div>
</div>
@ -144,9 +144,7 @@ EOS;
if ($cachelist) {
$isphp = $cachelist['type'] == $type_php;
if (function_exists("ob_filter_path_nicer")) {
ob_start("ob_filter_path_nicer");
}
ob_start($config['path_nicer']);
foreach (array('Cached' => $cachelist['cache_list'], 'Deleted' => $cachelist['deleted_list']) as $listname => $entries) {
$a->reset();
?>
@ -260,9 +258,7 @@ ENTRY;
</form>
<?php
}
if (function_exists("ob_filter_path_nicer")) {
ob_end_flush();
}
ob_end_flush();
}
if ($moduleinfo) {
$t_moduleinfo = _T("Module Info");

Loading…
Cancel
Save