<commit_before><?php
// (c) Copyright 2002-2013 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

require_once ('tiki-setup.php');

$opcode_cache = null;
$stat_flag = null;
$opcode_stats = array(
	'warning_check' => false,
	'warning_fresh' => false,
	'warning_ratio' => false,
	'warning_starve' => false,
	'warning_low' => false,
	'warning_xcache_blocked' => false,
);

if ( function_exists('apc_sma_info') && ini_get('apc.enabled') ) {
	$opcode_cache = 'APC';

	$sma = apc_sma_info();
	$mem_total = $sma['num_seg'] * $sma['seg_size'];

	$cache = apc_cache_info(null, true);
	$hit_total = $cache['num_hits'] + $cache['num_misses'];

	$stat_flag = 'apc.stat';
	$opcode_stats = array(
		'memory_used' => ( $mem_total - $sma['avail_mem'] ) / $mem_total,
		'memory_avail' => $sma['avail_mem'] / $mem_total,
		'memory_total' => $mem_total,
		'hit_hit' => $cache['num_hits'] / $hit_total,
		'hit_miss' => $cache['num_misses'] / $hit_total,
		'hit_total' => $hit_total,
	);
} elseif ( function_exists('xcache_info') && ( ini_get('xcache.cacher') == '1' || ini_get('xcache.cacher') == 'On' ) ) {
	$opcode_cache = 'XCache';

	if ( ini_get('xcache.admin.enable_auth') == '1' || ini_get('xcache.admin.enable_auth') == 'On' ) {
		$opcode_stats['warning_xcache_blocked'] = true;
	} else {
		$stat_flag = 'xcache.stat';
		$opcode_stats = array(
			'memory_used' => 0,
			'memory_avail' => 0,
			'memory_total' => 0,
			'hit_hit' => 0,
			'hit_miss' => 0,
			'hit_total' => 0,
		);

		foreach (range(0, xcache_count(XC_TYPE_PHP) - 1) as $index) {
			$info = xcache_info(XC_TYPE_PHP, $index);

			$opcode_stats['hit_hit'] += $info['hits'];
			$opcode_stats['hit_miss'] += $info['misses'];
			$opcode_stats['hit_total'] += $info['hits'] + $info['misses'];

			$opcode_stats['memory_used'] += $info['size'] - $info['avail'];
			$opcode_stats['memory_avail'] += $info['avail'];
			$opcode_stats['memory_total'] += $info['size'];
		}

		$opcode_stats['memory_used'] /= $opcode_stats['memory_total'];
		$opcode_stats['memory_avail'] /= $opcode_stats['memory_total'];
		$opcode_stats['hit_hit'] /= $opcode_stats['hit_total'];
		$opcode_stats['hit_miss'] /= $opcode_stats['hit_total'];
	}
} elseif ( function_exists('wincache_ocache_fileinfo') && ( ini_get('wincache.ocenabled') == '1') ) {
	$opcode_cache = 'WinCache';

	$stat_flag = 'wincache.ocenabled';
	$opcode_stats = array(
		'memory_used' => 0,
		'memory_avail' => 0,
		'memory_total' => 0,
		'hit_hit' => 0,
		'hit_miss' => 0,
		'hit_total' => 0,
		);
	
	$info = wincache_ocache_fileinfo();
	$opcode_stats['hit_hit'] = $info['total_hit_count'];
	$opcode_stats['hit_miss'] = $info['total_miss_count'];
	$opcode_stats['hit_total'] = $info['total_hit_count'] + $info['total_miss_count'];
	
	$memory = wincache_ocache_meminfo();
	$opcode_stats['memory_avail'] = $memory['memory_free'];
	$opcode_stats['memory_total'] = $memory['memory_total'];
	$opcode_stats['memory_used'] = $memory['memory_total'] - $memory['memory_free'];
	
	$opcode_stats['memory_used'] /= $opcode_stats['memory_total'];
	$opcode_stats['memory_avail'] /= $opcode_stats['memory_total'];
	$opcode_stats['hit_hit'] /= $opcode_stats['hit_total'];
	$opcode_stats['hit_miss'] /= $opcode_stats['hit_total'];
}

// Make results easier to read
$opcode_stats['memory_used'] = round($opcode_stats['memory_used'],2);
$opcode_stats['memory_avail'] = round($opcode_stats['memory_avail'],2);
$opcode_stats['hit_hit'] = round($opcode_stats['hit_hit'],2);
$opcode_stats['hit_miss'] = round($opcode_stats['hit_miss'],2);


if ( $stat_flag ) {
	$opcode_stats['warning_check'] = (bool) ini_get($stat_flag);
}

if ( isset($opcode_stats['hit_total']) ) {
	$opcode_stats = array_merge(
		$opcode_stats,
		array(
			'warning_fresh' => $opcode_stats['hit_total'] < 10000,
			'warning_ratio' => $opcode_stats['hit_hit'] < 0.8,<commit_msg>[MOD] introduce a new param in db/local.php to restrict the connection to tiki-monitor. The goal is to avoid brute force or stress tool to crash tiki<commit_after><?php
// (c) Copyright 2002-2013 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

require_once ('tiki-setup.php');
//TODO Use a pref to handle the list
if (!empty($tikiMonitorRestriction)) {
	if (is_array($tikiMonitorRestriction)) {
		if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
			$aListIp = explode(' ', $_SERVER['HTTP_X_FORWARDED_FOR']);
			if (!in_array($aListIp[0], $tikiMonitorRestriction)) {
				header('location: index.php');
			}
		}
	} else {
		echo tra("\$tikiMonitorRestriction need to be an array");
		exit;
	}
}
$opcode_cache = null;
$stat_flag = null;
$opcode_stats = array(
	'warning_check' => false,
	'warning_fresh' => false,
	'warning_ratio' => false,
	'warning_starve' => false,
	'warning_low' => false,
	'warning_xcache_blocked' => false,
);

if ( function_exists('apc_sma_info') && ini_get('apc.enabled') ) {
	$opcode_cache = 'APC';

	$sma = apc_sma_info();
	$mem_total = $sma['num_seg'] * $sma['seg_size'];

	$cache = apc_cache_info(null, true);
	$hit_total = $cache['num_hits'] + $cache['num_misses'];

	$stat_flag = 'apc.stat';
	$opcode_stats = array(
		'memory_used' => ( $mem_total - $sma['avail_mem'] ) / $mem_total,
		'memory_avail' => $sma['avail_mem'] / $mem_total,
		'memory_total' => $mem_total,
		'hit_hit' => $cache['num_hits'] / $hit_total,
		'hit_miss' => $cache['num_misses'] / $hit_total,
		'hit_total' => $hit_total,
	);
} elseif ( function_exists('xcache_info') && ( ini_get('xcache.cacher') == '1' || ini_get('xcache.cacher') == 'On' ) ) {
	$opcode_cache = 'XCache';

	if ( ini_get('xcache.admin.enable_auth') == '1' || ini_get('xcache.admin.enable_auth') == 'On' ) {
		$opcode_stats['warning_xcache_blocked'] = true;
	} else {
		$stat_flag = 'xcache.stat';
		$opcode_stats = array(
			'memory_used' => 0,
			'memory_avail' => 0,
			'memory_total' => 0,
			'hit_hit' => 0,
			'hit_miss' => 0,
			'hit_total' => 0,
		);

		foreach (range(0, xcache_count(XC_TYPE_PHP) - 1) as $index) {
			$info = xcache_info(XC_TYPE_PHP, $index);

			$opcode_stats['hit_hit'] += $info['hits'];
			$opcode_stats['hit_miss'] += $info['misses'];
			$opcode_stats['hit_total'] += $info['hits'] + $info['misses'];

			$opcode_stats['memory_used'] += $info['size'] - $info['avail'];
			$opcode_stats['memory_avail'] += $info['avail'];
			$opcode_stats['memory_total'] += $info['size'];
		}

		$opcode_stats['memory_used'] /= $opcode_stats['memory_total'];
		$opcode_stats['memory_avail'] /= $opcode_stats['memory_total'];
		$opcode_stats['hit_hit'] /= $opcode_stats['hit_total'];
		$opcode_stats['hit_miss'] /= $opcode_stats['hit_total'];
	}
} elseif ( function_exists('wincache_ocache_fileinfo') && ( ini_get('wincache.ocenabled') == '1') ) {
	$opcode_cache = 'WinCache';

	$stat_flag = 'wincache.ocenabled';
	$opcode_stats = array(
		'memory_used' => 0,
		'memory_avail' => 0,
		'memory_total' => 0,
		'hit_hit' => 0,
		'hit_miss' => 0,
		'hit_total' => 0,
		);

	$info = wincache_ocache_fileinfo();
	$opcode_stats['hit_hit'] = $info['total_hit_count'];
	$opcode_stats['hit_miss'] = $info['total_miss_count'];
	$opcode_stats['hit_total'] = $info['total_hit_count'] + $info['total_miss_count'];

	$memory = wincache_ocache_meminfo();
	$opcode_stats['memory_avail'] = $memory['memory_free'];
	$opcode_stats['memory_total'] = $memory['memory_total'];
	$opcode_stats['memory_used'] = $memory['memory_total'] - $memory['memory_free'];

	$opcode_stats['memory_used'] /= $opcode_stats['memory_total'];
	$opcode_stats['memory_avail'] /= $opcode_stats['memory_total'];
	$opcode_stats['hit_hit'] /= $opcode_stats['hit_total'];
	$opcode_stats['hit_miss'] /= $opcode_stats['hit_total'];
}

// Make results easier to read
$opcode_stats['memory_used'] = round($opcode_stats['memory_used'],2);
$opcode_stats['memory_avail'] = round($opcode_stats['memory_avail'],2);
$opcode_stats['hit_hit'] = round($opcode_stats['hit_hit'],2);
$opcode_stats['hit_miss'] = round($opcode_stats['hit_miss'],2);


if ( $stat_flag ) {
	$opcode_stats['warning_check'] = (bool) ini_get($stat_flag);
}

if ( isset($opcode_stats['hit_total']) ) {
	$opcode_stats = array_merge(
		$opcode_stats,
		array(
			'warning_fresh' => $opcode_stats['hit_total'] < 10000,
			'warning_ratio' => $opcode_stats['hit_hit'] < 0.8,
{'fraction_non_alphanumeric': 0.19911504424778761, 'fraction_numerical': 0.008500232883092687, 'mean_word_length': 5.876701361088871, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5064705', 'n_tokens_mistral': 3502, 'n_tokens_neox': 3392, 'n_words': 530}