smeserver-qmHandle/root/usr/share/smanager/lib/SrvMngr/Controller/Qmh.pm

330 lines
8.8 KiB
Perl
Raw Permalink Normal View History

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;