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
+225 -38
View File
@@ -1,18 +1,51 @@
<?php
/**
* Front-end plugin-API voor content-plugins.
*
* Biedt toegang tot de CodePressCMS-instance, pagina-informatie, menu, zoekresultaten,
* vertalingen en bestandsoperaties binnen de front-end context.
*
* @since 2.6.4
*/
class CMSAPI implements PluginAPIInterface
{
/**
* De CodePressCMS-hoofdinstantie.
*
* @since 2.6.4
* @var CodePressCMS
*/
private CodePressCMS $cms;
/**
* De front-end PluginManager-instantie, optioneel via setPluginManager geïnjecteerd.
*
* @since 2.6.4
* @var PluginManager|null
*/
private ?PluginManager $pluginManager = null;
/**
* Construeer een CMSAPI-instantie met de opgegeven CodePressCMS.
*
* @since 2.6.4
*
* @param CodePressCMS $cms De CodePressCMS-hoofdinstantie.
*/
public function __construct(CodePressCMS $cms)
{
$this->cms = $cms;
}
/**
* Inject the front-end PluginManager so content plugins can resolve
* their own translations through the same fallback chain.
* Injecteer de front-end PluginManager zodat content-plugins hun eigen
* vertalingen via dezelfde fallback-keten kunnen resolven.
*
* @since 2.6.4
*
* @param PluginManager $pm De front-end PluginManager-instantie.
* @return void
*/
public function setPluginManager(PluginManager $pm): void
{
@@ -20,7 +53,11 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get current page information
* Haal de informatie van de huidige pagina op.
*
* @since 2.6.4
*
* @return array<string,mixed> Pagina-informatie van de huidige pagina.
*/
public function getCurrentPage(): array
{
@@ -28,7 +65,11 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get current page title
* Haal de titel van de huidige pagina op.
*
* @since 2.6.4
*
* @return string De titel van de huidige pagina, of lege string.
*/
public function getCurrentPageTitle(): string
{
@@ -37,7 +78,11 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get current page content
* Haal de inhoud van de huidige pagina op.
*
* @since 2.6.4
*
* @return string De HTML-inhoud van de huidige pagina, of lege string.
*/
public function getCurrentPageContent(): string
{
@@ -46,7 +91,11 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get current page URL
* Haal de URL van de huidige pagina op.
*
* @since 2.6.4
*
* @return string De URL van de huidige pagina inclusief query-parameters.
*/
public function getCurrentPageUrl(): string
{
@@ -56,7 +105,11 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get menu structure
* Haal de menustructuur op.
*
* @since 2.6.4
*
* @return array<int,array<string,mixed>> De menustructuur.
*/
public function getMenu(): array
{
@@ -64,7 +117,13 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get configuration value
* Haal een configuratiewaarde op via dot-notatie.
*
* @since 2.6.4
*
* @param string $key Configuratie-sleutel in dot-notatie (bijv. 'language.default').
* @param mixed $default Standaardwaarde indien de sleutel niet bestaat.
* @return mixed De gevonden waarde of $default indien niet gevonden.
*/
public function getConfig(string $key, $default = null)
{
@@ -82,7 +141,70 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get translation
* Haal de project-rootdirectory op (absoluut, genormaliseerd).
*
* @since 2.6.4
*
* @return string Absoluut pad naar de project-root.
*/
public function getProjectRoot(): string
{
return dirname(__DIR__, 3);
}
/**
* Haal het pad naar de contentdirectory op (absoluut, genormaliseerd).
*
* De CMS-config lost relatieve content_dir-waarden al op
* (zie cms/core/config.php), dus deze wordt as-is teruggegeven.
*
* @since 2.6.4
*
* @return string Absoluut pad naar de contentdirectory.
*/
public function getContentDir(): string
{
return rtrim($this->cms->config['content_dir'] ?? ($this->getProjectRoot() . '/content'), '/');
}
/**
* Haal het pad naar de pluginsdirectory op (absoluut, genormaliseerd).
*
* @since 2.6.4
*
* @return string Absoluut pad naar de pluginsdirectory.
*/
public function getPluginsDir(): string
{
return $this->getProjectRoot() . '/plugins';
}
/**
* Haal de versie-informatie uit version.php op.
*
* @since 2.6.4
*
* @return array<string,mixed> Versie-informatie met minimaal de sleutel 'version'.
*/
public function getVersionInfo(): array
{
$versionFile = $this->getProjectRoot() . '/version.php';
if (file_exists($versionFile)) {
$data = include $versionFile;
if (is_array($data)) {
return $data;
}
}
return ['version' => '0.0.0'];
}
/**
* Haal een vertaling op voor de opgegeven sleutel.
*
* @since 2.6.4
*
* @param string $key Vertaalsleutel.
* @return string De vertaalde string, of $key indien niet gevonden.
*/
public function translate(string $key): string
{
@@ -90,7 +212,11 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get current language
* Haal de huidige content-taal op.
*
* @since 2.6.4
*
* @return string De huidige taalcode (bijv. 'nl', 'en').
*/
public function getCurrentLanguage(): string
{
@@ -98,7 +224,11 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Check if user is on homepage
* Controleer of de gebruiker zich op de homepage bevindt.
*
* @since 2.6.4
*
* @return bool True indien de huidige pagina de default_page is.
*/
public function isHomepage(): bool
{
@@ -108,7 +238,11 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get file info for current page
* Haal de bestandsinformatie van de huidige pagina op.
*
* @since 2.6.4
*
* @return array<string,mixed>|null Bestandsinformatie of null indien niet aanwezig.
*/
public function getCurrentPageFileInfo(): ?array
{
@@ -117,7 +251,11 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get breadcrumb data
* Haal de breadcrumb-HTML op.
*
* @since 2.6.4
*
* @return string De gegenereerde breadcrumb-HTML.
*/
public function getBreadcrumb(): string
{
@@ -125,7 +263,11 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Check if content directory has content
* Controleer of de contentdirectory inhoud bevat.
*
* @since 2.6.4
*
* @return bool True indien de contentdirectory niet leeg is.
*/
public function hasContent(): bool
{
@@ -133,7 +275,11 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get search results if searching
* Haal de zoekresultaten op indien een zoekopdracht actief is.
*
* @since 2.6.4
*
* @return array<int,array<string,mixed>> De zoekresultaten, of een lege array.
*/
public function getSearchResults(): array
{
@@ -144,7 +290,11 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Check if currently searching
* Controleer of momenteel een zoekopdracht wordt uitgevoerd.
*
* @since 2.6.4
*
* @return bool True indien de search-query-parameter aanwezig is.
*/
public function isSearching(): bool
{
@@ -152,7 +302,11 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get available languages
* Haal de beschikbare talen op.
*
* @since 2.6.4
*
* @return array<int,string> Lijst met beschikbare taalcodes.
*/
public function getAvailableLanguages(): array
{
@@ -160,7 +314,13 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Create URL for page
* Maak een URL voor een pagina.
*
* @since 2.6.4
*
* @param string $page Pagina-identifier.
* @param string|null $lang Taalcode; standaard de huidige content-taal.
* @return string De gegenereerde pagina-URL met query-parameters.
*/
public function createUrl(string $page, ?string $lang = null): string
{
@@ -169,7 +329,15 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Execute PHP file and capture output
* Voer een PHP-bestand uit en vang de output op.
*
* Het bestand moet binnen de CMS-directory liggen om willekeurige
* file-inclusion te voorkomen.
*
* @since 2.6.4
*
* @param string $filePath Absoluut pad naar het PHP-bestand.
* @return string De opgevangen output, of lege string indien ongeldig.
*/
public function executePhpFile(string $filePath): string
{
@@ -190,7 +358,12 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get content from PHP/HTML/Markdown file
* Haal de inhoud op uit een PHP-, HTML- of Markdown-bestand.
*
* @since 2.6.4
*
* @param string $filePath Pad naar het bestand.
* @return string De bestandsinhoud (gerenderd indien PHP/Markdown), of lege string.
*/
public function getFileContent(string $filePath): string
{
@@ -215,7 +388,12 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Check if file exists in content directory
* Controleer of een bestand in de contentdirectory bestaat.
*
* @since 2.6.4
*
* @param string $filename Bestandsnaam relatief ten opzichte van de contentdirectory.
* @return bool True indien het bestand bestaat.
*/
public function contentFileExists(string $filename): bool
{
@@ -224,9 +402,11 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get all content entries (mappen + bestanden) as a list of entry arrays.
* Haal alle content-items (mappen + bestanden) op als lijst met entry-arrays.
*
* @return array List of ['path' => ..., 'title' => ..., 'type' => ...]
* @since 2.6.4
*
* @return array<int,array<string,mixed>> Lijst met entries ['path' => ..., 'title' => ..., 'type' => ...].
*/
public function getAllPages(): array
{
@@ -234,10 +414,13 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get the author metadata for the current page.
* Returns author_name, author_email and created from the page frontmatter.
* Haal de auteursmetadata van de huidige pagina op.
*
* @return array Author metadata with keys: author_name, author_email, created
* Geeft author_name, author_email en created terug uit de pagina-frontmatter.
*
* @since 2.6.4
*
* @return array<string,string> Auteursmetadata met sleutels: author_name, author_email, created.
*/
public function getPageAuthor(): array
{
@@ -251,15 +434,17 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Get the translations for a plugin in the front-end context.
* Haal de vertalingen voor een plugin op in de front-end context.
*
* Content plugins follow the current content language. Fallback chain
* (handled by PluginManager): requested language -> plugin
* default_language -> empty array.
* Content-plugins volgen de huidige content-taal. Fallback-keten
* (afgehandeld door PluginManager): aangevraagde taal ->
* default_language van de plugin -> lege array.
*
* @param string $pluginName Plugin directory name
* @param string|null $lang Override language; defaults to the current content language
* @return array Translations [key => value]
* @since 2.6.4
*
* @param string $pluginName Plugin-directorynaam.
* @param string|null $lang Override-taal; standaard de huidige content-taal.
* @return array<string,string> Vertalingen als [key => value].
*/
public function getPluginTranslations(string $pluginName, ?string $lang = null): array
{
@@ -271,12 +456,14 @@ class CMSAPI implements PluginAPIInterface
}
/**
* Translate a single key for a plugin in the front-end context.
* Vertaal een enkele sleutel voor een plugin in de front-end context.
*
* @param string $key Translation key
* @param string $pluginName Plugin directory name
* @param string|null $lang Override language; defaults to the current content language
* @return string Translated string, or $key if not found
* @since 2.6.4
*
* @param string $key Vertaalsleutel.
* @param string $pluginName Plugin-directorynaam.
* @param string|null $lang Override-taal; standaard de huidige content-taal.
* @return string Vertaalde string, of $key indien niet gevonden.
*/
public function t(string $key, string $pluginName, ?string $lang = null): string
{