#! /usr/bin/perl
+# https://datatracker.ietf.org/doc/html/rfc1870
use strict;
use warnings;
require Net::DNS;
use HTML::Entities;
require URI::Query;
use POSIX;
+$|=1;
die "arg required" if @ARGV!=!$ENV{"GATEWAY_INTERFACE"};
my $arg=$ARGV[0];
}
return @retval;
}
-if ($arg) {
+sub load_ok() {
+ local *F;
+ open F,"/proc/loadavg" or die;
+ my $load=defined <F> or die;
+ close F or die;
+ $load=~s/ .*//;
+ return 1 if $load<16;
+ print "<p>Sorry but the current machine load ($load) does not permit running this service now. Try again later.</p>\n";
+ return 0;
+}
+if ($arg&&load_ok()) {
print "<pre>\n";
my @r=query $arg;
print "</pre>\n";
print "<p>Error: Unable to determine anything about domain ".encode_entities($arg)."</p>\n";
} else {
my $size=$r[0][1];
+ my $different;
for my $r (@r) {
- $size=undef if !$size||!$r->[1]||$size!=$r->[1];
+ $different=1 if ($size//-1)!=($r->[1]//-1);
}
sub sizecalc($) {
my($input_size)=@_;
}
sub rev($) {
my($size)=@_;
+ return 0 if $size==0;
my $l=0;
my $r=$size;
while ($l+1<$r) {
}
sub size($) {
my($size)=@_;
- return "unknown" if !$size;
+ return "unknown" if !defined $size;
+ return "unlimited" if $size==0;
my $rev=rev($size);
return human($rev)." ($rev bytes; raw text mail size $size)";
}
- if ($size) {
+ if (!$different) {
print "<p>Domain ".encode_entities($arg)." has maximum attachment size ".size($size)."</p>\n";
} else {
print "<p>Domain ".encode_entities($arg)." maximum attachment size depends on which server is contacted:</p>";
if ($ENV{"GATEWAY_INTERFACE"}) {
print <<"EOH";
<p>
- <form action="/cgi-bin/smtpsize" method="get">
+ <form action="mailsize.cgi" method="get">
<input type="text" name="domain" size="32" value="@{[ encode_entities($arg||"") ]}" autofocus="autofocus" />
<input type="submit">
</form>