ACC SHELL

Path : /srv/www/vhosts/alfa-com/engine/
File Upload :
Current File : /srv/www/vhosts/alfa-com/engine/Log.php

<?php
	// Author: Jakub Macek, CZ; Copyright: Poski.com s.r.o.; Code is 100% my work. Do not copy.
	
	class Log
	{
		const EVENT_TIME = 1;
		const EVENT_INCLUDE = 2;
		const EVENT_PAGE = 4;
		const EVENT_SITE = 8;
		const EVENT_GET = 16;
		const EVENT_POST = 32;
		const EVENT_COOKIE = 64;
		const EVENT_SERVER = 128;
		const EVENT_SESSION = 256;
		const EVENT_TEMPLATES = 512;
		const EVENT_CORE_MODULE = 1024;
		const EVENT_CORE_PROCESS = 2048;
		//const EVENT_MODULE_CONTRUCT = 4096;
		const EVENT_MODULE_INITIALIZE = 8192;
		const EVENT_MODULE_INDEX = 16384;
		const EVENT_MODULE_PROCESS = 32768;
		const EVENT_FIELD = 65536;
		const EVENT_STORAGE = 131072;
		const EVENT_STORAGE_FIREPHP = 262144;
			
		public $file;
		public $events;
		public $start = 0;
		public $time = 0;
		public $skipNext = 0;
		
		public function __construct($file, $append = false, $events = null)
		{
			if ($events === null)
				$events = Log::EVENT_TIME | Log::EVENT_PAGE | Log::EVENT_CORE_MODULE | Log::EVENT_STORAGE | Log::EVENT_SESSION | Log::EVENT_COOKIE;
			$this->file = $file;
			$this->events = $events;
			if (!$append && file_exists(DATA . 'logs/' . $this->file))
				unlink(DATA . 'logs/' . $this->file);
		}

		public function add($section, $path = null, $message = null, $event)
		{
			if (($this->events & $event) == 0)
				return;
			if ($this->skipNext > 0)
			{
				$this->skipNext--;
				return;
			}
				
			$file = DATA . 'logs/' . $this->file;
			$f = fopen($file, 'a');
			if ($message === null)
				$text = $section . "\n";
			else
			{
				//$text = date('Y-m-d H:i:s') . ' [' . strtoupper(str_pad($section, 16)) . '] (' . str_pad($path, 50) . ') ' . trim(U::indent($message, str_repeat(' ', 93))) . "\n";
				if (strpos($message, "\n") !== false)
					$text = date('Y-m-d H:i:s') . ' [' . strtoupper(str_pad($section, 16)) . '] (' . str_pad($path, 50) . ') ' . "\n" . U::indent(trim($message), "\t\t") . "\n";
				else
					$text = date('Y-m-d H:i:s') . ' [' . strtoupper(str_pad($section, 16)) . '] (' . str_pad($path, 50) . ') ' . $message . "\n";
			}

			fwrite($f, $text);
			fclose($f);
			chmod($file, 0666);
		}

		public function time($string = false)
		{
			if (!$string)
			{
				$this->time = microtime(true);
				return ($this->time - $this->start);
			}
			else
			{
				$temp = microtime(true);
				$result = round(($temp - $this->start), 1) . ' (+ ' . round(($temp - $this->time), 1) . ')';
				$this->time = $temp;
				return $result;
			}
		}

		public function rename($new)
		{
			$old = DATA . 'logs/' . $this->file;
			if (!is_file($old))
				return;
			rename($old, DATA . 'logs/' . $new);
			$this->file = $new;
		}
	}
	
	class NullLog extends Log
	{
		public function __construct() {}

		public function add($section, $path = null, $message = null, $event) {}

		public function rename($new) {}
	}
	
	function lll($section, $path = null, $message = null, $event = 16777215, $log = 0)
	{
		if (!isset($GLOBALS['logs'][$log]))
			return;
		$GLOBALS['logs'][$log]->add($section, $path, $message, $event);
	}
	
	if (DEV && (!site()->logIp || in_array($_SERVER['REMOTE_ADDR'], site()->logIp)))
	{
		$GLOBALS['logs'][0] = new Log($_SERVER['REMOTE_ADDR'] . '-' . date('Ymd-His'), false, site()->logEvents);
		$GLOBALS['logs']['qp'] = new Log('qp-' . date('Y-m-d') . '.log', true);
		$GLOBALS['logs'][0]->start = $GLOBALS['logs'][0]->time = microtime(true);
		lll('core', 'time', 'start at ' . date('Y-m-d H:i:s'), Log::EVENT_TIME);
		lll('core', 'request', $_SERVER['REQUEST_URI']);
		
		if ($GLOBALS['logs'][0]->events & Log::EVENT_TIME)
			register_shutdown_function(create_function('', "lll('core', 'time', 'finished (' . \$GLOBALS[\"logs\"][0]->time(true) . ')');"));
		if ($GLOBALS['logs'][0]->events & Log::EVENT_INCLUDE)
			register_shutdown_function(create_function('', "lll('core', 'included files', dump(get_included_files(), false, false, false));"));
		if ($GLOBALS['logs'][0]->events & Log::EVENT_PAGE)
			register_shutdown_function(create_function('', "lll('core', 'page', dump(\$GLOBALS[\"page\"], false, false, false));"));
		if ($GLOBALS['logs'][0]->events & Log::EVENT_SITE)
			register_shutdown_function(create_function('', "lll('core', 'site', dump(\$GLOBALS[\"site\"], false, false, false));"));
		if ($GLOBALS['logs'][0]->events & Log::EVENT_GET)
			register_shutdown_function(create_function('', "lll('core', 'get', dump(\$_GET, false, false, false));"));
		if ($GLOBALS['logs'][0]->events & Log::EVENT_POST)
			register_shutdown_function(create_function('', "lll('core', 'post', dump(\$_POST, false, false, false));"));
		if ($GLOBALS['logs'][0]->events & Log::EVENT_COOKIE)
			register_shutdown_function(create_function('', "lll('core', 'cookie', dump(\$_COOKIE, false, false, false));"));
		if ($GLOBALS['logs'][0]->events & Log::EVENT_SERVER)
			register_shutdown_function(create_function('', "lll('core', 'server', dump(\$_SERVER, false, false, false));"));
		if ($GLOBALS['logs'][0]->events & Log::EVENT_SESSION)
			register_shutdown_function(create_function('', "\$temp = \$_SESSION; unset(\$temp['viewstate']); unset(\$temp['history']); lll('core', 'session', dump(\$temp, false, false, false));"));
	}
	else
		$GLOBALS['logs'][0] = new NullLog();
?>

ACC SHELL 2018