Fix bad design that I shouldn't have ever added #1466
This commit is contained in:
parent
5110269a57
commit
49f75d239a
68
miniserv.pl
68
miniserv.pl
@ -2128,9 +2128,9 @@ if ($config{'userfile'}) {
|
|||||||
&write_data("\r\n");
|
&write_data("\r\n");
|
||||||
&reset_byte_count();
|
&reset_byte_count();
|
||||||
&write_data("<html>\n");
|
&write_data("<html>\n");
|
||||||
&write_data("<head><title>401 — Unauthorized</title></head>\n");
|
&write_data("<head>".&embed_error_styles($roots[0])."<title>401 — Unauthorized</title></head>\n");
|
||||||
&write_data("<body><h2 @{[get_error_style('heading')]}>401 — Unauthorized</h2>\n");
|
&write_data("<body><h2 class=\"err-head\">401 — Unauthorized</h2>\n");
|
||||||
&write_data("<p @{[get_error_style('content')]}>A password is required to access this\n");
|
&write_data("<p class=\"err-content\">A password is required to access this\n");
|
||||||
&write_data("web server. Please try again.</p> <p>\n");
|
&write_data("web server. Please try again.</p> <p>\n");
|
||||||
&write_data("</body></html>\n");
|
&write_data("</body></html>\n");
|
||||||
&log_request($loghost, undef, $reqline, 401, &byte_count());
|
&log_request($loghost, undef, $reqline, 401, &byte_count());
|
||||||
@ -2389,8 +2389,8 @@ if (-d _) {
|
|||||||
&write_keep_alive(0);
|
&write_keep_alive(0);
|
||||||
&write_data("\r\n");
|
&write_data("\r\n");
|
||||||
&reset_byte_count();
|
&reset_byte_count();
|
||||||
&write_data("<h2 @{[get_error_style('heading')]}>Index of $simple</h2>\n");
|
&write_data("".&embed_error_styles($roots[0])."<h2 class=\"err-head\">Index of $simple</h2>\n");
|
||||||
&write_data("<pre @{[get_error_style('content')]}>\n");
|
&write_data("<pre class=\"err-content\">\n");
|
||||||
&write_data(sprintf "%-35.35s %-20.20s %-10.10s\n",
|
&write_data(sprintf "%-35.35s %-20.20s %-10.10s\n",
|
||||||
"Name", "Last Modified", "Size");
|
"Name", "Last Modified", "Size");
|
||||||
&write_data("</pre>\n");
|
&write_data("</pre>\n");
|
||||||
@ -2810,10 +2810,10 @@ else {
|
|||||||
&write_data("\r\n");
|
&write_data("\r\n");
|
||||||
&reset_byte_count();
|
&reset_byte_count();
|
||||||
&write_data("<html>\n");
|
&write_data("<html>\n");
|
||||||
&write_data("<head><title>$code — $msg</title></head>\n");
|
&write_data("<head>".&embed_error_styles($roots[0])."<title>$code — $msg</title></head>\n");
|
||||||
&write_data("<body @{[get_error_style('body')]}><h2 @{[get_error_style('heading')]}>Error — $msg</h2>\n");
|
&write_data("<body class=\"err-body\"><h2 class=\"err-head\">Error — $msg</h2>\n");
|
||||||
if ($body) {
|
if ($body) {
|
||||||
&write_data("<p @{[get_error_style('content')]}>$body</p>\n");
|
&write_data("<p class=\"err-content\">$body</p>\n");
|
||||||
}
|
}
|
||||||
&write_data("</body></html>\n");
|
&write_data("</body></html>\n");
|
||||||
}
|
}
|
||||||
@ -2824,6 +2824,23 @@ shutdown(SOCK, 1);
|
|||||||
exit if (!$noexit);
|
exit if (!$noexit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# embed_error_styles()
|
||||||
|
# Returns HTML styles for nicer errors. For internal use only.
|
||||||
|
sub embed_error_styles
|
||||||
|
{
|
||||||
|
my ($root) = @_;
|
||||||
|
if ($root) {
|
||||||
|
my $err_style = &read_any_file("$root/unauthenticated/errors.css");
|
||||||
|
if ($err_style) {
|
||||||
|
$err_style =~ s/[\n\r]//g;
|
||||||
|
$err_style =~ s/\s+/ /g;
|
||||||
|
$err_style = "<style data-err type=\"text/css\">$err_style</style>";
|
||||||
|
return "\n$err_style\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
sub get_type
|
sub get_type
|
||||||
{
|
{
|
||||||
if ($_[0] =~ /\.([A-z0-9]+)$/) {
|
if ($_[0] =~ /\.([A-z0-9]+)$/) {
|
||||||
@ -3137,7 +3154,7 @@ local($idx, $more, $rv);
|
|||||||
while(($idx = index($main::read_buffer, "\n")) < 0) {
|
while(($idx = index($main::read_buffer, "\n")) < 0) {
|
||||||
if (length($main::read_buffer) > 100000 && !$nolimit) {
|
if (length($main::read_buffer) > 100000 && !$nolimit) {
|
||||||
&http_error(414, "Request too long",
|
&http_error(414, "Request too long",
|
||||||
"Received excessive line <pre @{[get_error_style('content')]}>".&html_strip($main::read_buffer)."</pre>");
|
"Received excessive line <pre class=\"err-content\">".&html_strip($main::read_buffer)."</pre>");
|
||||||
}
|
}
|
||||||
|
|
||||||
# need to read more..
|
# need to read more..
|
||||||
@ -4681,6 +4698,20 @@ close(CONF);
|
|||||||
return %rv;
|
return %rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# read_any_file(file)
|
||||||
|
# Reads any given file and returns its content
|
||||||
|
sub read_any_file
|
||||||
|
{
|
||||||
|
my ($realfile) = @_;
|
||||||
|
my $rv;
|
||||||
|
return $rv if (! -r $realfile);
|
||||||
|
open(my $fh, "<".$realfile);
|
||||||
|
local $/;
|
||||||
|
$rv = <$fh>;
|
||||||
|
close($fh);
|
||||||
|
return $rv;
|
||||||
|
}
|
||||||
|
|
||||||
# update_vital_config()
|
# update_vital_config()
|
||||||
# Updates %config with defaults, and dies if something vital is missing
|
# Updates %config with defaults, and dies if something vital is missing
|
||||||
sub update_vital_config
|
sub update_vital_config
|
||||||
@ -6472,22 +6503,3 @@ sub getenv
|
|||||||
my ($key) = @_;
|
my ($key) = @_;
|
||||||
return $ENV{ uc($key) } || $ENV{ lc($key) };
|
return $ENV{ uc($key) } || $ENV{ lc($key) };
|
||||||
}
|
}
|
||||||
|
|
||||||
# get_error_style(style_for)
|
|
||||||
# Returns a style for error messages
|
|
||||||
sub get_error_style
|
|
||||||
{
|
|
||||||
my ($type, $extra_style) = @_;
|
|
||||||
my $style = ' style="font-family:Lucida Console,Courier,monospace;';
|
|
||||||
if ($type eq 'heading') {
|
|
||||||
$style .= 'color:#f12b2b;font-size:14px;padding:5px 2.5px 0;transform:scale(1,1.5);text-transform:uppercase;white-space:pre-wrap;font-weight:500;';
|
|
||||||
}
|
|
||||||
if ($type eq 'content') {
|
|
||||||
$style .= 'font-size:12.5px;padding-left:2.5px;white-space:pre-wrap;';
|
|
||||||
}
|
|
||||||
if ($type eq 'body') {
|
|
||||||
$style .= 'font-size:12.5px;';
|
|
||||||
}
|
|
||||||
$style .= "$extra_style\"";
|
|
||||||
return $style;
|
|
||||||
}
|
|
||||||
|
81
unauthenticated/errors.css
Normal file
81
unauthenticated/errors.css
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
.err-head,
|
||||||
|
.err-content,
|
||||||
|
.err-body {
|
||||||
|
font-family: Lucida Console, Courier, monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.err-head {
|
||||||
|
color: #f12b2b;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
padding: 5px 2.5px 0;
|
||||||
|
text-transform: uppercase;
|
||||||
|
transform: scale(1, 1.5);
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.err-content {
|
||||||
|
padding-left: 2.5px;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.err-content,
|
||||||
|
.err-body {
|
||||||
|
font-size: 12.5px;
|
||||||
|
}
|
||||||
|
.err-head[data-fatal-error-text] {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.err-stack caption,
|
||||||
|
.err-stack > tbody > tr:first-child > td > b {
|
||||||
|
color: #151515;
|
||||||
|
font-weight: bold;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.err-stack > tbody > tr:first-child > td > b {
|
||||||
|
border-bottom: 1px solid #151515;
|
||||||
|
}
|
||||||
|
|
||||||
|
.err-stack > tbody > tr:first-child>td {
|
||||||
|
font-family: unset;
|
||||||
|
font-size: 14px;
|
||||||
|
height: 25px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
transform: scale(1, 1.2);
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
|
||||||
|
.err-stack {
|
||||||
|
border: 1px dashed #151515
|
||||||
|
}
|
||||||
|
|
||||||
|
.err-stack.captured {
|
||||||
|
margin-left: 12px;
|
||||||
|
width: auto
|
||||||
|
}
|
||||||
|
.err-stack tr td {
|
||||||
|
font-family: Lucida Console, Courier, monospace;
|
||||||
|
font-size: 13px;
|
||||||
|
padding: 1px 10px;
|
||||||
|
transform: scale(1, 1.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.err-stack tr:not(:first-child) td.captured {
|
||||||
|
font-size: 90%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.err-stack > tr:first-child > td.captured {
|
||||||
|
font-size: 96%;
|
||||||
|
padding-bottom: 7px;
|
||||||
|
padding-top: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.err-stack caption.err-head {
|
||||||
|
padding:0 0 10px 0;
|
||||||
|
}
|
||||||
|
.err-stack caption.err-head.captured {
|
||||||
|
color: #222;
|
||||||
|
font-size:98%;
|
||||||
|
}
|
@ -1659,9 +1659,16 @@ elsif ($ENV{'REQUEST_URI'} =~ /json-error=1/) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
&header($text{'error'}, "");
|
&header($text{'error'}, "");
|
||||||
my $hh = $miniserv::page_capture;
|
my $hh = $miniserv::page_capture ? " captured" : "";
|
||||||
|
my $err_style = &read_file_contents("$root_directory/unauthenticated/errors.css");
|
||||||
|
if ($err_style) {
|
||||||
|
$err_style =~ s/[\n\r]//g;
|
||||||
|
$err_style =~ s/\s+/ /g;
|
||||||
|
$err_style = "<style data-err type=\"text/css\">$err_style</style>";
|
||||||
|
print "\n$err_style\n";
|
||||||
|
}
|
||||||
print "<hr>\n" if ($hh);
|
print "<hr>\n" if ($hh);
|
||||||
if ($hh) {
|
if ($hh) {
|
||||||
print "<h3 data-fatal-error-text>",($main::whatfailed ? "$main::whatfailed : " : ""),
|
print "<h3 data-fatal-error-text>",($main::whatfailed ? "$main::whatfailed : " : ""),
|
||||||
@_,"</h3>\n";
|
@_,"</h3>\n";
|
||||||
}
|
}
|
||||||
@ -1673,32 +1680,22 @@ else {
|
|||||||
$error_text = " — $error_html";
|
$error_text = " — $error_html";
|
||||||
$error_html = undef;
|
$error_html = undef;
|
||||||
}
|
}
|
||||||
print "<title>$text{'error'}</title><h3 @{[miniserv::get_error_style('heading', 'padding:0;')]} data-fatal-error-text>$text{'error'}$error_text</h3>$error_html<br>\n";
|
print "<title>$text{'error'}</title><h3 class=\"err-head\" data-fatal-error-text>$text{'error'}$error_text</h3>$error_html<br>\n";
|
||||||
}
|
}
|
||||||
if ($gconfig{'error_stack'}) {
|
if ($gconfig{'error_stack'}) {
|
||||||
# Show call stack
|
# Show call stack
|
||||||
print "<style>\n";
|
my $cls_err_caption = " class=\"err-head$hh\"";
|
||||||
print "table.config-error-stack caption, table.config-error-stack > tbody > tr:first-child > td > b {color: #151515;font-weight:bold;text-align: left;}\n";
|
my $cls_err_td = $hh ? " class=\"@{[&trim($hh)]}\"" : "";
|
||||||
print "table.config-error-stack > tbody > tr:first-child > td > b {border-bottom: 1px solid #151515;}\n";
|
|
||||||
print "table.config-error-stack > tbody > tr:first-child > td {height: 25px;vertical-align:top;font-size:14px;font-family:unset;transform:scale(1,1.2);text-transform:uppercase;}\n";
|
|
||||||
print "table.config-error-stack {border: 1px dashed #151515}\n";
|
|
||||||
print "table.config-error-stack {margin-left: 12px;width:auto}\n" if ($hh);
|
|
||||||
print "table.config-error-stack tr:not(:first-child) td {font-size: 90%;}\n" if ($hh);
|
|
||||||
print "table.config-error-stack tr td {padding: 1px 10px!important;font-family:Lucida Console,Courier,monospace;font-size:13px;transform:scale(1,1.15);}\n";
|
|
||||||
print "table.config-error-stack > tbody > tr:first-child > td{font-size:96%; font-size: 96%;padding-top:3px!important;padding-bottom:7px!important;}\n" if ($hh);
|
|
||||||
print "</style>\n";
|
|
||||||
my $caption_no_header_style =
|
|
||||||
&miniserv::get_error_style('heading', "padding:0 0 10px 0;" . ($hh ? "color: #222;font-size:98%;" : "") . "");
|
|
||||||
print "<hr>\n" if ($hh);
|
print "<hr>\n" if ($hh);
|
||||||
print "<table class=\"config-error-stack\"><caption$caption_no_header_style>$text{'error_stack'}</caption>\n";
|
print "<table class=\"err-stack$hh\"><caption$cls_err_caption>$text{'error_stack'}</caption>\n";
|
||||||
print "<tr> <td><b>$text{'error_file'}</b></td> ",
|
print "<tr> <td$cls_err_td><b>$text{'error_file'}</b></td> ",
|
||||||
"<td><b>$text{'error_line'}</b></td> ",
|
"<td$cls_err_td><b>$text{'error_line'}</b></td> ",
|
||||||
"<td><b>$text{'error_sub'}</b></td> </tr>\n";
|
"<td$cls_err_td><b>$text{'error_sub'}</b></td> </tr>\n";
|
||||||
for($i=0; my @stack = caller($i); $i++) {
|
for($i=0; my @stack = caller($i); $i++) {
|
||||||
print "<tr>\n";
|
print "<tr>\n";
|
||||||
print "<td>$stack[1]</td>\n";
|
print "<td$cls_err_td>$stack[1]</td>\n";
|
||||||
print "<td>$stack[2]</td>\n";
|
print "<td$cls_err_td>$stack[2]</td>\n";
|
||||||
print "<td>$stack[3]</td>\n";
|
print "<td$cls_err_td>$stack[3]</td>\n";
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
}
|
}
|
||||||
print "</table>\n";
|
print "</table>\n";
|
||||||
@ -3854,7 +3851,7 @@ else {
|
|||||||
delete($ENV{'FOREIGN_ROOT_DIRECTORY'});
|
delete($ENV{'FOREIGN_ROOT_DIRECTORY'});
|
||||||
}
|
}
|
||||||
@INC = @OLDINC;
|
@INC = @OLDINC;
|
||||||
if ($@) { &error("<pre @{[miniserv::get_error_style('content')]}>Require $mod/$files[0] failed : $@</pre>"); }
|
if ($@) { &error("<pre class=\"err-content\">Require $mod/$files[0] failed : $@</pre>"); }
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user