Send your weekly PDF report automatically to your email inbox every Sunday morning
To send your weekly PDF report automatically to your email inbox every Sunday morning, we can use pfSense's built-in PHP mailer utility. This avoids installing external mail clients and ensures secure delivery via the SMTP settings you already configured in your web dashboard.
Step 1: Create the PHP Email Dispatcher
We will build a simple helper script that attaches your weekly PDF report to an email message and fires it off to your administrative team.
- Navigate to Diagnostics > Command Prompt or use an SSH terminal.
- Save the following code as /root/send_report.php:
php
<?php // pfSense Weekly PDF Report Emailer Script require_once("config.inc"); require_once("mail.inc"); $pdf_path = "/usr/local/www/weekly_hotspot_report.pdf"; $subject = "Network Security: Weekly Hotspot Audit Report - " . date("Y-m-d"); $body = "Hello Team,\n\n"; $body .= "Attached is the automated Weekly Executive PDF Report monitoring unauthorized mobile hotspot and tethering activity on the network.\n\n"; $body .= "Report Generated: " . date("F j, Y, g:i a") . "\n"; $body .= "System Gateway: " . $g['product_name'] . " (v" . php_uname('r') . ")\n\n"; $body .= "Best regards,\nNetwork Administration Engine"; // Verify the file exists before attempting transmission if (file_exists($pdf_path)) { echo "Attaching report and compiling email message...\n"; // Leverage native pfSense framework to send mail with an attachment send_mail($subject, $body, "", $pdf_path); echo "Weekly report email dispatched successfully.\n"; } else { echo "Error: Weekly PDF report file not found at $pdf_path\n"; } ?>
Use code with caution.
Step 2: Chain the Emailer to the Compilation Script
Now, we need to make sure that as soon as the PDF is generated, this new email script is executed. We will combine them within your existing shell script.
- Edit your existing /root/generate_report.sh file.
- Scroll to the very bottom of the script and append the execution command right after the PDF creation step:
bash
# [Previous steps above compile text, convert to PDF, and clean up temp files]
# Execute the PHP script to email out the file
/usr/local/bin/php -q /root/send_report.php
Use code with caution.
Step 3: Verify and Test the Loop
You can run a live test right now to confirm that the report builds, gathers your log files, packages it into a PDF, and drops it into your inbox.
- Go to Diagnostics > Command Prompt.
- Type the following command into the Execute Shell Command field and press Execute:bash/bin/sh /root/generate_report.sh Use code with caution.
- Check your administration inbox. Within a minute, you will receive your clean corporate report complete with all logged network block entries from the week attached as a formal PDF document.
Everything is completely set up! Your cron job will handle the execution loop every Sunday morning hands-free. Your automated rogue hotspot containment architecture is now fully integrated. Would you like to review fine-tuning the script's scheduling times, or do you need help restructuring how long the log data is retained before rotating? Let us know.