From a5272319f271e638afd0f36fb053ae5b21fef366 Mon Sep 17 00:00:00 2001 From: Brian Read Date: Sun, 6 Apr 2025 07:58:24 +0100 Subject: [PATCH] Add in mailstats generated code amd add html object to html controls --- Targets/Mailstats/Mailstats-Custom.pm | 172 +++++++++++++++++++++----- Targets/Mailstats/Mailstats.pm | 2 +- Targets/Mailstats/_mst_CONFIG.html.ep | 48 ++++--- Targets/Mailstats/_mst_TABLE.html.ep | 6 +- Targets/Mailstats/mailstats.css | 6 +- Targets/Mailstats/mailstats.html.ep | 2 +- Targets/Mailstats/mailstats.js | 63 +++++++++- Targets/Mailstats/mailstats_en.lex | 56 +++++---- Templates/html_controls.html.ep.xml | 16 ++- json5/Mailstats.json5 | 55 +++++--- 10 files changed, 320 insertions(+), 106 deletions(-) diff --git a/Targets/Mailstats/Mailstats-Custom.pm b/Targets/Mailstats/Mailstats-Custom.pm index 4bb573e..629cc76 100644 --- a/Targets/Mailstats/Mailstats-Custom.pm +++ b/Targets/Mailstats/Mailstats-Custom.pm @@ -13,6 +13,8 @@ use esmith::AccountsDB; use esmith::NetworksDB; use esmith::DomainsDB; +use POSIX 'strftime'; + use constant FALSE => 0; use constant TRUE => 1; @@ -94,23 +96,31 @@ use constant TRUE => 1; sub get_data_for_panel_CONFIG { # Return a hash with the fields required which will be loaded into the shared data my $c = shift; + my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db"); + my $key = 'mailstats'; my %ret = ( 'Data1'=>'Data for CONFIG', #Example # fields from Inputs in CONFIG $fields['CONFIG'] - 'TextorHTML'=>'TextorHTML contents', - 'Email'=>'Email contents', - 'EmailHost'=>'EmailHost contents', - 'EmailUser'=>'EmailUser contents', - 'DBSave'=>'DBSave contents', - 'DBHost'=>'DBHost contents', - 'DBUser'=>'DBUser contents', - 'CountrySelect'=>'CountrySelect contents', - 'AccumCountryCodes'=>'AccumCountryCodes contents', - 'EnableRHSBL'=>'EnableRHSBL contents', - 'EnableRHSBL'=>'EnableRHSBL contents', - 'RBLLIST'=>'RBLLIST contents', - 'SBLLIST'=>'SBLLIST contents', - 'UBLLIST'=>'UBLLIST contents', + 'TextorHTML'=>$cdb->get_prop($key,'TextorHTML') || 'HTML', + 'Email'=>$cdb->get_prop($key,'Email') || 'admin', + 'EmailHost'=>$cdb->get_prop($key,'EmailHost') || 'localhost', + 'EmailPort'=>$cdb->get_prop($key,'EmailPORT') || '25', + 'EmailUser'=>$cdb->get_prop($key,'EmailUser') || 'admin', + 'DBSave'=>$cdb->get_prop($key,'SaveDataToMySQL') || 'yes', + 'DBHost'=>$cdb->get_prop($key,'DBHost') || 'localhost', + 'DBUser'=>$cdb->get_prop($key,'DBUser') || 'admin', + 'DBPort'=>$cdb->get_prop($key,'DBPort') || '3306', + #'CountrySelect'=>'CountrySelect ', + 'AccumCountryCodes'=>$cdb->get_prop('qpsmtpd','BadCountries'), + 'EnableRHSBL'=>$cdb->get_prop('qpsmtpd','RHSBL'), + 'EnableDNSBL'=>$cdb->get_prop('qpsmtpd','DNSBL'), + 'EnableURIBL'=>$cdb->get_prop('qpsmtpd','URIBL'), + 'RBLList'=>$cdb->get_prop('qpsmtpd','RBLList'), + 'SBLList'=>$cdb->get_prop('qpsmtpd','SBLList'), + 'UBLList'=>$cdb->get_prop('qpsmtpd','UBLList'), + 'LevelPort'=>$cdb->get_prop('spamassassin','TagLevel') || '5', + 'RejectLevel'=>$cdb->get_prop('spamassassin','RejectLevel') || '12' + ); return %ret; @@ -161,38 +171,49 @@ use constant TRUE => 1; my $c = shift; my $prefix_data = shift; #Data hash as parameter my $ret = ""; + my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db"); my $db = $cdb; #maybe one of the others - my $dbkey = 'ChangeThis'; + my $dbkey = 'mailstats'; # To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g." - if (! TRUE) #copy or perform with value: TextorHTML e.g. $db->set_prop($dbkey,'TextorHTML',$c->param('TextorHTML'),type=>'service')) + if (! $db->set_prop($dbkey,'TextorHTML',$c->param('TextorHTML'),type=>'service')) {$ret .= 'Perform/save failed for TextorHTML';} - if (! TRUE) #copy or perform with value: Email e.g. $db->set_prop($dbkey,'Email',$c->param('Email'),type=>'service')) + if (! $db->set_prop($dbkey,'Email',$c->param('Email'),type=>'service')) {$ret .= 'Perform/save failed for Email';} - if (! TRUE) #copy or perform with value: EmailHost e.g. $db->set_prop($dbkey,'EmailHost',$c->param('EmailHost'),type=>'service')) + if (! $db->set_prop($dbkey,'EmailHost',$c->param('EmailHost'),type=>'service')) {$ret .= 'Perform/save failed for EmailHost';} - if (! TRUE) #copy or perform with value: EmailUser e.g. $db->set_prop($dbkey,'EmailUser',$c->param('EmailUser'),type=>'service')) + if (! $db->set_prop($dbkey,'EmailPort',$c->param('EmailPort'),type=>'service')) + {$ret .= 'Perform/save failed for EmailPort';} + if (! $db->set_prop($dbkey,'EmailUser',$c->param('EmailUser'),type=>'service')) {$ret .= 'Perform/save failed for EmailUser';} - if (! TRUE) #copy or perform with value: DBSave e.g. $db->set_prop($dbkey,'DBSave',$c->param('DBSave'),type=>'service')) + if (! $db->set_prop($dbkey,'SaveDataToMySQL',$c->param('DBSave'),type=>'service')) {$ret .= 'Perform/save failed for DBSave';} - if (! TRUE) #copy or perform with value: DBHost e.g. $db->set_prop($dbkey,'DBHost',$c->param('DBHost'),type=>'service')) + if (! $db->set_prop($dbkey,'DBHost',$c->param('DBHost'),type=>'service')) {$ret .= 'Perform/save failed for DBHost';} - if (! TRUE) #copy or perform with value: DBUser e.g. $db->set_prop($dbkey,'DBUser',$c->param('DBUser'),type=>'service')) + if (! $db->set_prop($dbkey,'DBUser',$c->param('DBUser'),type=>'service')) {$ret .= 'Perform/save failed for DBUser';} - if (! TRUE) #copy or perform with value: CountrySelect e.g. $db->set_prop($dbkey,'CountrySelect',$c->param('CountrySelect'),type=>'service')) - {$ret .= 'Perform/save failed for CountrySelect';} - if (! TRUE) #copy or perform with value: AccumCountryCodes e.g. $db->set_prop($dbkey,'AccumCountryCodes',$c->param('AccumCountryCodes'),type=>'service')) + if (! $db->set_prop($dbkey,'DBPort',$c->param('DBPort'),type=>'service')) + {$ret .= 'Perform/save failed for DBPort';} + #if (! $db->set_prop($dbkey,'CountrySelect',$c->param('CountrySelect'),type=>'service')) + # {$ret .= 'Perform/save failed for CountrySelect';} + if (! $db->set_prop('qpsmtpd','BadCountries',$c->param('AccumCountryCodes'),type=>'service')) {$ret .= 'Perform/save failed for AccumCountryCodes';} - if (! TRUE) #copy or perform with value: EnableRHSBL e.g. $db->set_prop($dbkey,'EnableRHSBL',$c->param('EnableRHSBL'),type=>'service')) + if (! $db->set_prop('qpsmtpd','RHSBL',$c->param('EnableRHSBL'),type=>'service')) {$ret .= 'Perform/save failed for EnableRHSBL';} - if (! TRUE) #copy or perform with value: EnableRHSBL e.g. $db->set_prop($dbkey,'EnableRHSBL',$c->param('EnableRHSBL'),type=>'service')) - {$ret .= 'Perform/save failed for EnableRHSBL';} - if (! TRUE) #copy or perform with value: RBLLIST e.g. $db->set_prop($dbkey,'RBLLIST',$c->param('RBLLIST'),type=>'service')) + if (! $db->set_prop('qpsmtpd','DNSBL',$c->param('EnableDNSBL'),type=>'service')) + {$ret .= 'Perform/save failed for EnableDNSBL';} + if (! $db->set_prop('qpsmtpd','URIBL',$c->param('EnableURIBL'),type=>'service')) + {$ret .= 'Perform/save failed for EnableURIBL';} + if (! $db->set_prop('qpsmtpd','RBLList',$c->param('RBLList'),type=>'service')) {$ret .= 'Perform/save failed for RBLLIST';} - if (! TRUE) #copy or perform with value: SBLLIST e.g. $db->set_prop($dbkey,'SBLLIST',$c->param('SBLLIST'),type=>'service')) + if (! $db->set_prop('qpsmtpd','SBLList',$c->param('SBLList'),type=>'service')) {$ret .= 'Perform/save failed for SBLLIST';} - if (! TRUE) #copy or perform with value: UBLLIST e.g. $db->set_prop($dbkey,'UBLLIST',$c->param('UBLLIST'),type=>'service')) + if (! $db->set_prop('qpsmtpd','UBLList',$c->param('UBLList'),type=>'service')) {$ret .= 'Perform/save failed for UBLLIST';} + if (! $db->set_prop('spamassassin','TagLevel',$c->param('TagLevel'),type=>'service')) + {$ret .= 'Perform/save failed for TagLevel';} + if (! $db->set_prop('spamassassin','RejectLevel',$c->param('RejectLevel'),type=>'service')) + {$ret .= 'Perform/save failed for RejectLevel';} if ($ret eq "") {$ret = 'ok';} return $ret; } @@ -209,7 +230,92 @@ sub get_StatsDate{ return ['yesterday'] } -sub get_CountrCodes{ - return ['UK'] +sub get_CountryCodes { + return [ + ['Afghanistan' => 'AF'], # Frequent political/malware spam + ['Argentina' => 'AR'], # 52% spam call rate (highest globally) + ['Brazil' => 'BR'], # Top spam call origin + ['China' => 'CN'], # High spam volume + ['France' => 'FR'], # 43% spam call rate, top email spam source + ['Germany' => 'DE'], # Significant email spam volume + ['India' => 'IN'], # High spam call/text volume + ['Indonesia' => 'ID'], # 51.5% spam call rate + ['Italy' => 'IT'], # 35.1% spam call rate, email spam source + ['Malaysia' => 'MY'], # 63% scam calls + ['Mexico' => 'MX'], # Emerging spam source + ['Nigeria' => 'NG'], # "Nigerian prince" scams + ['Pakistan' => 'PK'], # Phishing campaigns + ['Peru' => 'PE'], # Emerging spam source + ['Russia' => 'RU'], # Cybercrime associations + ['Saudi Arabia' => 'SA'], # High spam volume + ['Spain' => 'ES'], # 43.9% spam call rate, email spam + ['Turkey' => 'TR'], # Significant spam activity + ['Ukraine' => 'UA'], # Spam proxy servers + ['United States' => 'US'], # High email spam volume + ['Viet Nam' => 'VN'] # Phishing/malware origins + ]; } + + +sub get_RBL_lists{ + return ( + # Other Major Providers + "zen.spamhaus.org", # Combines SBL, XBL, and PBL + 'bl.spamcop.net', # SpamCop Blocklist (user-reported spam) + 'cbl.abuseat.org', # Composite Blocking List (bot-infected hosts) + 'b.barracudacentral.org', # Barracuda Reputation Blocklist + + # Specialized Lists + 'dun.dnsrbl.net', # DNSRBL (DNS-based blacklist) + 'psbl.surriel.com', # Passive Spam Block List (passive spam traps) + 'backscatterer.org', # Backscatter/Out-of-Bounce spam sources + 'dronebl.org', # Drones/Proxy/DDoS sources + 'dnsbl-1.uceprotect.net',# UCEPROTECT Level 1 (entry-level blocking)[User Query] + 'dnsbl-2.uceprotect.net' # UCEPROTECT Level 2 (more aggressive)[User Query] +);} + +sub get_SBL_list{ + return ( + "sbl.spamhaus.org", # Spamhaus Blocklist + "xbl.spamhaus.org", # eXploits Blocklist + "pbl.spamhaus.org", # Policy Blocklist + "auth.spamhaus.org", # Auth Blocklist + "multi.surbl.org", # SURBL's multi-level URI checker (domains in email content) + "rhsbl.sorbs.net" # Right-Hand Side Blocklist (domain-based, not IP-based) +);} + +sub get_URIBL_list{ + return my @uribl_lists = ( + "uribl.com", # Primary URIBL service + "multi.uribl.com", # Combined URIBL checks + "black.uribl.com", # Aggressive blocking list + "grey.uribl.com", # Suspicious URI list + "white.uribl.com" # Verified safe URI list +);} + +sub get_mailstat_dates { + my ($directory) = '/opt/mailstats/html'; + my @date_pairs; + + # Find all matching files in directory + opendir(my $dh, $directory) or die "Can't open directory: $!"; + + while (my $file = readdir($dh)) { + next unless $file =~ /mailstats_for_(\d{4}-\d{2}-\d{2})\.html$/; + my $date = $1; + + if ($date =~ /^(\d{4})-(\d{2})-(\d{2})$/) { + my $formatted_date = strftime("%B %-d %Y", 0, 0, 0, $3, $2-1, $1-1900); + push @date_pairs, [$formatted_date, $date]; + } + } + + closedir($dh); + + # Sort dates chronologically + @date_pairs = sort { $a->[1] cmp $b->[1] } @date_pairs; + + return \@date_pairs; +} + 1; \ No newline at end of file diff --git a/Targets/Mailstats/Mailstats.pm b/Targets/Mailstats/Mailstats.pm index b4d9ae2..0a58675 100644 --- a/Targets/Mailstats/Mailstats.pm +++ b/Targets/Mailstats/Mailstats.pm @@ -1,6 +1,6 @@ package SrvMngr::Controller::Mailstats; # -# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-04 13:12:40 +# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-05 11:59:08 # #---------------------------------------------------------------------- # heading : Investigation diff --git a/Targets/Mailstats/_mst_CONFIG.html.ep b/Targets/Mailstats/_mst_CONFIG.html.ep index 5f21fdd..4d91510 100644 --- a/Targets/Mailstats/_mst_CONFIG.html.ep +++ b/Targets/Mailstats/_mst_CONFIG.html.ep @@ -1,5 +1,5 @@ %# -%# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-04 13:12:40 +%# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-05 11:17:38 %#