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