Merge from knu-cvsweb 1.104.1.47.

2000-12-29 03:17  knu

	* README.knu: Mention automatic tarball generation feature.

2000-12-29 03:16  knu

	* TODO.knu: Directory sorting was fixed at the same time that "show
	only tags" feature was fixed.

2000-12-29 03:07  knu

	* cvsweb.cgi: Specify --ignore-failed-read on invoking tar(1).

2000-12-29 02:49  knu

	* cvsweb.cgi, cvsweb.conf: Add "automatic tarball generation"
	feature.  You can check out a whole directory in gzipped tarball.

	Obtained from:	Debian package: cvsweb_1.93-1

	Allow space characters in file names. (not tested yet)

Note that automatic tarball generation feature is disabled for the present.
This commit is contained in:
Akinori MUSHA 2000-12-28 18:42:21 +00:00
parent a0a56a50b1
commit badb97994d
Notes: svn2git 2020-12-08 03:00:23 +00:00
svn path=/www/; revision=8565
2 changed files with 115 additions and 22 deletions

View file

@ -43,8 +43,8 @@
# SUCH DAMAGE.
#
# $zId: cvsweb.cgi,v 1.104 2000/11/01 22:05:12 hnordstrom Exp $
# $Id: cvsweb.cgi,v 1.60 2000-12-18 04:43:56 knu Exp $
# $FreeBSD: www/en/cgi/cvsweb.cgi,v 1.59 2000/12/18 04:39:52 knu Exp $
# $Id: cvsweb.cgi,v 1.61 2000-12-28 18:42:21 knu Exp $
# $FreeBSD: www/en/cgi/cvsweb.cgi,v 1.60 2000/12/18 04:43:56 knu Exp $
#
###
@ -80,7 +80,7 @@ use vars qw (
$navigationHeaderColor $tableBorderColor $markupLogColor
$tabstop $state $annTable $sel $curbranch @HideModules
$module $use_descriptions %descriptions @mytz $dwhere $moddate
$use_moddate $has_zlib $gzip_open
$use_moddate $has_zlib $gzip_open $allow_tar
$LOG_FILESEPARATOR $LOG_REVSEPARATOR
);
@ -215,7 +215,7 @@ $LOG_REVSEPARATOR = q/^-{28}$/;
##### End of configuration variables #####
$cgi_style::hsty_base = 'http://www.FreeBSD.org';
$_ = q$FreeBSD: www/en/cgi/cvsweb.cgi,v 1.59 2000/12/18 04:39:52 knu Exp $;
$_ = q$FreeBSD: www/en/cgi/cvsweb.cgi,v 1.60 2000/12/18 04:43:56 knu Exp $;
@_ = split;
$cgi_style::hsty_date = "@_[3,4]";
@ -242,9 +242,10 @@ $verbose = $v;
$checkoutMagic = "~checkout~";
$pathinfo = defined($ENV{PATH_INFO}) ? $ENV{PATH_INFO} : '';
$where = $pathinfo;
$where =~ tr|/|/|s;
$doCheckout = ($where =~ /^\/$checkoutMagic/);
$where =~ s|^/($checkoutMagic)?||;
$where =~ s|/+$||;
$where =~ s|/$||;
$scriptname = defined($ENV{SCRIPT_NAME}) ? $ENV{SCRIPT_NAME} : '';
$scriptname =~ s|^/?|/|;
$scriptname =~ s|/+$||;
@ -308,6 +309,7 @@ $query = $ENV{QUERY_STRING};
if (defined($query) && $query ne '') {
foreach (split(/&/, $query)) {
y/+/ /;
s/%(..)/sprintf("%c", hex($1))/ge; # unquote %-quoted
if (/(\S+)=(.*)/) {
$input{$1} = $2 if ($2 ne "");
@ -418,7 +420,7 @@ foreach $k (keys %ICONS) {
my ($itxt,$ipath,$iwidth,$iheight) = @{$ICONS{$k}};
if ($ipath) {
${"${k}icon"} = sprintf('<IMG SRC="%s" ALT="%s" BORDER="0" WIDTH="%d" HEIGHT="%d">',
htmlquote($ipath), htmlquote($itxt), $iwidth, $iheight)
hrefquote($ipath), htmlquote($itxt), $iwidth, $iheight)
}
else {
${"${k}icon"} = $itxt;
@ -485,10 +487,68 @@ $module = $1;
if ($module && &forbidden_module($module)) {
&fatal("403 Forbidden", "Access to $where forbidden.");
}
#
# Handle tarball downloads before any headers are output.
#
if ($input{tarball}) {
&fatal("403 Forbidden", "Downloading tarballs is prohibited.")
unless $allow_tar;
$where =~ s,/[^/]*$,,;
$where =~ s,^/,,;
my($basedir) = ($where =~ m,([^/]+)$,);
if ($basedir eq '' || $where eq '') {
&fatal("500 Internal Error", "You cannot download the top level directory.");
}
my $tmpdir = "/tmp/.cvsweb.$$." . int(time);
mkdir($tmpdir, 0700)
or &fatal("500 Internal Error", "Unable to make temporary directory: $!");
my $fatal = '';
do {
chdir $tmpdir
or $fatal = "500 Internal Error", "Unable to cd to temporary directory: $!"
&& last;
my @params = (exists $input{only_with_tag} && length $input{only_with_tag})
? ("-r", $input{only_with_tag}) : ();
system "cvs", "-RlQd", $cvsroot, "co", @params, $where
and $fatal = "500 Internal Error","cvs co failure: $!: $where"
&& last;
chdir "$where/.."
or $fatal = "500 Internal Error","Cannot find expected directory in checkout"
&& last;
$| = 1; # Essential to get the buffering right.
print "Content-type: application/x-gzip\r\n\r\n";
system "tar", "--ignore-failed-read", "--exclude", "CVS", "-zcf", "-", $basedir
and $fatal = "500 Internal Error","tar zc failure: $!: $basedir"
&& last;
chdir $tmpdir
or $fatal = "500 Internal Error","Unable to cd to temporary directory: $!"
&& last;
} while (0);
system "rm", "-rf", $tmpdir if -d $tmpdir;
&fatal($fatal) if $fatal;
exit;
}
##############################
# View a directory
###############################
elsif (-d $fullname) {
if (-d $fullname) {
my $dh = do {local(*DH);};
opendir($dh, $fullname) || &fatal("404 Not Found","$where: $!");
my @dir = readdir($dh);
@ -826,6 +886,22 @@ elsif (-d $fullname) {
print "<INPUT TYPE=SUBMIT VALUE=\"Go\">\n";
print "</FORM>\n";
}
if ($allow_tar) {
my($basefile) = ($where =~ m,(?:.*/)?([^/]+),);
if ($basefile ne '') {
print "<HR NOSHADE>\n",
"<DIV align=center>",
&link("Download this directory in tarball",
# Mangle the filename so browsers show a reasonable
# filename to download.
"$basefile.tar.gz$query".
($query ? "&" : "?")."tarball=1"),
"</DIV>";
}
}
my $formwhere = $scriptwhere;
$formwhere =~ s|Attic/?$|| if ($input{'hideattic'});
@ -1134,7 +1210,7 @@ sub spacedHtmlText($;$) {
sub link($$) {
my($name, $where) = @_;
sprintf '<A HREF="%s">%s</A>', htmlquote($where), $name;
sprintf '<A HREF="%s">%s</A>', hrefquote($where), $name;
}
sub revcmp($$) {
@ -1578,10 +1654,10 @@ sub cvswebMarkup($$$) {
my $url = download_url($fileurl, $revision, $mimetype);
print "<HR noshade>";
if ($mimetype =~ /^image/) {
printf '<IMG SRC="%s"><BR>', htmlquote("$url$barequery");
printf '<IMG SRC="%s"><BR>', hrefquote("$url$barequery");
}
elsif ($mimetype =~ m%^application/pdf%) {
printf '<EMBED SRC="%s" WIDTH="100%"><BR>', htmlquote("$url$barequery");
printf '<EMBED SRC="%s" WIDTH="100%"><BR>', hrefquote("$url$barequery");
}
else {
print "<PRE>";
@ -2655,7 +2731,7 @@ sub navigateHeader($$$$$) {
print qq`<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">`;
print "<HTML>\n<HEAD>\n";
print qq`<META name="robots" content="nofollow">\n`;
print '<!-- CVSweb $zRevision: 1.104 $ $Revision: 1.60 $ -->';
print '<!-- CVSweb $zRevision: 1.104 $ $Revision: 1.61 $ -->';
print "\n<TITLE>$path$filename - $title - $rev</TITLE></HEAD>\n";
print "$body_tag_for_src\n";
print "<table width=\"100%\" border=0 cellspacing=0 cellpadding=1 bgcolor=\"$navigationHeaderColor\">";
@ -2878,7 +2954,7 @@ sub download_link($$$;$) {
my ($url, $revision, $textlink, $mimetype) = @_;
my ($fullurl) = download_url($url, $revision, $mimetype);
printf '<A HREF="%s"', htmlquote("$fullurl$barequery");
printf '<A HREF="%s"', hrefquote("$fullurl$barequery");
if ($open_extern_window && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
print ' target="cvs_checkout"';
@ -2912,7 +2988,7 @@ sub download_link($$$;$) {
if (defined($extern_window_height));
printf q` onClick="window.open('%s','cvs_checkout','%s');"`,
htmlquote($fullurl), join(',', @attr);
hrefquote($fullurl), join(',', @attr);
}
}
print "><b>$textlink</b></A>";
@ -2952,8 +3028,7 @@ sub urlencode($) {
s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
$_;
$_;
}
sub htmlquote($) {
@ -2980,6 +3055,14 @@ sub htmlunquote($) {
$_;
}
sub hrefquote($) {
local($_) = @_;
y/ /+/;
htmlquote($_)
}
sub http_header(;$) {
my $content_type = shift || "text/html";
if (defined($moddate)) {
@ -3038,7 +3121,7 @@ sub http_header(;$) {
sub html_header($) {
my ($title) = @_;
my $version = '$zRevision: 1.104 $ $Revision: 1.60 $'; #'
my $version = '$zRevision: 1.104 $ $Revision: 1.61 $'; #'
http_header(defined($charset) ? "text/html; charset=$charset" : "text/html");
(my $header = &cgi_style::html_header) =~ s/^.*\n\n//; # remove HTTP response header

View file

@ -7,8 +7,8 @@
# 2000 A. MUSHA <knu@FreeBSD.org>
# based on work by Bill Fenner <fenner@FreeBSD.org>
# $zId: cvsweb.conf,v 1.27 2000/07/27 10:16:39 kcoar Exp $
# $Id: cvsweb.conf,v 1.9 2000-12-07 15:21:06 knu Exp $
# $FreeBSD: www/en/cgi/cvsweb.conf,v 1.8 2000/11/04 19:23:25 knu Exp $
# $Id: cvsweb.conf,v 1.10 2000-12-28 18:42:21 knu Exp $
# $FreeBSD: www/en/cgi/cvsweb.conf,v 1.9 2000/12/07 15:21:06 knu Exp $
#
###
@ -313,7 +313,9 @@ $mime_types = '/usr/local/etc/apache/mime.types';
"shtml" => "text/html",
"gif" => "image/gif",
"jpeg" => "image/jpeg",
"jpg" => "image/jpeg",
"jpg" => "image/jpeg",
"png" => "image/png",
"xpm" => "image/xpm",
"*" => "text/plain",
);
@ -326,9 +328,9 @@ $mime_types = '/usr/local/etc/apache/mime.types';
##############
# allow annotation of files
# this requires rw-access to the
# CVSROOT/history - file and rw-access
# to the subdirectory to place the lock
# so you maybe don't want it
# CVSROOT/history file (if you have one)
# and rw-access to the subdirectory to
# place the lock so you maybe don't want it
$allow_annotate = 1;
# allow pretty-printed version of files
@ -403,4 +405,12 @@ $tabstop = 8;
# server
$use_moddate = 1;
# Allows downloading a tarball of the current directory if set.
# Bear in mind that this allows downloading a tarball of your entire
# repository, which can take a lot of time and disk space to create!
# If you enable this, you may need to make sure that cvsweb can write to
# CVSROOT/val-tags, due to a bug in cvs.
$allow_tar = '';
1;
#EOF