Massive refactor of code into classes, improve security on the image/file upload handler. Clean up the init.php into a config.php and refactor everything else to work around it.
Resolves issues #13 #14 and #16
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace NeoCMS;
|
||||
|
||||
class Logger
|
||||
{
|
||||
private $auditEnabled;
|
||||
private $logsDir;
|
||||
|
||||
public function __construct($auditEnabled)
|
||||
{
|
||||
$this->auditEnabled = $auditEnabled;
|
||||
|
||||
$this->logsDir = __DIR__ . '/../../logs';
|
||||
$this->logsDir = rtrim($this->logsDir, '/\\') . DIRECTORY_SEPARATOR;
|
||||
|
||||
// Ensure the logs directory exists
|
||||
if (!is_dir($this->logsDir)) {
|
||||
if (!mkdir($this->logsDir, 0755, true)) {
|
||||
throw new \Exception('Failed to create logs directory: ' . $this->logsDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an entry to the log
|
||||
* @param $message
|
||||
* @param $user
|
||||
* @return void
|
||||
*/
|
||||
public function write($message, $user): void
|
||||
{
|
||||
if (!$this->auditEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
$logFile = $this->logsDir . date('Y-m-d') . '-audit.txt';
|
||||
$entry = sprintf(
|
||||
"[%s]\tUser: %s\t%s\n",
|
||||
date('Y-m-d H:i:s'),
|
||||
$user,
|
||||
trim($message)
|
||||
);
|
||||
|
||||
file_put_contents($logFile, $entry, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user