From a58191f66795b9ba7b00398bff0dc889394b29a3 Mon Sep 17 00:00:00 2001 From: Brian Read Date: Sun, 6 Apr 2025 20:32:49 +0100 Subject: [PATCH] Update to mailstats panel --- .../SrvMngr/Controller/Mailstats-Custom.pm | 27 +++++++++++++++++++ .../themes/default/public/js/mailstats.js | 26 ++++++++++++++++++ .../templates/partials/_mst_TABLE.html.ep | 4 +-- smeserver-mailstats.spec | 9 ++++--- 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Mailstats-Custom.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Mailstats-Custom.pm index b1d573e..629cc76 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Mailstats-Custom.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/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; @@ -291,4 +293,29 @@ sub get_URIBL_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/root/usr/share/smanager/themes/default/public/js/mailstats.js b/root/usr/share/smanager/themes/default/public/js/mailstats.js index c01f2ad..d24e550 100644 --- a/root/usr/share/smanager/themes/default/public/js/mailstats.js +++ b/root/usr/share/smanager/themes/default/public/js/mailstats.js @@ -37,4 +37,30 @@ document.addEventListener('DOMContentLoaded', () => { // Add change listener to multiselect document.getElementById('CountrySelect_select') .addEventListener('click', updateTextInput); +}); + +// Initialize select with current object content +document.addEventListener('DOMContentLoaded', () => { + const objectElement = document.getElementById('mailstats_object'); + const selectElement = document.getElementById('StatsDate_select'); + + // Extract current date from object's data URL + const currentDate = objectElement.data.match(/mailstats_for_(\d{4}-\d{2}-\d{2})\.html/)?.[1]; + + if (currentDate) { + selectElement.value = currentDate; + } +}); + +// Update object content when selection changes +document.getElementById('StatsDate_select').addEventListener('change', function() { + const selectedDate = this.value; + const objectElement = document.getElementById('mailstats_object'); + + // Update object's data source + objectElement.data = `mailstats_for_${selectedDate}.html`; + + // Force refresh using clone method (cross-browser workaround) + const clone = objectElement.cloneNode(true); + objectElement.replaceWith(clone); }); \ No newline at end of file diff --git a/root/usr/share/smanager/themes/default/templates/partials/_mst_TABLE.html.ep b/root/usr/share/smanager/themes/default/templates/partials/_mst_TABLE.html.ep index b3c709b..6881ff3 100644 --- a/root/usr/share/smanager/themes/default/templates/partials/_mst_TABLE.html.ep +++ b/root/usr/share/smanager/themes/default/templates/partials/_mst_TABLE.html.ep @@ -39,12 +39,12 @@

%=l('mst_Date_for_Stats_display') - % my @StatsDate_options = [['$c->get_StatsDate()' => '$c->get_StatsDate()']]; + % my @StatsDate_options = $c->get_mailstat_dates(); % param 'StatsDate' => $mst_data->{StatsDate} unless param 'StatsDate'; %= select_field 'StatsDate' => @StatsDate_options, class => 'input', id => 'StatsDate_select'

- <%= $c->stash('title') %> not found + <%= $c->stash('title') %> not found %# Probably finally by a submit. diff --git a/smeserver-mailstats.spec b/smeserver-mailstats.spec index bd8e608..95bd013 100644 --- a/smeserver-mailstats.spec +++ b/smeserver-mailstats.spec @@ -5,8 +5,8 @@ Summary: Daily mail statistics for SME Server %define name smeserver-mailstats Name: %{name} -%define version 1.1 -%define release 19 +%define version 11.1 +%define release 2 Version: %{version} Release: %{release}%{?dist} License: GPL @@ -32,7 +32,10 @@ A script that via cron.d e-mails mail statistics to admin on a daily basis. See http://www.contribs.org/bugzilla/show_bug.cgi?id=819 %changelog -* Mon Dec 30 2024 Brian Read 1.1-19.sme +* Sun Apr 06 2025 Brian Read 11.2-2.sme +- Add in SM2 panel [SME: ] + +* Mon Dec 30 2024 Brian Read 11.2-1.sme - Update mailstats.pl to accomodate change in log format for SME11 [SME: 12841] * Fri Jun 07 2024 Brian Read 1.1-18.sme