From 60ab2b9723716f0a2141229f8c7848404f21f7f7 Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Fri, 1 Nov 2024 14:36:59 +0200 Subject: [PATCH] Improved the spec11 abuse report, fixed #167 --- automation/abusereport.php | 115 +++++++++++++++++++++++++------------ 1 file changed, 77 insertions(+), 38 deletions(-) diff --git a/automation/abusereport.php b/automation/abusereport.php index 18d53ba..1bcca45 100644 --- a/automation/abusereport.php +++ b/automation/abusereport.php @@ -4,32 +4,47 @@ require __DIR__ . '/vendor/autoload.php'; $c = require_once 'config.php'; require_once 'helpers.php'; -// Connect to the database -$dsn = "{$c['db_type']}:host={$c['db_host']};dbname={$c['db_database']}"; -$options = [ - PDO::ATTR_ERRMODE => 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.'); +$log->info('Job started.'); try { - $dbh = new PDO($dsn, $c['db_username'], $c['db_password'], $options); + // Database connection + $dsn = "{$c['db_type']}:host={$c['db_host']};dbname={$c['db_database']}"; + $dbh = new PDO($dsn, $c['db_username'], $c['db_password'], [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, + ]); } catch (PDOException $e) { $log->error('DB Connection failed: ' . $e->getMessage()); + exit; } -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); +// Retrieve tickets by user role +function getTicketsByUserRole($dbh, $userRoleMask, $userId = null) +{ + $query = "SELECT reported_domain, nature_of_abuse, status, priority, date_of_incident, date_created + FROM support_tickets + WHERE category_id = '8'"; - // Fetch all rows - $tickets = $stmt->fetchAll(PDO::FETCH_ASSOC); + if ($userRoleMask === 4 && $userId) { + $query .= " AND user_id = :userId"; + } - // Start HTML output + $stmt = $dbh->prepare($query); + if ($userRoleMask === 4 && $userId) { + $stmt->execute([':userId' => $userId]); + } else { + $stmt->execute(); + } + + return $stmt->fetchAll(); +} + +// Generate HTML report for abuse tickets +function generateReportHTML($tickets) +{ $html = "
@@ -37,12 +52,11 @@ try {Report Date: " . date('Y-m-d H:i:s') . "
"; // Display report generation date +Report Date: " . date('Y-m-d H:i:s') . "
"; if (empty($tickets)) { - $html .= "No abuse cases found for the period.
"; // Message if no tickets + $html .= "No abuse cases found for the period.
"; } else { - // Continue with the table if tickets are found $html .= "Reported Domain | @@ -53,7 +67,6 @@ try {Date Reported |
---|---|
" . htmlspecialchars($ticket['reported_domain']) . " | @@ -64,29 +77,30 @@ try {" . htmlspecialchars($ticket['date_created']) . " |