Annotation of cvsweb/cvsweb.cgi, Revision 3.130
3.55 knu 1: #!/usr/bin/perl -wT
1.1 jfieber 2: #
3.1 knu 3: # cvsweb - a CGI interface to CVS trees.
1.1 jfieber 4: #
3.12 knu 5: # Written in their spare time by
3.113 scop 6: # Bill Fenner <fenner@FreeBSD.org> (original work)
7: # extended by Henner Zeller <zeller@think.de>,
8: # Henrik Nordstrom <hno@hem.passagen.se>
9: # Ken Coar <coar@Apache.Org>
10: # Dick Balaska <dick@buckosoft.com>
11: # Akinori MUSHA <knu@FreeBSD.org>
12: # Jens-Uwe Mager <jum@helios.de>
13: # Ville Skyttä <scop@FreeBSD.org>
14: # Vassilii Khachaturov <vassilii@tarunz.org>
3.1 knu 15: #
16: # Based on:
17: # * Bill Fenners cvsweb.cgi revision 1.28 available from:
3.5 knu 18: # http://www.FreeBSD.org/cgi/cvsweb.cgi/www/en/cgi/cvsweb.cgi
1.1 jfieber 19: #
1.21 wosch 20: # Copyright (c) 1996-1998 Bill Fenner
3.1 knu 21: # (c) 1998-1999 Henner Zeller
3.109 scop 22: # (c) 1999 Henrik Nordstrom
23: # (c) 2000-2002 Akinori MUSHA
24: # (c) 2002 Ville Skyttä
1.21 wosch 25: # All rights reserved.
26: #
27: # Redistribution and use in source and binary forms, with or without
28: # modification, are permitted provided that the following conditions
29: # are met:
30: # 1. Redistributions of source code must retain the above copyright
31: # notice, this list of conditions and the following disclaimer.
32: # 2. Redistributions in binary form must reproduce the above copyright
33: # notice, this list of conditions and the following disclaimer in the
34: # documentation and/or other materials provided with the distribution.
35: #
36: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
37: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39: # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
40: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46: # SUCH DAMAGE.
47: #
3.87 knu 48: # $FreeBSD$
3.82 knu 49: # $Id: cvsweb.cgi,v 1.112 2001/07/24 13:03:16 hzeller Exp $
3.85 knu 50: # $Idaemons: /home/cvs/cvsweb/cvsweb.cgi,v 3.84 2001/10/07 20:50:10 knu Exp $
1.21 wosch 51: #
3.1 knu 52: ###
53:
3.55 knu 54: require 5.000;
55:
3.1 knu 56: use strict;
1.21 wosch 57:
3.1 knu 58: use vars qw (
3.121 scop 59: $VERSION
3.122 scop 60: $uname $config $allow_version_select $verbose
3.120 scop 61: @CVSrepositories @CVSROOT %CVSROOT %CVSROOTdescr
62: %MIRRORS %DEFAULTVALUE %ICONS %MTYPES
63: @DIFFTYPES %DIFFTYPES @LOGSORTKEYS %LOGSORTKEYS
3.129 scop 64: %alltags %fileinfo %tags @branchnames %nameprinted
3.120 scop 65: %symrev %revsym @allrevisions %date %author @revdisplayorder
66: @revisions %state %difflines %log %branchpoint @revorder
67: $prcgi @prcategories $re_prcategories $prkeyword $re_prkeyword $mancgi
68: $checkoutMagic $doCheckout $scriptname $scriptwhere
69: $where $pathinfo $Browser $nofilelinks $maycompress
3.129 scop 70: @stickyvars @unsafevars %funcline_regexp $is_mod_perl
3.120 scop 71: $is_links $is_lynx $is_w3m $is_msie $is_mozilla3 $is_textbased
72: %input $query $barequery $sortby $bydate $byrev $byauthor
73: $bylog $byfile $defaultDiffType $logsort $cvstree $cvsroot
74: $mimetype $charset $output_filter $defaultTextPlain $defaultViewable
3.129 scop 75: $command_path %CMD $allow_compress $backicon $diricon $fileicon
76: $fullname $newname $cvstreedefault $logo $defaulttitle $address
77: $long_intro $short_instruction $shortLogLen $show_author $dirtable
78: $tablepadding $hr_breakable $showfunc $hr_ignwhite $hr_ignkeysubst
79: $inputTextSize $mime_types $allow_annotate $allow_markup
3.120 scop 80: $allow_log_extra $allow_dir_extra $allow_source_extra
81: $use_java_script $open_extern_window
82: $extern_window_width $extern_window_height $edit_option_form
83: $show_subdir_lastmod $show_log_in_markup $preformat_in_markup $v
84: $tabstop $state $annTable $sel $curbranch @HideModules @ForbiddenFiles
85: $module $use_descriptions %descriptions @mytz $dwhere $moddate
86: $use_moddate $has_zlib $gzip_open
87: $allow_tar @tar_options @gzip_options @zip_options @cvs_options
3.128 scop 88: @annotate_options $LOG_FILESEPARATOR $LOG_REVSEPARATOR
3.120 scop 89: $tmpdir $HTML_DOCTYPE $HTML_META
3.1 knu 90: );
91:
3.125 scop 92: # TODO:
93: # Maybe "use filetest 'access'" on perl >= 5.6 for better -X checks.
94: #($] >= 5.006) and eval "use filetest 'access'";
95:
3.122 scop 96: use Cwd qw(abs_path);
97: use File::Basename ();
98: use IPC::Open2 qw(open2);
99: use Time::Local ();
100:
101: # -----------------------------------------------------------------------------
102:
103: # All global initialization that can be done in compile time should go to
104: # the BEGIN block. Persistent environments, such as mod_perl, will benefit
105: # from this.
106:
107: BEGIN
108: {
109: $VERSION = '3.0-dev';
110:
111: $HTML_DOCTYPE =
112: '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
113:
114: $HTML_META = <<EOM;
115: <meta name="robots" content="nofollow">
116: <meta name="generator" content="FreeBSD-CVSweb $VERSION">
117: <meta http-equiv="Content-Script-Type" content="text/javascript">
118: <meta http-equiv="Content-Style-Type" content="text/css">
119: EOM
120:
121: # Check if the zlib C library interface is installed, and if yes,
122: # we can avoid using the extra gzip process.
123: eval { require Compress::Zlib; };
124: $has_zlib = !$@;
125:
126: $is_mod_perl = defined($ENV{MOD_PERL});
127:
128: $tmpdir = $ENV{TMPDIR} || '/var/tmp';
129:
130: $LOG_FILESEPARATOR = qr/^={77}$/o;
131: $LOG_REVSEPARATOR = qr/^-{28}$/o;
132: }
133:
134: # -----------------------------------------------------------------------------
135:
3.12 knu 136: sub printDiffSelect($);
3.37 knu 137: sub printDiffLinks($$);
138: sub printLogSortSelect($);
3.12 knu 139: sub findLastModifiedSubdirs(@);
3.36 knu 140: sub htmlify_sub(&$);
3.12 knu 141: sub htmlify($;$);
3.20 knu 142: sub spacedHtmlText($;$);
3.12 knu 143: sub link($$);
144: sub revcmp($$);
3.103 knu 145: sub fatal($$@);
3.12 knu 146: sub redirect($);
147: sub safeglob($);
3.58 knu 148: sub search_path($);
3.12 knu 149: sub getMimeTypeFromSuffix($);
3.24 knu 150: sub head($;$);
151: sub scan_directives(@);
3.86 knu 152: sub openOutputFilter();
3.12 knu 153: sub doAnnotate($$);
154: sub doCheckout($$);
155: sub cvswebMarkup($$$);
156: sub viewable($);
157: sub doDiff($$$$$$);
158: sub getDirLogs($$@);
159: sub readLog($;$);
160: sub printLog($;$);
161: sub doLog($);
162: sub flush_diff_rows($$$$);
163: sub human_readable_diff($);
164: sub navigateHeader($$$$$);
165: sub plural_write($$);
166: sub readableTime($$);
167: sub clickablePath($$);
168: sub chooseCVSRoot();
169: sub chooseMirror();
170: sub fileSortCmp();
171: sub download_url($$;$);
172: sub download_link($$$;$);
173: sub toggleQuery($$);
174: sub urlencode($);
3.35 knu 175: sub htmlquote($);
3.36 knu 176: sub htmlunquote($);
3.48 knu 177: sub hrefquote($);
3.12 knu 178: sub http_header(;$);
179: sub html_header($);
180: sub html_footer();
181: sub link_tags($);
3.81 knu 182: sub forbidden_file($);
3.12 knu 183: sub forbidden_module($);
184:
3.1 knu 185: ##### Start of Configuration Area ########
3.122 scop 186:
187: # Don't put this in BEGIN...
3.59 knu 188: delete $ENV{PATH};
189:
3.122 scop 190: my ($mydir) = (File::Basename::dirname($0) =~ /(.*)/); # untaint
3.58 knu 191:
3.12 knu 192: # == EDIT this ==
3.28 knu 193: # Locations to search for user configuration, in order:
3.80 knu 194: for ("$mydir/cvsweb.conf", '/usr/local/etc/cvsweb/cvsweb.conf') {
3.120 scop 195: if (defined($_) && -r $_) {
196: $config = $_;
197: last;
198: }
3.11 knu 199: }
3.122 scop 200: undef $mydir;
3.1 knu 201:
202: # == Configuration defaults ==
203: # Defaults for configuration variables that shouldn't need
204: # to be configured..
205: $allow_version_select = 1;
3.120 scop 206: $allow_log_extra = 1;
3.1 knu 207:
208: ##### End of Configuration Area ########
209:
210: ######## Configuration variables #########
211: # These are defined to allow checking with perl -cw
3.120 scop 212:
3.80 knu 213: @CVSrepositories = @CVSROOT = %CVSROOT = %MIRRORS = %DEFAULTVALUE = %ICONS =
3.129 scop 214: %MTYPES = %tags = %alltags = %fileinfo = ();
3.120 scop 215:
3.129 scop 216: $cvstreedefault = $logo = $defaulttitle =
3.120 scop 217: $address = $long_intro = $short_instruction = $shortLogLen = $show_author =
3.129 scop 218: $dirtable = $tablepadding = $hr_breakable = $showfunc = $hr_ignwhite =
219: $hr_ignkeysubst = $inputTextSize = $mime_types = $allow_annotate =
3.120 scop 220: $allow_markup = $use_java_script = $open_extern_window =
221: $extern_window_width = $extern_window_height = $edit_option_form =
3.129 scop 222: $show_subdir_lastmod = $show_log_in_markup = $v =
223: $tabstop = $use_moddate = $moddate =
3.122 scop 224: $gzip_open = undef;
3.32 knu 225:
3.37 knu 226: @DIFFTYPES = qw(h H u c s);
227: @DIFFTYPES{@DIFFTYPES} = (
3.120 scop 228: {
229: 'descr' => 'colored',
230: 'opts' => ['-u'],
231: 'colored' => 1,
232: },
233: {
234: 'descr' => 'long colored',
235: 'opts' => ['--unified=15'],
236: 'colored' => 1,
237: },
238: {
239: 'descr' => 'unified',
240: 'opts' => ['-u'],
241: 'colored' => 0,
242: },
243: {
244: 'descr' => 'context',
245: 'opts' => ['-c'],
246: 'colored' => 0,
247: },
248: {
249: 'descr' => 'side by side',
250: 'opts' => ['--side-by-side', '--width=164'],
251: 'colored' => 0,
252: },
3.80 knu 253: );
3.37 knu 254:
255: @LOGSORTKEYS = qw(cvs date rev);
256: @LOGSORTKEYS{@LOGSORTKEYS} = (
3.120 scop 257: {'descr' => 'Not sorted',},
258: {'descr' => 'Commit date',},
259: {'descr' => 'Revision',},
3.80 knu 260: );
3.37 knu 261:
3.1 knu 262: ##### End of configuration variables #####
263:
3.120 scop 264: $verbose = $v;
265: $checkoutMagic = "~checkout~";
266: $pathinfo = defined($ENV{PATH_INFO}) ? $ENV{PATH_INFO} : '';
267: $where = $pathinfo;
268: $doCheckout = ($where =~ m|^/$checkoutMagic/|);
269: $where =~ s|^/$checkoutMagic/|/|;
270: $where =~ s|^/||;
271: $scriptname = defined($ENV{SCRIPT_NAME}) ? $ENV{SCRIPT_NAME} : '';
272: $scriptname =~ s|^/*|/|;
3.63 knu 273:
3.64 knu 274: # Let's workaround thttpd's stupidity..
3.63 knu 275: if ($scriptname =~ m|/$|) {
3.120 scop 276: $pathinfo .= '/';
277: my $re = quotemeta $pathinfo;
278: $scriptname =~ s/$re$//;
3.63 knu 279: }
280:
3.120 scop 281: $scriptwhere = $scriptname;
3.63 knu 282: $scriptwhere .= '/' . urlencode($where);
283: $where = '/' if ($where eq '');
3.3 knu 284:
3.1 knu 285: # in lynx, it it very annoying to have two links
286: # per file, so disable the link at the icon
287: # in this case:
3.120 scop 288: $Browser = $ENV{HTTP_USER_AGENT} || '';
3.80 knu 289: $is_links = ($Browser =~ m`^Links `);
290: $is_lynx = ($Browser =~ m`^Lynx/`i);
291: $is_w3m = ($Browser =~ m`^w3m/`i);
292: $is_msie = ($Browser =~ m`MSIE`);
3.5 knu 293: $is_mozilla3 = ($Browser =~ m`^Mozilla/[3-9]`);
3.3 knu 294:
3.34 knu 295: $is_textbased = ($is_links || $is_lynx || $is_w3m);
3.5 knu 296:
297: $nofilelinks = $is_textbased;
3.1 knu 298:
299: # newer browsers accept gzip content encoding
300: # and state this in a header
301: # (netscape did always but didn't state it)
302: # It has been reported that these
303: # braindamaged MS-Internet Exploders claim that they
304: # accept gzip .. but don't in fact and
305: # display garbage then :-/
3.23 knu 306: # Turn off gzip if running under mod_perl and no zlib is available,
307: # piping does not work as expected inside the server.
3.120 scop 308: $maycompress = (
309: ((defined($ENV{HTTP_ACCEPT_ENCODING})
310: && $ENV{HTTP_ACCEPT_ENCODING} =~ /gzip/)
311: || $is_mozilla3)
312: && !$is_msie
313: && !($is_mod_perl && !$has_zlib)
314: );
3.1 knu 315:
316: # put here the variables we need in order
317: # to hold our state - they will be added (with
3.12 knu 318: # their current value) to any link/query string
3.1 knu 319: # you construct
3.6 knu 320: @stickyvars = qw(cvsroot hideattic sortby logsort f only_with_tag);
3.97 knu 321: @unsafevars = qw(logsort only_with_tag r1 r2 rev sortby tr1 tr2);
1.1 jfieber 322:
3.1 knu 323: if (-f $config) {
3.120 scop 324: do "$config"
325: or fatal("500 Internal Error",
326: 'Error in loading configuration file: %s<br><br>%s<br>',
327: $config, $@);
3.27 knu 328: } else {
3.120 scop 329: fatal("500 Internal Error",
330: 'Configuration not found. Set the variable <code>$config</code> in cvsweb.cgi to your <b>cvsweb.conf</b> configuration file first.');
3.1 knu 331: }
332:
333: undef %input;
3.3 knu 334: $query = $ENV{QUERY_STRING};
335:
3.12 knu 336: if (defined($query) && $query ne '') {
3.120 scop 337: foreach (split (/&/, $query)) {
338: y/+/ /;
339: s/%(..)/sprintf("%c", hex($1))/ge; # unquote %-quoted
340: if (/(\S+)=(.*)/) {
341: $input{$1} = $2 if ($2 ne "");
342: } else {
343: $input{$_}++;
344: }
345: }
1.7 fenner 346: }
1.10 wosch 347:
3.12 knu 348: # For backwards compability, set only_with_tag to only_on_branch if set.
3.1 knu 349: $input{only_with_tag} = $input{only_on_branch}
3.120 scop 350: if (defined($input{only_on_branch}));
3.97 knu 351:
352: # Prevent cross-site scripting
353: foreach (@unsafevars) {
3.120 scop 354:
355: # Colons are needed in diffs between tags.
356: if (defined($input{$_}) && $input{$_} =~ /[^\w\-.:]/) {
357: fatal("500 Internal Error", 'Malformed query (%s=%s)', $_, $input{$_});
358: }
3.97 knu 359: }
360:
361: if (defined($input{"content-type"})) {
3.120 scop 362: fatal("500 Internal Error", "Unsupported content-type")
363: if ($input{"content-type"} !~ /^[-0-9A-Za-z]+\/[-0-9A-Za-z]+$/);
3.97 knu 364: }
1.10 wosch 365:
3.1 knu 366: $DEFAULTVALUE{'cvsroot'} = $cvstreedefault;
1.10 wosch 367:
3.120 scop 368: while (my ($key, $defval) = each %DEFAULTVALUE) {
3.80 knu 369:
3.120 scop 370: # Replace not given parameters with defaults.
371: next unless (defined($defval)
3.121 scop 372: && (!defined($input{$key}) || $input{$key} eq ''));
3.120 scop 373:
374: # Empty checkboxes in forms return nothing, so we define a helper variable
375: # in these forms (copt) which indicates that we just set parameters with a
376: # checkbox.
377: if (defined($input{'copt'})) {
378:
379: # 'copt' is defined -> the result of empty input checkbox
380: # -> set to zero (disable) if default is a boolean (0|1).
381: $input{$key} = 0 if ($defval eq '0' || $defval eq '1');
382:
383: } else {
384:
385: # 'copt' isn't defined --> empty input is not the result
386: # of empty input checkbox --> set default.
387: $input{$key} = $defval;
388: }
1.10 wosch 389: }
3.12 knu 390:
3.1 knu 391: $barequery = "";
3.31 knu 392: my @barequery;
3.1 knu 393: foreach (@stickyvars) {
3.80 knu 394:
3.120 scop 395: # construct a query string with the sticky non default parameters set
396: if (defined($input{$_})
397: && $input{$_} ne ''
398: && !(defined($DEFAULTVALUE{$_}) && $input{$_} eq $DEFAULTVALUE{$_}))
399: {
400: push @barequery, join ('=', urlencode($_), urlencode($input{$_}));
401: }
3.1 knu 402: }
3.80 knu 403:
3.1 knu 404: # is there any query ?
3.31 knu 405: if (@barequery) {
3.120 scop 406: $barequery = join ('&', @barequery);
407: $query = "?$barequery";
408: $barequery = "&$barequery";
3.80 knu 409: } else {
3.120 scop 410: $query = "";
3.1 knu 411: }
3.31 knu 412: undef @barequery;
3.1 knu 413:
3.120 scop 414: if (defined($input{'path'})) {
415: redirect("$scriptname/$input{path}$query");
3.57 knu 416: }
417:
3.1 knu 418: # get actual parameters
3.120 scop 419: $sortby = $input{'sortby'};
3.80 knu 420: $bydate = 0;
421: $byrev = 0;
3.1 knu 422: $byauthor = 0;
3.80 knu 423: $bylog = 0;
424: $byfile = 0;
3.120 scop 425: if ($sortby eq 'date') {
426: $bydate = 1;
427: } elsif ($sortby eq 'rev') {
428: $byrev = 1;
429: } elsif ($sortby eq 'author') {
430: $byauthor = 1;
431: } elsif ($sortby eq 'log') {
432: $bylog = 1;
3.80 knu 433: } else {
3.120 scop 434: $byfile = 1;
3.1 knu 435: }
436:
3.37 knu 437: $defaultDiffType = $input{'f'};
3.1 knu 438:
3.3 knu 439: $logsort = $input{'logsort'};
1.10 wosch 440:
3.95 knu 441: {
3.120 scop 442: my @tmp = @CVSrepositories;
443:
444: while (my ($key, $val) = splice(@tmp, 0, 2)) {
445: my ($descr, $cvsroot) = @$val;
3.56 knu 446:
3.120 scop 447: next unless -d $cvsroot;
448:
449: $CVSROOTdescr{$key} = $descr;
450: $CVSROOT{$key} = $cvsroot;
451: push(@CVSROOT, $key);
452: }
3.56 knu 453: }
1.12 fenner 454:
3.1 knu 455: ## Default CVS-Tree
456: if (!defined($CVSROOT{$cvstreedefault})) {
3.120 scop 457: fatal("500 Internal Error",
458: '<code>$cvstreedefault</code> points to a repository (%s) not defined in <code>%%CVSROOT</code> (edit your configuration file %s)',
459: $cvstreedefault,
460: $config);
3.1 knu 461: }
462:
463: # alternate CVS-Tree, configured in cvsweb.conf
464: if ($input{'cvsroot'} && $CVSROOT{$input{'cvsroot'}}) {
3.120 scop 465: $cvstree = $input{'cvsroot'};
3.1 knu 466: } else {
3.120 scop 467: $cvstree = $cvstreedefault;
1.10 wosch 468: }
469:
3.1 knu 470: $cvsroot = $CVSROOT{$cvstree};
1.10 wosch 471:
3.1 knu 472: # create icons out of description
3.120 scop 473: foreach my $k (keys %ICONS) {
474: my ($itxt, $ipath, $iwidth, $iheight) = @{$ICONS{$k}};
475: no strict 'refs';
476: if ($ipath) {
477: ${"${k}icon"} =
478: sprintf('<img src="%s" alt="%s" border="0" width="%d" height="%d">',
479: hrefquote($ipath), htmlquote($itxt), $iwidth, $iheight);
480: } else {
481: ${"${k}icon"} = $itxt;
482: }
1.24 wosch 483: }
484:
3.27 knu 485: my $config_cvstree = "$config-$cvstree";
486:
3.1 knu 487: # Do some special configuration for cvstrees
3.27 knu 488: if (-f $config_cvstree) {
3.120 scop 489: do "$config_cvstree"
490: or fatal("500 Internal Error",
491: 'Error in loading configuration file: %s<br><br>%s<br>',
492: $config_cvstree, $@);
3.27 knu 493: }
3.31 knu 494: undef $config_cvstree;
3.1 knu 495:
3.120 scop 496: $re_prcategories = '(?:' . join ('|', @prcategories) . ')' if @prcategories;
497: $re_prkeyword = quotemeta($prkeyword) if defined($prkeyword);
498: $prcgi .= '%s' if defined($prcgi) && $prcgi !~ /%s/;
1.24 wosch 499:
3.80 knu 500: $fullname = "$cvsroot/$where";
501: $mimetype = &getMimeTypeFromSuffix($fullname);
3.1 knu 502: $defaultTextPlain = ($mimetype eq "text/plain");
3.80 knu 503: $defaultViewable = $allow_markup && viewable($mimetype);
3.1 knu 504:
3.63 knu 505: my $rewrite = 0;
506:
507: if ($pathinfo =~ m|//|) {
3.120 scop 508: $pathinfo =~ y|/|/|s;
509: $rewrite = 1;
3.63 knu 510: }
511:
3.120 scop 512: if (-d $fullname) {
513: if ($pathinfo !~ m|/$|) {
514: $pathinfo .= '/';
515: $rewrite = 1;
516: }
517: } else {
518: if ($pathinfo =~ m|/$|) {
519: chop $pathinfo;
520: $rewrite = 1;
521: }
3.63 knu 522: }
523:
524: if ($rewrite) {
3.120 scop 525: redirect($scriptname . urlencode($pathinfo) . $query);
3.1 knu 526: }
527:
3.63 knu 528: undef $rewrite;
529:
3.1 knu 530: if (!-d $cvsroot) {
3.120 scop 531: fatal("500 Internal Error",
532: '$CVSROOT not found!<p>The server on which the CVS tree lives is probably down. Please try again in a few minutes.');
3.1 knu 533: }
534:
535: #
536: # See if the module is in our forbidden list.
537: #
538: $where =~ m:([^/]*):;
539: $module = $1;
540: if ($module && &forbidden_module($module)) {
3.120 scop 541: fatal("403 Forbidden", 'Access to %s forbidden.', $where);
3.1 knu 542: }
3.46 knu 543:
544: #
545: # Handle tarball downloads before any headers are output.
546: #
547: if ($input{tarball}) {
3.120 scop 548: fatal('403 Forbidden', 'Downloading tarballs is prohibited.')
549: unless $allow_tar;
550: my ($module) = ($where =~ m,^/?(.*),); # untaint
551: $module =~ s,/([^/]*)$,,;
552: my ($ext) = ($1 =~ /(\.tar\.gz|\.zip)$/);
553: my ($basedir) = ($module =~ m,([^/]+)$,);
554:
555: if ($basedir eq '' || $module eq '') {
556: fatal('500 Internal Error',
557: 'You cannot download the top level directory.');
558: }
559:
560: my $tmpexportdir = "$tmpdir/.cvsweb.$$." . int(time);
561:
562: mkdir($tmpexportdir, 0700) or
563: fatal('500 Internal Error', 'Unable to make temporary directory: %s', $!);
564:
565: my @fatal;
566:
567: my $tag =
568: (exists $input{only_with_tag} && length $input{only_with_tag})
569: ? $input{only_with_tag}
570: : 'HEAD';
571:
572: $tag = 'HEAD' if $tag eq 'MAIN';
573:
574: if (system($CMD{cvs},
575: @cvs_options, '-Qd', $cvsroot, 'export', '-r', $tag, '-d',
576: "$tmpexportdir/$basedir", $module))
577: {
578: @fatal = ('500 Internal Error', 'cvs co failure: %s: %s', $!, $module);
579: } else {
580: $| = 1; # Essential to get the buffering right.
581:
582: if ($ext eq '.tar.gz') {
583: print "Content-Type: application/x-gzip\r\n\r\n";
584:
585: system("$CMD{tar} @tar_options -cf - -C $tmpexportdir $basedir | $CMD{gzip} @gzip_options -c")
586: and @fatal =
587: ('500 Internal Error', 'tar zc failure: %s: %s', $!, $basedir);
588: } elsif ($ext eq '.zip' && $CMD{zip}) {
589: print "Content-Type: application/zip\r\n\r\n";
590:
591: system("cd $tmpexportdir && $CMD{zip} @zip_options -r - $basedir")
592: and @fatal =
593: ('500 Internal Error', 'zip failure: %s: %s', $!, $basedir);
594: } else {
595: @fatal = ('500 Internal Error', 'unsupported file type');
596: }
597: }
3.46 knu 598:
3.120 scop 599: system($CMD{rm}, '-rf', $tmpexportdir) if -d $tmpexportdir;
3.46 knu 600:
3.120 scop 601: &fatal(@fatal) if @fatal;
3.46 knu 602:
3.120 scop 603: exit;
3.46 knu 604: }
605:
3.1 knu 606: ##############################
607: # View a directory
608: ###############################
3.46 knu 609: if (-d $fullname) {
3.120 scop 610: my $dh = do { local (*DH); };
611: opendir($dh, $fullname) or fatal("404 Not Found", '%s: %s', $where, $!);
612: my @dir = readdir($dh);
613: closedir($dh);
614: my @subLevelFiles = findLastModifiedSubdirs(@dir)
615: if ($show_subdir_lastmod);
616: getDirLogs($cvsroot, $where, @subLevelFiles);
617:
618: if ($where eq '/') {
619: html_header($defaulttitle);
620: $long_intro =~ s/!!CVSROOTdescr!!/$CVSROOTdescr{$cvstree}/g;
621: print $long_intro;
622: } else {
623: html_header($where);
624: print $short_instruction;
625: }
626:
627: if ($use_descriptions && open(DESC, "<$cvsroot/CVSROOT/descriptions")) {
628: while (<DESC>) {
629: chomp;
630: my ($dir, $description) = /(\S+)\s+(.*)/;
631: $descriptions{$dir} = $description;
632: }
633: close(DESC);
634: }
635:
636: print "<p><a name=\"dirlist\"></a></p>\n";
637:
638: # give direct access to dirs
639: if ($where eq '/') {
640: chooseMirror();
641: chooseCVSRoot();
642: } else {
643: print "<p>Current directory: <b>", &clickablePath($where, 0), "</b></p>\n";
644:
645: print "<p>Current tag: <b>", $input{only_with_tag}, "</b></p>\n"
646: if $input{only_with_tag};
647:
648: }
649:
650: print "<hr noshade>\n";
651:
652: # Using <menu> in this manner violates the HTML2.0 spec but
653: # provides the results that I want in most browsers. Another
654: # case of layout spooging up HTML.
655:
656: my $infocols = 0;
657: if ($dirtable) {
3.129 scop 658: print "<table class=\"dir\" width=\"100%\" cellspacing=\"1\" cellpadding=\"$tablepadding\">\n";
3.120 scop 659: $infocols++;
3.129 scop 660: printf "<tr>\n<th class=\"dir-header%s\">", $byfile ? '-sorted' : '';
3.120 scop 661:
662: if ($byfile) {
663: print 'File';
664: } else {
665: print &link('File',
666: sprintf('./%s#dirlist', toggleQuery('sortby', 'file')));
667: }
668: print "</th>\n";
669:
670: # do not display the other column-headers, if we do not have any files
671: # with revision information:
672: if (scalar(%fileinfo)) {
673: $infocols++;
3.129 scop 674: printf '<th class="dir-header%s">', $byrev ? '-sorted' : '';
3.120 scop 675:
676: if ($byrev) {
677: print 'Rev.';
678: } else {
679: print &link('Rev.',
680: sprintf('./%s#dirlist', toggleQuery('sortby', 'rev')));
681: }
682: print "</th>\n";
683: $infocols++;
3.129 scop 684: printf '<th class="dir-header%s">', $bydate ? '-sorted' : '';
3.120 scop 685:
686: if ($bydate) {
687: print 'Age';
688: } else {
689: print &link('Age',
690: sprintf('./%s#dirlist', toggleQuery('sortby', 'date')));
691: }
692: print "</th>\n";
693:
694: if ($show_author) {
695: $infocols++;
3.129 scop 696: printf '<th class="dir-header%s">', $byauthor ? '-sorted' : '';
3.120 scop 697:
698: if ($byauthor) {
699: print 'Author';
700: } else {
701: print
702: &link('Author',
703: sprintf('./%s#dirlist', toggleQuery('sortby', 'author')));
704: }
705: print "</th>\n";
706: }
707: $infocols++;
3.129 scop 708: printf '<th class="dir-header%s">', $bylog ? '-sorted' : '';
3.120 scop 709:
710: if ($bylog) {
711: print 'Last log entry';
712: } else {
713: print &link('Last log entry',
714: sprintf('./%s#dirlist', toggleQuery('sortby', 'log')));
715: }
716: print "</th>\n";
717: } elsif ($use_descriptions) {
3.129 scop 718: print "<th class=\"dir-header\">Description</th>\n";
3.120 scop 719: $infocols++;
720: }
721: print "</tr>\n";
722: } else {
723: print "<menu>\n";
724: }
725: my $dirrow = 0;
726:
727: my $i;
728: lookingforattic:
729: for ($i = 0; $i <= $#dir; $i++) {
730: if ($dir[$i] eq "Attic") {
731: last lookingforattic;
732: }
733: }
734:
735: if (!$input{'hideattic'}
736: && ($i <= $#dir)
737: && opendir($dh, $fullname . '/Attic'))
738: {
739: splice(@dir, $i, 1, grep((s|^|Attic/|, !m|/\.|), readdir($dh)));
740: closedir($dh);
741: }
742:
743: my $hideAtticToggleLink =
744: $input{'hideattic'}
745: ? ''
746: : &link('[Hide]', sprintf('./%s#dirlist', &toggleQuery('hideattic')));
747:
748: # Sort without the Attic/ pathname.
749: # place directories first
750:
751: my $attic;
752: my $url;
753: my $fileurl;
754: my $filesexists;
755: my $filesfound;
756:
757: foreach my $file (sort { &fileSortCmp } @dir) {
758:
759: next if ($file eq '.');
760:
761: # ignore CVS lock and stale NFS files
762: next if ($file =~ /^\#cvs\.|^,|^\.nfs/); # \# for XEmacs cperl-mode...
763:
764: # Check whether to show the CVSROOT path
765: next if ($input{'hidecvsroot'} && $file eq 'CVSROOT');
766:
767: # Check whether the module is in the restricted list
768: next if ($file && &forbidden_module($file));
769:
770: # Ignore non-readable files
771: next if ($input{'hidenonreadable'} && !(-r "$fullname/$file"));
772:
773: if ($file =~ s|^Attic/||) {
774: $attic = ' (in the Attic) ' . $hideAtticToggleLink;
775: } else {
776: $attic = '';
777: }
778:
779: if ($file eq '..' || -d "$fullname/$file") {
780: next if ($file eq '..' && $where eq '/');
781: my ($rev, $date, $log, $author, $filename) = @{$fileinfo{$file}}
782: if (defined($fileinfo{$file}));
3.129 scop 783: printf "<tr class=\"dir-row-%s\">\n<td>", ($dirrow % 2) ? 'even' : 'odd'
784: if $dirtable;
3.120 scop 785:
786: if ($file eq '..') {
787: $url = "../$query";
788: if ($nofilelinks) {
789: print $backicon;
790: } else {
791: print &link($backicon, $url);
792: }
793: print ' ', &link("Parent Directory", $url);
794: } else {
795: $url = './' . urlencode($file) . "/$query";
796: print "<a name=\"$file\"></a>";
797:
798: if ($nofilelinks) {
799: print $diricon;
800: } else {
801: print &link($diricon, $url);
802: }
803: print ' ', &link("$file/", $url), $attic;
804:
805: if ($file eq "Attic") {
806: print " ";
807: print &link('[Don\'t hide]',
808: sprintf('./%s#dirlist', &toggleQuery('hideattic')));
809: }
810: }
811:
812: # Show last change in dir
813: if ($filename) {
814: print "</td>\n<td> </td>\n<td> "
815: if ($dirtable);
816: if ($date) {
817: print " <i>", readableTime(time() - $date, 0), "</i>";
818: }
819:
820: if ($show_author) {
821: print "</td>\n<td> " if ($dirtable);
822: print $author;
823: }
824: print "</td>\n<td> " if ($dirtable);
825: $filename =~ s%^[^/]+/%%;
826: print "$filename/$rev";
827: print "<br>" if ($dirtable);
828:
829: if ($log) {
830: print ' <span style="font-size: smaller">',
831: &htmlify(substr($log, 0, $shortLogLen), $allow_dir_extra);
832: print '...' if (length($log) > 80);
833: print '</span>';
834: }
835: } else {
836: my $dwhere = ($where ne '/' ? $where : '') . $file;
837:
838: if ($use_descriptions && defined $descriptions{$dwhere}) {
839: print '<td colspan="', ($infocols - 1), '"> '
840: if $dirtable;
841: print $descriptions{$dwhere};
842:
843: } elsif ($dirtable && $infocols > 1) {
844:
845: # close the row with the appropriate number of
846: # columns, so that the vertical seperators are visible
847: my ($cols) = $infocols;
848: while ($cols > 1) {
849: print "</td>\n<td> ";
850: $cols--;
851: }
852: }
853: }
854:
855: if ($dirtable) {
856: print "</td>\n</tr>\n";
857: } else {
858: print "<br>\n";
859: }
860: $dirrow++;
861: } elsif ($file =~ s/,v$//) {
862:
863: # Skip forbidden files now so we'll give no hint
864: # about their existence. This should probably have
865: # been done earlier, but it's straightforward here.
866: next if forbidden_file("$fullname/$file");
867:
868: $fileurl = ($attic ? 'Attic/' : '') . urlencode($file);
869: $url = './' . $fileurl . $query;
870: $filesexists++;
871: next if (!defined($fileinfo{$file}));
872: my ($rev, $date, $log, $author) = @{$fileinfo{$file}};
873: $filesfound++;
3.129 scop 874: printf "<tr class=\"dir-row-%s\">\n<td>", ($dirrow % 2) ? 'even' : 'odd'
3.120 scop 875: if $dirtable;
876: print "<a name=\"$file\"></a>";
877:
878: if ($nofilelinks) {
879: print $fileicon;
880: } else {
881: print &link($fileicon, $url);
882: }
883: print ' ', &link(htmlquote($file), $url), $attic;
884: print "</td>\n<td> " if ($dirtable);
885: download_link($fileurl, $rev, $rev,
886: $defaultViewable
887: ? "text/x-cvsweb-markup"
888: : undef);
889: print "</td>\n<td> " if ($dirtable);
890:
891: if ($date) {
892: print " <i>", readableTime(time() - $date, 0), "</i>";
893: }
894: if ($show_author) {
895: print "</td>\n<td> " if ($dirtable);
896: print $author;
897: }
898: print "</td>\n<td> " if ($dirtable);
899:
900: if ($log) {
901: print ' <span style="font-size: smaller">',
902: &htmlify(substr($log, 0, $shortLogLen), $allow_dir_extra);
903: print '...' if (length $log > 80);
904: print '</span>';
905: }
906: print($dirtable ? "</td>\n</tr>" : '<br>');
907: $dirrow++;
908: }
909: print "\n";
910: }
911:
912: print($dirtable ? "</table>\n" : "</menu>\n");
913:
914: if ($filesexists && !$filesfound) {
915: print
916: "<p><b>NOTE:</b> There are $filesexists files, but none matches the current tag ($input{only_with_tag}).</p>\n";
917: }
918:
919: if ($input{only_with_tag} && (!%tags || !$tags{$input{only_with_tag}})) {
920: %tags = %alltags;
921: }
922:
923: if (scalar %tags
924: || $input{only_with_tag}
925: || $edit_option_form
926: || defined($input{"options"}))
927: {
928: print "<hr size=\"1\" noshade>\n";
929: }
930:
931: if (scalar %tags || $input{only_with_tag}) {
932: print "<form method=\"get\" action=\"./\">\n";
933: foreach my $var (@stickyvars) {
934: print "<input type=\"hidden\" name=\"$var\" value=\"$input{$var}\">\n"
935: if (defined($input{$var})
936: && (!defined($DEFAULTVALUE{$var})
937: || $input{$var} ne $DEFAULTVALUE{$var})
938: && $input{$var} ne ""
939: && $var ne 'only_with_tag');
940: }
941: print "<p><label for=\"only_with_tag\" accesskey=\"T\">";
942: print "Show only files with tag:</label>\n";
943: print "<select id=\"only_with_tag\" name=\"only_with_tag\"";
944: print " onchange=\"this.form.submit()\"" if $use_java_script;
945: print ">";
946: print "<option value=\"\">All tags / default branch</option>\n";
947:
948: foreach my $tag (reverse sort { lc $a cmp lc $b } keys %tags) {
949: print "<option", defined($input{only_with_tag})
950: && $input{only_with_tag} eq $tag ? " selected" : "",
951: ">$tag</option>\n";
952: }
953: print "</select>\n";
954: print " <label for=\"path\" accesskey=\"P\">";
955: print "Module path or alias:</label>\n";
956: printf "<input type=\"text\" id=\"path\" name=\"path\" value=\"%s\" size=\"15\">\n", htmlquote($where);
957: print "<input type=\"submit\" value=\"Go\" accesskey=\"G\"></p>\n";
958: print "</form>\n";
959: }
960:
961: if ($allow_tar) {
962: my ($basefile) = ($where =~ m,(?:.*/)?([^/]+),);
963:
964: if (defined($basefile) && $basefile ne '') {
965: print "<hr noshade>\n",
966: "<div align=\"center\">Download this directory in ";
967:
968: # Mangle the filename so browsers show a reasonable
969: # filename to download.
970: print
971: &link("tarball",
972: "./$basefile.tar.gz$query" . ($query ? "&" : "?") . "tarball=1");
973: if ($CMD{zip}) {
974: print " or ",
975: &link("zip archive",
976: "./$basefile.zip$query" . ($query ? "&" : "?") . "tarball=1");
977: }
978: print "</div>\n";
979: }
980: }
981:
982: if ($edit_option_form || defined($input{"options"})) {
983:
984: my $formwhere = $scriptwhere;
985: $formwhere =~ s|Attic/?$|| if ($input{'hideattic'});
986:
987: print "<form method=\"get\" action=\"${formwhere}\">\n";
988: print "<input type=\"hidden\" name=\"copt\" value=\"1\">\n";
989: if ($cvstree ne $cvstreedefault) {
990: print "<input type=\"hidden\" name=\"cvsroot\" value=\"$cvstree\">\n";
991: }
992: print "<center>\n<table cellpadding=\"0\" cellspacing=\"0\">";
3.129 scop 993: print "\n<tr class=\"dir-header\">\n";
994: print "<th style=\"text-align: center\" colspan=\"2\">Preferences</th>\n</tr>\n";
3.120 scop 995: print "<tr>\n<td>";
996: print "<label for=\"sortby\" accesskey=\"F\">Sort files by ";
997: print "</label><select id=\"sortby\" name=\"sortby\">\n";
998: print "<option value=\"\">File</option>\n";
999: print "<option", $bydate ? " selected" : "",
1000: " value=\"date\">Age</option>\n";
1001: print "<option", $byauthor ? " selected" : "",
1002: " value=\"author\">Author</option>\n"
1003: if ($show_author);
1004: print "<option", $byrev ? " selected" : "",
1005: " value=\"rev\">Revision</option>\n";
1006: print "<option", $bylog ? " selected" : "",
1007: " value=\"log\">Log message</option>\n";
1008: print "</select>\n</td>\n";
1009: print "<td><label for=\"logsort\" accesskey=\"L\">";
1010: print "Sort log by: </label>";
1011: printLogSortSelect(0);
1012: print "</td>\n</tr>\n";
1013: print "<tr>\n<td><label for=\"f\" accesskey=\"D\">";
1014: print "Diff format: </label>";
1015: printDiffSelect(0);
1016: print "</td>\n";
1017: print "<td><label for=\"hideattic\" accesskey=\"A\">";
1018: print "Show Attic files: </label>";
1019: print "<input id=\"hideattic\" name=\"hideattic\" type=\"checkbox\"",
1020: $input{'hideattic'} ? " checked" : "", "></td>\n</tr>\n";
1021: print "<tr>\n<td align=\"center\" colspan=\"2\">";
1022: print "<input type=\"submit\" value=\"Change Options\" accesskey=\"C\">";
1023: print "</td>\n</tr>\n</table>\n</center>\n</form>\n";
1024: }
1025: html_footer();
3.80 knu 1026: }
3.1 knu 1027:
1028: ###############################
1029: # View Files
1030: ###############################
3.80 knu 1031: elsif (-f $fullname . ',v') {
3.114 scop 1032:
3.120 scop 1033: if (forbidden_file($fullname)) {
1034: fatal('403 Forbidden',
1035: 'Access forbidden. This file is mentioned in @ForbiddenFiles');
1036: return;
1037: }
1038:
1039: if (defined($input{'rev'}) || $doCheckout) {
1040: &doCheckout($fullname, $input{'rev'});
1041: gzipclose();
1042: exit;
1043: }
1044:
1045: if (defined($input{'annotate'}) && $allow_annotate) {
1046: &doAnnotate($input{'annotate'});
1047: gzipclose();
1048: exit;
1049: }
1050:
1051: if (defined($input{'r1'}) && defined($input{'r2'})) {
1052: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
1053: $input{'r2'}, $input{'tr2'}, $input{'f'});
1054: gzipclose();
1055: exit;
1056: }
1057: print("going to dolog($fullname)\n") if ($verbose);
1058: &doLog($fullname);
1059:
1060: ##############################
1061: # View Diff
1062: ##############################
1063: } elsif ($fullname =~ s/\.diff$//
1064: && -f $fullname . ",v"
1065: && $input{'r1'}
1066: && $input{'r2'})
1067: {
1068:
1069: # $where-diff-removal if 'cvs rdiff' is used
1070: # .. but 'cvs rdiff'doesn't support some options
1071: # rcsdiff does (-w and -p), so it is disabled
1072: # $where =~ s/\.diff$//;
1073:
1074: # Allow diffs using the ".diff" extension
1075: # so that browsers that default to the URL
1076: # for a save filename don't save diff's as
1077: # e.g. foo.c
1078: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
1079: $input{'r2'}, $input{'tr2'}, $input{'f'});
1080: gzipclose();
1081: exit;
1082: } elsif (($newname = $fullname) =~ s|/([^/]+)$|/Attic/$1|
1083: && -f $newname . ",v")
1084: {
1085:
1086: # The file has been removed and is in the Attic.
1087: # Send a redirect pointing to the file in the Attic.
1088: (my $newplace = $scriptwhere) =~ s|/([^/]+)$|/Attic/$1|;
1089: if ($ENV{QUERY_STRING} ne "") {
1090: redirect("${newplace}?$ENV{QUERY_STRING}");
1091: } else {
1092: redirect($newplace);
1093: }
1094: exit;
3.80 knu 1095: } elsif (0 && (my @files = &safeglob($fullname . ",v"))) {
3.120 scop 1096: http_header("text/plain");
1097: print "You matched the following files:\n";
1098: print join ("\n", @files);
3.80 knu 1099:
3.120 scop 1100: # Find the tags from each file
1101: # Display a form offering diffs between said tags
3.80 knu 1102: } else {
3.120 scop 1103: my $fh = do { local (*FH); };
1104: my ($xtra, $module);
3.80 knu 1105:
3.120 scop 1106: # Assume it's a module name with a potential path following it.
1107: $xtra = (($module = $where) =~ s|/.*||) ? $& : '';
3.80 knu 1108:
3.120 scop 1109: # Is there an indexed version of modules?
1110: if (open($fh, "< $cvsroot/CVSROOT/modules")) {
1111: while (<$fh>) {
1112: if (/^(\S+)\s+(\S+)/o
1113: && $module eq $1
1114: && -d "$cvsroot/$2"
1115: && $module ne $2)
1116: {
1117: redirect("$scriptname/$2$xtra$query");
1118: }
1119: }
1120: }
1121: fatal("404 Not Found", '%s: no such file or directory', $where);
3.80 knu 1122: }
3.23 knu 1123:
3.25 knu 1124: gzipclose();
3.80 knu 1125:
3.1 knu 1126: ## End MAIN
1127:
3.120 scop 1128: sub printDiffSelect($)
1129: {
1130: my ($use_java_script) = @_;
1131: my $f = $input{'f'};
1132:
1133: print '<select id="f" name="f"';
1134: print ' onchange="this.form.submit()"' if $use_java_script;
1135: print ">\n";
1136:
1137: local $_;
1138: for (@DIFFTYPES) {
1139: printf("<option value=\"%s\"%s>%s</option>\n",
1140: $_, $f eq $_ ? ' selected' : '',
1141: "\u$DIFFTYPES{$_}{'descr'}");
1142: }
1143:
1144: print "</select>";
1145: }
1146:
1147: sub printLogSortSelect($)
1148: {
1149: my ($use_java_script) = @_;
1150:
1151: print '<select id="logsort" name="logsort"';
1152: print ' onchange="this.form.submit()"' if $use_java_script;
1153: print ">\n";
1154:
1155: local $_;
1156: for (@LOGSORTKEYS) {
1157: printf("<option value=\"%s\"%s>%s</option>\n",
1158: $_, $logsort eq $_ ? ' selected' : '',
1159: "\u$LOGSORTKEYS{$_}{'descr'}");
1160: }
1161:
1162: print "</select>";
1163: }
1164:
1165: sub findLastModifiedSubdirs(@)
1166: {
1167: my (@dirs) = @_;
1168: my ($dirname, @files);
1169:
1170: foreach $dirname (@dirs) {
1171: next if ($dirname eq ".");
1172: next if ($dirname eq "..");
1173: my ($dir) = "$fullname/$dirname";
1174: next if (!-d $dir);
1175:
1176: my ($lastmod) = undef;
1177: my ($lastmodtime) = undef;
1178: my $dh = do { local (*DH); };
1179:
1180: opendir($dh, $dir) or next;
1181: my (@filenames) = readdir($dh);
1182: closedir($dh);
1183:
1184: foreach my $filename (@filenames) {
1185: $filename = "$dirname/$filename";
1186: my ($file) = "$fullname/$filename";
1187: next if ($filename !~ /,v$/ || !-f $file);
1188:
1189: # Skip forbidden files.
1190: (my $f = $file) =~ s/,v$//;
1191: next if forbidden_file($f);
1192:
1193: $filename =~ s/,v$//;
1194: my $modtime = -M $file;
1195:
1196: if (!defined($lastmod) || $modtime < $lastmodtime) {
1197: $lastmod = $filename;
1198: $lastmodtime = $modtime;
1199: }
1200: }
1201: push (@files, $lastmod) if (defined($lastmod));
1202: }
1203: return @files;
1204: }
1205:
1206: sub htmlify_sub(&$)
1207: {
1208: (my $proc, local $_) = @_;
1209: my @a = split (m`(<a [^>]+>[^<]*</a>)`i);
1210: my $linked;
1211: my $result = '';
1212:
1213: while (($_, $linked) = splice(@a, 0, 2)) {
1214: &$proc();
1215: $result .= $_ if defined($_);
1216: $result .= $linked if defined($linked);
1217: }
1218:
1219: $result;
1220: }
1221:
1222: sub htmlify($;$)
1223: {
1224: (local $_, my $extra) = @_;
1225:
1226: $_ = htmlquote($_);
1227:
1228: # get URL's as link
1229: s{
3.130 ! scop 1230: ((https?|ftp)://.+?)([\s\']|&(quot|[lg]t);)
3.120 scop 1231: }{
3.130 ! scop 1232: &link($1, htmlunquote($1)) . $3
3.120 scop 1233: }egx;
1234:
1235: # get e-mails as link
1236: $_ = htmlify_sub {
1237: s<
1238: [\w+=\-.!]+@[\w\-]+(\.[\w\-]+)+
1239: ><
1240: &link($&, "mailto:$&")
1241: >egix;
1242: } $_;
1243:
1244: if ($extra) {
1245:
1246: # get PR #'s as link: "PR#nnnn" "PR: nnnn, ..." "PR nnnn, ..." "bin/nnnn"
1247: if (defined($prcgi) && defined($re_prkeyword)) {
1248: my $prev;
1249:
1250: do {
1251: $prev = $_;
1252:
1253: $_ = htmlify_sub {
1254: s{
1255: (\b$re_prkeyword[:\#]?\s*
1256: (?:
1257: \#?
1258: \d+[,\s]\s*
1259: )*
1260: \#?)
1261: (\d+)\b
1262: }{
1263: $1 . &link($2, sprintf($prcgi, $2))
1264: }egix;
1265: } $_;
1266: } while ($_ ne $prev);
1267:
1268: if (defined($re_prcategories)) {
1269: $_ = htmlify_sub {
1270: s{
1271: (\b$re_prcategories/(\d+)\b)
1272: }{
1273: &link($1, sprintf($prcgi, $2))
1274: }egox;
1275: } $_;
1276: }
1277: }
1278:
1279: # get manpage specs as link: "foo.1" "foo(1)"
1280: if (defined($mancgi)) {
1281: $_ = htmlify_sub {
1282: s{
1283: (\b([a-zA-Z][\w.]+)
1284: (?:
1285: \( ([0-9n]) \)\B
1286: |
1287: \.([0-9n])\b
1288: )
1289: )
1290: }{
1291: &link($1, sprintf($mancgi, defined($3) ? $3 : $4, $2))
1292: }egx;
1293: } $_;
1294: }
1295: }
1296:
1297: $_;
1298: }
1299:
1300: sub spacedHtmlText($;$)
1301: {
1302: local $_ = $_[0];
1303: my $ts = $_[1] || $tabstop;
1304:
1305: # Cut trailing spaces and tabs
1306: s/[ \t]+$//;
1307:
1308: if (defined($ts)) {
1309:
1310: # Expand tabs
1311: 1 while s/\t+/' ' x (length($&) * $ts - length($`) % $ts)/e;
1312: }
1313:
1314: # replace <tab> and <space> (\001 is to protect us from htmlify)
1315: # gzip can make excellent use of this repeating pattern :-)
1316: if ($hr_breakable) {
1317:
1318: # make every other space 'breakable'
1319: s/ / \001nbsp;/g; # 2 * <space>
1320: # leave single space as it is
1321: } else {
1322: s/ /\001nbsp;/g;
1323: }
1324:
1325: $_ = htmlify($_, $allow_source_extra);
1326:
1327: # unescape
1328: y/\001/&/;
1329:
1330: return $_;
1331: }
1332:
1333: # Note that this doesn't htmlquote the first argument...
1334: sub link($$)
1335: {
1336: my ($name, $url) = @_;
1337:
1338: $url =~ s/:/sprintf("%%%02x", ord($&))/eg
1339: if $url =~ /^[^a-z]/; # relative
1340:
1341: sprintf '<a href="%s">%s</a>', hrefquote($url), $name;
1342: }
1343:
1344: sub revcmp($$)
1345: {
1346: my ($rev1, $rev2) = @_;
1347:
1348: # make no comparison for a tag or a branch
1349: return 0 if $rev1 =~ /[^\d.]/ || $rev2 =~ /[^\d.]/;
1350:
1351: my (@r1) = split (/\./, $rev1);
1352: my (@r2) = split (/\./, $rev2);
1353: my ($a, $b);
1354:
1355: while (($a = shift (@r1)) && ($b = shift (@r2))) {
1356: if ($a != $b) {
1357: return $a <=> $b;
1358: }
1359: }
1360: if (@r1) { return 1; }
1361: if (@r2) { return -1; }
1362: return 0;
1363: }
1364:
1365: sub fatal($$@)
1366: {
1367: my ($errcode, $format, @args) = @_;
1368: if ($is_mod_perl) {
1369: Apache->request->status((split (/ /, $errcode))[0]);
1370: } else {
1371: print "Status: $errcode\r\n";
1372: }
1373: html_header("Error");
1374: print "<p>Error: ", sprintf($format, map(htmlquote($_), @args)), "</p>\n";
1375: html_footer();
1376: exit(1);
1377: }
1378:
1379: sub redirect($)
1380: {
1381: my ($url) = @_;
1382: if ($is_mod_perl) {
1383: Apache->request->status(301);
1384: Apache->request->header_out(Location => $url);
1385: } else {
1386: print "Status: 301 Moved\r\n";
1387: print "Location: $url\r\n";
1388: }
1389: html_header("Moved");
1390: print "<p>This document is located ", &link('here', $url), "</p>\n";
1391: html_footer();
1392: exit(1);
1393: }
1394:
1395: sub safeglob($)
1396: {
1397: my ($filename) = @_;
1398: my ($dirname);
1399: my (@results);
1400: my $dh = do { local (*DH); };
1401:
1402: ($dirname = $filename) =~ s|/[^/]+$||;
1403: $filename =~ s|.*/||;
1404:
1405: if (opendir($dh, $dirname)) {
1406: my $glob = $filename;
1407: my $t;
1408:
1409: # transform filename from glob to regex. Deal with:
1410: # [, {, ?, * as glob chars
1411: # make sure to escape all other regex chars
1412: $glob =~ s/([\.\(\)\|\+])/\\$1/g;
1413: $glob =~ s/\*/.*/g;
1414: $glob =~ s/\?/./g;
1415: $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
1416: foreach (readdir($dh)) {
1417:
1418: if (/^${glob}$/) {
1419: push (@results, "$dirname/" . $_);
1420: }
1421: }
1422: closedir($dh);
1423: }
1424:
1425: @results;
1426: }
1427:
1428: sub search_path($)
1429: {
1430: my ($command) = @_;
1431: my $d;
1432:
1433: for $d (split (/:/, $command_path)) {
1434: return "$d/$command" if -x "$d/$command";
1435: }
1436:
1437: return '';
1438: }
1439:
1440: sub getMimeTypeFromSuffix($)
1441: {
1442: my ($fullname) = @_;
1443: my ($mimetype, $suffix);
1444: my $fh = do { local (*FH); };
1445:
1446: ($suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
1447: $mimetype = $MTYPES{$suffix};
1448: $mimetype = $MTYPES{'*'} if (!$mimetype);
1449:
1450: if (!$mimetype && -f $mime_types) {
1451:
1452: # okey, this is something special - search the
1453: # mime.types database
1454: open($fh, "<$mime_types");
1455: while (<$fh>) {
1456: if ($_ =~ /^\s*(\S+\/\S+).*\b$suffix\b/) {
1457: $mimetype = $1;
1458: last;
1459: }
1460: }
1461: close($fh);
1462: }
1463:
1464: # okey, didn't find anything useful ..
1465: if (!($mimetype =~ /\S\/\S/)) {
1466: $mimetype = "text/plain";
1467: }
1468: return $mimetype;
3.1 knu 1469: }
1470:
1471: ###############################
3.24 knu 1472: # read first lines like head(1)
1473: ###############################
3.120 scop 1474: sub head($;$)
1475: {
1476: my $fh = $_[0];
1477: my $linecount = $_[1] || 10;
3.24 knu 1478:
3.120 scop 1479: my @buf;
1480:
1481: if ($linecount > 0) {
1482: my $i;
1483: for ($i = 0; !eof($fh) && $i < $linecount; $i++) {
1484: push @buf, scalar <$fh>;
1485: }
1486: } else {
1487: @buf = <$fh>;
1488: }
1489:
1490: @buf;
3.24 knu 1491: }
1492:
1493: ###############################
1494: # scan vim and Emacs directives
1495: ###############################
3.120 scop 1496: sub scan_directives(@)
1497: {
1498: my $ts = undef;
3.24 knu 1499:
3.120 scop 1500: for (@_) {
1501: $ts = $1 if /\b(?:ts|tabstop|tab-width)[:=]\s*([1-9]\d*)\b/;
1502: }
3.24 knu 1503:
3.120 scop 1504: ('tabstop' => $ts);
3.24 knu 1505: }
1506:
3.120 scop 1507: sub openOutputFilter()
1508: {
1509: return if !defined($output_filter) || $output_filter eq '';
3.86 knu 1510:
3.120 scop 1511: open(STDOUT, "|-") and return;
3.86 knu 1512:
3.120 scop 1513: # child of child
1514: open(STDERR, '>/dev/null');
1515: exec($output_filter) or exit -1;
3.86 knu 1516: }
1517:
3.24 knu 1518: ###############################
3.1 knu 1519: # show Annotation
1520: ###############################
3.120 scop 1521: sub doAnnotate($$)
1522: {
1523: my ($rev) = @_;
1524: my ($pid);
1525: my ($pathname, $filename);
1526: my $reader = do { local (*FH); };
1527: my $writer = do { local (*FH); };
1528:
1529: # make sure the revisions are wellformed, for security
1530: # reasons ..
1531: if ($rev =~ /[^\w.]/) {
1532: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
1533: }
1534:
1535: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1536: ($filename = $where) =~ s/^.*\///;
1537:
1538: # this seems to be necessary
1539: $| = 1;
1540: $| = 0; # Flush
1541:
3.126 scop 1542: # Work around a mod_perl bug (?) in order to make open2() work.
1543: # Search for "untie STDIN" in mod_perl mailing list archives for more info.
1544: my $old_stdin;
1545: if ($is_mod_perl && ($old_stdin = tied *STDIN)) {
1546: local $^W = undef;
1547: untie *STDIN;
1548: }
1549:
3.120 scop 1550: # this annotate version is based on the
1551: # cvs annotate-demo Perl script by Cyclic Software
1552: # It was written by Cyclic Software, http://www.cyclic.com/, and is in
1553: # the public domain.
1554: # we could abandon the use of rlog, rcsdiff and co using
1555: # the cvsserver in a similiar way one day (..after rewrite)
3.128 scop 1556: $pid = open2($reader, $writer, $CMD{cvs}, @annotate_options, 'server')
3.120 scop 1557: or fatal("500 Internal Error",
1558: 'Fatal Error - unable to open cvs for annotation');
3.126 scop 1559:
1560: # Re-tie STDIN if we fiddled around with it earlier, just to be sure.
1561: tie(*STDIN, ref($old_stdin), $old_stdin) if ($old_stdin && !tied(*STDIN));
3.120 scop 1562:
1563: # OK, first send the request to the server. A simplified example is:
1564: # Root /home/kingdon/zwork/cvsroot
1565: # Argument foo/xx
1566: # Directory foo
1567: # /home/kingdon/zwork/cvsroot/foo
1568: # Directory .
1569: # /home/kingdon/zwork/cvsroot
1570: # annotate
1571: # although as you can see there are a few more details.
1572:
1573: print $writer "Root $cvsroot\n";
1574: print $writer
1575: "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
1576:
1577: # Don't worry about sending valid-requests, the server just needs to
1578: # support "annotate" and if it doesn't, there isn't anything to be done.
1579: print $writer "UseUnchanged\n";
1580: print $writer "Argument -r\n";
1581: print $writer "Argument $rev\n";
1582: print $writer "Argument $where\n";
1583:
1584: # The protocol requires us to fully fake a working directory (at
1585: # least to the point of including the directories down to the one
1586: # containing the file in question).
3.123 scop 1587: # So if $where is "dir/sdir/file", then dirs will be ("dir","sdir","file")
1588: my $path = '';
1589: foreach my $dir (split('/', $where)) {
3.120 scop 1590:
1591: if ($path eq "") {
3.123 scop 1592: # In our example, $dir is "dir".
1593: $path = $dir;
3.120 scop 1594: } else {
1595: print $writer "Directory $path\n";
1596: print $writer "$cvsroot/$path\n";
1597:
1598: # In our example, $_ is "sdir" and $path becomes "dir/sdir"
1599: # And the next time, "file" and "dir/sdir/file" (which then gets
1600: # ignored, because we don't need to send Directory for the file).
3.123 scop 1601: $path .= "/$dir";
3.120 scop 1602: }
1603: }
3.123 scop 1604: undef $path;
3.120 scop 1605:
1606: # And the last "Directory" before "annotate" is the top level.
1607: print $writer "Directory .\n";
1608: print $writer "$cvsroot\n";
1609:
1610: print $writer "annotate\n";
1611:
1612: # OK, we've sent our command to the server. Thing to do is to
1613: # close the writer side and get all the responses. If "cvs server"
1614: # were nicer about buffering, then we could just leave it open, I think.
1615: close($writer) or die "cannot close: $!";
1616:
1617: http_header();
1618:
1619: navigateHeader($scriptwhere, $pathname, $filename, $rev, "annotate");
1620: print
1621: "<h3 style=\"text-align: center\">Annotation of $pathname$filename, Revision $rev</h3>\n";
1622:
1623: # Ready to get the responses from the server.
1624: # For example:
1625: # E Annotations for foo/xx
1626: # E ***************
1627: # M 1.3 (kingdon 06-Sep-97): hello
1628: # ok
1629: my ($lineNr) = 0;
1630: my ($oldLrev, $oldLusr) = ("", "");
1631: my ($revprint, $usrprint);
1632:
1633: if ($annTable) {
1634: print
1635: "<table style=\"border: none\" cellspacing=\"0\" cellpadding=\"0\">\n";
1636: } else {
1637: print "<pre>";
1638: }
1639:
1640: # prefetch several lines
1641: my @buf = head($reader);
1642:
1643: my %d = scan_directives(@buf);
1644:
1645: while (@buf || !eof($reader)) {
1646: $_ = @buf ? shift @buf : <$reader>;
1647:
1648: my @words = split;
1649:
1650: # Adding one is for the (single) space which follows $words[0].
1651: my $rest = substr($_, length($words[0]) + 1);
1652: if ($words[0] eq "E") {
1653: next;
1654: } elsif ($words[0] eq "M") {
1655: $lineNr++;
1656: (my $lrev = substr($_, 2, 13)) =~ y/ //d;
1657: (my $lusr = substr($_, 16, 9)) =~ y/ //d;
1658: my $line = substr($_, 36);
1659: my $isCurrentRev = ($rev eq $lrev);
1660:
1661: # we should parse the date here ..
1662: if ($lrev eq $oldLrev) {
1663: $revprint = sprintf('%-8s', '');
1664: } else {
1665: $revprint = sprintf('%-8s', $lrev);
1666: $revprint =~ s`\S+`&link($&, "$scriptwhere$query#rev$&")`e; # `
1667: $oldLusr = '';
1668: }
1669:
1670: if ($lusr eq $oldLusr) {
1671: $usrprint = '';
1672: } else {
1673: $usrprint = $lusr;
1674: }
1675: $oldLrev = $lrev;
1676: $oldLusr = $lusr;
1677:
1678: # Set bold for text-based browsers only - graphical
1679: # browsers show bold fonts a bit wider than regular fonts,
1680: # so it looks irregular.
1681: print "<b>" if ($isCurrentRev && $is_textbased);
1682:
1683: printf "%s%s %-8s %4d:", $revprint, $isCurrentRev ? '!' : ' ', $usrprint,
1684: $lineNr;
1685: print spacedHtmlText($line, $d{'tabstop'});
1686:
1687: print "</b>" if ($isCurrentRev && $is_textbased);
1688: } elsif ($words[0] eq "ok") {
1689:
1690: # We could complain about any text received after this, like the
1691: # CVS command line client. But for simplicity, we don't.
1692: } elsif ($words[0] eq "error") {
1693: fatal("500 Internal Error",
1694: 'Error occured during annotate: <b>%s</b>', $_);
1695: }
1696: }
1697:
1698: if ($annTable) {
1699: print "</table>";
1700: } else {
1701: print "</pre>";
1702: }
3.124 scop 1703: html_footer();
1704:
3.120 scop 1705: close($reader) or warn "cannot close: $!";
1706: wait;
3.1 knu 1707: }
1708:
1709: ###############################
1710: # make Checkout
1711: ###############################
3.120 scop 1712: sub doCheckout($$)
1713: {
1714: my ($fullname, $rev) = @_;
1715: my ($mimetype, $revopt);
1716: my $fh = do { local (*FH); };
1717:
1718: if ($rev eq 'HEAD' || $rev eq '.') {
1719: $rev = undef;
1720: }
1721:
1722: # make sure the revisions a wellformed, for security
1723: # reasons ..
1724: if (defined($rev) && $rev =~ /[^\w.]/) {
1725: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
1726: }
1727:
1728: # get mimetype
1729: if (defined($input{"content-type"})
1730: && ($input{"content-type"} =~ /\S\/\S/))
1731: {
1732: $mimetype = $input{"content-type"};
1733: } else {
1734: $mimetype = &getMimeTypeFromSuffix($fullname);
1735: }
1736:
1737: if (defined($rev)) {
1738: $revopt = "-r$rev";
1739: if ($use_moddate) {
1740: readLog($fullname, $rev);
1741: $moddate = $date{$rev};
1742: }
1743: } else {
1744: $revopt = "-rHEAD";
1745:
1746: if ($use_moddate) {
1747: readLog($fullname);
1748: $moddate = $date{$symrev{HEAD}};
1749: }
1750: }
1751:
1752: ### just for the record:
1753: ### 'cvs co' seems to have a bug regarding single checkout of
1754: ### directories/files having spaces in it;
1755: ### this is an issue that should be resolved on cvs's side
1756: #
1757: # Safely for a child process to read from.
1758: if (!open($fh, "-|")) { # child
1759: # chdir to $tmpdir before to avoid non-readable cgi-bin directories
1760: chdir($tmpdir);
1761: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1762:
1763: # work around a bug of cvs -p; expand symlinks
1764: exec($CMD{cvs}, @cvs_options, '-d', abs_path($cvsroot), 'co', '-p',
1765: $revopt, $where)
1766: or exit -1;
1767: }
1768:
1769: if (eof($fh)) {
1770: fatal("404 Not Found", '%s is not (any longer) pertinent', $where);
1771: }
1772:
1773: #===================================================================
1774: #Checking out squid/src/ftp.c
1775: #RCS: /usr/src/CVS/squid/src/ftp.c,v
1776: #VERS: 1.1.1.28.6.2
1777: #***************
1778:
1779: # Parse CVS header
1780: my ($revision, $filename, $cvsheader);
1781: $filename = "";
1782: while (<$fh>) {
1783: last if (/^\*\*\*\*/);
1784: $revision = $1 if (/^VERS: (.*)$/);
1785:
1786: if (/^Checking out (.*)$/) {
1787: $filename = $1;
1788: $filename =~ s/^\.\/*//;
1789: }
1790: $cvsheader .= $_;
1791: }
1792:
1793: if ($filename ne $where) {
1794: fatal("500 Internal Error",
1795: 'Unexpected output from cvs co: %s', $cvsheader);
1796: }
1797: $| = 1;
1798:
1799: if ($mimetype eq "text/x-cvsweb-markup") {
1800: &cvswebMarkup($fh, $fullname, $revision);
1801: } else {
1802: http_header($mimetype);
1803: print <$fh>;
1804: }
1805: close($fh);
1.12 fenner 1806: }
1807:
3.120 scop 1808: sub cvswebMarkup($$$)
1809: {
1810: my ($filehandle, $fullname, $revision) = @_;
1811: my ($pathname, $filename);
3.1 knu 1812:
3.120 scop 1813: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1814: ($filename = $where) =~ s/^.*\///;
1815: my ($fileurl) = urlencode($filename);
1816:
1817: http_header();
1818:
1819: navigateHeader($scriptwhere, $pathname, $filename, $revision, "view");
1820: print "<hr noshade>";
3.129 scop 1821: print "<table width=\"100%\">\n<tr>\n<td class=\"log-markup\">";
3.120 scop 1822: print "File: ", &clickablePath($where, 1);
1823: print " (";
1824: &download_link($fileurl, $revision, "download");
1825: print ")";
1826:
1827: if (!$defaultTextPlain) {
1828: print " (";
1829: &download_link($fileurl, $revision, "as text", "text/plain");
1830: print ")";
1831: }
1832: print "<br>\n";
1833:
1834: if ($show_log_in_markup) {
1835: readLog($fullname); #,$revision);
1836: printLog($revision, 0);
1837: } else {
1838: print "Version: <b>$revision</b><br>\n";
1839: print "Tag: <b>", $input{only_with_tag}, "</b><br>\n"
1840: if $input{only_with_tag};
1841: }
1842: print "</td>\n</tr>\n</table>";
1843: my $url = download_url($fileurl, $revision, $mimetype);
1844: print "<hr noshade>";
1845:
1846: if ($mimetype =~ /^image/) {
1847: printf '<img src="%s" alt=""><br>', hrefquote("$url$barequery");
1848: } elsif ($mimetype =~ m%^application/pdf%) {
1849: printf '<embed src="%s" width="100%"><br>', hrefquote("$url$barequery");
1850: } elsif ($preformat_in_markup) {
1851: print "<pre>";
1852:
1853: # prefetch several lines
1854: my @buf = head($filehandle);
1855:
1856: my %d = scan_directives(@buf);
1857:
1858: while (@buf || !eof($filehandle)) {
1859: $_ = @buf ? shift @buf : <$filehandle>;
1860:
1861: print spacedHtmlText($_, $d{'tabstop'});
1862: }
1863: print "</pre>";
1864: } else {
1865: print "<pre>";
1866:
1867: while (<$filehandle>) {
1868: print htmlquote($_);
1869: }
1870: print "</pre>";
1871: }
1872: }
1873:
1874: sub viewable($)
1875: {
1876: my ($mimetype) = @_;
1877:
1878: $mimetype =~ m%^((text|image)/|application/pdf)%;
3.1 knu 1879: }
1880:
1881: ###############################
1882: # Show Colored Diff
1883: ###############################
3.120 scop 1884: sub doDiff($$$$$$)
1885: {
1886: my ($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
1887: my $fh = do { local (*FH); };
1888: my ($rev1, $rev2, $sym1, $sym2, $f1, $f2);
1889:
1890: if (&forbidden_file($fullname)) {
1891: fatal("403 Forbidden",
1892: 'Access forbidden. This file is mentioned in @ForbiddenFiles');
1893: }
1894:
1895: if ($r1 =~ /([^:]+)(:(.+))?/) {
1896: $rev1 = $1;
1897: $sym1 = $3;
1898: }
1899: if ($r1 eq 'text') {
1900: $rev1 = $tr1;
1901: $sym1 = "";
1902: }
1903:
1904: if ($r2 =~ /([^:]+)(:(.+))?/) {
1905: $rev2 = $1;
1906: $sym2 = $3;
1907: }
1908: if ($r2 eq 'text') {
1909: $rev2 = $tr2;
1910: $sym2 = "";
1911: }
1912:
1913: # make sure the revisions a wellformed, for security
1914: # reasons ..
1915: if ($rev1 =~ /[^\w.]/ || $rev2 =~ /[^\w.]/) {
1916: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
1917: }
1918:
1919: #
1920: # rev1 and rev2 are now both numeric revisions.
1921: # Thus we do a DWIM here and swap them if rev1 is after rev2.
1922: # XXX should we warn about the fact that we do this?
1923: if (&revcmp($rev1, $rev2) > 0) {
1924: my ($tmp1, $tmp2) = ($rev1, $sym1);
1925: ($rev1, $sym1) = ($rev2, $sym2);
1926: ($rev2, $sym2) = ($tmp1, $tmp2);
1927: }
1928: my $difftype = $DIFFTYPES{$f};
1929:
1930: if (!$difftype) {
1931: fatal("400 Bad arguments", 'Diff format %s not understood', $f);
1932: }
1933:
1934: my @difftype = @{$difftype->{'opts'}};
1935: my $human_readable = $difftype->{'colored'};
1936:
1937: # apply special options
1938: if ($showfunc) {
1939: push @difftype, '-p' if $f ne 's';
1940:
1941: my ($re1, $re2);
1942:
1943: while (($re1, $re2) = each %funcline_regexp) {
1944: if ($fullname =~ /$re1/) {
1945: push @difftype, '-F', $re2;
1946: last;
1947: }
1948: }
1949: }
1950:
1951: if ($human_readable) {
1952: if ($hr_ignwhite) {
1953: push @difftype, '-w';
1954: }
1955: if ($hr_ignkeysubst) {
1956: push @difftype, '-kk';
1957: }
1958: }
1959:
1960: if (!open($fh, "-|")) { # child
1961: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1962: openOutputFilter();
1963: exec($CMD{rcsdiff}, @difftype, "-r$rev1", "-r$rev2", $fullname) or exit -1;
1964: }
1965: if ($human_readable) {
1966: http_header();
1967: &human_readable_diff($fh, $rev2);
1968: html_footer();
1969: gzipclose();
1970: exit;
1971: } else {
1972: http_header("text/plain");
1973: }
1974:
1975: #
1976: #===================================================================
1977: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
1978: #retrieving revision 1.16
1979: #retrieving revision 1.17
1980: #diff -c -r1.16 -r1.17
1981: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1982: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
1983: #
1984: # Ideas:
1985: # - nuke the stderr output if it's what we expect it to be
1986: # - Add "no differences found" if the diff command supplied no output.
1987: #
1988: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1989: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
1990: # (bogus example, but...)
1991: #
1992: if (grep { $_ eq '-u' } @difftype) {
1993: $f1 = '---';
1994: $f2 = '\+\+\+';
1995: } else {
1996: $f1 = '\*\*\*';
1997: $f2 = '---';
1998: }
1999:
2000: while (<$fh>) {
2001: if (m|^$f1 $cvsroot|o) {
2002: s|$cvsroot/||o;
2003: if ($sym1) {
2004: chop;
2005: $_ .= " $sym1\n";
2006: }
2007: } elsif (m|^$f2 $cvsroot|o) {
2008: s|$cvsroot/||o;
2009:
2010: if ($sym2) {
2011: chop;
2012: $_ .= " $sym2\n";
2013: }
2014: }
2015: print $_;
2016: }
2017: close($fh);
1.12 fenner 2018: }
2019:
3.1 knu 2020: ###############################
2021: # Show Logs ..
2022: ###############################
3.120 scop 2023: sub getDirLogs($$@)
2024: {
2025: my ($cvsroot, $dirname, @otherFiles) = @_;
2026: my ($state, $otherFiles, $tag, $file, $date, $branchpoint, $branch, $log);
2027: my ($rev, $revision, $revwanted, $filename, $head, $author);
2028:
2029: $tag = $input{only_with_tag};
2030:
2031: my ($DirName) = "$cvsroot/$where";
2032: my (@files, @filetags);
2033: my $fh = do { local (*FH); };
2034:
2035: push (@files, &safeglob("$DirName/*,v"));
2036: push (@files, &safeglob("$DirName/Attic/*,v"))
2037: if (!$input{'hideattic'});
2038: foreach my $file (@otherFiles) {
2039: push (@files, "$DirName/$file");
2040: }
2041:
2042: # just execute rlog if there are any files
2043: return unless @files;
2044:
2045: if (defined($tag)) {
2046:
2047: #can't use -r<tag> as - is allowed in tagnames, but misinterpreated by rlog..
2048: if (!open($fh, "-|")) { # child
2049: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
2050: openOutputFilter();
2051: exec($CMD{rlog}, @files) or exit -1;
2052: }
2053: } else {
2054:
2055: if (!open($fh, "-|")) { # child
2056: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
2057: openOutputFilter();
2058: exec($CMD{rlog}, '-r', @files) or exit -1;
2059: }
2060: }
2061: $state = "start";
2062:
2063: while (<$fh>) {
2064: if ($state eq "start") {
2065:
2066: #Next file. Initialize file variables
2067: $rev = '';
2068: $revwanted = '';
2069: $branch = '';
2070: $branchpoint = '';
2071: $filename = '';
2072: $log = '';
2073: $revision = '';
2074: %symrev = ();
2075: @filetags = ();
2076:
2077: #jump to head state
2078: $state = "head";
2079: }
2080: print "$state:$_" if ($verbose);
2081: again:
2082:
2083: if ($state eq "head") {
2084:
2085: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
2086:
2087: if (/^Working file: (.+)$/) {
2088: $filename = $1;
2089: } elsif (/^head: (.+)$/) {
2090: $head = $1;
2091: } elsif (/^branch: (.+)$/) {
2092: $branch = $1;
2093: } elsif (/^symbolic names:/) {
2094: $state = "tags";
2095: ($branch = $head) =~ s/\.\d+$//
2096: if $branch eq '';
2097: $branch =~ s/(\d+)$/0.$1/;
2098: $symrev{MAIN} = $branch;
2099: $symrev{HEAD} = $branch;
2100: $alltags{MAIN} = 1;
2101: $alltags{HEAD} = 1;
2102: push (@filetags, "MAIN", "HEAD");
2103: } elsif (/$LOG_REVSEPARATOR/o) {
2104: $state = "log";
2105: $rev = '';
2106: $date = '';
2107: $log = '';
2108:
2109: # Try to reconstruct the relative filename if RCS spits out a full path
2110: $filename =~ s%^\Q$DirName\E/%%;
2111: }
2112: next;
2113: }
2114:
2115: if ($state eq "tags") {
2116: if (/^\s+([^:]+):\s+([\d\.]+)\s*$/) {
2117: push (@filetags, $1);
2118: $symrev{$1} = $2;
2119: $alltags{$1} = 1;
2120: next;
2121: } elsif (/^\S/) {
2122:
2123: if (defined($tag)) {
2124: if (defined($symrev{$tag}) || $tag eq "HEAD") {
2125: $revwanted = $symrev{$tag eq "HEAD" ? "MAIN" : $tag};
2126: ($branch = $revwanted) =~ s/\b0\.//;
2127: ($branchpoint = $branch) =~ s/\.?\d+$//;
2128: $revwanted = '' if ($revwanted ne $branch);
2129: } elsif ($tag ne "HEAD") {
2130: print "Tag not found, skip this file" if ($verbose);
2131: $state = "skip";
2132: next;
2133: }
2134: }
2135:
2136: foreach my $tagfound (@filetags) {
2137: $tags{$tagfound} = 1;
2138: }
2139: $state = "head";
2140: goto again;
2141: }
2142: }
2143:
2144: if ($state eq "log") {
2145: if (/$LOG_REVSEPARATOR/o || /$LOG_FILESEPARATOR/o) {
2146:
2147: # End of a log entry.
2148: my $revbranch = $rev;
2149: $revbranch =~ s/\.\d+$//;
2150: print "$filename $rev Wanted: $revwanted ",
2151: "Revbranch: $revbranch Branch: $branch ",
2152: "Branchpoint: $branchpoint\n"
2153: if ($verbose);
2154:
2155: if ($revwanted eq '' && $branch ne '' && $branch eq $revbranch
2156: || !defined($tag))
2157: {
2158: print "File revision $rev found for branch $branch\n"
2159: if ($verbose);
2160: $revwanted = $rev;
2161: }
2162:
2163: if ($revwanted ne ''
2164: ? $rev eq $revwanted
2165: : $branchpoint ne ''
2166: ? $rev eq $branchpoint
2167: : 0
2168: && ($rev eq $head))
2169: { # Don't think head is needed here..
2170: print "File info $rev found for $filename\n"
2171: if ($verbose);
2172: my @finfo = ($rev, $date, $log, $author, $filename);
2173: my ($name);
2174: ($name = $filename) =~ s%/.*%%;
2175: $fileinfo{$name} = [@finfo];
2176: $state = "done" if ($rev eq $revwanted);
2177: }
2178: $rev = '';
2179: $date = '';
2180: $log = '';
2181: } elsif ($date eq ''
2182: && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|)
2183: {
2184: my $yr = $1;
2185:
2186: # damn 2-digit year routines :-)
2187: if ($yr > 100) {
2188: $yr -= 1900;
2189: }
2190: $date = &Time::Local::timegm($6, $5, $4, $3, $2 - 1, $yr);
2191: ($author) = /author: ([^;]+)/;
2192: $state = "log";
2193: $log = '';
2194: next;
2195: } elsif ($rev eq '' && /^revision (\d+(?:\.\d+)+).*$/) {
2196: $rev = $1; # .*$ eats up the locker(lockers?) info, if any
2197: next;
2198: } else {
2199: $log .= $_;
2200: }
2201: }
2202:
2203: if (/$LOG_FILESEPARATOR/o) {
2204: $state = "start";
2205: next;
2206: }
2207: }
2208:
2209: if ($. == 0) {
2210: fatal("500 Internal Error",
2211: 'Failed to spawn GNU rlog on <em>"%s"</em>. <p>Did you set the <b>$command_path</b> in your configuration file correctly ? (Currently "%s"',
2212: join (", ", @files),
2213: $command_path);
2214: }
2215: close($fh);
2216: }
2217:
2218: sub readLog($;$)
2219: {
2220: my ($fullname, $revision) = @_;
2221: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
2222: my $fh = do { local (*FH); };
2223:
2224: if (defined($revision)) {
2225: $revision = "-r$revision";
2226: } else {
2227: $revision = "";
2228: }
2229:
2230: undef %symrev;
2231: undef %revsym;
2232: undef @allrevisions;
2233: undef %date;
2234: undef %author;
2235: undef %state;
2236: undef %difflines;
2237: undef %log;
2238:
2239: print("Going to rlog '$fullname'\n") if ($verbose);
2240: if (!open($fh, "-|")) { # child
2241: if ($revision ne '') {
2242: openOutputFilter();
2243: exec($CMD{rlog}, $revision, $fullname) or exit -1;
2244: } else {
2245: openOutputFilter();
2246: exec($CMD{rlog}, $fullname) or exit -1;
2247: }
2248: }
2249:
2250: while (<$fh>) {
2251: print if ($verbose);
2252: if ($symnames) {
2253: if (/^\s+([^:]+):\s+([\d\.]+)/) {
2254: $symrev{$1} = $2;
2255: } else {
2256: $symnames = 0;
2257: }
2258: } elsif (/^head:\s+([\d\.]+)/) {
2259: $head = $1;
2260: } elsif (/^branch:\s+([\d\.]+)/) {
2261: $curbranch = $1;
2262: } elsif (/^symbolic names/) {
2263: $symnames = 1;
2264: } elsif (/^-----/) {
2265: last;
2266: }
2267: }
2268: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
2269:
2270: # each log entry is of the form:
2271: # ----------------------------
2272: # revision 3.7.1.1
2273: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
2274: # log info
2275: # ----------------------------
2276:
2277: # For a locked revision, the first line after the separator
2278: # becomes smth like
2279: # revision 9.19 locked by: vassilii;
2280:
2281: logentry:
2282:
2283: while (!/$LOG_FILESEPARATOR/o) {
2284: $_ = <$fh>;
2285: last logentry if (!defined($_)); # EOF
2286: print "R:", $_ if ($verbose);
2287: if (/^revision (\d+(?:\.\d+)+)/) {
2288: $rev = $1;
2289: unshift (@allrevisions, $rev);
2290: } elsif (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o) {
2291: next logentry;
2292: } else {
2293:
2294: # The rlog output is syntactically ambiguous. We must
2295: # have guessed wrong about where the end of the last log
2296: # message was.
2297: # Since this is likely to happen when people put rlog output
2298: # in their commit messages, don't even bother keeping
2299: # these lines since we don't know what revision they go with
2300: # any more.
2301: next logentry;
2302: }
2303: $_ = <$fh>;
2304: print "D:", $_ if ($verbose);
2305: if (
2306: m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|
2307: )
2308: {
2309: my $yr = $1;
2310:
2311: # damn 2-digit year routines :-)
2312: if ($yr > 100) {
2313: $yr -= 1900;
2314: }
2315: $date{$rev} = &Time::Local::timegm($6, $5, $4, $3, $2 - 1, $yr);
2316: $author{$rev} = $7;
2317: $state{$rev} = $8;
2318: $difflines{$rev} = $10;
2319: } else {
2320: fatal("500 Internal Error", 'Error parsing RCS output: %s', $_);
2321: }
2322:
2323: line:
2324: while (<$fh>) {
2325: print "L:", $_ if ($verbose);
2326: next line if (/^branches:\s/);
2327: last line if (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o);
2328: $log{$rev} .= $_;
2329: }
2330: print "E:", $_ if ($verbose);
2331: }
2332: close($fh);
2333: print "Done reading RCS file\n" if ($verbose);
2334:
2335: @revorder = reverse sort { revcmp($a, $b) } @allrevisions;
2336: print "Done sorting revisions", join (" ", @revorder), "\n"
2337: if ($verbose);
2338:
2339: #
2340: # HEAD is an artificial tag which is simply the highest tag number on the main
2341: # branch, unless there is a branch tag in the RCS file in which case it's the
2342: # highest revision on that branch. Find it by looking through @revorder; it
2343: # is the first commit listed on the appropriate branch.
2344: # This is not neccesary the same revision as marked as head in the RCS file.
2345: my $headrev = $curbranch || "1";
2346: ($symrev{"MAIN"} = $headrev) =~ s/(\d+)$/0.$1/;
2347:
2348: foreach $rev (@revorder) {
2349: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
2350: $symrev{"HEAD"} = $rev;
2351: last;
2352: }
2353: }
2354: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
2355: if (!defined($symrev{"HEAD"}));
2356: print "Done finding HEAD\n" if ($verbose);
2357:
2358: #
2359: # Now that we know all of the revision numbers, we can associate
2360: # absolute revision numbers with all of the symbolic names, and
2361: # pass them to the form so that the same association doesn't have
2362: # to be built then.
2363: #
2364: undef @branchnames;
2365: undef %branchpoint;
2366: undef $sel;
2367:
2368: foreach (reverse sort keys %symrev) {
2369: $rev = $symrev{$_};
2370: if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
2371: push (@branchnames, $_);
2372:
2373: #
2374: # A revision number of A.B.0.D really translates into
2375: # "the highest current revision on branch A.B.D".
2376: #
2377: # If there is no branch A.B.D, then it translates into
2378: # the head A.B .
2379: #
2380: # This reasoning also applies to the main branch A.B,
2381: # with the branch number 0.A, with the exception that
2382: # it has no head to translate to if there is nothing on
2383: # the branch, but I guess this can never happen?
2384: #
2385: # (the code below gracefully forgets about the branch
2386: # if it should happen)
2387: #
2388: $head = defined($2) ? $2 : "";
2389: $branch = $3;
2390: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
2391: my $regex;
2392: $regex = quotemeta $branchrev;
2393: $rev = $head;
2394:
2395: foreach my $r (@revorder) {
2396: if ($r =~ /^${regex}\b/) {
2397: $rev = $branchrev;
2398: last;
2399: }
2400: }
2401: next if ($rev eq "");
2402:
2403: if ($rev ne $head && $head ne "") {
2404: $branchpoint{$head} .= ", "
2405: if ($branchpoint{$head});
2406: $branchpoint{$head} .= $_;
2407: }
2408: }
2409: $revsym{$rev} .= ", " if ($revsym{$rev});
2410: $revsym{$rev} .= $_;
2411: $sel .= "<option value=\"${rev}:${_}\">$_</option>\n";
2412: }
2413: print "Done associating revisions with branches\n" if ($verbose);
2414:
2415: my ($onlyonbranch, $onlybranchpoint);
2416: if ($onlyonbranch = $input{'only_with_tag'}) {
2417: $onlyonbranch = $symrev{$onlyonbranch};
2418: if ($onlyonbranch =~ s/\b0\.//) {
2419: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
2420: } else {
2421: $onlybranchpoint = $onlyonbranch;
2422: }
2423:
2424: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
2425: fatal("404 Tag not found", 'Tag %s not defined',
2426: $input{'only_with_tag'});
2427: }
2428: }
2429:
2430: undef @revisions;
2431:
2432: foreach (@allrevisions) {
2433: ($br = $_) =~ s/\.\d+$//;
2434: ($brp = $br) =~ s/\.\d+$//;
2435: next if ($onlyonbranch
2436: && $br ne $onlyonbranch
2437: && $_ ne $onlybranchpoint);
2438: unshift (@revisions, $_);
2439: }
2440:
2441: if ($logsort eq "date") {
2442:
2443: # Sort the revisions in commit order an secondary sort on revision
2444: # (secondary sort needed for imported sources, or the first main
2445: # revision gets before the same revision on the 1.1.1 branch)
2446: @revdisplayorder =
2447: sort { $date{$b} <=> $date{$a} || -revcmp($a, $b) } @revisions;
2448: } elsif ($logsort eq "rev") {
2449:
2450: # Sort the revisions in revision order, highest first
2451: @revdisplayorder = reverse sort { revcmp($a, $b) } @revisions;
2452: } else {
2453:
2454: # No sorting. Present in the same order as rlog / cvs log
2455: @revdisplayorder = @revisions;
2456: }
2457:
2458: }
2459:
2460: sub printDiffLinks($$)
2461: {
2462: my ($text, $url) = @_;
2463: my @extra;
2464:
2465: local $_;
2466: for ($DIFFTYPES{$defaultDiffType}{'colored'} ? qw(u) : qw(h)) {
2467: my $f = $_ eq $defaultDiffType ? '' : $_;
2468:
2469: push @extra, &link(lc $DIFFTYPES{$_}{'descr'}, "$url&f=$f");
2470: }
2471:
2472: print &link($text, $url), ' (', join (', ', @extra), ')';
2473: }
2474:
2475: sub printLog($;$)
2476: {
2477: my ($link, $br, $brp);
2478: ($_, $link) = @_;
2479: ($br = $_) =~ s/\.\d+$//;
2480: ($brp = $br) =~ s/\.?\d+$//;
2481: my ($isDead, $prev);
2482:
2483: $link = 1 if (!defined($link));
2484: $isDead = ($state{$_} eq "dead");
2485:
2486: print "<p>\n";
2487: if ($link && !$isDead) {
2488: my ($filename);
2489: ($filename = $where) =~ s/^.*\///;
2490: my ($fileurl) = urlencode($filename);
2491: print "<a name=\"rev$_\"></a>";
2492:
2493: if (defined($revsym{$_})) {
2494: foreach my $sym (split (", ", $revsym{$_})) {
2495: print "<a name=\"$sym\"></a>";
2496: }
2497: }
2498:
2499: if (defined($revsym{$br})
2500: && $revsym{$br}
2501: && !defined($nameprinted{$br}))
2502: {
2503: foreach my $sym (split (", ", $revsym{$br})) {
2504: print "<a name=\"$sym\"></a>";
2505: }
2506: $nameprinted{$br} = 1;
2507: }
2508: print "\n Revision ";
2509: &download_link($fileurl, $_, $_,
2510: $defaultViewable ? "text/x-cvsweb-markup" : undef);
2511:
2512: if ($defaultViewable) {
2513: print " / (";
2514: &download_link($fileurl, $_, "download", $mimetype);
2515: print ")";
2516: }
2517:
2518: if (not $defaultTextPlain) {
2519: print " / (";
2520: &download_link($fileurl, $_, "as text", "text/plain");
2521: print ")";
2522: }
2523:
2524: if (!$defaultViewable) {
2525: print " / (";
2526: &download_link($fileurl, $_, "view", "text/x-cvsweb-markup");
2527: print ")";
2528: }
2529:
2530: if ($allow_annotate) {
2531: print " - ";
2532: print &link('annotate',
2533: sprintf('%s/%s?annotate=%s%s',
2534: $scriptname, urlencode($where), $_, $barequery));
2535: }
2536:
2537: # Plus a select link if enabled, and this version isn't selected
2538: if ($allow_version_select) {
3.121 scop 2539: if (!defined($input{"r1"}) || $input{"r1"} ne $_) {
3.120 scop 2540: print " - ";
2541: print &link('[select for diffs]',
2542: sprintf('%s?r1=%s%s', $scriptwhere, $_, $barequery));
2543: } else {
2544: print " - <b>[selected]</b>";
2545: }
2546: }
2547: } else {
2548: print "Revision <b>$_</b>";
2549: }
2550:
2551: if (/^1\.1\.1\.\d+$/) {
2552: print " <i>(vendor branch)</i>";
2553: }
2554: if (defined @mytz) {
2555: my ($est) = $mytz[(localtime($date{$_}))[8]];
2556: print ", <i>", scalar localtime($date{$_}), " $est</i> (";
2557: } else {
2558: print ", <i>", scalar gmtime($date{$_}), " UTC</i> (";
2559: }
2560: print readableTime(time() - $date{$_}, 1), " ago)";
2561: print " by ";
2562: print "<i>", $author{$_}, "</i>\n";
2563: print "<br>Branch: <b>", $link ? link_tags($revsym{$br}) : $revsym{$br},
2564: "</b>\n"
2565: if ($revsym{$br});
2566: print "<br>CVS Tags: <b>", $link ? link_tags($revsym{$_}) : $revsym{$_},
2567: "</b>"
2568: if ($revsym{$_});
2569: print "<br>Branch point for: <b>",
2570: $link ? link_tags($branchpoint{$_}) : $branchpoint{$_}, "</b>\n"
2571: if ($branchpoint{$_});
2572:
2573: # Find the previous revision
2574: my @prevrev = split (/\./, $_);
2575: do {
2576: if (--$prevrev[$#prevrev] <= 0) {
2577:
2578: # If it was X.Y.Z.1, just make it X.Y
2579: pop (@prevrev);
2580: pop (@prevrev);
2581: }
2582: $prev = join (".", @prevrev);
2583: } until (defined($date{$prev}) || $prev eq "");
2584:
2585: if ($prev ne "") {
2586: if ($difflines{$_}) {
2587: print "<br>Changes since <b>$prev: $difflines{$_} lines</b>";
2588: }
2589: }
2590:
2591: if ($isDead) {
2592: print "<br><b><i>FILE REMOVED</i></b>\n";
2593: } elsif ($link) {
2594: my %diffrev = ();
2595: $diffrev{$_} = 1;
2596: $diffrev{""} = 1;
2597: print '<br>';
2598: my $diff = 'Diff';
2599:
2600: #
2601: # Offer diff to previous revision
2602: if ($prev) {
2603: $diffrev{$prev} = 1;
2604:
2605: my $url =
2606: sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere, $prev, $_, $barequery);
2607:
2608: print $diff, " to previous ";
2609: $diff = '';
2610: printDiffLinks($prev, $url);
2611: }
2612:
2613: #
2614: # Plus, if it's on a branch, and it's not a vendor branch,
2615: # offer a diff with the branch point.
2616: if ($revsym{$brp}
2617: && !/^1\.1\.1\.\d+$/
2618: && !defined($diffrev{$brp}))
2619: {
2620: my $url =
2621: sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere, $brp, $_, $barequery);
2622:
2623: print $diff, " to branchpoint ";
2624: $diff = '';
2625: printDiffLinks($brp, $url);
2626: }
2627:
2628: #
2629: # Plus, if it's on a branch, and it's not a vendor branch,
2630: # offer to diff with the next revision of the higher branch.
2631: # (e.g. change gets committed and then brought
2632: # over to -stable)
2633: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2634: my ($i, $nextmain);
2635:
2636: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++) {
2637: }
2638: my @tmp2 = split (/\./, $_);
2639: for ($nextmain = ""; $i > 0; $i--) {
2640: my $next = $revorder[$i - 1];
2641: my @tmp1 = split (/\./, $next);
2642:
2643: if (@tmp1 < @tmp2) {
2644: $nextmain = $next;
2645: last;
2646: }
2647:
2648: # Only the highest version on a branch should have
2649: # a diff for the "next main".
2650: last
2651: if (@tmp1 - 1 <= @tmp2
2652: && join (".", @tmp1[0 .. $#tmp1 - 1]) eq
2653: join (".", @tmp2[0 .. $#tmp1 - 1]));
2654: }
2655:
2656: if (!defined($diffrev{$nextmain})) {
2657: $diffrev{$nextmain} = 1;
2658:
2659: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2660: $scriptwhere, $nextmain, $_, $barequery);
2661:
2662: print $diff, " next main ";
2663: $diff = '';
2664: printDiffLinks($nextmain, $url);
2665: }
2666: }
2667:
2668: # Plus if user has selected only r1, then present a link
2669: # to make a diff to that revision
2670: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2671: $diffrev{$input{"r1"}} = 1;
2672:
2673: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2674: $scriptwhere, $input{'r1'}, $_, $barequery);
2675:
2676: print $diff, " to selected ";
2677: $diff = '';
2678: printDiffLinks($input{'r1'}, $url);
2679: }
2680:
2681: }
2682: print "\n</p>\n<pre>\n";
2683: print &htmlify($log{$_}, $allow_log_extra);
2684: print "</pre>\n";
2685: }
2686:
2687: sub doLog($)
2688: {
2689: my ($fullname) = @_;
2690: my ($diffrev, $upwhere, $filename, $backurl);
2691:
2692: readLog($fullname);
2693:
2694: html_header("CVS log for $where");
2695: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2696: ($filename = $where) =~ s|^.*/||;
2697: $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
2698: print "<p>\n ";
2699: print &link($backicon, "$backurl#$filename"), " <b>Up to ",
2700: &clickablePath($upwhere, 1), "</b>\n</p>\n";
2701: print "<p>\n ";
2702: print &link('Request diff between arbitrary revisions', '#diff');
2703: print "\n</p>\n<hr noshade>\n";
2704:
2705: print "<p>\n";
2706: if ($curbranch) {
2707: print "Default branch: ", ($revsym{$curbranch} || $curbranch);
2708: } else {
2709: print "No default branch";
2710: }
2711: print "<br>\n";
2712:
2713: if ($input{only_with_tag}) {
2714: print "Current tag: $input{only_with_tag}<br>\n";
2715: }
2716: print "</p>\n";
2717:
2718: undef %nameprinted;
2719:
2720: for (my $i = 0; $i <= $#revdisplayorder; $i++) {
2721: print "<hr size=\"1\" noshade>\n";
2722: printLog($revdisplayorder[$i]);
2723: }
2724:
2725: print "<hr noshade>\n<p>\n";
2726: print "<a name=\"diff\">\n";
2727: print "This form allows you to request diff's between any two\n";
2728: print "revisions of a file. You may select a symbolic revision\n";
2729: print "name using the selection box or you may type in a numeric\n";
2730: print "name using the type-in text box.\n";
2731: print "</a>\n</p>\n";
2732: print
2733: "<form method=\"get\" action=\"${scriptwhere}.diff\" name=\"diff_select\">\n";
2734:
2735: foreach (@stickyvars) {
2736: printf('<input type="hidden" name="%s" value="%s">', $_, $input{$_})
2737: if (defined($input{$_})
2738: && ((!defined($DEFAULTVALUE{$_}) || $input{$_} ne $DEFAULTVALUE{$_})
2739: && $input{$_} ne ""));
2740: }
2741: print "<table style=\"border: none\">\n<tr>\n";
2742: print "<td align=\"right\">";
2743: print "<label for=\"r1\" accesskey=\"1\">Diffs between </label>\n";
2744: print "<select id=\"r1\" name=\"r1\">\n";
2745: print "<option value=\"text\" selected>Use Text Field</option>\n";
2746: print $sel;
2747: print "</select>\n";
2748: $diffrev = $revdisplayorder[$#revdisplayorder];
2749: $diffrev = $input{"r1"} if (defined($input{"r1"}));
2750: print
2751: "<input type=\"text\" size=\"$inputTextSize\" name=\"tr1\" value=\"$diffrev\" onchange=\"this.form.r1.selectedIndex=0\"></td>\n";
2752: print "<td><br></td>\n</tr>\n";
2753: print "<tr>\n<td align=\"right\">";
2754: print "<label for=\"r2\" accesskey=\"2\">and </label>\n";
2755: print "<select id=\"r2\" name=\"r2\">\n";
2756: print "<option value=\"text\" selected>Use Text Field</option>\n";
2757: print $sel;
2758: print "</select>\n";
2759: $diffrev = $revdisplayorder[0];
2760: $diffrev = $input{"r2"} if (defined($input{"r2"}));
2761: print
2762: "<input type=\"text\" size=\"$inputTextSize\" name=\"tr2\" value=\"$diffrev\" onchange=\"this.form.r2.selectedIndex=0\"></td>\n";
2763: print
2764: "<td><input type=\"submit\" value=\" Get Diffs \" accesskey=\"G\"></td>\n";
2765: print "</tr>\n</table>\n";
2766: print "</form>\n";
2767: print "<hr noshade>\n";
2768: print "<form method=\"get\" action=\"$scriptwhere\">\n";
2769: print "<table style=\"border: none\">\n";
2770: print "<tr>\n<td align=\"right\">";
2771: print "<label for=\"f\" accesskey=\"D\">Preferred Diff type:";
2772: print "</label></td>\n";
2773: print "<td>";
2774: printDiffSelect($use_java_script);
2775: print "</td>\n<td></td>\n</tr>\n";
2776:
2777: if (@branchnames) {
2778: print "<tr>\n<td align=\"right\">";
2779: print "<label for=\"only_with_tag\" accesskey=\"B\">";
2780: print "View only Branch:</label></td>\n";
2781: print "<td>";
2782: print "<a name=\"branch\"></a>\n";
2783: print "<select id=\"only_with_tag\" name=\"only_with_tag\"";
2784: print " onchange=\"this.form.submit()\"" if $use_java_script;
2785: print ">\n";
2786: print "<option value=\"\"";
2787: print " selected"
2788: if (defined($input{"only_with_tag"})
2789: && $input{"only_with_tag"} eq "");
2790: print ">Show all branches</option>\n";
2791:
2792: foreach (reverse sort @branchnames) {
2793: print "<option";
2794: print " selected"
2795: if (defined($input{"only_with_tag"})
2796: && $input{"only_with_tag"} eq $_);
2797: print ">${_}</option>\n";
2798: }
2799: print "</select></td>\n<td></td>\n</tr>\n";
2800: }
2801:
2802: foreach (@stickyvars) {
2803: next if ($_ eq "f");
2804: next if ($_ eq "only_with_tag");
2805: next if ($_ eq "logsort");
2806: print "<input type=\"hidden\" name=\"$_\" value=\"$input{$_}\">\n"
2807: if (defined($input{$_})
2808: && (!defined($DEFAULTVALUE{$_})
2809: || $input{$_} ne $DEFAULTVALUE{$_})
2810: && $input{$_} ne "");
2811: }
2812: print "<tr>\n<td align=\"right\">";
2813: print "<a name=\"logsort\"></a>\n";
2814: print "<label for=\"logsort\" accesskey=\"L\">Sort log by:";
2815: print "</label></td>\n<td>";
2816: printLogSortSelect($use_java_script);
2817: print "</td>\n";
2818: print "<td><input type=\"submit\" value=\" Set \" accesskey=\"S\"></td>\n";
2819: print "</tr>\n</table>\n";
2820: print "</form>\n";
2821: html_footer();
2822: }
2823:
2824: sub flush_diff_rows($$$$)
2825: {
2826: my $j;
2827: my ($leftColRef, $rightColRef, $leftRow, $rightRow) = @_;
2828:
2829: if (!defined($state)) {
2830: return;
2831: }
2832:
2833: if ($state eq "PreChangeRemove") { # we just got remove-lines before
2834: for ($j = 0; $j < $leftRow; $j++) {
2835: print "<tr>\n<td class=\"diff-removed\"> @$leftColRef[$j]</td>\n";
2836: print "<td class=\"diff-empty\"> </td>\n</tr>\n";
2837: }
2838: } elsif ($state eq "PreChange") { # state eq "PreChange"
2839: # we got removes with subsequent adds
2840:
2841: for ($j = 0; $j < $leftRow || $j < $rightRow; $j++) { # dump out both cols
2842: print "<tr>\n";
2843: if ($j < $leftRow) {
2844: print "<td class=\"diff-changed\"> @$leftColRef[$j]</td>";
2845: } else {
2846: print "<td class=\"diff-changed-missing\"> </td>";
2847: }
2848: print "\n";
2849:
2850: if ($j < $rightRow) {
2851: print "<td class=\"diff-changed\"> @$rightColRef[$j]</td>";
2852: } else {
2853: print "<td class=\"diff-changed-missing\"> </td>";
2854: }
2855: print "\n</tr>\n";
2856: }
2857: }
3.1 knu 2858: }
2859:
2860: ##
2861: # Function to generate Human readable diff-files
2862: # human_readable_diff(String revision_to_return_to);
2863: ##
3.120 scop 2864: sub human_readable_diff($)
2865: {
2866: my ($difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
2867: my ($fh, $rev) = @_;
2868: my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
2869: my (@rightCol, @leftCol);
2870:
2871: ($where_nd = $where) =~ s/.diff$//;
2872: ($filename = $where_nd) =~ s/^.*\///;
2873: ($pathname = $where_nd) =~ s/(Attic\/)?[^\/]*$//;
2874: ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
2875:
2876: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, "diff");
2877:
2878: # Read header to pick up read revision and date, if possible
2879: while (<$fh>) {
2880: ($r1d, $r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
2881: ($r2d, $r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
2882: last if (/^\+\+\+ /);
2883: }
2884:
2885: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
2886: $rev1 = $r1r;
2887: $date1 = $r1d;
2888: }
2889: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
2890: $rev2 = $r2r;
2891: $date2 = $r2d;
2892: }
2893:
2894: print
2895: "<h3 style=\"text-align: center\">Diff for /$where_nd between version $rev1 and $rev2</h3>\n",
2896:
2897: # Using style=\"border: none\" here breaks NS 4.x badly...
2898: "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n",
2899: "<tr style=\"background-color: #ffffff\">\n",
3.129 scop 2900: "<th style=\"text-align: center; vertical-align: top\" width=\"50%\">",
2901: "version $rev1";
3.120 scop 2902: print ", $date1" if (defined($date1));
2903: print "<br>Tag: $sym1\n" if ($sym1);
3.129 scop 2904: print "</th>\n<th style=\"text-align: center; vertical-align: top\" width=\"50%\">version $rev2";
3.120 scop 2905: print ", $date2" if (defined($date2));
2906: print "<br>Tag: $sym2\n" if ($sym1);
2907: print "</th>\n";
2908:
2909: my $leftRow = 0;
2910: my $rightRow = 0;
2911: my ($oldline, $newline, $funname, $diffcode, $rest);
2912:
2913: # Process diff text
2914:
2915: # prefetch several lines
2916: my @buf = head($fh);
2917:
2918: my %d = scan_directives(@buf);
2919:
2920: while (@buf || !eof($fh)) {
2921: $difftxt = @buf ? shift @buf : <$fh>;
2922:
2923: if ($difftxt =~ /^@@/) {
2924: ($oldline, $newline, $funname) =
2925: $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
2926: $funname = htmlquote($funname);
2927: $funname =~ s/\s/ /go;
2928: print "<tr class=\"diff-heading\">\n<td width=\"50%\">";
2929: print
2930: "<table width=\"100%\" border=\"1\" cellpadding=\"5\">\n<tr>\n<td><b>Line $oldline</b>";
2931: print
2932: " <span style=\"font-size: smaller\">$funname</span></td>\n</tr>\n</table>";
2933: print "</td>\n<td width=\"50%\">";
2934: print
2935: "<table width=\"100%\" border=\"1\" cellpadding=\"5\">\n<tr>\n<td><b>Line $newline</b>";
2936: print
2937: " <span style=\"font-size: smaller\">$funname</span></td>\n</tr>\n</table>\n";
2938: print "</td>\n";
2939: $state = "dump";
2940: $leftRow = 0;
2941: $rightRow = 0;
2942: } else {
2943: ($diffcode, $rest) = $difftxt =~ /^([-+ ])(.*)/;
2944: $_ = spacedHtmlText($rest, $d{'tabstop'});
2945:
2946: #########
2947: # little state machine to parse unified-diff output (Hen, zeller@think.de)
2948: # in order to get some nice 'ediff'-mode output
2949: # states:
2950: # "dump" - just dump the value
2951: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
2952: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
2953: ##########
2954:
2955: if ($diffcode eq '+') {
2956: if ($state eq "dump")
2957: { # 'change' never begins with '+': just dump out value
2958: print
2959: "<tr>\n<td class=\"diff-empty\"> </td>\n<td class=\"diff-added\"> $_</td>\n</tr>\n";
2960: } else { # we got minus before
2961: $state = "PreChange";
2962: $rightCol[$rightRow++] = $_;
2963: }
2964: } elsif ($diffcode eq '-') {
2965: $state = "PreChangeRemove";
2966: $leftCol[$leftRow++] = $_;
2967: } else { # empty diffcode
2968: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2969: print
2970: "<tr>\n<td class=\"diff-same\"> $_</td>\n<td class=\"diff-same\"> $_</td>\n</tr>\n";
2971: $state = "dump";
2972: $leftRow = 0;
2973: $rightRow = 0;
2974: }
2975: }
2976: }
2977: close($fh);
2978:
2979: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2980:
2981: # state is empty if we didn't have any change
2982: if (!$state) {
2983: print "<tr>\n<td colspan=\"2\"> </td>\n</tr>\n";
2984: print "<tr class=\"diff-empty\">\n";
2985: print
2986: "<td colspan=\"2\" align=\"center\"><b>- No viewable change -</b></td>\n</tr>\n";
2987: }
2988: print "</table>\n";
2989:
2990: print "<hr style=\"width: 100%\" noshade>\n";
2991: print "<form method=\"get\" action=\"${scriptwhere}\">\n";
2992: print "<table style=\"border: none\">\n<tr>\n<td>\n";
2993:
2994: # print legend
2995: print "<table border=\"1\">\n<tr>\n<td>";
2996: print
2997: "Legend:<br><table style=\"border: none\" cellspacing=\"0\" cellpadding=\"1\">\n";
2998: print
2999: "<tr>\n<td align=\"center\" class=\"diff-removed\">Removed from v.$rev1</td>\n<td class=\"diff-empty\"> </td>\n</tr>\n";
3000: print
3001: "<tr class=\"diff-changed\">\n<td align=\"center\" colspan=\"2\">changed lines</td>\n</tr>\n";
3002: print
3003: "<tr>\n<td class=\"diff-empty\"> </td>\n<td align=\"center\" class=\"diff-added\">Added in v.$rev2</td>\n</tr>\n";
3004: print "</table>\n</td>\n</tr>\n</table>\n</td>\n<td>";
3005:
3006: # Print format selector
3007: foreach my $var (keys %input) {
3008: next if ($var eq "f");
3009: next if (defined($DEFAULTVALUE{$var})
3010: && $DEFAULTVALUE{$var} eq $input{$var});
3011: print "<input type=\"hidden\" name=\"", urlencode($var), "\" value=\"",
3012: urlencode($input{$var}), "\">\n";
3013: }
3014: printDiffSelect($use_java_script);
3015: print "<input type=\"submit\" value=\"Show\">\n";
3016: print "</td>\n";
3017:
3018: print "</tr>\n</table>\n";
3019: print "</form>\n";
3020: }
3021:
3022: sub navigateHeader($$$$$)
3023: {
3024: my ($swhere, $path, $filename, $rev, $title) = @_;
3025: $swhere = "" if ($swhere eq $scriptwhere);
3026: $swhere = './' . urlencode($filename) if ($swhere eq "");
3027:
3.129 scop 3028: my $css = css();
3029: $filename = htmlquote($filename);
3.100 knu 3030:
3.120 scop 3031: print <<EOF;
3.100 knu 3032: $HTML_DOCTYPE
3.89 knu 3033: <html>
3034: <head>
3.100 knu 3035: <title>$path$filename - $title - $rev</title>$css
3.106 scop 3036: $HTML_META</head>
3.129 scop 3037: <body class="src">
3038: <table width="100%" class="navigate-header" style="border: none" cellspacing="0" cellpadding="1">
3.89 knu 3039: <tr valign="bottom"><td>
3.64 knu 3040: EOF
3041:
3.120 scop 3042: print &link($backicon, "$swhere$query#rev$rev");
3.129 scop 3043: printf '<b>Return to %s CVS log', &link($filename, "$swhere$query#rev$rev");
3.120 scop 3044: print "</b> $fileicon</td>";
3045:
3046: print "<td align=\"right\">$diricon <b>Up to ", &clickablePath($path, 1),
3047: "</b></td>";
3048: print "</tr></table>";
3049: }
3050:
3051: sub plural_write($$)
3052: {
3053: my ($num, $text) = @_;
3054: if ($num != 1) {
3055: $text .= "s";
3056: }
3057:
3058: if ($num > 0) {
3059: return join (' ', $num, $text);
3060: } else {
3061: return "";
3062: }
3.1 knu 3063: }
3064:
3065: ##
3066: # print readable timestamp in terms of
3067: # '..time ago'
3068: # H. Zeller <zeller@think.de>
3069: ##
3.120 scop 3070: sub readableTime($$)
3071: {
3072: my ($i, $break, $retval);
3073: my ($secs, $long) = @_;
3074:
3075: # this function works correct for time >= 2 seconds
3076: if ($secs < 2) {
3077: return "very little time";
3078: }
3079:
3080: my %desc = (
3081: 1, 'second', 60, 'minute', 3600, 'hour',
3082: 86400, 'day', 604800, 'week', 2628000, 'month',
3083: 31536000, 'year'
3084: );
3085: my @breaks = sort { $a <=> $b } keys %desc;
3086: $i = 0;
3087:
3088: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
3089: $i++;
3090: }
3091: $i--;
3092: $break = $breaks[$i];
3093: $retval = plural_write(int($secs / $break), $desc{$break});
3094:
3095: if ($long == 1 && $i > 0) {
3096: my $rest = $secs % $break;
3097: $i--;
3098: $break = $breaks[$i];
3099: my $resttime = plural_write(int($rest / $break), $desc{$break});
3100: if ($resttime) {
3101: $retval .= ", $resttime";
3102: }
3103: }
3.1 knu 3104:
3.120 scop 3105: return $retval;
3.1 knu 3106: }
3107:
3108: ##
3109: # clickablePath(String pathname, boolean last_item_clickable)
3110: #
3111: # returns a html-ified path whereas each directory is a link for
3112: # faster navigation. last_item_clickable controls whether the
3113: # basename (last directory/file) is a link as well
3114: ##
3.120 scop 3115: sub clickablePath($$)
3116: {
3117: my ($pathname, $clickLast) = @_;
3118: my $retval = '';
3119:
3120: if ($pathname eq '/') {
3121:
3122: # this should never happen - chooseCVSRoot() is
3123: # intended to do this
3124: $retval = "[$cvstree]";
3125: } else {
3126: $retval .=
3127: ' ' . &link("[$cvstree]", sprintf('%s/%s#dirlist', $scriptname, $query));
3128: my $wherepath = '';
3129: my ($lastslash) = $pathname =~ m|/$|;
3130:
3131: foreach (split (/\//, $pathname)) {
3132: $retval .= " / ";
3133: $wherepath .= "/$_";
3134: my ($last) = "$wherepath/" eq "/$pathname"
3135: || $wherepath eq "/$pathname";
3136:
3137: if ($clickLast || !$last) {
3138: $retval .= &link($_,
3139: join ('',
3140: $scriptname, urlencode($wherepath),
3141: (!$last || $lastslash ? '/' : ''), $query,
3142: (!$last || $lastslash ? "#dirlist" : "")));
3143: } else { # do not make a link to the current dir
3144: $retval .= $_;
3145: }
3146: }
3147: }
3148: return $retval;
3149: }
3150:
3151: sub chooseCVSRoot()
3152: {
3153:
3154: print "<form method=\"get\" action=\"${scriptwhere}\">\n";
3155: if (2 <= @CVSROOT) {
3156: my ($k);
3157: foreach $k (keys %input) {
3158: print "<input type=\"hidden\" name=\"$k\" value=\"$input{$k}\">\n"
3159: if ($input{$k}) && ($k ne "cvsroot");
3160: }
3161:
3162: # Form-Elements look wierd in Netscape if the background
3163: # isn't gray and the form elements are not placed
3164: # within a table ...
3165: print "<table style=\"border: none\">\n<tr>\n";
3166: print
3167: "<td><label for=\"cvsroot\" accesskey=\"C\">CVS Root:</label></td>\n";
3168: print "<td>\n<select id=\"cvsroot\" name=\"cvsroot\"";
3169: print " onchange=\"this.form.submit()\"" if $use_java_script;
3170: print ">\n";
3171:
3172: foreach $k (@CVSROOT) {
3173: print "<option value=\"$k\"";
3174: print " selected" if ($k eq $cvstree);
3175: print ">", ($CVSROOTdescr{$k} ? $CVSROOTdescr{$k} : $k), "</option>\n";
3176: }
3177: print "</select>\n</td>\n<td>";
3178: } else {
3179:
3180: # no choice -- but we need the form to select module/path,
3181: # at least for Netscape
3182: print "<p>\n";
3183: print "CVS Root: <b>[$cvstree]</b>";
3184: }
3185:
3186: print " <label for=\"mpath\" accesskey=\"M\">Module path or alias:";
3187: print "</label>\n";
3188: print
3189: "<input type=\"text\" id=\"mpath\" name=\"path\" value=\"\" size=\"15\">\n";
3190: print "<input type=\"submit\" value=\"Go\" accesskey=\"O\">";
3191:
3192: if (2 <= @CVSROOT) {
3193: print "</td>\n</tr>\n</table>";
3194: } else {
3195: print "</p>";
3196: }
3197: print "\n</form>";
3198: }
3199:
3200: sub chooseMirror()
3201: {
3202:
3203: # This code comes from the original BSD-cvsweb
3204: # and may not be useful for your site; If you don't
3205: # set %MIRRORS this won't show up, anyway.
3206: scalar(%MIRRORS) or return;
3207:
3208: # Should perhaps exclude the current site somehow...
3209: print "\n<p>\nThis CVSweb is mirrored in\n";
3210:
3211: my @tmp = map(&link(htmlquote($_), $MIRRORS{$_}), sort keys %MIRRORS);
3212: my $tmp = pop (@tmp);
3213:
3214: if (scalar(@tmp)) {
3215: print join (', ', @tmp), ' and ';
3216: }
3217:
3218: print "$tmp.\n</p>\n";
3219: }
3220:
3221: sub fileSortCmp()
3222: {
3223: my ($comp) = 0;
3224: my ($c, $d, $af, $bf);
3225:
3226: ($af = $a) =~ s/,v$//;
3227: ($bf = $b) =~ s/,v$//;
3228: my ($rev1, $date1, $log1, $author1, $filename1) = @{$fileinfo{$af}}
3229: if (defined($fileinfo{$af}));
3230: my ($rev2, $date2, $log2, $author2, $filename2) = @{$fileinfo{$bf}}
3231: if (defined($fileinfo{$bf}));
3232:
3233: if ( defined($filename1)
3234: && defined($filename2)
3235: && $af eq $filename1
3236: && $bf eq $filename2)
3237: {
3238:
3239: # Two files
3240: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
3241: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
3242: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
3243: $comp = ($author1 cmp $author2)
3244: if ($byauthor && $author1 && $author2);
3245: }
3246:
3247: if ($comp == 0) {
3248:
3249: # Directories first, then files under version control,
3250: # then other, "rogue" files.
3251: # Sort by filename if no other criteria available.
3252:
3253: my $ad = (
3254: (-d "$fullname/$a")
3255: ? 'D'
3256: : (defined($fileinfo{$af}) ? 'F' : 'R')
3257: );
3258: my $bd = (
3259: (-d "$fullname/$b")
3260: ? 'D'
3261: : (defined($fileinfo{$bf}) ? 'F' : 'R')
3262: );
3263: ($c = $a) =~ s|.*/||;
3264: ($d = $b) =~ s|.*/||;
3265: $comp = ("$ad$c" cmp "$bd$d");
3266: }
3267: return $comp;
3.1 knu 3268: }
3269:
3270: # make A url for downloading
3.120 scop 3271: sub download_url($$;$)
3272: {
3273: my ($url, $revision, $mimetype) = @_;
3.1 knu 3274:
3.120 scop 3275: $revision =~ s/\b0\.//;
3.1 knu 3276:
3.120 scop 3277: if (defined($checkoutMagic)
3278: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup"))
3279: {
3280: my $path = $where;
3281: $path =~ s|[^/]+$||;
3282: $url = "$scriptname/$checkoutMagic/${path}$url";
3283: }
3284: $url .= "?rev=$revision";
3285: $url .= '&content-type=' . urlencode($mimetype) if (defined($mimetype));
3.67 knu 3286:
3.120 scop 3287: $url;
3.1 knu 3288: }
3289:
3.12 knu 3290: # Presents a link to download the
3.1 knu 3291: # selected revision
3.120 scop 3292: sub download_link($$$;$)
3293: {
3294: my ($url, $revision, $textlink, $mimetype) = @_;
3295: my ($fullurl) = download_url($url, $revision, $mimetype);
3296:
3297: $fullurl =~ s/:/sprintf("%%%02x", ord($&))/eg;
3298:
3299: printf '<a href="%s"', hrefquote("$fullurl$barequery");
3300:
3301: if ($open_extern_window
3302: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup"))
3303: {
3304: print ' target="cvs_checkout"';
3305:
3306: # we should have
3307: # 'if (document.cvswin==null) document.cvswin=window.open(...'
3308: # in order to allow the user to resize the window; otherwise
3309: # the user may resize the window, but on next checkout - zap -
3310: # its original (configured s. cvsweb.conf) size is back again
3311: # .. annoying (if $extern_window_(width|height) is defined)
3312: # but this if (..) solution is far from perfect
3313: # what we need to do as well is
3314: # 1) save cvswin in an invisible frame that always exists
3315: # (document.cvswin will be void on next load)
3316: # 2) on close of the cvs_checkout - window set the cvswin
3317: # variable to 'null' again - so that it will be
3318: # reopenend with the configured size
3319: # anyone a JavaScript programmer ?
3320: # .. so here without if (..):
3321: # currently, the best way is to comment out the size parameters
3322: # ($extern_window...) in cvsweb.conf.
3323: if ($use_java_script) {
3324: my @attr = qw(resizable scrollbars);
3325:
3326: push @attr, qw(status toolbar)
3327: if (defined($mimetype) && $mimetype eq "text/html");
3328:
3329: push @attr, "width=$extern_window_width"
3330: if (defined($extern_window_width));
3331:
3332: push @attr, "height=$extern_window_height"
3333: if (defined($extern_window_height));
3334:
3335: # We need the "return false" here to prevent browsers
3336: # from following the href after the onclick handler.
3337: # This would effectively load the same document in
3338: # the same window *twice*.
3339: printf q` onclick="window.open('%s','cvs_checkout','%s');return false"`,
3340: hrefquote("$fullurl$barequery"), join (',', @attr);
3341: }
3342: }
3343: print "><b>$textlink</b></a>";
3.1 knu 3344: }
3345:
3346: # Returns a Query string with the
3347: # specified parameter toggled
3.120 scop 3348: sub toggleQuery($$)
3349: {
3350: my ($toggle, $value) = @_;
3351: my ($newquery, $var);
3352: my (%vars);
3353: %vars = %input;
3354:
3355: if (defined($value)) {
3356: $vars{$toggle} = $value;
3357: } else {
3358: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
3359: }
3360:
3361: # Build a new query of non-default paramenters
3362: $newquery = "";
3363: foreach $var (@stickyvars) {
3364: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
3365: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
3366:
3367: if ($value ne $default) {
3368: $newquery .= "&" if ($newquery ne "");
3369: $newquery .= urlencode($var) . "=" . urlencode($value);
3370: }
3371: }
3372:
3373: if ($newquery) {
3374: return '?' . $newquery;
3375: }
3376: return "";
3377: }
3378:
3379: sub urlencode($)
3380: {
3381: local ($_) = @_;
3382:
3383: s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
3384:
3385: $_;
3386: }
3387:
3388: sub htmlquote($)
3389: {
3390: local ($_) = @_;
3391:
3392: # Special Characters; RFC 1866
3393: s/&/&/g;
3394: s/\"/"/g;
3395: s/</</g;
3396: s/>/>/g;
3397:
3398: $_;
3399: }
3400:
3401: sub htmlunquote($)
3402: {
3403: local ($_) = @_;
3404:
3405: # Special Characters; RFC 1866
3406: s/"/\"/g;
3407: s/</</g;
3408: s/>/>/g;
3409: s/&/&/g;
3410:
3411: $_;
3412: }
3413:
3414: sub hrefquote($)
3415: {
3416: local ($_) = @_;
3417:
3418: y/ /+/;
3419:
3420: htmlquote($_);
3421: }
3422:
3423: sub http_header(;$)
3424: {
3425: my $content_type = shift || "text/html";
3426:
3427: $content_type .= "; charset=$charset"
3428: if $content_type =~ m,^text/, && defined($charset) && $charset;
3429:
3430: if (defined($moddate)) {
3431: if ($is_mod_perl) {
3432: Apache->request->header_out(
3433: "Last-Modified" => scalar gmtime($moddate) . " GMT");
3434: } else {
3435: print "Last-Modified: ", scalar gmtime($moddate), " GMT\r\n";
3436: }
3437: }
3438:
3439: if ($is_mod_perl) {
3440: Apache->request->content_type($content_type);
3441: } else {
3442: print "Content-Type: $content_type\r\n";
3443: }
3444:
3445: if ($allow_compress && $maycompress) {
3446: if ($has_zlib
3447: || (defined($CMD{gzip}) && open(GZIP, "| $CMD{gzip} -1 -c")))
3448: {
3449:
3450: if ($is_mod_perl) {
3451: Apache->request->content_encoding("x-gzip");
3452: Apache->request->header_out(Vary => "Accept-Encoding");
3453: Apache->request->send_http_header;
3454: } else {
3455: print "Content-Encoding: x-gzip\r\n";
3456: print "Vary: Accept-Encoding\r\n"; #RFC 2068, 14.43
3457: print "\r\n"; # Close headers
3458: }
3459: $| = 1;
3460: $| = 0; # Flush header output
3461:
3462: if ($has_zlib) {
3463: tie *GZIP, __PACKAGE__, \*STDOUT;
3464: }
3465: select(GZIP);
3466: $gzip_open = 1;
3467:
3468: # print "<!-- gzipped -->" if ($content_type =~ m|^text/html\b|);
3469: } else {
3470: if ($is_mod_perl) {
3471: Apache->request->send_http_header;
3472: } else {
3473: print "\r\n"; # Close headers
3474: }
3475: print
3476: "<span style=\"font-size: smaller\">Unable to find gzip binary in the <b>\$command_path</b> ($command_path) to compress output</span><br>";
3477: }
3478: } else {
3479:
3480: if ($is_mod_perl) {
3481: Apache->request->send_http_header;
3482: } else {
3483: print "\r\n"; # Close headers
3484: }
3485: }
3486: }
3487:
3488: sub html_header($)
3489: {
3490: my ($title) = @_;
3.129 scop 3491: my $css = css();
3.120 scop 3492: http_header("text/html");
3493: print <<EOH;
3.100 knu 3494: $HTML_DOCTYPE
3.1 knu 3495: <html>
3.40 knu 3496: <head>
3.129 scop 3497: <title>$title</title>$css
3.106 scop 3498: $HTML_META</head>
3.129 scop 3499: <body>
3.1 knu 3500: $logo <h1 align="center">$title</h1>
3501: EOH
3502: }
3503:
3.120 scop 3504: sub html_footer()
3505: {
3.127 scop 3506: print "<hr noshade>\n<address>$address</address>\n" if $address;
3507: print "</body>\n</html>\n";
3.1 knu 3508: }
3509:
3.120 scop 3510: sub link_tags($)
3511: {
3512: my ($tags) = @_;
3513: my ($ret) = "";
3514: my ($fileurl, $filename);
3515:
3516: ($filename = $where) =~ s/^.*\///;
3517: $fileurl = './' . urlencode($filename);
3518:
3519: foreach my $sym (split (", ", $tags)) {
3520: $ret .= ",\n" if ($ret ne "");
3521: $ret .= &link($sym, $fileurl . toggleQuery('only_with_tag', $sym));
3522: }
3523: return "$ret\n";
3.1 knu 3524: }
3525:
3526: #
3.81 knu 3527: # See if a module is listed in the config file's @HideModules list.
3.1 knu 3528: #
3.120 scop 3529: sub forbidden_module($)
3530: {
3531: my ($module) = @_;
3532: local $_;
3533:
3534: for (@HideModules) {
3535: return 1 if $module =~ $_;
3536: }
3537: return 0;
3538: }
3539:
3540: sub forbidden_file($)
3541: {
3542: my ($path) = @_;
3543: $path = substr($path, length($cvsroot) + 1);
3544: local $_;
3545: for (@ForbiddenFiles) {
3546: return 1 if $path =~ $_;
3547: }
3548: return 0;
3.129 scop 3549: }
3550:
3551:
3552: sub css ()
3553: {
3554: # TODO: this should be moved into external CSS file.
3555: return "
3556: <style type=\"text/css\">
3557: body {
3558: color: #000;
3559: background-color: #fff;
3560: }
3561: th {
3562: text-align: left;
3563: }
3564: /* Source, diff and annotate views */
3565: .src {
3566: background-color: #eee;
3567: }
3568: /* Navigation header for diffs and annotations */
3569: .navigate-header {
3570: background-color: #99e;
3571: }
3572: /* Directory table */
3573: table.dir {
3574: border-width: 0;
3575: background-color: #ccc;
3576: }
3577: /* Directory column header */
3578: .dir-header {
3579: background-color: #ffc;
3580: }
3581: /* Sorted directory column header */
3582: .dir-header-sorted {
3583: background-color: #fc6;
3584: }
3585: /* Odd rows in directory table */
3586: .dir-row-odd {
3587: background-color: #fff;
3588: }
3589: /* Even rows in directory table */
3590: .dir-row-even {
3591: background-color: #fff;
3592: }
3593: /* Log entry in markup */
3594: .log-markup {
3595: background-color: #fff;
3596: }
3597: /* 'Line'-header of each diffed file */
3598: .diff-heading {
3599: background-color: #9cc;
3600: }
3601: /* Lines that are the same */
3602: .diff-same {
3603: font-family: Helvetica, Arial, sans-serif;
3604: font-size: smaller;
3605: }
3606: /* Empty lines */
3607: .diff-empty {
3608: background-color: #ccc;
3609: }
3610: /* Added lines */
3611: .diff-added {
3612: background-color: #ccf;
3613: font-family: Helvetica, Arial, sans-serif;
3614: font-size: smaller;
3615: }
3616: /* Removed lines */
3617: .diff-removed {
3618: background-color: #f99;
3619: font-family: Helvetica, Arial, sans-serif;
3620: font-size: smaller;
3621: }
3622: /* Changed lines */
3623: .diff-changed {
3624: background-color: #9f9;
3625: font-family: Helvetica, Arial, sans-serif;
3626: font-size: smaller;
3627: }
3628: /* Empty changed lines */
3629: .diff-changed-missing {
3630: background-color: #9c9;
3631: }
3632: </style>";
3.25 knu 3633: }
3634:
3635: # Close the GZIP handle remove the tie.
3636:
3.120 scop 3637: sub gzipclose
3638: {
3639: if ($gzip_open) {
3640: select(STDOUT);
3641: close(GZIP);
3642: untie *GZIP;
3643: $gzip_open = 0;
3644: }
3.23 knu 3645: }
3646:
3647: # implement a gzipped file handle via the Compress:Zlib compression
3648: # library.
3649:
3650: sub MAGIC1() { 0x1f }
3651: sub MAGIC2() { 0x8b }
3.80 knu 3652: sub OSCODE() { 3 }
3.23 knu 3653:
3.120 scop 3654: sub TIEHANDLE
3655: {
3656: my ($class, $out) = @_;
3657: my ($d) = Compress::Zlib::deflateInit(
3658: -Level => Compress::Zlib::Z_BEST_COMPRESSION(),
3659: -WindowBits => -Compress::Zlib::MAX_WBITS()
3660: )
3661: or return undef;
3662: my ($o) = { handle => $out,
3663: dh => $d,
3664: crc => 0,
3665: len => 0,
3666: };
3667: my ($header) = pack("c10",
3668: MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(),
3669: 0, 0, 0, 0, 0, 0, OSCODE);
3670: print {$o->{handle}} $header;
3671: return bless($o, $class);
3672: }
3673:
3674: sub PRINT
3675: {
3676: my ($o) = shift;
3677: my ($buf) = join (defined $, ? $, : "", @_);
3678: my ($len) = length($buf);
3679: my ($compressed, $status) = $o->{dh}->deflate($buf);
3680: print {$o->{handle}} $compressed if defined($compressed);
3681: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3682: $o->{len} += $len;
3683: return $len;
3684: }
3685:
3686: sub PRINTF
3687: {
3688: my ($o) = shift;
3689: my ($fmt) = shift;
3690: my ($buf) = sprintf($fmt, @_);
3691: my ($len) = length($buf);
3692: my ($compressed, $status) = $o->{dh}->deflate($buf);
3693: print {$o->{handle}} $compressed if defined($compressed);
3694: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3695: $o->{len} += $len;
3696: return $len;
3697: }
3698:
3699: sub WRITE
3700: {
3701: my ($o, $buf, $len, $off) = @_;
3702: my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
3703: print {$o->{handle}} $compressed if defined($compressed);
3704: $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
3705: $o->{len} += $len;
3706: return $len;
3707: }
3708:
3709: sub CLOSE
3710: {
3711: my ($o) = @_;
3712: return if !defined($o->{dh});
3713: my ($buf) = $o->{dh}->flush();
3714: $buf .= pack("V V", $o->{crc}, $o->{len});
3715: print {$o->{handle}} $buf;
3716: undef $o->{dh};
3717: }
3718:
3719: sub DESTROY
3720: {
3721: my ($o) = @_;
3722: CLOSE($o);
1.1 jfieber 3723: }
CVSweb