Security: verwijder hardcoded wachtwoord, voeg random-wachtwoord-generator toe bij eerste installatie

This commit is contained in:
2026-08-27 08:57:05 +00:00
parent 6485f693dc
commit 74612aefbb
55 changed files with 6019 additions and 876 deletions
+119 -43
View File
@@ -1,27 +1,75 @@
<?php
/**
* Simple Logger Class for CodePress CMS
*
* Provides structured logging with log levels and file output.
*
* @package CodePress
* @version 1.0.0
* Eenvoudige logger voor CodePress CMS.
*
* Voorziet in gestructureerde logging met loglevels en bestandsuitvoer.
* Logregels worden naar een tekstbestand geschreven en, indien aanwezig,
* tevens door de dynamische LogManager gerouteerd.
*
* @since 2.6.4
*/
class Logger {
/**
* Loglevel voor debug-boodschappen.
*
* @since 2.6.4
* @var string
*/
const DEBUG = 'DEBUG';
/**
* Loglevel voor informatieve boodschappen.
*
* @since 2.6.4
* @var string
*/
const INFO = 'INFO';
/**
* Loglevel voor waarschuwingen.
*
* @since 2.6.4
* @var string
*/
const WARNING = 'WARNING';
/**
* Loglevel voor fouten.
*
* @since 2.6.4
* @var string
*/
const ERROR = 'ERROR';
/**
* Pad naar het logbestand, of null indien nog niet geïnitialiseerd.
*
* @since 2.6.4
* @var string|null
*/
private static $logFile = null;
/**
* Of debug-logging actief is.
*
* @since 2.6.4
* @var bool
*/
private static $debugMode = false;
/**
* Initialize logger
*
* @param string $logFile Path to log file
* @param bool $debugMode Enable debug logging
* Initialiseert de logger.
*
* Stelt het pad naar het logbestand in en zorgt dat de bijbehorende
* map bestaat. Indien geen pad wordt opgegeven valt de logger terug
* op een standaardpad onder de core-map.
*
* @since 2.6.4
*
* @param string|null $logFile Pad naar het logbestand. Default null (standaardlocatie).
* @param bool $debugMode Of debug-logging actief is. Default false.
* @return void
*/
public static function init($logFile = null, $debugMode = false) {
if ($logFile === null) {
@@ -39,10 +87,13 @@ class Logger {
}
/**
* Log debug message (only in debug mode)
*
* @param string $message Message to log
* @param array $context Additional context
* Logt een debug-boodschap (enkel in debug-modus).
*
* @since 2.6.4
*
* @param string $message Boodschap die gelogd moet worden.
* @param array $context Aanvullende contextuele data. Default lege array.
* @return void
*/
public static function debug($message, $context = []) {
if (self::$debugMode) {
@@ -51,41 +102,59 @@ class Logger {
}
/**
* Log info message
*
* @param string $message Message to log
* @param array $context Additional context
* Logt een informatieve boodschap.
*
* @since 2.6.4
*
* @param string $message Boodschap die gelogd moet worden.
* @param array $context Aanvullende contextuele data. Default lege array.
* @return void
*/
public static function info($message, $context = []) {
self::write(self::INFO, $message, $context);
}
/**
* Log warning message
*
* @param string $message Message to log
* @param array $context Additional context
* Logt een waarschuwing.
*
* @since 2.6.4
*
* @param string $message Boodschap die gelogd moet worden.
* @param array $context Aanvullende contextuele data. Default lege array.
* @return void
*/
public static function warning($message, $context = []) {
self::write(self::WARNING, $message, $context);
}
/**
* Log error message
*
* @param string $message Message to log
* @param array $context Additional context
* Logt een fout.
*
* @since 2.6.4
*
* @param string $message Boodschap die gelogd moet worden.
* @param array $context Aanvullende contextuele data. Default lege array.
* @return void
*/
public static function error($message, $context = []) {
self::write(self::ERROR, $message, $context);
}
/**
* Write log entry to file
*
* @param string $level Log level
* @param string $message Message to log
* @param array $context Additional context
* Schrijft een logregel naar het bestand en routeert deze door LogManager.
*
* De context-array wordt als JSON aan de logregel toegevoegd. Fouten bij
* het schrijven worden gesilenced (graceful degradation). Wanneer de
* LogManager class beschikbaar is, wordt de entry tevens naar de
* dynamische log gestuurd (errors/warnings naar EVENT_ERRORS, verder
* naar EVENT_SYSTEM).
*
* @since 2.6.4
*
* @param string $level Loglevel (DEBUG, INFO, WARNING, ERROR).
* @param string $message Boodschap die gelogd moet worden.
* @param array $context Aanvullende contextuele data. Default lege array.
* @return void
*/
private static function write($level, $message, $context = []) {
if (self::$logFile === null) {
@@ -109,18 +178,22 @@ class Logger {
}
/**
* Get log file path
*
* @return string Log file path
* Geeft het pad naar het logbestand.
*
* @since 2.6.4
*
* @return string|null Pad naar het logbestand of null indien niet geïnitialiseerd.
*/
public static function getLogFile() {
return self::$logFile;
}
/**
* Clear log file
*
* @return bool Success status
* Verwijdert het logbestand.
*
* @since 2.6.4
*
* @return bool True indien het bestand succesvol verwijderd is, anders false.
*/
public static function clear() {
if (self::$logFile && file_exists(self::$logFile)) {
@@ -130,13 +203,16 @@ class Logger {
}
/**
* Get last N lines from log file
* Geeft de laatste N regels uit het logbestand.
*
* Reads the file backwards in chunks so large log files never have to be
* loaded into memory in their entirety.
* Leest het bestand achterwaarts in chunks zodat grote logbestanden
* nooit volledig in het geheugen geladen hoeven te worden. De regels
* worden inclusief afsluitende newlines teruggegeven, oudste eerst.
*
* @param int $lines Number of lines to retrieve
* @return array Log lines (including trailing newlines, oldest first)
* @since 2.6.4
*
* @param int $lines Aantal terug te halen regels. Default 100.
* @return array<string> Logregels (oudste eerst) of lege array indien niet beschikbaar.
*/
public static function tail($lines = 100) {
if (!self::$logFile || !file_exists(self::$logFile)) {