if (extension_loaded('newrelic')) { newrelic_add_custom_tracer('ApcCheckIp'); newrelic_add_custom_tracer('CheckIp'); } include 'common_lib.inc'; error_reporting(E_ERROR | E_PARSE); $has_apc = function_exists('apc_fetch') && function_exists('apc_store'); $ok = false; if (isset($_REQUEST['installer']) && isset($_SERVER['REMOTE_ADDR'])) { $installer = $_REQUEST['installer']; $installer_postfix = GetSetting('installerPostfix'); if ($installer_postfix) { $installer .= $installer_postfix; $ok = true; } elseif (preg_match('/^(software|browsers\\/[-_a-zA-Z0-9]+)\\.dat$/', $installer)) { $ok = $has_apc ? ApcCheckIp($installer) : CheckIp($installer); } } if ($ok) { $file = __DIR__ . '/installers/' . $installer; $data = $has_apc ? apc_fetch("installer-{$installer}") : null; if (!$data && is_file($file)) { $data = file_get_contents($file); if ($has_apc) { apc_store("installer-{$installer}", str_pad($data, 1000), 600); } } if (isset($data) && strlen($data)) { header("Content-type: text/plain"); header("Cache-Control: no-cache, must-revalidate"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
function IsValidIp($ip, $installer) { global $has_apc; $ok = true; // Make sure it isn't on our banned IP list $filename = __DIR__ . '/settings/block_installer_ip.txt'; if (is_file($filename)) { $blocked_addresses = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (in_array($ip, $blocked_addresses)) { $ok = false; } } if ($ok) { $ok = $has_apc ? ApcCheckIp($ip, $installer) : CheckIp($ip, $installer); if (!$ok) { logMsg("BLOCKED - {$ip} : {$_REQUEST['installer']}", "log/software.log", true); } } return $ok; }