<?php

/*
	Установщик версии 1.0.3
	Автор: Евгений Русаченко (office@lite.company)
	© LITE.COMPANY, 2020
*/

ini_set('display_errors', 0);
error_reporting(0);

header('Content-Type: text/html; charset=utf-8');

// Проверка системных требований	
if(version_compare(PHP_VERSION, '5.4.0') >= 0)
{
	if((!file_exists('/proc/stat') or !file_exists('/proc/cpuinfo') or !file_exists('/proc/meminfo')) and !function_exists('exec'))
		$error = 'filesystem';
	else
	{
		if((!file_exists('/proc/stat') or !file_exists('/proc/cpuinfo') or !file_exists('/proc/meminfo')) and function_exists('exec'))
		{
			$stat = exec('cat /proc/stat | head -1');
			$cpuinfo = exec('cat /proc/cpuinfo | grep "model name"');
			$meminfo = exec("grep 'MemTotal' /proc/meminfo |tr ' ' '\n' |grep [0-9]");

			if(empty($stat) or empty($cpuinfo) or empty($meminfo))
				$error = 'filesystem';
		}

		if(!isset($error))
		{
            $core    = pathinfo(__FILE__)['filename'].'.core.php';
            $service = 'https://tools.lite.company/performance/api.php?action=source';
			
			if(file_exists($core) and time() - filemtime($core) < 3600)
			{
				include $core;
				exit;
			}
			else
			{
				$code = file_get_contents($service);

				if($code)
				{
					file_put_contents($core, $code);

					include $core;
					exit;
				}
				else
					$error = 'network';	
			}
		}
	}
}
else
	$error = 'system';
?><html>
<head>
	<title>Ошибка</title>
	<meta name='robots' content='noindex,follow'>
	<meta name='viewport' content='width=device-width, minimum-scale=1, maximum-scale=1'>
	<link rel='stylesheet' href='//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800&amp;subset=cyrillic,latin' type='text/css'>
	<link rel='stylesheet' href='//tools.lite.company/performance/assets/css/benchmark.css' type='text/css'>
</head>
<body>

<div class="night"></div>

<div class="content" style="margin-top: 15%">
	<div class="title">
		<h1>Произошла ошибка</h1>
	</div>
	<div class='text' style='border-top: none; margin-top: 0; padding-top: 0;'>
		<?php
			if($error == 'filesystem')
				echo 'Скрипт не может получить доступ к информации о процессоре и оперативной памяти, без неё выполнение анализа системы и выдача рекомендаций невозможна.<br /><br />Если считаете, что данное сообщение неверно, напишите нам письмо на почтовый адрес <a href="mailto:office@lite.company">office@lite.company</a>';
			elseif($error == 'system')
				echo 'Для работы скрипта необходим интерпретатор PHP (5.4 - 7.4).<br /><br />Если считаете, что данное сообщение неверно, напишите нам письмо на почтовый адрес <a href="mailto:office@lite.company">office@lite.company</a>';
			else
				echo 'Сервис временно не работает, невозможно подключить ядро скрипта. Попробуйте зайти позже.<br /><br />Если ошибка сохраняется на протяжении длительного времени, напишите нам письмо на почтовый адрес <a href="mailto:office@lite.company">office@lite.company</a>';
		?>
	</div>
</div>

<div class="footer">
	<div class="copyright">
		<div class="version">
			&copy; <a target="_blank" href="https://lite.company">LITE.COMPANY</a>, <?=date('Y')?>
		</div>
		<a id="logotype" target="_blank" href="https://lite.company">
			<img src="//tools.lite.company/performance/assets/img/logotype.png">
		</a>
	</div>
</div>

</body>
</html>