Files
smeserver-pfhandle/root/etc/e-smith/web/functions/pfhandle
Brian Read 16598ff52b * Wed Nov 05 2025 Brian Read <brianr@koozali.org> 11.0-2.sme
- Refactor filenames, routes etc to bring it into line with other modules, v11 to reflect SME11 [SME: 13274]
2025-11-05 10:21:04 +00:00

397 lines
10 KiB
Perl
Executable File

#!/usr/bin/perl -wT
#----------------------------------------------------------------------
# heading : Administration
# description : E-mail Warteschlange
# navigation : 5000 5100
# Copyright (C) 2005/2008 Peter Schubert, SACO Software and Consulting GmbH
#----------------------------------------------------------------------
use strict;
use esmith::FormMagick;
use esmith::ConfigDB;
use esmith::AccountsDB;
use esmith::config;
use esmith::cgi;
use esmith::util;
use esmith::lockfile;
my $fm = esmith::FormMagick->new();
use CGI;
$CGI::POST_MAX = -1;
$CGI::DISABLE_UPLOADS = 0;
$fm->{cgi} = CGI->new();
$fm->parse_xml();
my $conf = esmith::ConfigDB->open()
|| die $fm->localise('CANNOT_OPEN').'/home/e-smith/configuration';
# We need this hash for some esmith::cgi calls, so...
tie my %conf, 'esmith::config', $conf->file;
# Unbuffer standard output so that files and directories are listed as
# they are restored
$| = 1;
# Store away current gid of 'www' group.
my $www_gid = getgrnam("www");
#------------------------------------------------------------
# examine state parameter and display the appropriate form
#------------------------------------------------------------
my $q = $fm->{cgi};
if (! grep (/^state$/, $q->param))
{
showInitial ($q, '');
}
elsif ($q->param ('state') eq "perform")
{
performAndShowResult ($q);
}
else
{
esmith::cgi::genStateError ($q, \%conf);
}
exit (0);
#------------------------------------------------------------
# subroutine to display initial form
#------------------------------------------------------------
sub showInitial
{
my ($q, $msg) = @_;
if ($msg eq '')
{
esmith::cgi::genHeaderNonCacheable ($q, \%conf,
$fm->localise('QMH_TITLE'));
}
else
{
esmith::cgi::genHeaderNonCacheable
($q, \%conf, $fm->localise('OPERATION_STATUS_REPORT'));
print $q->div ({-class => "sme-error"}, $msg);
print $q->hr;
}
# Hack to evaluate embedded vars
print eval 'return "'.$fm->localise('QMH_DESC').'\n";';
my %labels = (
"list-queues" => $fm->localise('LIST_QUEUE'),
"list-local-queue" => $fm->localise('LIST_LOCAL_QUEUE'),
"list-remote-queue" => $fm->localise('LIST_REMOTE_QUEUE'),
"resend" => $fm->localise('RESEND_QUEUE'),
);
my @labels = (
'list-queues',
'list-local-queue',
'list-remote-queue',
'resend',
);
my $default_action = 'list-queues';
print $q->start_form(
-method => 'POST',
-action => $q->url (-absolute => 1)
),"\n";
print $q->start_table ({-class => "sme-noborders"}),"\n";
print $q->Tr(
$q->td({-class => "sme-noborders-label"},
$fm->localise("SELECT_AN_ACTION")),
$q->td({-class => "sme-noborders-content"},
$q->popup_menu (
-name => 'function',
-values => [ @labels ],
-default => $default_action,
-labels => \%labels
)
)
),"\n";
print $q->end_table,"\n";
print $q->start_table ({width => "100%", -class => "sme-noborders"}),
"\n";
print esmith::cgi::genButtonRow(
$q,
$q->submit (-name => 'action', -value =>
$fm->localise('PERFORM'))
);
print $q->end_table,"\n";
print $q->hidden (
-name => 'state',
-override => 1,
-default => 'perform'
),"\n";
print $q->end_form,"\n";
esmith::cgi::genFooter($fm);
return;
}
sub performAndShowResult
{
my ($q) = @_;
my $function = $q->param ('function');
if ($function eq 'refresh')
{
showInitial ($q, '');
}
elsif ($function eq 'list-queues')
{
showListQueues ($q);
}
elsif ($function eq 'list-local-queue')
{
showListLocalQueue ($q);
}
elsif ($function eq 'list-remote-queue')
{
showListRemoteQueue ($q);
}
elsif ($function eq 'resend')
{
resend($q);
}
elsif ($function eq 'confirm-delete-message-number')
{
showDeleteMessageNumber ($q);
}
elsif ($function eq 'delete-message-number')
{
deleteMessageNumber($q);
}
else
{
# Unknown function - refresh the screen anyway
showInitial ($q, 'unknown');
}
return;
print $q->p ( $function );
esmith::cgi::genFooter($fm);
}
#------------------------------------------------------------
# subroutine to showListQueues
#------------------------------------------------------------
sub showListQueues ($)
{
my ($q) = @_;
esmith::cgi::genHeaderNonCacheable ($q, \%conf,
$fm->localise('SHOWLISTQUEUES'));
{
print $q->hr;
print $q->p($fm->localise('VIEW_TIME')),scalar localtime(time),"\n";
my $MailQueues = `/usr/sbin/pfHandle -l`;
my $queuetype = 'list-queues';
$MailQueues =~ s/</'/g;
$MailQueues =~ s/>/'/g;
$MailQueues = AddLinks($MailQueues, $queuetype, $q);
print $q->p ($q->pre ("$MailQueues"));
}
esmith::cgi::genFooter($fm);
return;
}
sub AddLinks
{
my $queues = shift;
my $queueType = shift;
my @splitq = split(/\n/, $queues);
for (my $i = 0; $i < $#splitq; $i++) {
if ($splitq[$i] =~ /^([0-9A-F]+)$/ ) {
$splitq[$i] = "<a href=\"" .
$q->url( -absolute => 1 ) .
"?state=perform&function=confirm-delete-message-number&queue=$queueType" .
"&msgid=$1\">$1</a>";
}
}
$queues = join("\n", @splitq);
return $queues;
}
#------------------------------------------------------------
# subroutine to showListLocalQueue
#------------------------------------------------------------
sub showListLocalQueue ($)
{
my ($q) = @_;
esmith::cgi::genHeaderNonCacheable ($q, \%conf,
$fm->localise('LIST_LOCAL_QUEUE'));
{
print $q->hr;
print $q->p($fm->localise('VIEW_TIME')),scalar localtime(time),"\n";
my $LocalQueue = `/usr/sbin/pfHandle -a`;
my $queuetype = 'list-local-queue';
$LocalQueue =~ s/</'/g;
$LocalQueue =~ s/>/'/g;
$LocalQueue = AddLinks($LocalQueue, $queuetype);
print $q->p ($q->pre ("$LocalQueue"));
}
esmith::cgi::genFooter($fm);
return;
}
#------------------------------------------------------------
# subroutine to showListRemoteQueue
#------------------------------------------------------------
sub showListRemoteQueue ($)
{
my ($q) = @_;
esmith::cgi::genHeaderNonCacheable ($q, \%conf,
$fm->localise('LIST_REMOTE_QUEUE'));
{
print $q->hr;
print $q->p($fm->localise('VIEW_TIME')),scalar localtime(time),"\n";
my $RemoteQueue = `/usr/sbin/pfHandle -d`;
my $queuetype = 'list-remote-queue';
$RemoteQueue =~ s/</'/g;
$RemoteQueue =~ s/>/'/g;
$RemoteQueue = AddLinks($RemoteQueue, $queuetype);
print $q->p ($q->pre ("$RemoteQueue"));
}
esmith::cgi::genFooter($fm);
return;
}
#------------------------------------------------------------
# subroutine to send ALARM to qmail
#------------------------------------------------------------
sub resend ($)
{
my ($q) = @_;
esmith::cgi::genHeaderNonCacheable ($q, \%conf,
$fm->localise('TRY_SEND_QUEUE'));
{
print $q->hr;
print $q->p($fm->localise('SEND_QUEUE_AT')),scalar localtime(time),"\n";
my $res = `/usr/sbin/pfHandle -f`;
print $q->p ($q->pre ("$res"));
print $q->h3 ("Done.");
}
esmith::cgi::genFooter($fm);
return;
}
#------------------------------------------------------------
# subroutine to showDeleteMessageNumber
#------------------------------------------------------------
sub showDeleteMessageNumber ($)
{
my ($q) = @_;
my $msgid = $q->param ('msgid');
my $queuetype = $q->param ('queue');
if ($msgid =~ /^([0-9A-F]+)$/ ) {
$msgid = $1;
} else {
$msgid = undef;
}
esmith::cgi::genHeaderNonCacheable ($q, \%conf,
$fm->localise('DELETE_MSG_TITLEB'));
print $q->hr;
print $q->p($fm->localise('DELETE_MESSAGE')),"\n";
my $Message = `/usr/sbin/pfHandle -m$msgid|head -100`;
print $q->textarea (-name => 'message', -override => 1, -default => "$Message", -rows => 30, -cols => 80);
print $q->start_multipart_form(-method => 'POST', -action => $q->url (-absolute => 1));
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4},
esmith::cgi::genButtonRow ($q,
$q->submit (-name => 'action', -value => $fm->localise('Delete'))));
print $q->hidden (-name => 'state', -override => 1, -default => 'perform');
print $q->hidden (-name => 'msgid', -override => 1, -default => "$msgid");
print $q->hidden (-name => 'function', -override => 1, -default => 'delete-message-number');
print $q->hidden (-name => 'queue', -override => 1, -default => "$queuetype");
print $q->end_form;
esmith::cgi::genFooter ($q);
return;
}
sub deleteMessageNumber ($)
{
my ($q) = @_;
my $msgid = $q->param ('msgid');
my $queuetype = $q->param ('queue');
if ($msgid =~ /^([0-9A-F]+)$/ ) {
$msgid = $1;
} else {
$msgid = undef;
}
my $Output = `/usr/sbin/pfHandle -D$msgid`;
esmith::cgi::genHeaderNonCacheable ($q, \%conf,
"qmail: ". $fm->localise('QMH_TITLE'));
print $q->hr;
print $q->h3 ($fm->localise('DELETED'))," $msgid ";
print $q->br();
print $q->br();
print $q->start_multipart_form(-method => 'POST', -action => $q->url (-absolute => 1));
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4},
esmith::cgi::genButtonRow ($q,
$q->submit (-name => 'action', -value => $fm->localise('RETURN_TO_QUEUE'))));
print $q->hidden (-name => 'state', -override => 1, -default => 'perform');
print $q->hidden (-name => 'function', -override => 1, -default => "$queuetype");
print $q->end_form;
esmith::cgi::genFooter ($q);
return;
}
__DATA__
<form>
</form>