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:
Andy Dixon
2024-11-12 21:20:46 +00:00
parent 94f1634fc2
commit d0c38378b6
13 changed files with 581 additions and 242 deletions
+46
View File
@@ -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);
}
}