2026-09-21 15:25:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Plugin\fp_altcha_spamschutz;
|
|
|
|
|
|
|
|
|
|
use JTL\Events\Dispatcher;
|
|
|
|
|
use JTL\Plugin\Bootstrapper;
|
|
|
|
|
use JTL\Plugin\PluginInterface;
|
|
|
|
|
use JTL\Shop;
|
|
|
|
|
use Plugin\fp_altcha_spamschutz\src\Handler\TemplateHandler;
|
|
|
|
|
use Plugin\fp_altcha_spamschutz\src\Handler\ValidationHandler;
|
|
|
|
|
use Plugin\fp_altcha_spamschutz\src\Service\AltchaService;
|
|
|
|
|
|
|
|
|
|
require_once __DIR__ . '/src/Vendor/AltchaOrg/Altcha/V1/Hasher/HasherInterface.php';
|
|
|
|
|
require_once __DIR__ . '/src/Vendor/AltchaOrg/Altcha/V1/Hasher/Algorithm.php';
|
|
|
|
|
require_once __DIR__ . '/src/Vendor/AltchaOrg/Altcha/V1/Hasher/Hasher.php';
|
|
|
|
|
require_once __DIR__ . '/src/Vendor/AltchaOrg/Altcha/V1/BaseChallengeOptions.php';
|
|
|
|
|
require_once __DIR__ . '/src/Vendor/AltchaOrg/Altcha/V1/ChallengeOptions.php';
|
|
|
|
|
require_once __DIR__ . '/src/Vendor/AltchaOrg/Altcha/V1/CheckChallengeOptions.php';
|
|
|
|
|
require_once __DIR__ . '/src/Vendor/AltchaOrg/Altcha/V1/Challenge.php';
|
|
|
|
|
require_once __DIR__ . '/src/Vendor/AltchaOrg/Altcha/V1/Payload.php';
|
|
|
|
|
require_once __DIR__ . '/src/Vendor/AltchaOrg/Altcha/V1/Solution.php';
|
|
|
|
|
require_once __DIR__ . '/src/Vendor/AltchaOrg/Altcha/V1/Obfuscator.php';
|
|
|
|
|
require_once __DIR__ . '/src/Vendor/AltchaOrg/Altcha/V1/ServerSignaturePayload.php';
|
|
|
|
|
require_once __DIR__ . '/src/Vendor/AltchaOrg/Altcha/V1/ServerSignatureVerificationData.php';
|
|
|
|
|
require_once __DIR__ . '/src/Vendor/AltchaOrg/Altcha/V1/ServerSignatureVerification.php';
|
|
|
|
|
require_once __DIR__ . '/src/Vendor/AltchaOrg/Altcha/V1/Altcha.php';
|
|
|
|
|
require_once __DIR__ . '/src/Service/AltchaService.php';
|
|
|
|
|
require_once __DIR__ . '/src/Handler/TemplateHandler.php';
|
|
|
|
|
require_once __DIR__ . '/src/Handler/ValidationHandler.php';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrap-Klasse fuer das Plugin fp_altcha_spamschutz.
|
|
|
|
|
*
|
|
|
|
|
* Setzt einen selbst gehosteten, quelloffenen Proof-of-Work-Spamschutz (ALTCHA, MIT-Lizenz) fuer
|
2026-09-21 19:24:59 +02:00
|
|
|
* die Kundenregistrierung, die Newsletter-Anmeldung und das Kontaktformular ein. Keine Daten
|
|
|
|
|
* verlassen den eigenen Server. Bewusst ohne Google reCAPTCHA und ohne Umleitung ueber Cloudflare
|
|
|
|
|
* oder aehnliche Dienste.
|
2026-09-21 15:25:08 +02:00
|
|
|
*
|
2026-09-21 19:24:59 +02:00
|
|
|
* Hintergrund/Anlass: ein Bot-Problem bei einem Kunden (Fake-Anmeldungen im Shop). Andere
|
|
|
|
|
* getestete Ansaetze konnten das dort verwendete Muster
|
|
|
|
|
* ("Test"/"Test User" in Vorname/Nachname/Ort/Strasse, aber echte Drittanbieter-E-Mail-Adressen)
|
|
|
|
|
* strukturell nicht erkennen, weil deren Wortlisten-Pruefung nur auf Kommentar-/
|
|
|
|
|
* Nachrichtenfelder wirkt, die das Registrierungsformular gar nicht besitzt.
|
2026-09-21 15:25:08 +02:00
|
|
|
*/
|
|
|
|
|
class Bootstrap extends Bootstrapper
|
|
|
|
|
{
|
|
|
|
|
public function boot(Dispatcher $dispatcher): void
|
|
|
|
|
{
|
|
|
|
|
parent::boot($dispatcher);
|
|
|
|
|
|
|
|
|
|
if (!Shop::isFrontend()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Die komplette Einrichtung ist defensiv umschlossen: boot() laeuft bei JEDEM
|
|
|
|
|
// Frontend-Aufruf, noch bevor irgendeine Seite gerendert wird. Ein Fehler hier (z. B.
|
|
|
|
|
// weil das Plugin gerade erst installiert und noch nicht konfiguriert wurde) darf
|
|
|
|
|
// niemals den gesamten Shop lahmlegen.
|
|
|
|
|
try {
|
|
|
|
|
/** @var PluginInterface $plugin */
|
|
|
|
|
$plugin = $this->getPlugin();
|
|
|
|
|
|
|
|
|
|
$altchaService = new AltchaService($plugin);
|
|
|
|
|
$templateHandler = new TemplateHandler($plugin, $altchaService);
|
|
|
|
|
$validationHandler = new ValidationHandler($altchaService);
|
|
|
|
|
|
|
|
|
|
// Frueheste moegliche Pruefung der Newsletter-Anmeldung: laeuft direkt hier, noch
|
|
|
|
|
// bevor JTL-Shop das $_POST verarbeitet. Siehe ValidationHandler::guardNewsletterSubmission().
|
|
|
|
|
$validationHandler->guardNewsletterSubmission();
|
|
|
|
|
|
2026-09-21 19:24:59 +02:00
|
|
|
// Dieselbe fruehe Pruefung fuer das Kontaktformular. Siehe
|
|
|
|
|
// ValidationHandler::guardContactSubmission().
|
|
|
|
|
$validationHandler->guardContactSubmission();
|
|
|
|
|
|
2026-09-21 15:25:08 +02:00
|
|
|
// Widget (Container + Skript) in Registrierungs- und Newsletter-Formular einfuegen.
|
|
|
|
|
$dispatcher->listen(
|
|
|
|
|
'shop.hook.' . \HOOK_SMARTY_OUTPUTFILTER,
|
|
|
|
|
[$templateHandler, 'generalTemplateIntegration']
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Registrierung: Plausibilitaetspruefung nach Formularabsendung.
|
|
|
|
|
$dispatcher->listen(
|
|
|
|
|
'shop.hook.' . \HOOK_REGISTRIEREN_PAGE_REGISTRIEREN_PLAUSI,
|
|
|
|
|
[$validationHandler, 'checkRegistrationPlausibility']
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Newsletter: zusaetzliche Absicherung kurz vor dem Speichern des Empfaengers.
|
|
|
|
|
if (\defined('HOOK_NEWSLETTER_PAGE_EMPFAENGEREINTRAGEN')) {
|
|
|
|
|
$dispatcher->listen(
|
|
|
|
|
'shop.hook.' . \HOOK_NEWSLETTER_PAGE_EMPFAENGEREINTRAGEN,
|
|
|
|
|
[$validationHandler, 'checkNewsletterRecipient']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
error_log('[fp_altcha_spamschutz] Fehler beim Initialisieren des Plugins: ' . $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|