r11109 - /man-cgi/man.cgi
Author: jfs
Date: Sun Apr 17 15:22:12 2016
New Revision: 11109
URL: http://svn.debian.org/wsvn/?sc=1&rev=11109
Log:
- Use CGI.pm's print header to print the HTTP headers
- Add caching values to content return. this will be provided
by CGI.pm in the "old" Expires: HTTP header
- Make the references to the information and help pages work
now by moving them into specific queries
Modified:
man-cgi/man.cgi
Modified: man-cgi/man.cgi
URL: http://svn.debian.org/wsvn/man-cgi/man.cgi?rev=11109&op=diff
==============================================================================
--- man-cgi/man.cgi (original)
+++ man-cgi/man.cgi Sun Apr 17 15:22:12 2016
@@ -291,7 +291,7 @@
# Set up CGI cache
CGI::Cache::setup();
-# Set up a cache in /manpages_cache/man-cgi, with publicly
+# Set up a cache in manpages_cache/man-cgi, with publicly
# unreadable cache entries, a maximum size of 10 megabytes,
# and a time-to-live of 24 hours.
CGI::Cache::setup( { cache_options =>
@@ -340,10 +340,10 @@
local($u) = $www{'home'}.'/cgi-bin/man.cgi';
local($u)= $BASE;
- return &faq_output($u) if ($path =~ /\/(faq|help)\.html$/);
- return &info_output($u) if ($path =~ /\/info\.html$/);
- #return ©right_output($u) if ($path =~ /copyright.html$/);
- return &get_the_sources if ($path =~ /source$/);
+ return &faq_output($u) if ($name =~ /(faq|help)\.html$/);
+ return &info_output($u) if ($name =~ /info\.html$/);
+ #return ©right_output($u) if ($name =~ /copyright.html$/);
+ return &get_the_sources if ($name =~ /source$/);
return &include_output($path)
if ($enable_include_links && $path =~ m%^/usr/include/% && -f $path);
@@ -390,7 +390,7 @@
# --------------------- support routines ------------------------
sub debug {
- &http_header("text/plain");
+ print header (-type=>'text/plain');
print @_,"\n----------\n\n\n";
}
@@ -399,7 +399,7 @@
$file = $0 if ! -f $file;
open(R, $file) || &mydie("open $file: $!\n");
- print "Content-type: text/plain\n\n";
+ &http_header ("text/plain", "+10d");
while(<R>) { print }
close R;
exit;
@@ -410,7 +410,7 @@
$file = $0 if ! -f $file;
open(R, $file) || &mydie("open $file: $!\n");
- print "Content-type: text/plain\n\n";
+ &http_header ("text/plain", "+3d");
while(<R>) { print }
close R;
exit;
@@ -426,9 +426,7 @@
$filename = &encode_url($filename);
$filename .= '.tar.gz';
- print qq{Content-type: application/x-gzip\n} .
- qq{Content-disposition: attachment; filename="$filename"\n} .
- "\n";
+ print header (-type=>'application/x-gzip', -expires=>'+10d', -attachment => "$filename");
local(@m);
local($m) = $manPath{"$manpath"};
@@ -448,21 +446,23 @@
exit(0);
}
-sub http_header {
- local($content_type) = @_;
- print "Content-type: $content_type\n\n";
+# Print the HTTP header for the pages
+sub http_header ($;$) {
+ local($content_type, $expiration) = @_;
+ $expiration = "now" if ! defined $expiration;
+ print header (-type=> "$content_type", -expires=> "$expiration");
}
sub env { defined($main'ENV{$_[0]}) ? $main'ENV{$_[0]} : undef; }
-sub printenv {
+sub printenv () {
# Print the environment, useful for debugging
while (($key,$value) = each %ENV) {
print "$key=$value\n";
}
}
-sub apropos {
+sub apropos ($){
local($query) = @_;
local($_, $title, $head, *APROPOS);
local($names, $section, $msg, $key);
@@ -480,7 +480,8 @@
$head = &encode_data($query);
}
- &http_header("text/html");
+ print header (type=>'text/html',
+ -expires=>'+3h');
print &html_header("Apropos $title");
print "<H1>$www{'head'}</H1>\n\n";
&formquery;
@@ -593,7 +594,7 @@
if ($format eq "html") {
$header="text/html";
$header = $header."; charset=".lc($charset) if $charset;
- &http_header("$header");
+ &http_header("$header", "+1d");
print &html_header("$title");
print "<H1>$www{'head'}</H1>\n\n";
&formquery;
@@ -603,17 +604,17 @@
# Content-encoding: x-gzip
if ($format eq "ps") {
- &http_header("application/postscript");
+ &http_header("application/postscript", "+1d");
} elsif ($format eq "pdf") {
- &http_header("application/pdf");
+ &http_header("application/pdf", "+1d");
} elsif ($format eq "dvi") {
- &http_header("application/x-dvi");
+ &http_header("application/x-dvi", "+1d");
} elsif ($format eq "troff") {
- &http_header("application/x-troff-mandoc");
+ &http_header("application/x-troff-mandoc", "+1d");
} else {
$header="text/plain";
$header = $header."; charset=".lc($charset) if $charset;
- &http_header($header);
+ &http_header($header, "+1d");
}
}
@@ -725,7 +726,7 @@
# run a PostScript to PDF converter
#
# TODO: Use Perl's Temp:: implementation
- local(@args) = ('mktemp', '/tmp/_man.cgi-ps2pdf-XXXXXXXXXXXX');
+ local(@args) = ('mktemp', $baseDir.'/manpages_cache/_man.cgi-ps2pdf-XXXXXXXXXXXX');
open(TMP, "-|") or
exec(@args) or die "open @args: $!\n";
local($tempfile) = <TMP>;
@@ -740,9 +741,7 @@
if (!$tempfile || ! -f $tempfile) {
die "Cannot create tempfile: $tempfile\n";
}
- #warn $tempfile;
-
- #$tempfile = '/tmp/bla2';
+
open(TMP, "> $tempfile") or die "open $tempfile: $!\n";
while(<MAN>) {
print TMP $_;
@@ -1055,7 +1054,7 @@
}
sub indexpage {
- &http_header("text/html");
+ &http_header("text/html", "+7d");
print &html_header("$www{'title'}: Index Page") .
"<H1>$www{'head'}</H1>\n\n" . &intro;
# If the content is out of date print a warning:
@@ -1231,9 +1230,9 @@
print <<ETX;
</FORM>
-<A HREF="$BASE?manpath=$m">home</A> |
-<A HREF="$BASE/help.html">help</A> |
-<A HREF="$BASE/info.html">more information</A>.
+<A HREF="$BASE">home</A> |
+<A HREF="$BASE?query=help.html">help</A> |
+<A HREF="$BASE?query=info.html">more information</A>.
<HR>
ETX
0;
@@ -1426,7 +1425,7 @@
}
sub copyright_output {
- &http_header("text/html");
+ &http_header("text/html", "+7d");
print &html_header("HTML hypertext Debian man page interface") .
"<H1>$www{'head'}</H1>\n" . ©right . qq{\
<HR>
@@ -1437,7 +1436,7 @@
}
sub faq_output {
- &http_header("text/html");
+ &http_header("text/html", "+7d");
print &html_header("HTML hypertext Debian man page interface") .
"<H1>$www{'head'}</H1>\n" . &faq . qq{\
<HR>
@@ -1448,7 +1447,7 @@
}
sub info_output {
- &http_header("text/html");
+ &http_header("text/html", "+7d");
print &html_header("HTML hypertext Debian man page interface") . &info . qq{\
<HR>
@@ -1554,7 +1553,7 @@
sub include_output {
local($inc) = @_;
- &http_header("text/plain");
+ &http_header("text/plain", "+1d");
open(I, "$inc") || do { print "open $inc: $!\n"; exit(1) };
while(<I>) { print }
close(I);
@@ -1576,10 +1575,10 @@
# CGI script must die with error status 0
-sub mydie {
+sub mydie ($) {
local($message) = @_;
- &http_header("text/html");
- print &html_header("Error");
+ print header (-type=>'text/html', -status=>"500 Server Error");
+ print &html_header("CGI Error");
print "<H1>$www{'head'}</H1>\n\n";
print "<P>".$message."</P>";
Reply to: