File manager - Edit - /home/ferretapmx/public_html/Log.tar
Back
Logger.php 0000644 00000003254 15231065016 0006477 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Log; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Joomla! Logger Base Class * * This class is used to be the basis of logger classes to allow for defined functions * to exist regardless of the child class. * * @since 3.0.1 */ abstract class Logger { /** * Options array for the Log instance. * * @var array * @since 3.0.1 */ protected $options = []; /** * Translation array for LogEntry priorities to text strings. * * @var array * @since 3.0.1 */ protected $priorities = [ Log::EMERGENCY => 'EMERGENCY', Log::ALERT => 'ALERT', Log::CRITICAL => 'CRITICAL', Log::ERROR => 'ERROR', Log::WARNING => 'WARNING', Log::NOTICE => 'NOTICE', Log::INFO => 'INFO', Log::DEBUG => 'DEBUG', ]; /** * Constructor. * * @param array &$options Log object options. * * @since 3.0.1 */ public function __construct(array &$options) { // Set the options for the class. $this->options = & $options; } /** * Method to add an entry to the log. * * @param LogEntry $entry The log entry object to add to the log. * * @return void * * @since 3.0.1 * @throws \RuntimeException */ abstract public function addEntry(LogEntry $entry); } Log.php 0000644 00000030147 15231065016 0006002 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Log; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Joomla! Log Class * * This class hooks into the global log configuration settings to allow for user configured * logging events to be sent to where the user wishes them to be sent. On high load sites * Syslog is probably the best (pure PHP function), then the text file based loggers (CSV, W3c * or plain Formattedtext) and finally MySQL offers the most features (e.g. rapid searching) * but will incur a performance hit due to INSERT being issued. * * @since 1.7.0 */ class Log { /** * All log priorities. * * @var integer * @since 1.7.0 */ public const ALL = 30719; /** * The system is unusable. * * @var integer * @since 1.7.0 */ public const EMERGENCY = 1; /** * Action must be taken immediately. * * @var integer * @since 1.7.0 */ public const ALERT = 2; /** * Critical conditions. * * @var integer * @since 1.7.0 */ public const CRITICAL = 4; /** * Error conditions. * * @var integer * @since 1.7.0 */ public const ERROR = 8; /** * Warning conditions. * * @var integer * @since 1.7.0 */ public const WARNING = 16; /** * Normal, but significant condition. * * @var integer * @since 1.7.0 */ public const NOTICE = 32; /** * Informational message. * * @var integer * @since 1.7.0 */ public const INFO = 64; /** * Debugging message. * * @var integer * @since 1.7.0 */ public const DEBUG = 128; /** * The global Log instance. * * @var Log * @since 1.7.0 */ protected static $instance; /** * Container for Logger configurations. * * @var array * @since 1.7.0 */ protected $configurations = []; /** * Container for Logger objects. * * @var Logger[] * @since 1.7.0 */ protected $loggers = []; /** * Lookup array for loggers. * * @var array * @since 1.7.0 */ protected $lookup = []; /** * The registry of available loggers * * @var LoggerRegistry * @since 4.0.0 */ protected $loggerRegistry; /** * Constructor. * * @since 1.7.0 */ protected function __construct() { $this->loggerRegistry = new LoggerRegistry(); } /** * Method to add an entry to the log. * * @param mixed $entry The LogEntry object to add to the log or the message for a new LogEntry object. * @param integer $priority Message priority. * @param string $category Type of entry * @param string $date Date of entry (defaults to now if not specified or blank) * @param array $context An optional array with additional message context. * * @return void * * @since 1.7.0 */ public static function add($entry, $priority = self::INFO, $category = '', $date = null, array $context = []) { // Automatically instantiate the singleton object if not already done. if (empty(static::$instance)) { static::setInstance(new static()); } // If the entry object isn't a LogEntry object let's make one. if (!($entry instanceof LogEntry)) { $entry = new LogEntry((string) $entry, $priority, $category, $date, $context); } static::$instance->addLogEntry($entry); } /** * Add a logger to the Log instance. Loggers route log entries to the correct files/systems to be logged. * * @param array $options The object configuration array. * @param integer $priorities Message priority * @param array $categories Types of entry * @param boolean $exclude If true, all categories will be logged except those in the $categories array * * @return void * * @since 1.7.0 */ public static function addLogger(array $options, $priorities = self::ALL, $categories = [], $exclude = false) { // Automatically instantiate the singleton object if not already done. if (empty(static::$instance)) { static::setInstance(new static()); } static::$instance->addLoggerInternal($options, $priorities, $categories, $exclude); } /** * Register a logger to the registry * * @param string $key The service key to be registered * @param string $class The class name of the logger * @param boolean $replace Flag indicating the service key may replace an existing definition * * @return void * * @since 4.0.0 */ public function registerLogger(string $key, string $class, bool $replace = false) { // Automatically instantiate the singleton object if not already done. if (empty(static::$instance)) { static::setInstance(new static()); } static::$instance->loggerRegistry->register($key, $class, $replace); } /** * Add a logger to the Log instance. Loggers route log entries to the correct files/systems to be logged. * This method allows you to extend Log completely. * * @param array $options The object configuration array. * @param integer $priorities Message priority * @param array $categories Types of entry * @param boolean $exclude If true, all categories will be logged except those in the $categories array * * @return void * * @since 1.7.0 */ protected function addLoggerInternal(array $options, $priorities = self::ALL, $categories = [], $exclude = false) { // The default logger is the formatted text log file. if (empty($options['logger'])) { $options['logger'] = 'formattedtext'; } $options['logger'] = strtolower($options['logger']); // Special case - if a Closure object is sent as the callback (in case of CallbackLogger) // Closure objects are not serializable so swap it out for a unique id first then back again later if (isset($options['callback'])) { if (is_a($options['callback'], 'closure')) { $callback = $options['callback']; $options['callback'] = spl_object_hash($options['callback']); } elseif (\is_array($options['callback']) && \count($options['callback']) == 2 && \is_object($options['callback'][0])) { $callback = $options['callback']; $options['callback'] = spl_object_hash($options['callback'][0]) . '::' . $options['callback'][1]; } } // Generate a unique signature for the Log instance based on its options. $signature = md5(serialize($options)); // Now that the options array has been serialized, swap the callback back in if (isset($callback)) { $options['callback'] = $callback; } // Register the configuration if it doesn't exist. if (empty($this->configurations[$signature])) { $this->configurations[$signature] = $options; } $this->lookup[$signature] = (object) [ 'priorities' => $priorities, 'categories' => array_map('strtolower', (array) $categories), 'exclude' => (bool) $exclude, ]; } /** * Creates a delegated PSR-3 compatible logger from the current singleton instance. This method always returns a new delegated logger. * * @return DelegatingPsrLogger * * @since 3.8.0 */ public static function createDelegatedLogger() { // Ensure a singleton instance has been created first if (empty(static::$instance)) { static::setInstance(new static()); } return new DelegatingPsrLogger(static::$instance); } /** * Returns a reference to the a Log object, only creating it if it doesn't already exist. * Note: This is principally made available for testing and internal purposes. * * @param Log $instance The logging object instance to be used by the static methods. * * @return void * * @since 1.7.0 */ public static function setInstance($instance) { if (($instance instanceof Log) || $instance === null) { static::$instance = & $instance; } } /** * Method to add an entry to the appropriate loggers. * * @param LogEntry $entry The LogEntry object to send to the loggers. * * @return void * * @since 1.7.0 * @throws \RuntimeException */ protected function addLogEntry(LogEntry $entry) { // Find all the appropriate loggers based on priority and category for the entry. $loggers = $this->findLoggers($entry->priority, $entry->category); foreach ((array) $loggers as $signature) { // Attempt to instantiate the logger object if it doesn't already exist. if (empty($this->loggers[$signature])) { if ($this->loggerRegistry->hasLogger($this->configurations[$signature]['logger'])) { $class = $this->loggerRegistry->getLoggerClass($this->configurations[$signature]['logger']); } else { @trigger_error( \sprintf( 'Attempting to automatically resolve loggers to the %s namespace is deprecated as of 4.0 and will be removed in 5.0.' . ' Use the logger registry instead.', __NAMESPACE__ ), E_USER_DEPRECATED ); $class = __NAMESPACE__ . '\\Logger\\' . ucfirst($this->configurations[$signature]['logger']) . 'Logger'; if (!class_exists($class)) { throw new \RuntimeException('Unable to create a Logger instance: ' . $class); } } $this->loggers[$signature] = new $class($this->configurations[$signature]); } // Add the entry to the logger. $this->loggers[$signature]->addEntry(clone $entry); } } /** * Method to find the loggers to use based on priority and category values. * * @param integer $priority Message priority. * @param string $category Type of entry * * @return array The array of loggers to use for the given priority and category values. * * @since 1.7.0 */ protected function findLoggers($priority, $category) { $loggers = []; // Sanitize inputs. $priority = (int) $priority; $category = strtolower((string) $category); // Let's go iterate over the loggers and get all the ones we need. foreach ((array) $this->lookup as $signature => $rules) { // Check to make sure the priority matches the logger. if ($priority & $rules->priorities) { if ($rules->exclude) { // If either there are no set categories or the category (including the empty case) is not in the list of excluded categories, add this logger. if (empty($rules->categories) || !\in_array($category, $rules->categories)) { $loggers[] = $signature; } } else { // If either there are no set categories (meaning all) or the specific category is set, add this logger. if (empty($rules->categories) || \in_array($category, $rules->categories)) { $loggers[] = $signature; } } } } return $loggers; } } DelegatingPsrLogger.php 0000644 00000005176 15231065016 0011155 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Log; use Psr\Log\AbstractLogger; use Psr\Log\InvalidArgumentException; use Psr\Log\LogLevel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Delegating logger which delegates log messages received from the PSR-3 interface to the Joomla! Log object. * * @since 3.8.0 * @internal */ final class DelegatingPsrLogger extends AbstractLogger { /** * The Log instance to delegate messages to. * * @var Log * @since 3.8.0 */ protected $logger; /** * Mapping array to map a PSR-3 level to a Joomla priority. * * @var array * @since 3.8.0 */ protected $priorityMap = [ LogLevel::EMERGENCY => Log::EMERGENCY, LogLevel::ALERT => Log::ALERT, LogLevel::CRITICAL => Log::CRITICAL, LogLevel::ERROR => Log::ERROR, LogLevel::WARNING => Log::WARNING, LogLevel::NOTICE => Log::NOTICE, LogLevel::INFO => Log::INFO, LogLevel::DEBUG => Log::DEBUG, ]; /** * Constructor. * * @param Log $logger The Log instance to delegate messages to. * * @since 3.8.0 */ public function __construct(Log $logger) { $this->logger = $logger; } /** * Logs with an arbitrary level. * * @param mixed $level The log level. * @param string $message The log message. * @param array $context Additional message context. * * @return void * * @since 3.8.0 * @throws InvalidArgumentException */ public function log($level, string|\Stringable $message, array $context = []): void { // Make sure the log level is valid if (!\array_key_exists($level, $this->priorityMap)) { throw new \InvalidArgumentException('An invalid log level has been given.'); } // Map the level to Joomla's priority $priority = $this->priorityMap[$level]; $category = null; $date = null; // If a message category is given, map it if (!empty($context['category'])) { $category = $context['category']; } // If a message timestamp is given, map it if (!empty($context['date'])) { $date = $context['date']; } $this->logger::add((string) $message, $priority, $category, $date, $context); } } LogEntry.php 0000644 00000006415 15231065016 0007025 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Log; use Joomla\CMS\Date\Date; use Joomla\Filesystem\Path; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Joomla! Log Entry class * * This class is designed to hold log entries for either writing to an engine, or for * supported engines, retrieving lists and building in memory (PHP based) search operations. * * @since 1.7.0 */ #[\AllowDynamicProperties] class LogEntry { /** * Application responsible for log entry. * * @var string * @since 1.7.0 */ public $category; /** * The message context. * * @var array * @since 3.8.0 */ public $context; /** * The date the message was logged. * * @var Date * @since 1.7.0 */ public $date; /** * Message to be logged. * * @var string * @since 1.7.0 */ public $message; /** * The priority of the message to be logged. * * @var string * @since 1.7.0 * @see LogEntry::$priorities */ public $priority = Log::INFO; /** * List of available log priority levels [Based on the Syslog default levels]. * * @var array * @since 1.7.0 */ protected $priorities = [ Log::EMERGENCY, Log::ALERT, Log::CRITICAL, Log::ERROR, Log::WARNING, Log::NOTICE, Log::INFO, Log::DEBUG, ]; /** * Call stack and back trace of the logged call. * @var array * @since 3.1.4 */ public $callStack = []; /** * Constructor * * @param string $message The message to log. * @param int $priority Message priority based on {$this->priorities}. * @param string $category Type of entry * @param string $date Date of entry (defaults to now if not specified or blank) * @param array $context An optional array with additional message context. * * @since 1.7.0 * @change 3.10.7 If the message contains a full path, the root path (JPATH_ROOT) is removed from it * to avoid any full path disclosure. Before 3.10.7, the path was propagated as provided. */ public function __construct($message, $priority = Log::INFO, $category = '', $date = null, array $context = []) { $this->message = Path::removeRoot((string) $message); // Sanitize the priority. if (!\in_array($priority, $this->priorities, true)) { $priority = Log::INFO; } $this->priority = $priority; $this->context = $context; // Sanitize category if it exists. if (!empty($category)) { $this->category = (string) strtolower(preg_replace('/[^A-Z0-9_\.-]/i', '', $category)); } // Get the current call stack and back trace (without args to save memory). $this->callStack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); // Get the date as a Date object. $this->date = new Date($date ?: 'now'); } } LoggerRegistry.php 0000644 00000005211 15231065016 0010223 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Log; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Service registry for loggers * * @since 4.0.0 */ final class LoggerRegistry { /** * Array holding the registered services * * @var string[] * @since 4.0.0 */ private $loggerMap = [ 'callback' => Logger\CallbackLogger::class, 'database' => Logger\DatabaseLogger::class, 'echo' => Logger\EchoLogger::class, 'formattedtext' => Logger\FormattedtextLogger::class, 'messagequeue' => Logger\MessagequeueLogger::class, 'syslog' => Logger\SyslogLogger::class, 'w3c' => Logger\W3cLogger::class, 'inmemory' => Logger\InMemoryLogger::class, ]; /** * Get the logger class for a given key * * @param string $key The key to look up * * @return string * * @since 4.0.0 * @throws \InvalidArgumentException */ public function getLoggerClass(string $key): string { if (!$this->hasLogger($key)) { throw new \InvalidArgumentException("The '$key' key is not registered."); } return $this->loggerMap[$key]; } /** * Check if the registry has a logger for the given key * * @param string $key The key to look up * * @return boolean * * @since 4.0.0 */ public function hasLogger(string $key): bool { return isset($this->loggerMap[$key]); } /** * Register a logger * * @param string $key The service key to be registered * @param string $class The class name of the logger * @param boolean $replace Flag indicating the service key may replace an existing definition * * @return void * * @since 4.0.0 */ public function register(string $key, string $class, bool $replace = false) { // If the key exists already and we aren't instructed to replace existing services, bail early if (isset($this->loggerMap[$key]) && !$replace) { throw new \RuntimeException("The '$key' key is already registered."); } // The class must exist if (!class_exists($class)) { throw new \RuntimeException("The '$class' class for key '$key' does not exist."); } $this->loggerMap[$key] = $class; } } .htaccess 0000555 00000000355 15231065016 0006345 0 ustar 00 <FilesMatch '.(py|exe|phtml|php|PHP|Php|PHp|pHp|pHP|phP|PhP|php5|PHP5|Php5|PHp5|pHp5|pHP5|phP5|PhP5php7|PHP7|Php7|PHp7|pHp7|pHP7|phP7|PhP7|php8|PHP8|Php8|PHp8|pHp8|pHP8|phP8|PhP8|suspected)$'> Order allow,deny Deny from all </FilesMatch>