qpsmtpd/plugins/help

143 lines
3.8 KiB
Plaintext
Raw Normal View History

POD corrections, additional tests, plugin consistency on files in plugins dir: fixed a number of POD errors formatted some # comments into POD removed bare 1; (these are plugins, not perl modules) most instances of this were copy/pasted from a previous plugin that had it removed instances of # vim ts=N ... they weren't consistent, many didn't match .perltidyrc on modules that failed perl -c tests, added 'use Qpsmtpd::Constants;' Conflicts: plugins/async/check_earlytalker plugins/async/dns_whitelist_soft plugins/async/dnsbl plugins/async/queue/smtp-forward plugins/async/require_resolvable_fromhost plugins/async/rhsbl plugins/async/uribl plugins/auth/auth_checkpassword plugins/auth/auth_cvm_unix_local plugins/auth/auth_flat_file plugins/auth/auth_ldap_bind plugins/auth/auth_vpopmail plugins/auth/auth_vpopmail_sql plugins/auth/authdeny plugins/check_badmailfromto plugins/check_badrcptto_patterns plugins/check_bogus_bounce plugins/check_earlytalker plugins/check_norelay plugins/check_spamhelo plugins/connection_time plugins/dns_whitelist_soft plugins/dnsbl plugins/domainkeys plugins/greylisting plugins/hosts_allow plugins/http_config plugins/logging/adaptive plugins/logging/apache plugins/logging/connection_id plugins/logging/transaction_id plugins/logging/warn plugins/milter plugins/queue/exim-bsmtp plugins/queue/maildir plugins/queue/postfix-queue plugins/queue/smtp-forward plugins/quit_fortune plugins/random_error plugins/rcpt_map plugins/rcpt_regexp plugins/relay_only plugins/require_resolvable_fromhost plugins/rhsbl plugins/sender_permitted_from plugins/spamassassin plugins/tls plugins/tls_cert plugins/uribl plugins/virus/aveclient plugins/virus/bitdefender plugins/virus/clamav plugins/virus/clamdscan plugins/virus/hbedv plugins/virus/kavscanner plugins/virus/klez_filter plugins/virus/sophie plugins/virus/uvscan
2012-04-08 02:11:16 +02:00
#!perl -Tw
=head1 NAME
help - default help plugin for qpsmtpd
=head1 DESCRIPTION
The B<help> plugin gives the answers for the help command. It can be configured
to return C<502 Not implemented>.
Without any arguments, the C<help_dir> is set to F<./help/>.
=head1 OPTIONS
=over 4
=item not_implemented (1|0)
If this option is set (and the next argument is true), the plugin answers,
that the B<HELP> command is not implemented
=item help_dir /path/to/help/files/
When a client requests help for C<COMMAND> the file F</path/to/help/files/
. lc(COMMAND)> is dumped to the client if it exists.
=item COMMAND HELPFILE
Any other argument pair is treated as command / help file pair. The file is
expexted in the F<help/> sub directory. If the client calls C<HELP COMMAND>
the contents of HELPFILE are dumped to him.
=back
=head1 NOTES
The hard coded F<help/> path should be changed.
=cut
my %config = ();
sub register {
my ($self,$qp,%args) = @_;
my ($file, $cmd);
unless (%args) {
$config{help_dir} = './help/';
}
foreach (keys %args) {
/^(\w+)$/ or
$self->log(LOGWARN, "Invalid argument for the 'help' plugin $_"),
next;
$cmd = $1;
if ($cmd eq 'not_implemented') {
$config{'not_implemented'} = $args{'not_implemented'};
}
elsif ($cmd eq 'help_dir') {
$file = $args{$cmd};
$file =~ m#^([\w\.\-/]+)$#
or $self->log(LOGERROR,
"Invalid charachters in filename for command $cmd"),
next;
$config{'help_dir'} = $1;
}
else {
$file = $args{$cmd};
$file =~ m#^([\w\.\-/]+)$#
or $self->log(LOGERROR,
"Invalid charachters in filename for command $cmd"),
next;
$file = $1;
if ($file =~ m#/#) {
-e $file
or $self->log(LOGWARN, "No help file for command '$cmd'"),
next;
}
else {
$file = "help/$file";
if (-e "help/$file") { ## FIXME: path
$file = "help/$file";
}
else {
$self->log(LOGWARN, "No help file for command '$cmd'");
next;
}
}
$config{lc $cmd} = $file;
}
}
return DECLINED;
}
sub hook_help {
my ($self, $transaction, @args) = @_;
my ($help, $cmd);
if ($config{not_implemented}) {
$self->qp->respond(502, "Not implemented.");
return DONE;
}
return OK, "Try 'HELP COMMAND' for getting help on COMMAND"
unless $args[0];
$cmd = lc $args[0];
unless ($cmd =~ /^(\w+)$/) { # else someone could request
# "HELP ../../../../../../../../etc/passwd"
$self->qp->respond(502, "Invalid command name");
return DONE;
}
$cmd = $1;
if (exists $config{$cmd}) {
$help = read_helpfile($config{$cmd}, $cmd)
or $self->log(LOGERROR, "failed to open help file for $cmd: $!"),
return OK, "No help available for SMTP command: $cmd";
}
elsif (exists $config{'help_dir'} && -e $config{'help_dir'}."/$cmd") {
$help = read_helpfile($config{help_dir}."/$cmd", $cmd)
or $self->log(LOGERROR, "failed to open help file for $cmd: $!"),
return OK, "No help available for SMTP command: $cmd";
}
$help = "No help available for SMTP command: $cmd" # empty file
unless $help;
return OK, split(/\n/, $help);
}
sub read_helpfile {
my ($file,$cmd) = @_;
my $help;
open HELP, $file
or return undef;
{
local $/ = undef;
$help = <HELP>;
};
close HELP;
return $help;
}