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