Start of work on SMTP monitor

This commit is contained in:
Jamie Cameron
2024-03-11 20:39:59 -07:00
parent a9d0f8b704
commit 0704ac640e
2 changed files with 71 additions and 6 deletions

View File

@@ -74,6 +74,8 @@ type_alive=Alive System
type_rssh=SSH Connection
type_slapd=LDAP Server
type_ldap=LDAP Connection
type_smtp=SMTP Connection
type_imap=IMAP Connection
mon_create=Create Monitor
mon_edit=Edit Monitor
@@ -582,4 +584,22 @@ info_desc=System monitor
info_last=Current status
info_title=System and Server Status
smtp_host=SMTP server host
smtp_port=SMTP server port
smtp_ssl=Use SSL?
smtp_ssl0=Plaintext only
smtp_ssl1=Always SSL
smtp_ssl2=Switch to SSL with STARTTLS
smtp_from=Test SMTP sender
smtp_none=None
smtp_addr=Use address
smtp_to=Test SMTP recipient
smtp_ehost=Missing or unresolvable SMTP server host
smtp_eport=Missing or non-numeric SMTP server port
smtp_efrom=Sender address must be like user@domain.com
smtp_eto=Recipient address must be like user@domain.com
smtp_ok1=HELO command accepted
smtp_ok2=Sender address accepted
smtp_ok3=Recipient address accepted
__norefs=1

View File

@@ -6,9 +6,10 @@ my ($serv) = @_;
&foreign_require("mailboxes");
$main::error_must_die = 1;
my $desc;
eval {
my $h = { 'fh' => 'MAIL' };
&open_socket($server, $port, $h->{'fh'});
&open_socket($serv->{'host'}, $serv->{'port'}, $h->{'fh'});
if ($serv->{'ssl'} == 1) {
# Switch to SSL mode right now
&switch_smtp_to_ssl($h);
@@ -27,15 +28,27 @@ eval {
$serv->{'ssl'} = 0;
}
}
# XXX
$desc = $text{'smtp_ok1'};
# Open an SMTP transaction
if ($serv->{'from'}) {
&mailboxes::smtp_command($h, "mail from: <$serv->{'from'}>\r\n");
$desc = $text{'smtp_ok2'};
}
if ($serv->{'to'}) {
&mailboxes::smtp_command($h, "rcpt to: <$serv->{'to'}>\r\n");
$desc = $text{'smtp_ok3'};
}
&mailboxes::smtp_command($h, "quit\r\n");
&close_http_connection($h);
};
if ($@) {
$err = &entities_to_ascii(&html_tags_to_text("$@"));
$err = &entities_to_ascii("$@");
$err =~ s/at\s+\S+\s+line\s+\d+.*//;
return { 'up' => 0,
'desc' => $err };
}
return { 'up' => 1 };
return { 'up' => 1, 'desc' => $desc };
}
sub switch_smtp_to_ssl
@@ -62,10 +75,24 @@ print &ui_table_row($text{'smtp_host'},
&ui_textbox("host", $serv->{'host'}, 25));
print &ui_table_row($text{'smtp_port'},
&ui_textbox("port", $serv->{'port'}, 5));
&ui_textbox("port", $serv->{'port'} || 25, 5));
print &ui_table_row($text{'smtp_ssl'},
&ui_radio("ssl", $serv->{'ssl'} || 0,
[ [ 0, $text{'smtp_ssl0'} ],
[ 1, $text{'smtp_ssl1'} ],
[ 2, $text{'smtp_ssl2'} ] ]));
print &ui_table_row($text{'smtp_from'},
&ui_opt_textbox("from", $serv->{'from'}, 25,
$text{'smtp_none'}, $text{'smtp_addr'}));
print &ui_table_row($text{'smtp_to'},
&ui_opt_textbox("to", $serv->{'to'}, 25,
$text{'smtp_none'}, $text{'smtp_addr'}));
}
sub parse_tcp_dialog
sub parse_smtp_dialog
{
my ($serv) = @_;
@@ -75,6 +102,24 @@ $serv->{'host'} = $in{'host'};
$in{'port'} =~ /^\d+$/ || &error($text{'smtp_eport'});
$serv->{'port'} = $in{'port'};
$serv->{'ssl'} = $in{'ssl'};
if ($in{'from_def'}) {
delete($serv->{'from'});
}
else {
$in{'from'} =~ /^\S+\@\S+$/ || &error($text{'smtp_efrom'});
$serv->{'from'} = $in{'from'};
}
if ($in{'to_def'}) {
delete($serv->{'to'});
}
else {
$in{'to'} =~ /^\S+\@\S+$/ || &error($text{'smtp_eto'});
$serv->{'to'} = $in{'to'};
}
}
1;