From 55fbbfd503a0c9f5320f8d26df26e0129544080d Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Sat, 9 Dec 2023 12:41:41 +0200 Subject: [PATCH] Added basic abuse monitoring and report (Spec 11) --- README.md | 2 +- automation/abusemonitor.php | 49 ++++++++-------- automation/abusereport.php | 111 ++++++++++++++++++++++++++++++++++++ automation/crontab.example | 3 + automation/helpers.php | 24 +++++++- 5 files changed, 161 insertions(+), 28 deletions(-) create mode 100644 automation/abusereport.php diff --git a/README.md b/README.md index 041489f..dbe7831 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Namingo is equipped with a comprehensive suite of features to meet the diverse n - **GDPR-Compliant Database Encryption**: Supports comprehensive database encryption to ensure GDPR compliance. For more details, see our [Encryption Guide](docs/encryption.md). -- **Automation Scripts**: Ensures the continuous and smooth operation of the registry by performing routine checks and operations. Advanced scripting capabilities also facilitate the generation of RDE deposits, the creation of ICANN's monthly reports, and ensure full compliance with other ICANN gTLD requirements for streamlined regulatory adherence. +- **Automation Scripts**: Ensures the continuous and smooth operation of the registry by performing routine checks and operations. Advanced scripting capabilities also facilitate the generation of RDE deposits, the creation of ICANN's monthly reports, Spec 11 abuse monitoring, and ensure full compliance with other ICANN gTLD requirements for streamlined regulatory adherence. ## Installation Instructions diff --git a/automation/abusemonitor.php b/automation/abusemonitor.php index 92eb7fb..e31ca65 100644 --- a/automation/abusemonitor.php +++ b/automation/abusemonitor.php @@ -28,34 +28,12 @@ Coroutine::create(function () use ($pool, $log) { try { $pdo = $pool->get(); $stmt = $pdo->query('SELECT name, clid FROM domain'); + // Get URLhaus data + $urlhausData = getUrlhausData(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $domain = $row['name']; - - if (checkSpamhaus($domain)) { - $userStmt = $pdo->prepare('SELECT user_id FROM registrar_users WHERE registrar_id = ?'); - $userStmt->execute([$row['clid']]); - $userData = $userStmt->fetch(PDO::FETCH_ASSOC); - - if ($userData) { - // Prepare INSERT statement to add a ticket - $insertStmt = $pdo->prepare('INSERT INTO support_tickets (id, user_id, category_id, subject, message, status, priority, reported_domain, nature_of_abuse, evidence, relevant_urls, date_of_incident, date_created, last_updated) VALUES (NULL, ?, 8, ?, ?, "Open", "High", ?, "Abuse", ?, ?, ?, CURRENT_TIMESTAMP(3), CURRENT_TIMESTAMP(3))'); - - // Execute the prepared statement with appropriate values - $insertStmt->execute([ - $userData['user_id'], // user_id - "Abuse Report for $domain", // subject - "Abuse detected for domain $domain.", // message - $domain, // reported_domain - "Link to Spamhaus", // evidence - "http://www.spamhaus.org/query/domain/$domain", // relevant_urls - date('Y-m-d H:i:s') // date_of_incident - ]); - } - } - // Get URLhaus data - $urlhausData = getUrlhausData(); $urlhausResult = checkUrlhaus($domain, $urlhausData); if ($urlhausResult) { @@ -79,6 +57,29 @@ Coroutine::create(function () use ($pool, $log) { ]); } } + + if (checkSpamhaus($domain)) { + $userStmt = $pdo->prepare('SELECT user_id FROM registrar_users WHERE registrar_id = ?'); + $userStmt->execute([$row['clid']]); + $userData = $userStmt->fetch(PDO::FETCH_ASSOC); + + if ($userData) { + // Prepare INSERT statement to add a ticket + $insertStmt = $pdo->prepare('INSERT INTO support_tickets (id, user_id, category_id, subject, message, status, priority, reported_domain, nature_of_abuse, evidence, relevant_urls, date_of_incident, date_created, last_updated) VALUES (NULL, ?, 8, ?, ?, "Open", "High", ?, "Abuse", ?, ?, ?, CURRENT_TIMESTAMP(3), CURRENT_TIMESTAMP(3))'); + + // Execute the prepared statement with appropriate values + $insertStmt->execute([ + $userData['user_id'], // user_id + "Abuse Report for $domain", // subject + "Abuse detected for domain $domain.", // message + $domain, // reported_domain + "Link to Spamhaus", // evidence + "http://www.spamhaus.org/query/domain/$domain", // relevant_urls + date('Y-m-d H:i:s') // date_of_incident + ]); + } + } + } $log->info('job finished successfully.'); } catch (PDOException $e) { diff --git a/automation/abusereport.php b/automation/abusereport.php new file mode 100644 index 0000000..18d53ba --- /dev/null +++ b/automation/abusereport.php @@ -0,0 +1,111 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, +]; +$logFilePath = '/var/log/namingo/abusereport.log'; +$log = setupLogger($logFilePath, 'Abuse_Report'); +$log->info('job started.'); + +try { + $dbh = new PDO($dsn, $c['db_username'], $c['db_password'], $options); +} catch (PDOException $e) { + $log->error('DB Connection failed: ' . $e->getMessage()); +} + +try { + // Prepare and execute the query + $query = "SELECT reported_domain, nature_of_abuse, status, priority, date_of_incident, date_created FROM support_tickets WHERE category_id = '8'"; + $stmt = $dbh->query($query); + + // Fetch all rows + $tickets = $stmt->fetchAll(PDO::FETCH_ASSOC); + + // Start HTML output + $html = " + +
+Report Date: " . date('Y-m-d H:i:s') . "
"; // Display report generation date + + if (empty($tickets)) { + $html .= "No abuse cases found for the period.
"; // Message if no tickets + } else { + // Continue with the table if tickets are found + $html .= "Reported Domain | +Nature of Abuse | +Status | +Priority | +Date of Incident | +Date Reported | +
---|---|---|---|---|---|
" . htmlspecialchars($ticket['reported_domain']) . " | +" . htmlspecialchars($ticket['nature_of_abuse']) . " | +" . htmlspecialchars($ticket['status']) . " | +" . htmlspecialchars($ticket['priority']) . " | +" . htmlspecialchars($ticket['date_of_incident']) . " | +" . htmlspecialchars($ticket['date_created']) . " | +