Skip to content

Instantly share code, notes, and snippets.

@moisseev
Created April 30, 2015 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moisseev/f27aaa9a771b3d66830e to your computer and use it in GitHub Desktop.
Save moisseev/f27aaa9a771b3d66830e to your computer and use it in GitHub Desktop.
BackupPC CGI: Set 404 status code to HTTP header for all objects returned on error.
--- ./lib/BackupPC/CGI/Lib.pm.orig 2015-04-30 16:04:21.000000000 +0300
+++ ./lib/BackupPC/CGI/Lib.pm 2015-04-30 17:04:54.000000000 +0300
@@ -289,7 +289,12 @@
Trailer();
} else {
my $content = eval("qq{$Lang->{Error____head}}");
- Header(eval("qq{$Lang->{Error}}"), $content);
+ Header(
+ eval("qq{$Lang->{Error}}"),
+ $content,
+ (undef) x 3,
+ '404 Not Found'
+ );
Trailer();
}
exit(1);
@@ -435,7 +440,7 @@
sub Header
{
- my($title, $content, $noBrowse, $contentSub, $contentPost) = @_;
+ my($title, $content, $noBrowse, $contentSub, $contentPost, $status) = @_;
my @adminLinks = (
{ link => "", name => $Lang->{Status}},
{ link => "?action=summary", name => $Lang->{PC_Summary}},
@@ -459,7 +464,7 @@
my $host = $In{host};
binmode(STDOUT, ":utf8");
- print $Cgi->header(-charset => "utf-8");
+ print $Cgi->header(-charset => "utf-8", -status=> $status);
print <<EOF;
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
@moisseev
Copy link
Author

This patch in not against source code but against installed FreeBSD package backuppc-3.3.0_7.
404 status code for every error is stupid, but quick and easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment