Skip to content

Commit

Permalink
Updated the Log class to support plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mystralkk committed Sep 28, 2019
1 parent a14676d commit 641f51f
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions system/classes/Log.php
Expand Up @@ -6,6 +6,7 @@

/**
* Class Log
*
* @package Geeklog
*/
abstract class Log
Expand Down Expand Up @@ -47,6 +48,48 @@ public static function init($pathToLogDir)
self::$isInitialized = true;
}

/**
* Magic method for those plugins that want to output their own log files
*
* @param string $name log file name e.g., 'ban', 'gus'
* @param array $arguments
* @return bool
*/
public static function __callStatic($name, $arguments)
{
$fileName = strtolower(basename($name));
if (substr($fileName, -4) !== '.log') {
$fileName .= '.log';
}

if (in_array($fileName, ['error.log', 'access.log', '404.log', 'spamx.log', 'recaptcha.log'])) {
// Possible attack
$msg = sprintf(
': Possible attack detected: user id = %d, IP = %s',
Session::getUid(), Input::server('REMOTE_ADDR', '?')
);
self::error(__METHOD__ . $msg);
die($msg);
}

$filePath = self::$pathToLogDir . $fileName;
if (!is_readable($filePath)) {
if (!touch($filePath)) {
self::error(sprintf('Could\'t create "%s" in the log directory.', $fileName));

return false;
}
}

if (count($arguments) === 0) {
self::error(__METHOD__ . ': log entry must be present.');

return false;
}

return self::common($arguments[0], $fileName);
}

/**
* Set timestamp format
*
Expand Down Expand Up @@ -158,7 +201,7 @@ public static function common($entry, $logFileName)
/**
* Add an entry into "access.log"
*
* @param string $entry
* @param string $entry
* @return bool
*/
public static function access($entry)
Expand All @@ -177,7 +220,7 @@ public static function access($entry)
/**
* Add an entry into "error.log"
*
* @param string $entry
* @param string $entry
* @return bool
*/
public static function error($entry)
Expand All @@ -192,7 +235,7 @@ public static function error($entry)
/**
* Add an entry into "404.log"
*
* @param string $entry
* @param string $entry
* @return bool
*/
public static function error404($entry)
Expand All @@ -207,7 +250,7 @@ public static function error404($entry)
/**
* Add an entry into "recaptcha.log"
*
* @param string $entry
* @param string $entry
* @return bool
*/
public static function recaptcha($entry)
Expand All @@ -222,7 +265,7 @@ public static function recaptcha($entry)
/**
* Add an entry into "spamx.log"
*
* @param string $entry
* @param string $entry
* @return bool
*/
public static function spamx($entry)
Expand Down

0 comments on commit 641f51f

Please sign in to comment.