<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////
// BotBanish 9.0.05
// Randem Systems: https://randemsystems.support
// BotBanish Cache Templates
// Date: 08/07/2026
// Usage:
//
// Function: Shows Cache Files
///////////////////////////////////////////////////////////////////////////////////////////////////////

	$method = isset($_POST['file']) ? $_POST : $_GET;
	
	if (isset($method['file']))
		BotBanishViewCache();
	
function BotBanishViewCache() {

	$method = isset($_POST['file']) ? $_POST : $_GET;

	$file = basename($method['file']);
	$cache = isset($method['dir']) ? $method['dir'] : '';
	$ip = str_ireplace('.cache', '', $file);

	if (defined('ABSPATH') || defined('SMF')) {
		
		global $BotBanishSettings;
		$filename = $BotBanishSettings['BOTBANISH_INCLUDE_DIR'] . 'BotBanish_PreIncludes.php';
		
	} else {
		
		$filename = realpath(str_ireplace(basename($_SERVER['PHP_SELF']), '../Include/BotBanish_PreIncludes.php', $_SERVER['SCRIPT_FILENAME']));
	}
	
	require_once $filename;

	$_REQUEST['ip'] = $ip;
	$BotBanishCache = new BotBanishCache;

	$cache = empty($cache) ? $BotBanishSettings['BOTBANISH_STATIC_CACHE_DIR'] : $cache;

	if (!empty($cache) && is_dir($cache))
		$BotBanishCache->setCacheDir($cache);

	$BotBanishSession = $BotBanishCache->getCacheObject($ip);
	BotBanishShowCacheInfo($BotBanishSession);
}

function template_show_cache() {

	global $BotBanishSettings;

	$system = BotBanishCheckSystem();
	$url = $BotBanishSettings['BOTBANISH_INSTALL_URL'] . 'Subs/BotBanish_ScanCacheFiles.php?system=' . strtoupper($system['install_type']);
	echo $BotBanishSettings['BOTBANISH_HEADER_HTML'];

	echo '
	<div id="cache">
		<iframe id="Cache" width="100%" height="1000" frameborder=0 scrolling=auto allowtransparency="true" src="' . $url . '"></iframe>
	</div>';
}

function BotBanishShowCacheInfo($session) {

	BotBanishBrowserNoCache();

	echo '
	<!DOCTYPE html>
	<html>
	<head>
	</head>
	<body>';

	echo '
		<form action="" method="post">
			<table>';

			foreach ($session->sessionInfo as $key => $value) {

				if (!is_array($value))

					$data = BotBanishIsTimestamp($value);
				else
					$data = var_export($value, true);

				echo '
					<tr>
						<td width="5%" align="right">' . $key. ':</td>
						<td width="30%" align="left">' . $data . '</td>
					</tr><tr></tr>';
			}

	echo '
			</table>
		</form>
	</body>
	</html>';
}

function BotBanishIsTimestamp($value) {

	if (strtotime($value) !== false)
		return $value;
	
	if (strlen((string)$value) < 10)
		return $value;

    // Check if the value contains only digits (handles numeric strings and integers)

    if (!ctype_digit((string)$value))
        return $value;

    // Ensure it converts to a structurally valid Unix timestamp date range

    return date('Y-m-d H:i:s', $value);
}
?>