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
+90
View File
@@ -1,14 +1,41 @@
<?php
/**
* Dashboard plugin: toont CMS-, content- en plugin-overzicht in het beheer.
*
* Systeem-plugin die een overzichtspagina biedt met site-informatie,
* content-statistieken en een lijst van geïnstalleerde plugins.
*
* @since 2.6.4
*/
class Dashboard
{
/**
* Plugin-API instantie voor communicatie met de CMS-core.
*
* @since 2.6.4
* @var PluginAPIInterface|null
*/
private ?PluginAPIInterface $api = null;
/**
* Stelt de Plugin-API instantie in.
*
* @since 2.6.4
* @param PluginAPIInterface $api De Plugin-API instantie.
* @return void
*/
public function setAPI(PluginAPIInterface $api): void
{
$this->api = $api;
}
/**
* Geeft de plugin-configuratie terug.
*
* @since 2.6.4
* @return array<string, mixed> Plugin-configuratie met title, viewable en type.
*/
public function getConfig(): array
{
return [
@@ -18,6 +45,12 @@ class Dashboard
];
}
/**
* Geeft de admin-menu-items voor deze plugin.
*
* @since 2.6.4
* @return array<int, array<string, mixed>> Lijst met admin-menu-item configuraties.
*/
public function getAdminMenu(): array
{
return [
@@ -33,6 +66,16 @@ class Dashboard
];
}
/**
* Verwerkt een admin-route en toont het dashboard.
*
* Geeft een HTML-weergave van site-informatie, content-statistieken
* en een plugin-overzicht.
*
* @since 2.6.4
* @param string $action De uit te voeren actie.
* @return string|null De HTML-uitvoer van het dashboard, of null.
*/
public function handleAdminRoute(string $action): ?string
{
$siteConfig = $this->getSiteConfig();
@@ -147,6 +190,12 @@ class Dashboard
return ob_get_clean();
}
/**
* Haalt de site-configuratie op via de AdminPluginAPI.
*
* @since 2.6.4
* @return array<string, mixed> De site-configuratie, of een lege array.
*/
private function getSiteConfig(): array
{
if ($this->api === null) {
@@ -159,6 +208,14 @@ class Dashboard
return [];
}
/**
* Bepaalt het type (system of content) van een plugin door het hoofdbestand te lezen.
*
* @since 2.6.4
* @param string $pluginDir Pad naar de plugin-map.
* @param string $pluginName Naam van de plugin.
* @return string Het plugin-type ('system' of 'content').
*/
private function getPluginType(string $pluginDir, string $pluginName): string
{
$pluginFile = $pluginDir . '/' . $pluginName . '.php';
@@ -173,6 +230,16 @@ class Dashboard
return 'content';
}
/**
* Telt het aantal bestanden in een map, eventueel gefilterd op extensie.
*
* Slaat verborgen en met '-' voorafgegane bestanden en mappen over.
*
* @since 2.6.4
* @param string $dir Pad naar de map die doorzocht moet worden.
* @param string[] $extensions Optionele lijst van toegestane extensies.
* @return int Het aantal gevonden bestanden.
*/
private function countFiles(string $dir, array $extensions = []): int
{
if (!is_dir($dir)) return 0;
@@ -197,6 +264,15 @@ class Dashboard
return $count;
}
/**
* Telt het aantal submappen in een map, recursief.
*
* Slaat verborgen en met '-' voorafgegane mappen over.
*
* @since 2.6.4
* @param string $dir Pad naar de map die doorzocht moet worden.
* @return int Het aantal gevonden submappen.
*/
private function countDirs(string $dir): int
{
if (!is_dir($dir)) return 0;
@@ -215,6 +291,13 @@ class Dashboard
return $count;
}
/**
* Berekent de totale bestandsgrootte in bytes van alle bestanden in een map.
*
* @since 2.6.4
* @param string $dir Pad naar de map die doorzocht moet worden.
* @return int De totale grootte in bytes.
*/
private function dirSize(string $dir): int
{
if (!is_dir($dir)) return 0;
@@ -230,6 +313,13 @@ class Dashboard
return $size;
}
/**
* Formateert een byte-grootte naar een leesbare string met eenheid.
*
* @since 2.6.4
* @param int $bytes Het aantal bytes.
* @return string De geformatteerde grootte met eenheid (bijv. '1.5 MB').
*/
private function formatSize(int $bytes): string
{
if ($bytes <= 0) return '0 B';