248 lines
7.1 KiB
PHP
248 lines
7.1 KiB
PHP
<?php
|
|
// ===========================================
|
|
// FUNKTIONEN FÜR DISPOSABLE EMAIL CHECK
|
|
// ===========================================
|
|
|
|
function is_disposable_email($email, $blocklist_path = null) {
|
|
// Standard-Pfad zur lokalen Blocklist-Datei
|
|
if (!$blocklist_path) {
|
|
$blocklist_path = __DIR__ . '/disposable_email_blocklist.conf';
|
|
}
|
|
|
|
// E-Mail-Format prüfen
|
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
return false;
|
|
}
|
|
|
|
// Lade die Blocklist falls nötig
|
|
if (!file_exists($blocklist_path)) {
|
|
download_blocklist($blocklist_path);
|
|
}
|
|
|
|
// Lese alle Domains aus der Datei
|
|
$disposable_domains = file($blocklist_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
|
|
// Extrahiere Domain aus der E-Mail-Adresse
|
|
$email_parts = explode('@', trim($email));
|
|
if (count($email_parts) != 2) {
|
|
return false;
|
|
}
|
|
|
|
$domain = strtolower($email_parts[1]);
|
|
// echo $domain ."\n";
|
|
|
|
// Prüfe ob Domain in der Liste steht
|
|
$ret = in_array($domain, $disposable_domains);
|
|
// echo "in_array: " .$ret ."<br>" ;
|
|
|
|
// Check, ob für Domain (mindestens) ein MX-Record existiert
|
|
if ($ret === false ) {
|
|
// MX-Record(s) abholen
|
|
getmxrr($domain, $mx_records, $mx_weight);
|
|
|
|
$mxs =[];
|
|
// Array zusammenstellen für Sortierung
|
|
for($i=0;$i<count($mx_records);$i++){
|
|
$mxs[$mx_records[$i]] = $mx_weight[$i];
|
|
}
|
|
|
|
// Sortieren
|
|
$records = [];
|
|
if (count($mxs) > 0) {
|
|
asort ($mxs);
|
|
// Erforderliche Daten stehen im Key => nach Array "records" schreiben
|
|
$records = array_keys($mxs);
|
|
}
|
|
|
|
if (count($records) == 0) {
|
|
$ret = true;
|
|
}
|
|
}
|
|
|
|
return ($ret);
|
|
}
|
|
|
|
function download_blocklist($file_path) {
|
|
// Alternative Liste: $url = 'https://raw.githubusercontent.com/disposable-email-domains/disposable-email-domains/main/disposable_email_blocklist.conf';
|
|
$url = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.txt';
|
|
|
|
echo "Lade Blocklist herunter...\n";
|
|
|
|
$content = file_get_contents($url);
|
|
if ($content === false) {
|
|
die("FEHLER: Konnte Blocklist nicht herunterladen von: $url\n");
|
|
}
|
|
|
|
// Zusätzliche lokale Liste der nicht zugelassenen Domains
|
|
$localContent = '';
|
|
if (file_exists(__DIR__ . '/localdomains.conf')) {
|
|
$localContent = file_get_contents(__DIR__ ."/localdomains.conf");
|
|
}
|
|
|
|
// Listen kombinieren
|
|
$content = $content ."\n" .$localContent;
|
|
|
|
if (file_put_contents($file_path, $content) === false) {
|
|
die("FEHLER: Konnte Blocklist nicht speichern: $file_path\n");
|
|
}
|
|
|
|
echo "Blocklist erfolgreich heruntergeladen: $file_path\n";
|
|
}
|
|
|
|
function update_blocklist_if_needed($blocklist_path = null, $max_age_hours = 1) {
|
|
if (!$blocklist_path) {
|
|
$blocklist_path = __DIR__ . '/disposable_email_blocklist.conf';
|
|
}
|
|
|
|
// Prüfe ob Datei existiert und wie alt sie ist
|
|
if (!file_exists($blocklist_path)) {
|
|
download_blocklist($blocklist_path);
|
|
return true;
|
|
}
|
|
|
|
$file_age = time() - filemtime($blocklist_path);
|
|
$max_age_seconds = $max_age_hours * 3600;
|
|
|
|
if ($file_age > $max_age_seconds) {
|
|
echo "Blocklist ist " . round($file_age / 3600, 1) . " Stunden alt. Aktualisiere...\n";
|
|
download_blocklist($blocklist_path);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
function filter_disposable_emails($emails, $blocklist_path = null) {
|
|
$valid_emails = array();
|
|
|
|
foreach ($emails as $email) {
|
|
if (!is_disposable_email($email, $blocklist_path)) {
|
|
$valid_emails[] = $email;
|
|
}
|
|
}
|
|
|
|
return $valid_emails;
|
|
}
|
|
|
|
function get_email_domain($email) {
|
|
$email_parts = explode('@', trim($email));
|
|
return count($email_parts) === 2 ? strtolower($email_parts[1]) : '';
|
|
}
|
|
|
|
function validate_email_form($email) {
|
|
// Umfassende Validierung für Formulare
|
|
if (empty($email)) {
|
|
return array('valid' => false, 'error' => 'E-Mail-Adresse ist erforderlich');
|
|
}
|
|
|
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
return array('valid' => false, 'error' => 'Ungültige E-Mail-Adresse');
|
|
}
|
|
|
|
if (is_disposable_email($email)) {
|
|
return array('valid' => false, 'error' => 'Wegwerf-E-Mail-Adressen sind nicht erlaubt');
|
|
}
|
|
|
|
return array('valid' => true, 'error' => null);
|
|
}
|
|
|
|
// ===========================================
|
|
// BEISPIELE:
|
|
// ===========================================
|
|
|
|
// Test-E-Mails
|
|
$test_emails = array(
|
|
'user@gmail.com', // Legitim
|
|
'test@mailinator.com', // Disposable
|
|
'demo@10minutemail.com', // Disposable
|
|
'contact@tempmail.org', // Disposable
|
|
'roland.keck@t-onlin.de',
|
|
'roland.keck@conlicom.de' // Legitim
|
|
);
|
|
|
|
// Blocklist aktualisieren falls nötig (alle 24h)
|
|
$updated = update_blocklist_if_needed();
|
|
if ($updated) {
|
|
echo "Blocklist wurde aktualisiert.<br>\n";
|
|
}
|
|
|
|
echo "<h3>E-Mail-Validierung:</h3>\n";
|
|
foreach ($test_emails as $email) {
|
|
if (is_disposable_email($email)) {
|
|
echo "❌ BLOCKIERT: $email ist eine Wegwerf-Adresse<br>\n";
|
|
} else {
|
|
echo "✅ ERLAUBT: $email<br>\n";
|
|
}
|
|
}
|
|
|
|
// Bulk-Filterung
|
|
//echo "<h3>Gefilterte Liste:</h3>\n";
|
|
//$valid_emails = filter_disposable_emails($test_emails);
|
|
//echo "Gültige E-Mails: " . implode(', ', $valid_emails) . "<br>\n";
|
|
|
|
// ===========================================
|
|
// FORMULAR-INTEGRATION:
|
|
// ===========================================
|
|
|
|
// In deinem Registrierungsformular:
|
|
if (isset($_POST['email'])) {
|
|
$email = trim($_POST['email']);
|
|
$validation = validate_email_form($email);
|
|
|
|
if ($validation['valid']) {
|
|
echo "✅ E-Mail-Adresse ist gültig: $email<br>\n";
|
|
// Hier: Registrierung fortsetzen...
|
|
} else {
|
|
echo "❌ " . $validation['error'] . "<br>\n";
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!-- EINFACHES TEST-FORMULAR -->
|
|
<form method="post">
|
|
<label>E-Mail-Adresse:</label>
|
|
<input type="email" name="email" required>
|
|
<button type="submit">Prüfen</button>
|
|
</form>
|
|
|
|
<?php
|
|
// ===========================================
|
|
// WEITERE HILFS-FUNKTIONEN:
|
|
// ===========================================
|
|
|
|
function count_disposable_domains($blocklist_path = null) {
|
|
if (!$blocklist_path) {
|
|
$blocklist_path = __DIR__ . '/disposable_email_blocklist.conf';
|
|
}
|
|
|
|
if (!file_exists($blocklist_path)) {
|
|
return 0;
|
|
}
|
|
|
|
$domains = file($blocklist_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
return count($domains);
|
|
}
|
|
|
|
function show_blocklist_info($blocklist_path = null) {
|
|
if (!$blocklist_path) {
|
|
$blocklist_path = __DIR__ . '/disposable_email_blocklist.conf';
|
|
}
|
|
|
|
if (file_exists($blocklist_path)) {
|
|
$count = count_disposable_domains($blocklist_path);
|
|
$age_hours = round((time() - filemtime($blocklist_path)) / 3600, 1);
|
|
|
|
echo "Blocklist-Info:<br>\n";
|
|
echo "- Anzahl Domains: $count<br>\n";
|
|
echo "- Alter: $age_hours Stunden<br>\n";
|
|
echo "- Datei: $blocklist_path<br>\n";
|
|
} else {
|
|
echo "Blocklist-Datei existiert noch nicht.<br>\n";
|
|
}
|
|
}
|
|
|
|
// Zeige Info über die Blocklist
|
|
echo "<h3>Blocklist-Status:</h3>\n";
|
|
show_blocklist_info();
|
|
?>
|