initial commit of file from CVS for smeserver-qmHandle on Sat Sep 7 20:58:19 AEST 2024
This commit is contained in:
329
root/usr/share/smanager/lib/SrvMngr/Controller/Qmh.pm
Normal file
329
root/usr/share/smanager/lib/SrvMngr/Controller/Qmh.pm
Normal file
@@ -0,0 +1,329 @@
|
||||
package SrvMngr::Controller::Qmh;
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# heading : System
|
||||
# description : E-Mail queue management
|
||||
# navigation : 4000 550
|
||||
# menu : A
|
||||
#
|
||||
# name : qmhandle, method : get, url : /qmh, ctlact : qmh#main
|
||||
# name : qmhandle2, method : post, url : /qmh, ctlact : qmh#do_update
|
||||
# name : qmhandled, method : get, url : /qmh2, ctlact : qmh#do_update
|
||||
|
||||
# routes : end
|
||||
# Copyright (C) 2005/2008 Peter Schubert, SACO Software and Consulting GmbH
|
||||
#----------------------------------------------------------------------
|
||||
use strict;
|
||||
use warnings;
|
||||
use Mojo::Base 'Mojolicious::Controller';
|
||||
|
||||
use esmith::FormMagick qw(gen_locale_date_string);
|
||||
use esmith::ConfigDB;
|
||||
|
||||
use Locale::gettext;
|
||||
use SrvMngr::I18N;
|
||||
|
||||
use SrvMngr qw(theme_list init_session);
|
||||
|
||||
our $cdb = esmith::ConfigDB->open() || die 'Cannot open configuration base';
|
||||
|
||||
sub main {
|
||||
|
||||
my $c = shift;
|
||||
$c->app->log->info($c->log_req);
|
||||
|
||||
my %qmh_datas = ();
|
||||
my $title = $c->l('qmh_QMH_TITLE');
|
||||
|
||||
$qmh_datas{'trt'} = 'LST';
|
||||
$qmh_datas{'altq'} = 0;
|
||||
|
||||
$c->stash( title => $title, qmh_datas => \%qmh_datas );
|
||||
$c->render('qmh');
|
||||
};
|
||||
|
||||
|
||||
sub do_update {
|
||||
|
||||
my $c = shift;
|
||||
$c->app->log->info($c->log_req);
|
||||
|
||||
my %qmh_datas = ();
|
||||
my $result = "";
|
||||
|
||||
my $report_type = $c->param('Report_type');
|
||||
|
||||
my $trt = $c->param('trt');
|
||||
$qmh_datas{'trt'} = $trt;
|
||||
|
||||
my $altq = $c->param('altq');
|
||||
$qmh_datas{'altq'} = $altq;
|
||||
|
||||
if ($trt eq 'LST') {
|
||||
if ($report_type =~ /^(\S+)$/) {
|
||||
$report_type = $1;
|
||||
} else {
|
||||
$result = $c->l('INVALID_REPORT_TYPE') . " : $report_type";
|
||||
$report_type = undef;
|
||||
}
|
||||
|
||||
$altq = 0;
|
||||
my $function = $report_type || '';
|
||||
if ($function =~ s/^alt-//) {
|
||||
$altq = 1;
|
||||
}
|
||||
$qmh_datas{'altq'} = $altq;
|
||||
|
||||
if ($function eq 'list-queues') {
|
||||
$result = showListQueues ($c, $altq);
|
||||
} elsif ($function eq 'list-local-queue') {
|
||||
$result = showListLocalQueue ($c, $altq);
|
||||
} elsif ($function eq 'list-remote-queue') {
|
||||
$result = showListRemoteQueue ($c, $altq);
|
||||
} elsif ($function eq 'resend') {
|
||||
$result = resend($c, $altq);
|
||||
}
|
||||
|
||||
$qmh_datas{'trt'} = 'REP';
|
||||
}
|
||||
|
||||
|
||||
if ($trt eq 'REP') {
|
||||
$c->redirect_to('/qmh');
|
||||
}
|
||||
|
||||
|
||||
if ($trt eq 'MSG') {
|
||||
my $msgid = $c->param('msgid');
|
||||
$result = $c->render_to_string(inline => showDeleteMessageNumber($c, $msgid, $altq, $report_type)) if $msgid;
|
||||
$qmh_datas{'msgid'} = $msgid;
|
||||
}
|
||||
|
||||
|
||||
if ($trt eq 'DEL') {
|
||||
my $msgid = $c->param('msgid');
|
||||
$result = $c->render_to_string(inline => deleteMessageNumber($c, $msgid, $altq, $report_type)) if $msgid;
|
||||
my $message = $c->l('qmh_DELETE') . ' <br> ' . $msgid;
|
||||
#$c->app->log->info($message.' '.$result);
|
||||
}
|
||||
|
||||
|
||||
my $title = $c->l('qmh_QMH_TITLE');
|
||||
$c->stash( title => $title, qmh_datas => \%qmh_datas, modul => $result );
|
||||
$c->render('qmh');
|
||||
|
||||
};
|
||||
|
||||
|
||||
sub reportType_list {
|
||||
|
||||
my $c = shift;
|
||||
|
||||
my $rec = $cdb->get('altqmail');
|
||||
my $altqmail = ($cdb->get('altqmail')->value || 0) if $rec;
|
||||
|
||||
return [[ $c->l('qmh_LIST_QUEUE') => 'list-queues' ],
|
||||
[ $c->l('qmh_LIST_LOCAL_QUEUE') => 'list-local-queue' ],
|
||||
[ $c->l('qmh_LIST_REMOTE_QUEUE') => 'list-remote-queue' ],
|
||||
[ $c->l('qmh_RESEND_QUEUE') => 'resend' ]]
|
||||
unless $altqmail;
|
||||
|
||||
return [[ $c->l('qmh_LIST_QUEUE') => 'list-queues' ],
|
||||
[ $c->l('qmh_LIST_LOCAL_QUEUE') => 'list-local-queue' ],
|
||||
[ $c->l('qmh_LIST_REMOTE_QUEUE') => 'list-remote-queue' ],
|
||||
[ $c->l('qmh_RESEND_QUEUE') => 'resend' ],
|
||||
[ "altqmail: ". $c->l('qmh_LIST_QUEUE') => 'alt-list-queues' ],
|
||||
[ "altqmail: ". $c->l('qmh_LIST_LOCAL_QUEUE') => 'alt-list-local-queue' ],
|
||||
[ "altqmail: ". $c->l('qmh_LIST_REMOTE_QUEUE') => 'alt-list-remote-queue' ],
|
||||
[ "altqmail: ". $c->l('qmh_RESEND_QUEUE') => 'alt-resend' ]];
|
||||
}
|
||||
|
||||
|
||||
#------------------------------------------------------------
|
||||
# subroutine to showListQueues
|
||||
#------------------------------------------------------------
|
||||
sub showListQueues {
|
||||
|
||||
my ($c, $altq) = @_;
|
||||
|
||||
my $out = '';
|
||||
my $reporttype = 'list-queues';
|
||||
|
||||
my $opt = ($altq ? 'altqmail: ' : '');
|
||||
$out .= sprintf("<h2>%s</h2><br>", $opt . $c->l('qmh_SHOWLISTQUEUES'));
|
||||
$out .= sprintf("%s<br>%s", $c->l('qmh_VIEW_TIME'), scalar localtime(time));
|
||||
|
||||
$opt = ($altq ? '-X -l' : '-l');
|
||||
my $MailQueues = `/usr/bin/qmHandle $opt`;
|
||||
$MailQueues =~ s/</'/g;
|
||||
$MailQueues =~ s/>/'/g;
|
||||
|
||||
$MailQueues = AddLinks($MailQueues, $altq, $reporttype);
|
||||
|
||||
$out .= sprintf "<pre>";
|
||||
$out .= "$MailQueues";
|
||||
$out .= sprintf "</pre>";
|
||||
$out .= sprintf "<input type=hidden name=\"Report_type\" value=\"$reporttype\">";
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
#------------------------------------------------------------
|
||||
# subroutine to showListLocalQueue
|
||||
#------------------------------------------------------------
|
||||
sub showListLocalQueue {
|
||||
|
||||
my ($c, $altq) = @_;
|
||||
|
||||
my $out = '';
|
||||
my $reporttype = 'list-local-queue';
|
||||
|
||||
my $opt = ($altq ? 'altqmail: ' : '');
|
||||
$out .= sprintf("<h2>%s</h2><br>", $opt . $c->l('qmh_LIST_LOCAL_QUEUE'));
|
||||
$out .= sprintf("%s<br>%s", $c->l('qmh_VIEW_TIME'), scalar localtime(time));
|
||||
|
||||
$opt = ($altq ? '-X -L' : '-L');
|
||||
my $LocalQueue = `/usr/bin/qmHandle $opt`;
|
||||
$LocalQueue =~ s/</'/g;
|
||||
$LocalQueue =~ s/>/'/g;
|
||||
|
||||
$LocalQueue = AddLinks($LocalQueue, $altq, $reporttype);
|
||||
|
||||
$out .= sprintf "<pre>";
|
||||
$out .= "$LocalQueue";
|
||||
$out .= sprintf "</pre>";
|
||||
$out .= sprintf "<input type=hidden name=\"Report_type\" value=\"$reporttype\">";
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
#------------------------------------------------------------
|
||||
# subroutine to showListRemoteQueue
|
||||
#------------------------------------------------------------
|
||||
sub showListRemoteQueue {
|
||||
|
||||
my ($c, $altq) = @_;
|
||||
|
||||
my $out = '';
|
||||
my $reporttype = 'list-remote-queue';
|
||||
|
||||
my $opt = ($altq ? 'altqmail: ' : '');
|
||||
$out .= sprintf("<h2>%s</h2><br>", $opt . $c->l('qmh_LIST_REMOTE_QUEUE'));
|
||||
$out .= sprintf("%s<br>%s", $c->l('qmh_VIEW_TIME'), scalar localtime(time));
|
||||
|
||||
$opt = ($altq ? '-X -R' : '-R');
|
||||
my $RemoteQueue = `/usr/bin/qmHandle $opt`;
|
||||
$RemoteQueue =~ s/</'/g;
|
||||
$RemoteQueue =~ s/>/'/g;
|
||||
|
||||
$RemoteQueue = AddLinks($RemoteQueue, $altq, $reporttype);
|
||||
|
||||
$out .= sprintf "<pre>";
|
||||
$out .= "$RemoteQueue";
|
||||
$out .= sprintf "</pre>";
|
||||
$out .= sprintf "<input type=hidden name=\"Report_type\" value=\"$reporttype\">";
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
#------------------------------------------------------------
|
||||
# subroutine to send ALARM to qmail
|
||||
#------------------------------------------------------------
|
||||
sub resend {
|
||||
|
||||
my ($c, $altq) = @_;
|
||||
|
||||
my $out = '';
|
||||
my $reporttype = 'resend';
|
||||
|
||||
my $opt = ($altq ? 'altqmail: ' : '');
|
||||
$out .= sprintf("<h2>%s</h2><br>", $opt . $c->l('qmh_TRY_SEND_QUEUE'));
|
||||
$out .= sprintf("%s<br>%s", $c->l('qmh_SEND_QUEUE_AT'), scalar localtime(time));
|
||||
|
||||
$opt = ($altq ? '-X -a' : '-a');
|
||||
my $Res = `/usr/bin/qmHandle $opt`;
|
||||
$Res =~ s/</'/g;
|
||||
$Res =~ s/>/'/g;
|
||||
|
||||
$Res = AddLinks($Res, $altq, $reporttype);
|
||||
|
||||
$out .= sprintf "<pre>";
|
||||
$out .= "$Res";
|
||||
$out .= sprintf "</pre>";
|
||||
$out .= sprintf "<input type=hidden name=\"Report_type\" value=\"$reporttype\">";
|
||||
$out .= sprintf "<h3>Done</h3>";
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
sub AddLinks {
|
||||
|
||||
my ($queues, $altq, $reporttype) = @_;
|
||||
|
||||
my @splitq = split(/\n/, $queues);
|
||||
|
||||
for (my $i = 0; $i < $#splitq; $i++) {
|
||||
if ($splitq[$i] =~ /^(\d+)\s+(\(\d+\,\s+\d+\/+\d+\)\s*)$/ ) {
|
||||
$splitq[$i] = "<a href=\"qmh2?trt=MSG&msgid=$1&Report_type=$reporttype\">$1</a> $2";
|
||||
}
|
||||
}
|
||||
$queues = join("\n", @splitq);
|
||||
|
||||
return $queues;
|
||||
}
|
||||
|
||||
|
||||
#------------------------------------------------------------
|
||||
# subroutine to showDeleteMessageNumber
|
||||
#------------------------------------------------------------
|
||||
sub showDeleteMessageNumber {
|
||||
|
||||
my ($c, $msgid, $altq, $reporttype) = @_;
|
||||
|
||||
if ($msgid =~ /^(\d+)$/) {
|
||||
$msgid = $1;
|
||||
} else {
|
||||
$msgid = undef;
|
||||
}
|
||||
|
||||
my $out = '';
|
||||
|
||||
my $opt = ($altq ? 'altqmail: ' : '');
|
||||
$out .= sprintf("<h2>%s</h2><br>", $opt . $c->l('qmh_DELETE_MSG_TITLEB'));
|
||||
$out .= sprintf("%s", $c->l('qmh_DELETE_MESSAGE'));
|
||||
|
||||
$opt = ($altq ? "-X -m$msgid|head -100" : "-m$msgid|head -100");
|
||||
my $Message = `/usr/bin/qmHandle $opt`;
|
||||
|
||||
$out .= sprintf "<pre>";
|
||||
$out .= "<textarea name=\"message\" rows=30 cols=80>$Message</textarea>";
|
||||
$out .= sprintf "</pre>";
|
||||
$out .= sprintf "<input type=hidden name=\"Report_type\" value=\"$reporttype\">";
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
sub deleteMessageNumber {
|
||||
|
||||
my ($c, $msgid, $altq, $reporttype) = @_;
|
||||
|
||||
if ($msgid =~ /^(\d+)$/) {
|
||||
$msgid = $1;
|
||||
} else {
|
||||
$msgid = undef;
|
||||
}
|
||||
|
||||
my $out = '';
|
||||
my $opt = ($altq ? "-X -d$msgid" : "-d$msgid");
|
||||
my $Output = `/usr/bin/qmHandle $opt`;
|
||||
|
||||
$out .= sprintf "<pre>";
|
||||
$out .= "$Output";
|
||||
$out .= sprintf "</pre>";
|
||||
$out .= sprintf "<input type=hidden name=\"Report_type\" value=\"$reporttype\">";
|
||||
return $out;
|
||||
|
||||
}
|
||||
|
||||
|
||||
1;
|
@@ -0,0 +1,21 @@
|
||||
'qmh_QMH_TITLE' => 'Qmail queue management',
|
||||
'qmh_OPERATION_STATUS_REPORT' => 'Operation status report',
|
||||
'qmh_QMH_DESC' => 'This panel uses <b>qmHandle</b> to manage the qmail message queues. Key features are the ability to view and delete messages in the queues.',
|
||||
'qmh_TRY_SEND_QUEUE' => 'Force resending of the Qmail queue',
|
||||
'qmh_SEND_QUEUE_AT' => 'Resend Qmail queue at: ',
|
||||
'qmh_LIST_QUEUE' => 'List message queues',
|
||||
'qmh_LIST_LOCAL_QUEUE' => 'List local message queue',
|
||||
'qmh_SHOWLISTQUEUES' => 'List Qmail local and remote queues',
|
||||
'qmh_LIST_REMOTE_QUEUE' => 'List remote message queue',
|
||||
'qmh_VIEW_TIME' => 'Qmail message queue, viewed at: ',
|
||||
'qmh_LIST_LOCAL_QUEUE' => 'List Qmail local queue',
|
||||
'qmh_LIST_REMOTE_QUEUE' => 'List Qmail remote queue',
|
||||
'qmh_RESEND_QUEUE' => 'Try to send queued messages now (qmail must be running)',
|
||||
'qmh_DELETE_MSG_TITLEB' => 'Queue management: delete Message',
|
||||
'qmh_DELETE_MESSAGE' => 'Delete this message from the queue ? (Only the first 100 lines are listed)',
|
||||
'qmh_DELETE' => 'Delete',
|
||||
'qmh_SELECT_AN_ACTION' => 'Select an action',
|
||||
'qmh_iFROM_QUEUE' => 'from message queue',
|
||||
'qmh_RETURN_TO_QUEUE' => 'Return to Queue',
|
||||
'qmh_Administration' => 'Administration',
|
||||
'E-mail Warteschlange' => 'E-Mail queue management',
|
@@ -0,0 +1,21 @@
|
||||
'qmh_QMH_TITLE' => 'Administration de file d\'attente',
|
||||
'qmh_OPERATION_STATUS_REPORT' => 'Rapport d\'état de l\'opération',
|
||||
'qmh_QMH_DESC' => 'Ce panel utilise <b>qmHandle</b> pour administrer la file d\'attente de Qmail. Les fonctionnalités principales sont de voir et d\'effacer des messages dans la file d\'attente. ',
|
||||
'qmh_TRY_SEND_QUEUE' => 'Forcer le renvoi de la file d\'attente de qmail',
|
||||
'qmh_SEND_QUEUE_AT' => 'Renvoi la file d\'attente Qmail le : ',
|
||||
'qmh_LIST_QUEUE' => 'Message de la file d\'attente',
|
||||
'qmh_LIST_LOCAL_QUEUE' => 'File d\'attente locale',
|
||||
'qmh_SHOWLISTQUEUES' => 'Files d\'attente locale et distante',
|
||||
'qmh_LIST_REMOTE_QUEUE' => 'File d\'attente distante de QMAIL',
|
||||
'qmh_VIEW_TIME' => 'La file d\'attente des messages de Qmail le : ',
|
||||
'qmh_LIST_LOCAL_QUEUE' => 'File d\'attente locale de QMAIL',
|
||||
'qmh_LIST_REMOTE_QUEUE' => 'File d\'attente distante de QMAIL',
|
||||
'qmh_RESEND_QUEUE' => 'Renvoyer les messages de la file d\'attente maintenant (Qmail doit être en fonction)',
|
||||
'qmh_DELETE_MSG_TITLEB' => 'Administration de file d\'attente : effacer le Message',
|
||||
'qmh_DELETE_MESSAGE' => 'Effacez ce message de la file d\'attente? (Seulement les 100 premières lignes sont affichées)',
|
||||
'qmh_DELETE' => 'Supprimer',
|
||||
'qmh_SELECT_AN_ACTION' => 'Sélectionnez une action :',
|
||||
'qmh_iFROM_QUEUE' => 'de la file d\'attente des messages',
|
||||
'qmh_RETURN_TO_QUEUE' => 'Retour à la file d\'attente',
|
||||
'qmh_Administration' => 'Administration',
|
||||
'E-mail Warteschlange' => 'Administration de file d\'attente des courriels',
|
Reference in New Issue
Block a user